[stgt] [PATCH 1/3] few logger fixes
Alexander Nezhinsky
alexandern at Voltaire.COM
Thu Jun 3 15:22:56 CEST 2010
register custom SIGSEGV handler that performs all log-related cleanups
in orderly fashion; force the same behaviour when the parent exits
Signed-off-by: Alexander Nezhinsky <alexandern at voltaire.com>
---
usr/log.c | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/usr/log.c b/usr/log.c
index 66f3e14..305e14f 100644
--- a/usr/log.c
+++ b/usr/log.c
@@ -29,6 +29,7 @@
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/prctl.h>
#include "log.h"
@@ -327,6 +328,14 @@ static void log_flush(void)
}
}
+static void log_sigsegv(void)
+{
+ log_error("tgtd logger exits abnormally, pid:%d\n", getpid());
+ log_flush();
+ closelog();
+ free_logarea();
+}
+
int log_init(char *program_name, int size, int daemon, int debug)
{
is_debug = debug;
@@ -358,11 +367,13 @@ int log_init(char *program_name, int size, int daemon, int debug)
}
/* flush on daemon's crash */
- sa_new.sa_handler = (void*)log_flush;
+ sa_new.sa_handler = (void*)log_sigsegv;
sigemptyset(&sa_new.sa_mask);
sa_new.sa_flags = 0;
sigaction(SIGSEGV, &sa_new, &sa_old );
+ prctl(PR_SET_PDEATHSIG, SIGSEGV);
+
while (la->active) {
log_flush();
sleep(1);
--
1.6.5
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list