Added SIGUSR1/SIGUSR2 handling.
authorJeremy Allison <jra@samba.org>
Wed, 24 Dec 1997 09:30:56 +0000 (09:30 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 24 Dec 1997 09:30:56 +0000 (09:30 +0000)
Sending nmbd/smbd a SIGUSR1 will raise the debug level by one (capped at 10)
sending a SIGUSR2 will lower it (lower limit at zero).
Jeremy.

source/include/proto.h
source/lib/util.c
source/nmbd/nmbd.c
source/nmbd/nmbd_packets.c
source/smbd/server.c

index 7c2966b64fc22ee7d5b8da222e3321b0279e872c..1245b21039c0c36e64d019eb52e030c05dbaf80b 100644 (file)
@@ -1368,6 +1368,8 @@ BOOL user_in_list(char *user,char *list);
 
 /*The following definitions come from  util.c  */
 
+int sig_usr2(void);
+int sig_usr1(void);
 void setup_logging(char *pname,BOOL interactive);
 void reopen_logs(void);
 char *tmpdir(void);
index 125db2ed1e6b4e167080c550a32a52bff742fb19..5c81a14c6637406d5961aae2b1d7e72aea2223e1 100644 (file)
@@ -92,6 +92,53 @@ static BOOL stdout_logging = False;
 
 static char *filename_dos(char *path,char *buf);
 
+#if defined(SIGUSR2)
+/**************************************************************************** **
+ catch a sigusr2 - decrease the debug log level.
+ **************************************************************************** */
+int sig_usr2(void)
+{  
+  BlockSignals( True, SIGUSR2);
+  DEBUGLEVEL--; 
+   
+  if(DEBUGLEVEL < 0) 
+    DEBUGLEVEL = 0; 
+
+  DEBUG( 0, ( "Got SIGUSR2 set debug level to %d.\n", DEBUGLEVEL ) );
+   
+  BlockSignals( False, SIGUSR2);
+#ifndef DONT_REINSTALL_SIG
+  signal(SIGUSR2, SIGNAL_CAST sig_usr2);
+#endif 
+  return(0);
+}  
+#endif /* SIGUSR1 */
+   
+#if defined(SIGUSR1)
+/**************************************************************************** **
+ catch a sigusr1 - increase the debug log level. 
+ **************************************************************************** */
+int sig_usr1(void)
+{
+  BlockSignals( True, SIGUSR1);
+  DEBUGLEVEL++;
+
+  if(DEBUGLEVEL > 10)
+    DEBUGLEVEL = 10;
+
+  DEBUG( 0, ( "Got SIGUSR1 set debug level to %d.\n", DEBUGLEVEL ) );
+
+  BlockSignals( False, SIGUSR1);
+#ifndef DONT_REINSTALL_SIG
+  signal(SIGUSR1, SIGNAL_CAST sig_usr1);
+#endif
+  return(0);
+}
+#endif /* SIGUSR1 */
+
+
 /*******************************************************************
   get ready for syslog stuff
   ******************************************************************/
index da98fbfde3a9f5b216b2bdb091987d36aae51d83..744942ba464cf11045cd8260eac58210d5c59fb9 100644 (file)
@@ -75,11 +75,11 @@ static int sig_term()
   announce_my_servers_removed();
 
   exit(0);
+
   /* Keep compiler happy.. */
   return 0;
 } /* sig_term */
 
-
 /**************************************************************************** **
  catch a sighup
  **************************************************************************** */
@@ -577,6 +577,17 @@ int main(int argc,char *argv[])
   signal( SIGHUP,  SIGNAL_CAST sig_hup );
   signal( SIGTERM, SIGNAL_CAST sig_term );
 
+  /* Setup the signals that allow the debug log level
+     to by dynamically changed. */
+
+#if defined(SIGUSR1)
+  signal( SIGUSR1, SIGNAL_CAST sig_usr1 );
+#endif /* SIGUSR1 */
+
+#if defined(SIGUSR2)
+  signal( SIGUSR2, SIGNAL_CAST sig_usr2 );
+#endif /* SIGUSR2 */
+
   while((opt = getopt(argc, argv, "as:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF)
     {
       switch (opt)
@@ -755,8 +766,14 @@ int main(int argc,char *argv[])
     exit(1);
   }
 
-  /* We can only take sigterm signals in the select. */
+  /* We can only take signals in the select. */
   BlockSignals( True, SIGTERM );
+#if defined(SIGUSR1)
+  BlockSignals( True, SIGUSR1);
+#endif /* SIGUSR1 */
+#if defined(SIGUSR2)
+  BlockSignals( True, SIGUSR2);
+#endif /* SIGUSR2 */
 
   process();
   close_sockets();
index 4fb05439673afb3bae907cb426a0c36bac230a3b..03bd3889fadeadb3e3ad190e046df3af98807e6a 100644 (file)
@@ -1650,10 +1650,27 @@ BOOL listen_for_packets(BOOL run_election)
   timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP;
   timeout.tv_usec = 0;
 
-  /* We can only take term signals when we are in the select. */
+  /* Prepare for the select - allow certain signals. */
+
   BlockSignals(False, SIGTERM);
+#if defined(SIGUSR1)
+  BlockSignals(False, SIGUSR1);
+#endif /* SIGUSR1 */
+#if defined(SIGUSR2)
+  BlockSignals(False, SIGUSR2);
+#endif /* SIGUSR2 */
+
   selrtn = sys_select(&fds,&timeout);
+
+  /* We can only take signals when we are in the select - block them again here. */
+
   BlockSignals(True, SIGTERM);
+#if defined(SIGUSR1)
+  BlockSignals(True, SIGUSR1);
+#endif /* SIGUSR1 */
+#if defined(SIGUSR2)
+  BlockSignals(True, SIGUSR2);
+#endif /* SIGUSR2 */
 
   if(selrtn > 0)
   {
index 5e5f129959ca1bd69e896400ad9c2391a17c2b2e..5eb360bbe7a7eb55a878da8995eed3d98e33ec71 100644 (file)
@@ -5243,7 +5243,18 @@ static void usage(char *pname)
 #ifndef NO_SIGNAL_TEST
   signal(SIGHUP,SIGNAL_CAST sig_hup);
 #endif
-  
+
+  /* Setup the signals that allow the debug log level
+     to by dynamically changed. */
+#if defined(SIGUSR1)
+  signal( SIGUSR1, SIGNAL_CAST sig_usr1 );
+#endif /* SIGUSR1 */
+   
+#if defined(SIGUSR2)
+  signal( SIGUSR2, SIGNAL_CAST sig_usr2 );
+#endif /* SIGUSR2 */
+
   DEBUG(3,("%s loaded services\n",timestring()));
 
   if (!is_daemon && !is_a_socket(0))