]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/utils.h
lxc-stop: use api, remove lxc_shutdown, extend lxc-stop functionality
[mirror_lxc.git] / src / lxc / utils.h
CommitLineData
0ad19a3f 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>
0ad19a3f 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 */
23#ifndef _utils_h
24#define _utils_h
25
6a44839f 26#include <errno.h>
c797a220 27#include <sys/types.h>
6a44839f 28#include "config.h"
c797a220 29
6e4bb2e0 30extern int lxc_setup_fs(void);
7c11d57a 31extern int get_u16(unsigned short *val, const char *arg, int base);
1b09f2c0 32extern int mkdir_p(const char *dir, mode_t mode);
2a59a681
SH
33/*
34 * Return a newly allocated buffer containing the default container
35 * path. Caller must free this buffer.
36 */
67e571de 37extern const char *default_lxc_path(void);
31a95fec
SH
38extern const char *default_zfs_root(void);
39extern const char *default_lvm_vg(void);
307cf2a6 40
6a44839f
DE
41/* Define getline() if missing from the C library */
42#ifndef HAVE_GETLINE
43#ifdef HAVE_FGETLN
44#include <../include/getline.h>
45#endif
46#endif
47
48/* Define setns() if missing from the C library */
49#ifndef HAVE_SETNS
50static inline int setns(int fd, int nstype)
51{
52#ifdef __NR_setns
53 return syscall(__NR_setns, fd, nstype);
54#else
55 errno = ENOSYS;
56 return -1;
57#endif
58}
59#endif
60
61/* Define unshare() if missing from the C library */
62#ifndef HAVE_UNSHARE
63static inline int unshare(int flags)
64{
65#ifdef __NR_unshare
66 return syscall(__NR_unshare, flags);
67#else
68 errno = ENOSYS;
69 return -1;
70#endif
71}
72#else
73int unshare(int);
74#endif
75
e51d4895
DE
76/**
77 * BUILD_BUG_ON - break compile if a condition is true.
78 * @condition: the condition which the compiler should know is false.
79 *
80 * If you have some code which relies on certain constants being equal, or
81 * other compile-time-evaluated condition, you should use BUILD_BUG_ON to
82 * detect if someone changes it.
83 *
84 * The implementation uses gcc's reluctance to create a negative array, but
85 * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments
86 * to inline functions). So as a fallback we use the optimizer; if it can't
87 * prove the condition is false, it will cause a link error on the undefined
88 * "__build_bug_on_failed". This error message can be harder to track down
89 * though, hence the two different methods.
90 */
91#ifndef __OPTIMIZE__
92#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
93#else
94extern int __build_bug_on_failed;
95#define BUILD_BUG_ON(condition) \
96 do { \
97 ((void)sizeof(char[1 - 2*!!(condition)])); \
98 if (condition) __build_bug_on_failed = 1; \
99 } while(0)
100#endif
101
9be53773
SH
102/*
103 * wait on a child we forked
104 */
105extern int wait_for_pid(pid_t pid);
c797a220 106extern int lxc_wait_for_pid_status(pid_t pid);
9be53773 107
92f023dc
CS
108/* send and receive buffers completely */
109extern int lxc_write_nointr(int fd, const void* buf, size_t count);
110extern int lxc_read_nointr(int fd, void* buf, size_t count);
111extern int lxc_read_nointr_expect(int fd, void* buf, size_t count, const void* expected_buf);
112
307cf2a6 113#endif