]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/utils.h
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
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.
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.
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
27 #include <sys/types.h>
31 /* returns 1 on success, 0 if there were any failures */
32 extern int lxc_rmdir_onedev(char *path
);
33 extern int lxc_setup_fs(void);
34 extern int get_u16(unsigned short *val
, const char *arg
, int base
);
35 extern int mkdir_p(const char *dir
, mode_t mode
);
37 * Return a newly allocated buffer containing the default container
38 * path. Caller must free this buffer.
40 extern const char *default_lxc_path(void);
41 extern const char *default_zfs_root(void);
42 extern const char *default_lvm_vg(void);
44 /* Define getline() if missing from the C library */
47 #include <../include/getline.h>
51 /* Define setns() if missing from the C library */
53 static inline int setns(int fd
, int nstype
)
56 return syscall(__NR_setns
, fd
, nstype
);
64 /* Define unshare() if missing from the C library */
66 static inline int unshare(int flags
)
69 return syscall(__NR_unshare
, flags
);
79 /* Define signalfd() if missing from the C library */
80 #ifdef HAVE_SYS_SIGNALFD_H
81 # include <sys/signalfd.h>
83 /* assume kernel headers are too old */
85 struct signalfd_siginfo
106 # ifndef __NR_signalfd4
107 /* assume kernel headers are too old */
109 # define __NR_signalfd4 327
111 # define __NR_signalfd4 289
113 # define __NR_signalfd4 313
115 # define __NR_signalfd4 322
119 # ifndef __NR_signalfd
120 /* assume kernel headers are too old */
122 # define __NR_signalfd 321
124 # define __NR_signalfd 282
126 # define __NR_signalfd 305
128 # define __NR_signalfd 316
132 static inline int signalfd(int fd
, const sigset_t
*mask
, int flags
)
136 retval
= syscall (__NR_signalfd4
, fd
, mask
, _NSIG
/ 8, flags
);
137 if (errno
== ENOSYS
&& flags
== 0)
138 retval
= syscall (__NR_signalfd
, fd
, mask
, _NSIG
/ 8);
145 * BUILD_BUG_ON - break compile if a condition is true.
146 * @condition: the condition which the compiler should know is false.
148 * If you have some code which relies on certain constants being equal, or
149 * other compile-time-evaluated condition, you should use BUILD_BUG_ON to
150 * detect if someone changes it.
152 * The implementation uses gcc's reluctance to create a negative array, but
153 * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments
154 * to inline functions). So as a fallback we use the optimizer; if it can't
155 * prove the condition is false, it will cause a link error on the undefined
156 * "__build_bug_on_failed". This error message can be harder to track down
157 * though, hence the two different methods.
160 #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
162 extern int __build_bug_on_failed
;
163 #define BUILD_BUG_ON(condition) \
165 ((void)sizeof(char[1 - 2*!!(condition)])); \
166 if (condition) __build_bug_on_failed = 1; \
171 * wait on a child we forked
173 extern int wait_for_pid(pid_t pid
);
174 extern int lxc_wait_for_pid_status(pid_t pid
);
176 /* send and receive buffers completely */
177 extern ssize_t
lxc_write_nointr(int fd
, const void* buf
, size_t count
);
178 extern ssize_t
lxc_read_nointr(int fd
, void* buf
, size_t count
);
179 extern ssize_t
lxc_read_nointr_expect(int fd
, void* buf
, size_t count
, const void* expected_buf
);
181 #define SHA_DIGEST_LENGTH 20
182 extern int sha1sum_file(char *fnam
, unsigned char *md_value
);