mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: Joe Korty <joe.korty@ccur.com>
Cc: Roland McGrath <roland@redhat.com>, Jiri Kosina <jkosina@suse.cz>,
	Andrew Morton <akpm@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [BUG, TEST PATCH] stallout race between SIGCONT and SIGSTOP
Date: Wed, 24 Sep 2008 21:34:59 +0400	[thread overview]
Message-ID: <20080924173459.GA5426@tv-sign.ru> (raw)
In-Reply-To: <20080924171143.GA18733@tsunami.ccur.com>

On 09/24, Joe Korty wrote:
>
> On Wed, Sep 24, 2008 at 11:56:11AM -0400, Oleg Nesterov wrote:
> > Confused. Do you agree the kernel is not buggy?
>
> I agree with you that what the kernel is doing now is correct.

Great. Thanks a lot for the report and discussion! And thanks
for your analysis (sent privately), the problem was completely
explained by you.

BTW, I forgot to show the test-case you sent me privately, perhaps
someone from CC might want to look... It really helped.

Oleg.

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/select.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#define NUMSTOPS 10

int child_stopped = 0;
int waiting = 1;

void handler(int signo, siginfo_t *info, void *context) 
{
	if (info && info->si_code == CLD_STOPPED) {
		printf("Child has been stopped\n");
		waiting = 0;
		child_stopped++;
	}
}


int main(void)
{
	pid_t pid;
	struct sigaction act;
	struct timeval tv;

	act.sa_sigaction = handler;
	act.sa_flags = SA_SIGINFO;
	sigemptyset(&act.sa_mask);
	sigaction(SIGCHLD,  &act, 0);     

	setbuf(stdout, NULL);
	printf("%d SIGSTOP/SIGCONT combinations to be sent.\n", NUMSTOPS);

	if ((pid = fork()) == 0) {
		/* child */
		while(1) {
			/* wait forever, or until we are 
			   interrupted by a signal */
			tv.tv_sec = 0;
			tv.tv_usec = 0;
			select(0, NULL, NULL, NULL, &tv);
		}
		return 0;
	} else {
		/* parent */
		int s; 		
		int i;

		usleep(12000);
		for (i = 0; i < NUMSTOPS; i++) {
			waiting = 1;

			printf("--> Sending SIGSTOP #%d\n", i);
			kill(pid, SIGSTOP);

			/*
			  Don't let the kernel optimize away queued
			  SIGSTOP/SIGCONT signals.
			*/
			while (waiting)
				usleep(12000);

			printf("--> Sending SIGCONT\n");
			kill(pid, SIGCONT);
			// usleep(12000);
		}

		/* POSIX specifies default action to be abnormal termination */
		usleep(12000);
		kill(pid, SIGKILL);
		waitpid(pid, &s, 0);
	}

	if (child_stopped == NUMSTOPS) {
		printf("Test PASSED\n");
		return 0;
	}

	printf("Test FAILED\n");
	return -1;
}


      reply	other threads:[~2008-09-24 17:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-23 15:53 Joe Korty
2008-09-23 16:35 ` Oleg Nesterov
2008-09-24 15:05   ` Oleg Nesterov
2008-09-24 15:19     ` Joe Korty
2008-09-24 15:56       ` Oleg Nesterov
2008-09-24 17:11         ` Joe Korty
2008-09-24 17:34           ` Oleg Nesterov [this message]

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=20080924173459.GA5426@tv-sign.ru \
    --to=oleg@tv-sign.ru \
    --cc=akpm@linux-foundation.org \
    --cc=jkosina@suse.cz \
    --cc=joe.korty@ccur.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®