Add setcap helper

This will setcap the perf stats helper appropriately when installed by
root. It wont fail if you try an unprivileged install, but it means the
perf stats helper also wont work.

Also check that we have the CAP_PERFMON capability in the kernel as this
isnt supported on ubuntu 20. On this platform packagers should setuid as
root.
pull/877/head
Kurt Kartaltepe 1 year ago
parent 96b605ce88
commit 5db1bc427f

@ -0,0 +1,19 @@
#!/bin/sh
# Simple post-install script to setcap the metrics helper
setcap="${1?SETCAP_UNSET}"
bindir="${2?BINDIR_UNSET}"
exe="${3?EXE_UNSET}"
exe_fullpath="$MESON_INSTALL_DESTDIR_PREFIX/$bindir/$exe"
euid=$(id -u)
if [ $euid != "0" ]; then
echo "Warning: installed by unprivileged user, could not setcap $exe_fullpath" >&2
exit 0
fi
if ! capsh --supports=CAP_PERFMON; then
echo "Warning: build environment does not support CAP_PERFMON, you must setuid root on this platform" >&2
exit 0
fi
"$setcap" cap_perfmon=+ep "$exe_fullpath"

@ -257,14 +257,24 @@ endif
if get_option('mango_intel_stats').enabled() and is_unixy
drm_dep = cc.find_library('libdrm')
warning('The mango_intel_stats binary must have CAP_PERFMON or setuid to be useful')
warning('You must do this manually post-install: setcap cap_perfmon=+ep /path/to/mango_intel_stats')
setcap = find_program('setcap', '/usr/sbin/setcap', '/sbin/setcap', required : false)
mangointel = executable(
'mango_intel_stats',
files('app/intel.cpp'),
install : true,
dependencies : [drm_dep, json_dep],
)
if setcap.found()
meson.add_install_script('app/setcap-helper.sh',
setcap.full_path(),
get_option('bindir'),
mangointel.name(),
)
else
warning('The mango_intel_stats binary must have CAP_PERFMON or setuid to be useful')
warning('Install setcap to have CAP_PERFMON set automatically, or')
warning('You must do this manually post-install: setcap cap_perfmon=+ep /path/to/mango_intel_stats')
endif
endif
if get_option('mangoapp_layer')

Loading…
Cancel
Save