[systemd-commits] 5 commits - src/execute.c src/execute.h src/load-fragment.c src/service.c src/unit.c units/fedora

Lennart Poettering lennart at kemper.freedesktop.org
Wed May 19 12:52:39 PDT 2010


 src/execute.c               |   52 +++++++++++++++++---------------------------
 src/execute.h               |    2 -
 src/load-fragment.c         |   50 +++++++++++++++++++++++++++++++-----------
 src/service.c               |   10 ++++++--
 src/unit.c                  |    2 -
 units/fedora/reboot.service |    2 -
 6 files changed, 69 insertions(+), 49 deletions(-)

New commits:
commit d017c6ca11ff48f8b39e7a16e139c4809ed1536e
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed May 19 21:52:30 2010 +0200

    service: refuse to parse sysv scripts that are requested with a boot. prefix or .sh suffix

diff --git a/src/service.c b/src/service.c
index 0615b51..2fcb304 100644
--- a/src/service.c
+++ b/src/service.c
@@ -654,6 +654,12 @@ static int service_load_sysv_name(Service *s, const char *name) {
         assert(s);
         assert(name);
 
+        /* For SysV services we strip the boot. or .sh
+         * prefixes/suffixes. */
+        if (startswith(name, "boot.") ||
+            endswith(name, ".sh.service"))
+                return -ENOENT;
+
         STRV_FOREACH(p, UNIT(s)->meta.manager->sysvinit_path) {
                 char *path;
                 int r;
@@ -667,7 +673,7 @@ static int service_load_sysv_name(Service *s, const char *name) {
                 r = service_load_sysv_path(s, path);
 
                 if (r >= 0 && UNIT(s)->meta.load_state == UNIT_STUB) {
-                        /* Try Debian style .sh source'able init scripts */
+                        /* Try Debian style xxx.sh source'able init scripts */
                         strcat(path, ".sh");
                         r = service_load_sysv_path(s, path);
                 }
@@ -675,7 +681,7 @@ static int service_load_sysv_name(Service *s, const char *name) {
                 free(path);
 
                 if (r >= 0 && UNIT(s)->meta.load_state == UNIT_STUB) {
-                        /* Try Suse style boot.xxxx init scripts */
+                        /* Try Suse style boot.xxx init scripts */
 
                         if (asprintf(&path, "%s/boot.%s", *p, name) < 0)
                                 return -ENOMEM;
commit 6c666e26c580c062c95035761deb7bef0885e7a5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed May 19 21:51:53 2010 +0200

    load-fragment: add support for overriding argv[0] in parsed command lines

diff --git a/src/load-fragment.c b/src/load-fragment.c
index 148a579..5e0637d 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -386,49 +386,73 @@ static int config_parse_exec(
         char *w;
         unsigned k;
         size_t l;
-        char *state;
+        char *state, *path = NULL;
+        bool honour_argv0, write_to_path;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
+        /* We accept an absolute path as first argument, or
+         * alternatively an absolute prefixed with @ to allow
+         * overriding of argv[0]. */
+
+        honour_argv0 = rvalue[0] == '@';
+
+        if (rvalue[honour_argv0 ? 1 : 0] != '/') {
+                log_error("[%s:%u] Invalid executable path in command line: %s", filename, line, rvalue);
+                return -EINVAL;
+        }
+
         k = 0;
         FOREACH_WORD_QUOTED(w, l, rvalue, state)
                 k++;
 
-        if (!(n = new(char*, k+1)))
+        if (!(n = new(char*, k + (honour_argv0 ? 0 : 1))))
                 return -ENOMEM;
 
         k = 0;
-        FOREACH_WORD_QUOTED(w, l, rvalue, state)
-                if (!(n[k++] = strndup(w, l)))
-                        goto fail;
+        write_to_path = honour_argv0;
+        FOREACH_WORD_QUOTED(w, l, rvalue, state) {
+                if (write_to_path) {
+                        if (!(path = strndup(w+1, l-1)))
+                                goto fail;
+                        write_to_path = false;
+                } else {
+                        if (!(n[k++] = strndup(w, l)))
+                                goto fail;
+                }
+        }
 
         n[k] = NULL;
 
-        if (!n[0] || !path_is_absolute(n[0])) {
-                log_error("[%s:%u] Invalid executable path in command line: %s", filename, line, rvalue);
+        if (!n[0]) {
+                log_error("[%s:%u] Invalid command line: %s", filename, line, rvalue);
                 strv_free(n);
                 return -EINVAL;
         }
 
+        if (!path)
+                if (!(path = strdup(n[0])))
+                        goto fail;
+
+        assert(path_is_absolute(path));
+
         if (!(nce = new0(ExecCommand, 1)))
                 goto fail;
 
         nce->argv = n;
-        if (!(nce->path = strdup(n[0])))
-                goto fail;
+        nce->path = path;
 
         exec_command_append_list(e, nce);
 
         return 0;
 
 fail:
-        for (; k > 0; k--)
-                free(n[k-1]);
-        free(n);
-
+        n[k] = NULL;
+        strv_free(n);
+        free(path);
         free(nce);
 
         return -ENOMEM;
diff --git a/units/fedora/reboot.service b/units/fedora/reboot.service
index da83fa0..1b0df32 100644
--- a/units/fedora/reboot.service
+++ b/units/fedora/reboot.service
@@ -24,4 +24,4 @@ After=shutdown.target killall.service
 Type=finish
 ValidNoProcess=yes
 Environment=RUNLEVEL=6
-ExecStart=/etc/init.d/reboot start
+ExecStart=@/etc/init.d/halt reboot start
commit 8783d2feaeb74fa37494b84024521a6e8a9b9276
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed May 19 21:51:25 2010 +0200

    execute: send output of services by default to same place as systemd internal output

diff --git a/src/execute.c b/src/execute.c
index 51e7688..f3cf026 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -1078,8 +1078,9 @@ void exec_context_init(ExecContext *c) {
         c->mount_flags = MS_SHARED;
 
         c->std_input = EXEC_INPUT_NULL;
-        c->std_output = EXEC_OUTPUT_SYSLOG;
-        c->std_error = EXEC_OUTPUT_SYSLOG;
+        c->std_output = c->std_error =
+                (log_get_target() == LOG_TARGET_CONSOLE ? EXEC_OUTPUT_INHERIT :
+                 log_get_target() == LOG_TARGET_KMSG ? EXEC_OUTPUT_KMSG : EXEC_OUTPUT_SYSLOG);
 }
 
 void exec_context_done(ExecContext *c) {
commit 03fd9c49328be40b53f63b43614eb9bea3a2cf45
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed May 19 21:50:34 2010 +0200

    execute: simplify stdin/stderr/stdout fixup a little

diff --git a/src/execute.c b/src/execute.c
index d899a54..51e7688 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -227,31 +227,20 @@ static bool is_terminal_input(ExecInput i) {
                 i == EXEC_INPUT_TTY_FAIL;
 }
 
-static int fixup_input(const ExecContext *context, int socket_fd) {
-        assert(context);
+static int fixup_input(ExecInput std_input, int socket_fd) {
 
-        if (socket_fd < 0 && context->std_input == EXEC_INPUT_SOCKET)
+        if (std_input == EXEC_INPUT_SOCKET && socket_fd < 0)
                 return EXEC_INPUT_NULL;
 
-        return context->std_input;
-}
-
-static int fixup_output(const ExecContext *context, int socket_fd) {
-        assert(context);
-
-        if (socket_fd < 0 && context->std_output == EXEC_OUTPUT_SOCKET)
-                return EXEC_OUTPUT_INHERIT;
-
-        return context->std_output;
+        return std_input;
 }
 
-static int fixup_error(const ExecContext *context, int socket_fd) {
-        assert(context);
+static int fixup_output(ExecOutput std_output, int socket_fd) {
 
-        if (socket_fd < 0 && context->std_error == EXEC_OUTPUT_SOCKET)
+        if (std_output == EXEC_OUTPUT_SOCKET && socket_fd < 0)
                 return EXEC_OUTPUT_INHERIT;
 
-        return context->std_error;
+        return std_output;
 }
 
 static int setup_input(const ExecContext *context, int socket_fd) {
@@ -259,7 +248,7 @@ static int setup_input(const ExecContext *context, int socket_fd) {
 
         assert(context);
 
-        i = fixup_input(context, socket_fd);
+        i = fixup_input(context->std_input, socket_fd);
 
         switch (i) {
 
@@ -302,8 +291,8 @@ static int setup_output(const ExecContext *context, int socket_fd, const char *i
         assert(context);
         assert(ident);
 
-        i = fixup_input(context, socket_fd);
-        o = fixup_output(context, socket_fd);
+        i = fixup_input(context->std_input, socket_fd);
+        o = fixup_output(context->std_output, socket_fd);
 
         /* This expects the input is already set up */
 
@@ -347,9 +336,9 @@ static int setup_error(const ExecContext *context, int socket_fd, const char *id
         assert(context);
         assert(ident);
 
-        i = fixup_input(context, socket_fd);
-        o = fixup_output(context, socket_fd);
-        e = fixup_error(context, socket_fd);
+        i = fixup_input(context->std_input, socket_fd);
+        o = fixup_output(context->std_output, socket_fd);
+        e = fixup_output(context->std_error, socket_fd);
 
         /* This expects the input and output are already set up */
 
commit 9a6bca7aada334cdcf10ae8e526de1f7f581da4f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed May 19 21:49:03 2010 +0200

    execute: s/EXEC_OUTPUT_KERNEL/EXEC_OUTPUT_KMSG/ to follow LOG_TARGET_xxx nomenclature

diff --git a/src/execute.c b/src/execute.c
index 37b2f84..d899a54 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -189,7 +189,7 @@ static int connect_logger_as(const ExecContext *context, ExecOutput output, cons
                 "%i\n"
                 "%s\n"
                 "%i\n",
-                output == EXEC_OUTPUT_KERNEL ? "kmsg" : "syslog",
+                output == EXEC_OUTPUT_KMSG ? "kmsg" : "syslog",
                 context->syslog_priority,
                 context->syslog_identifier ? context->syslog_identifier : ident,
                 !context->syslog_no_prefix);
@@ -328,7 +328,7 @@ static int setup_output(const ExecContext *context, int socket_fd, const char *i
                 return open_terminal_as(tty_path(context), O_WRONLY, STDOUT_FILENO);
 
         case EXEC_OUTPUT_SYSLOG:
-        case EXEC_OUTPUT_KERNEL:
+        case EXEC_OUTPUT_KMSG:
                 return connect_logger_as(context, o, ident, STDOUT_FILENO);
 
         case EXEC_OUTPUT_SOCKET:
@@ -377,7 +377,7 @@ static int setup_error(const ExecContext *context, int socket_fd, const char *id
                 return open_terminal_as(tty_path(context), O_WRONLY, STDERR_FILENO);
 
         case EXEC_OUTPUT_SYSLOG:
-        case EXEC_OUTPUT_KERNEL:
+        case EXEC_OUTPUT_KMSG:
                 return connect_logger_as(context, e, ident, STDERR_FILENO);
 
         case EXEC_OUTPUT_SOCKET:
@@ -1266,8 +1266,8 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
                         "%sTTYPath: %s\n",
                         prefix, c->tty_path);
 
-        if (c->std_output == EXEC_OUTPUT_SYSLOG || c->std_output == EXEC_OUTPUT_KERNEL ||
-            c->std_error == EXEC_OUTPUT_SYSLOG || c->std_error == EXEC_OUTPUT_KERNEL)
+        if (c->std_output == EXEC_OUTPUT_SYSLOG || c->std_output == EXEC_OUTPUT_KMSG ||
+            c->std_error == EXEC_OUTPUT_SYSLOG || c->std_error == EXEC_OUTPUT_KMSG)
                 fprintf(f,
                         "%sSyslogFacility: %s\n"
                         "%sSyslogLevel: %s\n",
@@ -1616,7 +1616,7 @@ static const char* const exec_output_table[_EXEC_OUTPUT_MAX] = {
         [EXEC_OUTPUT_NULL] = "null",
         [EXEC_OUTPUT_TTY] = "tty",
         [EXEC_OUTPUT_SYSLOG] = "syslog",
-        [EXEC_OUTPUT_KERNEL] = "kernel",
+        [EXEC_OUTPUT_KMSG] = "kmsg",
         [EXEC_OUTPUT_SOCKET] = "socket"
 };
 
diff --git a/src/execute.h b/src/execute.h
index be73542..d42e0ba 100644
--- a/src/execute.h
+++ b/src/execute.h
@@ -56,7 +56,7 @@ typedef enum ExecOutput {
         EXEC_OUTPUT_NULL,
         EXEC_OUTPUT_TTY,
         EXEC_OUTPUT_SYSLOG,
-        EXEC_OUTPUT_KERNEL,
+        EXEC_OUTPUT_KMSG,
         EXEC_OUTPUT_SOCKET,
         _EXEC_OUTPUT_MAX,
         _EXEC_OUTPUT_INVALID = -1
diff --git a/src/unit.c b/src/unit.c
index 374d2e1..8f0b077 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -534,7 +534,7 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) {
         assert(u);
         assert(c);
 
-        if (c->std_output != EXEC_OUTPUT_KERNEL && c->std_output != EXEC_OUTPUT_SYSLOG)
+        if (c->std_output != EXEC_OUTPUT_KMSG && c->std_output != EXEC_OUTPUT_SYSLOG)
                 return 0;
 
         /* If syslog or kernel logging is requested, make sure our own


More information about the systemd-commits mailing list