diff options
author | Michal Schmidt <mschmidt@redhat.com> | 2014-11-28 18:50:43 +0100 |
---|---|---|
committer | Michal Schmidt <mschmidt@redhat.com> | 2014-11-28 18:56:16 +0100 |
commit | f647962d64e844689f3e2acfce6102fc47e76df2 (patch) | |
tree | dcaf5e38de1d4e31f73f540bc85532ceb72cfa6b /src/login | |
parent | e80733be33e52d8ab2f1ae845326d39c600f5612 (diff) |
treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
'local $/;
local $_=<>;
s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
print;'
$f
done
And a couple of manual whitespace fixups.
Diffstat (limited to 'src/login')
-rw-r--r-- | src/login/loginctl.c | 30 | ||||
-rw-r--r-- | src/login/logind-session.c | 6 | ||||
-rw-r--r-- | src/login/logind-user.c | 6 | ||||
-rw-r--r-- | src/login/logind.c | 138 |
4 files changed, 60 insertions, 120 deletions
diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 80e03ebbec..6505eb89c1 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -384,10 +384,8 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li int r; r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &i); - if (r < 0) { - log_error_errno(r, "Could not get properties: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Could not get properties: %m"); if (*new_line) printf("\n"); @@ -699,10 +697,8 @@ static int show_user(sd_bus *bus, char **args, unsigned n) { uid_t uid; r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); - if (r < 0) { - log_error_errno(r, "Failed to look up user %s: %m", args[i]); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to look up user %s: %m", args[i]); r = sd_bus_call_method( bus, @@ -859,10 +855,8 @@ static int enable_linger(sd_bus *bus, char **args, unsigned n) { uid_t uid; r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); - if (r < 0) { - log_error_errno(r, "Failed to look up user %s: %m", args[i]); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to look up user %s: %m", args[i]); r = sd_bus_call_method ( bus, @@ -892,10 +886,8 @@ static int terminate_user(sd_bus *bus, char **args, unsigned n) { uid_t uid; r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); - if (r < 0) { - log_error_errno(r, "Failed to look up user %s: %m", args[i]); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to look up user %s: %m", args[i]); r = sd_bus_call_method ( bus, @@ -928,10 +920,8 @@ static int kill_user(sd_bus *bus, char **args, unsigned n) { uid_t uid; r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL); - if (r < 0) { - log_error_errno(r, "Failed to look up user %s: %m", args[i]); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to look up user %s: %m", args[i]); r = sd_bus_call_method ( bus, diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 20161ede9d..5b30457a88 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -337,10 +337,8 @@ int session_load(Session *s) { "CONTROLLER", &controller, NULL); - if (r < 0) { - log_error_errno(r, "Failed to read %s: %m", s->state_file); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to read %s: %m", s->state_file); if (!s->user) { uid_t u; diff --git a/src/login/logind-user.c b/src/login/logind-user.c index d2a4f7e9cb..f865afdb53 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -310,10 +310,8 @@ static int user_mkdir_runtime_path(User *u) { assert(u); r = mkdir_safe_label("/run/user", 0755, 0, 0); - if (r < 0) { - log_error_errno(r, "Failed to create /run/user: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to create /run/user: %m"); if (!u->runtime_path) { if (asprintf(&p, "/run/user/" UID_FMT, u->uid) < 0) diff --git a/src/login/logind.c b/src/login/logind.c index d7fb1bf170..78220ff4dd 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -583,52 +583,36 @@ static int manager_connect_bus(Manager *m) { assert(!m->bus); r = sd_bus_default_system(&m->bus); - if (r < 0) { - log_error_errno(r, "Failed to connect to system bus: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to connect to system bus: %m"); r = sd_bus_add_object_vtable(m->bus, NULL, "/org/freedesktop/login1", "org.freedesktop.login1.Manager", manager_vtable, m); - if (r < 0) { - log_error_errno(r, "Failed to add manager object vtable: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add manager object vtable: %m"); 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_errno(r, "Failed to add seat object vtable: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add seat object vtable: %m"); r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/login1/seat", seat_node_enumerator, m); - if (r < 0) { - log_error_errno(r, "Failed to add seat enumerator: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add seat enumerator: %m"); 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_errno(r, "Failed to add session object vtable: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add session object vtable: %m"); r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/login1/session", session_node_enumerator, m); - if (r < 0) { - log_error_errno(r, "Failed to add session enumerator: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add session enumerator: %m"); 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_errno(r, "Failed to add user object vtable: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add user object vtable: %m"); r = sd_bus_add_node_enumerator(m->bus, NULL, "/org/freedesktop/login1/user", user_node_enumerator, m); - if (r < 0) { - log_error_errno(r, "Failed to add user enumerator: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add user enumerator: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -638,10 +622,8 @@ static int manager_connect_bus(Manager *m) { "member='NameOwnerChanged'," "path='/org/freedesktop/DBus'", match_name_owner_changed, m); - if (r < 0) { - log_error_errno(r, "Failed to add match for NameOwnerChanged: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add match for NameOwnerChanged: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -651,10 +633,8 @@ static int manager_connect_bus(Manager *m) { "member='JobRemoved'," "path='/org/freedesktop/systemd1'", match_job_removed, m); - if (r < 0) { - log_error_errno(r, "Failed to add match for JobRemoved: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add match for JobRemoved: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -664,10 +644,8 @@ static int manager_connect_bus(Manager *m) { "member='UnitRemoved'," "path='/org/freedesktop/systemd1'", match_unit_removed, m); - if (r < 0) { - log_error_errno(r, "Failed to add match for UnitRemoved: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add match for UnitRemoved: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -676,10 +654,8 @@ static int manager_connect_bus(Manager *m) { "interface='org.freedesktop.DBus.Properties'," "member='PropertiesChanged'", match_properties_changed, m); - if (r < 0) { - log_error_errno(r, "Failed to add match for PropertiesChanged: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add match for PropertiesChanged: %m"); r = sd_bus_add_match(m->bus, NULL, @@ -689,10 +665,8 @@ static int manager_connect_bus(Manager *m) { "member='Reloading'," "path='/org/freedesktop/systemd1'", match_reloading, m); - if (r < 0) { - log_error_errno(r, "Failed to add match for Reloading: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add match for Reloading: %m"); r = sd_bus_call_method( m->bus, @@ -708,16 +682,12 @@ static int manager_connect_bus(Manager *m) { } r = sd_bus_request_name(m->bus, "org.freedesktop.login1", 0); - if (r < 0) { - log_error_errno(r, "Failed to register name: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to register name: %m"); r = sd_bus_attach_event(m->bus, m->event, 0); - if (r < 0) { - log_error_errno(r, "Failed to attach bus to event loop: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to attach bus to event loop: %m"); return 0; } @@ -806,16 +776,12 @@ static int manager_connect_console(Manager *m) { } r = ignore_signals(SIGRTMIN + 1, -1); - if (r < 0) { - log_error_errno(r, "Cannot ignore SIGRTMIN + 1: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Cannot ignore SIGRTMIN + 1: %m"); r = sigprocmask_many(SIG_BLOCK, SIGRTMIN, -1); - if (r < 0) { - log_error_errno(r, "Cannot block SIGRTMIN: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Cannot block SIGRTMIN: %m"); r = sd_event_add_signal(m->event, NULL, SIGRTMIN, manager_vt_switch, m); if (r < 0) @@ -1016,28 +982,20 @@ static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *us CLOCK_MONOTONIC, elapse, USEC_PER_SEC*30, manager_dispatch_idle_action, m); - if (r < 0) { - log_error_errno(r, "Failed to add idle event source: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add idle event source: %m"); r = sd_event_source_set_priority(m->idle_action_event_source, SD_EVENT_PRIORITY_IDLE+10); - if (r < 0) { - log_error_errno(r, "Failed to set idle event source priority: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to set idle event source priority: %m"); } else { r = sd_event_source_set_time(m->idle_action_event_source, elapse); - if (r < 0) { - log_error_errno(r, "Failed to set idle event timer: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to set idle event timer: %m"); r = sd_event_source_set_enabled(m->idle_action_event_source, SD_EVENT_ONESHOT); - if (r < 0) { - log_error_errno(r, "Failed to enable idle event timer: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to enable idle event timer: %m"); } return 0; @@ -1061,10 +1019,8 @@ int manager_startup(Manager *m) { /* Connect to udev */ r = manager_connect_udev(m); - if (r < 0) { - log_error_errno(r, "Failed to create udev watchers: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to create udev watchers: %m"); /* Connect to the bus */ r = manager_connect_bus(m); @@ -1073,10 +1029,8 @@ int manager_startup(Manager *m) { /* Instantiate magic seat 0 */ r = manager_add_seat(m, "seat0", &m->seat0); - if (r < 0) { - log_error_errno(r, "Failed to add seat0: %m"); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to add seat0: %m"); r = manager_set_lid_switch_ignore(m, 0 + IGNORE_LID_SWITCH_STARTUP_USEC); if (r < 0) |