[systemd-commits] 3 commits - fixme src/execute.c src/execute.h src/main.c src/manager.c src/util.c src/util.h

Lennart Poettering lennart at kemper.freedesktop.org
Fri May 21 18:32:07 PDT 2010


 fixme         |    4 --
 src/execute.c |    6 +++
 src/execute.h |    4 ++
 src/main.c    |   10 +-----
 src/manager.c |   48 +++++++++++++++++++++++++----
 src/util.c    |   94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/util.h    |    7 +++-
 7 files changed, 150 insertions(+), 23 deletions(-)

New commits:
commit 967d86b5cbc39f2b6edeea7ae109dbfcaaf4f006
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat May 22 03:32:00 2010 +0200

    manager: link ~/.local/share/systemd/session to ~/.config/systemd/session if possible

diff --git a/src/manager.c b/src/manager.c
index 5964fc9..5d88875 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -163,6 +163,16 @@ static char** session_dirs(void) {
         } else if (home) {
                 if (asprintf(&data_home, "%s/.local/share/systemd/session", home) < 0)
                         goto fail;
+
+                /* There is really no need for two unit dirs in $HOME,
+                 * except to be fully compliant with the XDG spec. We
+                 * now try to link the two dirs, so that we can
+                 * minimize disk seeks a little. Further down we'll
+                 * then filter out this link, if it is actually is
+                 * one. */
+
+                mkdir_parents(data_home, 0777);
+                symlink("../../../.config/systemd/session", data_home);
         }
 
         if ((e = getenv("XDG_DATA_DIRS")))
commit c3f6d6757a0923428a82ff617c10635d4ff4b184
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat May 22 03:30:46 2010 +0200

    manager: canonicalize search paths and filter out non-existing paths and those pointing to the same fs directory

diff --git a/src/manager.c b/src/manager.c
index f6f205f..5964fc9 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -283,15 +283,33 @@ static int manager_find_paths(Manager *m) {
                 }
         }
 
+        if (m->unit_path)
+                if (!strv_path_canonicalize(m->unit_path))
+                        return -ENOMEM;
+
+        if (m->sysvinit_path)
+                if (!strv_path_canonicalize(m->sysvinit_path))
+                        return -ENOMEM;
+
+        if (m->sysvrcnd_path)
+                if (!strv_path_canonicalize(m->sysvrcnd_path))
+                        return -ENOMEM;
+
         strv_uniq(m->unit_path);
         strv_uniq(m->sysvinit_path);
         strv_uniq(m->sysvrcnd_path);
 
-        assert(!strv_isempty(m->unit_path));
-        if (!(t = strv_join(m->unit_path, "\n\t")))
-                return -ENOMEM;
-        log_debug("Looking for unit files in:\n\t%s", t);
-        free(t);
+        if (!strv_isempty(m->unit_path)) {
+
+                if (!(t = strv_join(m->unit_path, "\n\t")))
+                        return -ENOMEM;
+                log_debug("Looking for unit files in:\n\t%s", t);
+                free(t);
+        } else {
+                log_debug("Ignoring unit files.");
+                strv_free(m->unit_path);
+                m->unit_path = NULL;
+        }
 
         if (!strv_isempty(m->sysvinit_path)) {
 
@@ -300,8 +318,11 @@ static int manager_find_paths(Manager *m) {
 
                 log_debug("Looking for SysV init scripts in:\n\t%s", t);
                 free(t);
-        } else
+        } else {
                 log_debug("Ignoring SysV init scripts.");
+                strv_free(m->sysvinit_path);
+                m->sysvinit_path = NULL;
+        }
 
         if (!strv_isempty(m->sysvrcnd_path)) {
 
@@ -310,8 +331,11 @@ static int manager_find_paths(Manager *m) {
 
                 log_debug("Looking for SysV rcN.d links in:\n\t%s", t);
                 free(t);
-        } else
+        } else {
                 log_debug("Ignoring SysV rcN.d links.");
+                strv_free(m->sysvrcnd_path);
+                m->sysvrcnd_path = NULL;
+        }
 
         return 0;
 }
diff --git a/src/util.c b/src/util.c
index 47b1b44..85a8e37 100644
--- a/src/util.c
+++ b/src/util.c
@@ -652,6 +652,51 @@ char **strv_path_make_absolute_cwd(char **l) {
         return l;
 }
 
+char **strv_path_canonicalize(char **l) {
+        char **s;
+        unsigned k = 0;
+        bool enomem = false;
+
+        if (strv_isempty(l))
+                return l;
+
+        /* Goes through every item in the string list and canonicalize
+         * the path. This works in place and won't rollback any
+         * changes on failure. */
+
+        STRV_FOREACH(s, l) {
+                char *t, *u;
+
+                t = path_make_absolute_cwd(*s);
+                free(*s);
+
+                if (!t) {
+                        enomem = true;
+                        continue;
+                }
+
+                errno = 0;
+                u = canonicalize_file_name(t);
+                free(t);
+
+                if (!u) {
+                        if (errno == ENOMEM || !errno)
+                                enomem = true;
+
+                        continue;
+                }
+
+                l[k++] = u;
+        }
+
+        l[k] = NULL;
+
+        if (enomem)
+                return NULL;
+
+        return l;
+}
+
 int reset_all_signal_handlers(void) {
         int sig;
 
diff --git a/src/util.h b/src/util.h
index 93d6708..ccb9769 100644
--- a/src/util.h
+++ b/src/util.h
@@ -138,7 +138,9 @@ bool is_path(const char *p);
 bool path_is_absolute(const char *p);
 char *path_make_absolute(const char *p, const char *prefix);
 char *path_make_absolute_cwd(const char *p);
+
 char **strv_path_make_absolute_cwd(char **l);
+char **strv_path_canonicalize(char **l);
 
 int reset_all_signal_handlers(void);
 
commit 9a34ec5fbb4b55413dc9d610b636fe760d34ecd7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Sat May 22 01:46:08 2010 +0200

    execute: only reset those signals to the default we really need to reset to the default

diff --git a/fixme b/fixme
index d15e0db..513c32b 100644
--- a/fixme
+++ b/fixme
@@ -23,8 +23,6 @@
 
 * reinvestigate random seed, hwclock
 
-* introduce serialized mode
-
 * "disabled" load state?
 
 * uid are 32bit
@@ -63,8 +61,6 @@
 
 * Add code to systemctl to wait for an operation to finish
 
-* update to new libudev/tags
-
 Regularly:
 
 * look for close() vs. close_nointr() vs. close_nointr_nofail()
diff --git a/src/execute.c b/src/execute.c
index 06eb152..ead6c0f 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -783,7 +783,11 @@ int exec_spawn(ExecCommand *command,
 
                 /* child */
 
-                reset_all_signal_handlers();
+                /* We reset exactly these two signals, since they are
+                 * the only ones we set to SIG_IGN in the main
+                 * daemon. All others */
+                default_signals(SIGNALS_CRASH_HANLDER,
+                                SIGNALS_IGNORE, -1);
 
                 if (sigemptyset(&ss) < 0 ||
                     sigprocmask(SIG_SETMASK, &ss, NULL) < 0) {
diff --git a/src/execute.h b/src/execute.h
index d42e0ba..045d462 100644
--- a/src/execute.h
+++ b/src/execute.h
@@ -41,6 +41,10 @@ struct CGroupBonding;
 /* Abstract namespace! */
 #define LOGGER_SOCKET "/org/freedesktop/systemd1/logger"
 
+/* This doesn't really belong here, but I couldn't find a better place to put this. */
+#define SIGNALS_CRASH_HANLDER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT
+#define SIGNALS_IGNORE SIGKILL,SIGPIPE
+
 typedef enum ExecInput {
         EXEC_INPUT_NULL,
         EXEC_INPUT_TTY,
diff --git a/src/main.c b/src/main.c
index 95d2115..5c2af04 100644
--- a/src/main.c
+++ b/src/main.c
@@ -165,12 +165,7 @@ static void install_crash_handler(void) {
         sa.sa_handler = crash;
         sa.sa_flags = SA_NODEFER;
 
-        assert_se(sigaction(SIGSEGV, &sa, NULL) == 0);
-        assert_se(sigaction(SIGILL, &sa, NULL) == 0);
-        assert_se(sigaction(SIGFPE, &sa, NULL) == 0);
-        assert_se(sigaction(SIGBUS, &sa, NULL) == 0);
-        assert_se(sigaction(SIGQUIT, &sa, NULL) == 0);
-        assert_se(sigaction(SIGABRT, &sa, NULL) == 0);
+        sigaction_many(&sa, SIGNALS_CRASH_HANLDER, -1);
 }
 
 static int make_null_stdio(void) {
@@ -569,8 +564,7 @@ int main(int argc, char *argv[]) {
         assert_se(reset_all_signal_handlers() == 0);
 
         /* If we are init, we can block sigkill. Yay. */
-        ignore_signal(SIGKILL);
-        ignore_signal(SIGPIPE);
+        ignore_signals(SIGNALS_IGNORE, -1);
 
         if (running_as != MANAGER_SESSION)
                 if (parse_proc_cmdline() < 0)
diff --git a/src/util.c b/src/util.c
index 5c1e16a..47b1b44 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1735,14 +1735,59 @@ int release_terminal(void) {
         return r;
 }
 
-int ignore_signal(int sig) {
+int sigaction_many(const struct sigaction *sa, ...) {
+        va_list ap;
+        int r = 0, sig;
+
+        va_start(ap, sa);
+        while ((sig = va_arg(ap, int)) > 0)
+                if (sigaction(sig, sa, NULL) < 0)
+                        r = -errno;
+        va_end(ap);
+
+        return r;
+}
+
+int ignore_signals(int sig, ...) {
         struct sigaction sa;
+        va_list ap;
+        int r = 0;
 
         zero(sa);
         sa.sa_handler = SIG_IGN;
         sa.sa_flags = SA_RESTART;
 
-        return sigaction(sig, &sa, NULL);
+        if (sigaction(sig, &sa, NULL) < 0)
+                r = -errno;
+
+        va_start(ap, sig);
+        while ((sig = va_arg(ap, int)) > 0)
+                if (sigaction(sig, &sa, NULL) < 0)
+                        r = -errno;
+        va_end(ap);
+
+        return r;
+}
+
+int default_signals(int sig, ...) {
+        struct sigaction sa;
+        va_list ap;
+        int r = 0;
+
+        zero(sa);
+        sa.sa_handler = SIG_DFL;
+        sa.sa_flags = SA_RESTART;
+
+        if (sigaction(sig, &sa, NULL) < 0)
+                r = -errno;
+
+        va_start(ap, sig);
+        while ((sig = va_arg(ap, int)) > 0)
+                if (sigaction(sig, &sa, NULL) < 0)
+                        r = -errno;
+        va_end(ap);
+
+        return r;
 }
 
 int close_pipe(int p[]) {
diff --git a/src/util.h b/src/util.h
index 84dd2bc..93d6708 100644
--- a/src/util.h
+++ b/src/util.h
@@ -28,6 +28,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <signal.h>
 
 typedef uint64_t usec_t;
 
@@ -223,7 +224,9 @@ int release_terminal(void);
 
 int flush_fd(int fd);
 
-int ignore_signal(int sig);
+int ignore_signals(int sig, ...);
+int default_signals(int sig, ...);
+int sigaction_many(const struct sigaction *sa, ...);
 
 int close_pipe(int p[]);
 


More information about the systemd-commits mailing list