chiark / gitweb /
unit: use weaker dependencies between mount and device units in --user mode
[elogind.git] / src / core / device.c
index 42e3a261e2c31fdd630dda1170fb3ecf14edd096..2d983cc565f382cf37cb760583744feb60d18fc4 100644 (file)
 #include <sys/epoll.h>
 #include <libudev.h>
 
-#include "strv.h"
 #include "log.h"
 #include "unit-name.h"
 #include "dbus-device.h"
-#include "def.h"
 #include "path-util.h"
 #include "udev-util.h"
 #include "unit.h"
@@ -334,7 +332,7 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
         return 0;
 
 fail:
-        log_warning_errno(-r, "Failed to load device unit: %m");
+        log_warning_errno(r, "Failed to load device unit: %m");
 
         if (delete && u)
                 unit_free(u);
@@ -382,7 +380,7 @@ static int device_process_new_device(Manager *m, struct udev_device *dev) {
                  * same /dev/disk/by-label/xxx link because they have
                  * the same label. We want to make sure that the same
                  * device that won the symlink wins in systemd, so we
-                 * check the device node major/minor*/
+                 * check the device node major/minor */
                 if (stat(p, &st) >= 0)
                         if ((!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) ||
                             st.st_rdev != udev_device_get_devnum(dev))
@@ -628,7 +626,7 @@ static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
                 static RATELIMIT_DEFINE(limit, 10*USEC_PER_SEC, 5);
 
                 if (!ratelimit_test(&limit))
-                        log_error("Failed to get udev event: %m");
+                        log_error_errno(errno, "Failed to get udev event: %m");
                 if (!(revents & EPOLLIN))
                         return 0;
         }
@@ -650,20 +648,20 @@ static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
         if (streq(action, "remove") || !device_is_ready(dev))  {
                 r = device_process_removed_device(m, dev);
                 if (r < 0)
-                        log_error_errno(-r, "Failed to process device remove event: %m");
+                        log_error_errno(r, "Failed to process device remove event: %m");
 
                 r = swap_process_removed_device(m, dev);
                 if (r < 0)
-                        log_error_errno(-r, "Failed to process swap device remove event: %m");
+                        log_error_errno(r, "Failed to process swap device remove event: %m");
 
         } else {
                 r = device_process_new_device(m, dev);
                 if (r < 0)
-                        log_error_errno(-r, "Failed to process device new event: %m");
+                        log_error_errno(r, "Failed to process device new event: %m");
 
                 r = swap_process_new_device(m, dev);
                 if (r < 0)
-                        log_error_errno(-r, "Failed to process swap device new event: %m");
+                        log_error_errno(r, "Failed to process swap device new event: %m");
 
                 manager_dispatch_load_queue(m);
 
@@ -673,6 +671,19 @@ static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
         return 0;
 }
 
+static bool device_supported(Manager *m) {
+        static int read_only = -1;
+        assert(m);
+
+        /* If /sys is read-only we don't support device units, and any
+         * attempts to start one should fail immediately. */
+
+        if (read_only < 0)
+                read_only = path_is_read_only_fs("/sys");
+
+        return read_only <= 0;
+}
+
 static const char* const device_state_table[_DEVICE_STATE_MAX] = {
         [DEVICE_DEAD] = "dead",
         [DEVICE_PLUGGED] = "plugged"
@@ -708,6 +719,7 @@ const UnitVTable device_vtable = {
 
         .enumerate = device_enumerate,
         .shutdown = device_shutdown,
+        .supported = device_supported,
 
         .status_message_formats = {
                 .starting_stopping = {