From: Renato Westphal Date: Wed, 19 Apr 2017 19:59:50 +0000 (-0300) Subject: ldpd: use synchronous channels for sending log messages X-Git-Tag: reindent-master-before~85^2~1^2~9 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=d8292558bde9802b8267deff44dabb87b12b885f;p=matthieu%2Ffrr.git ldpd: use synchronous channels for sending log messages 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 --- diff --git a/ldpd/lde.c b/ldpd/lde.c index 426af8dbe8..1c7458ce73 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -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); } } diff --git a/ldpd/lde.h b/ldpd/lde.h index 3349d4ca00..c1d66f9fff 100644 --- a/ldpd/lde.h +++ b/ldpd/lde.h @@ -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 *); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index bd0f9dbd6f..20cc9f7444 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -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) diff --git a/ldpd/ldpe.h b/ldpd/ldpe.h index 2c1ba46c6b..d34ca4dc24 100644 --- a/ldpd/ldpe.h +++ b/ldpd/ldpe.h @@ -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); diff --git a/ldpd/log.c b/ldpd/log.c index fc8c995ba3..b138e5754a 100644 --- a/ldpd/log.c +++ b/ldpd/log.c @@ -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);