You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jf...@apache.org on 2002/03/02 17:07:10 UTC

cvs commit: jakarta-commons-sandbox/daemon/src/native/unix/native jsvc-unix.c

jfclere     02/03/02 08:07:10

  Modified:    daemon/src/native/unix/native jsvc-unix.c
  Log:
  Finish arrange the thread (pid) handling. Now it kills the right pid on Linux.
  
  Revision  Changes    Path
  1.3       +31 -7     jakarta-commons-sandbox/daemon/src/native/unix/native/jsvc-unix.c
  
  Index: jsvc-unix.c
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/unix/native/jsvc-unix.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jsvc-unix.c	26 Feb 2002 21:31:48 -0000	1.2
  +++ jsvc-unix.c	2 Mar 2002 16:07:09 -0000	1.3
  @@ -55,7 +55,7 @@
    *                                                                           *
    * ========================================================================= */
   
  -/* @version $Id: jsvc-unix.c,v 1.2 2002/02/26 21:31:48 jfclere Exp $ */
  +/* @version $Id: jsvc-unix.c,v 1.3 2002/03/02 16:07:09 jfclere Exp $ */
   #include "jsvc.h"
   
   #include <signal.h>
  @@ -72,7 +72,7 @@
   
   extern char **environ;
   
  -pid_t controlled=0;
  +pid_t controlled=0; /* the son process pid */
   static bool stopping=false;
   static bool doreload=false;
   static void (*handler_int)(int)=NULL;
  @@ -268,12 +268,32 @@
               break;
       }
   }
  +/*
  + * Return the address of the current signal handler and set the new one.
  + */
  +static void * signal_set(int sig, void * handler) {
  +    void *hand;
  +
  +    hand=signal(sig,handler);
  +#ifdef SIG_ERR
  +    if (hand==SIG_ERR)
  +        hand=NULL;
  +#endif
  +    if (hand==handler || hand==controller)
  +        hand=NULL;
  +    return(hand);
  +}
  +
  +/*
  + * son process logic.
  + */
   
   static int child(arg_data *args, home_data *data, uid_t uid, gid_t gid) {
       FILE *pidf=fopen(args->pidf,"w");
       pid_t pidn=getpid();
       int ret=0;
   
  +    /* Write the our pid in the pid file */
       if (pidf!=NULL) {
           fprintf(pidf,"%d\n",(int)pidn);
           fclose(pidf);
  @@ -281,6 +301,9 @@
           log_error("Cannot open PID file %s, PID is %d",args->pidf,pidn);
       }
   
  +    /* create a new process group to prevent kill 0 killing the monitor process */
  +    setpgrp();
  +
   #ifdef OS_LINUX
       /* setuid()/setgid() only apply the current thread so we must do it now */
       if (linuxset_user_group(args->user,uid,gid)!=0)
  @@ -321,9 +344,10 @@
       if (java_start()!=true) return(5);
   
       /* Install signal handlers */
  -    handler_hup=signal(SIGHUP,handler);
  -    handler_trm=signal(SIGTERM,handler);
  -    handler_trm=signal(SIGINT,handler);
  +    handler_hup=signal_set(SIGHUP,handler);
  +    handler_trm=signal_set(SIGTERM,handler);
  +    handler_trm=signal_set(SIGINT,handler);
  +    controlled = getpid();
       log_debug("Waiting for a signal to be delivered");
       while (!stopping) pause();
       log_debug("Shutdown or reload requested: exiting");
  @@ -462,11 +486,11 @@
   
   void main_reload(void) {
       log_debug("Killing self with HUP signal");
  -    kill(getpid(),SIGHUP);
  +    kill(controlled,SIGHUP);
   }
   
   void main_shutdown(void) {
       log_debug("Killing self with TERM signal");
  -    kill(getpid(),SIGTERM);
  +    kill(controlled,SIGTERM);
   }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>