From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 9D8AE5A061F; Mon, 28 Oct 2024 11:00:44 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH v3 5/9] log: Don't use O_APPEND at all Date: Mon, 28 Oct 2024 11:00:40 +0100 Message-ID: <20241028100044.939714-6-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241028100044.939714-1-sbrivio@redhat.com> References: <20241028100044.939714-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: LHLU7FMBE6FIV2Y7YL5VAC75UZWOSUYM X-Message-ID-Hash: LHLU7FMBE6FIV2Y7YL5VAC75UZWOSUYM X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: We open the log file with O_APPEND, but switch it off before seeking, and turn it back on afterwards. We never seek when O_APPEND is on, so we don't actually need it, as its only function is to override the offset for writes so that they are always performed at the end regardless of the current offset (which is at the end anyway, for us). Signed-off-by: Stefano Brivio --- log.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/log.c b/log.c index 6932885..dd25862 100644 --- a/log.c +++ b/log.c @@ -204,9 +204,6 @@ out: */ static int logfile_rotate(int fd, const struct timespec *now) { - if (fcntl(fd, F_SETFL, O_RDWR /* Drop O_APPEND: explicit lseek() */)) - return -errno; - #ifdef FALLOC_FL_COLLAPSE_RANGE /* Only for Linux >= 3.15, extent-based ext4 or XFS, glibc >= 2.18 */ if (!fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, 0, log_cut_size)) @@ -215,9 +212,6 @@ static int logfile_rotate(int fd, const struct timespec *now) #endif logfile_rotate_move(fd, now); - if (fcntl(fd, F_SETFL, O_RDWR | O_APPEND)) - return -errno; - return 0; } @@ -416,7 +410,7 @@ void logfile_init(const char *name, const char *path, size_t size) if (readlink("/proc/self/exe", exe, PATH_MAX - 1) < 0) die_perror("Failed to read own /proc/self/exe link"); - log_file = open(path, O_CREAT | O_TRUNC | O_APPEND | O_RDWR | O_CLOEXEC, + log_file = open(path, O_CREAT | O_TRUNC | O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR); if (log_file == -1) die_perror("Couldn't open log file %s", path); -- 2.43.0