summaryrefslogtreecommitdiff
path: root/src/core/automount.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-04-23 15:53:16 -0300
committerLennart Poettering <lennart@poettering.net>2013-04-23 16:00:32 -0300
commit3ecaa09bccd8a59c9f1e06756a1334a162206dc4 (patch)
tree5db15dc8f6fe6ea17e0d2449b8fee015b6066f47 /src/core/automount.c
parenta34cb32e54ed51125957f69622efef30f42d5fae (diff)
unit: rework trigger dependency logic
Instead of having explicit type-specific callbacks that inform the triggering unit when a triggered unit changes state, make this generic so that state changes are forwarded betwee any triggered and triggering unit. Also, get rid of UnitRef references from automount, timer, path units, to the units they trigger and rely exclsuively on UNIT_TRIGGER type dendencies.
Diffstat (limited to 'src/core/automount.c')
-rw-r--r--src/core/automount.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/core/automount.c b/src/core/automount.c
index 4a98540d82..e6eedda96f 100644
--- a/src/core/automount.c
+++ b/src/core/automount.c
@@ -109,7 +109,6 @@ static void automount_done(Unit *u) {
assert(a);
unmount_autofs(a);
- unit_ref_unset(&a->mount);
free(a->where);
a->where = NULL;
@@ -200,8 +199,8 @@ static int automount_verify(Automount *a) {
}
static int automount_load(Unit *u) {
- int r;
Automount *a = AUTOMOUNT(u);
+ int r;
assert(u);
assert(u->load_state == UNIT_STUB);
@@ -222,17 +221,15 @@ static int automount_load(Unit *u) {
path_kill_slashes(a->where);
- r = automount_add_mount_links(a);
+ r = unit_load_related_unit(u, ".mount", &x);
if (r < 0)
return r;
- r = unit_load_related_unit(u, ".mount", &x);
+ r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, x, true);
if (r < 0)
return r;
- unit_ref_set(&a->mount, x);
-
- r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, UNIT_DEREF(a->mount), true);
+ r = automount_add_mount_links(a);
if (r < 0)
return r;
@@ -586,12 +583,11 @@ fail:
}
static void automount_enter_runnning(Automount *a) {
- int r;
- struct stat st;
_cleanup_dbus_error_free_ DBusError error;
+ struct stat st;
+ int r;
assert(a);
- assert(UNIT_DEREF(a->mount));
dbus_error_init(&error);
@@ -616,11 +612,15 @@ static void automount_enter_runnning(Automount *a) {
if (!S_ISDIR(st.st_mode) || st.st_dev != a->dev_id)
log_info_unit(UNIT(a)->id,
"%s's automount point already active?", UNIT(a)->id);
- else if ((r = manager_add_job(UNIT(a)->manager, JOB_START, UNIT_DEREF(a->mount), JOB_REPLACE, true, &error, NULL)) < 0) {
- log_warning_unit(UNIT(a)->id,
- "%s failed to queue mount startup job: %s",
- UNIT(a)->id, bus_error(&error, r));
- goto fail;
+ else {
+ r = manager_add_job(UNIT(a)->manager, JOB_START, UNIT_TRIGGER(UNIT(a)),
+ JOB_REPLACE, true, &error, NULL);
+ if (r < 0) {
+ log_warning_unit(UNIT(a)->id,
+ "%s failed to queue mount startup job: %s",
+ UNIT(a)->id, bus_error(&error, r));
+ goto fail;
+ }
}
automount_set_state(a, AUTOMOUNT_RUNNING);
@@ -643,7 +643,7 @@ static int automount_start(Unit *u) {
return -EEXIST;
}
- if (UNIT_DEREF(a->mount)->load_state != UNIT_LOADED)
+ if (UNIT_TRIGGER(u)->load_state != UNIT_LOADED)
return -ENOENT;
a->result = AUTOMOUNT_SUCCESS;
@@ -765,14 +765,12 @@ static const char *automount_sub_state_to_string(Unit *u) {
}
static bool automount_check_gc(Unit *u) {
- Automount *a = AUTOMOUNT(u);
-
- assert(a);
+ assert(u);
- if (!UNIT_DEREF(a->mount))
+ if (!UNIT_TRIGGER(u))
return false;
- return UNIT_VTABLE(UNIT_DEREF(a->mount))->check_gc(UNIT_DEREF(a->mount));
+ return UNIT_VTABLE(UNIT_TRIGGER(u))->check_gc(UNIT_TRIGGER(u));
}
static void automount_fd_event(Unit *u, int fd, uint32_t events, Watch *w) {