linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Never mind. Re: Signal left blocked after signal handler.
@ 2003-11-26 21:53 Albert Cahalan
  2003-11-27  9:11 ` Ingo Oeser
  0 siblings, 1 reply; 8+ messages in thread
From: Albert Cahalan @ 2003-11-26 21:53 UTC (permalink / raw)
  To: linux-kernel mailing list; +Cc: bruce, Linus Torvalds

> One difference in 2.4.x and 2.6.x is the signal blocking
> wrt blocked signals that are _forced_ (ie anything that
> is thread-synchronous, like a SIGSEGV/SIGTRAP/SIGBUS that
> happens as a result of a fault):
>
>  - in 2.4.x they will just punch through the block
>  - in 2.6.x they will refuse to punch through a blocked
>    signal, but since they can't be delivered they will
>    cause the process to be killed.
...
> and in 2.4.x this will cause infinte SIGSEGV's (well,
> they'll be caught by the stack size eventually, but you
> see the problem: do a "strace" to see what's going on).
> In 2.6.x the second SIGSEGV will just kill the program
> immediately.

How about making the process sleep in a killable state?

This is as if the blocking was obeyed, but doesn't
burn CPU time. Only a debugger should be able to
tell the difference.




^ permalink raw reply	[flat|nested] 8+ messages in thread
* Signal left blocked after signal handler.
@ 2003-11-26 17:39 Bruce Perens
  2003-11-26 17:55 ` Linus Torvalds
  0 siblings, 1 reply; 8+ messages in thread
From: Bruce Perens @ 2003-11-26 17:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: torvalds

Hi,

A signal should be blocked while its signal handler is executing, and
then unblocked when the handler returns - unless SA_NOMASK is set.

-test9 and -test10 leave the signal _blocked_forever_.

This causes the build-time confidence test for Electric Fence to break,
and no doubt lots of other code.

If SA_NOMASK is set, the signal is not blocked.

Test program attached below.

	Thanks

	Bruce

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <setjmp.h>

static sigjmp_buf	sjbuf;
static int		sig = SIGINT;

static void
handler(int i)
{
	struct sigaction	act;

	memset((void *)&act, 0, sizeof(act));
	act.sa_handler = SIG_DFL;

	fprintf(stderr, "Signal handler hit!\n");
	fflush(stderr);
	sigaction(sig, &act, 0);
	siglongjmp(sjbuf, 1);

}

static void
invoke_signal()
{
	struct sigaction	act;

	memset((void *)&act, 0, sizeof(act));
	act.sa_handler = handler;

	/* act.sa_flags = SA_NOMASK; */

	if ( sigsetjmp(sjbuf, 0) == 0 ) {
		sigaction(sig, &act, 0);
		fprintf(stderr, "Sending signal... ");
		fflush(stderr);
		kill(getpid(), sig);
		fprintf(stderr, "Huh? Nothing happened. Signal was left blocked.\n");
	}
}

int
main(int argc, char * * argv)
{
	sigset_t	set;

	sigemptyset(&set);
	sigaddset(&set, sig);

	invoke_signal();
	invoke_signal();
	fprintf(stderr, "Unblocking signal... ");
	if ( sigsetjmp(sjbuf, 0) == 0 ) {
		sigprocmask(SIG_UNBLOCK,  &set, 0);
	}

	return 0;
}

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-11-27 17:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-26 21:53 Never mind. Re: Signal left blocked after signal handler Albert Cahalan
2003-11-27  9:11 ` Ingo Oeser
2003-11-27 15:45   ` Albert Cahalan
2003-11-27 17:26     ` Jörn Engel
  -- strict thread matches above, loose matches on Subject: below --
2003-11-26 17:39 Bruce Perens
2003-11-26 17:55 ` Linus Torvalds
     [not found]   ` <3FC4ED5F.4090901@perens.com>
     [not found]     ` <3FC4EF24.9040307@perens.com>
     [not found]       ` <3FC4F248.8060307@perens.com>
2003-11-26 18:45         ` Never mind. " Linus Torvalds
2003-11-26 19:04           ` Bruce Perens
2003-11-26 19:14             ` Linus Torvalds
2003-11-26 19:52               ` Jamie Lokier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).