[CRIU] [PATCH v2 1/2] Add stopexec
Christopher Covington
cov at codeaurora.org
Mon Aug 24 07:23:55 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>
---
.gitignore | 1 +
Makefile | 11 +++++++++++
stopexec.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+)
create mode 100644 .gitignore
create mode 100644 Makefile
create mode 100644 stopexec.c
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9125f1f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+stopexec
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..33c0b5a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,11 @@
+OBJS=stopexec
+
+all: $(OBJS)
+
+stopexec: stopexec.c
+ $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
+
+.PHONY: clean
+
+clean:
+ rm -f $(OBJS)
diff --git a/stopexec.c b/stopexec.c
new file mode 100644
index 0000000..329f601
--- /dev/null
+++ b/stopexec.c
@@ -0,0 +1,46 @@
+/*
+ * 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("Typical usage: %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