mirror of
https://github.com/systemd/systemd.git
synced 2025-01-25 10:04:04 +03:00
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.
This commit is contained in:
parent
a065dcd239
commit
4c3d2523a0
@ -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) {
|
||||
|
@ -20,7 +20,7 @@ typedef struct Writer {
|
||||
unsigned n_ref;
|
||||
} Writer;
|
||||
|
||||
Writer* writer_new(RemoteServer* server);
|
||||
int writer_new(RemoteServer *server, Writer **ret);
|
||||
Writer* writer_ref(Writer *w);
|
||||
Writer* writer_unref(Writer *w);
|
||||
|
||||
|
@ -122,14 +122,14 @@ int journal_remote_get_writer(RemoteServer *s, const char *host, Writer **writer
|
||||
if (w)
|
||||
writer_ref(w);
|
||||
else {
|
||||
w = writer_new(s);
|
||||
if (!w)
|
||||
return log_oom();
|
||||
r = writer_new(s, &w);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (s->split_mode == JOURNAL_WRITE_SPLIT_HOST) {
|
||||
w->hashmap_key = strdup(key);
|
||||
if (!w->hashmap_key)
|
||||
return log_oom();
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
r = open_output(s, w, host);
|
||||
@ -142,7 +142,6 @@ int journal_remote_get_writer(RemoteServer *s, const char *host, Writer **writer
|
||||
}
|
||||
|
||||
*writer = TAKE_PTR(w);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user