Re: SIGPIPE handling - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: SIGPIPE handling
Date
Msg-id 200401081653.i08Grrq21700@candle.pha.pa.us
Whole thread Raw
In response to Re: SIGPIPE handling  (Manfred Spraul <manfred@colorfullife.com>)
List pgsql-patches
Manfred Spraul wrote:
> Bruce Momjian wrote:
>
> >>
> >>+     /*
> >>+      *    We could lose a signal during this test.
> >>+      *    In a multi-threaded application, this might
> >>+      *    be a problem.  Do any non-threaded platforms
> >>
> Threaded or non-threaded?
>
> >>+      *    lack sigaction()?
> >>+      */
> >>
> Additionally, the problem is not restricted to multithreaded apps:
> signal(,SIG_IGN) clears all pending signals.

OK, new function using sigblock():

    pqsigfunc
    pqsignalinquire(int signo)
    {
    #if !defined(HAVE_POSIX_SIGNALS)
        pqsigfunc old_sigfunc;
        int     old_sigmask;

        /* Prevent signal handler calls during test */
        old_sigmask = sigblock(sigmask(signo));
        old_sigfunc = signal(signo, SIG_DFL);
        signal(signo, old_sigfunc);
        sigblock(old_sigmask);
        return old_sigfunc;
    #else
        struct sigaction oact;

        if (sigaction(signo, NULL, &oact) < 0)
           return SIG_ERR;
        return oact.sa_handler;
    #endif   /* !HAVE_POSIX_SIGNALS */
    }

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: SIGPIPE handling
Next
From: Bruce Momjian
Date:
Subject: Re: psql \i handling ~ in specified file name