Fix logread file logging
authorJohn Crispin <blogic@openwrt.org>
Tue, 9 Jul 2013 12:33:14 +0000 (14:33 +0200)
committerJohn Crispin <blogic@openwrt.org>
Tue, 9 Jul 2013 12:50:45 +0000 (14:50 +0200)
This patch fixes logread and now appends to files instead of writting to the beginning the specified logfile. It also sets the access rights to 0600.

Signed-off-by: Peter Wagner <tripolar@gmx.at>
logread.c

index ba12f446119762221f01d772f373858607ad20f4..16af3ef7359d2a1ae3e641eef0103e45f43d3aa3 100644 (file)
--- a/logread.c
+++ b/logread.c
@@ -116,7 +116,7 @@ static int log_notify(struct ubus_context *ctx, struct ubus_object *obj,
                        rename(log_file, old);
                        free(old);
                }
-               sender.fd = open(log_file, O_CREAT | O_WRONLY | O_TRUNC);
+               sender.fd = open(log_file, O_CREAT | O_WRONLY | O_APPEND, 0600);
                if (sender.fd < 0) {
 //                     fprintf(stderr, "failed to open %s: %s\n", log_file, strerror(errno));
                        exit(-1);
@@ -184,7 +184,7 @@ static void follow_log(struct ubus_context *ctx, int id)
                uloop_timeout_set(&retry, 1000);
        } else if (log_file) {
                log_type = LOG_FILE;
-               sender.fd = open(log_file, O_CREAT | O_WRONLY);
+               sender.fd = open(log_file, O_CREAT | O_WRONLY| O_APPEND, 0600);
                if (sender.fd < 0) {
                        fprintf(stderr, "failed to open %s: %s\n", log_file, strerror(errno));
                        exit(-1);