1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Capability utilities 4 */ 5 6 #ifdef HAVE_LIBCAP_SUPPORT 7 8 #include "cap.h" 9 #include <stdbool.h> 10 #include <sys/capability.h> 11 12 bool perf_cap__capable(cap_value_t cap) 13 { 14 cap_flag_value_t val; 15 cap_t caps = cap_get_proc(); 16 17 if (!caps) 18 return false; 19 20 if (cap_get_flag(caps, cap, CAP_EFFECTIVE, &val) != 0) 21 val = CAP_CLEAR; 22 23 if (cap_free(caps) != 0) 24 return false; 25 26 return val == CAP_SET; 27 } 28 29 #endif /* HAVE_LIBCAP_SUPPORT */ 30