]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Workaround missing functions in other libc
authorStéphane Graber <stgraber@ubuntu.com>
Thu, 3 Jan 2013 17:24:14 +0000 (12:24 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 9 Jan 2013 15:13:45 +0000 (10:13 -0500)
Some libc implementation (bionic) is lacking some of the syscall functions
that are present in the glibc.

For those, detect at build time the they are missing and implement a minimal
syscall() wrapper that will essentially give the same result as the glibc
function.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
configure.ac
src/lxc/attach.c
src/lxc/conf.c

index 51a7749bd9eb1e5b7d7e13511f88aef64577e390..d6ecc909b46cb180f1e9cb303e6d11466d678b14 100644 (file)
@@ -223,6 +223,9 @@ AC_CHECK_DECLS([PR_CAPBSET_DROP], [], [], [#include <sys/prctl.h>])
 # Check for some headers
 AC_CHECK_HEADERS([sys/signalfd.h pty.h sys/capability.h sys/personality.h])
 
+# Check for some syscalls functions
+AC_CHECK_FUNCS([setns pivot_root sethostname unshare])
+
 # Check for some functions
 AC_CHECK_FUNCS([openpty])
 AC_CHECK_FUNCS([getline],
index 9b7efbc0b7f4bb798e530af4ef3a60bd6c65a428..b86d2f46a0e5b225456b79cea376459c8d0a2133 100644 (file)
 
 lxc_log_define(lxc_attach, lxc);
 
-int setns(int fd, int nstype)
+/* Define setns() if missing from the C library */
+#ifndef HAVE_SETNS
+static int setns(int fd, int nstype)
 {
-#ifndef __NR_setns
-       errno = ENOSYS;
-       return -1;
+#ifdef __NR_setns
+return syscall(__NR_setns, fd, nstype);
 #else
-       return syscall(__NR_setns, fd, nstype);
+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
index 673048d7f3863afd9796839a8b920f9a7a76d77d..7428b0a355efec26a261be3cbcc347be8cab9511 100644 (file)
@@ -31,6 +31,7 @@
 #include <mntent.h>
 #include <unistd.h>
 #include <sys/wait.h>
+#include <sys/syscall.h>
 
 #if HAVE_PTY_H
 #include <pty.h>
@@ -132,11 +133,37 @@ lxc_log_define(lxc_conf, lxc);
 #define LO_FLAGS_AUTOCLEAR 4
 #endif
 
+/* Define pivot_root() if missing from the C library */
+#ifndef HAVE_PIVOT_ROOT
+static int pivot_root(const char * new_root, const char * put_old)
+{
+#ifdef __NR_pivot_root
+return syscall(__NR_pivot_root, new_root, put_old);
+#else
+errno = ENOSYS;
+return -1;
+#endif
+}
+#else
+extern int pivot_root(const char * new_root, const char * put_old);
+#endif
+
+/* Define sethostname() if missing from the C library */
+#ifndef HAVE_SETHOSTNAME
+static int sethostname(const char * name, size_t len)
+{
+#ifdef __NR_sethostname
+return syscall(__NR_sethostname, name, len);
+#else
+errno = ENOSYS;
+return -1;
+#endif
+}
+#endif
+
 char *lxchook_names[NUM_LXC_HOOKS] = {
        "pre-start", "pre-mount", "mount", "start", "post-stop" };
 
-extern int pivot_root(const char * new_root, const char * put_old);
-
 typedef int (*instanciate_cb)(struct lxc_handler *, struct lxc_netdev *);
 
 struct mount_opt {