chiark / gitweb /
logind: make sure login sessions are terminated with SIGHUP
authorLennart Poettering <lennart@poettering.net>
Tue, 30 Jul 2013 00:51:12 +0000 (02:51 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 30 Jul 2013 00:54:56 +0000 (02:54 +0200)
bash ignores SIGTERM, and can only be terminated cleanly via SIGHUP.
Hence make sure that we the scope unit for the session is created with
SendSIGHUP enabled.

src/login/logind-dbus.c

index 7b9bd20..ed5d8d8 100644 (file)
@@ -2526,11 +2526,11 @@ int manager_start_scope(
                 DBusError *error,
                 char **job) {
 
+        const char *timeout_stop_property = "TimeoutStopUSec", *send_sighup_property = "SendSIGHUP", *pids_property = "PIDs";
         _cleanup_dbus_message_unref_ DBusMessage *m = NULL, *reply = NULL;
         DBusMessageIter iter, sub, sub2, sub3, sub4;
-        const char *timeout_stop_property = "TimeoutStopUSec";
-        const char *pids_property = "PIDs";
         uint64_t timeout = 500 * USEC_PER_MSEC;
+        dbus_bool_t send_sighup = true;
         const char *fail = "fail";
         uint32_t u;
 
@@ -2607,6 +2607,16 @@ int manager_start_scope(
             !dbus_message_iter_close_container(&sub, &sub2))
                 return log_oom();
 
+        /* Make sure that the session shells are terminated with
+         * SIGHUP since bash and friends tend to ignore SIGTERM */
+        if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
+            !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &send_sighup_property) ||
+            !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, "b", &sub3) ||
+            !dbus_message_iter_append_basic(&sub3, DBUS_TYPE_BOOLEAN, &send_sighup) ||
+            !dbus_message_iter_close_container(&sub2, &sub3) ||
+            !dbus_message_iter_close_container(&sub, &sub2))
+                return log_oom();
+
         u = pid;
         if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2) ||
             !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &pids_property) ||
@@ -2615,8 +2625,10 @@ int manager_start_scope(
             !dbus_message_iter_append_basic(&sub4, DBUS_TYPE_UINT32, &u) ||
             !dbus_message_iter_close_container(&sub3, &sub4) ||
             !dbus_message_iter_close_container(&sub2, &sub3) ||
-            !dbus_message_iter_close_container(&sub, &sub2) ||
-            !dbus_message_iter_close_container(&iter, &sub))
+            !dbus_message_iter_close_container(&sub, &sub2))
+                return log_oom();
+
+        if (!dbus_message_iter_close_container(&iter, &sub))
                 return log_oom();
 
         reply = dbus_connection_send_with_reply_and_block(manager->bus, m, -1, error);