chiark / gitweb /
core: do not spawn jobs or touch other units during coldplugging
[elogind.git] / src / core / automount.c
index bc2834334e2fa9930902ee252e157c4e15f2e1f6..0539fbbc41c1dab4da93533589b9611acc23dfde 100644 (file)
@@ -32,8 +32,6 @@
 #include "unit.h"
 #include "automount.h"
 #include "mount.h"
-#include "load-fragment.h"
-#include "load-dropin.h"
 #include "unit-name.h"
 #include "special.h"
 #include "label.h"
@@ -75,7 +73,7 @@ static void repeat_unmount(const char *path) {
                         continue;
 
                 if (errno != EINVAL)
-                        log_error("Failed to unmount: %m");
+                        log_error_errno(errno, "Failed to unmount: %m");
 
                 break;
         }
@@ -235,7 +233,7 @@ static void automount_set_state(Automount *a, AutomountState state) {
         unit_notify(UNIT(a), state_translation_table[old_state], state_translation_table[state], true);
 }
 
-static int automount_coldplug(Unit *u) {
+static int automount_coldplug(Unit *u, Hashmap *deferred_work) {
         Automount *a = AUTOMOUNT(u);
         int r;
 
@@ -300,10 +298,8 @@ static int open_dev_autofs(Manager *m) {
         label_fix("/dev/autofs", false, false);
 
         m->dev_autofs_fd = open("/dev/autofs", O_CLOEXEC|O_RDONLY);
-        if (m->dev_autofs_fd < 0) {
-                log_error("Failed to open /dev/autofs: %m");
-                return -errno;
-        }
+        if (m->dev_autofs_fd < 0)
+                return log_error_errno(errno, "Failed to open /dev/autofs: %m");
 
         init_autofs_dev_ioctl(&param);
         if (ioctl(m->dev_autofs_fd, AUTOFS_DEV_IOCTL_VERSION, &param) < 0) {
@@ -451,7 +447,9 @@ int automount_send_ready(Automount *a, int status) {
 static void automount_enter_waiting(Automount *a) {
         _cleanup_close_ int ioctl_fd = -1;
         int p[2] = { -1, -1 };
-        char name[32], options[128];
+        char name[sizeof("systemd-")-1 + DECIMAL_STR_MAX(pid_t) + 1];
+        char options[sizeof("fd=,pgrp=,minproto=5,maxproto=5,direct")-1
+                     + DECIMAL_STR_MAX(int) + DECIMAL_STR_MAX(gid_t) + 1];
         bool mounted = false;
         int r, dev_autofs_fd;
         struct stat st;
@@ -479,12 +477,8 @@ static void automount_enter_waiting(Automount *a) {
                 goto fail;
         }
 
-        snprintf(options, sizeof(options), "fd=%i,pgrp=%u,minproto=5,maxproto=5,direct", p[1], (unsigned) getpgrp());
-        char_array_0(options);
-
-        snprintf(name, sizeof(name), "systemd-%u", (unsigned) getpid());
-        char_array_0(name);
-
+        xsprintf(options, "fd=%i,pgrp="PID_FMT",minproto=5,maxproto=5,direct", p[1], getpgrp());
+        xsprintf(name, "systemd-"PID_FMT, getpid());
         if (mount(name, a->where, "autofs", 0, options) < 0) {
                 r = -errno;
                 goto fail;
@@ -605,7 +599,7 @@ static int automount_start(Unit *u) {
 
         a->result = AUTOMOUNT_SUCCESS;
         automount_enter_waiting(a);
-        return 0;
+        return 1;
 }
 
 static int automount_stop(Unit *u) {
@@ -615,7 +609,7 @@ static int automount_stop(Unit *u) {
         assert(a->state == AUTOMOUNT_WAITING || a->state == AUTOMOUNT_RUNNING);
 
         automount_enter_dead(a, AUTOMOUNT_SUCCESS);
-        return 0;
+        return 1;
 }
 
 static int automount_serialize(Unit *u, FILE *f, FDSet *fds) {
@@ -760,7 +754,7 @@ static int automount_dispatch_io(sd_event_source *s, int fd, uint32_t events, vo
 
                         get_process_comm(packet.v5_packet.pid, &p);
                         log_unit_info(UNIT(a)->id,
-                                       "Got automount request for %s, triggered by "PID_FMT" (%s)",
+                                       "Got automount request for %s, triggered by %"PRIu32" (%s)",
                                        a->where, packet.v5_packet.pid, strna(p));
                 } else
                         log_unit_debug(UNIT(a)->id, "Got direct mount request on %s", a->where);
@@ -809,6 +803,17 @@ static void automount_reset_failed(Unit *u) {
         a->result = AUTOMOUNT_SUCCESS;
 }
 
+static bool automount_supported(Manager *m) {
+        static int supported = -1;
+
+        assert(m);
+
+        if (supported < 0)
+                supported = access("/dev/autofs", F_OK) >= 0;
+
+        return supported;
+}
+
 static const char* const automount_state_table[_AUTOMOUNT_STATE_MAX] = {
         [AUTOMOUNT_DEAD] = "dead",
         [AUTOMOUNT_WAITING] = "waiting",
@@ -861,6 +866,7 @@ const UnitVTable automount_vtable = {
         .bus_vtable = bus_automount_vtable,
 
         .shutdown = automount_shutdown,
+        .supported = automount_supported,
 
         .status_message_formats = {
                 .finished_start_job = {