diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-06-24 19:42:45 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-06-24 19:42:45 +0200 |
commit | ed18b08bed983b845c72a83666a7d7db546d89ad (patch) | |
tree | abfd2a0deea88527011c95bf599d43b8f5644dc3 /src | |
parent | 98a28fef2618e54a644614c759f371f297381b70 (diff) |
logind: various clean-ups
Diffstat (limited to 'src')
-rw-r--r-- | src/logind-seat-dbus.c | 3 | ||||
-rw-r--r-- | src/logind-seat.c | 11 | ||||
-rw-r--r-- | src/logind-session-dbus.c | 3 | ||||
-rw-r--r-- | src/logind-session.c | 25 | ||||
-rw-r--r-- | src/logind-user-dbus.c | 3 | ||||
-rw-r--r-- | src/logind-user.c | 22 | ||||
-rw-r--r-- | src/logind.h | 3 | ||||
-rw-r--r-- | src/pam-module.c | 41 |
8 files changed, 72 insertions, 39 deletions
diff --git a/src/logind-seat-dbus.c b/src/logind-seat-dbus.c index 4a4527d01d..ad0298e7a7 100644 --- a/src/logind-seat-dbus.c +++ b/src/logind-seat-dbus.c @@ -378,6 +378,9 @@ int seat_send_changed(Seat *s, const char *properties) { assert(s); + if (!s->started) + return 0; + p = seat_bus_path(s); if (!p) return -ENOMEM; diff --git a/src/logind-seat.c b/src/logind-seat.c index 26c2bd4f5e..c232a87d5d 100644 --- a/src/logind-seat.c +++ b/src/logind-seat.c @@ -350,18 +350,17 @@ int seat_stop(Seat *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); + if (s->started) + seat_send_signal(s, false); + s->started = false; return r; diff --git a/src/logind-session-dbus.c b/src/logind-session-dbus.c index 8d1e607e62..2435a6512b 100644 --- a/src/logind-session-dbus.c +++ b/src/logind-session-dbus.c @@ -429,6 +429,9 @@ int session_send_changed(Session *s, const char *properties) { assert(s); + if (!s->started) + return 0; + p = session_bus_path(s); if (!p) return -ENOMEM; diff --git a/src/logind-session.c b/src/logind-session.c index 42d28016da..74f8ad1b0c 100644 --- a/src/logind-session.c +++ b/src/logind-session.c @@ -480,6 +480,10 @@ int session_start(Session *s) { 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 */ @@ -514,7 +518,16 @@ int session_start(Session *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) { @@ -584,10 +597,8 @@ int session_stop(Session *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); @@ -599,8 +610,10 @@ int session_stop(Session *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) diff --git a/src/logind-user-dbus.c b/src/logind-user-dbus.c index 5926dcfbc7..6d7e8e7030 100644 --- a/src/logind-user-dbus.c +++ b/src/logind-user-dbus.c @@ -362,6 +362,9 @@ int user_send_changed(User *u, const char *properties) { assert(u); + if (!u->started) + return 0; + p = user_bus_path(u); if (!p) return -ENOMEM; diff --git a/src/logind-user.c b/src/logind-user.c index 8ebd6eca23..63033e0fd3 100644 --- a/src/logind-user.c +++ b/src/logind-user.c @@ -265,6 +265,8 @@ int user_start(User *u) { 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) @@ -304,7 +306,16 @@ static int user_stop_service(User *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) { @@ -368,8 +379,8 @@ int user_stop(User *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); @@ -377,8 +388,6 @@ int user_stop(User *u) { r = k; } - user_send_signal(u, false); - /* 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); + if (u->started) + user_send_signal(u, false); + u->started = false; return r; diff --git a/src/logind.h b/src/logind.h index 7de8e3bcf8..22eab55625 100644 --- a/src/logind.h +++ b/src/logind.h @@ -35,10 +35,11 @@ /* TODO: * * recreate VTs when disallocated - * PAM rewrite * 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 diff --git a/src/pam-module.c b/src/pam-module.c index b742d649d2..dc7c00166e 100644 --- a/src/pam-module.c +++ b/src/pam-module.c @@ -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) { - pam_syslog(handle, LOG_ERR, "Failed to parse kill-session= argument."); + pam_syslog(handle, LOG_ERR, "Failed to parse kill-processes= argument."); return k; } @@ -304,26 +304,25 @@ _public_ PAM_EXTERN int pam_sm_open_session( int flags, int argc, const char **argv) { - const char *username = NULL; 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; - int r; 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 r; 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) @@ -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, - &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) @@ -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); + 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)); @@ -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); + 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"; @@ -481,12 +480,12 @@ finish: dbus_connection_unref(bus); } - if (reply) - dbus_message_unref(reply); - if (m) dbus_message_unref(m); + if (reply) + dbus_message_unref(reply); + if (session_fd >= 0) close_nointr_nofail(session_fd); |