Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/lib/libc/gen Pull up revision 1.27 (requested by atatat):



details:   https://anonhg.NetBSD.org/src/rev/4444d5e72619
branches:  netbsd-1-5
changeset: 493029:4444d5e72619
user:      he <he%NetBSD.org@localhost>
date:      Fri Mar 29 23:19:58 2002 +0000

description:
Pull up revision 1.27 (requested by atatat):
  Add a single retry into syslog(), to cope with a restarted syslogd,
  so that log messages don't get lost.  Most useful for long-running
  programs.

diffstat:

 lib/libc/gen/syslog.c |  30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)

diffs (58 lines):

diff -r 531022fbe3d4 -r 4444d5e72619 lib/libc/gen/syslog.c
--- a/lib/libc/gen/syslog.c     Fri Mar 29 23:13:08 2002 +0000
+++ b/lib/libc/gen/syslog.c     Fri Mar 29 23:19:58 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: syslog.c,v 1.24 2000/01/22 22:19:12 mycroft Exp $      */
+/*     $NetBSD: syslog.c,v 1.24.4.1 2002/03/29 23:19:58 he Exp $       */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)syslog.c   8.5 (Berkeley) 4/29/95";
 #else
-__RCSID("$NetBSD: syslog.c,v 1.24 2000/01/22 22:19:12 mycroft Exp $");
+__RCSID("$NetBSD: syslog.c,v 1.24.4.1 2002/03/29 23:19:58 he Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -129,7 +129,7 @@
        char ch, *p, *t;
        time_t now;
        struct tm tmnow;
-       int fd, saved_errno;
+       int fd, saved_errno, tries;
 #define        TBUF_LEN        2048
 #define        FMT_LEN         1024
        char *stdp = NULL;      /* pacify gcc */
@@ -246,12 +246,24 @@
 
        /* Get connected, output the message to the local logger. */
        mutex_lock(&syslog_mutex);
-       if (!connected)
-               openlog_unlocked(LogTag, LogStat | LOG_NDELAY, 0);
-       if (send(LogFile, tbuf, cnt, 0) >= 0) {
-               mutex_unlock(&syslog_mutex);
-               return;
-       } 
+       /*
+        * Try to send it twice.  If the first try fails, we might
+        * be able to simply reconnect and send the message (which
+        * means syslogd was restarted since we connected the first
+        * time).  If the second attempt doesn't work, then something
+        * else is wrong and there's probably not much we can do
+        * here.
+        */
+       for (tries = 1; tries <= 2; tries++) {
+               if (!connected)
+                       openlog_unlocked(LogTag, LogStat | LOG_NDELAY, 0);
+               if (send(LogFile, tbuf, cnt, 0) >= 0) {
+                       mutex_unlock(&syslog_mutex);
+                       return;
+               } 
+               else
+                       closelog_unlocked();
+       }
        mutex_unlock(&syslog_mutex);
 
        /*



Home | Main Index | Thread Index | Old Index