]>
Commit | Line | Data |
---|---|---|
b3357a6f DL |
1 | /* |
2 | * lxc: linux Container library | |
3 | * | |
4 | * (C) Copyright IBM Corp. 2007, 2008 | |
5 | * | |
6 | * Authors: | |
9afe19d6 | 7 | * Daniel Lezcano <daniel.lezcano at free.fr> |
b3357a6f DL |
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 | |
250b1eec | 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
b3357a6f | 22 | */ |
495d2046 SG |
23 | #include "config.h" |
24 | ||
f1a4a029 ÇO |
25 | #ifndef __LXC_CAPS_H |
26 | #define __LXC_CAPS_H | |
7d40e69b | 27 | |
495d2046 | 28 | #if HAVE_SYS_CAPABILITY_H |
05cda563 | 29 | extern int lxc_caps_reset(void); |
7d40e69b DL |
30 | extern int lxc_caps_down(void); |
31 | extern int lxc_caps_up(void); | |
32 | extern int lxc_caps_init(void); | |
33 | ||
20d81659 | 34 | extern int lxc_caps_last_cap(void); |
495d2046 SG |
35 | #else |
36 | static inline int lxc_caps_reset(void) { | |
37 | return 0; | |
38 | } | |
39 | static inline int lxc_caps_down(void) { | |
40 | return 0; | |
41 | } | |
42 | static inline int lxc_caps_up(void) { | |
43 | return 0; | |
44 | } | |
45 | static inline int lxc_caps_init(void) { | |
46 | return 0; | |
47 | } | |
495d2046 SG |
48 | |
49 | static inline int lxc_caps_last_cap(void) { | |
50 | return 0; | |
51 | } | |
52 | #endif | |
20d81659 | 53 | |
7d40e69b DL |
54 | #define lxc_priv(__lxc_function) \ |
55 | ({ \ | |
596a818d | 56 | __label__ out; \ |
c4b79084 | 57 | int __ret, __ret2, ___errno = 0; \ |
7d40e69b DL |
58 | __ret = lxc_caps_up(); \ |
59 | if (__ret) \ | |
596a818d | 60 | goto out; \ |
7d40e69b DL |
61 | __ret = __lxc_function; \ |
62 | if (__ret) \ | |
c4b79084 | 63 | ___errno = errno; \ |
7d40e69b | 64 | __ret2 = lxc_caps_down(); \ |
c4b79084 | 65 | out: __ret ? errno = ___errno,__ret : __ret2; \ |
7d40e69b DL |
66 | }) |
67 | ||
596a818d | 68 | #define lxc_unpriv(__lxc_function) \ |
7d40e69b | 69 | ({ \ |
596a818d | 70 | __label__ out; \ |
c4b79084 | 71 | int __ret, __ret2, ___errno = 0; \ |
7d40e69b DL |
72 | __ret = lxc_caps_down(); \ |
73 | if (__ret) \ | |
596a818d | 74 | goto out; \ |
7d40e69b DL |
75 | __ret = __lxc_function; \ |
76 | if (__ret) \ | |
c4b79084 | 77 | ___errno = errno; \ |
7d40e69b | 78 | __ret2 = lxc_caps_up(); \ |
c4b79084 | 79 | out: __ret ? errno = ___errno,__ret : __ret2; \ |
7d40e69b | 80 | }) |
b3357a6f | 81 | #endif |