-/*-*- Mode: C; c-basic-offset: 8 -*-*/
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
assert(u->meta.load_state == UNIT_STUB);
m->timeout_usec = DEFAULT_TIMEOUT_USEC;
- exec_context_init(&m->exec_context);
-
m->directory_mode = 0755;
+ exec_context_init(&m->exec_context);
+
/* We need to make sure that /bin/mount is always called in
* the same process group as us, so that the autofs kernel
* side doesn't send us another mount request while we are
}
}
+static int mount_add_default_dependencies(Mount *m) {
+ int r;
+
+ assert(m);
+
+ if (m->meta.manager->running_as == MANAGER_SYSTEM &&
+ !path_equal(m->where, "/")) {
+
+ if ((r = unit_add_dependency_by_name(UNIT(m), UNIT_AFTER, SPECIAL_FSCK_TARGET, NULL, true)) < 0)
+ return r;
+
+ if ((r = unit_add_two_dependencies_by_name(UNIT(m), UNIT_BEFORE, UNIT_CONFLICTED_BY, SPECIAL_UMOUNT_TARGET, NULL, true)) < 0)
+ return r;
+ }
+
+ return 0;
+}
+
static int mount_verify(Mount *m) {
bool b;
char *e;
return -EBADMSG;
}
- if (m->exec_context.pam_name && m->kill_mode != KILL_CONTROL_GROUP) {
+ if (m->exec_context.pam_name && m->exec_context.kill_mode != KILL_CONTROL_GROUP) {
log_error("%s has PAM enabled. Kill mode must be set to 'control-group'. Refusing.", m->meta.id);
return -EINVAL;
}
if ((r = unit_add_default_cgroup(u)) < 0)
return r;
+
+ if (m->meta.default_dependencies)
+ if ((r = mount_add_default_dependencies(m)) < 0)
+ return r;
}
return mount_verify(m);
"%sFrom /etc/fstab: %s\n"
"%sFrom /proc/self/mountinfo: %s\n"
"%sFrom fragment: %s\n"
- "%sKillMode: %s\n"
"%sDirectoryMode: %04o\n",
prefix, mount_state_to_string(m->state),
prefix, m->where,
prefix, yes_no(m->from_etc_fstab),
prefix, yes_no(m->from_proc_self_mountinfo),
prefix, yes_no(m->from_fragment),
- prefix, kill_mode_to_string(m->kill_mode),
prefix, m->directory_mode);
if (m->control_pid > 0)
m->meta.manager->environment,
true,
true,
- m->meta.manager->confirm_spawn,
true,
+ m->meta.manager->confirm_spawn,
m->meta.cgroup_bondings,
&pid)) < 0)
goto fail;
if (!success)
m->failure = true;
- if (m->kill_mode != KILL_NONE) {
+ if (m->exec_context.kill_mode != KILL_NONE) {
int sig = (state == MOUNT_MOUNTING_SIGTERM ||
state == MOUNT_UNMOUNTING_SIGTERM ||
- state == MOUNT_REMOUNTING_SIGTERM) ? SIGTERM : SIGKILL;
+ state == MOUNT_REMOUNTING_SIGTERM) ? m->exec_context.kill_signal : SIGKILL;
- if (m->kill_mode == KILL_CONTROL_GROUP) {
+ if (m->exec_context.kill_mode == KILL_CONTROL_GROUP) {
if ((r = cgroup_bonding_kill_list(m->meta.cgroup_bondings, sig)) < 0) {
if (r != -EAGAIN && r != -ESRCH)
}
if (!sent && m->control_pid > 0)
- if (kill(m->kill_mode == KILL_PROCESS ? m->control_pid : -m->control_pid, sig) < 0 && errno != ESRCH) {
+ if (kill(m->exec_context.kill_mode == KILL_PROCESS ?
+ m->control_pid :
+ -m->control_pid, sig) < 0 && errno != ESRCH) {
+
r = -errno;
goto fail;
}
return;
fail:
+ log_warning("%s failed to run 'remount' task: %s", m->meta.id, strerror(-r));
mount_enter_mounted(m, false);
}
assert(m);
- /* Cann't do this right now. */
- if (m->state == MOUNT_MOUNTING ||
- m->state == MOUNT_MOUNTING_DONE ||
- m->state == MOUNT_MOUNTING_SIGTERM ||
- m->state == MOUNT_MOUNTING_SIGKILL ||
- m->state == MOUNT_REMOUNTING ||
- m->state == MOUNT_REMOUNTING_SIGTERM ||
- m->state == MOUNT_REMOUNTING_SIGKILL)
- return -EAGAIN;
-
/* Already on it */
if (m->state == MOUNT_UNMOUNTING ||
m->state == MOUNT_UNMOUNTING_SIGKILL ||
m->state == MOUNT_UNMOUNTING_SIGTERM)
return 0;
- assert(m->state == MOUNT_MOUNTED);
+ assert(m->state == MOUNT_MOUNTING ||
+ m->state == MOUNT_MOUNTING_DONE ||
+ m->state == MOUNT_MOUNTED ||
+ m->state == MOUNT_MOUNTING_SIGTERM ||
+ m->state == MOUNT_MOUNTING_SIGKILL ||
+ m->state == MOUNT_REMOUNTING ||
+ m->state == MOUNT_REMOUNTING_SIGTERM ||
+ m->state == MOUNT_REMOUNTING_SIGKILL);
mount_enter_unmounting(m, true);
return 0;
static int mount_deserialize_item(Unit *u, const char *key, const char *value, FDSet *fds) {
Mount *m = MOUNT(u);
- int r;
assert(u);
assert(key);
} else if (streq(key, "control-pid")) {
pid_t pid;
- if ((r = parse_pid(value, &pid)) < 0)
+ if (parse_pid(value, &pid) < 0)
log_debug("Failed to parse control-pid value %s", value);
else
m->control_pid = pid;
m->control_command_id = _MOUNT_EXEC_COMMAND_INVALID;
}
- log_debug("%s control process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
+ log_full(success ? LOG_DEBUG : LOG_NOTICE,
+ "%s mount process exited, code=%s status=%i", u->meta.id, sigchld_code_to_string(code), status);
/* Note that mount(8) returning and the kernel sending us a
* mount table change event might happen out-of-order. If an
* table changes */
if ((r = mount_load_proc_self_mountinfo(m, true)) < 0) {
- log_error("Failed to reread /proc/self/mountinfo: %s", strerror(errno));
+ log_error("Failed to reread /proc/self/mountinfo: %s", strerror(-r));
/* Reset flags, just in case, for later calls */
LIST_FOREACH(units_per_type, meta, m->units_per_type[UNIT_MOUNT]) {
}
}
-int mount_path_is_mounted(Manager *m, const char* path) {
- char *t;
- int r;
+static void mount_reset_maintenance(Unit *u) {
+ Mount *m = MOUNT(u);
assert(m);
- assert(path);
-
- if (path[0] != '/')
- return 1;
-
- if (!(t = strdup(path)))
- return -ENOMEM;
-
- path_kill_slashes(t);
-
- for (;;) {
- char *e, *slash;
- Unit *u;
- if (!(e = unit_name_from_path(t, ".mount"))) {
- r = -ENOMEM;
- goto finish;
- }
+ if (m->state == MOUNT_MAINTENANCE)
+ mount_set_state(m, MOUNT_DEAD);
- u = manager_get_unit(m, e);
- free(e);
-
- if (u &&
- (MOUNT(u)->from_etc_fstab || MOUNT(u)->from_fragment) &&
- MOUNT(u)->state != MOUNT_MOUNTED) {
- r = 0;
- goto finish;
- }
-
- assert_se(slash = strrchr(t, '/'));
-
- if (slash == t) {
- r = 1;
- goto finish;
- }
-
- *slash = 0;
- }
-
- r = 1;
-
-finish:
- free(t);
- return r;
+ m->failure = false;
}
static const char* const mount_state_table[_MOUNT_STATE_MAX] = {
.sigchld_event = mount_sigchld_event,
.timer_event = mount_timer_event,
+ .reset_maintenance = mount_reset_maintenance,
+
.bus_message_handler = bus_mount_message_handler,
.enumerate = mount_enumerate,