chiark / gitweb /
sd-device: fix return codes on error
[elogind.git] / src / libelogind / sd-device / device-private.c
index f6beef84949bb6bbd406240e6670c81e308578b7..3cadedbf4a6e513ee106b7988e865c2ff23489ae 100644 (file)
@@ -366,7 +366,7 @@ static int device_set_devgid(sd_device *device, const char *gid) {
         return 0;
 }
 
-static int device_ammend(sd_device *device, const char *key, const char *value) {
+static int device_amend(sd_device *device, const char *key, const char *value) {
         int r;
 
         assert(device);
@@ -423,9 +423,10 @@ static int device_ammend(sd_device *device, const char *key, const char *value)
                 size_t l;
 
                 FOREACH_WORD(word, l, value, state) {
-                        char *devlink;
+                        char devlink[l + 1];
 
-                        devlink = strndupa(word, l);
+                        strncpy(devlink, word, l);
+                        devlink[l] = '\0';
 
                         r = device_add_devlink(device, devlink);
                         if (r < 0)
@@ -436,9 +437,10 @@ static int device_ammend(sd_device *device, const char *key, const char *value)
                 size_t l;
 
                 FOREACH_WORD_SEPARATOR(word, l, value, ":", state) {
-                        char *tag;
+                        char tag[l + 1];
 
-                        tag = strndupa(word, l);
+                        (void)strncpy(tag, word, l);
+                        tag[l] = '\0';
 
                         r = device_add_tag(device, tag);
                         if (r < 0)
@@ -507,7 +509,7 @@ static int device_append(sd_device *device, char *key, const char **_major, cons
                                 return -EINVAL;
                 }
 
-                r = device_ammend(device, key, value);
+                r = device_amend(device, key, value);
                 if (r < 0)
                         return r;
         }
@@ -641,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;
 
@@ -677,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;
@@ -1097,3 +1100,9 @@ int device_delete_db(sd_device *device) {
 
         return 0;
 }
+
+int device_read_db_force(sd_device *device) {
+        assert(device);
+
+        return device_read_db_aux(device, true);
+}