chiark / gitweb /
sd-device: allow uevent files to be write-only
[elogind.git] / src / libelogind / sd-device / sd-device.c
index 0dd0e14eef929283b67345cb201e0c3b5b72f23b..7d52e3cc1d0f052f3d92de3fd9d0af7bae57363a 100644 (file)
@@ -499,7 +499,10 @@ int device_read_uevent_file(sd_device *device) {
         path = strjoina(syspath, "/uevent");
 
         r = read_full_file(path, &uevent, &uevent_len);
-        if (r < 0) {
+        if (r == -EACCES)
+                /* empty uevent files may be write-only */
+                return 0;
+        else if (r < 0) {
                 log_debug("sd-device: failed to read uevent file '%s': %s", path, strerror(-r));
                 return r;
         }
@@ -1781,8 +1784,8 @@ _public_ int sd_device_set_sysattr_value(sd_device *device, const char *sysattr,
         value_len = strlen(_value);
 
         /* drop trailing newlines */
-        while (value_len > 0 && _value[--value_len] == '\n')
-                _value[value_len] = '\0';
+        while (value_len > 0 && _value[value_len - 1] == '\n')
+                _value[--value_len] = '\0';
 
         /* value length is limited to 4k */
         if (value_len > 4096)