policycoreutils/setfiles: stdout messages don't need program prefix
PATCH 1/3 policycoreutils/setfiles: stdout messages don't need program prefix
I suggested that if you run a command for its informational output (by passing -v), you don't expect it to be prefixed with the program name. Prefixing is used for error messages, so you can tell where your shell script blew up :). If a script is running a command for its informational output, it's usually the script's responsibility to make sure it's in context, e.g. providing headers if there are multiple sections of output.
Removing the program name from setfiles/restorecon output is particularly useful because it generates very long lines. But also, it actually helps highlight where there are error messages - the prefix will make them stand out visually.
--- policycoreutils/setfiles/setfiles.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
policycoreutils/setfiles/setfiles.c +8 -2
@@ -142,9 +142,15 @@ static int __attribute__ ((format(printf, 2, 3))) log_callback(int type, const char *fmt, ...) { int rc; -FILE *out = (type ==SELINUX_INFO ) ? stdout : stderr; +FILE *out;va_list ap; -fprintf (out,"%s: " , r_opts.progname); + +if (type ==SELINUX_INFO ) { + out = stdout; + }else { + out = stderr; +fprintf (out,"%s: " , r_opts.progname); + }va_start (ap, fmt); rc =vfprintf (out, fmt, ap);va_end (ap);
Signature · 1 line
2.9.3
PATCH 3/3 policycoreutils: fixfiles: remove useless use of cat
Don't force output through a pipe - let them access the TTY.
When run interactively, this acts as a workaround for "Output of fixfiles gets garbled?"
https://bugzilla.redhat.com/show_bug.cgi?id=1435894
E.g. it would also be useful if restorecon ever decides it doesn't want to output backspace characters on non-TTY outputs.
--- policycoreutils/scripts/fixfiles | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
policycoreutils/scripts/fixfiles +3 -3
@@ -243,17 +243,17 @@ FC=$TEMPFCFILE fi if [ ! -z "$RPMFILES" ]; then for i in `echo "$RPMFILES" | sed 's/,/ /g'`; do - rpmlist $i | ${RESTORECON} $exclude_dirs ${FORCEFLAG} ${VERBOSE} $* -R -i -f - 2>&1 | cat >> $LOGFILE + rpmlist $i | ${RESTORECON} $exclude_dirs ${FORCEFLAG} ${VERBOSE} $* -R -i -f - >>$LOGFILE 2>&1 done exit $? fi if [ ! -z "$FILEPATH" ]; then - ${RESTORECON} $exclude_dirs ${FORCEFLAG} ${VERBOSE} -R $* -- "$FILEPATH" 2>&1 | cat >> $LOGFILE + ${RESTORECON} $exclude_dirs ${FORCEFLAG} ${VERBOSE} -R $* -- "$FILEPATH" >>$LOGFILE 2>&1 return fi if [ -n "${FILESYSTEMSRW}" ]; then echo "${OPTION}ing `echo ${FILESYSTEMSRW}`" - ${SETFILES} ${VERBOSE} $exclude_dirs -q ${FORCEFLAG} $* ${FC} ${FILESYSTEMSRW} 2>&1 | cat >> $LOGFILE + ${SETFILES} ${VERBOSE} $exclude_dirs -q ${FORCEFLAG} $* ${FC} ${FILESYSTEMSRW} >>$LOGFILE 2>&1 else echo >&2 "fixfiles: No suitable file systems found" fi
Signature · 1 line
2.9.3
PATCH 2/3 policycoreutils/setfiles: don't scramble stdout and stderr together
In reply to Alan Jenkinshttps://bugzilla.redhat.com/show_bug.cgi?id=1435894
When output to a non-tty (as caused by the implementation of fixfiles), stdout is fully buffered. stdout should be flushed before writes to stderr.
See e.g. https://news.ycombinator.com/item?id=1271015
--- policycoreutils/setfiles/setfiles.c | 1 + 1 file changed, 1 insertion(+)
policycoreutils/setfiles/setfiles.c +1 -0
@@ -149,6 +149,7 @@ log_callback(int type, const char *fmt, ...) out = stdout; }else { out = stderr; +fflush (stdout);fprintf (out,"%s: " , r_opts.progname); }va_start (ap, fmt);
Signature · 1 line
2.9.3
Quoted 7 lines · Alan Jenkins
I suggested that if you run a command for its informational output (by passing
-v), you don't expect it to be prefixed with the program name. Prefixing is used for error messages, so you can tell where your shell script blew up :). If a script is running a command for its informational output, it's usually the script's responsibility to make sure it's in context, e.g. providing headers if there are multiple sections of output.
Quoted 6 lines
Removing the program name from setfiles/restorecon output is particularly useful because it generates very long lines. But also, it actually helps highlight where there are error messages - the prefix will make them stand out visually.
Signed-off-by Alan Jenkins <[email protected]>
All three of these have been applied.
Thanks,
Jim
Quoted 27 lines
--- policycoreutils/setfiles/setfiles.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)policycoreutils/setfiles/setfiles.c +8
-2@@ -142,9 +142,15 @@ static int __attribute__ ((format(printf, 2, 3))) log_callback(int type, const char *fmt, ...) { int rc; -FILE *out = (type ==SELINUX_INFO ) ? stdout : stderr; +FILE *out;va_list ap; -fprintf (out,"%s: " , r_opts.progname); + +if (type ==SELINUX_INFO ) { + out = stdout; + }else { + out = stderr; +fprintf (out,"%s: " , r_opts.progname); + }va_start (ap, fmt); rc =vfprintf (out, fmt, ap);va_end (ap);
Signature · 2 lines
James Carter <[email protected]> National Security Agency