[CRIU] [PATCH] crtools: use criu_main() instead of main()

Yicheng Qin yichengq at google.com
Wed Aug 14 14:09:58 EDT 2013


Replace main() with criu_main(), and put main() function under
new 'main' directory.

Include some standard header files in list.h and util.h to resolve
lack of symbol.

This is intended for a simple criu binary implementation.

Signed-off-by: Yicheng Qin <yichengq at google.com>
---
 Makefile          | 14 +++++++++++---
 crtools.c         |  2 +-
 include/crtools.h |  2 ++
 include/list.h    |  1 +
 include/util.h    |  1 +
 main/Makefile     |  1 +
 main/criu.c       |  9 +++++++++
 7 files changed, 26 insertions(+), 4 deletions(-)
 create mode 100644 main/Makefile
 create mode 100644 main/criu.c

diff --git a/Makefile b/Makefile
index fecc7f5..8e34770 100644
--- a/Makefile
+++ b/Makefile
@@ -120,7 +120,7 @@ build-crtools := -r -R -f scripts/Makefile.build makefile=Makefile.crtools obj
 PROGRAM		:= criu
 
 .PHONY: all zdtm test rebuild clean distclean tags cscope	\
-	docs help pie protobuf arch/$(ARCH) clean-built lib
+	docs help pie protobuf arch/$(ARCH) clean-built lib main
 
 ifeq ($(GCOV),1)
 %.o $(PROGRAM): override CFLAGS += --coverage
@@ -132,7 +132,12 @@ all: config pie $(VERSION_HEADER) lib
 lib: $(VERSION_HEADER)
 	$(Q) $(MAKE) -C lib all
 
-protobuf/%::
+main/%::
+	$(Q) $(MAKE) $(build)=main $@
+main:
+	$(Q) $(MAKE) $(build)=main all
+
+protobuf/%:: main
 	$(Q) $(MAKE) $(build)=protobuf $@
 protobuf:
 	$(Q) $(MAKE) $(build)=protobuf all
@@ -152,6 +157,8 @@ pie: arch/$(ARCH)
 built-in.o: $(VERSION_HEADER) pie
 	$(Q) $(MAKE) $(build-crtools)=. $@
 
+MAIN-BUILTINS		+= main/built-in.o
+
 PROGRAM-BUILTINS	+= pie/util.o
 PROGRAM-BUILTINS	+= protobuf/built-in.o
 PROGRAM-BUILTINS	+= built-in.o
@@ -160,7 +167,7 @@ $(ARCH_DIR)/vdso-pie.o: pie
 	$(Q) $(MAKE) $(build)=pie $(ARCH_DIR)/vdso-pie.o
 PROGRAM-BUILTINS	+= $(ARCH_DIR)/vdso-pie.o
 
-$(PROGRAM): $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS)
+$(PROGRAM): $(SYSCALL-LIB) $(ARCH-LIB) $(PROGRAM-BUILTINS) $(MAIN-BUILTINS)
 	$(E) "  LINK    " $@
 	$(Q) $(CC) $(CFLAGS) $^ $(LIBS) $(LDFLAGS) -o $@
 
@@ -173,6 +180,7 @@ test: zdtm
 clean-built:
 	$(Q) $(RM) $(VERSION_HEADER)
 	$(Q) $(MAKE) $(build)=arch/$(ARCH) clean
+	$(Q) $(MAKE) $(build)=main clean
 	$(Q) $(MAKE) $(build)=protobuf clean
 	$(Q) $(MAKE) $(build)=pie clean
 	$(Q) $(MAKE) $(build-crtools)=. clean
diff --git a/crtools.c b/crtools.c
index c7bc8b4..e76b429 100644
--- a/crtools.c
+++ b/crtools.c
@@ -60,7 +60,7 @@ bad_ns:
 	return -1;
 }
 
-int main(int argc, char *argv[])
+int criu_main(int argc, char *argv[])
 {
 	pid_t pid = 0, tree_id = 0;
 	int ret = -1;
diff --git a/include/crtools.h b/include/crtools.h
index 65ed166..1cdc35f 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -190,4 +190,6 @@ static inline int in_vma_area(struct vma_area *vma, unsigned long addr)
 		addr < (unsigned long)vma->vma.end;
 }
 
+int criu_main(int argc, char *argv[]);
+
 #endif /* __CR_CRTOOLS_H__ */
diff --git a/include/list.h b/include/list.h
index 32d8edd..5af1093 100644
--- a/include/list.h
+++ b/include/list.h
@@ -5,6 +5,7 @@
  * Double linked lists.
  */
 
+#include <stdlib.h>
 #include "compiler.h"
 
 #define POISON_POINTER_DELTA 0
diff --git a/include/util.h b/include/util.h
index 3475700..ddeb716 100644
--- a/include/util.h
+++ b/include/util.h
@@ -4,6 +4,7 @@
 /*
  * Some bits are stolen from perf and kvm tools
  */
+#include <unistd.h>
 #include <signal.h>
 #include <stdio.h>
 #include <errno.h>
diff --git a/main/Makefile b/main/Makefile
new file mode 100644
index 0000000..868d526
--- /dev/null
+++ b/main/Makefile
@@ -0,0 +1 @@
+obj-y			+= criu.o
diff --git a/main/criu.c b/main/criu.c
new file mode 100644
index 0000000..398a59f
--- /dev/null
+++ b/main/criu.c
@@ -0,0 +1,9 @@
+#include "crtools.h"
+
+/*
+ * Entry point to criu_main
+ */
+int main(int argc, char *argv[])
+{
+	return criu_main(argc, argv);
+}
-- 
1.8.3



More information about the CRIU mailing list