This macro is a helper to call a function into a [un]privilegied section.

Signed-off-by: Daniel Lezcano <dlezc...@fr.ibm.com>
---
 src/lxc/caps.h |   33 ++++++++++++++++++++++++++++++---
 1 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/src/lxc/caps.h b/src/lxc/caps.h
index bdc248b..6b27648 100644
--- a/src/lxc/caps.h
+++ b/src/lxc/caps.h
@@ -22,7 +22,34 @@
  */
 #ifndef _caps_h
 #define _caps_h
-int lxc_caps_down(void);
-int lxc_caps_up(void);
-int lxc_caps_init(void);
+
+extern int lxc_caps_down(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
-- 
1.7.0.4


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to