httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dean Gaudet <dgau...@arctic.org>
Subject [PATCH] errno cleanup
Date Thu, 20 Mar 1997 23:55:49 GMT
At Roy's request I redid this patch.  I removed the herror() stuff since
that proved to be non-portable, and so we don't want it in this late
in the cycle.  This patch corrects a bunch of cases where we would call
perror() after possibly stomping on errno.  It also adds some perror()
calls to places where they are useful.

Dean

Index: CHANGES
===================================================================
RCS file: /export/home/cvs/apache/src/CHANGES,v
retrieving revision 1.208
diff -c -3 -r1.208 CHANGES
*** CHANGES	1997/03/20 23:30:48	1.208
--- CHANGES	1997/03/20 23:47:32
***************
*** 1,5 ****
--- 1,10 ----
  Changes with Apache 1.2b8
  
+   *) Report extra info from errno with many errors that cause httpd to exit.
+      spawn_child, popenf, and pclosef now have valid errno returns in the
+      event of an error.  Correct problems where errno was stomped on
+      before being reported.  [Dean Gaudet]
+ 
    *) In the proxy, if the cache filesystem was full, garbage_coll() was
       never called, and thus the filesystem would remain full indefinitely.
       We now also remove incomplete cache files left if the origin server
Index: alloc.c
===================================================================
RCS file: /export/home/cvs/apache/src/alloc.c,v
retrieving revision 1.24
diff -c -3 -r1.24 alloc.c
*** alloc.c	1997/03/20 17:10:10	1.24
--- alloc.c	1997/03/20 23:47:32
***************
*** 791,812 ****
--- 791,818 ----
  int popenf(pool *a, const char *name, int flg, int mode)
  {
    int fd;
+   int save_errno;
  
    block_alarms();
    fd = open(name, flg, mode);
+   save_errno = errno;
    if (fd >= 0) note_cleanups_for_fd (a, fd);
    unblock_alarms();
+   errno = save_errno;
    return fd;
  }
  
  int pclosef(pool *a, int fd)
  {
    int res;
+   int save_errno;
    
    block_alarms();
    res = close(fd);
+   save_errno = errno;
    kill_cleanup(a, (void *)fd, fd_cleanup);
    unblock_alarms();
+   errno = save_errno;
    return res;
  }
  
***************
*** 927,950 ****
--- 933,962 ----
    int in_fds[2];
    int out_fds[2];
    int err_fds[2];
+   int save_errno;
  
    block_alarms();
    
    if (pipe_in && pipe (in_fds) < 0)
    {
+       save_errno = errno;
        unblock_alarms();
+       errno = save_errno;
        return 0;
    }
    
    if (pipe_out && pipe (out_fds) < 0) {
+     save_errno = errno;
      if (pipe_in) {
        close (in_fds[0]); close (in_fds[1]);
      }
      unblock_alarms();
+     errno = save_errno;
      return 0;
    }
  
    if (pipe_err && pipe (err_fds) < 0) {
+     save_errno = errno;
      if (pipe_in) {
        close (in_fds[0]); close (in_fds[1]);
      }
***************
*** 952,961 ****
--- 964,975 ----
        close (out_fds[0]); close (out_fds[1]);
      }
      unblock_alarms();
+     errno = save_errno;
      return 0;
    }
  
    if ((pid = fork()) < 0) {
+     save_errno = errno;
      if (pipe_in) {
        close (in_fds[0]); close (in_fds[1]);
      }
***************
*** 966,971 ****
--- 980,986 ----
        close (err_fds[0]); close (err_fds[1]);
      }
      unblock_alarms();
+     errno = save_errno;
      return 0;
    }
  
Index: http_config.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_config.c,v
retrieving revision 1.46
diff -c -3 -r1.46 http_config.c
*** http_config.c	1997/03/20 23:30:48	1.46
--- http_config.c	1997/03/20 23:47:33
***************
*** 759,767 ****
      parms.override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
      
      if(!(cfg = fopen(fname, "r"))) {
          fprintf(stderr,"httpd: could not open document config file %s\n",
                  fname);
-         perror("fopen");
          exit(1);
      } 
  
--- 759,767 ----
      parms.override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
      
      if(!(cfg = fopen(fname, "r"))) {
+         perror("fopen");
          fprintf(stderr,"httpd: could not open document config file %s\n",
                  fname);
          exit(1);
      } 
  
***************
*** 931,938 ****
      getrlimit ( RLIMIT_NOFILE, &limits );
      if ( limits.rlim_cur < limits.rlim_max ) {
        limits.rlim_cur += 2;
!       if ( setrlimit ( RLIMIT_NOFILE, &limits ) < 0 )
  	fprintf (stderr, "Cannot exceed hard limit for open files");
      }
  #endif
  
--- 931,940 ----
      getrlimit ( RLIMIT_NOFILE, &limits );
      if ( limits.rlim_cur < limits.rlim_max ) {
        limits.rlim_cur += 2;
!       if ( setrlimit ( RLIMIT_NOFILE, &limits ) < 0 ) {
! 	perror ("setrlimit(RLIMIT_NOFILE)");
  	fprintf (stderr, "Cannot exceed hard limit for open files");
+       }
      }
  #endif
  
Index: http_log.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_log.c,v
retrieving revision 1.12
diff -c -3 -r1.12 http_log.c
*** http_log.c	1997/01/10 09:34:41	1.12
--- http_log.c	1997/03/20 23:47:33
***************
*** 92,110 ****
      if (*s->error_fname == '|') {
        FILE *dummy;
  
!       spawn_child(p, error_log_child, (void *)(s->error_fname+1),
!                     kill_after_timeout, &dummy, NULL);
! 
!         if (dummy == NULL) {
!             fprintf (stderr, "Couldn't fork child for ErrorLog process\n");
!             exit (1);
        }
  
        s->error_log = dummy;
      } else {
          if(!(s->error_log = pfopen(p, fname, "a"))) {
-             fprintf(stderr,"httpd: could not open error log file %s.\n", fname);
              perror("fopen");
              exit(1);
        }
      }
--- 92,109 ----
      if (*s->error_fname == '|') {
        FILE *dummy;
  
!       if (!spawn_child (p, error_log_child, (void *)(s->error_fname+1),
!                     kill_after_timeout, &dummy, NULL)) {
! 	perror ("spawn_child");
! 	fprintf (stderr, "Couldn't fork child for ErrorLog process\n");
! 	exit (1);
        }
  
        s->error_log = dummy;
      } else {
          if(!(s->error_log = pfopen(p, fname, "a"))) {
              perror("fopen");
+             fprintf(stderr,"httpd: could not open error log file %s.\n", fname);
              exit(1);
        }
      }
Index: http_main.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_main.c,v
retrieving revision 1.132
diff -c -3 -r1.132 http_main.c
*** http_main.c	1997/03/20 23:30:49	1.132
--- http_main.c	1997/03/20 23:47:33
***************
*** 774,781 ****
  #endif
      if (scoreboard_fd == -1)
      {
- 	fprintf (stderr, "Cannot open scoreboard file:\n");
  	perror (scoreboard_fname);
  	exit (1);
      }
  
--- 774,781 ----
  #endif
      if (scoreboard_fd == -1)
      {
  	perror (scoreboard_fname);
+ 	fprintf (stderr, "Cannot open scoreboard file:\n");
  	exit (1);
      }
  
***************
*** 800,807 ****
  #endif
      if (scoreboard_fd == -1)
      {
- 	fprintf (stderr, "Cannot open scoreboard file:\n");
  	perror (scoreboard_fname);
  	exit (1);
      }
  #else
--- 800,807 ----
  #endif
      if (scoreboard_fd == -1)
      {
  	perror (scoreboard_fname);
+ 	fprintf (stderr, "Cannot open scoreboard file:\n");
  	exit (1);
      }
  #else
***************
*** 1192,1213 ****
      if((x = fork()) > 0)
          exit(0);
      else if(x == -1) {
-         fprintf(stderr,"httpd: unable to fork new process\n");
          perror("fork");
          exit(1);
      }
  #endif
  #ifndef NO_SETSID
      if((pgrp=setsid()) == -1) {
-         fprintf(stderr,"httpd: setsid failed\n");
          perror("setsid");
          exit(1);
      }
  #else
  #if defined(NEXT)
      if(setpgrp(0,getpid()) == -1 || (pgrp = getpgrp(0)) == -1) {
-         fprintf(stderr,"httpd: setpgrp or getpgrp failed\n");
          perror("setpgrp");
          exit(1);
      }
  #else
--- 1192,1213 ----
      if((x = fork()) > 0)
          exit(0);
      else if(x == -1) {
          perror("fork");
+         fprintf(stderr,"httpd: unable to fork new process\n");
          exit(1);
      }
  #endif
  #ifndef NO_SETSID
      if((pgrp=setsid()) == -1) {
          perror("setsid");
+         fprintf(stderr,"httpd: setsid failed\n");
          exit(1);
      }
  #else
  #if defined(NEXT)
      if(setpgrp(0,getpid()) == -1 || (pgrp = getpgrp(0)) == -1) {
          perror("setpgrp");
+         fprintf(stderr,"httpd: setpgrp or getpgrp failed\n");
          exit(1);
      }
  #else
***************
*** 1216,1223 ****
      pgrp=-getpid();
  #else
      if((pgrp=setpgrp(getpid(),0)) == -1) {
-         fprintf(stderr,"httpd: setpgrp failed\n");
          perror("setpgrp");
          exit(1);
      }
  #endif    
--- 1216,1223 ----
      pgrp=-getpid();
  #else
      if((pgrp=setpgrp(getpid(),0)) == -1) {
          perror("setpgrp");
+         fprintf(stderr,"httpd: setpgrp failed\n");
          exit(1);
      }
  #endif    
***************
*** 1570,1577 ****
      int just_say_no = 1;
  
      if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&just_say_no,
!                    sizeof(int)) < 0)
  	fprintf(stderr, "httpd: could not set socket option TCP_NODELAY\n");
  }
  #else
  #define sock_disable_nagle(s) /* NOOP */
--- 1570,1579 ----
      int just_say_no = 1;
  
      if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&just_say_no,
!                    sizeof(int)) < 0) {
! 	perror ("setsockopt(TCP_NODELAY)");
  	fprintf(stderr, "httpd: could not set socket option TCP_NODELAY\n");
+     }
  }
  #else
  #define sock_disable_nagle(s) /* NOOP */
***************
*** 1932,1941 ****
  #endif
      if(bind(s, (struct sockaddr *)server,sizeof(struct sockaddr_in)) == -1)
      {
  #ifdef MPE
          if (ntohs(server->sin_port) < 1024) GETUSERMODE();
  #endif
-         perror("bind");
  	if (server->sin_addr.s_addr != htonl(INADDR_ANY))
  	    fprintf(stderr,"httpd: could not bind to address %s port %d\n",
  		    inet_ntoa(server->sin_addr), ntohs(server->sin_port));
--- 1934,1943 ----
  #endif
      if(bind(s, (struct sockaddr *)server,sizeof(struct sockaddr_in)) == -1)
      {
+         perror("bind");
  #ifdef MPE
          if (ntohs(server->sin_port) < 1024) GETUSERMODE();
  #endif
  	if (server->sin_addr.s_addr != htonl(INADDR_ANY))
  	    fprintf(stderr,"httpd: could not bind to address %s port %d\n",
  		    inet_ntoa(server->sin_addr), ntohs(server->sin_port));
Index: mod_log_agent.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_log_agent.c,v
retrieving revision 1.10
diff -c -3 -r1.10 mod_log_agent.c
*** mod_log_agent.c	1997/03/07 14:15:42	1.10
--- mod_log_agent.c	1997/03/20 23:47:33
***************
*** 111,116 ****
--- 111,118 ----
  #else    
      execl (SHELL_PATH, SHELL_PATH, "-c", (char *)cmd, NULL);
  #endif    
+     perror ("exec");
+     fprintf (stderr, "Exec of shell for logging failed!!!\n");
      exit (1);
  }
  
***************
*** 126,135 ****
      if (*cls->fname == '|') {
  	FILE *dummy;
  	
! 	spawn_child(p, agent_log_child, (void *)(cls->fname+1),
! 		    kill_after_timeout, &dummy, NULL);
! 
! 	if (dummy == NULL) {
  	    fprintf (stderr, "Couldn't fork child for AgentLog process\n");
  	    exit (1);
  	}
--- 128,136 ----
      if (*cls->fname == '|') {
  	FILE *dummy;
  	
! 	if (!spawn_child (p, agent_log_child, (void *)(cls->fname+1),
! 		    kill_after_timeout, &dummy, NULL)) {
! 	    perror ("spawn_child");
  	    fprintf (stderr, "Couldn't fork child for AgentLog process\n");
  	    exit (1);
  	}
***************
*** 138,145 ****
      }
      else if(*cls->fname != '\0') {
        if((cls->agent_fd = popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
-         fprintf(stderr,"httpd: could not open agent log file %s.\n", fname);
          perror("open");
          exit(1);
        }
      }
--- 139,146 ----
      }
      else if(*cls->fname != '\0') {
        if((cls->agent_fd = popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
          perror("open");
+         fprintf(stderr,"httpd: could not open agent log file %s.\n", fname);
          exit(1);
        }
      }
Index: mod_log_config.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_log_config.c,v
retrieving revision 1.25
diff -c -3 -r1.25 mod_log_config.c
*** mod_log_config.c	1997/03/07 14:15:42	1.25
--- mod_log_config.c	1997/03/20 23:47:34
***************
*** 687,692 ****
--- 687,693 ----
  #else
      execl (SHELL_PATH, SHELL_PATH, "-c", (char *)cmd, NULL);
  #endif
+     perror ("exec");
      fprintf (stderr, "Exec of shell for logging failed!!!\n");
      exit (1);
  }
***************
*** 699,708 ****
      if (*cls->fname == '|') {
          FILE *dummy;
          
!         spawn_child(p, config_log_child, (void *)(cls->fname+1),
!                     kill_after_timeout, &dummy, NULL);
! 
!         if (dummy == NULL) {
              fprintf (stderr, "Couldn't fork child for TransferLog process\n");
              exit (1);
          }
--- 700,708 ----
      if (*cls->fname == '|') {
          FILE *dummy;
          
!         if (!spawn_child (p, config_log_child, (void *)(cls->fname+1),
!                     kill_after_timeout, &dummy, NULL)) {
! 	    perror ("spawn_child");
              fprintf (stderr, "Couldn't fork child for TransferLog process\n");
              exit (1);
          }
***************
*** 712,720 ****
      else {
          char *fname = server_root_relative (p, cls->fname);
          if((cls->log_fd = popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
              fprintf (stderr,
                       "httpd: could not open transfer log file %s.\n", fname);
-             perror("open");
              exit(1);
          }
      }
--- 712,720 ----
      else {
          char *fname = server_root_relative (p, cls->fname);
          if((cls->log_fd = popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
+             perror("open");
              fprintf (stderr,
                       "httpd: could not open transfer log file %s.\n", fname);
              exit(1);
          }
      }
Index: mod_log_referer.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_log_referer.c,v
retrieving revision 1.10
diff -c -3 -r1.10 mod_log_referer.c
*** mod_log_referer.c	1997/03/07 14:15:42	1.10
--- mod_log_referer.c	1997/03/20 23:47:34
***************
*** 125,130 ****
--- 125,131 ----
  #else
      execl (SHELL_PATH, SHELL_PATH, "-c", (char *)cmd, NULL);
  #endif
+     perror ("execl");
      fprintf (stderr, "Exec of shell for logging failed!!!\n");
      exit (1);
  }
***************
*** 141,150 ****
      if (*cls->fname == '|') {
  	FILE *dummy;
  	
! 	spawn_child(p, referer_log_child, (void *)(cls->fname+1),
! 		    kill_after_timeout, &dummy, NULL);
! 
! 	if (dummy == NULL) {
  	    fprintf (stderr, "Couldn't fork child for RefererLog process\n");
  	    exit (1);
  	}
--- 142,150 ----
      if (*cls->fname == '|') {
  	FILE *dummy;
  	
! 	if (!spawn_child (p, referer_log_child, (void *)(cls->fname+1),
! 		    kill_after_timeout, &dummy, NULL)) {
! 	    perror ("spawn_child");
  	    fprintf (stderr, "Couldn't fork child for RefererLog process\n");
  	    exit (1);
  	}
***************
*** 153,160 ****
      }
      else if(*cls->fname != '\0') {
        if((cls->referer_fd = popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
-         fprintf(stderr,"httpd: could not open referer log file %s.\n", fname);
          perror("open");
          exit(1);
        }
      }
--- 153,160 ----
      }
      else if(*cls->fname != '\0') {
        if((cls->referer_fd = popenf(p, fname, xfer_flags, xfer_mode)) < 0) {
          perror("open");
+         fprintf(stderr,"httpd: could not open referer log file %s.\n", fname);
          exit(1);
        }
      }
Index: mod_mime.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_mime.c,v
retrieving revision 1.16
diff -c -3 -r1.16 mod_mime.c
*** mod_mime.c	1997/03/07 14:15:42	1.16
--- mod_mime.c	1997/03/20 23:47:34
***************
*** 193,201 ****
      types_confname = server_root_relative (p, types_confname);
  
      if(!(f = fopen(types_confname,"r"))) {
          fprintf(stderr,"httpd: could not open mime types file %s\n",
                  types_confname);
-         perror("fopen");
          exit(1);
      }
  
--- 193,201 ----
      types_confname = server_root_relative (p, types_confname);
  
      if(!(f = fopen(types_confname,"r"))) {
+         perror("fopen");
          fprintf(stderr,"httpd: could not open mime types file %s\n",
                  types_confname);
          exit(1);
      }
  
Index: mod_rewrite.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_rewrite.c,v
retrieving revision 1.22
diff -c -3 -r1.22 mod_rewrite.c
*** mod_rewrite.c	1997/03/20 18:03:35	1.22
--- mod_rewrite.c	1997/03/20 23:47:35
***************
*** 2250,2258 ****
      fname = server_root_relative(p, conf->rewritelogfile);
      
      if (*conf->rewritelogfile == '|') {
!         spawn_child(p, rewritelog_child, (void *)(conf->rewritelogfile+1),
!                     kill_after_timeout, &fp, NULL);
!         if (fp == NULL) {
              fprintf (stderr, "mod_rewrite: could not fork child for RewriteLog process\n");
              exit (1);
          }
--- 2250,2258 ----
      fname = server_root_relative(p, conf->rewritelogfile);
      
      if (*conf->rewritelogfile == '|') {
!         if (!spawn_child (p, rewritelog_child, (void *)(conf->rewritelogfile+1),
!                     kill_after_timeout, &fp, NULL)) {
! 	    perror ("spawn_child");
              fprintf (stderr, "mod_rewrite: could not fork child for RewriteLog process\n");
              exit (1);
          }
***************
*** 2260,2267 ****
      }
      else if (*conf->rewritelogfile != '\0') {
          if ((conf->rewritelogfp = popenf(p, fname, rewritelog_flags, rewritelog_mode))
< 0) {
-             fprintf(stderr, "mod_rewrite: could not open RewriteLog file %s.\n", fname);
              perror("open");
              exit(1);
          }
      }
--- 2260,2267 ----
      }
      else if (*conf->rewritelogfile != '\0') {
          if ((conf->rewritelogfp = popenf(p, fname, rewritelog_flags, rewritelog_mode))
< 0) {
              perror("open");
+             fprintf(stderr, "mod_rewrite: could not open RewriteLog file %s.\n", fname);
              exit(1);
          }
      }
***************
*** 2405,2410 ****
--- 2405,2411 ----
          fpout = NULL;
          rc = spawn_child(p, rewritemap_program_child, (void *)map->datafile, kill_after_timeout,
&fpin, &fpout);
          if (rc == 0 || fpin == NULL || fpout == NULL) {
+ 	    perror ("spawn_child");
              fprintf (stderr, "mod_rewrite: could not fork child for RewriteMap process\n");
              exit (1);
          }
***************
*** 3216,3221 ****
--- 3217,3223 ----
  #endif
  
      if (rc < 0) {
+ 	perror ("flock");
          fprintf(stderr, "Error getting lock. Exiting!");
          exit(1);
      }
***************
*** 3240,3245 ****
--- 3242,3248 ----
  #endif 
  
      if (rc < 0) {
+ 	perror ("flock");
          fprintf(stderr, "Error freeing lock. Exiting!");
          exit(1);
      }
Index: util.c
===================================================================
RCS file: /export/home/cvs/apache/src/util.c,v
retrieving revision 1.50
diff -c -3 -r1.50 util.c
*** util.c	1997/03/20 17:10:09	1.50
--- util.c	1997/03/20 23:47:35
***************
*** 1129,1136 ****
  
      len = sizeof(struct sockaddr);
      if(getsockname(sd,&addr,&len) < 0) {
-         fprintf (stderr, "Can't get local host address!\n");
  	perror ("getsockname");
  	exit(1);
      }
           
--- 1129,1136 ----
  
      len = sizeof(struct sockaddr);
      if(getsockname(sd,&addr,&len) < 0) {
  	perror ("getsockname");
+         fprintf (stderr, "Can't get local host address!\n");
  	exit(1);
      }
           



Mime
View raw message