[CRIU] [PATCH 3/3] crtools: no more linked with builtin syscall

Laurent Dufour ldufour at linux.vnet.ibm.com
Wed Feb 3 08:13:48 PST 2016


crtools binary is linked with the C library and could rely on all the
services this library is providing, including system calls.

Thus it doesn't need to be linked with the builtin system calls code
made for the parasite/restorer binaries.

This patch does:
 - remove the inclusion of syscall.h
 - replace all call to sys_<syscall>() by C library <syscall>()
 - replace unwrapped system calls by syscall(SYS_<syscall>,...)
 - fix the generated compiler's issues.

There should not be any functional changes. The only 'code' changes is
appearing in locks.h when futex is called through the C library, the
errno value is fetched from errno variable instead of the return
value.

Signed-off-by: Laurent Dufour <ldufour at linux.vnet.ibm.com>
---
 Makefile                     |  2 +-
 arch/aarch64/crtools.c       |  1 -
 arch/arm/crtools.c           |  1 -
 arch/ppc64/crtools.c         |  2 +-
 arch/ppc64/syscalls-ppc64.sh |  3 +++
 arch/x86/Makefile            |  3 +++
 arch/x86/crtools.c           |  1 -
 arch/x86/prlimit.c           |  1 -
 cr-check.c                   | 30 +++++++++++++++---------------
 cr-dump.c                    |  5 ++---
 cr-restore.c                 |  5 ++---
 cr-service.c                 |  1 +
 crtools.c                    |  2 +-
 file-ids.c                   |  1 -
 files-reg.c                  |  1 +
 fsnotify.c                   | 13 ++++++-------
 include/lock.h               | 14 +++++++++++++-
 include/sk-inet.h            |  5 ++++-
 include/sockets.h            |  1 +
 ipc_ns.c                     |  2 +-
 kcmp-ids.c                   | 11 ++++++-----
 kerndat.c                    |  8 ++++----
 mount.c                      |  1 +
 namespaces.c                 |  2 +-
 net.c                        |  1 -
 parasite-syscall.c           |  1 -
 pie/util-vdso.c              |  1 -
 pie/util.c                   | 18 ++++++++++++------
 pstree.c                     |  3 +++
 shmem.c                      |  2 +-
 sk-packet.c                  |  1 +
 sk-tcp.c                     |  2 ++
 sockets.c                    |  1 +
 sysctl.c                     |  1 +
 tty.c                        |  1 -
 tun.c                        |  1 +
 util.c                       |  1 +
 uts_ns.c                     |  2 +-
 38 files changed, 91 insertions(+), 61 deletions(-)

diff --git a/Makefile b/Makefile
index 8a0a23055767..a1617a3fac3e 100644
--- a/Makefile
+++ b/Makefile
@@ -245,7 +245,7 @@ PROGRAM-BUILTINS	+= built-in.o
 
 $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS): config
 
-$(PROGRAM): $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS)
+$(PROGRAM): $(ARCH-LIB) $(PROGRAM-BUILTINS)
 	$(E) "  LINK    " $@
 	$(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(LDFLAGS) $(GMONLDOPT) -rdynamic -o $@
 
diff --git a/arch/aarch64/crtools.c b/arch/aarch64/crtools.c
index 9dc2777efaff..5df7f1d5fd6c 100644
--- a/arch/aarch64/crtools.c
+++ b/arch/aarch64/crtools.c
@@ -12,7 +12,6 @@
 #include "protobuf/core.pb-c.h"
 #include "protobuf/creds.pb-c.h"
 #include "parasite-syscall.h"
-#include "syscall.h"
 #include "log.h"
 #include "util.h"
 #include "cpu.h"
diff --git a/arch/arm/crtools.c b/arch/arm/crtools.c
index 66405d27eb5f..8ce889463f6a 100644
--- a/arch/arm/crtools.c
+++ b/arch/arm/crtools.c
@@ -10,7 +10,6 @@
 #include "protobuf/core.pb-c.h"
 #include "protobuf/creds.pb-c.h"
 #include "parasite-syscall.h"
-#include "syscall.h"
 #include "log.h"
 #include "util.h"
 #include "cpu.h"
diff --git a/arch/ppc64/crtools.c b/arch/ppc64/crtools.c
index 99a0addfffb9..b1f4f6381591 100644
--- a/arch/ppc64/crtools.c
+++ b/arch/ppc64/crtools.c
@@ -2,6 +2,7 @@
 #include <unistd.h>
 #include <elf.h>
 #include <sys/user.h>
+#include <asm/unistd.h>
 
 #include "asm/types.h"
 #include "asm/fpu.h"
@@ -11,7 +12,6 @@
 #include "compiler.h"
 #include "ptrace.h"
 #include "parasite-syscall.h"
-#include "syscall.h"
 #include "log.h"
 #include "util.h"
 #include "cpu.h"
diff --git a/arch/ppc64/syscalls-ppc64.sh b/arch/ppc64/syscalls-ppc64.sh
index 22c81293dfff..871895efaf7a 100644
--- a/arch/ppc64/syscalls-ppc64.sh
+++ b/arch/ppc64/syscalls-ppc64.sh
@@ -19,6 +19,9 @@ gen_asm() {
 	echo "/* Autogenerated, don't edit */"	>  $protosout
 	echo "#ifndef $protosdef"		>> $protosout
 	echo "#define $protosdef"		>> $protosout
+	echo "#ifndef CR_NOGLIBC"		>> $protosout
+	echo "#error This file should only be used in the parasite code" >> $protosout
+	echo "#endif"				>> $protosout
 	echo "#include \"$prototypes\""		>> $protosout
 	echo "#include \"$codesinc\""		>> $protosout
 
diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 5ee12fc67876..c0c0f8035cab 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -52,6 +52,9 @@ $(obj)/$(SYS-PROTO): $(obj)/syscalls/$(SYS-DEF)
 	$(Q) echo "/* Autogenerated, don't edit */"							>  $@
 	$(Q) echo "#ifndef __ASM_CR_SYSCALL_PROTO_H__"							>> $@
 	$(Q) echo "#define __ASM_CR_SYSCALL_PROTO_H__"							>> $@
+	$(Q) echo "#ifndef CR_NOGLIBC"									>> $@
+	$(Q) echo "#error This file should only be used in the parasite code"				>> $@
+	$(Q) echo "#endif"										>> $@
 	$(Q) echo "#include \"syscall-codes.h\""							>> $@
 	$(Q) echo "#include \"syscall-types.h\""							>> $@
 ifneq ($(ARCH),x86_64)
diff --git a/arch/x86/crtools.c b/arch/x86/crtools.c
index 1d50c07faf8f..f713b0d3fd40 100644
--- a/arch/x86/crtools.c
+++ b/arch/x86/crtools.c
@@ -14,7 +14,6 @@
 #include "ptrace.h"
 #include "parasite-syscall.h"
 #include "restorer.h"
-#include "syscall.h"
 #include "log.h"
 #include "util.h"
 #include "cpu.h"
diff --git a/arch/x86/prlimit.c b/arch/x86/prlimit.c
index 596d6da20529..8bc4aba9f6a6 100644
--- a/arch/x86/prlimit.c
+++ b/arch/x86/prlimit.c
@@ -7,7 +7,6 @@
 #include "asm/prlimit.h"
 
 #include "compiler.h"
-#include "syscall.h"
 #include "config.h"
 
 #ifndef CONFIG_HAS_PRLIMIT
diff --git a/cr-check.c b/cr-check.c
index 6ecc99834f45..466cfd9eb38f 100644
--- a/cr-check.c
+++ b/cr-check.c
@@ -17,13 +17,16 @@
 #include <sys/ioctl.h>
 #include <termios.h>
 #include <sys/mman.h>
+#include <netinet/in.h>
+#include <sys/prctl.h>
+#include <sched.h>
+#include <linux/aio_abi.h>
 
 #include "proc_parse.h"
 #include "sockets.h"
 #include "crtools.h"
 #include "log.h"
 #include "util-pie.h"
-#include "syscall.h"
 #include "prctl.h"
 #include "files.h"
 #include "sk-inet.h"
@@ -156,7 +159,7 @@ static int check_sock_peek_off(void)
 
 static int check_kcmp(void)
 {
-	int ret = sys_kcmp(getpid(), -1, -1, -1, -1);
+	int ret = syscall(SYS_kcmp, getpid(), -1, -1, -1, -1);
 
 	if (ret != -ENOSYS)
 		return 0;
@@ -173,7 +176,7 @@ static int check_prctl(void)
 	unsigned int size = 0;
 	int ret;
 
-	ret = sys_prctl(PR_GET_TID_ADDRESS, (unsigned long)&tid_addr, 0, 0, 0);
+	ret = prctl(PR_GET_TID_ADDRESS, (unsigned long)&tid_addr, 0, 0, 0);
 	if (ret) {
 		pr_msg("prctl: PR_GET_TID_ADDRESS is not supported");
 		return -1;
@@ -182,7 +185,7 @@ static int check_prctl(void)
 	/*
 	 * Either new or old interface must be supported in the kernel.
 	 */
-	ret = sys_prctl(PR_SET_MM, PR_SET_MM_MAP_SIZE, (unsigned long)&size, 0, 0);
+	ret = prctl(PR_SET_MM, PR_SET_MM_MAP_SIZE, (unsigned long)&size, 0, 0);
 	if (ret) {
 		if (!opts.check_ms_kernel) {
 			pr_msg("prctl: PR_SET_MM_MAP is not supported, which "
@@ -191,7 +194,7 @@ static int check_prctl(void)
 		} else
 			pr_warn("Skipping unssuported PR_SET_MM_MAP\n");
 
-		ret = sys_prctl(PR_SET_MM, PR_SET_MM_BRK, sys_brk(0), 0, 0);
+		ret = prctl(PR_SET_MM, PR_SET_MM_BRK, brk(0), 0, 0);
 		if (ret) {
 			if (ret == -EPERM)
 				pr_msg("prctl: One needs CAP_SYS_RESOURCE capability to perform testing\n");
@@ -200,13 +203,13 @@ static int check_prctl(void)
 			return -1;
 		}
 
-		ret = sys_prctl(PR_SET_MM, PR_SET_MM_EXE_FILE, -1, 0, 0);
+		ret = prctl(PR_SET_MM, PR_SET_MM_EXE_FILE, -1, 0, 0);
 		if (ret != -EBADF) {
 			pr_msg("prctl: PR_SET_MM_EXE_FILE is not supported (%d)\n", ret);
 			return -1;
 		}
 
-		ret = sys_prctl(PR_SET_MM, PR_SET_MM_AUXV, (long)&user_auxv, sizeof(user_auxv), 0);
+		ret = prctl(PR_SET_MM, PR_SET_MM_AUXV, (long)&user_auxv, sizeof(user_auxv), 0);
 		if (ret) {
 			pr_msg("prctl: PR_SET_MM_AUXV is not supported\n");
 			return -1;
@@ -516,14 +519,11 @@ static int check_ipc(void)
 
 static int check_sigqueuinfo()
 {
-	int ret;
 	siginfo_t info = { .si_code = 1 };
 
 	signal(SIGUSR1, SIG_IGN);
 
-	ret = sys_rt_sigqueueinfo(getpid(), SIGUSR1, &info);
-	if (ret < 0) {
-		errno = -ret;
+	if (syscall(SYS_rt_sigqueueinfo, getpid(), SIGUSR1, &info)) {
 		pr_perror("Unable to send siginfo with positive si_code to itself");
 		return -1;
 	}
@@ -657,7 +657,7 @@ static int setup_seccomp_filter(void)
 		.filter = filter,
 	};
 
-	if (sys_prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, (long) &bpf_prog, 0, 0) < 0)
+	if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, (long) &bpf_prog, 0, 0) < 0)
 		return -1;
 
 	return 0;
@@ -753,7 +753,7 @@ static int check_aio_remap(void)
 	void *naddr;
 	int r;
 
-	if (sys_io_setup(16, &ctx) < 0) {
+	if (syscall(SYS_io_setup, 16, &ctx) < 0) {
 		pr_err("No AIO syscall\n");
 		return -1;
 	}
@@ -774,7 +774,7 @@ static int check_aio_remap(void)
 	}
 
 	ctx = (aio_context_t)naddr;
-	r = sys_io_getevents(ctx, 0, 1, NULL, NULL);
+	r = syscall(SYS_io_getevents, ctx, 0, 1, NULL, NULL);
 	if (r < 0) {
 		if (!opts.check_ms_kernel) {
 			pr_err("AIO remap doesn't work properly\n");
@@ -916,7 +916,7 @@ static int check_userns(void)
 		return -1;
 	}
 
-	ret = sys_prctl(PR_SET_MM, PR_SET_MM_MAP_SIZE, (unsigned long)&size, 0, 0);
+	ret = prctl(PR_SET_MM, PR_SET_MM_MAP_SIZE, (unsigned long)&size, 0, 0);
 	if (ret) {
 		errno = -ret;
 		pr_perror("No new prctl API");
diff --git a/cr-dump.c b/cr-dump.c
index 4ac3eed1e21a..7a690a6dc4b4 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -42,7 +42,6 @@
 #include "cr_options.h"
 #include "servicefd.h"
 #include "string.h"
-#include "syscall.h"
 #include "ptrace.h"
 #include "util.h"
 #include "namespaces.h"
@@ -522,7 +521,7 @@ static int get_task_futex_robust_list(pid_t pid, ThreadCoreEntry *info)
 	size_t len = 0;
 	int ret;
 
-	ret = sys_get_robust_list(pid, &head, &len);
+	ret = syscall(SYS_get_robust_list, pid, &head, &len);
 	if (ret == -ENOSYS) {
 		/*
 		 * If the kernel says get_robust_list is not implemented, then
@@ -535,7 +534,7 @@ static int get_task_futex_robust_list(pid_t pid, ThreadCoreEntry *info)
 		 * implemented, in which case it will return -EINVAL because
 		 * len should be greater than zero.
 		 */
-		if (sys_set_robust_list(NULL, 0) != -ENOSYS)
+		if (syscall(SYS_set_robust_list, NULL, 0) != -ENOSYS)
 			goto err;
 
 		head = NULL;
diff --git a/cr-restore.c b/cr-restore.c
index 3254efc3fb46..b758bb87e389 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -35,7 +35,6 @@
 #include "util.h"
 #include "util-pie.h"
 #include "log.h"
-#include "syscall.h"
 #include "restorer.h"
 #include "sockets.h"
 #include "sk-packet.h"
@@ -746,7 +745,7 @@ static int prepare_sigactions(void)
 		 * A pure syscall is used, because glibc
 		 * sigaction overwrites se_restorer.
 		 */
-		ret = sys_sigaction(sig, &act, NULL, sizeof(k_rtsigset_t));
+		ret = syscall(SYS_rt_sigaction, sig, &act, NULL, sizeof(k_rtsigset_t));
 		if (ret < 0) {
 			errno = -ret;
 			pr_perror("Can't restore sigaction");
@@ -982,7 +981,7 @@ static int restore_one_zombie(CoreEntry *core)
 	if (inherit_fd_fini() < 0)
 		return -1;
 
-	sys_prctl(PR_SET_NAME, (long)(void *)core->tc->comm, 0, 0, 0);
+	prctl(PR_SET_NAME, (long)(void *)core->tc->comm, 0, 0, 0);
 
 	if (task_entries != NULL) {
 		restore_finish_stage(CR_STATE_RESTORE);
diff --git a/cr-service.c b/cr-service.c
index 00dc17d4fa65..a1987e713833 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -12,6 +12,7 @@
 #include <sys/un.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
+#include <arpa/inet.h>
 
 #include "crtools.h"
 #include "cr_options.h"
diff --git a/crtools.c b/crtools.c
index 039b7a0ed12c..2690c38f8804 100644
--- a/crtools.c
+++ b/crtools.c
@@ -6,6 +6,7 @@
 #include <getopt.h>
 #include <string.h>
 #include <ctype.h>
+#include <sched.h>
 
 #include <fcntl.h>
 
@@ -24,7 +25,6 @@
 #include "crtools.h"
 #include "cr_options.h"
 #include "sockets.h"
-#include "syscall.h"
 #include "files.h"
 #include "sk-inet.h"
 #include "net.h"
diff --git a/file-ids.c b/file-ids.c
index 78e270778b94..f23924a0516b 100644
--- a/file-ids.c
+++ b/file-ids.c
@@ -14,7 +14,6 @@
 #include "rbtree.h"
 #include "kcmp-ids.h"
 #include "compiler.h"
-#include "syscall.h"
 #include "image.h"
 #include "util.h"
 #include "irmap.h"
diff --git a/files-reg.c b/files-reg.c
index a394e65c51b3..2bb1bf729160 100644
--- a/files-reg.c
+++ b/files-reg.c
@@ -9,6 +9,7 @@
 #include <sys/vfs.h>
 #include <sys/prctl.h>
 #include <ctype.h>
+#include <sched.h>
 
 /* Stolen from kernel/fs/nfs/unlink.c */
 #define SILLYNAME_PREF ".nfs"
diff --git a/fsnotify.c b/fsnotify.c
index 4477ba79987d..59259c13e2c3 100644
--- a/fsnotify.c
+++ b/fsnotify.c
@@ -20,14 +20,13 @@
 #include <sys/mount.h>
 #include <aio.h>
 
-#include <linux/fanotify.h>
+#include <sys/fanotify.h>
 
 #include "compiler.h"
 #include "asm/types.h"
 #include "imgset.h"
 #include "fsnotify.h"
 #include "proc_parse.h"
-#include "syscall.h"
 #include "mount.h"
 #include "image.h"
 #include "util.h"
@@ -104,7 +103,7 @@ static void decode_handle(fh_t *handle, FhEntry *img)
 
 static int open_by_handle(void *arg, int fd, int pid)
 {
-	return sys_open_by_handle_at(fd, arg, O_PATH);
+	return open_by_handle_at(fd, arg, O_PATH);
 }
 
 static char *alloc_openable(unsigned int s_dev, unsigned long i_ino, FhEntry *f_handle)
@@ -648,7 +647,7 @@ static int restore_one_fanotify(int fd, struct fsnotify_mark_info *mark)
 	flags |= fme->mflags;
 
 	if (mark->fme->mask) {
-		ret = sys_fanotify_mark(fd, flags, fme->mask, AT_FDCWD, path);
+		ret = fanotify_mark(fd, flags, fme->mask, AT_FDCWD, path);
 		if (ret) {
 			pr_err("Adding fanotify mask 0x%x on 0x%x/%s failed (%d)\n",
 			       fme->mask, fme->id, path, ret);
@@ -657,8 +656,8 @@ static int restore_one_fanotify(int fd, struct fsnotify_mark_info *mark)
 	}
 
 	if (fme->ignored_mask) {
-		ret = sys_fanotify_mark(fd, flags | FAN_MARK_IGNORED_MASK,
-					fme->ignored_mask, AT_FDCWD, path);
+		ret = fanotify_mark(fd, flags | FAN_MARK_IGNORED_MASK,
+				    fme->ignored_mask, AT_FDCWD, path);
 		if (ret) {
 			pr_err("Adding fanotify ignored-mask 0x%x on 0x%x/%s failed (%d)\n",
 			       fme->ignored_mask, fme->id, path, ret);
@@ -717,7 +716,7 @@ static int open_fanotify_fd(struct file_desc *d)
 	if (info->ffe->flags & O_NONBLOCK)
 		flags |= FAN_NONBLOCK;
 
-	ret = sys_fanotify_init(flags, info->ffe->evflags);
+	ret = fanotify_init(flags, info->ffe->evflags);
 	if (ret < 0) {
 		errno = -ret;
 		pr_perror("Can't init fanotify mark (%d)", ret);
diff --git a/include/lock.h b/include/lock.h
index 734132c28d8f..1678d10ef988 100644
--- a/include/lock.h
+++ b/include/lock.h
@@ -8,9 +8,21 @@
 
 #include "asm/types.h"
 #include "asm/atomic.h"
-#include "syscall.h"
 #include "bug.h"
 
+#ifdef CR_NOGLIBC
+# include "syscall.h"
+#else
+# include <sys/syscall.h>
+static inline long sys_futex(void *addr1, int op, int val1,
+                            struct timespec *timeout, void *addr2, int val3)
+{
+       int rc = syscall(SYS_futex, addr1, op, val1, timeout, addr2, val3);
+       if (rc == -1) rc = -errno;
+       return rc;
+}
+#endif
+
 typedef struct {
 	atomic_t raw;
 } futex_t;
diff --git a/include/sk-inet.h b/include/sk-inet.h
index eb1a79a484e0..5b5fca63870c 100644
--- a/include/sk-inet.h
+++ b/include/sk-inet.h
@@ -52,11 +52,14 @@ struct inet_sk_info {
 extern int inet_bind(int sk, struct inet_sk_info *);
 extern int inet_connect(int sk, struct inet_sk_info *);
 
+#ifdef CR_NOGLIBC
+#define setsockopt	sys_setsockopt
+#endif
 static inline void tcp_repair_off(int fd)
 {
 	int aux = 0, ret;
 
-	ret = sys_setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux));
+	ret = setsockopt(fd, SOL_TCP, TCP_REPAIR, &aux, sizeof(aux));
 	if (ret < 0)
 		pr_err("Failed to turn off repair mode on socket (%d)\n", ret);
 }
diff --git a/include/sockets.h b/include/sockets.h
index 9ec85a4c84a9..b726e2f7a0b3 100644
--- a/include/sockets.h
+++ b/include/sockets.h
@@ -2,6 +2,7 @@
 #define __CR_SOCKETS_H__
 
 #include <stdbool.h>
+#include <sys/socket.h>
 
 #include "asm/types.h"
 
diff --git a/ipc_ns.c b/ipc_ns.c
index 3bc0c6523634..9abb40311a18 100644
--- a/ipc_ns.c
+++ b/ipc_ns.c
@@ -6,11 +6,11 @@
 #include <sys/msg.h>
 #include <sys/sem.h>
 #include <sys/shm.h>
+#include <sched.h>
 
 #include "util.h"
 #include "cr_options.h"
 #include "imgset.h"
-#include "syscall.h"
 #include "namespaces.h"
 #include "sysctl.h"
 #include "ipc_ns.h"
diff --git a/kcmp-ids.c b/kcmp-ids.c
index 9755969b385c..853879fe071b 100644
--- a/kcmp-ids.c
+++ b/kcmp-ids.c
@@ -1,9 +1,10 @@
 #include <unistd.h>
 #include <stdlib.h>
+#include <sys/syscall.h>
+
 #include "asm/types.h"
 #include "rbtree.h"
 #include "util.h"
-#include "syscall.h"
 #include "kcmp-ids.h"
 
 /*
@@ -92,7 +93,7 @@ static u32 kid_generate_sub(struct kid_tree *tree, struct kid_entry *e,
 
 	while (node) {
 		struct kid_entry *this = rb_entry(node, struct kid_entry, subtree_node);
-		int ret = sys_kcmp(this->elem.pid, elem->pid, tree->kcmp_type,
+		int ret = syscall(SYS_kcmp, this->elem.pid, elem->pid, tree->kcmp_type,
 				this->elem.idx, elem->idx);
 
 		parent = *new;
@@ -103,9 +104,9 @@ static u32 kid_generate_sub(struct kid_tree *tree, struct kid_entry *e,
 		else if (ret == 0)
 			return this->subid;
 		else {
-			pr_err("kcmp failed: pid (%d %d) type %u idx (%u %u) ret %d\n",
-			       this->elem.pid, elem->pid, tree->kcmp_type,
-			       this->elem.idx, elem->idx, ret);
+			pr_perror("kcmp failed: pid (%d %d) type %u idx (%u %u)",
+				  this->elem.pid, elem->pid, tree->kcmp_type,
+				  this->elem.idx, elem->idx);
 			return 0;
 		}
 	}
diff --git a/kerndat.c b/kerndat.c
index 696701d4f9c2..d03fdb3028ed 100644
--- a/kerndat.c
+++ b/kerndat.c
@@ -6,6 +6,7 @@
 #include <sys/types.h>
 #include <sys/mman.h>
 #include <errno.h>
+#include <sys/syscall.h>
 
 #include "log.h"
 #include "bug.h"
@@ -14,7 +15,6 @@
 #include "mem.h"
 #include "compiler.h"
 #include "sysctl.h"
-#include "syscall.h"
 #include "asm/types.h"
 #include "cr_options.h"
 #include "util.h"
@@ -385,11 +385,11 @@ static bool kerndat_has_memfd_create(void)
 {
 	int ret;
 
-	ret = sys_memfd_create(NULL, 0);
+	ret = syscall(SYS_memfd_create, NULL, 0);
 
-	if (ret == -ENOSYS)
+	if (ret == -1 && errno == ENOSYS)
 		kdat.has_memfd = false;
-	else if (ret == -EFAULT)
+	else if (ret == -1 && errno == EFAULT)
 		kdat.has_memfd = true;
 	else {
 		pr_err("Unexpected error %d from memfd_create(NULL, 0)\n", ret);
diff --git a/mount.c b/mount.c
index 84371d194f6a..05cf6cf0a0f9 100644
--- a/mount.c
+++ b/mount.c
@@ -11,6 +11,7 @@
 #include <sys/mount.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sched.h>
 
 #include "cr_options.h"
 #include "asm/types.h"
diff --git a/namespaces.c b/namespaces.c
index 8279368ed402..9a7836bcad89 100644
--- a/namespaces.c
+++ b/namespaces.c
@@ -8,11 +8,11 @@
 #include <sys/un.h>
 #include <stdarg.h>
 #include <signal.h>
+#include <sched.h>
 
 #include "cr-show.h"
 #include "util.h"
 #include "imgset.h"
-#include "syscall.h"
 #include "uts_ns.h"
 #include "ipc_ns.h"
 #include "mount.h"
diff --git a/net.c b/net.c
index 51b31597a528..81010b019144 100644
--- a/net.c
+++ b/net.c
@@ -11,7 +11,6 @@
 #include <linux/sockios.h>
 
 #include "imgset.h"
-#include "syscall-types.h"
 #include "namespaces.h"
 #include "net.h"
 #include "libnetlink.h"
diff --git a/parasite-syscall.c b/parasite-syscall.c
index b0a3d211d386..ee6bfef0e3bc 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -13,7 +13,6 @@
 #include "protobuf/pagemap.pb-c.h"
 
 #include "imgset.h"
-#include "syscall.h"
 #include "ptrace.h"
 #include "asm/processor-flags.h"
 #include "parasite-syscall.h"
diff --git a/pie/util-vdso.c b/pie/util-vdso.c
index 65746d914fdd..e93b110fe43b 100644
--- a/pie/util-vdso.c
+++ b/pie/util-vdso.c
@@ -12,7 +12,6 @@
 #include "asm/string.h"
 #include "asm/types.h"
 
-#include "syscall.h"
 #include "image.h"
 #include "util-vdso.h"
 #include "vma.h"
diff --git a/pie/util.c b/pie/util.c
index 2910da3665a6..354667294e37 100644
--- a/pie/util.c
+++ b/pie/util.c
@@ -1,32 +1,38 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/mount.h>
-
+#include <unistd.h>
 #include <errno.h>
 
 #include "compiler.h"
 #include "asm/string.h"
 #include "asm/types.h"
-#include "syscall.h"
 #include "fcntl.h"
 #include "log.h"
 #include "util-pie.h"
 
+#ifdef CR_NOGLIBC
+# include "syscall.h"
+# define __sys(foo)     sys_##foo
+#else
+# define __sys(foo)     foo
+#endif
+
 int open_detach_mount(char *dir)
 {
 	int fd, ret;
 
-	fd = sys_open(dir, O_RDONLY | O_DIRECTORY, 0);
+	fd = __sys(open)(dir, O_RDONLY | O_DIRECTORY, 0);
 	if (fd < 0)
 		pr_err("Can't open directory %s: %d\n", dir, fd);
 
-	ret = sys_umount2(dir, MNT_DETACH);
+	ret = __sys(umount2)(dir, MNT_DETACH);
 	if (ret) {
 		pr_err("Can't detach mount %s: %d\n", dir, ret);
 		goto err_close;
 	}
 
-	ret = sys_rmdir(dir);
+	ret = __sys(rmdir)(dir);
 	if (ret) {
 		pr_err("Can't remove tmp dir %s: %d\n", dir, ret);
 		goto err_close;
@@ -36,6 +42,6 @@ int open_detach_mount(char *dir)
 
 err_close:
 	if (fd >= 0)
-		sys_close(fd);
+		__sys(close)(fd);
 	return -1;
 }
diff --git a/pstree.c b/pstree.c
index 1c31d89ad0e2..06bc5f84b5be 100644
--- a/pstree.c
+++ b/pstree.c
@@ -1,6 +1,7 @@
 #include <sys/mman.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <sched.h>
 
 #include "cr_options.h"
 #include "pstree.h"
@@ -17,6 +18,8 @@
 
 struct pstree_item *root_item;
 
+#define CLONE_ALLNS     (CLONE_NEWPID | CLONE_NEWNET | CLONE_NEWIPC | CLONE_NEWUTS | CLONE_NEWNS | CLONE_NEWUSER)
+
 void core_entry_free(CoreEntry *core)
 {
 	if (core->tc && core->tc->timers)
diff --git a/shmem.c b/shmem.c
index b2900f4f875d..0f9da630ccc5 100644
--- a/shmem.c
+++ b/shmem.c
@@ -216,7 +216,7 @@ int get_shmem_fd(int pid, VmaEntry *vi)
 
 	flags = MAP_SHARED;
 	if (kdat.has_memfd) {
-		f = sys_memfd_create("", 0);
+		f = syscall(SYS_memfd_create, "", 0);
 		if (f < 0) {
 			pr_perror("Unable to create memfd");
 			goto err;
diff --git a/sk-packet.c b/sk-packet.c
index b79a8ec00606..a296dfa16a7f 100644
--- a/sk-packet.c
+++ b/sk-packet.c
@@ -12,6 +12,7 @@
 #include "sk-packet.h"
 #include "packet_diag.h"
 #include "vma.h"
+#include <arpa/inet.h>
 
 #include "protobuf.h"
 #include "protobuf/packet-sock.pb-c.h"
diff --git a/sk-tcp.c b/sk-tcp.c
index b5e66b0e00c0..dc95d3ddd736 100644
--- a/sk-tcp.c
+++ b/sk-tcp.c
@@ -5,6 +5,8 @@
 #include <stdlib.h>
 #include <sys/mman.h>
 #include <string.h>
+#include <sched.h>
+#include <netinet/in.h>
 
 #include "cr_options.h"
 #include "util.h"
diff --git a/sockets.c b/sockets.c
index f4ffd0e1817d..d8d09aae2d15 100644
--- a/sockets.c
+++ b/sockets.c
@@ -7,6 +7,7 @@
 #include <linux/if.h>
 #include <linux/filter.h>
 #include <string.h>
+#include <netinet/in.h>
 
 #include "libnetlink.h"
 #include "sockets.h"
diff --git a/sysctl.c b/sysctl.c
index 819ad7cab26a..21ae4cef19e8 100644
--- a/sysctl.c
+++ b/sysctl.c
@@ -5,6 +5,7 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sched.h>
 
 #include "asm/types.h"
 #include "namespaces.h"
diff --git a/tty.c b/tty.c
index 1643ef084fc3..ef82583ddfd6 100644
--- a/tty.c
+++ b/tty.c
@@ -15,7 +15,6 @@
 #include "compiler.h"
 #include "asm/types.h"
 
-#include "syscall.h"
 #include "files.h"
 #include "cr_options.h"
 #include "imgset.h"
diff --git a/tun.c b/tun.c
index 14012f2377e5..dcee704e48b4 100644
--- a/tun.c
+++ b/tun.c
@@ -3,6 +3,7 @@
 #include <linux/if.h>
 #include <linux/if_tun.h>
 #include <sys/ioctl.h>
+#include <sched.h>
 
 // MAO required on Centos 6 (linux-3.18.1 kernel)
 #include <linux/filter.h>
diff --git a/util.c b/util.c
index 241670cb98f3..fc8269a179a7 100644
--- a/util.c
+++ b/util.c
@@ -31,6 +31,7 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#include <sched.h>
 
 #include "compiler.h"
 #include "asm/types.h"
diff --git a/uts_ns.c b/uts_ns.c
index ca6bbdc0e61b..ed64d77ec467 100644
--- a/uts_ns.c
+++ b/uts_ns.c
@@ -2,9 +2,9 @@
 #include <fcntl.h>
 #include <sys/utsname.h>
 #include <string.h>
+#include <sched.h>
 
 #include "util.h"
-#include "syscall.h"
 #include "namespaces.h"
 #include "sysctl.h"
 #include "uts_ns.h"
-- 
1.9.1



More information about the CRIU mailing list