X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fcore%2Fmount.c;h=7cadd9fcb44a29430e23574a418a9e289bd5026a;hb=4f0eedb703848597d004da506b7636719892a958;hp=fc981c74f430dc957ef8ef14578a2f0e3f5ee9b5;hpb=96342de68d0d6de71a062d984dafd2a0905ed9fe;p=elogind.git diff --git a/src/core/mount.c b/src/core/mount.c index fc981c74f..7cadd9fcb 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -30,6 +30,7 @@ #include "load-fragment.h" #include "load-dropin.h" #include "log.h" +#include "sd-messages.h" #include "strv.h" #include "mkdir.h" #include "path-util.h" @@ -221,9 +222,11 @@ static int mount_add_swap_links(Mount *m) { assert(m); - LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SWAP]) - if ((r = swap_add_one_mount_link(SWAP(other), m)) < 0) + LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SWAP]) { + r = swap_add_one_mount_link(SWAP(other), m); + if (r < 0) return r; + } return 0; } @@ -234,9 +237,11 @@ static int mount_add_path_links(Mount *m) { assert(m); - LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_PATH]) - if ((r = path_add_one_mount_link(PATH(other), m)) < 0) + LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_PATH]) { + r = path_add_one_mount_link(PATH(other), m); + if (r < 0) return r; + } return 0; } @@ -247,9 +252,11 @@ static int mount_add_automount_links(Mount *m) { assert(m); - LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_AUTOMOUNT]) - if ((r = automount_add_one_mount_link(AUTOMOUNT(other), m)) < 0) + LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_AUTOMOUNT]) { + r = automount_add_one_mount_link(AUTOMOUNT(other), m); + if (r < 0) return r; + } return 0; } @@ -260,9 +267,11 @@ static int mount_add_socket_links(Mount *m) { assert(m); - LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SOCKET]) - if ((r = socket_add_one_mount_link(SOCKET(other), m)) < 0) + LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SOCKET]) { + r = socket_add_one_mount_link(SOCKET(other), m); + if (r < 0) return r; + } return 0; } @@ -352,17 +361,21 @@ static int mount_add_device_links(Mount *m) { if (!p->what) return 0; - if (!mount_is_bind(p) && - !path_equal(m->where, "/")) { - r = unit_add_node_link(UNIT(m), p->what, false); - if (r < 0) - return r; - } + if (mount_is_bind(p)) + return 0; + + if (!is_device_path(p->what)) + return 0; + + if (path_equal(m->where, "/")) + return 0; + + r = unit_add_node_link(UNIT(m), p->what, false); + if (r < 0) + return r; if (p->passno > 0 && - !mount_is_bind(p) && - !path_equal(m->where, "/") && - UNIT(m)->manager->running_as == MANAGER_SYSTEM) { + UNIT(m)->manager->running_as == SYSTEMD_SYSTEM) { char *name; Unit *fsck; /* Let's add in the fsck service */ @@ -396,7 +409,7 @@ static int mount_add_quota_links(Mount *m) { assert(m); - if (UNIT(m)->manager->running_as != MANAGER_SYSTEM) + if (UNIT(m)->manager->running_as != SYSTEMD_SYSTEM) return 0; p = get_mount_parameters_fragment(m); @@ -424,7 +437,7 @@ static int mount_add_default_dependencies(Mount *m) { assert(m); - if (UNIT(m)->manager->running_as != MANAGER_SYSTEM) + if (UNIT(m)->manager->running_as != SYSTEMD_SYSTEM) return 0; p = get_mount_parameters_fragment(m); @@ -543,10 +556,6 @@ static int mount_add_extras(Mount *m) { Unit *u = UNIT(m); int r; - r = unit_add_exec_dependencies(u, &m->exec_context); - if (r < 0) - return r; - if (UNIT(m)->fragment_path) m->from_fragment = true; @@ -558,6 +567,10 @@ static int mount_add_extras(Mount *m) { path_kill_slashes(m->where); + r = unit_add_exec_dependencies(u, &m->exec_context); + if (r < 0) + return r; + if (!UNIT(m)->description) { r = unit_set_description(u, m->where); if (r < 0) @@ -737,10 +750,12 @@ static int mount_coldplug(Unit *u) { if (m->control_pid <= 0) return -EBADMSG; - if ((r = unit_watch_pid(UNIT(m), m->control_pid)) < 0) + r = unit_watch_pid(UNIT(m), m->control_pid); + if (r < 0) return r; - if ((r = unit_watch_timer(UNIT(m), m->timeout_usec, &m->timer_watch)) < 0) + r = unit_watch_timer(UNIT(m), CLOCK_MONOTONIC, true, m->timeout_usec, &m->timer_watch); + if (r < 0) return r; } @@ -796,7 +811,8 @@ static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) { assert(c); assert(_pid); - if ((r = unit_watch_timer(UNIT(m), m->timeout_usec, &m->timer_watch)) < 0) + r = unit_watch_timer(UNIT(m), CLOCK_MONOTONIC, true, m->timeout_usec, &m->timer_watch); + if (r < 0) goto fail; if ((r = exec_spawn(c, @@ -896,7 +912,8 @@ static void mount_enter_signal(Mount *m, MountState state, MountResult f) { } if (wait_for_exit) { - if ((r = unit_watch_timer(UNIT(m), m->timeout_usec, &m->timer_watch)) < 0) + r = unit_watch_timer(UNIT(m), CLOCK_MONOTONIC, true, m->timeout_usec, &m->timer_watch); + if (r < 0) goto fail; mount_set_state(m, state); @@ -919,6 +936,18 @@ fail: set_free(pid_set); } +void warn_if_dir_nonempty(const char *unit, const char* where) { + if (dir_is_empty(where) > 0) + return; + log_struct(LOG_NOTICE, + "MESSAGE=%s: Directory %s to mount over is not empty, mounting anyway.", + unit, where, + "WHERE=%s", where, + "_SYSTEMD_UNIT=%s", unit, + MESSAGE_ID(SD_MESSAGE_OVERMOUNTING), + NULL); +} + static void mount_enter_unmounting(Mount *m) { int r; @@ -959,6 +988,8 @@ static void mount_enter_mounting(Mount *m) { mkdir_p_label(m->where, m->directory_mode); + warn_if_dir_nonempty(m->meta.id, m->where); + /* Create the source directory for bind-mounts if needed */ p = get_mount_parameters_fragment(m); if (p && mount_is_bind(p)) @@ -981,7 +1012,8 @@ static void mount_enter_mounting(Mount *m) { mount_unwatch_control_pid(m); - if ((r = mount_spawn(m, m->control_command, &m->control_pid)) < 0) + r = mount_spawn(m, m->control_command, &m->control_pid); + if (r < 0) goto fail; mount_set_state(m, MOUNT_MOUNTING); @@ -1400,6 +1432,7 @@ static int mount_add_one( bool delete; char *e, *w = NULL, *o = NULL, *f = NULL; MountParameters *p; + bool load_extras = false; assert(m); assert(what); @@ -1450,12 +1483,21 @@ static int mount_add_one( delete = false; free(e); + if (!MOUNT(u)->where) { + MOUNT(u)->where = strdup(where); + if (!MOUNT(u)->where) { + r = -ENOMEM; + goto fail; + } + } + if (u->load_state == UNIT_ERROR) { u->load_state = UNIT_LOADED; u->load_error = 0; - r = mount_add_extras(MOUNT(u)); - if (r < 0) - goto fail; + + /* Load in the extras later on, after we + * finished initialization of the unit */ + load_extras = true; } } @@ -1486,6 +1528,12 @@ static int mount_add_one( p->passno = passno; + if (load_extras) { + r = mount_add_extras(MOUNT(u)); + if (r < 0) + goto fail; + } + unit_add_to_dbus_queue(u); return 0; @@ -1630,7 +1678,8 @@ void mount_fd_event(Manager *m, int events) { * /proc/self/mountinfo file, which informs us about mounting * table changes */ - if ((r = mount_load_proc_self_mountinfo(m, true)) < 0) { + r = mount_load_proc_self_mountinfo(m, true); + if (r < 0) { log_error("Failed to reread /proc/self/mountinfo: %s", strerror(-r)); /* Reset flags, just in case, for later calls */ @@ -1797,6 +1846,8 @@ DEFINE_STRING_TABLE_LOOKUP(mount_result, MountResult); const UnitVTable mount_vtable = { .object_size = sizeof(Mount), + .exec_context_offset = offsetof(Mount, exec_context), + .sections = "Unit\0" "Mount\0"