chiark / gitweb /
logind: various clean-ups
authorLennart Poettering <lennart@poettering.net>
Fri, 24 Jun 2011 17:42:45 +0000 (19:42 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 24 Jun 2011 17:42:45 +0000 (19:42 +0200)
src/logind-seat-dbus.c
src/logind-seat.c
src/logind-session-dbus.c
src/logind-session.c
src/logind-user-dbus.c
src/logind-user.c
src/logind.h
src/pam-module.c

index 4a4527d01ddfdf2afb53a7b09ad81b77ee7dfbfe..ad0298e7a7f661efeac64ffdca5d160fdf4dc7c7 100644 (file)
@@ -378,6 +378,9 @@ int seat_send_changed(Seat *s, const char *properties) {
 
         assert(s);
 
 
         assert(s);
 
+        if (!s->started)
+                return 0;
+
         p = seat_bus_path(s);
         if (!p)
                 return -ENOMEM;
         p = seat_bus_path(s);
         if (!p)
                 return -ENOMEM;
index 26c2bd4f5e91d11766647e36a87a1a485a0f4708..c232a87d5de8effd1b51b09971f569c5b4791f43 100644 (file)
@@ -350,18 +350,17 @@ int seat_stop(Seat *s) {
 
         assert(s);
 
 
         assert(s);
 
-        if (!s->started)
-                return 0;
-
-        log_info("Removed seat %s.", s->id);
-
-        seat_send_signal(s, false);
+        if (s->started)
+                log_info("Removed seat %s.", s->id);
 
         seat_stop_sessions(s);
 
         unlink(s->state_file);
         seat_add_to_gc_queue(s);
 
 
         seat_stop_sessions(s);
 
         unlink(s->state_file);
         seat_add_to_gc_queue(s);
 
+        if (s->started)
+                seat_send_signal(s, false);
+
         s->started = false;
 
         return r;
         s->started = false;
 
         return r;
index 8d1e607e623d6e8b039915e5e69670246661bab8..2435a6512b79f3a422931cd9d92711189c09f517 100644 (file)
@@ -429,6 +429,9 @@ int session_send_changed(Session *s, const char *properties) {
 
         assert(s);
 
 
         assert(s);
 
+        if (!s->started)
+                return 0;
+
         p = session_bus_path(s);
         if (!p)
                 return -ENOMEM;
         p = session_bus_path(s);
         if (!p)
                 return -ENOMEM;
index 42d28016da6e0207bf790dd7ed4647d4ad9fc06a..74f8ad1b0c60b8048c7d6634eb495f0fcdcc06cb 100644 (file)
@@ -480,6 +480,10 @@ int session_start(Session *s) {
         if (s->started)
                 return 0;
 
         if (s->started)
                 return 0;
 
+        r = user_start(s->user);
+        if (r < 0)
+                return r;
+
         log_info("New session %s of user %s.", s->id, s->user->name);
 
         /* Create cgroup */
         log_info("New session %s of user %s.", s->id, s->user->name);
 
         /* Create cgroup */
@@ -514,7 +518,16 @@ int session_start(Session *s) {
 static bool session_shall_kill(Session *s) {
         assert(s);
 
 static bool session_shall_kill(Session *s) {
         assert(s);
 
-        return s->kill_processes;
+        if (!s->kill_processes)
+                return false;
+
+        if (strv_contains(s->manager->kill_exclude_users, s->user->name))
+                return false;
+
+        if (strv_isempty(s->manager->kill_only_users))
+                return true;
+
+        return strv_contains(s->manager->kill_only_users, s->user->name);
 }
 
 static int session_kill_cgroup(Session *s) {
 }
 
 static int session_kill_cgroup(Session *s) {
@@ -584,10 +597,8 @@ int session_stop(Session *s) {
 
         assert(s);
 
 
         assert(s);
 
-        if (!s->started)
-                return 0;
-
-        log_info("Removed session %s.", s->id);
+        if (s->started)
+                log_info("Removed session %s.", s->id);
 
         /* Kill cgroup */
         k = session_kill_cgroup(s);
 
         /* Kill cgroup */
         k = session_kill_cgroup(s);
@@ -599,8 +610,10 @@ int session_stop(Session *s) {
 
         unlink(s->state_file);
         session_add_to_gc_queue(s);
 
         unlink(s->state_file);
         session_add_to_gc_queue(s);
+        user_add_to_gc_queue(s->user);
 
 
-        session_send_signal(s, false);
+        if (s->started)
+                session_send_signal(s, false);
 
         if (s->seat) {
                 if (s->seat->active == s)
 
         if (s->seat) {
                 if (s->seat->active == s)
index 5926dcfbc7ab04e85e5968a67788be97182be009..6d7e8e70309c95254947351e1a93b46e5532cb00 100644 (file)
@@ -362,6 +362,9 @@ int user_send_changed(User *u, const char *properties) {
 
         assert(u);
 
 
         assert(u);
 
+        if (!u->started)
+                return 0;
+
         p = user_bus_path(u);
         if (!p)
                 return -ENOMEM;
         p = user_bus_path(u);
         if (!p)
                 return -ENOMEM;
index 8ebd6eca235b1a3e7803006872ed13b50d46294d..63033e0fd3a37e299b808b87814df44ff4e1a29c 100644 (file)
@@ -265,6 +265,8 @@ int user_start(User *u) {
         if (u->started)
                 return 0;
 
         if (u->started)
                 return 0;
 
+        log_info("New user %s logged in.", u->name);
+
         /* Make XDG_RUNTIME_DIR */
         r = user_mkdir_runtime_path(u);
         if (r < 0)
         /* Make XDG_RUNTIME_DIR */
         r = user_mkdir_runtime_path(u);
         if (r < 0)
@@ -304,7 +306,16 @@ static int user_stop_service(User *u) {
 static int user_shall_kill(User *u) {
         assert(u);
 
 static int user_shall_kill(User *u) {
         assert(u);
 
-        return u->manager->kill_user_processes;
+        if (!u->manager->kill_user_processes)
+                return false;
+
+        if (strv_contains(u->manager->kill_exclude_users, u->name))
+                return false;
+
+        if (strv_isempty(u->manager->kill_only_users))
+                return true;
+
+        return strv_contains(u->manager->kill_only_users, u->name);
 }
 
 static int user_kill_cgroup(User *u) {
 }
 
 static int user_kill_cgroup(User *u) {
@@ -368,8 +379,8 @@ int user_stop(User *u) {
         int r = 0, k;
         assert(u);
 
         int r = 0, k;
         assert(u);
 
-        if (!u->started)
-                return 0;
+        if (u->started)
+                log_info("User %s logged out.", u->name);
 
         LIST_FOREACH(sessions_by_user, s, u->sessions) {
                 k = session_stop(s);
 
         LIST_FOREACH(sessions_by_user, s, u->sessions) {
                 k = session_stop(s);
@@ -377,8 +388,6 @@ int user_stop(User *u) {
                         r = k;
         }
 
                         r = k;
         }
 
-        user_send_signal(u, false);
-
         /* Kill systemd */
         k = user_stop_service(u);
         if (k < 0)
         /* Kill systemd */
         k = user_stop_service(u);
         if (k < 0)
@@ -397,6 +406,9 @@ int user_stop(User *u) {
         unlink(u->state_file);
         user_add_to_gc_queue(u);
 
         unlink(u->state_file);
         user_add_to_gc_queue(u);
 
+        if (u->started)
+                user_send_signal(u, false);
+
         u->started = false;
 
         return r;
         u->started = false;
 
         return r;
index 7de8e3bcf8e5e2bed527ac81b3542f949df89bb6..22eab55625b6ee9ac3d439a113ae8fa4a0e28a9d 100644 (file)
 /* TODO:
  *
  * recreate VTs when disallocated
 /* TODO:
  *
  * recreate VTs when disallocated
- * PAM rewrite
  * spawn user systemd
  * direct client API
  * subscribe to cgroup changes, fd HUP
  * spawn user systemd
  * direct client API
  * subscribe to cgroup changes, fd HUP
+ * D-Bus method: AttachDevice(seat, device);
+ * D-Bus method: PermitLinger(user, bool b);
  *
  * non-local X11 server
  * reboot/shutdown halt management
  *
  * non-local X11 server
  * reboot/shutdown halt management
index b742d649d24f6b274d738b1719b60725d764aecc..dc7c00166e6ca35f1f313de3df236a9c57d93a9b 100644 (file)
@@ -60,7 +60,7 @@ static int parse_argv(pam_handle_t *handle,
 
                 if (startswith(argv[i], "kill-processes=")) {
                         if ((k = parse_boolean(argv[i] + 15)) < 0) {
 
                 if (startswith(argv[i], "kill-processes=")) {
                         if ((k = parse_boolean(argv[i] + 15)) < 0) {
-                                pam_syslog(handle, LOG_ERR, "Failed to parse kill-session= argument.");
+                                pam_syslog(handle, LOG_ERR, "Failed to parse kill-processes= argument.");
                                 return k;
                         }
 
                                 return k;
                         }
 
@@ -304,26 +304,25 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                 int flags,
                 int argc, const char **argv) {
 
                 int flags,
                 int argc, const char **argv) {
 
-        const char *username = NULL;
         struct passwd *pw;
         bool kill_processes = false, debug = false;
         struct passwd *pw;
         bool kill_processes = false, debug = false;
+        const char *username, *id, *object_path, *runtime_path, *service = NULL, *tty = NULL, *display = NULL, *remote_user = NULL, *remote_host = NULL, *seat = NULL, *type;
         char **controllers = NULL, **reset_controllers = NULL, **kill_only_users = NULL, **kill_exclude_users = NULL;
         char **controllers = NULL, **reset_controllers = NULL, **kill_only_users = NULL, **kill_exclude_users = NULL;
-        int r;
         DBusError error;
         uint32_t uid, pid;
         DBusMessageIter iter;
         dbus_bool_t kp;
         DBusError error;
         uint32_t uid, pid;
         DBusMessageIter iter;
         dbus_bool_t kp;
-        const char *id, *object_path, *runtime_path, *service = NULL, *tty = NULL, *display = NULL, *remote_user = NULL, *remote_host = NULL, *seat = NULL, *type;
         int session_fd = -1;
         DBusConnection *bus = NULL;
         DBusMessage *m = NULL, *reply = NULL;
         dbus_bool_t remote;
         int session_fd = -1;
         DBusConnection *bus = NULL;
         DBusMessage *m = NULL, *reply = NULL;
         dbus_bool_t remote;
+        int r;
 
         assert(handle);
 
         dbus_error_init(&error);
 
 
         assert(handle);
 
         dbus_error_init(&error);
 
-        pam_syslog(handle, LOG_ERR, "pam-systemd initializing");
+        /* pam_syslog(handle, LOG_INFO, "pam-systemd initializing"); */
 
         /* Make this a NOP on non-systemd systems */
         if (sd_booted() <= 0)
 
         /* Make this a NOP on non-systemd systems */
         if (sd_booted() <= 0)
@@ -333,8 +332,10 @@ _public_ PAM_EXTERN int pam_sm_open_session(
                        argc, argv,
                        &controllers, &reset_controllers,
                        &kill_processes, &kill_only_users, &kill_exclude_users,
                        argc, argv,
                        &controllers, &reset_controllers,
                        &kill_processes, &kill_only_users, &kill_exclude_users,
-                       &debug) < 0)
-                return PAM_SESSION_ERR;
+                       &debug) < 0) {
+                r = PAM_SESSION_ERR;
+                goto finish;
+        }
 
         r = get_user_data(handle, &username, &pw);
         if (r != PAM_SUCCESS)
 
         r = get_user_data(handle, &username, &pw);
         if (r != PAM_SUCCESS)
@@ -343,6 +344,8 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         if (kill_processes)
                 kill_processes = check_user_lists(handle, pw->pw_uid, kill_only_users, kill_exclude_users);
 
         if (kill_processes)
                 kill_processes = check_user_lists(handle, pw->pw_uid, kill_only_users, kill_exclude_users);
 
+        dbus_connection_set_change_sigpipe(FALSE);
+
         bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
         if (!bus) {
                 pam_syslog(handle, LOG_ERR, "Failed to connect to system bus: %s", bus_error_message(&error));
         bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
         if (!bus) {
                 pam_syslog(handle, LOG_ERR, "Failed to connect to system bus: %s", bus_error_message(&error));
@@ -370,18 +373,14 @@ _public_ PAM_EXTERN int pam_sm_open_session(
         pam_get_item(handle, PAM_TTY, (const void**) &tty);
         pam_get_item(handle, PAM_RUSER, (const void**) &remote_user);
         pam_get_item(handle, PAM_RHOST, (const void**) &remote_host);
         pam_get_item(handle, PAM_TTY, (const void**) &tty);
         pam_get_item(handle, PAM_RUSER, (const void**) &remote_user);
         pam_get_item(handle, PAM_RHOST, (const void**) &remote_host);
+        seat = pam_getenv(handle, "XDG_SEAT");
 
 
-        if (isempty(tty))
-                service = "";
-        if (isempty(tty))
-                tty = "";
-        if (isempty(display))
-                display = "";
-        if (isempty(remote_user))
-                remote_user = "";
-        if (isempty(remote_host))
-                remote_host = "";
-        seat = "";
+        service = strempty(service);
+        tty = strempty(tty);
+        display = strempty(display);
+        remote_user = strempty(remote_user);
+        remote_host = strempty(remote_host);
+        seat = strempty(seat);
 
         type = !isempty(display) ? "x11" :
                    !isempty(tty) ? "tty" : "other";
 
         type = !isempty(display) ? "x11" :
                    !isempty(tty) ? "tty" : "other";
@@ -481,12 +480,12 @@ finish:
                 dbus_connection_unref(bus);
         }
 
                 dbus_connection_unref(bus);
         }
 
-        if (reply)
-                dbus_message_unref(reply);
-
         if (m)
                 dbus_message_unref(m);
 
         if (m)
                 dbus_message_unref(m);
 
+        if (reply)
+                dbus_message_unref(reply);
+
         if (session_fd >= 0)
                 close_nointr_nofail(session_fd);
 
         if (session_fd >= 0)
                 close_nointr_nofail(session_fd);