On Sat, May 16, 2020 at 07:23:37PM -0400, sven falempin wrote:
> This was looked at before.
> Did not get through.

The posted diff was not my final solution.  But yes, the issue was
forgotten.  So I would suggest this.

When DNS lookup of an UDP loghost failed, syslogd(8) did close the
UDP sockets for sending messages.  Keep the sockets open in this
case.  Then they can be used if DNS is working during the next
SIGHUP.

ok?

bluhm

Index: usr.sbin/syslogd/syslogd.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.262
diff -u -p -r1.262 syslogd.c
--- usr.sbin/syslogd/syslogd.c  5 Jul 2019 13:23:27 -0000       1.262
+++ usr.sbin/syslogd/syslogd.c  9 Feb 2020 20:25:20 -0000
@@ -853,20 +853,6 @@ main(int argc, char *argv[])
                        event_add(ev_udp, NULL);
                if (fd_udp6 != -1)
                        event_add(ev_udp6, NULL);
-       } else {
-               /*
-                * If generic UDP file descriptors are used neither
-                * for receiving nor for sending, close them.  Then
-                * there is no useless *.514 in netstat.
-                */
-               if (fd_udp != -1 && !send_udp) {
-                       close(fd_udp);
-                       fd_udp = -1;
-               }
-               if (fd_udp6 != -1 && !send_udp6) {
-                       close(fd_udp6);
-                       fd_udp6 = -1;
-               }
        }
        for (i = 0; i < nbind; i++)
                if (fd_bind[i] != -1)
@@ -2416,6 +2402,7 @@ init(void)
        s = 0;
        strlcpy(progblock, "*", sizeof(progblock));
        strlcpy(hostblock, "*", sizeof(hostblock));
+       send_udp = send_udp6 = 0;
        while (getline(&cline, &s, cf) != -1) {
                /*
                 * check for end-of-section, comments, strip off trailing
@@ -2508,6 +2495,22 @@ init(void)
        Initialized = 1;
        dropped_warn(&init_dropped, "during initialization");

+       if (SecureMode) {
+               /*
+                * If generic UDP file descriptors are used neither
+                * for receiving nor for sending, close them.  Then
+                * there is no useless *.514 in netstat.
+                */
+               if (fd_udp != -1 && !send_udp) {
+                       close(fd_udp);
+                       fd_udp = -1;
+               }
+               if (fd_udp6 != -1 && !send_udp6) {
+                       close(fd_udp6);
+                       fd_udp6 = -1;
+               }
+       }
+
        if (Debug) {
                SIMPLEQ_FOREACH(f, &Files, f_next) {
                        for (i = 0; i <= LOG_NFACILITIES; i++)
@@ -2755,6 +2758,13 @@ cfline(char *line, char *progblock, char
                    sizeof(f->f_un.f_forw.f_addr)) != 0) {
                        log_warnx("bad hostname \"%s\"",
                            f->f_un.f_forw.f_loghost);
+                       /* DNS lookup may work after SIGHUP, keep sockets */
+                       if (strcmp(proto, "udp") == 0)
+                               send_udp = send_udp6 = 1;
+                       else if (strcmp(proto, "udp4") == 0)
+                               send_udp = 1;
+                       else if (strcmp(proto, "udp6") == 0)
+                               send_udp6 = 1;
                        break;
                }
                f->f_file = -1;

Reply via email to