summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-11-28 18:23:20 +0100
committerMichal Schmidt <mschmidt@redhat.com>2014-11-28 18:24:30 +0100
commit23bbb0de4e3f85d9704a5c12a5afa2dfa0159e41 (patch)
tree28e66fb86dd0cffc3a3cca3cf234cb52c3b64ad3 /src/journal
parent5e03c6e3b517286bbd65b48d88f60e5b83721894 (diff)
treewide: more log_*_errno + return simplifications
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/coredump.c12
-rw-r--r--src/journal/coredumpctl.c33
-rw-r--r--src/journal/journalctl.c66
-rw-r--r--src/journal/journald-audit.c18
-rw-r--r--src/journal/journald-native.c6
-rw-r--r--src/journal/journald-server.c39
-rw-r--r--src/journal/journald-stream.c12
-rw-r--r--src/journal/journald-syslog.c6
8 files changed, 64 insertions, 128 deletions
diff --git a/src/journal/coredump.c b/src/journal/coredump.c
index 32fa7be0aa..c22d0b0471 100644
--- a/src/journal/coredump.c
+++ b/src/journal/coredump.c
@@ -312,10 +312,8 @@ static int save_external_coredump(
assert(ret_size);
r = make_filename(info, &fn);
- if (r < 0) {
- log_error_errno(r, "Failed to determine coredump file name: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to determine coredump file name: %m");
tmp = tempfn_random(fn);
if (!tmp)
@@ -445,10 +443,8 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s
memcpy(field, "COREDUMP=", 9);
n = read(fd, field + 9, size);
- if (n < 0) {
- log_error_errno(n, "Failed to read core data: %m");
- return (int) n;
- }
+ if (n < 0)
+ return log_error_errno((int) n, "Failed to read core data: %m");
if ((size_t) n < size) {
log_error("Core data too short.");
return -EIO;
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index edc12fead6..7e87f5f21d 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -116,8 +116,7 @@ static int add_match(Set *set, const char *match) {
return 0;
fail:
- log_error_errno(r, "Failed to add match: %m");
- return r;
+ return log_error_errno(r, "Failed to add match: %m");
}
static void help(void) {
@@ -326,10 +325,8 @@ static int print_list(FILE* file, sd_journal *j, int had_legend) {
}
r = sd_journal_get_realtime_usec(j, &t);
- if (r < 0) {
- log_error_errno(r, "Failed to get realtime timestamp: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get realtime timestamp: %m");
format_timestamp(buf, sizeof(buf), t);
present = filename && access(filename, F_OK) == 0;
@@ -521,10 +518,8 @@ static int focus(sd_journal *j) {
r = sd_journal_seek_tail(j);
if (r == 0)
r = sd_journal_previous(j);
- if (r < 0) {
- log_error_errno(r, "Failed to search journal: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to search journal: %m");
if (r == 0) {
log_error("No match found.");
return -ESRCH;
@@ -704,10 +699,8 @@ static int dump_core(sd_journal* j) {
}
r = save_core(j, output ? fileno(output) : STDOUT_FILENO, NULL, NULL);
- if (r < 0) {
- log_error_errno(r, "Coredump retrieval failed: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Coredump retrieval failed: %m");
r = sd_journal_previous(j);
if (r >= 0)
@@ -735,10 +728,8 @@ static int run_gdb(sd_journal *j) {
fputs("\n", stdout);
r = sd_journal_get_data(j, "COREDUMP_EXE", (const void**) &data, &len);
- if (r < 0) {
- log_error_errno(r, "Failed to retrieve COREDUMP_EXE field: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to retrieve COREDUMP_EXE field: %m");
assert(len > strlen("COREDUMP_EXE="));
data += strlen("COREDUMP_EXE=");
@@ -759,10 +750,8 @@ static int run_gdb(sd_journal *j) {
}
r = save_core(j, -1, &path, &unlink_path);
- if (r < 0) {
- log_error_errno(r, "Failed to retrieve core: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to retrieve core: %m");
pid = fork();
if (pid < 0) {
diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
index 96b0ddd80f..d6e6332915 100644
--- a/src/journal/journalctl.c
+++ b/src/journal/journalctl.c
@@ -501,10 +501,8 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_FILE:
r = glob_extend(&arg_file, optarg);
- if (r < 0) {
- log_error_errno(r, "Failed to add paths: %m");
- return r;
- };
+ if (r < 0)
+ return log_error_errno(r, "Failed to add paths: %m");
break;
case ARG_ROOT:
@@ -749,10 +747,8 @@ static int generate_new_id128(void) {
unsigned i;
r = sd_id128_randomize(&id);
- if (r < 0) {
- log_error_errno(r, "Failed to generate ID: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to generate ID: %m");
printf("As string:\n"
SD_ID128_FORMAT_STR "\n\n"
@@ -851,10 +847,8 @@ static int add_matches(sd_journal *j, char **args) {
have_term = true;
}
- if (r < 0) {
- log_error_errno(r, "Failed to add match '%s': %m", *i);
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add match '%s': %m", *i);
}
if (!strv_isempty(args) && !have_term) {
@@ -1040,10 +1034,8 @@ static int add_boot(sd_journal *j) {
sd_id128_to_string(arg_boot_id, match + 9);
r = sd_journal_add_match(j, match, sizeof(match) - 1);
- if (r < 0) {
- log_error_errno(r, "Failed to add match: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add match: %m");
r = sd_journal_add_conjunction(j);
if (r < 0)
@@ -1060,10 +1052,8 @@ static int add_dmesg(sd_journal *j) {
return 0;
r = sd_journal_add_match(j, "_TRANSPORT=kernel", strlen("_TRANSPORT=kernel"));
- if (r < 0) {
- log_error_errno(r, "Failed to add match: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add match: %m");
r = sd_journal_add_conjunction(j);
if (r < 0)
@@ -1263,10 +1253,8 @@ static int add_priorities(sd_journal *j) {
match[sizeof(match)-2] = '0' + i;
r = sd_journal_add_match(j, match, strlen(match));
- if (r < 0) {
- log_error_errno(r, "Failed to add match: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add match: %m");
}
r = sd_journal_add_conjunction(j);
@@ -1327,16 +1315,12 @@ static int setup_keys(void) {
}
r = sd_id128_get_machine(&machine);
- if (r < 0) {
- log_error_errno(r, "Failed to get machine ID: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get machine ID: %m");
r = sd_id128_get_boot(&boot);
- if (r < 0) {
- log_error_errno(r, "Failed to get boot ID: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get boot ID: %m");
if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR "/fss",
SD_ID128_FORMAT_VAL(machine)) < 0)
@@ -1681,10 +1665,8 @@ static int flush_to_var(void) {
/* OK, let's actually do the full logic, send SIGUSR1 to the
* daemon and set up inotify to wait for the flushed file to appear */
r = bus_open_system_systemd(&bus);
- if (r < 0) {
- log_error_errno(r, "Failed to get D-Bus connection: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get D-Bus connection: %m");
r = sd_bus_call_method(
bus,
@@ -1724,16 +1706,12 @@ static int flush_to_var(void) {
}
r = fd_wait_for_event(watch_fd, POLLIN, USEC_INFINITY);
- if (r < 0) {
- log_error_errno(r, "Failed to wait for event: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to wait for event: %m");
r = flush_fd(watch_fd);
- if (r < 0) {
- log_error_errno(r, "Failed to flush inotify events: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to flush inotify events: %m");
}
return 0;
diff --git a/src/journal/journald-audit.c b/src/journal/journald-audit.c
index bd985f0e9d..18235d9308 100644
--- a/src/journal/journald-audit.c
+++ b/src/journal/journald-audit.c
@@ -308,10 +308,8 @@ static int map_all_fields(
continue;
r = m->map(m->journal_field, &v, iov, n_iov_allocated, n_iov);
- if (r < 0) {
- log_debug_errno(r, "Failed to parse audit array: %m");
- return r;
- }
+ if (r < 0)
+ return log_debug_errno(r, "Failed to parse audit array: %m");
if (r > 0) {
mapped = true;
@@ -322,10 +320,8 @@ static int map_all_fields(
if (!mapped) {
r = map_generic_field(prefix, &p, iov, n_iov_allocated, n_iov);
- if (r < 0) {
- log_debug_errno(r, "Failed to parse audit array: %m");
- return r;
- }
+ if (r < 0)
+ return log_debug_errno(r, "Failed to parse audit array: %m");
if (r == 0) {
/* Couldn't process as generic field, let's just skip over it */
@@ -547,10 +543,8 @@ int server_open_audit(Server *s) {
}
r = sd_event_add_io(s->event, &s->audit_event_source, s->audit_fd, EPOLLIN, process_datagram, s);
- if (r < 0) {
- log_error_errno(r, "Failed to add audit fd to event loop: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add audit fd to event loop: %m");
/* We are listening now, try to enable audit */
r = enable_audit(s->audit_fd, true);
diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c
index 3b3908fb3e..6b2edc191d 100644
--- a/src/journal/journald-native.c
+++ b/src/journal/journald-native.c
@@ -462,10 +462,8 @@ int server_open_native_socket(Server*s) {
}
r = sd_event_add_io(s->event, &s->native_event_source, s->native_fd, EPOLLIN, process_datagram, s);
- if (r < 0) {
- log_error_errno(r, "Failed to add native server fd to event loop: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add native server fd to event loop: %m");
return 0;
}
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 4f5d002d21..3d1947f25f 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -927,10 +927,8 @@ static int system_journal_open(Server *s, bool flush_requested) {
char ids[33];
r = sd_id128_get_machine(&machine);
- if (r < 0) {
- log_error_errno(r, "Failed to get machine id: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to get machine id: %m");
sd_id128_to_string(machine, ids);
@@ -999,10 +997,8 @@ static int system_journal_open(Server *s, bool flush_requested) {
r = journal_file_open_reliably(fn, O_RDWR|O_CREAT, 0640, s->compress, false, &s->runtime_metrics, s->mmap, NULL, &s->runtime_journal);
free(fn);
- if (r < 0) {
- log_error_errno(r, "Failed to open runtime journal: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to open runtime journal: %m");
}
if (s->runtime_journal)
@@ -1045,10 +1041,8 @@ int server_flush_to_var(Server *s) {
return r;
r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY);
- if (r < 0) {
- log_error_errno(r, "Failed to read runtime journal: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to read runtime journal: %m");
sd_journal_set_data_threshold(j, 0);
@@ -1453,15 +1447,12 @@ static int server_open_hostname(Server *s) {
return 0;
}
- log_error_errno(r, "Failed to register hostname fd in event loop: %m");
- return r;
+ return log_error_errno(r, "Failed to register hostname fd in event loop: %m");
}
r = sd_event_source_set_priority(s->hostname_event_source, SD_EVENT_PRIORITY_IMPORTANT-10);
- if (r < 0) {
- log_error_errno(r, "Failed to adjust priority of host name event source: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to adjust priority of host name event source: %m");
return 0;
}
@@ -1514,18 +1505,14 @@ int server_init(Server *s) {
return log_oom();
r = sd_event_default(&s->event);
- if (r < 0) {
- log_error_errno(r, "Failed to create event loop: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to create event loop: %m");
sd_event_set_watchdog(s->event, true);
n = sd_listen_fds(true);
- if (n < 0) {
- log_error_errno(n, "Failed to read listening file descriptors from environment: %m");
- return n;
- }
+ if (n < 0)
+ return log_error_errno(n, "Failed to read listening file descriptors from environment: %m");
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index 293006dc97..ee309d16b9 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -464,16 +464,12 @@ int server_open_stdout_socket(Server *s) {
fd_nonblock(s->stdout_fd, 1);
r = sd_event_add_io(s->event, &s->stdout_event_source, s->stdout_fd, EPOLLIN, stdout_stream_new, s);
- if (r < 0) {
- log_error_errno(r, "Failed to add stdout server fd to event source: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add stdout server fd to event source: %m");
r = sd_event_source_set_priority(s->stdout_event_source, SD_EVENT_PRIORITY_NORMAL+10);
- if (r < 0) {
- log_error_errno(r, "Failed to adjust priority of stdout server event source: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to adjust priority of stdout server event source: %m");
return 0;
}
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
index d7fa245721..45483eff36 100644
--- a/src/journal/journald-syslog.c
+++ b/src/journal/journald-syslog.c
@@ -466,10 +466,8 @@ int server_open_syslog_socket(Server *s) {
}
r = sd_event_add_io(s->event, &s->syslog_event_source, s->syslog_fd, EPOLLIN, process_datagram, s);
- if (r < 0) {
- log_error_errno(r, "Failed to add syslog server fd to event loop: %m");
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to add syslog server fd to event loop: %m");
return 0;
}