OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/lmtp2nntp.c versions 1.82 and 1.83
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/lmtp2nntp/lmtp2nntp.c 1.82 -> 1.83

--- lmtp2nntp.c  2001/10/12 07:14:28     1.82
+++ lmtp2nntp.c  2001/10/12 07:43:31     1.83
@@ -341,16 +341,24 @@
         return;
     }
     if (ctx != NULL) {
-        if ((sig == SIGHUP) || (sig == SIGINT) || (sig == SIGQUIT))
-            log1(ctx, NOTICE, "caught signal %d - exit - no more logging", sig);
-        else if (sig == SIGCHLD) {
-            log1(ctx, NOTICE, "caught signal %d - wait for child", sig);
-            pid = wait(NULL);
-            log2(ctx, NOTICE, "caught signal %d - child [%ld] terminated", sig, (long)pid);
-            l2_stream_flush(ctx->l2);
-            return;
-        } else
-            log1(ctx, PANIC, "CAUGHT SIGNAL %d - EXIT - NO MORE LOGGING", sig);
+        switch (sig) {
+            case SIGCHLD:
+                log1(ctx, NOTICE, "caught signal %d - wait for child", sig);
+                pid = wait(NULL);
+                log2(ctx, NOTICE, "caught signal %d - child [%ld] terminated", sig, (long)pid);
+                return;
+            case SIGUSR1:
+                log1(ctx, NOTICE, "caught signal %d - flush logging buffer", sig);
+                l2_stream_flush(ctx->l2);
+                return;
+            case SIGHUP:
+            case SIGINT:
+            case SIGQUIT:
+                log1(ctx, NOTICE, "caught signal %d - exit - no more logging", sig);
+                break;
+            default:
+                log1(ctx, PANIC, "CAUGHT SIGNAL %d - EXIT - NO MORE LOGGING", sig);
+        }
         l2_stream_destroy(ctx->l2);
     }
     exit(ERR_EXECUTION);
@@ -923,7 +931,7 @@
     signal(SIGSEGV, (void(*)())catchsignal);
     signal(SIGSYS,  (void(*)())catchsignal);
     signal(SIGTERM, (void(*)())catchsignal);
-    signal(SIGUSR1,            SIG_IGN    );
+    signal(SIGUSR1, (void(*)())catchsignal);
     signal(SIGUSR2,            SIG_IGN    );
 
     /* loop for LMTP protocol with support for alternate io through daemon */
@@ -968,7 +976,7 @@
         pid = getpid();
         if (ctx->option_daemon) {
             daemonize();
-            log1(ctx, NOTICE, "daemonized, previous pid[%d]", pid); l2_stream_flush(ctx->l2);
+            log1(ctx, NOTICE, "daemonized, previous pid[%d]", pid);
         }
         if (ctx->option_pidfile != NULL) {
             if ((fd = fopen(ctx->option_pidfile, "w+")) == NULL)
@@ -1027,27 +1035,27 @@
                 sa_addr_a2u(ctx->saaIO, &cpA);
                 log1(ctx, TRACE, "connection from %s accepted due to ACL", cpA); 
                 free(cpA);
-                l2_stream_flush(ctx->l2);
             }
             else {
                 char *cpA;
                 sa_addr_a2u(ctx->saaIO, &cpA);
                 log1(ctx, ERROR, "connection from %s refused due to ACL", cpA); 
                 free(cpA);
-                l2_stream_flush(ctx->l2);
                 sa_destroy(ctx->saIO);
                 sa_addr_destroy(ctx->saaIO);
                 continue;
             }
 
-            l2_stream_flush(ctx->l2); /* must flush before fork() */
+            /* logging buffer must be empty before fork otherwise content is
+             * duplicated and written twice on next flush */
+            l2_stream_flush(ctx->l2);
             pid = fork();
             if (pid == -1) {
-                log0(ctx, ERROR, "daemon cannot spawn child %m"); l2_stream_flush(ctx->l2);
+                log0(ctx, ERROR, "daemon cannot spawn child %m");
                 continue;
             }
             if (pid != 0) {
-                log1(ctx, INFO, "daemon forked process, new child pid[%d]", pid); l2_stream_flush(ctx->l2);
+                log1(ctx, INFO, "daemon forked process, new child pid[%d]", pid);
                 sa_destroy(ctx->saIO);
                 sa_addr_destroy(ctx->saaIO);
                 continue;

CVSTrac 2.0.1