OSSP CVS Repository

ossp - Check-in [952]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 952
Date: 2001-Sep-12 11:58:22 (local)
2001-Sep-12 09:58:22 (UTC)
User:thl
Branch:
Comment: now handling signals
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/00TODO      1.35 -> 1.36     0 inserted, 2 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp.c      1.54 -> 1.55     40 inserted, 1 deleted

ossp-pkg/lmtp2nntp/00TODO 1.35 -> 1.36

--- 00TODO       2001/09/12 08:18:58     1.35
+++ 00TODO       2001/09/12 09:58:22     1.36
@@ -1,6 +1,4 @@
 
-- FIXME
-- signal handler to catch EINTR and segfaults
 - improve sendmail.m4 templates
 
     **** DEVELOPMENT INFORMATION ****


ossp-pkg/lmtp2nntp/lmtp2nntp.c 1.54 -> 1.55

--- lmtp2nntp.c  2001/09/12 08:18:19     1.54
+++ lmtp2nntp.c  2001/09/12 09:58:22     1.55
@@ -32,6 +32,7 @@
 #include <fcntl.h>
 #include <sys/utsname.h>
 #include <sys/time.h>
+#include <signal.h>
 
 /* third party */
 #include "str.h"
@@ -104,6 +105,7 @@
     char   *lhlo_domain;
 };
 
+static void catchsignal(int sig, ...);
 static int connect_nonb(int, const struct sockaddr *, socklen_t, int);
 static void initsession(struct session *session);
 static void resetsession(struct session *session);
@@ -260,6 +262,30 @@
     return L2_OK;
 }
 
+static void catchsignal(int sig, ...)
+{
+    va_list ap;
+    static lmtp2nntp_t *ctx = NULL;
+
+    va_start(ap, sig);
+    if(sig == 0) {
+        if ((ctx = va_arg(ap, lmtp2nntp_t *)) == NULL)
+            exit(ERR_EXECUTION);
+        log0(ctx, TRACE, "catching and logging signals now");
+        va_end(ap);
+        return;
+    }
+    if (ctx != NULL) {
+        if ((sig == SIGHUP) || (sig == SIGINT) || (sig == SIGQUIT))
+            log1(ctx, NOTICE, "caught signal %d - exit - no more logging", sig);
+        else
+            log1(ctx, PANIC, "CAUGHT SIGNAL %d - EXIT - NO MORE LOGGING", sig);
+        l2_stream_destroy(ctx->l2);
+    }
+    va_end(ap);
+    exit(ERR_EXECUTION);
+}
+
 int main(int argc, char **argv)
 {
     lmtp_t       *lmtp;
@@ -573,7 +599,7 @@
             fprintf(stderr, "%s:Error: logging failed to create buffer channel\n", ctx->progname);
             exit(ERR_EXECUTION);
         }
-        if (l2_channel_configure(chBuf, "size", 65536) != L2_OK) { //FIXME
+        if (l2_channel_configure(chBuf, "size", 65536) != L2_OK) {
             fprintf(stderr, "%s:Error: logging failed to configure buffer channel\n", ctx->progname);
             exit(ERR_EXECUTION);
         }
@@ -612,6 +638,19 @@
         exit(ERR_EXECUTION);
     }
 
+    catchsignal(0, ctx);
+    signal(SIGHUP,  (void(*)())catchsignal);
+    signal(SIGINT,  (void(*)())catchsignal);
+    signal(SIGQUIT, (void(*)())catchsignal);
+    signal(SIGILL,  (void(*)())catchsignal);
+    signal(SIGBUS,  (void(*)())catchsignal);
+    signal(SIGSEGV, (void(*)())catchsignal);
+    signal(SIGSYS,  (void(*)())catchsignal);
+    signal(SIGTERM, (void(*)())catchsignal);
+    signal(SIGINFO,            SIG_IGN    );
+    signal(SIGUSR1,            SIG_IGN    );
+    signal(SIGUSR2,            SIG_IGN    );
+
     /* initialize LMTP context */
     lmtp_io.ctx    = ctx;
     lmtp_io.select = NULL;

CVSTrac 2.0.1