chiark / gitweb /
core: add bus API and systemctl commands for altering cgroup parameters during runtime
[elogind.git] / src / core / device.c
index 88ce0cdd18719174de07cbe502152cdb7ae87421..0b01718ad4bc0ada8f79aa56f51b201319ba6c89 100644 (file)
@@ -30,6 +30,7 @@
 #include "unit-name.h"
 #include "dbus-device.h"
 #include "def.h"
+#include "path-util.h"
 
 static const UnitActiveState state_translation_table[_DEVICE_STATE_MAX] = {
         [DEVICE_DEAD] = UNIT_INACTIVE,
@@ -91,10 +92,10 @@ static void device_set_state(Device *d, DeviceState state) {
         d->state = state;
 
         if (state != old_state)
-                log_debug("%s changed %s -> %s",
-                          UNIT(d)->id,
-                          device_state_to_string(old_state),
-                          device_state_to_string(state));
+                log_debug_unit(UNIT(d)->id,
+                               "%s changed %s -> %s", UNIT(d)->id,
+                               device_state_to_string(old_state),
+                               device_state_to_string(state));
 
         unit_notify(UNIT(d), state_translation_table[old_state], state_translation_table[state], true);
 }
@@ -143,7 +144,8 @@ static int device_add_escaped_name(Unit *u, const char *dn) {
         assert(dn);
         assert(dn[0] == '/');
 
-        if (!(e = unit_name_from_path(dn, ".device")))
+        e = unit_name_from_path(dn, ".device");
+        if (!e)
                 return -ENOMEM;
 
         r = unit_add_name(u, e);
@@ -164,7 +166,8 @@ static int device_find_escape_name(Manager *m, const char *dn, Unit **_u) {
         assert(dn[0] == '/');
         assert(_u);
 
-        if (!(e = unit_name_from_path(dn, ".device")))
+        e = unit_name_from_path(dn, ".device");
+        if (!e)
                 return -ENOMEM;
 
         u = manager_get_unit(m, e);
@@ -248,30 +251,46 @@ static int device_update_unit(Manager *m, struct udev_device *dev, const char *p
                  * interpret for the main object */
                 const char *wants, *alias;
 
-                if ((alias = udev_device_get_property_value(dev, "SYSTEMD_ALIAS"))) {
-                        if (!is_path(alias))
-                                log_warning("SYSTEMD_ALIAS for %s is not a path, ignoring: %s", sysfs, alias);
-                        else {
-                                if ((r = device_add_escaped_name(u, alias)) < 0)
+                alias = udev_device_get_property_value(dev, "SYSTEMD_ALIAS");
+                if (alias) {
+                        char *state, *w;
+                        size_t l;
+
+                        FOREACH_WORD_QUOTED(w, l, alias, state) {
+                                char *e;
+
+                                e = strndup(w, l);
+                                if (!e) {
+                                        r = -ENOMEM;
                                         goto fail;
+                                }
+
+                                if (!is_path(e)) {
+                                        log_warning("SYSTEMD_ALIAS for %s is not a path, ignoring: %s", sysfs, e);
+                                        free(e);
+                                } else {
+                                        device_update_unit(m, dev, e, false);
+                                        free(e);
+                                }
                         }
                 }
 
-                if ((wants = udev_device_get_property_value(dev, "SYSTEMD_WANTS"))) {
+                wants = udev_device_get_property_value(dev, "SYSTEMD_WANTS");
+                if (wants) {
                         char *state, *w;
                         size_t l;
 
                         FOREACH_WORD_QUOTED(w, l, wants, state) {
                                 char *e;
 
-                                if (!(e = strndup(w, l))) {
+                                e = strndup(w, l);
+                                if (!e) {
                                         r = -ENOMEM;
                                         goto fail;
                                 }
 
                                 r = unit_add_dependency_by_name(u, UNIT_WANTS, e, NULL, true);
                                 free(e);
-
                                 if (r < 0)
                                         goto fail;
                         }
@@ -584,7 +603,6 @@ static const char* const device_state_table[_DEVICE_STATE_MAX] = {
 DEFINE_STRING_TABLE_LOOKUP(device_state, DeviceState);
 
 const UnitVTable device_vtable = {
-        .suffix = ".device",
         .object_size = sizeof(Device),
         .sections =
                 "Unit\0"
@@ -612,5 +630,15 @@ const UnitVTable device_vtable = {
         .following_set = device_following_set,
 
         .enumerate = device_enumerate,
-        .shutdown = device_shutdown
+        .shutdown = device_shutdown,
+
+        .status_message_formats = {
+                .starting_stopping = {
+                        [0] = "Expecting device %s...",
+                },
+                .finished_start_job = {
+                        [JOB_DONE]       = "Found device %s.",
+                        [JOB_TIMEOUT]    = "Timed out waiting for device %s.",
+                },
+        },
 };