]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
consolidate missing C library functions into utils.h
authorDwight Engen <dwight.engen@oracle.com>
Thu, 23 May 2013 19:39:03 +0000 (15:39 -0400)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Sat, 25 May 2013 00:16:20 +0000 (19:16 -0500)
This fixes the build of lxccontainer.c on systems that have __NR_setns
but not HAVE_SETNS.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
src/lxc/attach.c
src/lxc/bdev.c
src/lxc/lxccontainer.c
src/lxc/parse.c
src/lxc/utils.h

index a33d24f89d18ccaae43d4f5c3e2734584fbdb9a2..5061b93abaec8f649f7a6737d8796e38b15799b3 100644 (file)
 #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));
index fcde16b51485b56e7c623cac06098a7301f55139..a0ce5f52244135842f9d911e21fcb15a577611d6 100644 (file)
 #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
index 2934afa51647f8f43fc97595fac491f7e1c9fc83..60b77b92d62bd5ef05116a6325ea3f7e454fb28a 100644 (file)
@@ -35,6 +35,7 @@
 #include "version.h"
 #include "log.h"
 #include "bdev.h"
+#include "utils.h"
 #include <lxc/utils.h>
 #include <lxc/monitor.h>
 #include <sched.h>
 
 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
index 4504ec292030d88e88761852581972440a4c1dc7..6c2ed5a6cc69bb54d77f150e43d9cac08c206d19 100644 (file)
 
 #include "parse.h"
 #include "config.h"
+#include "utils.h"
 #include <lxc/log.h>
 
-/* 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.
index d1242b1f55e987678c4e09cabb8f200b109a3961..fbfe5d3a04668d14cdd017d6fd85847f3e38d2d9 100644 (file)
@@ -23,7 +23,9 @@
 #ifndef _utils_h
 #define _utils_h
 
+#include <errno.h>
 #include <sys/types.h>
+#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.