diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2014-11-28 11:58:34 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2014-11-28 12:04:41 +0100 |
commit | 0a1beeb64207eaa88ab9236787b1cbc2f704ae14 (patch) | |
tree | 50117277be2e2078d0373b944a30b4f09bb94443 /src/journal-remote | |
parent | b4d23205f238e06aaa31264628e20669e714acad (diff) |
treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'
Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
Diffstat (limited to 'src/journal-remote')
-rw-r--r-- | src/journal-remote/journal-gatewayd.c | 22 | ||||
-rw-r--r-- | src/journal-remote/journal-remote-write.c | 2 | ||||
-rw-r--r-- | src/journal-remote/journal-remote.c | 26 | ||||
-rw-r--r-- | src/journal-remote/journal-upload-journal.c | 16 | ||||
-rw-r--r-- | src/journal-remote/journal-upload.c | 12 | ||||
-rw-r--r-- | src/journal-remote/microhttpd-util.c | 4 |
6 files changed, 41 insertions, 41 deletions
diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index db81fe3ca3..499a5fc6a2 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -155,14 +155,14 @@ static ssize_t request_reader_entries( r = sd_journal_next(m->journal); if (r < 0) { - log_error("Failed to advance journal pointer: %s", strerror(-r)); + log_error_errno(-r, "Failed to advance journal pointer: %m"); return MHD_CONTENT_READER_END_WITH_ERROR; } else if (r == 0) { if (m->follow) { r = sd_journal_wait(m->journal, (uint64_t) -1); if (r < 0) { - log_error("Couldn't wait for journal event: %s", strerror(-r)); + log_error_errno(-r, "Couldn't wait for journal event: %m"); return MHD_CONTENT_READER_END_WITH_ERROR; } @@ -177,7 +177,7 @@ static ssize_t request_reader_entries( r = sd_journal_test_cursor(m->journal, m->cursor); if (r < 0) { - log_error("Failed to test cursor: %s", strerror(-r)); + log_error_errno(-r, "Failed to test cursor: %m"); return MHD_CONTENT_READER_END_WITH_ERROR; } @@ -205,7 +205,7 @@ static ssize_t request_reader_entries( r = output_journal(m->tmp, m->journal, m->mode, 0, OUTPUT_FULL_WIDTH, NULL); if (r < 0) { - log_error("Failed to serialize item: %s", strerror(-r)); + log_error_errno(-r, "Failed to serialize item: %m"); return MHD_CONTENT_READER_END_WITH_ERROR; } @@ -394,7 +394,7 @@ static int request_parse_arguments_iterator( r = sd_id128_get_boot(&bid); if (r < 0) { - log_error("Failed to get boot ID: %s", strerror(-r)); + log_error_errno(-r, "Failed to get boot ID: %m"); return MHD_NO; } @@ -543,7 +543,7 @@ static ssize_t request_reader_fields( r = sd_journal_enumerate_unique(m->journal, &d, &l); if (r < 0) { - log_error("Failed to advance field index: %s", strerror(-r)); + log_error_errno(-r, "Failed to advance field index: %m"); return MHD_CONTENT_READER_END_WITH_ERROR; } else if (r == 0) return MHD_CONTENT_READER_END_OF_STREAM; @@ -566,7 +566,7 @@ static ssize_t request_reader_fields( r = output_field(m->tmp, m->mode, d, l); if (r < 0) { - log_error("Failed to serialize item: %s", strerror(-r)); + log_error_errno(-r, "Failed to serialize item: %m"); return MHD_CONTENT_READER_END_WITH_ERROR; } @@ -910,7 +910,7 @@ static int parse_argv(int argc, char *argv[]) { } r = read_full_file(optarg, &key_pem, NULL); if (r < 0) { - log_error("Failed to read key file: %s", strerror(-r)); + log_error_errno(-r, "Failed to read key file: %m"); return r; } assert(key_pem); @@ -923,7 +923,7 @@ static int parse_argv(int argc, char *argv[]) { } r = read_full_file(optarg, &cert_pem, NULL); if (r < 0) { - log_error("Failed to read certificate file: %s", strerror(-r)); + log_error_errno(-r, "Failed to read certificate file: %m"); return r; } assert(cert_pem); @@ -937,7 +937,7 @@ static int parse_argv(int argc, char *argv[]) { } r = read_full_file(optarg, &trust_pem, NULL); if (r < 0) { - log_error("Failed to read CA certificate file: %s", strerror(-r)); + log_error_errno(-r, "Failed to read CA certificate file: %m"); return r; } assert(trust_pem); @@ -992,7 +992,7 @@ int main(int argc, char *argv[]) { n = sd_listen_fds(1); if (n < 0) { - log_error("Failed to determine passed sockets: %s", strerror(-n)); + log_error_errno(-n, "Failed to determine passed sockets: %m"); goto finish; } else if (n > 1) { log_error("Can't listen on more than one socket."); diff --git a/src/journal-remote/journal-remote-write.c b/src/journal-remote/journal-remote-write.c index 0139f851a5..ac59cb7a17 100644 --- a/src/journal-remote/journal-remote-write.c +++ b/src/journal-remote/journal-remote-write.c @@ -153,7 +153,7 @@ int writer_write(Writer *w, return 1; } - log_debug("%s: Write failed, rotating: %s", w->journal->path, strerror(-r)); + log_debug_errno(-r, "%s: Write failed, rotating: %m", w->journal->path); r = do_rotate(&w->journal, compress, seal); if (r < 0) return r; diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index b3f5c828dd..d2050eff9f 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -151,13 +151,13 @@ static int spawn_getter(const char *getter, const char *url) { assert(getter); r = strv_split_quoted(&words, getter, false); if (r < 0) { - log_error("Failed to split getter option: %s", strerror(-r)); + log_error_errno(-r, "Failed to split getter option: %m"); return r; } r = strv_extend(&words, url); if (r < 0) { - log_error("Failed to create command line: %s", strerror(-r)); + log_error_errno(-r, "Failed to create command line: %m"); return r; } @@ -400,7 +400,7 @@ static int add_source(RemoteServer *s, int fd, char* name, bool own_name) { r = sd_event_source_set_description(source->event, name); if (r < 0) { - log_error("Failed to set source name for fd:%d: %s", fd, strerror(-r)); + log_error_errno(-r, "Failed to set source name for fd:%d: %m", fd); goto error; } @@ -662,7 +662,7 @@ static int setup_microhttpd_server(RemoteServer *s, r = fd_nonblock(fd, true); if (r < 0) { - log_error("Failed to make fd:%d nonblocking: %s", fd, strerror(-r)); + log_error_errno(-r, "Failed to make fd:%d nonblocking: %m", fd); return r; } @@ -720,13 +720,13 @@ static int setup_microhttpd_server(RemoteServer *s, epoll_fd, EPOLLIN, dispatch_http_event, d); if (r < 0) { - log_error("Failed to add event callback: %s", strerror(-r)); + log_error_errno(-r, "Failed to add event callback: %m"); goto error; } r = sd_event_source_set_description(d->event, "epoll-fd"); if (r < 0) { - log_error("Failed to set source name: %s", strerror(-r)); + log_error_errno(-r, "Failed to set source name: %m"); goto error; } @@ -738,7 +738,7 @@ static int setup_microhttpd_server(RemoteServer *s, r = hashmap_put(s->daemons, &d->fd, d); if (r < 0) { - log_error("Failed to add daemon to hashmap: %s", strerror(-r)); + log_error_errno(-r, "Failed to add daemon to hashmap: %m"); goto error; } @@ -841,7 +841,7 @@ static int remoteserver_init(RemoteServer *s, r = sd_event_default(&s->events); if (r < 0) { - log_error("Failed to allocate event loop: %s", strerror(-r)); + log_error_errno(-r, "Failed to allocate event loop: %m"); return r; } @@ -882,7 +882,7 @@ static int remoteserver_init(RemoteServer *s, r = getnameinfo_pretty(fd, &hostname); if (r < 0) { - log_error("Failed to retrieve remote name: %s", strerror(-r)); + log_error_errno(-r, "Failed to retrieve remote name: %m"); return r; } @@ -1051,7 +1051,7 @@ static int dispatch_raw_source_event(sd_event_source *event, } else if (r == -EAGAIN) { return 0; } else if (r < 0) { - log_info("Closing connection: %s", strerror(-r)); + log_info_errno(-r, "Closing connection: %m"); remove_source(server, fd); return 0; } else @@ -1084,7 +1084,7 @@ static int accept_connection(const char* type, int fd, r = socket_address_print(addr, &a); if (r < 0) { - log_error("socket_address_print(): %s", strerror(-r)); + log_error_errno(-r, "socket_address_print(): %m"); close(fd2); return r; } @@ -1542,7 +1542,7 @@ int main(int argc, char **argv) { r = sd_event_set_watchdog(s.events, true); if (r < 0) - log_error("Failed to enable watchdog: %s", strerror(-r)); + log_error_errno(-r, "Failed to enable watchdog: %m"); else log_debug("Watchdog is %s.", r > 0 ? "enabled" : "disabled"); @@ -1561,7 +1561,7 @@ int main(int argc, char **argv) { r = sd_event_run(s.events, -1); if (r < 0) { - log_error("Failed to run event loop: %s", strerror(-r)); + log_error_errno(-r, "Failed to run event loop: %m"); break; } } diff --git a/src/journal-remote/journal-upload-journal.c b/src/journal-remote/journal-upload-journal.c index 1cd52db2c1..290cfb9f56 100644 --- a/src/journal-remote/journal-upload-journal.c +++ b/src/journal-remote/journal-upload-journal.c @@ -26,7 +26,7 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) { r = sd_journal_get_cursor(u->journal, &u->current_cursor); if (r < 0) { - log_error("Failed to get cursor: %s", strerror(-r)); + log_error_errno(-r, "Failed to get cursor: %m"); return r; } @@ -52,7 +52,7 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) { r = sd_journal_get_realtime_usec(u->journal, &realtime); if (r < 0) { - log_error("Failed to get realtime timestamp: %s", strerror(-r)); + log_error_errno(-r, "Failed to get realtime timestamp: %m"); return r; } @@ -79,7 +79,7 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) { r = sd_journal_get_monotonic_usec(u->journal, &monotonic, &boot_id); if (r < 0) { - log_error("Failed to get monotonic timestamp: %s", strerror(-r)); + log_error_errno(-r, "Failed to get monotonic timestamp: %m"); return r; } @@ -106,7 +106,7 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) { r = sd_journal_get_monotonic_usec(u->journal, NULL, &boot_id); if (r < 0) { - log_error("Failed to get monotonic timestamp: %s", strerror(-r)); + log_error_errno(-r, "Failed to get monotonic timestamp: %m"); return r; } @@ -305,7 +305,7 @@ static int process_journal_input(Uploader *u, int skip) { r = sd_journal_next_skip(u->journal, skip); if (r < 0) { - log_error("Failed to skip to next entry: %s", strerror(-r)); + log_error_errno(-r, "Failed to skip to next entry: %m"); return r; } else if (r < skip) return 0; @@ -321,7 +321,7 @@ int check_journal_input(Uploader *u) { r = sd_journal_process(u->journal); if (r < 0) { - log_error("Failed to process journal: %s", strerror(-r)); + log_error_errno(-r, "Failed to process journal: %m"); close_journal_input(u); return r; } @@ -364,7 +364,7 @@ int open_journal_for_upload(Uploader *u, if (follow) { fd = sd_journal_get_fd(j); if (fd < 0) { - log_error("sd_journal_get_fd failed: %s", strerror(-fd)); + log_error_errno(-fd, "sd_journal_get_fd failed: %m"); return fd; } @@ -380,7 +380,7 @@ int open_journal_for_upload(Uploader *u, r = sd_event_add_io(u->events, &u->input_event, fd, events, dispatch_journal_input, u); if (r < 0) { - log_error("Failed to register input event: %s", strerror(-r)); + log_error_errno(-r, "Failed to register input event: %m"); return r; } diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 9f13ffdbfe..36c0241d02 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -147,7 +147,7 @@ static int update_cursor_state(Uploader *u) { finish: if (r < 0) - log_error("Failed to save state %s: %s", u->state_file, strerror(-r)); + log_error_errno(-r, "Failed to save state %s: %m", u->state_file); return r; } @@ -375,7 +375,7 @@ static int open_file_for_upload(Uploader *u, const char *filename) { fd, EPOLLIN, dispatch_fd_input, u); if (r < 0) { if (r != -EPERM || arg_follow > 0) { - log_error("Failed to register input event: %s", strerror(-r)); + log_error_errno(-r, "Failed to register input event: %m"); return r; } @@ -459,13 +459,13 @@ static int setup_uploader(Uploader *u, const char *url, const char *state_file) r = sd_event_default(&u->events); if (r < 0) { - log_error("sd_event_default failed: %s", strerror(-r)); + log_error_errno(-r, "sd_event_default failed: %m"); return r; } r = setup_signals(u); if (r < 0) { - log_error("Failed to set up signals: %s", strerror(-r)); + log_error_errno(-r, "Failed to set up signals: %m"); return r; } @@ -702,7 +702,7 @@ static int parse_argv(int argc, char *argv[]) { case ARG_FILE: r = glob_extend(&arg_file, optarg); if (r < 0) { - log_error("Failed to add paths: %s", strerror(-r)); + log_error_errno(-r, "Failed to add paths: %m"); return r; }; break; @@ -869,7 +869,7 @@ int main(int argc, char **argv) { r = sd_event_run(u.events, u.timeout); if (r < 0) { - log_error("Failed to run event loop: %s", strerror(-r)); + log_error_errno(-r, "Failed to run event loop: %m"); break; } } diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c index 5dae10bd80..3df34b2323 100644 --- a/src/journal-remote/microhttpd-util.c +++ b/src/journal-remote/microhttpd-util.c @@ -171,14 +171,14 @@ static int verify_cert_authorized(gnutls_session_t session) { r = gnutls_certificate_verify_peers2(session, &status); if (r < 0) { - log_error("gnutls_certificate_verify_peers2 failed: %s", strerror(-r)); + log_error_errno(-r, "gnutls_certificate_verify_peers2 failed: %m"); return r; } type = gnutls_certificate_type_get(session); r = gnutls_certificate_verification_status_print(status, type, &out, 0); if (r < 0) { - log_error("gnutls_certificate_verification_status_print failed: %s", strerror(-r)); + log_error_errno(-r, "gnutls_certificate_verification_status_print failed: %m"); return r; } |