Am Freitag, 2. April 2004 19:45 schrieb Juergen Spitzmueller:
> errno is ECHILD (no child processes), so your guess is probably right.
> OTOH man popen says: "If pclose() cannot obtain the child status, errno is 
set 
> to ECHILD", which sounds a bit vague.

Yes, it seems that it does not tell all information we need. And the sun 
manpage that you cited in your other mail tells something similar.

> Is the attached safe? It sets pret to 0 when errno is ECHILD and fixes the 
> bug. It also prints out an error message both when popen does not succeed 
and 
> when pclose gets an error (other than ECHILD).

As I understand it, it is not safe to assume that the child process was 
executed successfully if errno is ECHILD. The siginfo struct that can be 
obtained with sigwaitinfo() has probably the needed information. On linux, 
this struct and the following enum is defined in
/usr/include/bits/siginfo.h:


/* `si_code' values for SIGCHLD signal.  */
enum
{
  CLD_EXITED = 1,               /* Child has exited.  */
# define CLD_EXITED     CLD_EXITED
  CLD_KILLED,                   /* Child was killed.  */
# define CLD_KILLED     CLD_KILLED
  CLD_DUMPED,                   /* Child terminated abnormally.  */
# define CLD_DUMPED     CLD_DUMPED
  CLD_TRAPPED,                  /* Traced child has trapped.  */
# define CLD_TRAPPED    CLD_TRAPPED
  CLD_STOPPED,                  /* Child has stopped.  */
# define CLD_STOPPED    CLD_STOPPED
  CLD_CONTINUED                 /* Stopped child has continued.  */
# define CLD_CONTINUED  CLD_CONTINUED
};


If we had the value of si_code, we could ignore the error for CLD_EXITED.
But I don't know if/how/when one could call sigwaitinfo() to obtain the 
desired information.


Georg

Reply via email to