Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / util / cap.c
blobc3ba841bbf3772bffabde9e5d4f0060a8daa9dfa
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Capability utilities
4 */
6 #ifdef HAVE_LIBCAP_SUPPORT
8 #include "cap.h"
9 #include <stdbool.h>
10 #include <sys/capability.h>
12 bool perf_cap__capable(cap_value_t cap)
14 cap_flag_value_t val;
15 cap_t caps = cap_get_proc();
17 if (!caps)
18 return false;
20 if (cap_get_flag(caps, cap, CAP_EFFECTIVE, &val) != 0)
21 val = CAP_CLEAR;
23 if (cap_free(caps) != 0)
24 return false;
26 return val == CAP_SET;
29 #endif /* HAVE_LIBCAP_SUPPORT */