diff options
-rw-r--r-- | tools/sys_cap.h | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/sys_cap.h b/tools/sys_cap.h new file mode 100644 index 00000000..eb7b8805 --- /dev/null +++ b/tools/sys_cap.h @@ -0,0 +1,56 @@ +/* + * sys_cap.h: + * + * See the main source file 'xineliboutput.c' for copyright information and + * how to reach the author. + * + * $Id: sys_cap.h,v 1.1 2011-02-28 13:11:54 phintuka Exp $ + * + */ + +#ifndef _XINELIBOUTPUT_SYS_CAP_H_ +#define _XINELIBOUTPUT_SYS_CAP_H_ + +#include "features.h" + +#include <unistd.h> +#include <sys/types.h> +#ifdef HAVE_LIBCAP +# include <sys/capability.h> +#endif + +#ifdef HAVE_LIBCAP +static inline cap_flag_value_t get_cap_flag(cap_value_t cap) +{ + cap_flag_value_t val = CAP_CLEAR; + cap_t caps = cap_get_proc(); + + if (!caps) { + LOGDBG("cap_get_proc() failed"); + return val; + } + + if (cap_get_flag(caps, cap, CAP_EFFECTIVE, &val)) { + LOGDBG("cap_get_flag(CAP_SYS_NICE) failed"); + } + + cap_free(caps); + + return val; +} +#endif + +static inline int have_cap_sys_nice(void) +{ +#ifdef HAVE_LIBCAP + if (get_cap_flag(CAP_SYS_NICE) == CAP_SET) { + LOGDBG("Have CAP_SYS_NICE capability"); + return 1; + } + LOGDBG("No CAP_SYS_NICE capability"); +#endif + + return geteuid() == 0; +} + +#endif // _XINELIBOUTPUT_SYS_CAP_H_ |