All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
Cc: Containers <containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>
Subject: Re: [C/R] sleepers don't wake up on restart
Date: Thu, 2 Apr 2009 15:43:42 -0700	[thread overview]
Message-ID: <20090402224342.GA7613@us.ibm.com> (raw)
In-Reply-To: <49D539B5.7060305-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 188 bytes --]

Oren Laadan [orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org] wrote:
| 
| Suka,
| 
| can you please post the entire test program so I can try to reproduce
| it here ?

Sure. Attached.

Suka

[-- Attachment #2: ptree1.c --]
[-- Type: text/x-csrc, Size: 2575 bytes --]

#include <stdio.h>
#include <unistd.h>
#include <wait.h>
#include <errno.h>

#define NUM_PROCS	10
#define CKPT_READY	"ckpt-ready"
#define CKPT_DONE	"ckpt-done"
#define TEST_DONE	"test-done"
#define LOG_FILE	"log.ptree1"

FILE *logfp;

void do_exit(int status)
{
	if (logfp) {
		fflush(logfp);
		fclose(logfp);
	}
	_Exit(status);
}

int test_done()
{
	int rc;

	rc = access(TEST_DONE, F_OK);
	if (rc == 0)
		return 1;
	else if (errno == ENOENT)
		return 0;

	fprintf(logfp, "access(%s) failed, %s\n", TEST_DONE, strerror(errno));
	do_exit(1);
}

int checkpoint_done()
{
	int rc;

	rc = access(CKPT_DONE, F_OK);
	if (rc == 0)
		return 1;
	else if (errno == ENOENT)
		return 0;

	fprintf(logfp, "access(%s) failed, %s\n", CKPT_DONE, strerror(errno));
	do_exit(1);
}

void checkpoint_ready()
{
	int fd;

	fd = creat(CKPT_READY, 0666, 0);
	if (fd < 0) {
		fprintf(logfp, "creat(%s) failed, %s\n", CKPT_READY,
				strerror(errno));
		do_exit(1);
	}
	close(fd);
}

do_child(int cnum)
{
	int i;
	FILE *cfp;
	char cfile[256];

	sprintf(cfile, "child-log-%d", cnum);

	i = 0;
	while (!test_done()) {
		cfp = fopen(cfile, "a");
		if (!cfp) {
			fprintf(logfp, "fopen(%s) failed, error %s\n", cfile,
					strerror(errno));
			do_exit(1);
		}
		fprintf(cfp, "i = %d\n", i++);
		fflush(cfp);
		fclose(cfp);
		sleep(1);
	}

	do_exit(0);
}

print_exit_status(int pid, int status)
{
	fprintf(logfp, "Pid %d unexpected exit - ", pid);
	if (WIFEXITED(status)) {
		fprintf(logfp, "exit status %d\n", WEXITSTATUS(status));
	} else if (WIFSIGNALED(status)) {
		fprintf(logfp, "got signal %d\n", WTERMSIG(status));
	} else {
		fprintf(logfp, "stopped/continued ?\n");
	}
}

main(int argc, char *argv[])
{
	int i;
	int status;
	int pid_list[NUM_PROCS];

	if (test_done()) {
		printf("Remove %s before running test\n", TEST_DONE);
		do_exit(1);
	}

	logfp = fopen(LOG_FILE, "w");
	if (!logfp) {
		fprintf(stderr, "fopen(%s) failed, %s\n", LOG_FILE,
					strerror(errno));
		fflush(stderr);
		do_exit(1);
	}
	close(0);close(1);close(2);

	for (i = 0; i < NUM_PROCS; i++) {
		if ((pid_list[i] = fork()) == 0)
			do_child(i);
	}

	/*
 	 * Now that we closed the special files and created process tree
	 * tell any wrapper scripts, we are ready for checkpoint
	 */
	checkpoint_ready();

	while(!checkpoint_done())
		sleep(1);

	for (i = 0; i < NUM_PROCS; i++) {
		if (waitpid(pid_list[i], &status, 0) < 0) {
			fprintf(logfp, "waitpid(%d) failed, error %s\n",
					pid_list[i], strerror(errno));
		}

		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
			print_exit_status(pid_list[i], status);	
	}
}

[-- Attachment #3: Type: text/plain, Size: 206 bytes --]

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

  parent reply	other threads:[~2009-04-02 22:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-02  0:20 [C/R] sleepers don't wake up on restart Sukadev Bhattiprolu
     [not found] ` <20090402002005.GA22375-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-04-02 22:18   ` Oren Laadan
     [not found]     ` <49D539B5.7060305-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-04-02 22:43       ` Sukadev Bhattiprolu [this message]
     [not found]         ` <20090402224342.GA7613-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-04-07 12:47           ` Oren Laadan
     [not found]             ` <49DB4B6C.3050500-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-04-26  0:56               ` Sukadev Bhattiprolu
     [not found]                 ` <20090426005641.GA4376-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-04-29 21:45                   ` Oren Laadan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090402224342.GA7613@us.ibm.com \
    --to=sukadev-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
    --cc=orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.