[systemd-commits] 4 commits - TODO man/systemd-run.xml src/core src/login src/run

Lennart Poettering lennart at kemper.freedesktop.org
Mon Jul 29 17:55:02 PDT 2013


 TODO                                  |    4 +-
 man/systemd-run.xml                   |   12 +++++++
 src/core/dbus-kill.c                  |   54 ++++++++++++++++++++++++++++++++--
 src/core/dbus-kill.h                  |    2 -
 src/core/dbus-scope.c                 |    6 +++
 src/core/dbus-service.c               |    4 ++
 src/core/load-fragment-gperf.gperf.m4 |    2 +
 src/login/logind-dbus.c               |   20 ++++++++++--
 src/run/run.c                         |   18 +++++++++--
 9 files changed, 110 insertions(+), 12 deletions(-)

New commits:
commit 743e89454093361653b85ff394d0434c0714a92d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Jul 30 02:51:12 2013 +0200

    logind: make sure login sessions are terminated with SIGHUP
    
    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.

diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 7b9bd20..ed5d8d8 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -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);

commit 07beec1244817a0e6e9d79798f7c65bd89b23549
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Jul 30 02:51:07 2013 +0200

    update TODO

diff --git a/TODO b/TODO
index fe2af67..99122b5 100644
--- a/TODO
+++ b/TODO
@@ -39,10 +39,10 @@ CGroup Rework Completion:
 
 * wiki: document new bus APIs of PID 1 (transient units, Reloading signal)
 
-* Send SIGHUP and SIGTERM in session scopes
-
 Features:
 
+* for transient units, instead of writing out drop-ins for all properties consider serializing them in the normal serialization stream
+
 * logind: when logging out, remove user-owned sysv and posix IPC objects
 
 * session scopes/user unit: add RequiresMountsFor for the home directory of the user

commit c3df8d3dde5a032b382b3f59c016c1d0b7741ae8
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Jul 30 02:50:44 2013 +0200

    core: make sure scope attributes survive a reload

diff --git a/src/core/dbus-kill.c b/src/core/dbus-kill.c
index beae7da..80e15e3 100644
--- a/src/core/dbus-kill.c
+++ b/src/core/dbus-kill.c
@@ -55,8 +55,11 @@ int bus_kill_context_set_transient_property(
 
                 if (mode != UNIT_CHECK) {
                         dbus_bool_t b;
+
                         dbus_message_iter_get_basic(i, &b);
                         c->send_sighup = b;
+
+                        unit_write_drop_in_format(u, mode, name, "[Scope]\nSendSIGHUP=%s\n", yes_no(b));
                 }
 
                 return 1;
@@ -68,8 +71,11 @@ int bus_kill_context_set_transient_property(
 
                 if (mode != UNIT_CHECK) {
                         dbus_bool_t b;
+
                         dbus_message_iter_get_basic(i, &b);
                         c->send_sigkill = b;
+
+                        unit_write_drop_in_format(u, mode, name, "[Scope]\nSendSIGKILL4=%s\n", yes_no(b));
                 }
 
                 return 1;
diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c
index 497e452..783a969 100644
--- a/src/core/dbus-scope.c
+++ b/src/core/dbus-scope.c
@@ -138,6 +138,8 @@ static int bus_scope_set_transient_property(
                         dbus_message_iter_get_basic(i, &t);
 
                         s->timeout_stop_usec = t;
+
+                        unit_write_drop_in_format(UNIT(s), mode, name, "[Scope]\nTimeoutStopSec=%lluus\n", (unsigned long long) t);
                 }
 
                 return 1;
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
index 2b0106f..33c6880 100644
--- a/src/core/load-fragment-gperf.gperf.m4
+++ b/src/core/load-fragment-gperf.gperf.m4
@@ -263,6 +263,8 @@ m4_dnl
 CGROUP_CONTEXT_CONFIG_ITEMS(Slice)m4_dnl
 m4_dnl
 CGROUP_CONTEXT_CONFIG_ITEMS(Scope)m4_dnl
+KILL_CONTEXT_CONFIG_ITEMS(Scope)m4_dnl
+Scope.TimeoutStopSec,            config_parse_sec,                   0,                             offsetof(Scope, timeout_stop_usec)
 m4_dnl The [Install] section is ignored here.
 Install.Alias,                   NULL,                               0,                             0
 Install.WantedBy,                NULL,                               0,                             0

commit a6c0353b9268d5b780fb7ff05a10cb5031446e5d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Jul 30 02:28:22 2013 +0200

    core: open up SendSIGHUP property for transient units

diff --git a/man/systemd-run.xml b/man/systemd-run.xml
index 707d88d..e1e8851 100644
--- a/man/systemd-run.xml
+++ b/man/systemd-run.xml
@@ -160,6 +160,18 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
         </para>
         </listitem>
       </varlistentry>
+
+      <varlistentry>
+        <term><option>--send-sighup</option></term>
+
+        <listitem><para>When terminating the scope unit send a SIGHUP
+        immediately after SIGTERM. This is useful to indicate to
+        shells and shell-like processes that the connection has been
+        sewered. Also see <varname>SendSIGHUP=</varname> in
+        <citerefentry><refentrytitle>systemd.kill</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
+        </para>
+        </listitem>
+      </varlistentry>
     </variablelist>
 
     <para>All command-line arguments after the first non-option
diff --git a/src/core/dbus-kill.c b/src/core/dbus-kill.c
index e970ea3..beae7da 100644
--- a/src/core/dbus-kill.c
+++ b/src/core/dbus-kill.c
@@ -25,12 +25,56 @@
 #include "dbus-kill.h"
 #include "dbus-common.h"
 
-DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_kill_append_mode, kill_mode, KillMode);
+static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_kill_append_mode, kill_mode, KillMode);
 
 const BusProperty bus_kill_context_properties[] = {
         { "KillMode",    bus_kill_append_mode,     "s", offsetof(KillContext, kill_mode)    },
         { "KillSignal",  bus_property_append_int,  "i", offsetof(KillContext, kill_signal)  },
         { "SendSIGKILL", bus_property_append_bool, "b", offsetof(KillContext, send_sigkill) },
         { "SendSIGHUP",  bus_property_append_bool, "b", offsetof(KillContext, send_sighup)  },
-        { NULL, }
+        {}
 };
+
+int bus_kill_context_set_transient_property(
+                Unit *u,
+                KillContext *c,
+                const char *name,
+                DBusMessageIter *i,
+                UnitSetPropertiesMode mode,
+                DBusError *error) {
+
+        assert(u);
+        assert(c);
+        assert(name);
+        assert(i);
+
+        if (streq(name, "SendSIGHUP")) {
+
+                if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_BOOLEAN)
+                        return -EINVAL;
+
+                if (mode != UNIT_CHECK) {
+                        dbus_bool_t b;
+                        dbus_message_iter_get_basic(i, &b);
+                        c->send_sighup = b;
+                }
+
+                return 1;
+
+        } else if (streq(name, "SendSIGKILL")) {
+
+                if (dbus_message_iter_get_arg_type(i) != DBUS_TYPE_BOOLEAN)
+                        return -EINVAL;
+
+                if (mode != UNIT_CHECK) {
+                        dbus_bool_t b;
+                        dbus_message_iter_get_basic(i, &b);
+                        c->send_sigkill = b;
+                }
+
+                return 1;
+
+        }
+
+        return 0;
+}
diff --git a/src/core/dbus-kill.h b/src/core/dbus-kill.h
index 8c8bff5..7676d98 100644
--- a/src/core/dbus-kill.h
+++ b/src/core/dbus-kill.h
@@ -34,4 +34,4 @@
 
 extern const BusProperty bus_kill_context_properties[];
 
-int bus_kill_append_mode(DBusMessageIter *i, const char *property, void *data);
+int bus_kill_context_set_transient_property(Unit *u, KillContext *c, const char *name, DBusMessageIter *i, UnitSetPropertiesMode mode, DBusError *error);
diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c
index 771820c..497e452 100644
--- a/src/core/dbus-scope.c
+++ b/src/core/dbus-scope.c
@@ -170,6 +170,10 @@ int bus_scope_set_property(
                 r = bus_scope_set_transient_property(s, name, i, mode, error);
                 if (r != 0)
                         return r;
+
+                r = bus_kill_context_set_transient_property(u, &s->kill_context, name, i, mode, error);
+                if (r != 0)
+                        return r;
         }
 
         return 0;
diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c
index 1a44e1f..85b13f0 100644
--- a/src/core/dbus-service.c
+++ b/src/core/dbus-service.c
@@ -324,6 +324,10 @@ int bus_service_set_property(
                 r = bus_service_set_transient_property(s, name, i, mode, error);
                 if (r != 0)
                         return r;
+
+                r = bus_kill_context_set_transient_property(u, &s->kill_context, name, i, mode, error);
+                if (r != 0)
+                        return r;
         }
 
         return 0;
diff --git a/src/run/run.c b/src/run/run.c
index c1a0ffb..c5d314b 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -35,6 +35,7 @@ static bool arg_remain_after_exit = false;
 static const char *arg_unit = NULL;
 static const char *arg_description = NULL;
 static const char *arg_slice = NULL;
+static bool arg_send_sighup = false;
 
 static int help(void) {
 
@@ -47,7 +48,8 @@ static int help(void) {
                "     --unit=UNIT          Run under the specified unit name\n"
                "     --description=TEXT   Description for unit\n"
                "     --slice=SLICE        Run in the specified slice\n"
-               "  -r --remain-after-exit  Leave service around until explicitly stopped\n",
+               "  -r --remain-after-exit  Leave service around until explicitly stopped\n"
+               "     --send-sighup        Send SIGHUP when terminating\n",
                program_invocation_short_name);
 
         return 0;
@@ -61,7 +63,8 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_SCOPE,
                 ARG_UNIT,
                 ARG_DESCRIPTION,
-                ARG_SLICE
+                ARG_SLICE,
+                ARG_SEND_SIGHUP,
         };
 
         static const struct option options[] = {
@@ -72,7 +75,8 @@ static int parse_argv(int argc, char *argv[]) {
                 { "unit",              required_argument, NULL, ARG_UNIT        },
                 { "description",       required_argument, NULL, ARG_DESCRIPTION },
                 { "slice",             required_argument, NULL, ARG_SLICE       },
-                { "remain-after-exit", required_argument, NULL, 'r'             },
+                { "remain-after-exit", no_argument,       NULL, 'r'             },
+                { "send-sighup",       no_argument,       NULL, ARG_SEND_SIGHUP },
                 { NULL,                0,                 NULL, 0               },
         };
 
@@ -114,6 +118,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_slice = optarg;
                         break;
 
+                case ARG_SEND_SIGHUP:
+                        arg_send_sighup = true;
+                        break;
+
                 case 'r':
                         arg_remain_after_exit = true;
                         break;
@@ -174,6 +182,10 @@ static int message_start_transient_unit_new(sd_bus *bus, const char *name, sd_bu
                         return r;
         }
 
+        r = sd_bus_message_append(m, "(sv)", "SendSIGHUP", "b", arg_send_sighup);
+        if (r < 0)
+                return r;
+
         *ret = m;
         m = NULL;
 



More information about the systemd-commits mailing list