From: John Crispin Date: Sun, 14 Jul 2013 09:24:14 +0000 (+0200) Subject: logread should handle return code when sending data over the net X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=434865f6f870f89571d7f2f5fa5690d16d6fb1d9;p=oweals%2Fprocd.git logread should handle return code when sending data over the net Signed-off-by: John Crispin --- diff --git a/logread.c b/logread.c index 16af3ef..1bf3ed8 100644 --- a/logread.c +++ b/logread.c @@ -129,10 +129,24 @@ static int log_notify(struct ubus_context *ctx, struct ubus_object *obj, c[strlen(c) - 1] = '\0'; str = blobmsg_format_json(msg, true); if (log_type == LOG_NET) { + int err; + snprintf(buf, sizeof(buf), "%s%s\n", (blobmsg_get_u32(tb[LOG_SOURCE])) ? ("") : ("kernel: "), method); - send(sender.fd, buf, strlen(buf), 0); + if (log_udp) + err = write(sender.fd, buf, strlen(buf)); + else + err = send(sender.fd, buf, strlen(buf), 0); + + if (err < 0) { + syslog(0, "failed to send log data to %s:%s via %s\n", + log_ip, log_port, (log_udp) ? ("udp") : ("tcp")); + uloop_fd_delete(&sender); + close(sender.fd); + sender.fd = -1; + uloop_timeout_set(&retry, 1000); + } } else { snprintf(buf, sizeof(buf), "%s %s.%s%s %s\n", c, facilitynames[LOG_FAC(p)].c_name, prioritynames[LOG_PRI(p)].c_name,