Skip to content

Commit

Permalink
build: avoid needless re-executions
Browse files Browse the repository at this point in the history
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@oracle.com>
Reviewed-by: Kris Van Hees <kris.van.hees@oracle.com>
  • Loading branch information
nickalcock authored and kvanhees committed Feb 7, 2024
1 parent d73277c commit f454b37
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ 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

# 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.
Expand Down

0 comments on commit f454b37

Please sign in to comment.