On Mon, May 13, 2002 at 10:58:55AM -0400, Michael Stenner wrote:
> On Mon, May 13, 2002 at 10:41:45AM -0400, Theo Van Dinter wrote:
> > Well, "broken pipe" is really the process receiving a SIGPIPE.  So a
> > possible solution would be something like:
> > 
> > my $old = $SIG{'PIPE'};
> > $SIG{'PIPE'} = sub { closelog; openlog ... ; }
> > 
> > do logging;
> > 
> > $SIG{'PIPE'} = $old;
> > 
> > around the logging areas.  That way the signal will be trapped when
> > appropriate and handled.
> 
> If you guys think that's a reasonable solution, then I'm game.  Unless
> I hear otherwise, I'll whip something up that does that.

Here's the patch I dreamed up.  If there are no objections, I'll
submit this with a bug report.  I've tested it here and it certainly
solves my problem.

                                        -Michael

======================================================================
--- spamd       Mon May 13 14:26:17 2002
+++ spamd-new   Mon May 13 15:19:31 2002
@@ -610,9 +610,37 @@
 
 sub logmsg
 {
+    my $old = $SIG{'PIPE'};
+    $SIG{'PIPE'} = sub { $main::SIGPIPE_RECEIVED++; };
+    
     openlog('spamd','cons,pid',$log_facility);
     syslog('info',"@_");
     if ($opt_D) { warn "logmsg: @_\n"; }
+
+    if ($main::SIGPIPE_RECEIVED) {
+       # SIGPIPE recieved when writing to syslog - this has been
+       # found to occur with syslog-ng after syslog-ng restarts.
+       # Close and reopen the log handle, then try again.
+
+       closelog();
+       openlog('spamd','cons,pid',$log_facility);
+       syslog('info',"@_");
+
+       # now report what happend
+       my $msg = "SIGPIPE received - reopening log socket";
+       if ($opt_D) { warn "logmsg: $msg\n"; }
+       syslog('warning', $msg);
+
+       # if we've received multiple sigpipes, logging is probably
+       # still broken.
+       if ($main::SIGPIPE_RECEIVED > 1) {
+           warn "logging failure: multiple SIGPIPEs received\n";
+       }
+
+       $main::SIGPIPE_RECEIVED = 0;
+    }
+
+    $SIG{'PIPE'} = $old;
 }
 
 sub kill_handler

===========================================================================

_______________________________________________________________

Have big pipes? SourceForge.net is looking for download mirrors. We supply
the hardware. You get the recognition. Email Us: [EMAIL PROTECTED]
_______________________________________________
Spamassassin-talk mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/spamassassin-talk

Reply via email to