[lxc-devel] [lxc/master] Fix tool_utils.c build when HAVE_SETNS is unset

pkun on Github lxc-bot at linuxcontainers.org
Thu Apr 26 11:06:07 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 622 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180426/9bf3812e/attachment.bin>
-------------- next part --------------
From 9051c53ee8a8b0a16d5d37853f3b977fc6ce9cd8 Mon Sep 17 00:00:00 2001
From: Serj Kalichev <serj.kalichev at gmail.com>
Date: Thu, 26 Apr 2018 13:44:20 +0300
Subject: [PATCH 1/2] Headers in src/tools dir use their own defines to disable
 double includes

---
 src/lxc/tools/arguments.h  | 6 +++---
 src/lxc/tools/tool_list.h  | 6 +++---
 src/lxc/tools/tool_utils.h | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/lxc/tools/arguments.h b/src/lxc/tools/arguments.h
index 15941bcc3..e4cf8fc0a 100644
--- a/src/lxc/tools/arguments.h
+++ b/src/lxc/tools/arguments.h
@@ -22,8 +22,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef __LXC_ARGUMENTS_H
-#define __LXC_ARGUMENTS_H
+#ifndef __LXC_TOOLS_ARGUMENTS_H
+#define __LXC_TOOLS_ARGUMENTS_H
 
 #include <getopt.h>
 #include <stdbool.h>
@@ -177,4 +177,4 @@ extern int lxc_arguments_str_to_int(struct lxc_arguments *args,
 
 extern bool lxc_setup_shared_ns(struct lxc_arguments *args, struct lxc_container *c);
 
-#endif /* __LXC_ARGUMENTS_H */
+#endif /* __LXC_TOOLS_ARGUMENTS_H */
diff --git a/src/lxc/tools/tool_list.h b/src/lxc/tools/tool_list.h
index 9858081ab..1dd82d28e 100644
--- a/src/lxc/tools/tool_list.h
+++ b/src/lxc/tools/tool_list.h
@@ -21,8 +21,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef __LXC_LIST_H
-#define __LXC_LIST_H
+#ifndef __LXC_TOOLS_LIST_H
+#define __LXC_TOOLS_LIST_H
 
 #include <stdio.h>
 
@@ -164,4 +164,4 @@ static inline size_t lxc_list_len(struct lxc_list *list)
 	 return i;
 }
 
-#endif /* __LXC_LIST_H */
+#endif /* __LXC_TOOLS_LIST_H */
diff --git a/src/lxc/tools/tool_utils.h b/src/lxc/tools/tool_utils.h
index 25f2dfd61..3e8fa93a2 100644
--- a/src/lxc/tools/tool_utils.h
+++ b/src/lxc/tools/tool_utils.h
@@ -17,8 +17,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifndef __LXC_UTILS_H
-#define __LXC_UTILS_H
+#ifndef __LXC_TOOLS_UTILS_H
+#define __LXC_TOOLS_UTILS_H
 
 /* Properly support loop devices on 32bit systems. */
 #define _FILE_OFFSET_BITS 64
@@ -201,4 +201,4 @@ int clone(int (*fn)(void *), void *child_stack,
 
 extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags);
 
-#endif /* __LXC_UTILS_H */
+#endif /* __LXC_TOOLS_UTILS_H */

From 6c4bec671b158b9e7a5177f572266928339097aa Mon Sep 17 00:00:00 2001
From: Serj Kalichev <serj.kalichev at gmail.com>
Date: Thu, 26 Apr 2018 13:50:57 +0300
Subject: [PATCH 2/2] Add inline setns() function to tool_utils.h. Without it
 tool_utils.c can't be build when HAVE_SETNS is unset.

---
 src/lxc/tools/tool_utils.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/lxc/tools/tool_utils.h b/src/lxc/tools/tool_utils.h
index 3e8fa93a2..0aae00e05 100644
--- a/src/lxc/tools/tool_utils.h
+++ b/src/lxc/tools/tool_utils.h
@@ -109,6 +109,37 @@ extern signed long lxc_config_parse_arch(const char *arch);
 extern int lxc_namespace_2_cloneflag(const char *namespace);
 extern int lxc_fill_namespace_flags(char *flaglist, int *flags);
 
+#if !defined(__NR_setns) && !defined(__NR_set_ns)
+	#if defined(__x86_64__)
+		#define __NR_setns 308
+	#elif defined(__i386__)
+		#define __NR_setns 346
+	#elif defined(__arm__)
+		#define __NR_setns 375
+	#elif defined(__aarch64__)
+		#define __NR_setns 375
+	#elif defined(__powerpc__)
+		#define __NR_setns 350
+	#elif defined(__s390__)
+		#define __NR_setns 339
+	#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);
+#elif defined(__NR_set_ns)
+	return syscall(__NR_set_ns, fd, nstype);
+#else
+	errno = ENOSYS;
+	return -1;
+#endif
+}
+#endif
+
 #if HAVE_LIBCAP
 #include <sys/capability.h>
 


More information about the lxc-devel mailing list