From 03ef5372abc04dcb944a9e34995eaf0c7575e168 Mon Sep 17 00:00:00 2001 From: Calvin Owens Date: Thu, 16 Apr 2026 13:00:52 -0700 Subject: [PATCH] Don't truncate existing logfiles in logger output modules The current behavior is to truncate logfiles after the daemon is restarted, which is probably not what anybody expects or wants. Fix by dropping O_TRUNC and seeking to the end of the file. Also drop abort() for exit() as seen elsewhere in the program. Signed-off-by: Calvin Owens --- modules/logger-advanced.cc | 8 ++++++-- modules/logger-simple.cc | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/logger-advanced.cc b/modules/logger-advanced.cc index 3fbb13a..e268e33 100644 --- a/modules/logger-advanced.cc +++ b/modules/logger-advanced.cc @@ -96,13 +96,17 @@ struct logtarget { } } - ret = open(hostname, O_TRUNC | O_WRONLY | O_CREAT, 0644); + ret = open(hostname, O_WRONLY | O_CREAT, 0644); if (ret == -1) { fprintf(stderr, "FATAL: open() failed: %m\n"); - abort(); + exit(EXIT_FAILURE); } fd = ret; + if (lseek(fd, 0, SEEK_END) == -1) { + fprintf(stderr, "FATAL: lseek(SEEK_END) failed: %m\n"); + exit(EXIT_FAILURE); + } } /* diff --git a/modules/logger-simple.cc b/modules/logger-simple.cc index 95a79df..41f6688 100644 --- a/modules/logger-simple.cc +++ b/modules/logger-simple.cc @@ -85,13 +85,17 @@ struct logtarget { } } - ret = open(hostname, O_TRUNC | O_WRONLY | O_CREAT, 0644); + ret = open(hostname, O_WRONLY | O_CREAT, 0644); if (ret == -1) { fprintf(stderr, "FATAL: open() failed: %m\n"); - abort(); + exit(EXIT_FAILURE); } fd = ret; + if (lseek(fd, 0, SEEK_END) == -1) { + fprintf(stderr, "FATAL: lseek(SEEK_END) failed: %m\n"); + exit(EXIT_FAILURE); + } } /*