Commit 7d40e69b by Daniel Lezcano

add a macro to wrap a privilegied function

This macro is a helper to call a function into a [un]privilegied section. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent b3357a6f
...@@ -22,7 +22,34 @@ ...@@ -22,7 +22,34 @@
*/ */
#ifndef _caps_h #ifndef _caps_h
#define _caps_h #define _caps_h
int lxc_caps_down(void);
int lxc_caps_up(void); extern int lxc_caps_down(void);
int lxc_caps_init(void); extern int lxc_caps_up(void);
extern int lxc_caps_init(void);
#define lxc_priv(__lxc_function) \
({ \
int __ret, __ret2, __errno = 0; \
__ret = lxc_caps_up(); \
if (__ret) \
goto __out; \
__ret = __lxc_function; \
if (__ret) \
__errno = errno; \
__ret2 = lxc_caps_down(); \
__out: __ret ? errno = __errno,__ret : __ret2; \
})
#define lxc_unpriv(__lxc_function) \
({ \
int __ret, __ret2, __errno = 0; \
__ret = lxc_caps_down(); \
if (__ret) \
goto __out; \
__ret = __lxc_function; \
if (__ret) \
__errno = errno; \
__ret2 = lxc_caps_up(); \
__out: __ret ? errno = __errno,__ret : __ret2; \
})
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment