summaryrefslogtreecommitdiff
path: root/log
diff options
context:
space:
mode:
authorJohn Crispin <blogic@openwrt.org>2015-03-28 15:38:09 +0100
committerJohn Crispin <blogic@openwrt.org>2015-03-28 18:33:48 +0100
commitc0138bae8ed746e30f3d3a591e1615f2a705b1a5 (patch)
tree4a431ff3484b06a0a3af94df94dacda5fe40ee9e /log
parentdd338ce30b6158f3f6feda9f01a2f409a8a5832c (diff)
downloadubox-c0138bae8ed746e30f3d3a591e1615f2a705b1a5.tar.gz
properly handle return codes
Signed-off-by: John Crispin <blogic@openwrt.org>
Diffstat (limited to 'log')
-rw-r--r--log/logread.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/log/logread.c b/log/logread.c
index 871cd5b..06dda62 100644
--- a/log/logread.c
+++ b/log/logread.c
@@ -102,6 +102,7 @@ static int log_notify(struct blob_attr *msg)
char *str;
time_t t;
char *c, *m;
+ int ret = 0;
if (sender.fd < 0)
return 0;
@@ -138,16 +139,16 @@ static int log_notify(struct blob_attr *msg)
snprintf(buf, sizeof(buf), "<%u>", p);
strncat(buf, c + 4, 16);
if (hostname) {
- strncat(buf, hostname, sizeof(buf));
- strncat(buf, " ", sizeof(buf));
+ strncat(buf, hostname, sizeof(buf) - strlen(buf) - 1);
+ strncat(buf, " ", sizeof(buf) - strlen(buf) - 1);
}
if (log_prefix) {
- strncat(buf, log_prefix, sizeof(buf));
- strncat(buf, ": ", sizeof(buf));
+ strncat(buf, log_prefix, sizeof(buf) - strlen(buf) - 1);
+ strncat(buf, ": ", sizeof(buf) - strlen(buf) - 1);
}
if (blobmsg_get_u32(tb[LOG_SOURCE]) == SOURCE_KLOG)
- strncat(buf, "kernel: ", sizeof(buf));
- strncat(buf, m, sizeof(buf));
+ strncat(buf, "kernel: ", sizeof(buf) - strlen(buf) - 1);
+ strncat(buf, m, sizeof(buf) - strlen(buf) - 1);
if (log_udp)
err = write(sender.fd, buf, strlen(buf));
else
@@ -165,14 +166,14 @@ static int log_notify(struct blob_attr *msg)
snprintf(buf, sizeof(buf), "%s %s.%s%s %s\n",
c, getcodetext(LOG_FAC(p) << 3, facilitynames), getcodetext(LOG_PRI(p), prioritynames),
(blobmsg_get_u32(tb[LOG_SOURCE])) ? ("") : (" kernel:"), m);
- write(sender.fd, buf, strlen(buf));
+ ret = write(sender.fd, buf, strlen(buf));
}
free(str);
if (log_type == LOG_FILE)
fsync(sender.fd);
- return 0;
+ return ret;
}
static int usage(const char *prog)