Bug 771843

Summary: Better document ls behaviour for formatting options('ls -Zl' and 'ls -lZ' show different results)
Product: Red Hat Enterprise Linux 6 Reporter: ryo fujita <rfujita>
Component: coreutilsAssignee: Ondrej Vasik <ovasik>
Status: CLOSED ERRATA QA Contact: qe-baseos-daemons
Severity: low Docs Contact:
Priority: medium    
Version: 6.2CC: azelinka, kdudka, meyering, prc
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: coreutils-8.4-17.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-06-20 14:34:25 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description ryo fujita 2012-01-05 08:18:11 UTC
Description of problem:
'ls -Zl' and 'ls -lZ' show different results on RHEL6.2.

Version-Release number of selected component (if applicable):
coreutils-8.4-16.el6

How reproducible:
Always.

Steps to Reproduce:
1. Issuing 'ls -Zl' and 'ls -lZ'
  
Actual results:
'ls -Zl' shows a list like followings.
# ls -Zl
total 130
dr-xr-xr-x.   2 system_u:object_r:bin_t:s0       root    root     4096 Jan  5 17:08 bin
dr-xr-xr-x.   5 system_u:object_r:boot_t:s0      root    root     1024 Nov 30 20:36 boot
drwxr-xr-x.  10 system_u:object_r:cgroup_t:s0    root    root     4096 Nov 30 20:59 cgroup
drwxr-xr-x.  19 system_u:object_r:device_t:s0    root    root     3980 Jan  5 17:08 dev
drwxr-xr-x. 123 system_u:object_r:etc_t:s0       root    root    12288 Jan  5 17:08 etc
drwxr-xr-x.   4 system_u:object_r:home_root_t:s0 root    root     4096 Nov 30 21:03 home
dr-xr-xr-x.  12 system_u:object_r:lib_t:s0       root    root     4096 Jan  5 17:04 lib

'ls -lZ' shows another one.
# ls -lZ
dr-xr-xr-x. root    root    system_u:object_r:bin_t:s0       bin
dr-xr-xr-x. root    root    system_u:object_r:boot_t:s0      boot
drwxr-xr-x. root    root    system_u:object_r:cgroup_t:s0    cgroup
drwxr-xr-x. root    root    system_u:object_r:device_t:s0    dev
drwxr-xr-x. root    root    system_u:object_r:etc_t:s0       etc
drwxr-xr-x. root    root    system_u:object_r:home_root_t:s0 home
dr-xr-xr-x. root    root    system_u:object_r:lib_t:s0       lib

Expected results:
We can get same results even if the order of options is changed.

Additional info:
In coreutils/src/ls.c patched with SELinux.patch,
1696         case 'l':
1697           format = long_format;
1698           break;

1940         case 'Z':
1941           print_scontext = 1;
1942     format = security_format;
1943           break;

If 'Z' option precedes 'l', the variant 'format' is set to 'long_format'. But 'l' option precedes 'Z', it's set to 'security_format'.

Comment 2 Kamil Dudka 2012-01-05 10:03:24 UTC
Please have a look at the following bugs:

    bug 448903 - Incorrect output of ls -lZ

    bug 524202 - "ls -lZ" is not the same as "ls -Zl"

Comment 3 Ondrej Vasik 2012-01-05 11:24:36 UTC
Although it is not a bug, as there are more such reports, I think it would be good to improve the ls info documentation a bit.

Comment 8 errata-xmlrpc 2012-06-20 14:34:25 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2012-0933.html