summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-01-26 14:06:35 +0100
committerLennart Poettering <lennart@poettering.net>2016-01-26 14:13:30 +0100
commite167d7fd8d5fe918b6d675e16aeca2c43398a5b2 (patch)
treef55b2debba6284f724f4a2ed1264d8e215d567ab
parentd8fc78b40fab1d1545b384eb0b8928b78c8828ff (diff)
journald: minor fixes
This primarily contains some minor coding style fixups for 7a24f3bf2fb181243a1957a0cdd54cd919396793 and earlier changes. Specifically: * Don't log at log levels above LOG_DEBUG from "library" code like journal-file.c * Don't negate errno values before passing them to log_debug_errno(), as the call can handle this fine anyway * Cast some calls we knowingly ignore the return values of to (void) * Don't clobber function call-by-ref return values on failure * Don't mix function calls and variable declarations in one line There's also one more relevant change: when failing to enqueue a journal change fs event, we'll run it immediately.
-rw-r--r--src/journal/journal-file.c32
-rw-r--r--src/journal/journald-server.c11
2 files changed, 26 insertions, 17 deletions
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 929ad0aa7c..2973176c8d 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -157,7 +157,7 @@ JournalFile* journal_file_close(JournalFile *f) {
if (enabled == SD_EVENT_ONESHOT)
journal_file_post_change(f);
- sd_event_source_set_enabled(f->post_change_timer, SD_EVENT_OFF);
+ (void) sd_event_source_set_enabled(f->post_change_timer, SD_EVENT_OFF);
sd_event_source_unref(f->post_change_timer);
}
@@ -1409,7 +1409,7 @@ void journal_file_post_change(JournalFile *f) {
__sync_synchronize();
if (ftruncate(f->fd, f->last_stat.st_size) < 0)
- log_error_errno(errno, "Failed to truncate file to its own size: %m");
+ log_debug_errno(errno, "Failed to truncate file to its own size: %m");
}
static int post_change_thunk(sd_event_source *timer, uint64_t usec, void *userdata) {
@@ -1432,8 +1432,8 @@ static void schedule_post_change(JournalFile *f) {
r = sd_event_source_get_enabled(timer, &enabled);
if (r < 0) {
- log_error_errno(-r, "Failed to get ftruncate timer state: %m");
- return;
+ log_debug_errno(r, "Failed to get ftruncate timer state: %m");
+ goto fail;
}
if (enabled == SD_EVENT_ONESHOT)
@@ -1441,21 +1441,27 @@ static void schedule_post_change(JournalFile *f) {
r = sd_event_now(sd_event_source_get_event(timer), CLOCK_MONOTONIC, &now);
if (r < 0) {
- log_error_errno(-r, "Failed to get clock's now for scheduling ftruncate: %m");
- return;
+ log_debug_errno(r, "Failed to get clock's now for scheduling ftruncate: %m");
+ goto fail;
}
r = sd_event_source_set_time(timer, now+f->post_change_timer_period);
if (r < 0) {
- log_error_errno(-r, "Failed to set time for scheduling ftruncate: %m");
- return;
+ log_debug_errno(r, "Failed to set time for scheduling ftruncate: %m");
+ goto fail;
}
r = sd_event_source_set_enabled(timer, SD_EVENT_ONESHOT);
if (r < 0) {
- log_error_errno(-r, "Failed to enable scheduled ftruncate: %m");
- return;
+ log_debug_errno(r, "Failed to enable scheduled ftruncate: %m");
+ goto fail;
}
+
+ return;
+
+fail:
+ /* On failure, let's simply post the change immediately. */
+ journal_file_post_change(f);
}
/* Enable coalesced change posting in a timer on the provided sd_event instance */
@@ -2854,9 +2860,11 @@ int journal_file_open(
}
if (template && template->post_change_timer) {
- sd_event *e = sd_event_source_get_event(template->post_change_timer);
+ r = journal_file_enable_post_change_timer(
+ f,
+ sd_event_source_get_event(template->post_change_timer),
+ template->post_change_timer_period);
- r = journal_file_enable_post_change_timer(f, e, template->post_change_timer_period);
if (r < 0)
goto fail;
}
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index c3add87ed1..0a85c38e1c 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -233,25 +233,26 @@ static int open_journal(
JournalFile *template,
JournalFile **ret) {
int r;
+ JournalFile *f;
assert(s);
assert(fname);
assert(ret);
if (reliably)
- r = journal_file_open_reliably(fname, flags, 0640, s->compress, seal, metrics, s->mmap, template, ret);
+ r = journal_file_open_reliably(fname, flags, 0640, s->compress, seal, metrics, s->mmap, template, &f);
else
- r = journal_file_open(fname, flags, 0640, s->compress, seal, metrics, s->mmap, template, ret);
-
+ r = journal_file_open(fname, flags, 0640, s->compress, seal, metrics, s->mmap, template, &f);
if (r < 0)
return r;
- r = journal_file_enable_post_change_timer(*ret, s->event, POST_CHANGE_TIMER_INTERVAL_USEC);
+ r = journal_file_enable_post_change_timer(f, s->event, POST_CHANGE_TIMER_INTERVAL_USEC);
if (r < 0) {
- *ret = journal_file_close(*ret);
+ journal_file_close(f);
return r;
}
+ *ret = f;
return r;
}