You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Stanley Gambarin <st...@cs.bu.edu> on 1997/07/10 03:22:11 UTC

stdin/stdout/stderr_FILENO's

	This is NOT a bug..

	Currently, some of the modules make an implicit assumption that
file descriptors are matched as follows: stdin = 0, stdout = 1, stderr=2.
Even though it is true for most (all Unix) systems, Stevens suggests
using STD[IN|OUT|ERR}_FILENO defines instead to provide better
portability.  The following diffs hange those.  Note, that the defines
are declared in unistd.h (on Solaris, at least), which is included by
buff.h, which itself is included by httpd.h, which is included by most
modules, so they should always be defined (I think)...
						Stanley.

*** mod_cgi.c	Wed Jul  9 21:08:57 1997
--- mod_cgi2.c	Wed Jul  9 21:07:50 1997
***************
*** 336,342 ****
      ap_snprintf(err_string, sizeof(err_string),
  	    "exec of %s failed, reason: %s (errno = %d)\n", 
              r->filename, strerror(errno), errno);
!     write(STDERR_FILENO, err_string, strlen(err_string));
      exit(0);
      /* NOT REACHED */
      return(0);
--- 336,342 ----
      ap_snprintf(err_string, sizeof(err_string),
  	    "exec of %s failed, reason: %s (errno = %d)\n", 
              r->filename, strerror(errno), errno);
!     write(2, err_string, strlen(err_string));
      exit(0);
      /* NOT REACHED */
      return(0);



*** mod_include.c	Wed Jul  9 21:10:51 1997
--- mod_include2.c	Wed Jul  9 21:07:59 1997
***************
*** 663,669 ****
      ap_snprintf(err_string, sizeof(err_string),
  	"httpd: exec of %s failed, reason: %s (errno = %d)\n",
  	SHELL_PATH, strerror(errno), errno);
!     write (STDERR_FILENO, err_string, strlen(err_string));
      exit(0);
      /* NOT REACHED */
      return(child_pid);
--- 663,669 ----
      ap_snprintf(err_string, sizeof(err_string),
  	"httpd: exec of %s failed, reason: %s (errno = %d)\n",
  	SHELL_PATH, strerror(errno), errno);
!     write (2, err_string, strlen(err_string));
      exit(0);
      /* NOT REACHED */
      return(child_pid);


*** mod_mime_magic.c	Wed Jul  9 21:13:14 1997
--- mod_mime_magic2.c	Wed Jul  9 21:08:14 1997
***************
*** 2291,2307 ****
      }
      switch (fork()) {
      case 0:        /* child */
!         (void) close(STDIN_FILENO);
          (void) dup(fdin[0]);
          (void) close(fdin[0]);
          (void) close(fdin[1]);
  
!         (void) close(STDOUT_FILENO)
          (void) dup(fdout[1]);
          (void) close(fdout[0]);
          (void) close(fdout[1]);
          if (compr[method].silent)
!             (void) close(STDERR_FILENO);
  
          execvp(compr[method].argv[0], compr[method].argv);
          log_printf(s, "%s: could not execute `%s' (%s).\n", MODNAME,
--- 2291,2307 ----
      }
      switch (fork()) {
      case 0:        /* child */
!         (void) close(0);
          (void) dup(fdin[0]);
          (void) close(fdin[0]);
          (void) close(fdin[1]);
  
!         (void) close(1);
          (void) dup(fdout[1]);
          (void) close(fdout[0]);
          (void) close(fdout[1]);
          if (compr[method].silent)
!             (void) close(2);
  
          execvp(compr[method].argv[0], compr[method].argv);
          log_printf(s, "%s: could not execute `%s' (%s).\n", MODNAME,


Re: stdin/stdout/stderr_FILENO's

Posted by Dean Gaudet <dg...@arctic.org>.
We already use foo_FILENO in alloc.c so portability isn't a concern.  I
applied your patch, thanks.

Dean

On Wed, 9 Jul 1997, Stanley Gambarin wrote:

> 	Currently, some of the modules make an implicit assumption that
> file descriptors are matched as follows: stdin = 0, stdout = 1, stderr=2.
> Even though it is true for most (all Unix) systems, Stevens suggests
> using STD[IN|OUT|ERR}_FILENO defines instead to provide better
> portability.  The following diffs hange those.  Note, that the defines
> are declared in unistd.h (on Solaris, at least), which is included by
> buff.h, which itself is included by httpd.h, which is included by most
> modules, so they should always be defined (I think)...
> 						Stanley.