util: softsig version of function to setup logging signal handlers 38/12238/2
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 90c20fc..214bceb 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 2251643..c7249b2 100644 (file)
@@ -12,6 +12,7 @@ OpenLog
 ReOpenLog
 SetLogThreadNumProgram
 SetupLogSignals
+SetupLogSoftSignals
 WriteLogBuffer
 afsUUID_from_string
 afsUUID_to_string
index 5a6207b..0f203b2 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);