public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] seccomp.sh: Try to account for terminal width while formatting list of system calls
@ 2024-08-27  6:26 Stefano Brivio
  0 siblings, 0 replies; only message in thread
From: Stefano Brivio @ 2024-08-27  6:26 UTC (permalink / raw)
  To: passt-dev; +Cc: David Gibson

Avoid excess lines on wide terminals, but make sure we don't fail if
we can't fetch the number of columns for any reason, as it's not a
fundamental feature and we don't want to break anything with it.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 seccomp.sh | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/seccomp.sh b/seccomp.sh
index 052e1c8..38aa826 100755
--- a/seccomp.sh
+++ b/seccomp.sh
@@ -242,7 +242,10 @@ for __p in ${__profiles}; do
 	__calls="$(sed -n 's/[\t ]*\*[\t ]*#syscalls\(:'"${__p}"'\|\)[\t ]\{1,\}\(.*\)/\2/p' ${IN})"
 	__calls="${__calls} ${EXTRA_SYSCALLS:-}"
 	__calls="$(filter ${__calls})"
-	echo "seccomp profile ${__p} allows: ${__calls}" | tr '\n' ' ' | fmt -t
+
+	cols="$(stty -a | sed -n 's/.*columns \([0-9]*\).*/\1/p' || :)" 2>/dev/null
+	case $cols in [0-9]*) col_args="-w ${cols}";; *) col_args="";; esac
+	echo "seccomp profile ${__p} allows: ${__calls}" | tr '\n' ' ' | fmt -t ${col_args}
 
 	# Pad here to keep gen_profile() "simple"
 	__count=0
-- 
@@ -242,7 +242,10 @@ for __p in ${__profiles}; do
 	__calls="$(sed -n 's/[\t ]*\*[\t ]*#syscalls\(:'"${__p}"'\|\)[\t ]\{1,\}\(.*\)/\2/p' ${IN})"
 	__calls="${__calls} ${EXTRA_SYSCALLS:-}"
 	__calls="$(filter ${__calls})"
-	echo "seccomp profile ${__p} allows: ${__calls}" | tr '\n' ' ' | fmt -t
+
+	cols="$(stty -a | sed -n 's/.*columns \([0-9]*\).*/\1/p' || :)" 2>/dev/null
+	case $cols in [0-9]*) col_args="-w ${cols}";; *) col_args="";; esac
+	echo "seccomp profile ${__p} allows: ${__calls}" | tr '\n' ' ' | fmt -t ${col_args}
 
 	# Pad here to keep gen_profile() "simple"
 	__count=0
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-08-27  6:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-27  6:26 [PATCH] seccomp.sh: Try to account for terminal width while formatting list of system calls Stefano Brivio

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).