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/login | |
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/login')
-rw-r--r-- | src/login/inhibit.c | 2 | ||||
-rw-r--r-- | src/login/loginctl.c | 18 | ||||
-rw-r--r-- | src/login/logind-button.c | 2 | ||||
-rw-r--r-- | src/login/logind-core.c | 2 | ||||
-rw-r--r-- | src/login/logind-inhibit.c | 2 | ||||
-rw-r--r-- | src/login/logind-seat.c | 6 | ||||
-rw-r--r-- | src/login/logind-session.c | 4 | ||||
-rw-r--r-- | src/login/logind-user.c | 12 | ||||
-rw-r--r-- | src/login/logind.c | 70 | ||||
-rw-r--r-- | src/login/user-sessions.c | 2 |
10 files changed, 60 insertions, 60 deletions
diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 8c9d1165d2..3034e20f0e 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -235,7 +235,7 @@ int main(int argc, char *argv[]) { r = sd_bus_default_system(&bus); if (r < 0) { - log_error("Failed to connect to bus: %s", strerror(-r)); + log_error_errno(-r, "Failed to connect to bus: %m"); return EXIT_FAILURE; } diff --git a/src/login/loginctl.c b/src/login/loginctl.c index fcdf6275e9..d0fd14b90d 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -385,7 +385,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i); if (r < 0) { - log_error("Could not get properties: %s", strerror(-r)); + log_error_errno(-r, "Could not get properties: %m"); return r; } @@ -498,7 +498,7 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line) r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i); if (r < 0) { - log_error("Could not get properties: %s", strerror(-r)); + log_error_errno(-r, "Could not get properties: %m"); goto finish; } @@ -562,7 +562,7 @@ static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line) r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i); if (r < 0) { - log_error("Could not get properties: %s", strerror(-r)); + log_error_errno(-r, "Could not get properties: %m"); goto finish; } @@ -617,7 +617,7 @@ static int show_properties(sd_bus *bus, const char *path, bool *new_line) { r = bus_print_all_properties(bus, "org.freedesktop.login1", path, arg_property, arg_all); if (r < 0) - log_error("Could not get properties: %s", strerror(-r)); + log_error_errno(-r, "Could not get properties: %m"); return r; } @@ -700,7 +700,7 @@ static int show_user(sd_bus *bus, char **args, unsigned n) { r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); if (r < 0) { - log_error("Failed to look up user %s: %s", args[i], strerror(-r)); + log_error_errno(-r, "Failed to look up user %s: %m", args[i]); return r; } @@ -860,7 +860,7 @@ static int enable_linger(sd_bus *bus, char **args, unsigned n) { r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); if (r < 0) { - log_error("Failed to look up user %s: %s", args[i], strerror(-r)); + log_error_errno(-r, "Failed to look up user %s: %m", args[i]); return r; } @@ -893,7 +893,7 @@ static int terminate_user(sd_bus *bus, char **args, unsigned n) { r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); if (r < 0) { - log_error("Failed to look up user %s: %s", args[i], strerror(-r)); + log_error_errno(-r, "Failed to look up user %s: %m", args[i]); return r; } @@ -929,7 +929,7 @@ static int kill_user(sd_bus *bus, char **args, unsigned n) { r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); if (r < 0) { - log_error("Failed to look up user %s: %s", args[i], strerror(-r)); + log_error_errno(-r, "Failed to look up user %s: %m", args[i]); return r; } @@ -1308,7 +1308,7 @@ int main(int argc, char *argv[]) { r = bus_open_transport(arg_transport, arg_host, false, &bus); if (r < 0) { - log_error("Failed to create bus connection: %s", strerror(-r)); + log_error_errno(-r, "Failed to create bus connection: %m"); goto finish; } diff --git a/src/login/logind-button.c b/src/login/logind-button.c index e380dc0611..d2cc430845 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -263,7 +263,7 @@ int button_open(Button *b) { r = sd_event_add_io(b->manager->event, &b->io_event_source, b->fd, EPOLLIN, button_dispatch, b); if (r < 0) { - log_error("Failed to add button event: %s", strerror(-r)); + log_error_errno(-r, "Failed to add button event: %m"); goto fail; } diff --git a/src/login/logind-core.c b/src/login/logind-core.c index ed7ea5da31..0f4ac9fb81 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -551,7 +551,7 @@ bool manager_is_docked_or_multiple_displays(Manager *m) { * assume that we are docked. */ n = manager_count_displays(m); if (n < 0) - log_warning("Display counting failed: %s", strerror(-n)); + log_warning_errno(-n, "Display counting failed: %m"); else if (n > 1) { log_debug("Multiple (%i) displays connected.", n); return true; diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index a9e14af8db..198e7df78c 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -138,7 +138,7 @@ int inhibitor_save(Inhibitor *i) { finish: if (r < 0) - log_error("Failed to save inhibit data %s: %s", i->state_file, strerror(-r)); + log_error_errno(-r, "Failed to save inhibit data %s: %m", i->state_file); return r; } diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 709c6385e6..04909a991a 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -154,7 +154,7 @@ int seat_save(Seat *s) { finish: if (r < 0) - log_error("Failed to save seat data %s: %s", s->state_file, strerror(-r)); + log_error_errno(-r, "Failed to save seat data %s: %m", s->state_file); return r; } @@ -201,7 +201,7 @@ int seat_preallocate_vts(Seat *s) { q = vt_allocate(i); if (q < 0) { - log_error("Failed to preallocate VT %i: %s", i, strerror(-q)); + log_error_errno(-q, "Failed to preallocate VT %i: %m", i); r = q; } } @@ -221,7 +221,7 @@ int seat_apply_acls(Seat *s, Session *old_active) { !!s->active, s->active ? s->active->user->uid : 0); if (r < 0) - log_error("Failed to apply ACLs: %s", strerror(-r)); + log_error_errno(-r, "Failed to apply ACLs: %m"); return r; } diff --git a/src/login/logind-session.c b/src/login/logind-session.c index c4fe53bc61..1cbb64c438 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -292,7 +292,7 @@ int session_save(Session *s) { finish: if (r < 0) - log_error("Failed to save session data %s: %s", s->state_file, strerror(-r)); + log_error_errno(-r, "Failed to save session data %s: %m", s->state_file); return r; } @@ -338,7 +338,7 @@ int session_load(Session *s) { NULL); if (r < 0) { - log_error("Failed to read %s: %s", s->state_file, strerror(-r)); + log_error_errno(-r, "Failed to read %s: %m", s->state_file); return r; } diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 1205b48abb..7a39140d88 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -252,7 +252,7 @@ int user_save(User *u) { finish: if (r < 0) - log_error("Failed to save user data %s: %s", u->state_file, strerror(-r)); + log_error_errno(-r, "Failed to save user data %s: %m", u->state_file); return r; } @@ -278,7 +278,7 @@ int user_load(User *u) { if (r == -ENOENT) return 0; - log_error("Failed to read %s: %s", u->state_file, strerror(-r)); + log_error_errno(-r, "Failed to read %s: %m", u->state_file); return r; } @@ -311,7 +311,7 @@ static int user_mkdir_runtime_path(User *u) { r = mkdir_safe_label("/run/user", 0755, 0, 0); if (r < 0) { - log_error("Failed to create /run/user: %s", strerror(-r)); + log_error_errno(-r, "Failed to create /run/user: %m"); return r; } @@ -338,7 +338,7 @@ static int user_mkdir_runtime_path(User *u) { r = mount("tmpfs", p, "tmpfs", MS_NODEV|MS_NOSUID, t); if (r < 0) { - log_error("Failed to mount per-user tmpfs directory %s: %s", p, strerror(-r)); + log_error_errno(-r, "Failed to mount per-user tmpfs directory %s: %m", p); goto fail; } } @@ -510,14 +510,14 @@ static int user_remove_runtime_path(User *u) { r = rm_rf(u->runtime_path, false, false, false); if (r < 0) - log_error("Failed to remove runtime directory %s: %s", u->runtime_path, strerror(-r)); + log_error_errno(-r, "Failed to remove runtime directory %s: %m", u->runtime_path); if (umount2(u->runtime_path, MNT_DETACH) < 0) log_error("Failed to unmount user runtime directory %s: %m", u->runtime_path); r = rm_rf(u->runtime_path, false, true, false); if (r < 0) - log_error("Failed to remove runtime directory %s: %s", u->runtime_path, strerror(-r)); + log_error_errno(-r, "Failed to remove runtime directory %s: %m", u->runtime_path); free(u->runtime_path); u->runtime_path = NULL; diff --git a/src/login/logind.c b/src/login/logind.c index 69b219d89e..63e07ad9a3 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -339,7 +339,7 @@ static int manager_enumerate_linger_users(Manager *m) { k = manager_add_user_by_name(m, de->d_name, NULL); if (k < 0) { - log_notice("Couldn't add lingering user %s: %s", de->d_name, strerror(-k)); + log_notice_errno(-k, "Couldn't add lingering user %s: %m", de->d_name); r = k; } } @@ -375,7 +375,7 @@ static int manager_enumerate_users(Manager *m) { k = manager_add_user_by_name(m, de->d_name, &u); if (k < 0) { - log_error("Failed to add user by file name %s: %s", de->d_name, strerror(-k)); + log_error_errno(-k, "Failed to add user by file name %s: %m", de->d_name); r = k; continue; @@ -423,7 +423,7 @@ static int manager_enumerate_sessions(Manager *m) { k = manager_add_session(m, de->d_name, &s); if (k < 0) { - log_error("Failed to add session by file name %s: %s", de->d_name, strerror(-k)); + log_error_errno(-k, "Failed to add session by file name %s: %m", de->d_name); r = k; continue; @@ -464,7 +464,7 @@ static int manager_enumerate_inhibitors(Manager *m) { k = manager_add_inhibitor(m, de->d_name, &i); if (k < 0) { - log_notice("Couldn't add inhibitor %s: %s", de->d_name, strerror(-k)); + log_notice_errno(-k, "Couldn't add inhibitor %s: %m", de->d_name); r = k; continue; } @@ -584,49 +584,49 @@ static int manager_connect_bus(Manager *m) { r = sd_bus_default_system(&m->bus); if (r < 0) { - log_error("Failed to connect to system bus: %s", strerror(-r)); + log_error_errno(-r, "Failed to connect to system bus: %m"); return r; } r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/login1", "org.freedesktop.login1.Manager", manager_vtable, m); if (r < 0) { - log_error("Failed to add manager object vtable: %s", strerror(-r)); + log_error_errno(-r, "Failed to add manager object vtable: %m"); return r; } r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/login1/seat", "org.freedesktop.login1.Seat", seat_vtable, seat_object_find, m); if (r < 0) { - log_error("Failed to add seat object vtable: %s", strerror(-r)); + log_error_errno(-r, "Failed to add seat object vtable: %m"); return r; } r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/login1/seat", seat_node_enumerator, m); if (r < 0) { - log_error("Failed to add seat enumerator: %s", strerror(-r)); + log_error_errno(-r, "Failed to add seat enumerator: %m"); return r; } r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/login1/session", "org.freedesktop.login1.Session", session_vtable, session_object_find, m); if (r < 0) { - log_error("Failed to add session object vtable: %s", strerror(-r)); + log_error_errno(-r, "Failed to add session object vtable: %m"); return r; } r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/login1/session", session_node_enumerator, m); if (r < 0) { - log_error("Failed to add session enumerator: %s", strerror(-r)); + log_error_errno(-r, "Failed to add session enumerator: %m"); return r; } r = sd_bus_add_fallback_vtable(m->bus, NULL, "/org/freedesktop/login1/user", "org.freedesktop.login1.User", user_vtable, user_object_find, m); if (r < 0) { - log_error("Failed to add user object vtable: %s", strerror(-r)); + log_error_errno(-r, "Failed to add user object vtable: %m"); return r; } r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/login1/user", user_node_enumerator, m); if (r < 0) { - log_error("Failed to add user enumerator: %s", strerror(-r)); + log_error_errno(-r, "Failed to add user enumerator: %m"); return r; } @@ -639,7 +639,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/DBus'", match_name_owner_changed, m); if (r < 0) { - log_error("Failed to add match for NameOwnerChanged: %s", strerror(-r)); + log_error_errno(-r, "Failed to add match for NameOwnerChanged: %m"); return r; } @@ -652,7 +652,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/systemd1'", match_job_removed, m); if (r < 0) { - log_error("Failed to add match for JobRemoved: %s", strerror(-r)); + log_error_errno(-r, "Failed to add match for JobRemoved: %m"); return r; } @@ -665,7 +665,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/systemd1'", match_unit_removed, m); if (r < 0) { - log_error("Failed to add match for UnitRemoved: %s", strerror(-r)); + log_error_errno(-r, "Failed to add match for UnitRemoved: %m"); return r; } @@ -677,7 +677,7 @@ static int manager_connect_bus(Manager *m) { "member='PropertiesChanged'", match_properties_changed, m); if (r < 0) { - log_error("Failed to add match for PropertiesChanged: %s", strerror(-r)); + log_error_errno(-r, "Failed to add match for PropertiesChanged: %m"); return r; } @@ -690,7 +690,7 @@ static int manager_connect_bus(Manager *m) { "path='/org/freedesktop/systemd1'", match_reloading, m); if (r < 0) { - log_error("Failed to add match for Reloading: %s", strerror(-r)); + log_error_errno(-r, "Failed to add match for Reloading: %m"); return r; } @@ -709,13 +709,13 @@ static int manager_connect_bus(Manager *m) { r = sd_bus_request_name(m->bus, "org.freedesktop.login1", 0); if (r < 0) { - log_error("Failed to register name: %s", strerror(-r)); + log_error_errno(-r, "Failed to register name: %m"); return r; } r = sd_bus_attach_event(m->bus, m->event, 0); if (r < 0) { - log_error("Failed to attach bus to event loop: %s", strerror(-r)); + log_error_errno(-r, "Failed to attach bus to event loop: %m"); return r; } @@ -807,13 +807,13 @@ static int manager_connect_console(Manager *m) { r = ignore_signals(SIGRTMIN + 1, -1); if (r < 0) { - log_error("Cannot ignore SIGRTMIN + 1: %s", strerror(-r)); + log_error_errno(-r, "Cannot ignore SIGRTMIN + 1: %m"); return r; } r = sigprocmask_many(SIG_BLOCK, SIGRTMIN, -1); if (r < 0) { - log_error("Cannot block SIGRTMIN: %s", strerror(-r)); + log_error_errno(-r, "Cannot block SIGRTMIN: %m"); return r; } @@ -1017,25 +1017,25 @@ static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *us elapse, USEC_PER_SEC*30, manager_dispatch_idle_action, m); if (r < 0) { - log_error("Failed to add idle event source: %s", strerror(-r)); + log_error_errno(-r, "Failed to add idle event source: %m"); return r; } r = sd_event_source_set_priority(m->idle_action_event_source, SD_EVENT_PRIORITY_IDLE+10); if (r < 0) { - log_error("Failed to set idle event source priority: %s", strerror(-r)); + log_error_errno(-r, "Failed to set idle event source priority: %m"); return r; } } else { r = sd_event_source_set_time(m->idle_action_event_source, elapse); if (r < 0) { - log_error("Failed to set idle event timer: %s", strerror(-r)); + log_error_errno(-r, "Failed to set idle event timer: %m"); return r; } r = sd_event_source_set_enabled(m->idle_action_event_source, SD_EVENT_ONESHOT); if (r < 0) { - log_error("Failed to enable idle event timer: %s", strerror(-r)); + log_error_errno(-r, "Failed to enable idle event timer: %m"); return r; } } @@ -1062,7 +1062,7 @@ int manager_startup(Manager *m) { /* Connect to udev */ r = manager_connect_udev(m); if (r < 0) { - log_error("Failed to create udev watchers: %s", strerror(-r)); + log_error_errno(-r, "Failed to create udev watchers: %m"); return r; } @@ -1074,38 +1074,38 @@ int manager_startup(Manager *m) { /* Instantiate magic seat 0 */ r = manager_add_seat(m, "seat0", &m->seat0); if (r < 0) { - log_error("Failed to add seat0: %s", strerror(-r)); + log_error_errno(-r, "Failed to add seat0: %m"); return r; } r = manager_set_lid_switch_ignore(m, 0 + IGNORE_LID_SWITCH_STARTUP_USEC); if (r < 0) - log_warning("Failed to set up lid switch ignore event source: %s", strerror(-r)); + log_warning_errno(-r, "Failed to set up lid switch ignore event source: %m"); /* Deserialize state */ r = manager_enumerate_devices(m); if (r < 0) - log_warning("Device enumeration failed: %s", strerror(-r)); + log_warning_errno(-r, "Device enumeration failed: %m"); r = manager_enumerate_seats(m); if (r < 0) - log_warning("Seat enumeration failed: %s", strerror(-r)); + log_warning_errno(-r, "Seat enumeration failed: %m"); r = manager_enumerate_users(m); if (r < 0) - log_warning("User enumeration failed: %s", strerror(-r)); + log_warning_errno(-r, "User enumeration failed: %m"); r = manager_enumerate_sessions(m); if (r < 0) - log_warning("Session enumeration failed: %s", strerror(-r)); + log_warning_errno(-r, "Session enumeration failed: %m"); r = manager_enumerate_inhibitors(m); if (r < 0) - log_warning("Inhibitor enumeration failed: %s", strerror(-r)); + log_warning_errno(-r, "Inhibitor enumeration failed: %m"); r = manager_enumerate_buttons(m); if (r < 0) - log_warning("Button enumeration failed: %s", strerror(-r)); + log_warning_errno(-r, "Button enumeration failed: %m"); /* Remove stale objects before we start them */ manager_gc(m, false); @@ -1214,7 +1214,7 @@ int main(int argc, char *argv[]) { r = manager_startup(m); if (r < 0) { - log_error("Failed to fully start up daemon: %s", strerror(-r)); + log_error_errno(-r, "Failed to fully start up daemon: %m"); goto finish; } diff --git a/src/login/user-sessions.c b/src/login/user-sessions.c index ca5de41f40..3639a1836b 100644 --- a/src/login/user-sessions.c +++ b/src/login/user-sessions.c @@ -68,7 +68,7 @@ int main(int argc, char*argv[]) { r = write_string_file_atomic("/run/nologin", "System is going down."); if (r < 0) { - log_error("Failed to create /run/nologin: %s", strerror(-r)); + log_error_errno(-r, "Failed to create /run/nologin: %m"); return EXIT_FAILURE; } |