bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] addition: wait-process.h, wait-process.c


From: Bruno Haible
Subject: Re: [Bug-gnulib] addition: wait-process.h, wait-process.c
Date: Thu, 24 Apr 2003 14:40:05 +0200 (CEST)

Paul Eggert writes:

> There is also a convention that the return code is 126 if exec failed
> due to errno == ENOEXEC.

This convention is described in POSIX:2001 sections 2.8.2, 2.9 ("Shell
Command Language") and some commands ("nice", "nohup" etc) but is
*not* mentioned in the description of the function posix_spawn().
Therefore I think patching glibc's implementation of posix_spawn() to
support this convention - see appended patch - would be wrong.

Further, since in my programs
  1. I don't want to have behavioural differences between platforms
     with and platforms without posix_spawn(),
  2. I want to use posix_spawn() where available because it's designed
     to be more portable,
I cannot rely on or use this convention of 126.

> Also, some programs need to run code if waitpid fails with errno == EINTR.

If waitpid fails with errno == EINTR, a signal handler was run. The
program can run its code from within the signal handler, can't it?
Specifically, diffutils' checksigs() could call exit (EXIT_TROUBLE)
after longjmping back to main, no?

Or do you mean, the wait_subprocess function really needs to take an
additional argument
          void (*eintr_hook) (void)  ?

Bruno


*** glibc-cvs/sysdeps/posix/spawni.c    Mon Aug  5 13:24:44 2002
--- glibc-cvs/sysdeps/posix/spawni.c.126        Thu Apr 24 14:25:58 2003
***************
*** 1,5 ****
  /* Guts of POSIX spawn interface.  Generic POSIX.1 version.
!    Copyright (C) 2000,01,02 Free Software Foundation, Inc.
     This file is part of the GNU C Library.
  
     The GNU C Library is free software; you can redistribute it and/or
--- 1,5 ----
  /* Guts of POSIX spawn interface.  Generic POSIX.1 version.
!    Copyright (C) 2000-2003 Free Software Foundation, Inc.
     This file is part of the GNU C Library.
  
     The GNU C Library is free software; you can redistribute it and/or
***************
*** 34,39 ****
--- 34,44 ----
     normal program exit with the exit code 127.  */
  #define SPAWN_ERROR   127
  
+ /* POSIX:2001 XCU sections 2.8.2, 2.9 also specify that if fork() was
+    successful and the program to be executed exists but is not executable,
+    the exit code shall be 126, not 127.  */
+ #define SPAWN_ENOEXEC 126
+ 
  
  /* The file is accessible but it is not an executable file.  Invoke
     the shell to interpret it as a script.  */
***************
*** 208,214 ****
        script_execute (file, argv, envp);
  
        /* Oh, oh.  `execve' returns.  This is bad.  */
!       _exit (SPAWN_ERROR);
      }
  
    /* We have to search for FILE on the path.  */
--- 213,219 ----
        script_execute (file, argv, envp);
  
        /* Oh, oh.  `execve' returns.  This is bad.  */
!       _exit (errno == ENOEXEC ? SPAWN_ENOEXEC : SPAWN_ERROR);
      }
  
    /* We have to search for FILE on the path.  */
***************
*** 264,275 ****
             directory.  */
          break;
  
        default:
          /* Some other error means we found an executable file, but
             something went wrong executing it; return the error to our
             caller.  */
          _exit (SPAWN_ERROR);
!           }
      }
    while (*p++ != '\0');
  
--- 269,284 ----
             directory.  */
          break;
  
+       case ENOEXEC:
+         /* The file exists but is not executable.  */
+         _exit (SPAWN_ENOEXEC);
+ 
        default:
          /* Some other error means we found an executable file, but
             something went wrong executing it; return the error to our
             caller.  */
          _exit (SPAWN_ERROR);
!       }
      }
    while (*p++ != '\0');
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]