diff --git a/src/lxc/attach.c b/src/lxc/attach.c index a33d24f89..5061b93ab 100644 --- a/src/lxc/attach.c +++ b/src/lxc/attach.c @@ -46,42 +46,10 @@ #include "caps.h" #include "config.h" #include "apparmor.h" +#include "utils.h" lxc_log_define(lxc_attach, lxc); -/* Define setns() if missing from the C library */ -#ifndef HAVE_SETNS -static int setns(int fd, int nstype) -{ -#ifdef __NR_setns -return syscall(__NR_setns, fd, nstype); -#else -errno = ENOSYS; -return -1; -#endif -} -#endif - -/* Define unshare() if missing from the C library */ -#ifndef HAVE_UNSHARE -static int unshare(int flags) -{ -#ifdef __NR_unshare -return syscall(__NR_unshare, flags); -#else -errno = ENOSYS; -return -1; -#endif -} -#endif - -/* Define getline() if missing from the C library */ -#ifndef HAVE_GETLINE -#ifdef HAVE_FGETLN -#include <../include/getline.h> -#endif -#endif - struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid) { struct lxc_proc_context_info *info = calloc(1, sizeof(*info)); diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c index fcde16b51..a0ce5f522 100644 --- a/src/lxc/bdev.c +++ b/src/lxc/bdev.c @@ -44,23 +44,10 @@ #include "utils.h" #include "namespace.h" #include "parse.h" +#include "utils.h" lxc_log_define(bdev, lxc); -/* Define unshare() if missing from the C library */ -/* this is also in attach.c and lxccontainer.c: commonize it in utils.c */ -#ifndef HAVE_UNSHARE -static int unshare(int flags) -{ -#ifdef __NR_unshare -return syscall(__NR_unshare, flags); -#else -errno = ENOSYS; -return -1; -#endif -} -#endif - static int do_rsync(const char *src, const char *dest) { // call out to rsync diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 2934afa51..60b77b92d 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -35,6 +35,7 @@ #include "version.h" #include "log.h" #include "bdev.h" +#include "utils.h" #include #include #include @@ -44,22 +45,6 @@ static pthread_mutex_t thread_mutex = PTHREAD_MUTEX_INITIALIZER; -/* Define unshare() if missing from the C library */ -/* this is also in attach.c and lxccontainer.c: commonize it in utils.c */ -#ifndef HAVE_UNSHARE -static int unshare(int flags) -{ -#ifdef __NR_unshare - return syscall(__NR_unshare, flags); -#else - errno = ENOSYS; - return -1; -#endif -} -#else -int unshare(int); -#endif - lxc_log_define(lxc_container, lxc); /* LOCKING diff --git a/src/lxc/parse.c b/src/lxc/parse.c index 4504ec292..6c2ed5a6c 100644 --- a/src/lxc/parse.c +++ b/src/lxc/parse.c @@ -30,15 +30,9 @@ #include "parse.h" #include "config.h" +#include "utils.h" #include -/* Define getline() if missing from the C library */ -#ifndef HAVE_GETLINE -#ifdef HAVE_FGETLN -#include <../include/getline.h> -#endif -#endif - /* Workaround for the broken signature of alphasort() in bionic. This was fixed upstream in 40e467ec668b59be25491bd44bf348a884d6a68d so the workaround can probably be dropped with the next version of the Android NDK. diff --git a/src/lxc/utils.h b/src/lxc/utils.h index d1242b1f5..fbfe5d3a0 100644 --- a/src/lxc/utils.h +++ b/src/lxc/utils.h @@ -23,7 +23,9 @@ #ifndef _utils_h #define _utils_h +#include #include +#include "config.h" extern int lxc_setup_fs(void); extern int get_u16(unsigned short *val, const char *arg, int base); @@ -36,6 +38,41 @@ extern const char *default_lxc_path(void); extern const char *default_zfs_root(void); extern const char *default_lvm_vg(void); +/* Define getline() if missing from the C library */ +#ifndef HAVE_GETLINE +#ifdef HAVE_FGETLN +#include <../include/getline.h> +#endif +#endif + +/* Define setns() if missing from the C library */ +#ifndef HAVE_SETNS +static inline int setns(int fd, int nstype) +{ +#ifdef __NR_setns + return syscall(__NR_setns, fd, nstype); +#else + errno = ENOSYS; + return -1; +#endif +} +#endif + +/* Define unshare() if missing from the C library */ +#ifndef HAVE_UNSHARE +static inline int unshare(int flags) +{ +#ifdef __NR_unshare + return syscall(__NR_unshare, flags); +#else + errno = ENOSYS; + return -1; +#endif +} +#else +int unshare(int); +#endif + /** * BUILD_BUG_ON - break compile if a condition is true. * @condition: the condition which the compiler should know is false.