chiark / gitweb /
Prep v225: Applying various fixes and changes to src/login that got lost during git...
authorSven Eden <yamakuzure@gmx.net>
Wed, 4 Jan 2017 05:40:46 +0000 (06:40 +0100)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 09:18:48 +0000 (10:18 +0100)
12 files changed:
src/login/loginctl.c
src/login/logind-core.c
src/login/logind-dbus.c
src/login/logind-inhibit.c
src/login/logind-seat.c
src/login/logind-session.c
src/login/logind-session.h
src/login/logind-user.c
src/login/logind.c
src/login/logind.h
src/login/org.freedesktop.login1.policy.in
src/login/test-login-shared.c

index 2a2c71f8f0ad35a2ad7ee91849b19e6ff70b65b0..cf4ca46631c629f2fdc0a37793a6a9ef481e3089 100644 (file)
@@ -375,11 +375,9 @@ static int prop_map_first_of_struct(sd_bus *bus, const char *member, sd_bus_mess
                 if (r < 0)
                         return r;
 
                 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)
         } else {
                 r = sd_bus_message_read_basic(m, contents[0], userdata);
                 if (r < 0)
index 440c32aa2cd2284e042f41bb2e834e0a2af0d241..107b3243a5a1701f1e2ac9ed017eaaf9dd0aa740 100644 (file)
@@ -183,44 +183,6 @@ int manager_add_button(Manager *m, const char *name, Button **_button) {
         return 0;
 }
 
         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;
 int manager_process_seat_device(Manager *m, struct udev_device *d) {
         Device *device;
         int r;
index 1f5cf865b1440824cd5680053ca4a9c99efe487f..768aa1a3190607f14a67465316c834453b04d6a2 100644 (file)
@@ -726,15 +726,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;
 
                         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 {
                 }
         }
 
         if (!id) {
                 do {
-                        free(id);
-                        id = NULL;
+                        id = mfree(id);
 
                         if (asprintf(&id, "c%lu", ++m->session_counter) < 0)
                                 return -ENOMEM;
 
                         if (asprintf(&id, "c%lu", ++m->session_counter) < 0)
                                 return -ENOMEM;
@@ -1342,7 +1340,8 @@ static int bus_manager_log_shutdown(
                 InhibitWhat w,
                 const char *unit_name) {
 
                 InhibitWhat w,
                 const char *unit_name) {
 
-        const char *p, *q;
+        const char *p;
+        const char *q;
 
         assert(m);
         assert(unit_name);
 
         assert(m);
         assert(unit_name);
@@ -1367,6 +1366,9 @@ static int bus_manager_log_shutdown(
                 q = NULL;
         }
 
                 q = NULL;
         }
 
+        if (m->wall_message)
+                p = strjoina(p, " (", m->wall_message, ")", NULL);
+
         return log_struct(LOG_NOTICE,
                           LOG_MESSAGE_ID(SD_MESSAGE_SHUTDOWN),
                           p,
         return log_struct(LOG_NOTICE,
                           LOG_MESSAGE_ID(SD_MESSAGE_SHUTDOWN),
                           p,
@@ -1803,17 +1805,22 @@ static int update_schedule_file(Manager *m) {
         if (!isempty(m->wall_message))
                 fprintf(f, "WALL_MESSAGE=%s\n", t);
 
         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;
                 r = -errno;
+                goto fail;
+        }
 
 
+        return 0;
+
+fail:
                 (void) unlink(temp_path);
                 (void) unlink("/run/systemd/shutdown/scheduled");
                 (void) unlink(temp_path);
                 (void) unlink("/run/systemd/shutdown/scheduled");
-        }
 
 
-        return r;
+        return log_error_errno(r, "Failed to write information about scheduled shutdowns: %m");
 }
 
 static int manager_scheduled_shutdown_handler(
 }
 
 static int manager_scheduled_shutdown_handler(
@@ -2261,6 +2268,44 @@ static int method_can_reboot_to_firmware_setup(
         return sd_bus_reply_method_return(message, "s", result);
 }
 
         return sd_bus_reply_method_return(message, "s", result);
 }
 
+static int method_set_wall_message(
+                sd_bus_message *message,
+                void *userdata,
+                sd_bus_error *error) {
+
+        int r;
+        Manager *m = userdata;
+        char *wall_message;
+        bool enable_wall_messages;
+
+        assert(message);
+        assert(m);
+
+        r = sd_bus_message_read(message, "sb", &wall_message, &enable_wall_messages);
+        if (r < 0)
+                return r;
+
+        r = bus_verify_polkit_async(message,
+                                    CAP_SYS_ADMIN,
+                                    "org.freedesktop.login1.set-wall-message",
+                                    false,
+                                    UID_INVALID,
+                                    &m->polkit_registry,
+                                    error);
+
+        if (r < 0)
+                return r;
+        if (r == 0)
+                return 1; /* Will call us back */
+
+        r = free_and_strdup(&m->wall_message, wall_message);
+        if (r < 0)
+                return log_oom();
+        m->enable_wall_messages = enable_wall_messages;
+
+        return sd_bus_reply_method_return(message, NULL);
+}
+
 static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error *error) {
         _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
         const char *who, *why, *what, *mode;
 static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error *error) {
         _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
         const char *who, *why, *what, *mode;
@@ -2332,8 +2377,7 @@ static int method_inhibit(sd_bus_message *message, void *userdata, sd_bus_error
                 return r;
 
         do {
                 return r;
 
         do {
-                free(id);
-                id = NULL;
+                id = mfree(id);
 
                 if (asprintf(&id, "%lu", ++m->inhibit_counter) < 0)
                         return -ENOMEM;
 
                 if (asprintf(&id, "%lu", ++m->inhibit_counter) < 0)
                         return -ENOMEM;
@@ -2442,6 +2486,7 @@ const sd_bus_vtable manager_vtable[] = {
         SD_BUS_METHOD("Inhibit", "ssss", "h", method_inhibit, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("CanRebootToFirmwareSetup", NULL, "s", method_can_reboot_to_firmware_setup, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("SetRebootToFirmwareSetup", "b", NULL, method_set_reboot_to_firmware_setup, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("Inhibit", "ssss", "h", method_inhibit, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("CanRebootToFirmwareSetup", NULL, "s", method_can_reboot_to_firmware_setup, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("SetRebootToFirmwareSetup", "b", NULL, method_set_reboot_to_firmware_setup, SD_BUS_VTABLE_UNPRIVILEGED),
+        SD_BUS_METHOD("SetWallMessage", "sb", NULL, method_set_wall_message, SD_BUS_VTABLE_UNPRIVILEGED),
 
         SD_BUS_SIGNAL("SessionNew", "so", 0),
         SD_BUS_SIGNAL("SessionRemoved", "so", 0),
 
         SD_BUS_SIGNAL("SessionNew", "so", 0),
         SD_BUS_SIGNAL("SessionRemoved", "so", 0),
@@ -2490,7 +2535,7 @@ int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *err
         r = sd_bus_message_read(message, "uoss", &id, &path, &unit, &result);
         if (r < 0) {
                 bus_log_parse_error(r);
         r = sd_bus_message_read(message, "uoss", &id, &path, &unit, &result);
         if (r < 0) {
                 bus_log_parse_error(r);
-                return r;
+                return 0;
         }
 
         if (m->action_job && streq(m->action_job, path)) {
         }
 
         if (m->action_job && streq(m->action_job, path)) {
@@ -2499,8 +2544,7 @@ int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *err
                 /* Tell people that they now may take a lock again */
                 send_prepare_for(m, m->action_what, false);
 
                 /* Tell people that they now may take a lock again */
                 send_prepare_for(m, m->action_what, false);
 
-                free(m->action_job);
-                m->action_job = NULL;
+                m->action_job = mfree(m->action_job);
                 m->action_unit = NULL;
                 m->action_what = 0;
                 return 0;
                 m->action_unit = NULL;
                 m->action_what = 0;
                 return 0;
@@ -2509,10 +2553,8 @@ int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *err
         session = hashmap_get(m->session_units, unit);
         if (session) {
 
         session = hashmap_get(m->session_units, unit);
         if (session) {
 
-                if (streq_ptr(path, session->scope_job)) {
-                        free(session->scope_job);
-                        session->scope_job = NULL;
-                }
+                if (streq_ptr(path, session->scope_job))
+                        session->scope_job = mfree(session->scope_job);
 
                 session_jobs_reply(session, unit, result);
 
 
                 session_jobs_reply(session, unit, result);
 
@@ -2523,19 +2565,14 @@ int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *err
         user = hashmap_get(m->user_units, unit);
         if (user) {
 
         user = hashmap_get(m->user_units, unit);
         if (user) {
 
-                if (streq_ptr(path, user->service_job)) {
-                        free(user->service_job);
-                        user->service_job = NULL;
-                }
+                if (streq_ptr(path, user->service_job))
+                        user->service_job = mfree(user->service_job);
 
 
-                if (streq_ptr(path, user->slice_job)) {
-                        free(user->slice_job);
-                        user->slice_job = NULL;
-                }
+                if (streq_ptr(path, user->slice_job))
+                        user->slice_job = mfree(user->slice_job);
 
 
-                LIST_FOREACH(sessions_by_user, session, user->sessions) {
+                LIST_FOREACH(sessions_by_user, session, user->sessions)
                         session_jobs_reply(session, unit, result);
                         session_jobs_reply(session, unit, result);
-                }
 
                 user_save(user);
                 user_add_to_gc_queue(user);
 
                 user_save(user);
                 user_add_to_gc_queue(user);
@@ -2557,7 +2594,7 @@ int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *er
         r = sd_bus_message_read(message, "so", &unit, &path);
         if (r < 0) {
                 bus_log_parse_error(r);
         r = sd_bus_message_read(message, "so", &unit, &path);
         if (r < 0) {
                 bus_log_parse_error(r);
-                return r;
+                return 0;
         }
 
         session = hashmap_get(m->session_units, unit);
         }
 
         session = hashmap_get(m->session_units, unit);
@@ -2589,8 +2626,10 @@ int match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_err
         r = unit_name_from_dbus_path(path, &unit);
         if (r == -EINVAL) /* not a unit */
                 return 0;
         r = unit_name_from_dbus_path(path, &unit);
         if (r == -EINVAL) /* not a unit */
                 return 0;
-        if (r < 0)
-                return r;
+        if (r < 0) {
+                log_oom();
+                return 0;
+        }
 
         session = hashmap_get(m->session_units, unit);
         if (session)
 
         session = hashmap_get(m->session_units, unit);
         if (session)
@@ -2615,7 +2654,7 @@ int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error
         r = sd_bus_message_read(message, "b", &b);
         if (r < 0) {
                 bus_log_parse_error(r);
         r = sd_bus_message_read(message, "b", &b);
         if (r < 0) {
                 bus_log_parse_error(r);
-                return r;
+                return 0;
         }
 
         if (b)
         }
 
         if (b)
@@ -2630,41 +2669,6 @@ int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error
         return 0;
 }
 
         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;
 
 int manager_send_changed(Manager *manager, const char *property, ...) {
         char **l;
 
index a9f76d6c4ed29c963ac986c1936350f9e87e4e83..cfae186edd615c5c8e4e3c799acca50f3aaa8c26 100644 (file)
@@ -86,11 +86,11 @@ int inhibitor_save(Inhibitor *i) {
 
         r = mkdir_safe_label("/run/systemd/inhibit", 0755, 0, 0);
         if (r < 0)
 
         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)
 
         r = fopen_temporary(i->state_file, &f, &temp_path);
         if (r < 0)
-                goto finish;
+                goto fail;
 
         fchmod(fileno(f), 0644);
 
 
         fchmod(fileno(f), 0644);
 
@@ -132,19 +132,24 @@ int inhibitor_save(Inhibitor *i) {
         if (i->fifo_path)
                 fprintf(f, "FIFO=%s\n", i->fifo_path);
 
         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;
                 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) {
 }
 
 int inhibitor_start(Inhibitor *i) {
index 495ec50be06d21e1da86505f5c394b01c78b53af..8d13a63688180d7b029cab930e272259a4e9e64d 100644 (file)
@@ -93,11 +93,11 @@ int seat_save(Seat *s) {
 
         r = mkdir_safe_label("/run/systemd/seats", 0755, 0, 0);
         if (r < 0)
 
         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)
 
         r = fopen_temporary(s->state_file, &f, &temp_path);
         if (r < 0)
-                goto finish;
+                goto fail;
 
         fchmod(fileno(f), 0644);
 
 
         fchmod(fileno(f), 0644);
 
@@ -141,19 +141,24 @@ int seat_save(Seat *s) {
                                 i->sessions_by_seat_next ? ' ' : '\n');
         }
 
                                 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;
                 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) {
 }
 
 int seat_load(Seat *s) {
index 1a5c76b815f4811a12e995fe89778a6e1fed4c3f..92a6027a7ef4a085f21ca90c5a60f13823b2d68a 100644 (file)
@@ -165,11 +165,11 @@ int session_save(Session *s) {
 
         r = mkdir_safe_label("/run/systemd/sessions", 0755, 0, 0);
         if (r < 0)
 
         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)
 
         r = fopen_temporary(s->state_file, &f, &temp_path);
         if (r < 0)
-                goto finish;
+                goto fail;
 
         assert(s->user);
 
 
         assert(s->user);
 
@@ -217,7 +217,7 @@ int session_save(Session *s) {
                 escaped = cescape(s->remote_host);
                 if (!escaped) {
                         r = -ENOMEM;
                 escaped = cescape(s->remote_host);
                 if (!escaped) {
                         r = -ENOMEM;
-                        goto finish;
+                        goto fail;
                 }
 
                 fprintf(f, "REMOTE_HOST=%s\n", escaped);
                 }
 
                 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;
                 escaped = cescape(s->remote_user);
                 if (!escaped) {
                         r = -ENOMEM;
-                        goto finish;
+                        goto fail;
                 }
 
                 fprintf(f, "REMOTE_USER=%s\n", escaped);
                 }
 
                 fprintf(f, "REMOTE_USER=%s\n", escaped);
@@ -241,7 +241,7 @@ int session_save(Session *s) {
                 escaped = cescape(s->service);
                 if (!escaped) {
                         r = -ENOMEM;
                 escaped = cescape(s->service);
                 if (!escaped) {
                         r = -ENOMEM;
-                        goto finish;
+                        goto fail;
                 }
 
                 fprintf(f, "SERVICE=%s\n", escaped);
                 }
 
                 fprintf(f, "SERVICE=%s\n", escaped);
@@ -254,7 +254,7 @@ int session_save(Session *s) {
                 escaped = cescape(s->desktop);
                 if (!escaped) {
                         r = -ENOMEM;
                 escaped = cescape(s->desktop);
                 if (!escaped) {
                         r = -ENOMEM;
-                        goto finish;
+                        goto fail;
                 }
 
                 fprintf(f, "DESKTOP=%s\n", escaped);
                 }
 
                 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);
 
         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;
                 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,
 int session_load(Session *s) {
         _cleanup_free_ char *remote = NULL,
                 *seat = NULL,
@@ -650,7 +656,6 @@ int session_stop(Session *s, bool force) {
 }
 
 int session_finalize(Session *s) {
 }
 
 int session_finalize(Session *s) {
-        int r = 0;
         SessionDevice *sd;
 
         assert(s);
         SessionDevice *sd;
 
         assert(s);
@@ -676,7 +681,7 @@ int session_finalize(Session *s) {
         while ((sd = hashmap_first(s->devices)))
                 session_device_free(sd);
 
         while ((sd = hashmap_first(s->devices)))
                 session_device_free(sd);
 
-        unlink(s->state_file);
+        (void) unlink(s->state_file);
         session_add_to_gc_queue(s);
         user_add_to_gc_queue(s->user);
 
         session_add_to_gc_queue(s);
         user_add_to_gc_queue(s->user);
 
@@ -696,7 +701,7 @@ int session_finalize(Session *s) {
         user_save(s->user);
         user_send_changed(s->user, "Sessions", "Display", NULL);
 
         user_save(s->user);
         user_send_changed(s->user, "Sessions", "Display", NULL);
 
-        return r;
+        return 0;
 }
 
 static int release_timeout_callback(sd_event_source *es, uint64_t usec, void *userdata) {
 }
 
 static int release_timeout_callback(sd_event_source *es, uint64_t usec, void *userdata) {
@@ -1125,7 +1130,18 @@ static void session_release_controller(Session *s, bool notify) {
                 session_device_free(sd);
 
         s->controller = NULL;
                 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) {
 }
 
 int session_set_controller(Session *s, const char *sender, bool force) {
@@ -1144,8 +1160,13 @@ int session_set_controller(Session *s, const char *sender, bool force) {
         if (!name)
                 return -ENOMEM;
 
         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
                 return r;
 
         /* When setting a session controller, we forcibly mute the VT and set
@@ -1158,7 +1179,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) {
          * 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;
         }
 
                 return r;
         }
 
@@ -1176,6 +1197,7 @@ void session_drop_controller(Session *s) {
         if (!s->controller)
                 return;
 
         if (!s->controller)
                 return;
 
+        s->track = sd_bus_track_unref(s->track);
         session_release_controller(s, false);
         session_save(s);
         session_restore_vt(s);
         session_release_controller(s, false);
         session_save(s);
         session_restore_vt(s);
index 854f30fbd15841ec93a0b74c4eb3816bef15e96a..d054c33ceca6b5a671b4352943914d99056ca04a 100644 (file)
@@ -26,7 +26,7 @@ typedef enum KillWho KillWho;
 
 #include "list.h"
 #include "logind-user.h"
 
 #include "list.h"
 #include "logind-user.h"
-#include "login-shared.h"
+#include "login-util.h"
 
 typedef enum SessionState {
         SESSION_OPENING,  /* Session scope is being created */
 
 typedef enum SessionState {
         SESSION_OPENING,  /* Session scope is being created */
@@ -117,6 +117,7 @@ struct Session {
 
         char *controller;
         Hashmap *devices;
 
         char *controller;
         Hashmap *devices;
+        sd_bus_track *track;
 
         LIST_FIELDS(Session, sessions_by_user);
         LIST_FIELDS(Session, sessions_by_seat);
 
         LIST_FIELDS(Session, sessions_by_user);
         LIST_FIELDS(Session, sessions_by_seat);
index 71bff96728fd1b733b1ccd654e729103549b74d2..987244e27ec1f2cfd5e55e699ca0376dce8ae0a9 100644 (file)
@@ -118,11 +118,11 @@ int user_save(User *u) {
 
         r = mkdir_safe_label("/run/systemd/users", 0755, 0, 0);
         if (r < 0)
 
         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)
 
         r = fopen_temporary(u->state_file, &f, &temp_path);
         if (r < 0)
-                goto finish;
+                goto fail;
 
         fchmod(fileno(f), 0644);
 
 
         fchmod(fileno(f), 0644);
 
@@ -243,19 +243,24 @@ int user_save(User *u) {
                 fputc('\n', f);
         }
 
                 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;
                 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_load(User *u) {
 }
 
 int user_load(User *u) {
index 575bcee5b03579eb9a431c9458a3a8e7c8767f12..6cc6218b3de851df3aa715ed6166502a30bbe9f5 100644 (file)
@@ -34,7 +34,6 @@
 #include "udev-util.h"
 #include "formats-util.h"
 #include "label.h"
 #include "udev-util.h"
 #include "formats-util.h"
 #include "label.h"
-#include "label.h"
 
 static void manager_free(Manager *m);
 
 
 static void manager_free(Manager *m);
 
@@ -77,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->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);
                 goto fail;
 
         m->kill_exclude_users = strv_new("root", NULL);
@@ -142,8 +138,6 @@ static void manager_free(Manager *m) {
         hashmap_free(m->user_units);
         hashmap_free(m->session_units);
 
         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);
         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);
@@ -159,16 +153,11 @@ static void manager_free(Manager *m) {
 
         safe_close(m->console_active_fd);
 
 
         safe_close(m->console_active_fd);
 
-        if (m->udev_seat_monitor)
                 udev_monitor_unref(m->udev_seat_monitor);
                 udev_monitor_unref(m->udev_seat_monitor);
-        if (m->udev_device_monitor)
                 udev_monitor_unref(m->udev_device_monitor);
                 udev_monitor_unref(m->udev_device_monitor);
-        if (m->udev_vcsa_monitor)
                 udev_monitor_unref(m->udev_vcsa_monitor);
                 udev_monitor_unref(m->udev_vcsa_monitor);
-        if (m->udev_button_monitor)
                 udev_monitor_unref(m->udev_button_monitor);
 
                 udev_monitor_unref(m->udev_button_monitor);
 
-        if (m->udev)
                 udev_unref(m->udev);
 
         if (m->unlink_nologin)
                 udev_unref(m->udev);
 
         if (m->unlink_nologin)
@@ -628,17 +617,6 @@ static int manager_connect_bus(Manager *m) {
                 return log_error_errno(r, "Failed to add user enumerator: %m");
 
         r = sd_bus_add_match(m->bus,
                 return log_error_errno(r, "Failed to add user enumerator: %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',"
                              NULL,
                              "type='signal',"
                              "sender='org.freedesktop.systemd1',"
@@ -929,8 +907,8 @@ static void manager_gc(Manager *m, bool drop_not_started) {
                     session_get_state(session) != SESSION_CLOSING)
                         session_stop(session, false);
 
                     session_get_state(session) != SESSION_CLOSING)
                         session_stop(session, false);
 
-                /* Normally, this should make the session busy again,
-                 * if it doesn't then let's get rid of it
+                /* Normally, this should make the session referenced
+                 * again, if it doesn't then let's get rid of it
                  * immediately */
                 if (!session_check_gc(session, drop_not_started)) {
                         session_finalize(session);
                  * immediately */
                 if (!session_check_gc(session, drop_not_started)) {
                         session_finalize(session);
@@ -1124,8 +1102,8 @@ static int manager_run(Manager *m) {
 static int manager_parse_config_file(Manager *m) {
         assert(m);
 
 static int manager_parse_config_file(Manager *m) {
         assert(m);
 
-        return config_parse_many("/etc/elogind/elogind.conf",
-                                 CONF_DIRS_NULSTR("elogind/elogind.conf"),
+        return config_parse_many("/etc/systemd/logind.conf",
+                                 CONF_DIRS_NULSTR("systemd/logind.conf"),
                                  "Login\0",
                                  config_item_perf_lookup, logind_gperf_lookup,
                                  false, m);
                                  "Login\0",
                                  config_item_perf_lookup, logind_gperf_lookup,
                                  false, m);
@@ -1186,7 +1164,6 @@ finish:
                   "STOPPING=1\n"
                   "STATUS=Shutting down...");
 
                   "STOPPING=1\n"
                   "STATUS=Shutting down...");
 
-        if (m)
                 manager_free(m);
 
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
                 manager_free(m);
 
         return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
index cd226f55fc8cc5502b5256817aaa548114885716..3990ab040fdeb4cc4a7edbdf733060a0b9de528d 100644 (file)
@@ -48,8 +48,6 @@ struct Manager {
         Hashmap *inhibitors;
         Hashmap *buttons;
 
         Hashmap *inhibitors;
         Hashmap *buttons;
 
-        Set *busnames;
-
         LIST_HEAD(Seat, seat_gc_queue);
         LIST_HEAD(Session, session_gc_queue);
         LIST_HEAD(User, user_gc_queue);
         LIST_HEAD(Seat, seat_gc_queue);
         LIST_HEAD(Session, session_gc_queue);
         LIST_HEAD(User, user_gc_queue);
@@ -183,9 +181,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);
 
 /* 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);
 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);
index 83e7183323aa081f1d42408ca710abfee03250ca..23326bb79feedf56adae5099e835c86665f92576 100644 (file)
                         <allow_inactive>auth_admin_keep</allow_inactive>
                         <allow_active>yes</allow_active>
                 </defaults>
                         <allow_inactive>auth_admin_keep</allow_inactive>
                         <allow_active>yes</allow_active>
                 </defaults>
+                <annotate key="org.freedesktop.policykit.imply">org.freedesktop.login1.set-wall-message</annotate>
         </action>
 
         <action id="org.freedesktop.login1.power-off-multiple-sessions">
         </action>
 
         <action id="org.freedesktop.login1.power-off-multiple-sessions">
                         <allow_inactive>auth_admin_keep</allow_inactive>
                         <allow_active>yes</allow_active>
                 </defaults>
                         <allow_inactive>auth_admin_keep</allow_inactive>
                         <allow_active>yes</allow_active>
                 </defaults>
+                <annotate key="org.freedesktop.policykit.imply">org.freedesktop.login1.set-wall-message</annotate>
         </action>
 
         <action id="org.freedesktop.login1.reboot-multiple-sessions">
         </action>
 
         <action id="org.freedesktop.login1.reboot-multiple-sessions">
                 </defaults>
         </action>
 
                 </defaults>
         </action>
 
+        <action id="org.freedesktop.login1.set-wall-message">
+                <_description>Set a wall message</_description>
+                <_message>Authentication is required to set a wall message</_message>
+                <defaults>
+                        <allow_any>auth_admin_keep</allow_any>
+                        <allow_inactive>auth_admin_keep</allow_inactive>
+                        <allow_active>auth_admin_keep</allow_active>
+                </defaults>
+        </action>
+
 </policyconfig>
 </policyconfig>
index d29d7e7921332bb3d47be9223ea6282aad0b857c..4c4275d1245eaf8c00cb75f257e332c3bf002d5f 100644 (file)
@@ -20,7 +20,7 @@
 ***/
 
 #include "macro.h"
 ***/
 
 #include "macro.h"
-#include "login-shared.h"
+#include "login-util.h"
 
 static void test_session_id_valid(void) {
         assert_se(session_id_valid("c1"));
 
 static void test_session_id_valid(void) {
         assert_se(session_id_valid("c1"));