coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] ls: avoid expensive capability lookup by default


From: Pádraig Brady
Subject: [PATCH] ls: avoid expensive capability lookup by default
Date: Sun, 3 Apr 2022 22:10:51 +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              | 4 ++++
 src/dircolors.hin | 2 +-
 src/ls.c          | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 6d6f204ee..2041b8a6d 100644
--- 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.
 
diff --git a/src/dircolors.hin b/src/dircolors.hin
index 6dc5a2d74..f11735958 100644
--- a/src/dircolors.hin
+++ b/src/dircolors.hin
@@ -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
diff --git a/src/ls.c b/src/ls.c
index 255789061..d15a10367 100644
--- 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 */
   };
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]