chiark / gitweb /
sysv: sysv service should depend on the full basic system, not only rc.sysinit
[elogind.git] / socket.c
index 79933347d0e02d296e8858d2e421360bf89f4f3e..a1f3ef8af75eadb9a637638f88ce494c99a1b0b7 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -30,6 +30,8 @@
 #include "unit.h"
 #include "socket.h"
 #include "log.h"
+#include "load-dropin.h"
+#include "load-fragment.h"
 
 static const UnitActiveState state_translation_table[_SOCKET_STATE_MAX] = {
         [SOCKET_DEAD] = UNIT_INACTIVE,
@@ -92,7 +94,7 @@ static void socket_done(Unit *u) {
         unit_unwatch_timer(u, &s->timer_watch);
 }
 
-static int socket_init(Unit *u) {
+static int socket_init(Unit *u, UnitLoadState *new_state) {
         Socket *s = SOCKET(u);
         char *t;
         int r;
@@ -109,35 +111,38 @@ static int socket_init(Unit *u) {
         s->socket_mode = 0666;
         exec_context_init(&s->exec_context);
 
-        if ((r = unit_load_fragment_and_dropin(u)) <= 0) {
-                if (r == 0)
-                        r = -ENOENT;
-                goto fail;
-        }
+        if ((r = unit_load_fragment(u, new_state)) < 0)
+                return r;
 
-        if (!(t = unit_name_change_suffix(unit_id(u), ".service"))) {
-                r = -ENOMEM;
-                goto fail;
-        }
+        if (*new_state == UNIT_STUB)
+                return -ENOENT;
 
-        r = manager_load_unit(u->meta.manager, t, (Unit**) &s->service);
-        free(t);
+        if ((r = unit_load_dropin(unit_follow_merge(u))) < 0)
+                return r;
 
-        if (r < 0)
-                goto fail;
+        /* This is a new unit? Then let's add in some extras */
+        if (*new_state == UNIT_LOADED) {
 
-        if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(s->service))) < 0)
-                goto fail;
+                if (!(t = unit_name_change_suffix(unit_id(u), ".service")))
+                        return -ENOMEM;
 
-        /* Add default cgroup */
-        if ((r = unit_add_default_cgroup(u)) < 0)
-                goto fail;
+                r = manager_load_unit(u->meta.manager, t, (Unit**) &s->service);
+                free(t);
 
-        return 0;
+                if (r < 0)
+                        return r;
 
-fail:
-        socket_done(u);
-        return r;
+                if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(s->service))) < 0)
+                        return r;
+
+                if ((r = unit_add_exec_dependencies(u, &s->exec_context)) < 0)
+                        return r;
+
+                if ((r = unit_add_default_cgroup(u)) < 0)
+                        return r;
+        }
+
+        return 0;
 }
 
 static const char* listen_lookup(int type) {
@@ -267,7 +272,9 @@ static int socket_open_fds(Socket *s) {
                         struct stat st;
                         assert(p->type == SOCKET_FIFO);
 
-                        if (mkfifo(p->path, 0666 & ~s->exec_context.umask) < 0 && errno != EEXIST) {
+                        mkdir_parents(p->path, s->directory_mode);
+
+                        if (mkfifo(p->path, s->socket_mode) < 0 && errno != EEXIST) {
                                 r = -errno;
                                 goto rollback;
                         }
@@ -701,7 +708,7 @@ static void socket_sigchld_event(Unit *u, pid_t pid, int code, int status) {
         log_debug("%s control process exited, code=%s status=%i", unit_id(u), sigchld_code_to_string(code), status);
 
         if (s->control_command->command_next &&
-            (success || (s->state == SOCKET_EXEC_STOP_PRE || s->state == SOCKET_EXEC_STOP_POST))) {
+            (success || (s->state == SOCKET_STOP_PRE || s->state == SOCKET_STOP_POST))) {
                 log_debug("%s running next command for the state %s", unit_id(u), state_string_table[s->state]);
                 socket_run_next(s, success);
         } else {