[CRIU] [PATCH 1/2] Add stopexec

Pavel Emelyanov xemul at parallels.com
Fri Aug 21 14:49:44 PDT 2015


On 08/18/2015 06:48 PM, Christopher Covington wrote:
> 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.

Well, this is definitely a useful tool, but I'm not sure these has to
sit in the criu repository. We've had the same story with criu-to-core
conversion tool some time ago and decided to put it aside.

I have a separate repo on github (https://github.com/xemul/criu-scripts)
where I put all the stuff that is not so tied to criu to be merged
into the main repo, but that I use to play with criu. If you want, we
can put this into criu-scripts too, I'm sore other guys will state
the values of them.

-- Pavel

> 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]);
> +}
> 



More information about the CRIU mailing list