|
|
62d9ef |
From 1ae96f0e2befb602a8e1b63f642e525df5b44bb8 Mon Sep 17 00:00:00 2001
|
|
|
62d9ef |
From: Rob Crittenden <rcritten@redhat.com>
|
|
|
62d9ef |
Date: Fri, 5 Aug 2016 18:22:00 -0400
|
|
|
62d9ef |
Subject: [PATCH] Fix leaking semaphore on shutdown
|
|
|
62d9ef |
|
|
|
62d9ef |
When Apache kills its children it does so with a SIGTERM.
|
|
|
62d9ef |
This wasn't being handled so the semaphore used to do locking
|
|
|
62d9ef |
for the crlhelper wasn't being removed.
|
|
|
62d9ef |
|
|
|
62d9ef |
Add a signal handler to catch SIGTERM and perform cleanup.
|
|
|
62d9ef |
|
|
|
62d9ef |
Resolves: #1326840
|
|
|
62d9ef |
|
|
|
62d9ef |
---
|
|
|
62d9ef |
crlhelper.cpp | 43 ++++++++++++++++++++++++++++++++-----------
|
|
|
62d9ef |
1 file changed, 32 insertions(+), 11 deletions(-)
|
|
|
62d9ef |
|
|
|
62d9ef |
diff --git a/crlhelper.cpp b/crlhelper.cpp
|
|
|
62d9ef |
index f0a5b8a..719f8ff 100644
|
|
|
62d9ef |
--- a/crlhelper.cpp
|
|
|
62d9ef |
+++ b/crlhelper.cpp
|
|
|
62d9ef |
@@ -98,16 +98,41 @@ static void printList(Node *list)
|
|
|
62d9ef |
|
|
|
62d9ef |
/* global variables */
|
|
|
62d9ef |
Node *urlcache = NULL;
|
|
|
62d9ef |
+int semid = 0;
|
|
|
62d9ef |
+PRFileDesc *in = NULL;
|
|
|
62d9ef |
+PRFileDesc *out = NULL;
|
|
|
62d9ef |
+
|
|
|
62d9ef |
+void cleanup() {
|
|
|
62d9ef |
+ union semun semarg;
|
|
|
62d9ef |
+
|
|
|
62d9ef |
+ freeList(urlcache);
|
|
|
62d9ef |
+ if (in) {
|
|
|
62d9ef |
+ PR_Close(in);
|
|
|
62d9ef |
+ in = NULL;
|
|
|
62d9ef |
+ }
|
|
|
62d9ef |
+ if (NSS_IsInitialized()) {
|
|
|
62d9ef |
+ NSS_Shutdown();
|
|
|
62d9ef |
+ }
|
|
|
62d9ef |
+
|
|
|
62d9ef |
+ /* Remove the semaphore used for locking here. This is because this
|
|
|
62d9ef |
+ * program only goes away when Apache shuts down so we don't have to
|
|
|
62d9ef |
+ * worry about reloads.
|
|
|
62d9ef |
+ */
|
|
|
62d9ef |
+ semctl(semid, 0, IPC_RMID, semarg);
|
|
|
62d9ef |
+}
|
|
|
62d9ef |
+
|
|
|
62d9ef |
+void signalhandler(int signo) {
|
|
|
62d9ef |
+ if (signo == SIGTERM) {
|
|
|
62d9ef |
+ cleanup();
|
|
|
62d9ef |
+ }
|
|
|
62d9ef |
+}
|
|
|
62d9ef |
|
|
|
62d9ef |
int main(int argc, char ** argv)
|
|
|
62d9ef |
{
|
|
|
62d9ef |
SECStatus rv;
|
|
|
62d9ef |
PRInt32 numfds;
|
|
|
62d9ef |
- PRFileDesc *in;
|
|
|
62d9ef |
- PRFileDesc *out;
|
|
|
62d9ef |
PRPollDesc pd;
|
|
|
62d9ef |
PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
|
|
|
62d9ef |
- int semid;
|
|
|
62d9ef |
pid_t parent_pid;
|
|
|
62d9ef |
union semun semarg;
|
|
|
62d9ef |
char buf[4096];
|
|
|
62d9ef |
@@ -121,6 +146,8 @@ int main(int argc, char ** argv)
|
|
|
62d9ef |
PRInt32 len = 0;
|
|
|
62d9ef |
PRInt32 errnum = -1;
|
|
|
62d9ef |
|
|
|
62d9ef |
+ signal(SIGTERM, signalhandler);
|
|
|
62d9ef |
+
|
|
|
62d9ef |
/* Close all fds but stdin, stdout and stderr */
|
|
|
62d9ef |
fd = 3;
|
|
|
62d9ef |
while (fd < fdlimit)
|
|
|
62d9ef |
@@ -290,14 +317,8 @@ done:
|
|
|
62d9ef |
}
|
|
|
62d9ef |
} /* end POLL */
|
|
|
62d9ef |
} /* end while */
|
|
|
62d9ef |
- freeList(urlcache);
|
|
|
62d9ef |
- PR_Close(in);
|
|
|
62d9ef |
- NSS_Shutdown();
|
|
|
62d9ef |
|
|
|
62d9ef |
- /* Remove the semaphore used for locking here. This is because this
|
|
|
62d9ef |
- * program only goes away when Apache shuts down so we don't have to
|
|
|
62d9ef |
- * worry about reloads.
|
|
|
62d9ef |
- */
|
|
|
62d9ef |
- semctl(semid, 0, IPC_RMID, semarg);
|
|
|
62d9ef |
+ cleanup();
|
|
|
62d9ef |
+
|
|
|
62d9ef |
return 0;
|
|
|
62d9ef |
}
|
|
|
62d9ef |
--
|
|
|
62d9ef |
1.8.3.1
|
|
|
62d9ef |
|