diff options
Diffstat (limited to 'src/login')
-rw-r--r-- | src/login/70-power-switch.rules | 2 | ||||
-rw-r--r-- | src/login/loginctl.c | 8 | ||||
-rw-r--r-- | src/login/logind-core.c | 38 | ||||
-rw-r--r-- | src/login/logind-dbus.c | 63 | ||||
-rw-r--r-- | src/login/logind-inhibit.c | 25 | ||||
-rw-r--r-- | src/login/logind-seat.c | 25 | ||||
-rw-r--r-- | src/login/logind-session.c | 65 | ||||
-rw-r--r-- | src/login/logind-session.h | 1 | ||||
-rw-r--r-- | src/login/logind-user.c | 25 | ||||
-rw-r--r-- | src/login/logind.c | 18 | ||||
-rw-r--r-- | src/login/logind.h | 5 |
11 files changed, 114 insertions, 161 deletions
diff --git a/src/login/70-power-switch.rules b/src/login/70-power-switch.rules index 695d246370..71f9fe6c72 100644 --- a/src/login/70-power-switch.rules +++ b/src/login/70-power-switch.rules @@ -11,5 +11,7 @@ SUBSYSTEM=="input", KERNEL=="event*", SUBSYSTEMS=="acpi", TAG+="power-switch" SUBSYSTEM=="input", KERNEL=="event*", KERNELS=="thinkpad_acpi", TAG+="power-switch" SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="twl4030_pwrbutton", TAG+="power-switch" SUBSYSTEM=="input", KERNEL=="event*", ATTRS{name}=="tps65217_pwr_but", TAG+="power-switch" +SUBSYSTEM=="input", KERNEL=="event*", \ + SUBSYSTEMS=="platform", DRIVERS=="gpio-keys", ATTRS{keys}=="116", TAG+="power-switch" LABEL="power_switch_end" diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 9709eca9bd..5fa98e069f 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -372,11 +372,9 @@ static int prop_map_first_of_struct(sd_bus *bus, const char *member, sd_bus_mess if (r < 0) return r; - free(*p); - *p = strdup(s); - - if (!*p) - return -ENOMEM; + r = free_and_strdup(p, s); + if (r < 0) + return r; } else { r = sd_bus_message_read_basic(m, contents[0], userdata); if (r < 0) diff --git a/src/login/logind-core.c b/src/login/logind-core.c index 96a20e27b9..6c05c11dbd 100644 --- a/src/login/logind-core.c +++ b/src/login/logind-core.c @@ -183,44 +183,6 @@ int manager_add_button(Manager *m, const char *name, Button **_button) { return 0; } -int manager_watch_busname(Manager *m, const char *name) { - char *n; - int r; - - assert(m); - assert(name); - - if (set_get(m->busnames, (char*) name)) - return 0; - - n = strdup(name); - if (!n) - return -ENOMEM; - - r = set_put(m->busnames, n); - if (r < 0) { - free(n); - return r; - } - - return 0; -} - -void manager_drop_busname(Manager *m, const char *name) { - Session *session; - Iterator i; - - assert(m); - assert(name); - - /* keep it if the name still owns a controller */ - HASHMAP_FOREACH(session, m->sessions, i) - if (session_is_controller(session, name)) - return; - - free(set_remove(m->busnames, (char*) name)); -} - int manager_process_seat_device(Manager *m, struct udev_device *d) { Device *device; int r; diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index e6371ff04d..1647bb293a 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -725,15 +725,13 @@ static int method_create_session(sd_bus_message *message, void *userdata, sd_bus log_warning("Existing logind session ID %s used by new audit session, ignoring", id); audit_id = 0; - free(id); - id = NULL; + id = mfree(id); } } if (!id) { do { - free(id); - id = NULL; + id = mfree(id); if (asprintf(&id, "c%lu", ++m->session_counter) < 0) return -ENOMEM; @@ -1816,17 +1814,22 @@ static int update_schedule_file(Manager *m) { if (!isempty(m->wall_message)) fprintf(f, "WALL_MESSAGE=%s\n", t); - (void) fflush_and_check(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, "/run/systemd/shutdown/scheduled") < 0) { - log_error_errno(errno, "Failed to write information about scheduled shutdowns: %m"); + if (rename(temp_path, "/run/systemd/shutdown/scheduled") < 0) { r = -errno; - - (void) unlink(temp_path); - (void) unlink("/run/systemd/shutdown/scheduled"); + goto fail; } - return r; + return 0; + +fail: + (void) unlink(temp_path); + (void) unlink("/run/systemd/shutdown/scheduled"); + + return log_error_errno(r, "Failed to write information about scheduled shutdowns: %m"); } static int manager_scheduled_shutdown_handler( @@ -2350,8 +2353,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error return r; do { - free(id); - id = NULL; + id = mfree(id); if (asprintf(&id, "%lu", ++m->inhibit_counter) < 0) return -ENOMEM; @@ -2650,41 +2652,6 @@ int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error return 0; } -int match_name_owner_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) { - const char *name, *old, *new; - Manager *m = userdata; - Session *session; - Iterator i; - int r; - char *key; - - assert(message); - assert(m); - - r = sd_bus_message_read(message, "sss", &name, &old, &new); - if (r < 0) { - bus_log_parse_error(r); - return r; - } - - if (isempty(old) || !isempty(new)) - return 0; - - key = set_remove(m->busnames, (char*) old); - if (!key) - return 0; - - /* Drop all controllers owned by this name */ - - free(key); - - HASHMAP_FOREACH(session, m->sessions, i) - if (session_is_controller(session, old)) - session_drop_controller(session); - - return 0; -} - int manager_send_changed(Manager *manager, const char *property, ...) { char **l; diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 855c85402c..a261e6a719 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -86,11 +86,11 @@ int inhibitor_save(Inhibitor *i) { r = mkdir_safe_label("/run/systemd/inhibit", 0755, 0, 0); if (r < 0) - goto finish; + goto fail; r = fopen_temporary(i->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; fchmod(fileno(f), 0644); @@ -128,19 +128,24 @@ int inhibitor_save(Inhibitor *i) { if (i->fifo_path) fprintf(f, "FIFO=%s\n", i->fifo_path); - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, i->state_file) < 0) { + if (rename(temp_path, i->state_file) < 0) { r = -errno; - unlink(i->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error_errno(r, "Failed to save inhibit data %s: %m", i->state_file); + return 0; - return r; +fail: + (void) unlink(i->state_file); + + if (temp_path) + (void) unlink(temp_path); + + return log_error_errno(r, "Failed to save inhibit data %s: %m", i->state_file); } int inhibitor_start(Inhibitor *i) { diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index 495ec50be0..8d13a63688 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -93,11 +93,11 @@ int seat_save(Seat *s) { r = mkdir_safe_label("/run/systemd/seats", 0755, 0, 0); if (r < 0) - goto finish; + goto fail; r = fopen_temporary(s->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; fchmod(fileno(f), 0644); @@ -141,19 +141,24 @@ int seat_save(Seat *s) { i->sessions_by_seat_next ? ' ' : '\n'); } - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, s->state_file) < 0) { + if (rename(temp_path, s->state_file) < 0) { r = -errno; - unlink(s->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error_errno(r, "Failed to save seat data %s: %m", s->state_file); + return 0; - return r; +fail: + (void) unlink(s->state_file); + + if (temp_path) + (void) unlink(temp_path); + + return log_error_errno(r, "Failed to save seat data %s: %m", s->state_file); } int seat_load(Seat *s) { diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 45f4c09d3d..fc92f7f73b 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -165,11 +165,11 @@ int session_save(Session *s) { r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0); if (r < 0) - goto finish; + goto fail; r = fopen_temporary(s->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; assert(s->user); @@ -217,7 +217,7 @@ int session_save(Session *s) { escaped = cescape(s->remote_host); if (!escaped) { r = -ENOMEM; - goto finish; + goto fail; } fprintf(f, "REMOTE_HOST=%s\n", escaped); @@ -229,7 +229,7 @@ int session_save(Session *s) { escaped = cescape(s->remote_user); if (!escaped) { r = -ENOMEM; - goto finish; + goto fail; } fprintf(f, "REMOTE_USER=%s\n", escaped); @@ -241,7 +241,7 @@ int session_save(Session *s) { escaped = cescape(s->service); if (!escaped) { r = -ENOMEM; - goto finish; + goto fail; } fprintf(f, "SERVICE=%s\n", escaped); @@ -254,7 +254,7 @@ int session_save(Session *s) { escaped = cescape(s->desktop); if (!escaped) { r = -ENOMEM; - goto finish; + goto fail; } fprintf(f, "DESKTOP=%s\n", escaped); @@ -282,21 +282,27 @@ int session_save(Session *s) { if (s->controller) fprintf(f, "CONTROLLER=%s\n", s->controller); - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, s->state_file) < 0) { + if (rename(temp_path, s->state_file) < 0) { r = -errno; - unlink(s->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error_errno(r, "Failed to save session data %s: %m", s->state_file); + return 0; - return r; +fail: + (void) unlink(s->state_file); + + if (temp_path) + (void) unlink(temp_path); + + return log_error_errno(r, "Failed to save session data %s: %m", s->state_file); } + int session_load(Session *s) { _cleanup_free_ char *remote = NULL, *seat = NULL, @@ -630,6 +636,9 @@ int session_stop(Session *s, bool force) { s->timer_event_source = sd_event_source_unref(s->timer_event_source); + if (s->seat) + seat_evict_position(s->seat, s); + /* We are going down, don't care about FIFOs anymore */ session_remove_fifo(s); @@ -666,6 +675,9 @@ int session_finalize(Session *s) { s->timer_event_source = sd_event_source_unref(s->timer_event_source); + if (s->seat) + seat_evict_position(s->seat, s); + /* Kill session devices */ while ((sd = hashmap_first(s->devices))) session_device_free(sd); @@ -1108,7 +1120,18 @@ static void session_release_controller(Session *s, bool notify) { session_device_free(sd); s->controller = NULL; - manager_drop_busname(s->manager, name); + s->track = sd_bus_track_unref(s->track); +} + +static int on_bus_track(sd_bus_track *track, void *userdata) { + Session *s = userdata; + + assert(track); + assert(s); + + session_drop_controller(s); + + return 0; } int session_set_controller(Session *s, const char *sender, bool force) { @@ -1127,8 +1150,13 @@ int session_set_controller(Session *s, const char *sender, bool force) { if (!name) return -ENOMEM; - r = manager_watch_busname(s->manager, name); - if (r) + s->track = sd_bus_track_unref(s->track); + r = sd_bus_track_new(s->manager->bus, &s->track, on_bus_track, s); + if (r < 0) + return r; + + r = sd_bus_track_add_name(s->track, name); + if (r < 0) return r; /* When setting a session controller, we forcibly mute the VT and set @@ -1141,7 +1169,7 @@ int session_set_controller(Session *s, const char *sender, bool force) { * or reset the VT in case it crashed/exited, too. */ r = session_prepare_vt(s); if (r < 0) { - manager_drop_busname(s->manager, name); + s->track = sd_bus_track_unref(s->track); return r; } @@ -1159,6 +1187,7 @@ void session_drop_controller(Session *s) { if (!s->controller) return; + s->track = sd_bus_track_unref(s->track); session_release_controller(s, false); session_save(s); session_restore_vt(s); diff --git a/src/login/logind-session.h b/src/login/logind-session.h index b8565ebf51..d054c33cec 100644 --- a/src/login/logind-session.h +++ b/src/login/logind-session.h @@ -117,6 +117,7 @@ struct Session { char *controller; Hashmap *devices; + sd_bus_track *track; LIST_FIELDS(Session, sessions_by_user); LIST_FIELDS(Session, sessions_by_seat); diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 21d7268120..5d8a7571cd 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -116,11 +116,11 @@ static int user_save_internal(User *u) { r = mkdir_safe_label("/run/systemd/users", 0755, 0, 0); if (r < 0) - goto finish; + goto fail; r = fopen_temporary(u->state_file, &f, &temp_path); if (r < 0) - goto finish; + goto fail; fchmod(fileno(f), 0644); @@ -241,19 +241,24 @@ static int user_save_internal(User *u) { fputc('\n', f); } - fflush(f); + r = fflush_and_check(f); + if (r < 0) + goto fail; - if (ferror(f) || rename(temp_path, u->state_file) < 0) { + if (rename(temp_path, u->state_file) < 0) { r = -errno; - unlink(u->state_file); - unlink(temp_path); + goto fail; } -finish: - if (r < 0) - log_error_errno(r, "Failed to save user data %s: %m", u->state_file); + return 0; - return r; +fail: + (void) unlink(u->state_file); + + if (temp_path) + (void) unlink(temp_path); + + return log_error_errno(r, "Failed to save user data %s: %m", u->state_file); } int user_save(User *u) { diff --git a/src/login/logind.c b/src/login/logind.c index e2fb496289..49a2811842 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -76,10 +76,7 @@ static Manager *manager_new(void) { m->user_units = hashmap_new(&string_hash_ops); m->session_units = hashmap_new(&string_hash_ops); - m->busnames = set_new(&string_hash_ops); - - if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->busnames || - !m->user_units || !m->session_units) + if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->user_units || !m->session_units) goto fail; m->kill_exclude_users = strv_new("root", NULL); @@ -141,8 +138,6 @@ static void manager_free(Manager *m) { hashmap_free(m->user_units); hashmap_free(m->session_units); - set_free_free(m->busnames); - sd_event_source_unref(m->idle_action_event_source); sd_event_source_unref(m->inhibit_timeout_source); sd_event_source_unref(m->scheduled_shutdown_timeout_source); @@ -629,17 +624,6 @@ static int manager_connect_bus(Manager *m) { r = sd_bus_add_match(m->bus, NULL, "type='signal'," - "sender='org.freedesktop.DBus'," - "interface='org.freedesktop.DBus'," - "member='NameOwnerChanged'," - "path='/org/freedesktop/DBus'", - match_name_owner_changed, m); - if (r < 0) - return log_error_errno(r, "Failed to add match for NameOwnerChanged: %m"); - - r = sd_bus_add_match(m->bus, - NULL, - "type='signal'," "sender='org.freedesktop.systemd1'," "interface='org.freedesktop.systemd1.Manager'," "member='JobRemoved'," diff --git a/src/login/logind.h b/src/login/logind.h index ad437b72cb..ce99d75bc1 100644 --- a/src/login/logind.h +++ b/src/login/logind.h @@ -48,8 +48,6 @@ struct Manager { Hashmap *inhibitors; Hashmap *buttons; - Set *busnames; - LIST_HEAD(Seat, seat_gc_queue); LIST_HEAD(Session, session_gc_queue); LIST_HEAD(User, user_gc_queue); @@ -181,9 +179,6 @@ int manager_job_is_active(Manager *manager, const char *path); /* gperf lookup function */ const struct ConfigPerfItem* logind_gperf_lookup(const char *key, unsigned length); -int manager_watch_busname(Manager *manager, const char *name); -void manager_drop_busname(Manager *manager, const char *name); - int manager_set_lid_switch_ignore(Manager *m, usec_t until); int config_parse_tmpfs_size(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata); |