modprobe: fix a bug where we were entering endless loop
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 6 Nov 2007 11:34:03 +0000 (11:34 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 6 Nov 2007 11:34:03 +0000 (11:34 -0000)
syslogd: strip trailing '\n' too, not only NULs

modutils/modprobe.c
sysklogd/syslogd.c

index f7d193a055de96627bf2367ffcb7187f5df575e5..dafbb4ecd7ea9ce0c500458c2a5a913a8dd118fe 100644 (file)
@@ -791,7 +791,7 @@ static void check_dep(char *mod, struct mod_list_t **head, struct mod_list_t **t
        if (*tail)
                (*tail)->m_next = find;
        find->m_prev = *tail;
-       /*find->m_next = NULL; - xzalloc did it */
+       find->m_next = NULL; /* possibly NOT done by xzalloc! */
 
        if (!*head)
                *head = find;
index 2bf5b5c80442c5a5ad31ebed9a051515fcd90c3d..da63ced4261a25cca5d59fea09aadb38843845af 100644 (file)
@@ -536,10 +536,20 @@ static void do_syslogd(void)
                while (1) {
                        if (sz == 0)
                                goto read_again;
-                       if (G.recvbuf[sz-1])
+                       /* man 3 syslog says: "A trailing newline is added when needed".
+                        * However, neither glibc nor uclibc do this:
+                        * syslog(prio, "test")   sends "test\0" to /dev/log,
+                        * syslog(prio, "test\n") sends "test\n\0",
+                        * IOW: newline is passed verbatim!
+                        * I take it to mean that it's syslogd's job
+                        * to make those look identical in the log files */
+                       if (G.recvbuf[sz-1] && G.recvbuf[sz-1] != '\n')
                                break;
                        sz--;
                }
+               /* Maybe we need to add '\n' here, not later?
+                * It looks like stock syslogd does send '\n' over network,
+                * but we do not (see sendto below) */
                G.recvbuf[sz] = '\0'; /* make sure it *is* NUL terminated */
 
                /* TODO: maybe suppress duplicates? */