You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jf...@apache.org on 2001/08/09 00:46:33 UTC

cvs commit: jakarta-tomcat-4.0/service/native signals.c Makefile.in jsvc-unix.c

jfclere     01/08/08 15:46:33

  Modified:    service/native Makefile.in jsvc-unix.c
  Added:       service/native signals.c
  Log:
  Add signals.c to allow jsvc.exe to be run and stopped via a service wrapper
   on windows NT machines.
  
  Revision  Changes    Path
  1.2       +3 -2      jakarta-tomcat-4.0/service/native/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/service/native/Makefile.in,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Makefile.in	2001/06/26 01:35:30	1.1
  +++ Makefile.in	2001/08/08 22:46:32	1.2
  @@ -56,7 +56,7 @@
   # ========================================================================= #
   
   # @author  Pier Fumagalli <ma...@eng.sun.com>
  -# @version $Id: Makefile.in,v 1.1 2001/06/26 01:35:30 pier Exp $
  +# @version $Id: Makefile.in,v 1.2 2001/08/08 22:46:32 jfclere Exp $
   
   include ../Makedefs
   
  @@ -68,7 +68,8 @@
   	home.o \
   	java.o \
   	location.o \
  -	replace.o
  +	replace.o \
  +	signals.o
   
   all: jsvc libservice.a
   
  
  
  
  1.3       +9 -1      jakarta-tomcat-4.0/service/native/jsvc-unix.c
  
  Index: jsvc-unix.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/service/native/jsvc-unix.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- jsvc-unix.c	2001/06/26 03:24:53	1.2
  +++ jsvc-unix.c	2001/08/08 22:46:32	1.3
  @@ -55,7 +55,7 @@
    *                                                                           *
    * ========================================================================= */
   
  -/* @version $Id: jsvc-unix.c,v 1.2 2001/06/26 03:24:53 pier Exp $ */
  +/* @version $Id: jsvc-unix.c,v 1.3 2001/08/08 22:46:32 jfclere Exp $ */
   #include "jsvc.h"
   
   #include <signal.h>
  @@ -171,6 +171,11 @@
       return(false);
   }
   
  +#ifdef OS_CYGWIN
  +static void cygwincontroller() {
  +    raise(SIGTERM);
  +}
  +#endif
   static void controller(int sig) {
       switch (sig) {
           case SIGTERM:
  @@ -335,6 +340,9 @@
           /* We are in the controller, we have to forward all interesting signals
              to the child, and wait for it to die */
           controlled=pid;
  +#ifdef OS_CYGWIN
  +       SetTerm(cygwincontroller);
  +#endif
           signal(SIGHUP,controller);
           signal(SIGTERM,controller);
           signal(SIGINT,controller);
  
  
  
  1.1                  jakarta-tomcat-4.0/service/native/signals.c
  
  Index: signals.c
  ===================================================================
  /*
   * as Windows does not support signal, OnServe use event to emulate them.
   * The supported signal is SIGTERM.
   * The kills.c contains the kill logic.
   */
  #ifdef OS_CYGWIN
  #include <windows.h>
  #include <stdio.h>
  static void (*HandleTerm)()=NULL; // address of the handler routine.
  
  /*
   * Event handling routine
   */
  void v_difthf(LPVOID par)
  {
  HANDLE hevint; /* make a local copy because the parameter is shared! */
  
    hevint = (HANDLE) par;
  
    for (;;) {
      if (WaitForSingleObject(hevint,INFINITE) == WAIT_FAILED) {
        // something have gone wrong.
        return; // may be something more is needed.
        }
  
      // call the interrupt handler.
      if (HandleTerm==NULL) return;
      HandleTerm();
      }
  }
  
  /*
   * set a routine handler for the signal
   * note that it cannot be used to change the signal handler
   */
  int SetTerm(void (*func)())
  {
  char Name[256];
  HANDLE hevint, hthread;
  DWORD ThreadId; 
  SECURITY_ATTRIBUTES sa;
  SECURITY_DESCRIPTOR sd;
  
    sprintf(Name,"TERM%ld",GetCurrentProcessId());
  
    /*
     * event cannot be inherited.
     * the event is reseted to nonsignaled after the waiting thread is released.
     * the start state is resetted.
     */
  
    // Initialize the new security descriptor.
    InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION);
  
    // Add a NULL descriptor ACL to the security descriptor.
    SetSecurityDescriptorDacl (&sd, TRUE, (PACL)NULL, FALSE);
  
    sa.nLength = sizeof(sa);
    sa.lpSecurityDescriptor = &sd;
    sa.bInheritHandle = TRUE;
  
  
    //  It works also with NULL instead &sa!!
    hevint = CreateEvent(&sa,FALSE, FALSE,Name);
  
    HandleTerm = (int (*)()) func;
  
    if (hevint == NULL) return(-1); // failed
  
    /* create the thread to wait for event */
    hthread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE) v_difthf,
                           (LPVOID) hevint, 0, &ThreadId);
    if (hthread == NULL) {
      // failed remove the event
      CloseHandle(hevint); // windows will remove it.
      return(-1);
      }
  
    CloseHandle(hthread); // not needed
    return(0);
  }
  #endif