[systemd-commits] 2 commits - src/libsystemd

Tom Gundersen tomegun at kemper.freedesktop.org
Fri Apr 3 13:23:45 PDT 2015


 src/libsystemd/sd-device/device-private.c |   41 ++++++++++++++----------------
 1 file changed, 20 insertions(+), 21 deletions(-)

New commits:
commit 4df4fd1127df4b70f78d952a37a51a8c69e3243f
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Apr 3 21:04:48 2015 +0200

    sd-device: fix deserialization from netlink
    
    Use the standard FOREACH_WORD* macros.
    
    The current code was broken in the devlink case so the last one received
    was being dropped, causing https://bugs.freedesktop.org/show_bug.cgi?id=89894

diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index 2add6bb..544b837 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -419,32 +419,30 @@ static int device_ammend(sd_device *device, const char *key, const char *value)
                 if (r < 0)
                         return log_debug_errno(r, "sd-device: could not set devgid to '%s': %m", value);
         } else if (streq(key, "DEVLINKS")) {
-                char *devlinks, *next;
+                const char *word, *state;
+                size_t l;
 
-                devlinks = strdupa(value);
+                FOREACH_WORD(word, l, value, state) {
+                        char *devlink;
 
-                while ((next = strchr(devlinks, ' '))) {
-                        next[0] = '\0';
+                        devlink = strndupa(word, l);
 
-                        r = device_add_devlink(device, devlinks);
+                        r = device_add_devlink(device, devlink);
                         if (r < 0)
-                                return log_debug_errno(r, "sd-device: could not add devlink '%s': %m", devlinks);
-
-                        devlinks = next + 1;
+                                return log_debug_errno(r, "sd-device: could not add devlink '%s': %m", devlink);
                 }
         } else if (streq(key, "TAGS")) {
-                char *tags, *next;
+                const char *word, *state;
+                size_t l;
 
-                tags = strdupa(value);
+                FOREACH_WORD_SEPARATOR(word, l, value, ":", state) {
+                        char *tag;
 
-                while ((next = strchr(tags, ':'))) {
-                        next[0] = '\0';
+                        tag = strndupa(word, l);
 
-                        r = device_add_tag(device, tags);
+                        r = device_add_tag(device, tag);
                         if (r < 0)
-                                return log_debug_errno(r, "sd-device: could not add tag '%s': %m", tags);
-
-                        tags = next + 1;
+                                return log_debug_errno(r, "sd-device: could not add tag '%s': %m", tag);
                 }
         } else {
                 r = device_add_property_internal(device, key, value);

commit aa20f49a1c5816e6e7e97f2e2ba209be47f3c0a3
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Apr 3 21:05:42 2015 +0200

    sd-device: get_properties_{nulstr,strv} - don't recreate the buffer unnecessarily

diff --git a/src/libsystemd/sd-device/device-private.c b/src/libsystemd/sd-device/device-private.c
index 81b0b6d..2add6bb 100644
--- a/src/libsystemd/sd-device/device-private.c
+++ b/src/libsystemd/sd-device/device-private.c
@@ -643,6 +643,9 @@ static int device_update_properties_bufs(sd_device *device) {
 
         assert(device);
 
+        if (!device->properties_buf_outdated)
+                return 0;
+
         FOREACH_DEVICE_PROPERTY(device, prop, val) {
                 size_t len = 0;
 
@@ -679,11 +682,9 @@ int device_get_properties_nulstr(sd_device *device, const uint8_t **nulstr, size
         assert(nulstr);
         assert(len);
 
-        if (device->properties_buf_outdated) {
-                r = device_update_properties_bufs(device);
-                if (r < 0)
-                        return r;
-        }
+        r = device_update_properties_bufs(device);
+        if (r < 0)
+                return r;
 
         *nulstr = device->properties_nulstr;
         *len = device->properties_nulstr_len;



More information about the systemd-commits mailing list