blob: c3ba841bbf3772bffabde9e5d4f0060a8daa9dfa [file] [log] [blame]
Igor Lubashevc22e1502019-08-07 10:44:14 -04001// 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
12bool 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 */