Re: SIGCHLD and libpthread.so

Previous thread: Re: ASN Flow Exporter for OpenBGP device by Stuart Henderson on Friday, December 4, 2009 - 7:05 pm. (1 message)

Next thread: We have high quality MD and Dentist lists for less than five hundred bucks by megavolt Fournier on Saturday, December 5, 2009 - 1:45 am. (1 message)
From: Jun KAWAI
Date: Friday, December 4, 2009 - 8:42 pm

Hi,

I see that SIGCHLD which was sent before calling sigaction() for
SIGCHLD is delivered to the handler when program is linked to
libpthread.so.  However, this behavior doesn't occur when program
isn't linked to libpthread.so.

I feel the behavior of SIGCHLD when linked to libpthread.so
is strange, but I don't know whether the behavior is correct
or not.

Can anyone tell me what happened?


Best Regards,
Jun Kawai

------------------------------------------------------------------
% dmesg | head -2
OpenBSD 4.6-stable (GENERIC.MP) #0: Sat Dec  5 10:35:10 JST 2009
    kwj@cask.komos.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP
% cat SIGCHLD-test.c
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

void trap(int);
void puts_curtime(void);

int
main(int argc, char *argv[])
{
	pid_t pid;
	struct sigaction act, oact;

	puts_curtime();

	pid = fork();
	if (pid == 0) {
		sleep(1);
		_exit(0);
	} else if (pid == -1) {
		exit(1);
	} else {
		int status;
		waitpid(pid, &status, 0);
	}

	puts_curtime();
	sleep(5);
	puts_curtime();

	sigemptyset(&act.sa_mask);
	act.sa_handler = trap;
	act.sa_flags = 0;
	if (sigaction(SIGCHLD, &act, &oact) != 0) {
		exit(1);
	}

	sleep(5);

	if (sigaction(SIGCHLD, &oact, (struct sigaction *) 0) != 0) {
		exit(1);
	}

	puts_curtime();

	exit(0);
}

void
trap(int sig)
{
	printf("Received SIGCHLD - ");
	puts_curtime();

	return;
}

void
puts_curtime(void)
{
	time_t tloc;

	time(&tloc);
	puts(ctime(&tloc));

	return;
}

% cc -Wall -o SIGCHLD-test SIGCHLD-test.c
% cc -Wall -pthread -o SIGCHLD-test-thread SIGCHLD-test.c
% ldd ./SIGCHLD-test ./SIGCHLD-test-thread
./SIGCHLD-test:
	Start            End              Type Open Ref GrpRef Name
	0000000000400000 0000000000802000 exe  1    0   0      ./SIGCHLD-test
	000000020d2b6000 000000020d795000 rlib 0    1   0      /usr/lib/libc.so.51.0
	0000000201c00000 ...
From: Philip Guenther
Date: Tuesday, December 8, 2009 - 7:19 pm

It's a bug, due to how libpthread uses SIGCHLD to detect when a thread
blocked in wait*() should be unblocked.  The fix isn't entirely
trivial and I'm not going to have a chance to look at it closely for
quite a while, so please file a bug with "sendbug" so we don't lose
track of this if I forget about it.


Philip Guenther

From: Jun KAWAI
Date: Wednesday, December 9, 2009 - 12:47 pm

Thank you for your reply.  I'll file a bug report with sendbug.


Regards,
Jun Kawai

Previous thread: Re: ASN Flow Exporter for OpenBGP device by Stuart Henderson on Friday, December 4, 2009 - 7:05 pm. (1 message)

Next thread: We have high quality MD and Dentist lists for less than five hundred bucks by megavolt Fournier on Saturday, December 5, 2009 - 1:45 am. (1 message)