You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apache-bugdb@apache.org by Vladislav Malyshkin <ma...@mail1.nai.net> on 2000/02/29 04:30:01 UTC

Re: mod_jserv/5755: mod_jserv and -HUP

The following reply was made to PR mod_jserv/5755; it has been noted by GNATS.

From: Vladislav Malyshkin <ma...@mail1.nai.net>
To: Ed Korthof <ed...@cloudfactory.org>, apbugs@apache.org
Cc:  
Subject: Re: mod_jserv/5755: mod_jserv and -HUP
Date: Mon, 28 Feb 2000 22:27:18 -0500

 Hi, again.
 I am still experiencing the same problem, even without
 killall -HUP, just with apachectl restart , but much more seldom.
 Today is one of these days, so I looked at it.
 It looks like the main problem is with getppid()
 which is checked with 1 instead of 0.
 Allso I added -HUP handler,
 which is definitely OK because wrapper process
 does not use any apache handler anyway
 (the process is received by just calling fork
 without any apache setup calls)
 The following patch fixes all these problems.
 Vladislav
 
 
 --- ApacheJServ-1.1/src/c/jserv_wrapper_unix.c.orig Mon Feb 14 16:16:11 2000
 +++ ApacheJServ-1.1/src/c/jserv_wrapper_unix.c Mon Feb 28 22:16:09 2000
 @@ -98,10 +98,12 @@
  /* this is also used from the loop to kill JVM                               */
  void kill_hung_jvm(int signum) {
    int counter = 0;
 -
 +  const int jvm_pid_local=jvm_pid;
 +
    /* Is jvm is really started? If not - do nothing */
 -  if( jvm_pid == 0)
 +  if( jvm_pid_local == 0)
      return;
 +  jvm_pid=0;
 
    if( signum == 0) {
      jserv_error(JSERV_LOG_INFO, wrapper_data->config,
 @@ -112,18 +114,17 @@
    }
    /* IF JVM is not responding to connections, we can't do   *
     * anything but kill it.                                  */
 -  kill(jvm_pid, SIGTERM);
 +  kill(jvm_pid_local, SIGTERM);
 
    /* give the VM as long as five seconds to die gracefully */
    while (counter++ < 5) {
 -    if (waitpid(jvm_pid, NULL, WNOHANG) > 0)
 +    if (waitpid(jvm_pid_local, NULL, WNOHANG) > 0)
        break;
      sleep(1);
    }
 -  if( waitpid(jvm_pid,NULL,WNOHANG)==0 ) {
 -    kill(jvm_pid, SIGKILL);
 +  if( waitpid(jvm_pid_local,NULL,WNOHANG)==0 ) {
 +    kill(jvm_pid_local, SIGKILL);
    }
 -  jvm_pid=0;
  }
 
 
 @@ -199,6 +200,7 @@
      /* If we get a TERM signal, shut down the JVM nicely, then exit.
       */
      signal(SIGTERM, wrapper_shutdown);
 +    signal(SIGHUP, wrapper_shutdown);
 
      x = 5;
      while (binparams != NULL) {
 @@ -343,7 +345,7 @@
 
  #ifndef JSERV_STANDALONE
              /* did parent httpd die? */
 -            if(getppid() == 1) {
 +            if(getppid() == 0) {
                  jserv_error(JSERV_LOG_INFO,wrapper_data->config,
                              "wrapper: Apache exited, cleaning up (PID=%d)",
                              getpid());
 @@ -477,30 +479,32 @@
  /* ========================================================================= */
  /* This does the actual cleanup */
  int wrapper_shutdown_core(wrapper_config *cfg) {
 -    if (jvm_pid != 0) {
 +  const int jvm_pid_local=jvm_pid;
 +    if (jvm_pid_local != 0) {
          int counter = 0;
 +        jvm_pid=0;
          jserv_error(JSERV_LOG_INFO,wrapper_data->config,
                      "wrapper: Terminating JServ (PID=%d, VM PID=%d)",
 -                    getpid(), jvm_pid);
 +                    getpid(), jvm_pid_local);
          /* Send shutdown function */
          jserv_protocol_function(cfg->config->protocol,cfg->config,
                                  JSERV_SHUTDOWN,NULL);
          /* Wait for child to go down */
 -        while (waitpid(jvm_pid,NULL,WNOHANG)==0) {
 +        while (waitpid(jvm_pid_local,NULL,WNOHANG)==0) {
              /* give it a little while to shut down gracefully. Then kill it. */
              if (++counter > cfg->config->vmtimeout) {
                  jserv_error(JSERV_LOG_EMERG, wrapper_data->config,
                              "wrapper: JServ (%d) didn't die nicely, killing it",
 -                            jvm_pid);
 -                kill(jvm_pid, SIGTERM); /* give the process a chance to die */
 +                            jvm_pid_local);
 +                kill(jvm_pid_local, SIGTERM); /* give the process a chance to die */
                  counter = 0;
                  while (counter++ < 3) {
 -                    if (waitpid(jvm_pid, NULL, WNOHANG) > 0)
 +                    if (waitpid(jvm_pid_local, NULL, WNOHANG) > 0)
                          return 0;
                      sleep(1);
                  }
 -                if( waitpid(jvm_pid,NULL,WNOHANG)==0 ) {
 -                    kill(jvm_pid, SIGKILL);
 +                if( waitpid(jvm_pid_local,NULL,WNOHANG)==0 ) {
 +                    kill(jvm_pid_local, SIGKILL);
                  }
              }
              sleep(1);