]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/caps.h
ovl_rsync: make sure to umount
[mirror_lxc.git] / src / lxc / caps.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 #include "config.h"
24
25 #ifndef __LXC_CAPS_H
26 #define __LXC_CAPS_H
27
28 #if HAVE_SYS_CAPABILITY_H
29 extern int lxc_caps_down(void);
30 extern int lxc_caps_up(void);
31 extern int lxc_caps_init(void);
32
33 extern int lxc_caps_last_cap(void);
34 #else
35 static inline int lxc_caps_down(void) {
36 return 0;
37 }
38 static inline int lxc_caps_up(void) {
39 return 0;
40 }
41 static inline int lxc_caps_init(void) {
42 return 0;
43 }
44
45 static inline int lxc_caps_last_cap(void) {
46 return 0;
47 }
48 #endif
49
50 #define lxc_priv(__lxc_function) \
51 ({ \
52 __label__ out; \
53 int __ret, __ret2, ___errno = 0; \
54 __ret = lxc_caps_up(); \
55 if (__ret) \
56 goto out; \
57 __ret = __lxc_function; \
58 if (__ret) \
59 ___errno = errno; \
60 __ret2 = lxc_caps_down(); \
61 out: __ret ? errno = ___errno,__ret : __ret2; \
62 })
63
64 #define lxc_unpriv(__lxc_function) \
65 ({ \
66 __label__ out; \
67 int __ret, __ret2, ___errno = 0; \
68 __ret = lxc_caps_down(); \
69 if (__ret) \
70 goto out; \
71 __ret = __lxc_function; \
72 if (__ret) \
73 ___errno = errno; \
74 __ret2 = lxc_caps_up(); \
75 out: __ret ? errno = ___errno,__ret : __ret2; \
76 })
77 #endif