OSSP CVS Repository

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

Check-in Number: 1164
Date: 2001-Oct-12 09:43:31 (local)
2001-Oct-12 07:43:31 (UTC)
User:thl
Branch:
Comment: Sending a USR1 signal to the program will flush the logging buffer
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/lmtp2nntp.c      1.82 -> 1.83     25 inserted, 17 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp.pod      1.27 -> 1.28     4 inserted, 0 deleted

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;


ossp-pkg/lmtp2nntp/lmtp2nntp.pod 1.27 -> 1.28

--- lmtp2nntp.pod        2001/10/09 20:12:30     1.27
+++ lmtp2nntp.pod        2001/10/12 07:43:31     1.28
@@ -210,6 +210,10 @@
 
 =back
 
+=head1 SIGNALS
+
+Sending a USR1 signal to the program will flush the logging buffer.
+
 =head1 DIAGNOSTICS
 
 If invoked it returns 0 on successful execution (not neccessarily

CVSTrac 2.0.1