Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Apr 95 14:50:45 +0200
From:      rw@namu01.gwdg.de (Rainer Wittmann UMS)
To:        bugs@FreeBSD.org
Subject:   signal handling bug
Message-ID:  <9504201250.AA26059@namu01.gwdg.de>

next in thread | raw e-mail | index | archive | help
Any unix system, I know, except FreeBSD 2.0, behaves as follows,
if a process is reading from a slow device like standard input from
a terminal. If this process receives a signal, for which a signal
handler was installed by the process, then immediately control
is tranferred to the signal handler (FreeBSD does this as well).
After the signal was serviced, the read system call is termianted
and errno is set to EINTR. Rather then doing this, FreeBSD completes
the read system call, as if no signal would have arrived. This
misbehavior breaks some of may programs. No matter, how often
it gets a signal. It NEVER sets errno to EINTR. This behavior
also contradicts the man page of read.
To verify the above, run the program below and press `ctrl-c'
or send SIGINT to it. On FreeBSD it doesn't immediately terminate
as it does on any other unix.

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


void	SIGINT_handler(void)
{
	signal(SIGINT, (void (*)(int))SIGINT_handler);
	fprintf(stdout, "\nSIGINT received\n");
}

char	chr;

void	main(void)
{
	signal(SIGINT, (void (*)(int))SIGINT_handler);
	errno = 0;
	read(0, &chr, 1);
	if( errno == EINTR ) fprintf(stdout, "errno = EINTR\n");
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9504201250.AA26059>