From 6b5134770d35b045e5a9219bf4a216324e0113d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?=
Date: Sun, 3 Apr 2022 21:42:42 +0100 Subject: [PATCH] ls: avoid expensive capability lookup by default 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 6d6f204eee..2041b8a6da 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 6dc5a2d741..f117359580 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 255789061b..d15a103677 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.47.2