automount.c revision d4d00020d6ad855d65d31020fefa5003e1bb477f
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek This file is part of systemd.
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek Copyright 2010 Lennart Poettering
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek under the terms of the GNU Lesser General Public License as published by
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek the Free Software Foundation; either version 2.1 of the License, or
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek (at your option) any later version.
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek WITHOUT ANY WARRANTY; without even the implied warranty of
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek#include <linux/auto_dev-ioctl.h>
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic const UnitActiveState state_translation_table[_AUTOMOUNT_STATE_MAX] = {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek [AUTOMOUNT_DEAD] = UNIT_INACTIVE,
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek [AUTOMOUNT_WAITING] = UNIT_ACTIVE,
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek [AUTOMOUNT_RUNNING] = UNIT_ACTIVE,
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek [AUTOMOUNT_FAILED] = UNIT_FAILED
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic inline void expire_data_free(struct expire_data *data) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek safe_close(data->dev_autofs_fd);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-SzmekDEFINE_TRIVIAL_CLEANUP_FUNC(struct expire_data*, expire_data_free);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int open_dev_autofs(Manager *m);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, void *userdata);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic void automount_init(Unit *u) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek assert(u->load_state == UNIT_STUB);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek UNIT(a)->ignore_on_isolate = true;
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic void repeat_unmount(const char *path) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek /* If there are multiple mounts on a mount point, this
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek * removes them all */
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (umount2(path, MNT_DETACH) >= 0)
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek log_error_errno(errno, "Failed to unmount: %m");
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int automount_send_ready(Automount *a, Set *tokens, int status);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic void unmount_autofs(Automount *a) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek automount_send_ready(a, a->tokens, -EHOSTDOWN);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek automount_send_ready(a, a->expire_tokens, -EHOSTDOWN);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek a->pipe_event_source = sd_event_source_unref(a->pipe_event_source);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek a->pipe_fd = safe_close(a->pipe_fd);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek /* If we reload/reexecute things we keep the mount point
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek (UNIT(a)->manager->exit_code != MANAGER_RELOAD &&
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek UNIT(a)->manager->exit_code != MANAGER_REEXECUTE))
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic void automount_done(Unit *u) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek a->expire_event_source = sd_event_source_unref(a->expire_event_source);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int automount_add_mount_links(Automount *a) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek _cleanup_free_ char *parent = NULL;
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = path_get_parent(a->where, &parent);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek return unit_require_mounts_for(UNIT(a), parent);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int automount_add_default_dependencies(Automount *a) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (UNIT(a)->manager->running_as != MANAGER_SYSTEM)
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = unit_add_two_dependencies_by_name(UNIT(a), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_UMOUNT_TARGET, NULL, true);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int automount_verify(Automount *a) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (UNIT(a)->load_state != UNIT_LOADED)
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (path_equal(a->where, "/")) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek log_unit_error(UNIT(a), "Cannot have an automount unit for the root directory. Refusing.");
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = unit_name_from_path(a->where, ".automount", &e);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek return log_unit_error(UNIT(a), "Failed to generate unit name from path: %m");
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (!unit_has_name(UNIT(a), e)) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek log_unit_error(UNIT(a), "Where= setting doesn't match unit name. Refusing.");
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int automount_load(Unit *u) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek assert(u->load_state == UNIT_STUB);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek /* Load a .automount file */
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = unit_load_fragment_and_dropin_optional(u);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (u->load_state == UNIT_LOADED) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = unit_name_to_path(u->id, &a->where);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = unit_load_related_unit(u, ".mount", &x);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = unit_add_two_dependencies(u, UNIT_BEFORE, UNIT_TRIGGERS, x, true);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = automount_add_mount_links(a);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (UNIT(a)->default_dependencies) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = automount_add_default_dependencies(a);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic void automount_set_state(Automount *a, AutomountState state) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (state != AUTOMOUNT_WAITING &&
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek log_unit_debug(UNIT(a), "Changed %s -> %s", automount_state_to_string(old_state), automount_state_to_string(state));
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek unit_notify(UNIT(a), state_translation_table[old_state], state_translation_table[state], true);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int automount_coldplug(Unit *u) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek assert(a->state == AUTOMOUNT_DEAD);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (a->deserialized_state != a->state) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = open_dev_autofs(u->manager);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (a->deserialized_state == AUTOMOUNT_WAITING ||
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek a->deserialized_state == AUTOMOUNT_RUNNING) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek r = sd_event_add_io(u->manager->event, &a->pipe_event_source, a->pipe_fd, EPOLLIN, automount_dispatch_io, u);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek (void) sd_event_source_set_description(a->pipe_event_source, "automount-io");
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering automount_set_state(a, a->deserialized_state);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic void automount_dump(Unit *u, FILE *f, const char *prefix) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek char time_string[FORMAT_TIMESPAN_MAX];
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek "%sAutomount State: %s\n"
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek "%sResult: %s\n"
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek "%sDirectoryMode: %04o\n"
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek "%sTimeoutIdleUSec: %s\n",
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek prefix, automount_state_to_string(a->state),
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek prefix, automount_result_to_string(a->result),
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek prefix, format_timespan(time_string, FORMAT_TIMESPAN_MAX, a->timeout_idle_usec, USEC_PER_SEC));
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic void automount_enter_dead(Automount *a, AutomountResult f) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek automount_set_state(a, a->result != AUTOMOUNT_SUCCESS ? AUTOMOUNT_FAILED : AUTOMOUNT_DEAD);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int open_dev_autofs(Manager *m) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek label_fix("/dev/autofs", false, false);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek m->dev_autofs_fd = open("/dev/autofs", O_CLOEXEC|O_RDONLY);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek return log_error_errno(errno, "Failed to open /dev/autofs: %m");
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (ioctl(m->dev_autofs_fd, AUTOFS_DEV_IOCTL_VERSION, ¶m) < 0) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek m->dev_autofs_fd = safe_close(m->dev_autofs_fd);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek log_debug("Autofs kernel version %i.%i", param.ver_major, param.ver_minor);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int open_ioctl_fd(int dev_autofs_fd, const char *where, dev_t devid) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek l = sizeof(struct autofs_dev_ioctl) + strlen(where) + 1;
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_OPENMOUNT, param) < 0)
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek (void) fd_cloexec(param->ioctlfd, true);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int autofs_protocol(int dev_autofs_fd, int ioctl_fd) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_PROTOVER, ¶m) < 0)
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_PROTOSUBVER, ¶m) < 0)
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek minor = param.protosubver.sub_version;
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek log_debug("Autofs protocol version %i.%i", major, minor);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int autofs_set_timeout(int dev_autofs_fd, int ioctl_fd, usec_t usec) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek /* Convert to seconds, rounding up. */
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek param.timeout.timeout = (usec + USEC_PER_SEC - 1) / USEC_PER_SEC;
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (ioctl(dev_autofs_fd, AUTOFS_DEV_IOCTL_TIMEOUT, ¶m) < 0)
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int autofs_send_ready(int dev_autofs_fd, int ioctl_fd, uint32_t token, int status) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek if (ioctl(dev_autofs_fd, status ? AUTOFS_DEV_IOCTL_FAIL : AUTOFS_DEV_IOCTL_READY, ¶m) < 0)
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int automount_send_ready(Automount *a, Set *tokens, int status) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek _cleanup_close_ int ioctl_fd = -1;
92bd5ff3a062c3f9475b9d9d39b9335bfeb7705eDavid Herrmann ioctl_fd = open_ioctl_fd(UNIT(a)->manager->dev_autofs_fd, a->where, a->dev_id);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek log_unit_debug_errno(UNIT(a), status, "Sending failure: %m");
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek log_unit_debug(UNIT(a), "Sending success.");
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek /* Autofs thankfully does not hand out 0 as a token */
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek while ((token = PTR_TO_UINT(set_steal_first(tokens)))) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek /* Autofs fun fact II:
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek * if you pass a positive status code here, the kernel will
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek * freeze! Yay! */
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek k = autofs_send_ready(UNIT(a)->manager->dev_autofs_fd,
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekstatic int automount_start_expire(Automount *a);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmekint automount_update_mount(Automount *a, MountState old_state, MountState state) {
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek automount_send_ready(a, a->tokens, 0);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek log_unit_warning_errno(UNIT(a), r, "Failed to start expiration timer, ignoring: %m");
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek automount_send_ready(a, a->tokens, -ENODEV);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek (void) sd_event_source_set_enabled(a->expire_event_source, SD_EVENT_OFF);
2b3ab29de466ae6bd7c3243a5a48c7291cc2af0aZbigniew Jędrzejewski-Szmek automount_send_ready(a, a->expire_tokens, 0);
2d62c530d2b4c2730abff715b7342f1402114513Lennart Poettering automount_send_ready(a, a->expire_tokens, -ENODEV);
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poetteringstatic void automount_enter_waiting(Automount *a) {
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering char name[sizeof("systemd-")-1 + DECIMAL_STR_MAX(pid_t) + 1];
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering char options[sizeof("fd=,pgrp=,minproto=5,maxproto=5,direct")-1
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering + DECIMAL_STR_MAX(int) + DECIMAL_STR_MAX(gid_t) + 1];
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering r = unit_fail_if_symlink(UNIT(a), a->where);
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering unit_warn_if_dir_nonempty(UNIT(a), a->where);
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering dev_autofs_fd = open_dev_autofs(UNIT(a)->manager);
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering if (pipe2(p, O_NONBLOCK|O_CLOEXEC) < 0) {
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering xsprintf(options, "fd=%i,pgrp="PID_FMT",minproto=5,maxproto=5,direct", p[1], getpgrp());
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering xsprintf(name, "systemd-"PID_FMT, getpid());
6a79c58603ea816a1b4fa1520397b4e138bc1ca0Lennart Poettering if (mount(name, a->where, "autofs", 0, options) < 0) {
mounted = true;
r = -errno;
goto fail;
if (ioctl_fd < 0) {
r = ioctl_fd;
goto fail;
goto fail;
goto fail;
r = sd_event_add_io(UNIT(a)->manager->event, &a->pipe_event_source, p[0], EPOLLIN, automount_dispatch_io, a);
goto fail;
a->pipe_fd = p[0];
fail:
safe_close_pair(p);
if (mounted)
static void *expire_thread(void *p) {
return NULL;
assert(a);
if (!data)
return log_oom();
return automount_start_expire(a);
assert(a);
if (a->timeout_idle_usec == 0)
if (a->expire_event_source) {
r = sd_event_add_time(
&a->expire_event_source,
assert(a);
goto fail;
goto fail;
fail:
assert(a);
return -EEXIST;
return -ENOENT;
assert(a);
Iterator i;
assert(a);
assert(f);
if (a->pipe_fd >= 0) {
int copy;
if (copy < 0)
return copy;
assert(a);
if (state < 0)
else if (f != AUTOMOUNT_SUCCESS)
a->result = f;
a->dev_id = (unsigned) d;
unsigned token;
log_oom();
unsigned token;
log_oom();
int fd;
assert(u);
assert(u);
assert(u);
if (!UNIT_TRIGGER(u))
assert(a);
goto fail;
goto fail;
log_unit_info(UNIT(a), "Got automount request for %s, triggered by %"PRIu32" (%s)", a->where, packet.v5_packet.pid, strna(p));
goto fail;
goto fail;
goto fail;
goto fail;
goto fail;
r = manager_add_job(UNIT(a)->manager, JOB_STOP, UNIT_TRIGGER(UNIT(a)), JOB_REPLACE, true, &error, NULL);
goto fail;
fail:
assert(m);
assert(a);
static bool automount_supported(void) {
if (supported < 0)
return supported;
.sections =
.no_alias = true,
.no_instances = true,
.finished_start_job = {
.finished_stop_job = {