Re: SIGCHLD handler in Postgres C function.

From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
To: tgl(at)sss(dot)pgh(dot)pa(dot)us
Cc: spshealy(at)yahoo(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: SIGCHLD handler in Postgres C function.
Date: 2001-07-22 00:28:03
Message-ID: 20010722092803N.t-ishii@sra.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> spshealy(at)yahoo(dot)com writes:
> > I have written a postgres C function that
> > uses a popen linux system call. Orginally when I first tried it I kept
> > getting an ECHILD. I read a little bit more on the pclose function
> > and the wait system calls and discoverd that on LINUX if the signal
> > handler for SIGCHLD is set to SIG_IGN you will get the ECHILD error
> > on pclose(or wait4 for that matter). So I did some snooping around in
> > the postgres backend code and found that in the traffic cop that the
> > SIGCHLD signal handler is set to SIG_IGN. So in my C function right
> > before the popen call I set the signal handler for SIGCHLD to SIG_DFL
> > and right after the pclose I set it back to SIG_IGN. I tested this
> > and it seems to solve my problem.
>
> Hmm. A possibly related bit of ugliness can be found in
> src/backend/commands/dbcommands.c, where we ignore ECHILD after
> a system() call:
>
> ret = system(buf);
> /* Some versions of SunOS seem to return ECHILD after a system() call */
> if (ret != 0 && errno != ECHILD)
> {
>
> Interesting, no? I wonder whether we could get rid of that kluge
> if the signal handler was SIG_DFL rather than SIG_IGN. Can anyone
> try this on one of the affected versions of SunOS? (Tatsuo, you
> seem to have added the ECHILD exception on May 25 2000; the commit
> message mentions Solaris but not which version. Could you try it?)

It was Solaris 2.6.

>Subject: [HACKERS] Solaris 2.6 problems
>From: Tatsuo Ishii <t-ishii(at)sra(dot)co(dot)jp>
>To: pgsql-hackers(at)postgresql(dot)org
>Cc: t-ishii(at)sra(dot)co(dot)jp
>Date: Wed, 24 May 2000 18:28:25 +0900
>X-Mailer: Mew version 1.93 on Emacs 19.34 / Mule 2.3 (SUETSUMUHANA)
>
>Hi, I have encountered a really strange problem with PostgreSQL 7.0 on
>Solaris 2.6/Sparc. The problem is that createdb command or create
>database SQL always fails. Inspecting the output of truss shows that
>system() call in createdb() (commands/dbcomand.c) fails because
>waitid() system call in system() returns error no. 10 (ECHILD).
>
>This problem was not in 6.5.3, so I checked the source of it. The
>reason why 6.5.3's createdb worked was that it just ignored the return
>code of system()!
>
>It seems that we need to ignore an error from system() if the error is
>ECHILD on Solaris.
>
>Any idea?
>
>BTW, I have compiled PostgreSQL with egcs 2.95 with/without
>optimization.
>--
>Tatsuo Ishii
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message eCommerce Software Solutions Inc. 2001-07-22 04:19:11 Fw: Leaking Handles in Postgres 7.1.2 on Cygwin dll 1.3.2 on Win 2000
Previous Message Philip Warner 2001-07-22 00:22:48 Re: Incomplete idea about views and INSERT...RETURNING