[CRIU] [PATCH 1/2] Add stopexec

Christopher Covington cov at codeaurora.org
Tue Aug 18 08:48:49 PDT 2015


stopexec allows one to dump a checkpoint of a process just before it
starts, capturing command line arguments, environment variables, and
inherited file descriptors. While this can be done with a sufficiently
sophisticated shell script, putting this data in CRIU format allows
the start of a program to be treated in the same manner as resuming at
all other points in an applications execution must be treated--by
dumping and restoring a checkpoint.

Signed-off-by: Christopher Covington <cov at codeaurora.org>
---
 Makefile   |  5 ++++-
 stopexec.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)
 create mode 100644 stopexec.c

diff --git a/Makefile b/Makefile
index 7f5c890..2d48895 100644
--- a/Makefile
+++ b/Makefile
@@ -193,10 +193,13 @@ ifeq ($(GCOV),1)
 %.o $(PROGRAM): override CFLAGS += --coverage
 endif
 
-all: config pie $(VERSION_HEADER) $(CRIU-LIB)
+all: config pie $(VERSION_HEADER) $(CRIU-LIB) stopexec
 	$(Q) $(MAKE) $(PROGRAM)
 	$(Q) $(MAKE) crit
 
+stopexec: stopexec.c
+	$(Q) $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
+
 protobuf/%::
 	$(Q) $(MAKE) $(build)=protobuf $@
 protobuf:
diff --git a/stopexec.c b/stopexec.c
new file mode 100644
index 0000000..a5b5bfb
--- /dev/null
+++ b/stopexec.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 and only version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * stopexec - Stop an application immediately prior to execution.
+ *
+ * Written by Christopher Covington.
+ */
+
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[])
+{
+	FILE *fp;
+
+	if (argc < 3) {
+		printf("Usage is %s logfile -- program [args...]\n", argv[0]);
+		return -1;
+	}
+
+	fp = fopen(argv[1], "w");
+	if (fp == NULL) {
+		printf("Error opening %s.\n", argv[1]);
+		return errno;
+	}
+
+	/* Set session ID to make process easily `criu dump`-able */
+	setsid();
+	fprintf(fp, "Stopping pid %d before exec().\n", getpid());
+	fclose(fp);
+	raise(SIGSTOP);
+
+	return execvp(argv[3], &argv[3]);
+}
-- 
Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project



More information about the CRIU mailing list