[systemd-commits] 4 commits - man/systemd-activate.xml man/systemd.socket.xml src/activate src/python-systemd

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Sun Dec 29 21:17:49 PST 2013


 man/systemd-activate.xml     |    2 -
 man/systemd.socket.xml       |   67 +++++++++++++++++++++++++++++++------------
 src/activate/activate.c      |   30 +++++++++----------
 src/python-systemd/_daemon.c |   16 +++++-----
 src/python-systemd/_reader.c |   63 +++++++++++++++++-----------------------
 5 files changed, 101 insertions(+), 77 deletions(-)

New commits:
commit 3cf148f307e6450aa3411968f59a2563fe9cb154
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Dec 30 00:11:30 2013 -0500

    man: expand on some more subtle points in systemd.socket(5)
    
    http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=727708#1694

diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml
index d1879fa..946c30a 100644
--- a/man/systemd.socket.xml
+++ b/man/systemd.socket.xml
@@ -85,21 +85,26 @@
                 processes of the socket.</para>
 
                 <para>For each socket file a matching service file
-                (see
+                must exist, describing the service to start on
+                incoming traffic on the socket (see
                 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
-                for details) must exist, describing the service to
-                start on incoming traffic on the socket. Depending on
-                the setting of <option>Accept=</option> (see below),
-                this must either be named like the socket unit, but
-                with the suffix replaced; or it must be a template
-                file named the same way. Example: a socket file
+                for more information about .service files). The name
+                of the .service unit is by default the same as the
+                name of the .socket unit, but can be altered with
+                <option>Service=</option> option described below.
+                Depending on the setting of <option>Accept=</option>
+                option described below, this .service unit must either
+                be named like the .socket unit, but with the suffix
+                replaced, unless overridden with
+                <option>Service=</option>; or it must be a template
+                unit named the same way. Example: a socket file
                 <filename>foo.socket</filename> needs a matching
                 service <filename>foo.service</filename> if
                 <option>Accept=false</option> is set. If
-                <option>Accept=true</option> is set, a service template
-                file <filename>foo at .service</filename> must exist from
-                which services are instantiated for each incoming
-                connection.</para>
+                <option>Accept=true</option> is set, a service
+                template file <filename>foo at .service</filename> must
+                exist from which services are instantiated for each
+                incoming connection.</para>
 
                 <para>Unless <varname>DefaultDependencies=</varname>
                 is set to <option>false</option>, socket units will
@@ -116,9 +121,21 @@
                 boot or late system shutdown should disable this
                 option.</para>
 
+		<para>Socket units will have a
+		<varname>Before=</varname> dependency on the service
+		which they trigger added implicitly. No implicit
+		<varname>WantedBy=</varname> or
+		<varname>RequiredBy=</varname> dependency from the
+		socket to the service is added. This means that the
+		service may be started without the socket, in which
+		case it must be able to open sockets by itself. To
+		prevent this, an explicit <varname>Requires=</varname>
+		dependency may be added.</para>
+
                 <para>Socket units may be used to implement on-demand
                 starting of services, as well as parallelized starting
-                of services.</para>
+                of services. See the blog stories linked at the end
+                for introduction.</para>
 
                 <para>Note that the daemon software configured for
                 socket activation with socket units needs to be able
@@ -221,12 +238,23 @@
                                 of any of these options will have no
                                 effect.</para>
 
+                                <para>It is also possible to have more
+                                than one socket unit for the same
+                                service when using
+                                <varname>Service=</varname>, and the
+                                service will receive all the sockets
+                                configured in all the socket units.
+                                Sockets configured in one unit are
+                                passed in the order of configuration,
+                                but no ordering between socket units
+                                is specified.</para>
+
                                 <para>If an IP address is used here,
                                 it is often desirable to listen on it
                                 before the interface it is configured
                                 on is up and running, and even
                                 regardless of whether it will be up and
-                                running ever at all. To deal with this
+                                running at any point. To deal with this
                                 it is recommended to set the
                                 <varname>FreeBind=</varname> option
                                 described below.</para></listitem>
@@ -687,11 +715,14 @@
                                 <term><varname>Service=</varname></term>
                                 <listitem><para>Specifies the service
                                 unit name to activate on incoming
-                                traffic. This defaults to the service
-                                that bears the same name as the socket
-                                (ignoring the different suffixes). In
-                                most cases it should not be necessary
-                                to use this option.</para></listitem>
+                                traffic. This setting is only allowed
+                                for sockets with
+                                <varname>Accept=no</varname>. It
+                                defaults to the service that bears the
+                                same name as the socket (with the
+                                suffix replaced). In most cases it
+                                should not be necessary to use this
+                                option.</para></listitem>
                         </varlistentry>
 
                 </variablelist>

commit 819c7e4fa4422af1298a0bf074b1f5644e46fa13
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Mon Dec 30 00:01:00 2013 -0500

    systemd-python: fix listen_fds under Python 2

diff --git a/src/python-systemd/_daemon.c b/src/python-systemd/_daemon.c
index c6db69f..3982e85 100644
--- a/src/python-systemd/_daemon.c
+++ b/src/python-systemd/_daemon.c
@@ -114,7 +114,7 @@ static PyObject* listen_fds(PyObject *self, PyObject *args, PyObject *keywds) {
 #else
         PyObject *obj = NULL;
         if (!PyArg_ParseTupleAndKeywords(args, keywds, "|O:_listen_fds",
-                                         (char**) kwlist, &unset, &obj))
+                                         (char**) kwlist, &obj))
                 return NULL;
         if (obj != NULL)
                 unset = PyObject_IsTrue(obj);

commit b560cc1c45006a98c7652435df13c96b39827f22
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sun Dec 29 23:39:28 2013 -0500

    systemd-python: fix setting of exception codes
    
    The return value of 0 would be treated as failure by mistake,
    resulting in " SystemError: error return without exception set".
    The way that set_error() is used is changed to be the same
    everywhere.

diff --git a/src/python-systemd/_daemon.c b/src/python-systemd/_daemon.c
index f0ab16f..c6db69f 100644
--- a/src/python-systemd/_daemon.c
+++ b/src/python-systemd/_daemon.c
@@ -88,7 +88,7 @@ static PyObject* notify(PyObject *self, PyObject *args, PyObject *keywds) {
 #endif
 
         r = sd_notify(unset, msg);
-        if (set_error(r, NULL, NULL))
+        if (set_error(r, NULL, NULL) < 0)
                 return NULL;
 
         return PyBool_FromLong(r);
@@ -123,7 +123,7 @@ static PyObject* listen_fds(PyObject *self, PyObject *args, PyObject *keywds) {
 #endif
 
         r = sd_listen_fds(unset);
-        if (set_error(r, NULL, NULL))
+        if (set_error(r, NULL, NULL) < 0)
                 return NULL;
 
         return long_FromLong(r);
@@ -151,7 +151,7 @@ static PyObject* is_fifo(PyObject *self, PyObject *args) {
 #endif
 
         r = sd_is_fifo(fd, path);
-        if (set_error(r, path, NULL))
+        if (set_error(r, path, NULL) < 0)
                 return NULL;
 
         return PyBool_FromLong(r);
@@ -179,7 +179,7 @@ static PyObject* is_mq(PyObject *self, PyObject *args) {
 #endif
 
         r = sd_is_mq(fd, path);
-        if (set_error(r, path, NULL))
+        if (set_error(r, path, NULL) < 0)
                 return NULL;
 
         return PyBool_FromLong(r);
@@ -203,7 +203,7 @@ static PyObject* is_socket(PyObject *self, PyObject *args) {
                 return NULL;
 
         r = sd_is_socket(fd, family, type, listening);
-        if (set_error(r, NULL, NULL))
+        if (set_error(r, NULL, NULL) < 0)
                 return NULL;
 
         return PyBool_FromLong(r);
@@ -230,7 +230,7 @@ static PyObject* is_socket_inet(PyObject *self, PyObject *args) {
         }
 
         r = sd_is_socket_inet(fd, family, type, listening, (uint16_t) port);
-        if (set_error(r, NULL, NULL))
+        if (set_error(r, NULL, NULL) < 0)
                 return NULL;
 
         return PyBool_FromLong(r);
@@ -265,7 +265,7 @@ static PyObject* is_socket_unix(PyObject *self, PyObject *args) {
 #endif
 
         r = sd_is_socket_unix(fd, type, listening, path, length);
-        if (set_error(r, path, NULL))
+        if (set_error(r, path, NULL) < 0)
                 return NULL;
 
         return PyBool_FromLong(r);
diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c
index 1012606..ee25c49 100644
--- a/src/python-systemd/_reader.c
+++ b/src/python-systemd/_reader.c
@@ -202,8 +202,7 @@ PyDoc_STRVAR(Reader_reliable_fd__doc__,
              "See man:sd_journal_reliable_fd(3).");
 static PyObject* Reader_reliable_fd(Reader *self, PyObject *args) {
     int r = sd_journal_reliable_fd(self->j);
-    set_error(r, NULL, NULL);
-    if (r < 0)
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
     return PyBool_FromLong(r);
 }
@@ -216,8 +215,7 @@ PyDoc_STRVAR(Reader_get_events__doc__,
              "See man:sd_journal_get_events(3) for further discussion.");
 static PyObject* Reader_get_events(Reader *self, PyObject *args) {
     int r = sd_journal_get_events(self->j);
-    set_error(r, NULL, NULL);
-    if (r < 0)
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
     return long_FromLong(r);
 }
@@ -236,8 +234,7 @@ static PyObject* Reader_get_timeout(Reader *self, PyObject *args) {
     uint64_t t;
 
     r = sd_journal_get_timeout(self->j, &t);
-    set_error(r, NULL, NULL);
-    if (r < 0)
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     if (t == (uint64_t) -1)
@@ -258,8 +255,7 @@ static PyObject* Reader_get_timeout_ms(Reader *self, PyObject *args) {
     uint64_t t;
 
     r = sd_journal_get_timeout(self->j, &t);
-    set_error(r, NULL, NULL);
-    if (r < 0)
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     return absolute_timeout(t);
@@ -295,7 +291,7 @@ static PyObject* Reader_get_usage(Reader *self, PyObject *args) {
     uint64_t bytes;
 
     r = sd_journal_get_usage(self->j, &bytes);
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     assert_cc(sizeof(unsigned long long) == sizeof(bytes));
@@ -354,8 +350,7 @@ static PyObject* Reader_next(Reader *self, PyObject *args) {
         assert_not_reached("should not be here");
     Py_END_ALLOW_THREADS
 
-    set_error(r, NULL, NULL);
-    if (r < 0)
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
     return PyBool_FromLong(r);
 }
@@ -431,7 +426,8 @@ static PyObject* Reader_get(Reader *self, PyObject *args) {
     if (r == -ENOENT) {
         PyErr_SetString(PyExc_KeyError, field);
         return NULL;
-    } else if (set_error(r, NULL, "field name is not valid"))
+    }
+    if (set_error(r, NULL, "field name is not valid") < 0)
         return NULL;
 
     r = extract(msg, msg_len, NULL, &value);
@@ -514,7 +510,7 @@ static PyObject* Reader_get_realtime(Reader *self, PyObject *args) {
     assert(!args);
 
     r = sd_journal_get_realtime_usec(self->j, &timestamp);
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     assert_cc(sizeof(unsigned long long) == sizeof(timestamp));
@@ -538,7 +534,7 @@ static PyObject* Reader_get_monotonic(Reader *self, PyObject *args) {
     assert(!args);
 
     r = sd_journal_get_monotonic_usec(self->j, &timestamp, &id);
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     assert_cc(sizeof(unsigned long long) == sizeof(timestamp));
@@ -580,8 +576,7 @@ static PyObject* Reader_add_match(Reader *self, PyObject *args, PyObject *keywds
         return NULL;
 
     r = sd_journal_add_match(self->j, match, match_len);
-    set_error(r, NULL, "Invalid match");
-    if (r < 0)
+    if (set_error(r, NULL, "Invalid match") < 0)
             return NULL;
 
     Py_RETURN_NONE;
@@ -597,8 +592,7 @@ PyDoc_STRVAR(Reader_add_disjunction__doc__,
 static PyObject* Reader_add_disjunction(Reader *self, PyObject *args) {
     int r;
     r = sd_journal_add_disjunction(self->j);
-    set_error(r, NULL, NULL);
-    if (r < 0)
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
     Py_RETURN_NONE;
 }
@@ -613,8 +607,7 @@ PyDoc_STRVAR(Reader_add_conjunction__doc__,
 static PyObject* Reader_add_conjunction(Reader *self, PyObject *args) {
     int r;
     r = sd_journal_add_conjunction(self->j);
-    set_error(r, NULL, NULL);
-    if (r < 0)
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
     Py_RETURN_NONE;
 }
@@ -639,7 +632,7 @@ static PyObject* Reader_seek_head(Reader *self, PyObject *args) {
     Py_BEGIN_ALLOW_THREADS
     r = sd_journal_seek_head(self->j);
     Py_END_ALLOW_THREADS
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
     Py_RETURN_NONE;
 }
@@ -655,7 +648,7 @@ static PyObject* Reader_seek_tail(Reader *self, PyObject *args) {
     Py_BEGIN_ALLOW_THREADS
     r = sd_journal_seek_tail(self->j);
     Py_END_ALLOW_THREADS
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
     Py_RETURN_NONE;
 }
@@ -675,7 +668,7 @@ static PyObject* Reader_seek_realtime(Reader *self, PyObject *args) {
     Py_BEGIN_ALLOW_THREADS
     r = sd_journal_seek_realtime_usec(self->j, timestamp);
     Py_END_ALLOW_THREADS
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
     Py_RETURN_NONE;
 }
@@ -698,20 +691,20 @@ static PyObject* Reader_seek_monotonic(Reader *self, PyObject *args) {
 
     if (bootid) {
         r = sd_id128_from_string(bootid, &id);
-        if (set_error(r, NULL, "Invalid bootid"))
+        if (set_error(r, NULL, "Invalid bootid") < 0)
             return NULL;
     } else {
         Py_BEGIN_ALLOW_THREADS
         r = sd_id128_get_boot(&id);
         Py_END_ALLOW_THREADS
-        if (set_error(r, NULL, NULL))
+        if (set_error(r, NULL, NULL) < 0)
             return NULL;
     }
 
     Py_BEGIN_ALLOW_THREADS
     r = sd_journal_seek_monotonic_usec(self->j, id, timestamp);
     Py_END_ALLOW_THREADS
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     Py_RETURN_NONE;
@@ -781,7 +774,7 @@ static PyObject* Reader_seek_cursor(Reader *self, PyObject *args) {
     Py_BEGIN_ALLOW_THREADS
     r = sd_journal_seek_cursor(self->j, cursor);
     Py_END_ALLOW_THREADS
-    if (set_error(r, NULL, "Invalid cursor"))
+    if (set_error(r, NULL, "Invalid cursor") < 0)
         return NULL;
     Py_RETURN_NONE;
 }
@@ -799,7 +792,7 @@ static PyObject* Reader_get_cursor(Reader *self, PyObject *args) {
     assert(!args);
 
     r = sd_journal_get_cursor(self->j, &cursor);
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     return unicode_FromString(cursor);
@@ -821,8 +814,7 @@ static PyObject* Reader_test_cursor(Reader *self, PyObject *args) {
         return NULL;
 
     r = sd_journal_test_cursor(self->j, cursor);
-    set_error(r, NULL, NULL);
-    if (r < 0)
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     return PyBool_FromLong(r);
@@ -845,7 +837,7 @@ static PyObject* Reader_query_unique(Reader *self, PyObject *args) {
     Py_BEGIN_ALLOW_THREADS
     r = sd_journal_query_unique(self->j, query);
     Py_END_ALLOW_THREADS
-    if (set_error(r, NULL, "Invalid field name"))
+    if (set_error(r, NULL, "Invalid field name") < 0)
         return NULL;
 
     value_set = PySet_New(0);
@@ -898,7 +890,8 @@ static PyObject* Reader_get_catalog(Reader *self, PyObject *args) {
         else
             set_error(r, NULL, NULL);
         return NULL;
-    } else if (set_error(r, NULL, NULL))
+    }
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     return unicode_FromString(msg);
@@ -922,13 +915,13 @@ static PyObject* get_catalog(PyObject *self, PyObject *args) {
         return NULL;
 
     r = sd_id128_from_string(id_, &id);
-    if (set_error(r, NULL, "Invalid id128"))
+    if (set_error(r, NULL, "Invalid id128") < 0)
         return NULL;
 
     Py_BEGIN_ALLOW_THREADS
     r = sd_journal_get_catalog_for_message_id(id, &msg);
     Py_END_ALLOW_THREADS
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     return unicode_FromString(msg);
@@ -945,7 +938,7 @@ static PyObject* Reader_get_data_threshold(Reader *self, void *closure) {
     int r;
 
     r = sd_journal_get_data_threshold(self->j, &cvalue);
-    if (set_error(r, NULL, NULL))
+    if (set_error(r, NULL, NULL) < 0)
         return NULL;
 
     return long_FromSize_t(cvalue);

commit 892213bf1fd23e48d64a407ece6e10b07bef1926
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Sun Dec 29 14:56:09 2013 -0500

    acticate: rename --environment to --setenv
    
    Nspawn has --setenv, and systemd itself accepts systemd.setenv.
    It is nice to have the same parameter name everywhere.
    
    Old name is accepted, but not advertised.

diff --git a/man/systemd-activate.xml b/man/systemd-activate.xml
index d48774d..35eec19 100644
--- a/man/systemd-activate.xml
+++ b/man/systemd-activate.xml
@@ -119,7 +119,7 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
 
       <varlistentry>
         <term><option>-E <replaceable>VAR</replaceable><optional>=<replaceable>VALUE</replaceable></optional></option></term>
-        <term><option>--environment=<replaceable>VAR</replaceable><optional>=<replaceable>VALUE</replaceable></optional></option></term>
+        <term><option>--setenv=<replaceable>VAR</replaceable><optional>=<replaceable>VALUE</replaceable></optional></option></term>
 
         <listitem><para>Add this variable to the environment of the
         launched process. If <replaceable>VAR</replaceable> is
diff --git a/src/activate/activate.c b/src/activate/activate.c
index cf545d6..23c484c 100644
--- a/src/activate/activate.c
+++ b/src/activate/activate.c
@@ -38,7 +38,7 @@
 static char** arg_listen = NULL;
 static bool arg_accept = false;
 static char** arg_args = NULL;
-static char** arg_environ = NULL;
+static char** arg_setenv = NULL;
 
 static int add_epoll(int epoll_fd, int fd) {
         struct epoll_event ev = {
@@ -162,14 +162,14 @@ static int launch(char* name, char **argv, char **env, int fds) {
         char **s;
         unsigned i;
 
-        length = strv_length(arg_environ);
+        length = strv_length(arg_setenv);
 
         /* PATH, TERM, HOME, USER, LISTEN_FDS, LISTEN_PID, NULL */
         envp = new0(char *, length + 7);
         if (!envp)
                 return log_oom();
 
-        STRV_FOREACH(s, arg_environ) {
+        STRV_FOREACH(s, arg_setenv) {
                 if (strchr(*s, '='))
                         envp[n_env++] = *s;
                 else {
@@ -302,12 +302,11 @@ static int help(void) {
         printf("%s [OPTIONS...]\n\n"
                "Listen on sockets and launch child on connection.\n\n"
                "Options:\n"
-               "  -l --listen=ADDR     Listen for raw connections at ADDR\n"
-               "  -a --accept          Spawn separate child for each connection\n"
-               "  -h --help            Show this help and exit\n"
-               "  -E --environment=NAME[=VALUE]\n"
-               "                       Pass an environment variable to children\n"
-               "  --version            Print version string and exit\n"
+               "  -l --listen=ADDR         Listen for raw connections at ADDR\n"
+               "  -a --accept              Spawn separate child for each connection\n"
+               "  -h --help                Show this help and exit\n"
+               "  -E --setenv=NAME[=VALUE] Pass an environment variable to children\n"
+               "  --version                Print version string and exit\n"
                "\n"
                "Note: file descriptors from sd_listen_fds() will be passed through.\n"
                , program_invocation_short_name
@@ -322,11 +321,12 @@ static int parse_argv(int argc, char *argv[]) {
         };
 
         static const struct option options[] = {
-                { "help",         no_argument,       NULL, 'h'           },
-                { "version",      no_argument,       NULL, ARG_VERSION   },
-                { "listen",       required_argument, NULL, 'l'           },
-                { "accept",       no_argument,       NULL, 'a'           },
-                { "environment",  required_argument, NULL, 'E'           },
+                { "help",        no_argument,       NULL, 'h'           },
+                { "version",     no_argument,       NULL, ARG_VERSION   },
+                { "listen",      required_argument, NULL, 'l'           },
+                { "accept",      no_argument,       NULL, 'a'           },
+                { "setenv",      required_argument, NULL, 'E'           },
+                { "environment", required_argument, NULL, 'E'           }, /* alias */
                 {}
         };
 
@@ -358,7 +358,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case 'E': {
-                        int r = strv_extend(&arg_environ, optarg);
+                        int r = strv_extend(&arg_setenv, optarg);
                         if (r < 0)
                                 return r;
 



More information about the systemd-commits mailing list