chiark / gitweb /
logind: always kill session when termination is requested
[elogind.git] / src / login / logind-dbus.c
index 47459617733da9f6295729173bc442c384e31f66..08e53c36956a6821e56a717c646a637865375155 100644 (file)
@@ -748,15 +748,7 @@ static int method_release_session(sd_bus *bus, sd_bus_message *message, void *us
         if (!session)
                 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
 
-        /* We use the FIFO to detect stray sessions where the process
-           invoking PAM dies abnormally. We need to make sure that
-           that process is not killed if at the clean end of the
-           session it closes the FIFO. Hence, with this call
-           explicitly turn off the FIFO logic, so that the PAM code
-           can finish clean up on its own */
-        session_remove_fifo(session);
-        session_save(session);
-        user_save(session->user);
+        session_release(session);
 
         return sd_bus_reply_method_return(message, NULL);
 }
@@ -947,7 +939,7 @@ static int method_terminate_session(sd_bus *bus, sd_bus_message *message, void *
         if (!session)
                 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SESSION, "No session '%s' known", name);
 
-        r = session_stop(session);
+        r = session_stop(session, true);
         if (r < 0)
                 return r;
 
@@ -972,7 +964,7 @@ static int method_terminate_user(sd_bus *bus, sd_bus_message *message, void *use
         if (!user)
                 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER, "No user '%lu' known or logged in", (unsigned long) uid);
 
-        r = user_stop(user);
+        r = user_stop(user, true);
         if (r < 0)
                 return r;
 
@@ -997,7 +989,7 @@ static int method_terminate_seat(sd_bus *bus, sd_bus_message *message, void *use
         if (!seat)
                 return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_SEAT, "No seat '%s' known", name);
 
-        r = seat_stop_sessions(seat);
+        r = seat_stop_sessions(seat, true);
         if (r < 0)
                 return r;
 
@@ -1919,6 +1911,27 @@ const sd_bus_vtable manager_vtable[] = {
         SD_BUS_VTABLE_END
 };
 
+static int session_jobs_reply(Session *s, const char *unit, const char *result) {
+        int r = 0;
+
+        assert(s);
+        assert(unit);
+
+        if (!s->started)
+                return r;
+
+        if (streq(result, "done"))
+                r = session_send_create_reply(s, NULL);
+        else {
+                _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
+
+                sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
+                r = session_send_create_reply(s, &e);
+        }
+
+        return r;
+}
+
 int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error) {
         const char *path, *result, *unit;
         Manager *m = userdata;
@@ -1958,18 +1971,9 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_b
                         session->scope_job = NULL;
                 }
 
-                if (session->started) {
-                        if (streq(result, "done"))
-                                session_send_create_reply(session, NULL);
-                        else {
-                                _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
-
-                                sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
-                                session_send_create_reply(session, &e);
-                        }
-                } else
-                        session_save(session);
+                session_jobs_reply(session, unit, result);
 
+                session_save(session);
                 session_add_to_gc_queue(session);
         }
 
@@ -1987,17 +1991,7 @@ int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_b
                 }
 
                 LIST_FOREACH(sessions_by_user, session, user->sessions) {
-                        if (!session->started)
-                                continue;
-
-                        if (streq(result, "done"))
-                                session_send_create_reply(session, NULL);
-                        else {
-                                _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
-
-                                sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
-                                session_send_create_reply(session, &e);
-                        }
+                        session_jobs_reply(session, unit, result);
                 }
 
                 user_save(user);
@@ -2184,8 +2178,7 @@ int manager_start_scope(
                 pid_t pid,
                 const char *slice,
                 const char *description,
-                const char *after,
-                const char *kill_mode,
+                const char *after, const char *after2,
                 sd_bus_error *error,
                 char **job) {
 
@@ -2226,14 +2219,14 @@ int manager_start_scope(
                         return r;
         }
 
-        if (!isempty(description)) {
+        if (!isempty(after)) {
                 r = sd_bus_message_append(m, "(sv)", "After", "as", 1, after);
                 if (r < 0)
                         return r;
         }
 
-        if (!isempty(kill_mode)) {
-                r = sd_bus_message_append(m, "(sv)", "KillMode", "s", kill_mode);
+        if (!isempty(after2)) {
+                r = sd_bus_message_append(m, "(sv)", "After", "as", 1, after2);
                 if (r < 0)
                         return r;
         }
@@ -2243,10 +2236,6 @@ int manager_start_scope(
          * stop timeout for sessions, so that we don't wait
          * forever. */
 
-        r = sd_bus_message_append(m, "(sv)", "TimeoutStopUSec", "t", 500 * USEC_PER_MSEC);
-        if (r < 0)
-                return r;
-
         /* Make sure that the session shells are terminated with
          * SIGHUP since bash and friends tend to ignore SIGTERM */
         r = sd_bus_message_append(m, "(sv)", "SendSIGHUP", "b", true);
@@ -2372,6 +2361,40 @@ int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, c
         return 1;
 }
 
+int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error) {
+        _cleanup_free_ char *path = NULL;
+        int r;
+
+        assert(manager);
+        assert(scope);
+
+        path = unit_dbus_path_from_name(scope);
+        if (!path)
+                return -ENOMEM;
+
+        r = sd_bus_call_method(
+                        manager->bus,
+                        "org.freedesktop.systemd1",
+                        path,
+                        "org.freedesktop.systemd1.Scope",
+                        "Abandon",
+                        error,
+                        NULL,
+                        NULL);
+        if (r < 0) {
+                if (sd_bus_error_has_name(error, BUS_ERROR_NO_SUCH_UNIT) ||
+                    sd_bus_error_has_name(error, BUS_ERROR_LOAD_FAILED) ||
+                    sd_bus_error_has_name(error, BUS_ERROR_SCOPE_NOT_RUNNING)) {
+                        sd_bus_error_free(error);
+                        return 0;
+                }
+
+                return r;
+        }
+
+        return 1;
+}
+
 int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error) {
         assert(manager);
         assert(unit);