diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-27 19:26:33 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2023-03-27 19:26:33 +0200 |
commit | 4c3d2523a0ec8a075652d8b8a80787747576e03f (patch) | |
tree | a03bf0bfdfe05dbc3e193752d2faced343947ca4 /src/journal-remote/journal-remote-write.c | |
parent | locale: Add missing libxkbcommon dependency to tests (diff) | |
download | systemd-4c3d2523a0ec8a075652d8b8a80787747576e03f.tar.xz systemd-4c3d2523a0ec8a075652d8b8a80787747576e03f.zip |
journal-remote: make writer_new() return negative errno on failure
After f12b399dd6362a03379cb769954ebfb9972236ed, writer_new() may fail
with non-OOM error. Let's return the error cause, and logs the failure
in the caller side.
This also drops logs in journal_remote_get_writer(), adds its caller
typically logs the failure.
Diffstat (limited to 'src/journal-remote/journal-remote-write.c')
-rw-r--r-- | src/journal-remote/journal-remote-write.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c index ace4a1cfad..54ed1e23a0 100644 --- a/src/journal-remote/journal-remote-write.c +++ b/src/journal-remote/journal-remote-write.c @@ -21,19 +21,22 @@ static int do_rotate(ManagedJournalFile **f, MMapCache *m, JournalFileFlags file return r; } -Writer* writer_new(RemoteServer *server) { +int writer_new(RemoteServer *server, Writer **ret) { _cleanup_(writer_unrefp) Writer *w = NULL; int r; + assert(server); + assert(ret); + w = new0(Writer, 1); if (!w) - return NULL; + return -ENOMEM; w->metrics = server->metrics; w->mmap = mmap_cache_new(); if (!w->mmap) - return NULL; + return -ENOMEM; w->n_ref = 1; w->server = server; @@ -41,16 +44,15 @@ Writer* writer_new(RemoteServer *server) { if (is_dir(server->output, /* follow = */ true) > 0) { w->output = strdup(server->output); if (!w->output) - return NULL; + return -ENOMEM; } else { r = path_extract_directory(server->output, &w->output); - if (r < 0) { - log_error_errno(r, "Failed to find directory of file \"%s\": %m", server->output); - return NULL; - } + if (r < 0) + return r; } - return TAKE_PTR(w); + *ret = TAKE_PTR(w); + return 0; } static Writer* writer_free(Writer *w) { |