]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ldpd: use synchronous channels for sending log messages
authorRenato Westphal <renato@opensourcerouting.org>
Wed, 19 Apr 2017 19:59:50 +0000 (16:59 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Mon, 5 Jun 2017 15:23:33 +0000 (12:23 -0300)
This is necessary to guarantee that all log messages sent from the child
processes are received in the parent process right away.

Without this patch, when a child process calls fatal() or fatalx(),
the log messages don't make it to the parent because the child doesn't
have a chance to flush its buffers before exiting.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ldpd/lde.c
ldpd/lde.h
ldpd/ldpe.c
ldpd/ldpe.h
ldpd/log.c

index 426af8dbe86ed3057ced06c63833eff6f7ab36bb..1c7458ce7386d4e89c2d507feb5128b4769619d7 100644 (file)
@@ -130,7 +130,7 @@ zclient_sync_init(u_short instance)
        zclient_sync->redist_default = ZEBRA_ROUTE_LDP;
        zclient_sync->instance = instance;
        while (zclient_socket_connect (zclient_sync) < 0) {
-               fprintf(stderr, "Error connecting synchronous zclient!\n");
+               log_warnx("Error connecting synchronous zclient!");
                sleep(1);
        }
        /* make socket non-blocking */
@@ -138,7 +138,7 @@ zclient_sync_init(u_short instance)
 
        /* Connect to label manager */
        while (lm_label_manager_connect (zclient_sync) != 0) {
-               fprintf(stderr, "Error connecting to label manager!\n");
+               log_warnx("Error connecting to label manager!");
                sleep(1);
        }
 }
@@ -240,6 +240,13 @@ lde_imsg_compose_parent(int type, pid_t pid, void *data, uint16_t datalen)
        return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen));
 }
 
+void
+lde_imsg_compose_parent_sync(int type, pid_t pid, void *data, uint16_t datalen)
+{
+       imsg_compose_event(iev_main_sync, type, 0, pid, -1, data, datalen);
+       imsg_flush(&iev_main_sync->ibuf);
+}
+
 int
 lde_imsg_compose_ldpe(int type, uint32_t peerid, pid_t pid, void *data,
     uint16_t datalen)
@@ -1620,7 +1627,7 @@ lde_label_list_init(void)
 
        /* get first chunk */
        while (lde_get_label_chunk () != 0) {
-               fprintf(stderr, "Error getting first label chunk!\n");
+               log_warnx("Error getting first label chunk!");
                sleep(1);
        }
 }
index 3349d4ca000aeca4309e1eacbbe453a87d25bbf4..c1d66f9fffee94c8c424044cac76956f0c09e6a8 100644 (file)
@@ -142,6 +142,7 @@ extern struct thread        *gc_timer;
 void            lde(void);
 void            lde_init(struct ldpd_init *);
 int             lde_imsg_compose_parent(int, pid_t, void *, uint16_t);
+void            lde_imsg_compose_parent_sync(int, pid_t, void *, uint16_t);
 int             lde_imsg_compose_ldpe(int, uint32_t, pid_t, void *, uint16_t);
 int             lde_acl_check(char *, int, union ldpd_addr *, uint8_t);
 uint32_t        lde_update_label(struct fec_node *);
index bd0f9dbd6f586482f2c5f38ac2607c1554e9c8d3..20cc9f7444290bef31c86e05e9e8873b7cfa5b66 100644 (file)
@@ -245,6 +245,13 @@ ldpe_imsg_compose_parent(int type, pid_t pid, void *data, uint16_t datalen)
        return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen));
 }
 
+void
+ldpe_imsg_compose_parent_sync(int type, pid_t pid, void *data, uint16_t datalen)
+{
+       imsg_compose_event(iev_main_sync, type, 0, pid, -1, data, datalen);
+       imsg_flush(&iev_main_sync->ibuf);
+}
+
 int
 ldpe_imsg_compose_lde(int type, uint32_t peerid, pid_t pid, void *data,
     uint16_t datalen)
index 2c1ba46c6b7af727f272a6011570d1fae672242c..d34ca4dc246542a09be32d0696f88e78e0aea1b1 100644 (file)
@@ -199,6 +199,7 @@ void                 ldpe(void);
 void            ldpe_init(struct ldpd_init *);
 int             ldpe_imsg_compose_parent(int, pid_t, void *,
                    uint16_t);
+void            ldpe_imsg_compose_parent_sync(int, pid_t, void *, uint16_t);
 int             ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *,
                    uint16_t);
 int             ldpe_acl_check(char *, int, union ldpd_addr *, uint8_t);
index fc8c995ba3b75b4aea1e7aaabe9adedeff209f70..b138e5754aa7762890c3e6d124c722718368024c 100644 (file)
@@ -46,11 +46,13 @@ vlog(int pri, const char *fmt, va_list ap)
        switch (ldpd_process) {
        case PROC_LDE_ENGINE:
                vsnprintf(buf, sizeof(buf), fmt, ap);
-               lde_imsg_compose_parent(IMSG_LOG, pri, buf, strlen(buf) + 1);
+               lde_imsg_compose_parent_sync(IMSG_LOG, pri, buf,
+                   strlen(buf) + 1);
                break;
        case PROC_LDP_ENGINE:
                vsnprintf(buf, sizeof(buf), fmt, ap);
-               ldpe_imsg_compose_parent(IMSG_LOG, pri, buf, strlen(buf) + 1);
+               ldpe_imsg_compose_parent_sync(IMSG_LOG, pri, buf,
+                   strlen(buf) + 1);
                break;
        case PROC_MAIN:
                vzlog(pri, fmt, ap);