]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: make device_set_action() take sd_device_action_t
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Feb 2022 03:31:02 +0000 (12:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Feb 2022 11:34:38 +0000 (20:34 +0900)
src/libsystemd/sd-device/device-private.c
src/libsystemd/sd-device/device-private.h

index 37eda23a5f66c40ce2dc51fc3aa9e83cc15cc13d..23f9ce97de94fa4d064a5873239c00d38610664e 100644 (file)
@@ -184,16 +184,11 @@ static int device_set_devgid(sd_device *device, const char *gid) {
         return 0;
 }
 
-static int device_set_action(sd_device *device, const char *action) {
-        sd_device_action_t a;
+int device_set_action(sd_device *device, sd_device_action_t a) {
         int r;
 
         assert(device);
-        assert(action);
-
-        a = device_action_from_string(action);
-        if (a < 0)
-                return a;
+        assert(a >= 0 && a < _SD_DEVICE_ACTION_MAX);
 
         r = device_add_property_internal(device, "ACTION", device_action_to_string(a));
         if (r < 0)
@@ -204,6 +199,19 @@ static int device_set_action(sd_device *device, const char *action) {
         return 0;
 }
 
+static int device_set_action_from_string(sd_device *device, const char *action) {
+        sd_device_action_t a;
+
+        assert(device);
+        assert(action);
+
+        a = device_action_from_string(action);
+        if (a < 0)
+                return a;
+
+        return device_set_action(device, a);
+}
+
 static int device_set_seqnum(sd_device *device, const char *str) {
         uint64_t seqnum;
         int r;
@@ -307,7 +315,7 @@ static int device_amend(sd_device *device, const char *key, const char *value) {
                 if (r < 0)
                         return log_device_debug_errno(device, r, "sd-device: Failed to set devgid to '%s': %m", value);
         } else if (streq(key, "ACTION")) {
-                r = device_set_action(device, value);
+                r = device_set_action_from_string(device, value);
                 if (r < 0)
                         return log_device_debug_errno(device, r, "sd-device: Failed to set action to '%s': %m", value);
         } else if (streq(key, "SEQNUM")) {
@@ -866,7 +874,7 @@ int device_new_from_synthetic_event(sd_device **new_device, const char *syspath,
         if (r < 0)
                 return r;
 
-        r = device_set_action(ret, action);
+        r = device_set_action_from_string(ret, action);
         if (r < 0)
                 return r;
 
index 09b2d67ab136878623762fc8ea296904b9f34ed9..11f019f88a32a81a7d58f6575e60f2cac82cb304 100644 (file)
@@ -66,6 +66,7 @@ static inline int device_read_db(sd_device *device) {
 
 int device_read_uevent_file(sd_device *device);
 
+int device_set_action(sd_device *device, sd_device_action_t a);
 sd_device_action_t device_action_from_string(const char *s) _pure_;
 const char *device_action_to_string(sd_device_action_t a) _const_;
 void dump_device_action_table(void);