]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/caps.h
Merge git://github.com/lxc/lxc
[mirror_lxc.git] / src / lxc / caps.h
CommitLineData
b3357a6f
DL
1/*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
495d2046
SG
23#include "config.h"
24
b3357a6f
DL
25#ifndef _caps_h
26#define _caps_h
7d40e69b 27
495d2046 28#if HAVE_SYS_CAPABILITY_H
05cda563 29extern int lxc_caps_reset(void);
7d40e69b
DL
30extern int lxc_caps_down(void);
31extern int lxc_caps_up(void);
32extern int lxc_caps_init(void);
4a2ca8b2 33extern int lxc_caps_check(void);
7d40e69b 34
20d81659 35extern int lxc_caps_last_cap(void);
495d2046
SG
36#else
37static inline int lxc_caps_reset(void) {
38 return 0;
39}
40static inline int lxc_caps_down(void) {
41 return 0;
42}
43static inline int lxc_caps_up(void) {
44 return 0;
45}
46static inline int lxc_caps_init(void) {
47 return 0;
48}
49static inline int lxc_caps_check(void) {
50 return 1;
51}
52
53static inline int lxc_caps_last_cap(void) {
54 return 0;
55}
56#endif
20d81659 57
7d40e69b
DL
58#define lxc_priv(__lxc_function) \
59 ({ \
596a818d 60 __label__ out; \
c4b79084 61 int __ret, __ret2, ___errno = 0; \
7d40e69b
DL
62 __ret = lxc_caps_up(); \
63 if (__ret) \
596a818d 64 goto out; \
7d40e69b
DL
65 __ret = __lxc_function; \
66 if (__ret) \
c4b79084 67 ___errno = errno; \
7d40e69b 68 __ret2 = lxc_caps_down(); \
c4b79084 69 out: __ret ? errno = ___errno,__ret : __ret2; \
7d40e69b
DL
70 })
71
596a818d 72#define lxc_unpriv(__lxc_function) \
7d40e69b 73 ({ \
596a818d 74 __label__ out; \
c4b79084 75 int __ret, __ret2, ___errno = 0; \
7d40e69b
DL
76 __ret = lxc_caps_down(); \
77 if (__ret) \
596a818d 78 goto out; \
7d40e69b
DL
79 __ret = __lxc_function; \
80 if (__ret) \
c4b79084 81 ___errno = errno; \
7d40e69b 82 __ret2 = lxc_caps_up(); \
c4b79084 83 out: __ret ? errno = ___errno,__ret : __ret2; \
7d40e69b 84 })
b3357a6f 85#endif