[systemd-commits] 3 commits - src/core src/python-systemd src/readahead src/run

Lennart Poettering lennart at kemper.freedesktop.org
Fri Jan 31 08:48:47 PST 2014


 src/core/dbus-scope.c             |   55 ++++++++++++++++++++++++++++++++++++++
 src/core/dbus-scope.h             |    2 +
 src/core/dbus-unit.c              |    2 -
 src/core/scope.c                  |   26 +++++++++++++----
 src/core/scope.h                  |    2 +
 src/python-systemd/_journal.c     |    3 --
 src/readahead/readahead-collect.c |    3 --
 src/run/run.c                     |    8 +++++
 8 files changed, 89 insertions(+), 12 deletions(-)

New commits:
commit 9ceefc810f86026fd9c97ac89d9d1898f8482d89
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 31 17:47:22 2014 +0100

    core: fix oom check

diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c
index 37c1e8c..d4393e3 100644
--- a/src/core/dbus-unit.c
+++ b/src/core/dbus-unit.c
@@ -627,7 +627,7 @@ static int send_changed_signal(sd_bus *bus, const char *destination, void *userd
         assert(u);
 
         p = unit_dbus_path(u);
-        if (!u)
+        if (!p)
                 return -ENOMEM;
 
         /* Send a properties changed signal. First for the specific

commit 2d4a39e759c4ab846ad8a546abeddd40bc8d736e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 31 17:45:13 2014 +0100

    core: introduce new stop protocol for unit scopes
    
    By specifiy a Controller property when creating the scope a client can
    specify a bus name that will be notified with a RequestStop bus signal
    when the scope has been asked to shut down, instead of sending SIGTERM
    to the scope processes themselves.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1032695

diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c
index bb251ed..d5a2048 100644
--- a/src/core/dbus-scope.c
+++ b/src/core/dbus-scope.c
@@ -26,13 +26,16 @@
 #include "dbus-kill.h"
 #include "dbus-scope.h"
 #include "bus-util.h"
+#include "bus-internal.h"
 
 static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, scope_result, ScopeResult);
 
 const sd_bus_vtable bus_scope_vtable[] = {
         SD_BUS_VTABLE_START(0),
+        SD_BUS_PROPERTY("Controller", "s", NULL, offsetof(Scope, controller), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("TimeoutStopUSec", "t", bus_property_get_usec, offsetof(Scope, timeout_stop_usec), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+        SD_BUS_SIGNAL("RequestStop", NULL, 0),
         SD_BUS_VTABLE_END
 };
 
@@ -86,6 +89,32 @@ static int bus_scope_set_transient_property(
 
                 return 1;
 
+        } else if (streq(name, "Controller")) {
+                const char *controller;
+                char *c;
+
+                r = sd_bus_message_read(message, "s", &controller);
+                if (r < 0)
+                        return r;
+
+                if (!isempty(controller) && !service_name_is_valid(controller))
+                        return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Controller '%s' is not a valid bus name.", controller);
+
+                if (mode != UNIT_CHECK) {
+                        if (isempty(controller))
+                                c = NULL;
+                        else {
+                                c = strdup(controller);
+                                if (!c)
+                                        return -ENOMEM;
+                        }
+
+                        free(s->controller);
+                        s->controller = c;
+                }
+
+                return 1;
+
         } else if (streq(name, "TimeoutStopUSec")) {
 
                 if (mode != UNIT_CHECK) {
@@ -145,3 +174,29 @@ int bus_scope_commit_properties(Unit *u) {
         unit_realize_cgroup(u);
         return 0;
 }
+
+int bus_scope_send_request_stop(Scope *s) {
+        _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
+        _cleanup_free_ char *p = NULL;
+        int r;
+
+        assert(s);
+
+        if (!s->controller)
+                return 0;
+
+        p = unit_dbus_path(UNIT(s));
+        if (!p)
+                return -ENOMEM;
+
+        r = sd_bus_message_new_signal(
+                        UNIT(s)->manager->api_bus,
+                        p,
+                        "org.freedesktop.systemd1.Scope",
+                        "RequestStop",
+                        &m);
+        if (r < 0)
+                return r;
+
+        return sd_bus_send_to(UNIT(s)->manager->api_bus, m, /* s->controller */ NULL, NULL);
+}
diff --git a/src/core/dbus-scope.h b/src/core/dbus-scope.h
index 7e8f005..33beda4 100644
--- a/src/core/dbus-scope.h
+++ b/src/core/dbus-scope.h
@@ -28,3 +28,5 @@ extern const sd_bus_vtable bus_scope_vtable[];
 
 int bus_scope_set_property(Unit *u, const char *name, sd_bus_message *i, UnitSetPropertiesMode mode, sd_bus_error *error);
 int bus_scope_commit_properties(Unit *u);
+
+int bus_scope_send_request_stop(Scope *s);
diff --git a/src/core/scope.c b/src/core/scope.c
index 5beb4f8..0c1d17e 100644
--- a/src/core/scope.c
+++ b/src/core/scope.c
@@ -64,6 +64,8 @@ static void scope_done(Unit *u) {
 
         cgroup_context_done(&s->cgroup_context);
 
+        free(s->controller);
+
         set_free(s->pids);
         s->pids = NULL;
 
@@ -217,6 +219,7 @@ static void scope_enter_dead(Scope *s, ScopeResult f) {
 }
 
 static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) {
+        bool skip_signal = false;
         int r;
 
         assert(s);
@@ -224,13 +227,22 @@ static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) {
         if (f != SCOPE_SUCCESS)
                 s->result = f;
 
-        r = unit_kill_context(
-                        UNIT(s),
-                        &s->kill_context,
-                        state != SCOPE_STOP_SIGTERM,
-                        -1, -1, false);
-        if (r < 0)
-                goto fail;
+        /* If we have a controller set let's ask the controller nicely
+         * to terminate the scope, instead of us going directly into
+         * SIGTERM beserk mode */
+        if (state == SCOPE_STOP_SIGTERM)
+                skip_signal = bus_scope_send_request_stop(s) > 0;
+
+        if (!skip_signal) {
+                r = unit_kill_context(
+                                UNIT(s),
+                                &s->kill_context,
+                                state != SCOPE_STOP_SIGTERM,
+                                -1, -1, false);
+                if (r < 0)
+                        goto fail;
+        } else
+                r = 1;
 
         if (r > 0) {
                 r = scope_arm_timer(s);
diff --git a/src/core/scope.h b/src/core/scope.h
index 4d8a171..014b50c 100644
--- a/src/core/scope.h
+++ b/src/core/scope.h
@@ -55,6 +55,8 @@ struct Scope {
 
         usec_t timeout_stop_usec;
 
+        char *controller;
+
         Set *pids;
 
         sd_event_source *timer_event_source;
diff --git a/src/run/run.c b/src/run/run.c
index 1b14e40..b9e1700 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -356,6 +356,14 @@ static int start_transient_scope(
         if (r < 0)
                 return r;
 
+        {
+                const char *unique_id;
+                sd_bus_get_unique_name(bus, &unique_id);
+                r = sd_bus_message_append(m, "(sv)", "Controller", "s", unique_id);
+                if (r < 0)
+                        return r;
+        }
+
         r = message_start_transient_unit_send(bus, m, error, NULL);
         if (r < 0)
                 return r;

commit fb818b2ea194ec182aa3e776d38883dc615910a1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jan 31 12:27:35 2014 +0100

    util: use alloca0() intead of alloca() + memzero()

diff --git a/src/python-systemd/_journal.c b/src/python-systemd/_journal.c
index 669c22c..8cc6d3e 100644
--- a/src/python-systemd/_journal.c
+++ b/src/python-systemd/_journal.c
@@ -41,8 +41,7 @@ static PyObject *journal_sendv(PyObject *self, PyObject *args) {
 
         /* Allocate an array for the argument strings */
         argc = PyTuple_Size(args);
-        encoded = alloca(argc * sizeof(PyObject*));
-        memzero(encoded, argc * sizeof(PyObject*));
+        encoded = alloca0(argc * sizeof(PyObject*));
 
         /* Allocate sufficient iovector space for the arguments. */
         iov = alloca(argc * sizeof(struct iovec));
diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index 211ef95..be92006 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -129,8 +129,7 @@ static int pack_file(FILE *pack, const char *fn, bool on_btrfs) {
         }
 
         pages = l / page_size();
-        vec = alloca(pages);
-        memzero(vec, pages);
+        vec = alloca0(pages);
         if (mincore(start, l, vec) < 0) {
                 log_warning("mincore(%s) failed: %m", fn);
                 r = -errno;



More information about the systemd-commits mailing list