[CRIU] [PATCH 1/2] zdtm: Write .inprogress pidfile

Pavel Emelyanov xemul at virtuozzo.com
Wed Oct 26 12:36:19 PDT 2016


On 10/26/2016 09:16 PM, Andrei Vagin wrote:
> On Wed, Oct 26, 2016 at 11:51:29AM +0300, Pavel Emelyanov wrote:
>> This one will contain pid of the task living in a sub-ns and
>> waiting for the rest of the test to get daemonized.
>>
>> Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
>> ---
>>  test/zdtm/lib/ns.c      | 12 ++++++++++++
>>  test/zdtm/lib/test.c    |  1 -
>>  test/zdtm/lib/zdtmtst.h |  2 ++
>>  3 files changed, 14 insertions(+), 1 deletion(-)
>>
>> diff --git a/test/zdtm/lib/ns.c b/test/zdtm/lib/ns.c
>> index acf4a31..fa6ee86 100644
>> --- a/test/zdtm/lib/ns.c
>> +++ b/test/zdtm/lib/ns.c
>> @@ -362,6 +362,7 @@ void ns_create(int argc, char **argv)
>>  	int ret, status;
>>  	struct ns_exec_args args;
>>  	int flags;
>> +	char *pidf;
>>  
>>  	args.argc = argc;
>>  	args.argv = argv;
>> @@ -416,6 +417,14 @@ void ns_create(int argc, char **argv)
>>  	}
>>  	shutdown(args.status_pipe[0], SHUT_WR);
>>  
>> +	pidf = pidfile;
>> +	pidfile = malloc(strlen(pidfile) + 13);
>> +	sprintf(pidfile, "%s%s", pidf, INPROGRESS);
> 
> Why do we need another pid file? Why is it bad to write pidfile (without
> INPROGRESS)?

Because it contains PID of a process that will die really soon.
Also, some scripts (may) wait for the .pid file to appear, meaning
that the test has started.

>> +	if (write_pidfile(pid)) {
>> +		fprintf(stderr, "Preparations fail\n");
>> +		exit(1);
>> +	}
>> +
>>  	status = 1;
>>  	ret = read(args.status_pipe[0], &status, sizeof(status));
>>  	if (ret != sizeof(status) || status) {
>> @@ -428,6 +437,9 @@ void ns_create(int argc, char **argv)
>>  		exit(1);
>>  	}
>>  
>> +	unlink(pidfile);
>> +	pidfile = pidf;
>> +
>>  	if (write_pidfile(pid))
>>  		exit(1);
>>  
>> diff --git a/test/zdtm/lib/test.c b/test/zdtm/lib/test.c
>> index db7118d..a3576a5 100644
>> --- a/test/zdtm/lib/test.c
>> +++ b/test/zdtm/lib/test.c
>> @@ -41,7 +41,6 @@ int test_fork_id(int id)
>>  
>>  static int cwd = -1;
>>  
>> -#define INPROGRESS ".inprogress"
>>  static void test_fini(void)
>>  {
>>  	char path[PATH_MAX];
>> diff --git a/test/zdtm/lib/zdtmtst.h b/test/zdtm/lib/zdtmtst.h
>> index 8a6f6ba..3f9f550 100644
>> --- a/test/zdtm/lib/zdtmtst.h
>> +++ b/test/zdtm/lib/zdtmtst.h
>> @@ -4,6 +4,8 @@
>>  #include <sys/types.h>
>>  #include <unistd.h>
>>  
>> +#define INPROGRESS ".inprogress"
>> +
>>  #ifndef PAGE_SIZE
>>  # define PAGE_SIZE (unsigned int)(sysconf(_SC_PAGESIZE))
>>  #endif
>> -- 
>> 2.5.0
>>
>> _______________________________________________
>> CRIU mailing list
>> CRIU at openvz.org
>> https://lists.openvz.org/mailman/listinfo/criu
> .
> 



More information about the CRIU mailing list