--- jsvc_unix.c-orig	Sun Feb 25 18:29:41 2001
+++ jsvc_unix.c	Sun Feb 25 23:57:34 2001
@@ -60,11 +60,21 @@
 
 #include <jsvc.h>
 
+// local prototypes
+void setsignals(void);
+void huphandler(int);
+void termhandler(int);
+
+// jsvc configuration
+jsvc_config *config;
+
 int main(int argc, char *argv[]) {
-    jsvc_config *config;
     char *bin;
     char *root;
     char *home;
+#ifdef DEBUG
+    int x;
+#endif
 
     // Resolve the real full path name of the binary
     root=(char *)malloc(PATH_MAX*sizeof(char));
@@ -130,6 +140,8 @@
 
     if (!jsvc_version(config)) return(1);
 
+    setsignals();
+
     if (!jsvc_init(config)) return(1);
 
     if (!jsvc_start(config)) return(1);
@@ -229,3 +244,33 @@
 #endif
 }
 
+/**
+ * Function to set up HUP and TERM signal handlers
+ */
+void setsignals(void)
+{
+    signal(SIGHUP, huphandler);
+    jsvc_debug(JSVC_MARK, "set HUP handler");
+    signal(SIGTERM, termhandler);
+    jsvc_debug(JSVC_MARK, "set TERM handler");
+
+    jsvc_debug(JSVC_MARK, "PID is %d", getpid());
+}
+
+/**
+ * Callback invoked upon receiving SIGHUP, restart jsvc
+ */
+void huphandler(int i)
+{
+    jsvc_restart(config);
+    jsvc_debug(JSVC_MARK, "restarted after HUP signal");
+}
+
+/**
+ * Callback invoked upon receiving SIGTERM, stop jsvc
+ */
+void termhandler(int i)
+{
+    jsvc_stop(config);
+    jsvc_debug(JSVC_MARK, "terminated after TERM signal");
+}
--- jsvc.h-orig	Sun Feb 25 22:02:06 2001
+++ jsvc.h	Sun Feb 25 22:02:21 2001
@@ -71,6 +71,7 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <dlfcn.h>
+#include <signal.h>
 #include <jni.h>
 
 #ifndef TRUE
