]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-device: shorten code a bit
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 17 Apr 2022 05:29:07 +0000 (14:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 17 Apr 2022 19:34:14 +0000 (04:34 +0900)
src/libsystemd/sd-device/device-private.c

index b6043848eaeba9aab55864c3055da7ed1f35acee..6fa70a8fd399142e867b19f42f1e70f80288e02d 100644 (file)
@@ -933,15 +933,11 @@ static int device_tag(sd_device *device, const char *tag, bool add) {
 
         path = strjoina("/run/udev/tags/", tag, "/", id);
 
-        if (add) {
-                r = touch_file(path, true, USEC_INFINITY, UID_INVALID, GID_INVALID, 0444);
-                if (r < 0)
-                        return r;
-        } else {
-                r = unlink(path);
-                if (r < 0 && errno != ENOENT)
-                        return -errno;
-        }
+        if (add)
+                return touch_file(path, true, USEC_INFINITY, UID_INVALID, GID_INVALID, 0444);
+
+        if (unlink(path) < 0 && errno != ENOENT)
+                return -errno;
 
         return 0;
 }
@@ -950,16 +946,14 @@ int device_tag_index(sd_device *device, sd_device *device_old, bool add) {
         const char *tag;
         int r = 0, k;
 
-        if (add && device_old) {
+        if (add && device_old)
                 /* delete possible left-over tags */
-                FOREACH_DEVICE_TAG(device_old, tag) {
+                FOREACH_DEVICE_TAG(device_old, tag)
                         if (!sd_device_has_tag(device, tag)) {
                                 k = device_tag(device_old, tag, false);
                                 if (r >= 0 && k < 0)
                                         r = k;
                         }
-                }
-        }
 
         FOREACH_DEVICE_TAG(device, tag) {
                 k = device_tag(device, tag, add);
@@ -1017,8 +1011,7 @@ int device_update_db(sd_device *device) {
 
         /* do not store anything for otherwise empty devices */
         if (!has_info && major(device->devnum) == 0 && device->ifindex == 0) {
-                r = unlink(path);
-                if (r < 0 && errno != ENOENT)
+                if (unlink(path) < 0 && errno != ENOENT)
                         return -errno;
 
                 return 0;
@@ -1106,8 +1099,7 @@ int device_delete_db(sd_device *device) {
 
         path = strjoina("/run/udev/data/", id);
 
-        r = unlink(path);
-        if (r < 0 && errno != ENOENT)
+        if (unlink(path) < 0 && errno != ENOENT)
                 return -errno;
 
         return 0;