summaryrefslogtreecommitdiff
path: root/socket.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-04-06 02:43:58 +0200
committerLennart Poettering <lennart@poettering.net>2010-04-06 02:43:58 +0200
commit23a177ef7c8c38c238ef06666f900f581b48298f (patch)
tree0e1467035854fea1a51c5efad2f69464ac2d402b /socket.c
parent5af98f828476716954f327c479c4cf6321ae3fe4 (diff)
rework merging/loading logic
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/socket.c b/socket.c
index 2a19e97b7b..a1f3ef8af7 100644
--- 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) {