This is the mail archive of the cygwin@sources.redhat.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Signal Handler Overwrites errno (or YACPP)


On Wed, Dec 27, 2000 at 11:59:00AM -0500, Jason Tishler wrote:
>On Fri, 10 Dec 1999 20:51:27 -0500, Chris Faylor wrote:
>> I've checked in changes that seem to fix this.  It was an interesting
>> problem.  read() was setting the EINTR errno but it was getting
>> overwritten by a signal handler because I've changed the way signal
>> handlers are called now.  Although, actually, I would not be surprised
>> to hear that this cropped up with B20.1 one time in a thousand too.
>> 
>> So, now, in some situations, I save the errno for restoration when
>> a signal handler returns.
>
>I am observing the same behavior as above but with select() and a SIGCHLD
>handler when PostgreSQL has multiple TCP/IP connections.  Unfortunately,
>this causes PostgreSQL's postmaster to abort since it perceives that
>select() has returned with an unexpected error.

It's extremely unlikely that the year-old post that you copied has any
bearing on this problem.

I've written a simple test case to verify that cygwin is saving and restoring
errno correctly and it seems to work fine.  It returns this:

ouch
errno 2
-1 = select ()
errno 4
read ready

The test case is included below.

cgf

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
#include <signal.h>

void ouch (int sig)
{
  puts ("ouch");
  open("qwoeurpoqweuiroqpwiuroqpweiur", 0);
  fprintf (stderr, "errno %d\n", errno);
}

int
main(int argc, char **argv)
{
    int i, fds[2];
    fd_set r;

    pipe(fds);
    signal(SIGCHLD, ouch);
    if (fork() == 0)
      {
	sleep (3);
	exit (0);
      }
    FD_ZERO(&r);
    FD_SET(fds[0], &r);
    /*close(fds[1]);*/
    fprintf(stderr, "%d = select ()\n", select(fds[0] + 1, &r, NULL, NULL, NULL));
    fprintf(stderr, "errno %d\n", errno);
    if (FD_ISSET(fds[0], &r))
	fprintf(stderr, "read ready\n");
    exit(0);
}

--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]