chiark / gitweb /
bus: introduce "trusted" bus concept and encode access control in object vtables
[elogind.git] / src / core / device.c
index 63d0302d3b48de0367aaa1721dee8c7c5cd15618..19fc7451d8b7108d8e069f74cadeca84e4f40896 100644 (file)
@@ -23,8 +23,6 @@
 #include <sys/epoll.h>
 #include <libudev.h>
 
-#include "unit.h"
-#include "device.h"
 #include "strv.h"
 #include "log.h"
 #include "unit-name.h"
@@ -32,6 +30,9 @@
 #include "def.h"
 #include "path-util.h"
 #include "udev-util.h"
+#include "unit.h"
+#include "swap.h"
+#include "device.h"
 
 static const UnitActiveState state_translation_table[_DEVICE_STATE_MAX] = {
         [DEVICE_DEAD] = UNIT_INACTIVE,
@@ -263,6 +264,7 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
                         FOREACH_WORD_QUOTED(w, l, wants, state) {
                                 _cleanup_free_ char *n = NULL;
                                 char e[l+1];
+                                Unit *other;
 
                                 memcpy(e, w, l);
                                 e[l] = 0;
@@ -276,6 +278,15 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
                                 r = unit_add_dependency_by_name(u, UNIT_WANTS, n, NULL, true);
                                 if (r < 0)
                                         goto fail;
+
+                                other = manager_get_unit(u->manager, n);
+                                if (!other || !unit_can_start(other))
+                                        continue;
+
+                                r = manager_add_job(u->manager, JOB_START, other, JOB_REPLACE, true, NULL, NULL);
+                                if (r < 0)
+                                        log_warning("Failed to add job %s/%s, ignoring: %s.",
+                                                    other->id, job_type_to_string(JOB_START), strerror(-r));
                         }
                 }
         }
@@ -502,11 +513,6 @@ static void device_shutdown(Manager *m) {
                 m->udev_monitor = NULL;
         }
 
-        if (m->udev) {
-                udev_unref(m->udev);
-                m->udev = NULL;
-        }
-
         hashmap_free(m->devices_by_sysfs);
         m->devices_by_sysfs = NULL;
 }
@@ -518,11 +524,7 @@ static int device_enumerate(Manager *m) {
 
         assert(m);
 
-        if (!m->udev) {
-                m->udev = udev_new();
-                if (!m->udev)
-                        return -ENOMEM;
-
+        if (!m->udev_monitor) {
                 m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
                 if (!m->udev_monitor) {
                         r = -ENOMEM;
@@ -607,11 +609,20 @@ static int device_dispatch_io(sd_event_source *source, int fd, uint32_t revents,
                 r = device_process_removed_device(m, dev);
                 if (r < 0)
                         log_error("Failed to process device remove event: %s", strerror(-r));
+
+                r = swap_process_removed_device(m, dev);
+                if (r < 0)
+                        log_error("Failed to process swap device remove event: %s", strerror(-r));
+
         } else {
                 r = device_process_new_device(m, dev);
                 if (r < 0)
                         log_error("Failed to process device new event: %s", strerror(-r));
 
+                r = swap_process_new_device(m, dev);
+                if (r < 0)
+                        log_error("Failed to process swap device new event: %s", strerror(-r));
+
                 manager_dispatch_load_queue(m);
 
                 device_set_path_plugged(m, dev);