You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ma...@hyperreal.org on 1998/09/15 02:15:21 UTC

cvs commit: apache-1.3/src/main http_log.c http_main.c

martin      98/09/14 17:15:20

  Modified:    src      CHANGES
               src/main http_log.c http_main.c
  Log:
  When the server shuts down cleanly, it also removes the httpd.pid PID file.
  This avoids the problem that apachectl cannot decide whether a "kill -0 pid"
  failed because of permissions (or system restrictions) or because the pid
  doesn't exist. Upon startup, an info msg is logged if an old PID file remains.
  
  PR: 2947
  Submitted by:	Charles Randall <cr...@matchlogic.com>
  Reviewed by:	Martin Kraemer, Dean Gaudet
  
  Revision  Changes    Path
  1.1058    +3 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1057
  retrieving revision 1.1058
  diff -u -r1.1057 -r1.1058
  --- CHANGES	1998/09/12 11:26:00	1.1057
  +++ CHANGES	1998/09/15 00:15:16	1.1058
  @@ -1,5 +1,8 @@
   Changes with Apache 1.3.2
   
  +  *) Delete PID file on clean shutdowns.
  +     [Charles Randall <cr...@matchlogic.com>] PR#2947
  +
     *) Fix mod_auth_*.html documents: NSCA -> NCSA
        [Youichirou Koga <y-...@jp.FreeBSD.org>] PR#2991
   
  
  
  
  1.66      +22 -1     apache-1.3/src/main/http_log.c
  
  Index: http_log.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/main/http_log.c,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- http_log.c	1998/09/10 06:58:19	1.65
  +++ http_log.c	1998/09/15 00:15:18	1.66
  @@ -446,16 +446,37 @@
   void ap_log_pid (pool *p, char *fname)
   {
       FILE *pid_file;
  +    struct stat finfo;
  +    static pid_t saved_pid = -1;
  +    pid_t mypid;
   
       if (!fname) return;
  +
       fname = ap_server_root_relative (p, fname);
  +    mypid = getpid();
  +    if (mypid != saved_pid && stat(fname,&finfo) == 0) {
  +      /* USR1 and HUP call this on each restart.
  +       * Only warn on first time through for this pid.
  +       *
  +       * XXX: Could just write first time through too, although
  +       *      that may screw up scripts written to do something
  +       *      based on the last modification time of the pid file.
  +       */
  +      ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL,
  +		   ap_psprintf(p,
  +			       "pid file %s overwritten -- Unclean shutdown of previous apache run?",
  +			       fname)
  +		   );
  +    }
  +
       if(!(pid_file = fopen(fname,"w"))) {
   	perror("fopen");
           fprintf(stderr,"httpd: could not log pid to file %s\n", fname);
           exit(1);
       }
  -    fprintf(pid_file,"%ld\n",(long)getpid());
  +    fprintf(pid_file,"%ld\n",(long)mypid);
       fclose(pid_file);
  +    saved_pid = mypid;
   }
   
   API_EXPORT(void) ap_log_error_old (const char *err, server_rec *s)
  
  
  
  1.390     +11 -1     apache-1.3/src/main/http_main.c
  
  Index: http_main.c
  ===================================================================
  RCS file: /export/home/cvs/apache-1.3/src/main/http_main.c,v
  retrieving revision 1.389
  retrieving revision 1.390
  diff -u -r1.389 -r1.390
  --- http_main.c	1998/09/10 17:38:00	1.389
  +++ http_main.c	1998/09/15 00:15:19	1.390
  @@ -4288,9 +4288,19 @@
   		ap_log_error(APLOG_MARK, APLOG_WARNING, server_conf, "killpg SIGTERM");
   	    }
   	    reclaim_child_processes(1);		/* Start with SIGTERM */
  +
  +	    /* cleanup pid file on normal shutdown */
  +	    {
  +		const char *pidfile = NULL;
  +		pidfile = ap_server_root_relative (pconf, ap_pid_fname);
  +		if ( pidfile != NULL && unlink(pidfile) == 0)
  +		    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, server_conf,
  +				 "httpd: removed PID file %s (pid=%d)",
  +				 pidfile, getpid());
  +	    }
  +
   	    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_NOTICE, server_conf,
   			"httpd: caught SIGTERM, shutting down");
  -
   	    clean_parent_exit(0);
   	}