]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
util: softsig version of function to setup logging signal handlers
authorMichael Meffie <mmeffie@sinenomine.net>
Thu, 31 Mar 2016 20:39:48 +0000 (16:39 -0400)
committerBenjamin Kaduk <kaduk@mit.edu>
Mon, 25 Apr 2016 03:56:29 +0000 (23:56 -0400)
Provide a new routine to setup the server log signals which registers
soft signal handlers for the common log management signals (SIGTSTP and
SIGHUP). Keep the old SetupLogSignals() routine around while lwp still
exists.

Change-Id: Ic9151c7ad25528e8e4008a4567836e4196cbe8c3
Reviewed-on: https://gerrit.openafs.org/12238
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
src/util/afsutil.h
src/util/liboafs_util.la.sym
src/util/serverLog.c

index 90c20fcbc62aaf7b2852f23140a103a2667db3e8..214bcebc80308873b75723a6fd3da8b7f8fe2259 100644 (file)
@@ -57,6 +57,7 @@ extern int OpenLog(const char *filename);
 extern int ReOpenLog(const char *fileName);
 extern void SetupLogSignals(void);
 extern void CloseLog(void);
+extern void SetupLogSoftSignals(void);
 
 #ifdef AFS_NT40_ENV
 #ifndef _MFC_VER
index 225164379aaa606837be6f4ee04ae1148e139d27..c7249b252a590e1c163926ac3bf0c5a3e5718575 100644 (file)
@@ -12,6 +12,7 @@ OpenLog
 ReOpenLog
 SetLogThreadNumProgram
 SetupLogSignals
+SetupLogSoftSignals
 WriteLogBuffer
 afsUUID_from_string
 afsUUID_to_string
index 5a6207b670f699e0781f836b6ead3d865fa0f61d..0f203b2f8c4bdfb1e23f59d04f222e0ecb0dcc22 100644 (file)
 #include <afs/procmgmt.h>      /* signal(), kill(), wait(), etc. */
 
 #include <roken.h>             /* Must come after procmgmt.h */
+#ifdef AFS_PTHREAD_ENV
+ #include <opr/softsig.h>
+ #include <afs/procmgmt_softsig.h>     /* Must come after softsig.h */
+#endif
 #include <afs/opr.h>
 #include "afsutil.h"
 #include "fileutil.h"
@@ -69,6 +73,7 @@ int LogLevel;
 int mrafsStyleLogs = 0;
 static int threadIdLogs = 0;
 int printLocks = 0;
+static int resetSignals = 0;
 static char ourName[MAXPATHLEN];
 
 void
@@ -236,9 +241,11 @@ SetDebug_Signal(int signo)
     IOMGR_SoftSig(DebugOn, (void *)(intptr_t)LogLevel);
 #endif /* AFS_PTHREAD_ENV */
 
-    (void)signal(signo, SetDebug_Signal);      /* on some platforms, this
-                                                * signal handler needs to
-                                                * be set again */
+    if (resetSignals) {
+       /* When pthreaded softsig handlers are not in use, some platforms
+        * require this signal handler to be set again. */
+       (void)signal(signo, SetDebug_Signal);
+    }
 }                              /*SetDebug_Signal */
 
 void
@@ -254,10 +261,11 @@ ResetDebug_Signal(int signo)
     IOMGR_SoftSig(DebugOn, (void *)(intptr_t)LogLevel);
 #endif /* AFS_PTHREAD_ENV */
 
-    (void)signal(signo, ResetDebug_Signal);    /* on some platforms,
-                                                * this signal handler
-                                                * needs to be set
-                                                * again */
+    if (resetSignals) {
+       /* When pthreaded softsig handlers are not in use, some platforms
+        * require this signal handler to be set again. */
+       (void)signal(signo, ResetDebug_Signal);
+    }
 #if defined(AFS_PTHREAD_ENV)
     if (threadIdLogs == 1)
         threadIdLogs = 0;
@@ -267,9 +275,35 @@ ResetDebug_Signal(int signo)
 }                              /*ResetDebug_Signal */
 
 
+#ifdef AFS_PTHREAD_ENV
+/*!
+ * Register pthread-safe signal handlers for server log management.
+ *
+ * \note opr_softsig_Init() must be called before this function.
+ */
+void
+SetupLogSoftSignals(void)
+{
+    opr_softsig_Register(SIGHUP, ResetDebug_Signal);
+    opr_softsig_Register(SIGTSTP, SetDebug_Signal);
+#ifndef AFS_NT40_ENV
+    (void)signal(SIGPIPE, SIG_IGN);
+#endif
+}
+#endif /* AFS_PTHREAD_ENV */
+
+/*!
+ * Register signal handlers for server log management.
+ *
+ * \note This function is deprecated and should not be used
+ *       in new code. This function should be removed when
+ *       all the servers have been converted to pthreads
+ *       and lwp has been removed.
+ */
 void
 SetupLogSignals(void)
 {
+    resetSignals = 1;
     (void)signal(SIGHUP, ResetDebug_Signal);
     /* Note that we cannot use SIGUSR1 -- Linux stole it for pthreads! */
     (void)signal(SIGTSTP, SetDebug_Signal);