############################################################
+exe = executable(
+ 'test_cap',
+ 'tests/helpers/test_cap.c',
+ include_directories : includes,
+ dependencies : [lib_cap_ng],
+ build_by_default: program_tests)
+exes += exe
+
exe = executable(
'test_mbsencode',
'tests/helpers/test_mbsencode.c',
# helpers
TS_HELPER_BYTESWAP="${ts_helpersdir}test_byteswap"
TS_HELPER_CPUSET="${ts_helpersdir}test_cpuset"
+TS_HELPER_CAP="${ts_helpersdir}test_cap"
TS_HELPER_DMESG="${ts_helpersdir}test_dmesg"
TS_HELPER_ENOSYS="${ts_helpersdir}test_enosys"
TS_HELPER_ISLOCAL="${ts_helpersdir}test_islocal"
# ts_skip_capability cap_wake_alarm
#
function ts_skip_capability {
- local self=$$
- local cap=$1
+ ts_check_prog "$TS_HELPER_CAP"
- # On Fedora, libcap package provides getpcaps command.
- ts_check_prog "getpcaps"
-
- local caps=$(getpcaps "$self" 2>&1)
- if [[ "$caps" == "${self}: =ep" || "$caps" == 'Capabilities for `'"${self}': =ep" ]]; then
- return 0
- fi
-
- if [[ "$caps" =~ .*${cap}.* ]]; then
- return 0
+ if ! "$TS_HELPER_CAP" "$1"; then
+ ts_skip "no capability: $1"
fi
-
- ts_skip "no capability: ${cap}"
}
function ts_skip_qemu_user {
check_PROGRAMS += test_enosys
test_enosys_SOURCES = tests/helpers/test_enosys.c
endif
+
+if HAVE_CAP_NG
+check_PROGRAMS += test_cap
+test_cap_SOURCES = tests/helpers/test_cap.c
+test_cap_LDADD = -lcap-ng
+endif
--- /dev/null
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2023 Thomas Weißschuh <thomas@t-8ch.de>
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <cap-ng.h>
+
+int main(int argc, char **argv)
+{
+ int cap, r;
+
+ if (argc != 2)
+ return EXIT_FAILURE;
+
+ cap = capng_name_to_capability(argv[1]);
+ if (cap < 0) {
+ fprintf(stderr, "capng_name_to_capability(%s) failed\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ r = capng_get_caps_process();
+ if (r) {
+ fprintf(stderr, "capng_get_caps_process() failed\n");
+ return EXIT_FAILURE;
+ }
+
+ r = capng_have_capability(CAPNG_EFFECTIVE, cap);
+ return r ? EXIT_SUCCESS : EXIT_FAILURE;
+}
. "$TS_TOPDIR"/functions.sh
ts_init "$*"
-ts_skip_capability cap_wake_alarm
+ts_skip_capability WAKE_ALARM
ts_check_test_command "$TS_CMD_LSFD"
ts_check_test_command "$TS_HELPER_MKFDS"