]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: avoid expensive capability lookup by default
authorPádraig Brady <P@draigBrady.com>
Sun, 3 Apr 2022 20:42:42 +0000 (21:42 +0100)
committerPádraig Brady <P@draigBrady.com>
Sun, 3 Apr 2022 21:10:35 +0000 (22:10 +0100)
Lookup of file-based capabilities adds 30% overhead to the common
case of ls --color usage.  Since the use of file capabilities is
very rare, it doesn't make sense to pay this cost in the common
case.  It's better to use getcap to inspect capabilities, and the
following run shows only 8 files using capabilities on my fedora
35 distro (14 years after the feature was introduced to the linux
kernel).

  $ getcap -r /
  /usr/bin/arping = cap_net_raw+p
  /usr/bin/clockdiff = cap_net_raw+p
  /usr/bin/gnome-keyring-daemon = cap_ipc_lock+ep
  /usr/bin/gnome-shell = cap_sys_nice+ep
  /usr/bin/newgidmap = cap_setgid+ep
  /usr/bin/newuidmap = cap_setuid+ep
  /usr/sbin/mtr-packet = cap_net_raw+ep
  /usr/sbin/suexec = cap_setgid,cap_setuid+ep

* src/dircolors.hin: Set "CAPABILITY" to "00", to indicate unused.
* src/ls.c: Set the default C_CAP color to not colored.
* NEWS: Mention the change in behavior.

NEWS
src/dircolors.hin
src/ls.c

diff --git a/NEWS b/NEWS
index 6d6f204eee18005de57634be4f9b96f6dd94420e..2041b8a6da16cd8793f68f2fb41d009141a02ff9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -72,6 +72,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   seek_bytes are therefore obsolescent and are no longer documented,
   though they still work.
 
+  ls no longer colors files with capabilities by default, as file-based
+  capabilties are very rarely used, and lookup increases processing per file by
+  about 30%.  It's best to use getcap [-r] to identify files with capabilities.
+
   ls no longer tries to automount files, reverting to the behavior
   before the statx() call was introduced in coreutils-8.32.
 
index 6dc5a2d741782824364ab156523a82ee66bbf9ef..f117359580b86afde95b4f7af86a9a781ef20580 100644 (file)
@@ -65,7 +65,7 @@ ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file ...
 MISSING 00      # ... and the files they point to
 SETUID 37;41   # file that is setuid (u+s)
 SETGID 30;43   # file that is setgid (g+s)
-CAPABILITY 30;41       # file with capability
+CAPABILITY 00  # file with capability (very expensive to lookup)
 STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
 OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
 STICKY 37;44   # dir with the sticky bit set (+t) and not other-writable
index 255789061b20fdf667d7b8a7fa93a4a76fad9766..d15a10367720c45baa8be0a7891513bb125ff997 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -638,7 +638,7 @@ static struct bin_str color_indicator[] =
     { LEN_STR_PAIR ("37;44") },                /* st: sticky: black on blue */
     { LEN_STR_PAIR ("34;42") },                /* ow: other-writable: blue on green */
     { LEN_STR_PAIR ("30;42") },                /* tw: ow w/ sticky: black on green */
-    { LEN_STR_PAIR ("30;41") },                /* ca: black on red */
+    { 0, NULL },                       /* ca: disabled by default */
     { 0, NULL },                       /* mh: disabled by default */
     { LEN_STR_PAIR ("\033[K") },       /* cl: clear to end of line */
   };