[DTrace-devel] [PATCH v3 4/9] build: avoid needless re-executions

Nick Alcock nick.alcock at oracle.com
Fri Jan 26 13:58:44 UTC 2024


The USER_UID and DUMPCAP_GROUP variables are recursively assigned, but
contain shell execution. It's not terribly expensive execution, but these
variables are substituted into every compile line, so they're executed
dozens of times, even though their values will never change.

Move them into immediate assignment (which makes DUMPCAP_GROUP a bit more
complex to allow it to be overridden).

This speeds up near-do-nothing runs like 'make help' so that they take only
about 1/10s now, which is acceptably fast.

Signed-off-by: Nick Alcock <nick.alcock at oracle.com>
---
 GNUmakefile | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/GNUmakefile b/GNUmakefile
index 723c81033992..9a2078593cce 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -43,7 +43,7 @@ BPFCFLAGS ?= -O2 -Wall -Wno-unknown-pragmas
 export BPFLD = bpf-unknown-none-ld
 
 # The first non-system uid on this system.
-USER_UID=$(shell grep '^UID_MIN' /etc/login.defs | awk '{print $$2;}')
+USER_UID := $(shell grep '^UID_MIN' /etc/login.defs | awk '{print $$2;}')
 
 # A uid suitable for unprivileged execution.
 UNPRIV_UID ?= -3
@@ -51,7 +51,10 @@ UNPRIV_UID ?= -3
 # The group one must run as to invoke dumpcap: by default the group of
 # the dumpcap binary.  If dumpcap is owned by root, use the same gid as
 # the UNPRIV_UID unless otherwise overridden.
-DUMPCAP_GROUP ?= $(filter-out root,$(shell stat -c %G /usr/sbin/dumpcap /usr/bin/dumpcap 2>/dev/null | head -1))
+# (We avoid ?= here to avoid rerunning the stat over and over again.)
+ifeq ($(origin DUMPCAP_GROUP), undefined)
+DUMPCAP_GROUP := $(filter-out root,$(shell stat -c %G /usr/sbin/dumpcap /usr/bin/dumpcap 2>/dev/null | head -1))
+endif
 
 # Unwritable but readable directory suitable for overriding as the $HOME of
 # unprivileged processes.
-- 
2.43.0.272.gce700b77fd




More information about the DTrace-devel mailing list