The attached fixes a logic inversion issue, and doesn't print context in file system mode which is confusing to me at least.
There is also the argument not to print context in terse mode at all, as we'll have issues with outputting other extended attributes like capabilities and ACLs etc? cheers, Pádraig.
>From fd4ca634513a610309206be3b446a3d11c5b1d3a Mon Sep 17 00:00:00 2001 From: =?utf-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com> Date: Tue, 5 Oct 2010 08:40:17 +0100 Subject: [PATCH] stat: adjust the printing of SELinux context * src/stat.c (default_format): Don't print SELinux context when in file system (-f) mode, as the context is associated with the file, not the file system. Fix logic inversion, so that in terse mode, %C is included only when is_selinux_enabled and not vice versa. --- src/stat.c | 26 +++++--------------------- 1 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/stat.c b/src/stat.c index e13f21f..a82fcb3 100644 --- a/src/stat.c +++ b/src/stat.c @@ -1074,12 +1074,7 @@ default_format (bool fs, bool terse, bool device) if (fs) { if (terse) - { - if (0 < is_selinux_enabled ()) - format = xstrdup ("%n %i %l %t %s %S %b %f %a %c %d %C\n"); - else - format = xstrdup ("%n %i %l %t %s %S %b %f %a %c %d\n"); - } + format = xstrdup ("%n %i %l %t %s %S %b %f %a %c %d\n"); else { /* TRANSLATORS: This string uses format specifiers from @@ -1091,29 +1086,18 @@ Block size: %-10s Fundamental block size: %S\n\ Blocks: Total: %-10b Free: %-10f Available: %a\n\ Inodes: Total: %-10c Free: %d\n\ ")); - - if (0 < is_selinux_enabled ()) - { - /* TRANSLATORS: This string uses format specifiers from - 'stat --help' with --file-system, and NOT from printf. */ - char *temp = format; - format = xasprintf ("%s%s", format, _("\ -Context: %C\n\ -")); - free (temp); - } } } else /* ! fs */ { if (terse) { - if (0 < is_selinux_enabled ()) + if (is_selinux_enabled ()) format = xstrdup ("%n %s %b %f %u %g %D %i %h %t %T" - " %X %Y %Z %W %o\n"); + " %X %Y %Z %W %o %C\n"); else format = xstrdup ("%n %s %b %f %u %g %D %i %h %t %T" - " %X %Y %Z %W %o %C\n"); + " %X %Y %Z %W %o\n"); } else { @@ -1152,7 +1136,7 @@ Access: (%04a/%10.10A) Uid: (%5u/%8U) Gid: (%5g/%8G)\n\ ")); free (temp); - if (0 < is_selinux_enabled ()) + if (is_selinux_enabled ()) { temp = format; /* TRANSLATORS: This string uses format specifiers from -- 1.6.2.5