From 7cc750ce8df4b4963ebd9d4eede44959aafb9c77 Mon Sep 17 00:00:00 2001 From: phintuka Date: Mon, 28 Feb 2011 13:11:54 +0000 Subject: Added tools/sys_cap.h : check for CAP_SYS_NICE capability --- tools/sys_cap.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tools/sys_cap.h 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 +#include +#ifdef HAVE_LIBCAP +# include +#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_ -- cgit v1.2.3