X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fautomount.c;h=e685c96a76ab7206b9407484d9a92bc89c652169;hp=b8d7ad25f4d9a938bf1bb9c21df19497d2cb6c2e;hb=b9975629f03a43d4c6b14fdb42eb8dd5a30af28f;hpb=1cf18f27331286dfb56d92e1800facf4f696ad27 diff --git a/src/automount.c b/src/automount.c index b8d7ad25f..e685c96a7 100644 --- a/src/automount.c +++ b/src/automount.c @@ -35,6 +35,8 @@ #include "load-dropin.h" #include "unit-name.h" #include "dbus-automount.h" +#include "bus-errors.h" +#include "special.h" static const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = { [AUTOMOUNT_DEAD] = UNIT_INACTIVE, @@ -125,10 +127,7 @@ int automount_add_one_mount_link(Automount *a, Mount *m) { if (path_equal(a->where, m->where)) return 0; - if ((r = unit_add_dependency(UNIT(m), UNIT_BEFORE, UNIT(a), true)) < 0) - return r; - - if ((r = unit_add_dependency(UNIT(a), UNIT_REQUIRES, UNIT(m), true)) < 0) + if ((r = unit_add_two_dependencies(UNIT(a), UNIT_AFTER, UNIT_REQUIRES, UNIT(m), true)) < 0) return r; return 0; @@ -147,6 +146,23 @@ static int automount_add_mount_links(Automount *a) { return 0; } +static int automount_add_default_dependencies(Automount *a) { + int r; + + assert(a); + + if (a->meta.manager->running_as == MANAGER_SYSTEM) { + + if ((r = unit_add_dependency_by_name(UNIT(a), UNIT_AFTER, SPECIAL_SYSINIT_TARGET, NULL, true)) < 0) + return r; + + if ((r = unit_add_two_dependencies_by_name(UNIT(a), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true)) < 0) + return r; + } + + return 0; +} + static int automount_verify(Automount *a) { bool b; char *e; @@ -155,6 +171,11 @@ static int automount_verify(Automount *a) { if (a->meta.load_state != UNIT_LOADED) return 0; + if (path_equal(a->where, "/")) { + log_error("Cannot have an automount unit for the root directory. Refusing."); + return -EINVAL; + } + if (!(e = unit_name_from_path(a->where, ".automount"))) return -ENOMEM; @@ -196,6 +217,10 @@ static int automount_load(Unit *u) { if ((r = unit_add_dependency(u, UNIT_BEFORE, UNIT(a->mount), true)) < 0) return r; + + if (a->meta.default_dependencies) + if ((r = automount_add_default_dependencies(a)) < 0) + return r; } return automount_verify(a); @@ -536,10 +561,20 @@ fail: static void automount_enter_runnning(Automount *a) { int r; struct stat st; + DBusError error; assert(a); assert(a->mount); + dbus_error_init(&error); + + /* We don't take mount requests anymore if we are supposed to + * shut down anyway */ + if (a->meta.job && a->meta.job->type == JOB_STOP) { + automount_send_ready(a, -EHOSTDOWN); + return; + } + mkdir_p(a->where, a->directory_mode); /* Before we do anything, let's see if somebody is playing games with us? */ @@ -550,8 +585,8 @@ static void automount_enter_runnning(Automount *a) { if (!S_ISDIR(st.st_mode) || st.st_dev != a->dev_id) log_info("%s's automount point already active?", a->meta.id); - else if ((r = manager_add_job(a->meta.manager, JOB_START, UNIT(a->mount), JOB_REPLACE, true, NULL)) < 0) { - log_warning("%s failed to queue mount startup job: %s", a->meta.id, strerror(-r)); + else if ((r = manager_add_job(a->meta.manager, JOB_START, UNIT(a->mount), JOB_REPLACE, true, &error, NULL)) < 0) { + log_warning("%s failed to queue mount startup job: %s", a->meta.id, bus_error(&error, r)); goto fail; } @@ -560,6 +595,7 @@ static void automount_enter_runnning(Automount *a) { fail: automount_enter_dead(a, false); + dbus_error_free(&error); } static int automount_start(Unit *u) {