#include <errno.h>
#include <stdlib.h>
#include <sys/wait.h>
+#include <unistd.h>
+#include <sys/syscall.h>
#if HAVE_SETRLIMIT
# include <sys/time.h>
# include <sys/resource.h>
VIR_LOG_INIT("util.process");
+/*
+ * Workaround older glibc. While kernel may support the setns
+ * syscall, the glibc wrapper might not exist. If that's the
+ * case, use our own.
+ */
+#ifndef __NR_setns
+# if defined(__x86_64__)
+# define __NR_setns 308
+# elif defined(__i386__)
+# define __NR_setns 346
+# else
+# error "__NR_setns is not defined"
+# endif
+#endif
+
+#ifndef HAVE_SETNS
+static inline int setns(int fd, int nstype)
+{
+ return syscall(__NR_setns, fd, nstype);
+}
+#endif /* HAVE_SETNS */
+
/**
* virProcessTranslateStatus:
* @status: child exit status to translate
#endif /* HAVE_SCHED_GETAFFINITY */
-#if HAVE_SETNS
int virProcessGetNamespaces(pid_t pid,
size_t *nfdlist,
int **fdlist)
}
return 0;
}
-#else /* ! HAVE_SETNS */
-int virProcessGetNamespaces(pid_t pid,
- size_t *nfdlist ATTRIBUTE_UNUSED,
- int **fdlist ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENOSYS,
- _("Cannot get namespaces for %llu"),
- (unsigned long long)pid);
- return -1;
-}
-
-
-int virProcessSetNamespaces(size_t nfdlist ATTRIBUTE_UNUSED,
- int *fdlist ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENOSYS, "%s",
- _("Cannot set namespaces"));
- return -1;
-}
-#endif /* ! HAVE_SETNS */
#if HAVE_PRLIMIT
static int
#endif
-#ifdef HAVE_SETNS
static int virProcessNamespaceHelper(int errfd,
pid_t pid,
virProcessNamespaceCallback cb,
VIR_FORCE_CLOSE(errfd[1]);
return ret;
}
-#else /* !HAVE_SETNS */
-int
-virProcessRunInMountNamespace(pid_t pid ATTRIBUTE_UNUSED,
- virProcessNamespaceCallback cb ATTRIBUTE_UNUSED,
- void *opaque ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENOSYS, "%s",
- _("Mount namespaces are not available on this platform"));
- return -1;
-}
-#endif
/**