Skip to content

Commit 3498d6a

Browse files
committed
journal_restart: Lock journal file before trying to restart it
This will prevent multiple clients from restarting the same journal file. Thanks to Joshua Rogers for finding this.
1 parent 06382b8 commit 3498d6a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

logsrvd/logsrvd_journal.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,19 @@ journal_restart(const RestartMessage *msg, const uint8_t *buf, size_t buflen,
427427
if (len >= ssizeof(journal_path)) {
428428
errno = ENAMETOOLONG;
429429
sudo_warn("%s/incoming/%s", logsrvd_conf_relay_dir(), cp);
430-
closure->errstr = _("unable to create journal file");
430+
closure->errstr = _("unable to open journal file");
431431
debug_return_bool(false);
432432
}
433433
if ((fd = open(journal_path, O_RDWR)) == -1) {
434434
sudo_warn(U_("unable to open %s"), journal_path);
435-
closure->errstr = _("unable to create journal file");
436-
debug_return_bool(false);
435+
closure->errstr = _("unable to open journal file");
436+
debug_return_bool(false);
437+
}
438+
if (!sudo_lock_file(fd, SUDO_TLOCK)) {
439+
sudo_warn(U_("unable to lock %s"), journal_path);
440+
close(fd);
441+
closure->errstr = _("unable to lock journal file");
442+
debug_return_bool(false);
437443
}
438444
if (!journal_fdopen(fd, journal_path, closure)) {
439445
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));

0 commit comments

Comments
 (0)