1401
/* resolve custom link to a device and return its syspath */
1402
if (!streq(sysattr, "device")) {
1403
strscpyl(path, sizeof(path), udev_device->syspath, "/", sysattr, NULL);
1404
dev = udev_device_new_from_syspath(udev_device->udev, path);
1406
list_entry = udev_list_entry_add(&udev_device->sysattr_value_list, sysattr,
1407
udev_device_get_syspath(dev));
1408
val = udev_list_entry_get_value(list_entry);
1409
udev_device_unref(dev);
1431
* udev_device_set_sysattr_value:
1432
* @udev_device: udev device
1433
* @sysattr: attribute name
1434
* @value: new value to be set
1436
* Update the contents of the sys attribute and the cached value of the device.
1438
* Returns: Negative error code on failure or 0 on success.
1440
_public_ int udev_device_set_sysattr_value(struct udev_device *udev_device, const char *sysattr, char *value)
1442
struct udev_device *dev;
1443
char path[UTIL_PATH_SIZE];
1444
struct stat statbuf;
1446
ssize_t size, value_len;
1449
if (udev_device == NULL)
1452
if (sysattr == NULL)
1457
value_len = strlen(value);
1459
strscpyl(path, sizeof(path), udev_device_get_syspath(dev), "/", sysattr, NULL);
1460
if (lstat(path, &statbuf) != 0) {
1461
udev_list_entry_add(&dev->sysattr_value_list, sysattr, NULL);
1466
if (S_ISLNK(statbuf.st_mode)) {
1471
/* skip directories */
1472
if (S_ISDIR(statbuf.st_mode)) {
1477
/* skip non-readable files */
1478
if ((statbuf.st_mode & S_IRUSR) == 0) {
1483
/* Value is limited to 4k */
1484
if (value_len > 4096) {
1488
util_remove_trailing_chars(value, '\n');
1490
/* write attribute value */
1491
fd = open(path, O_WRONLY|O_CLOEXEC);
1496
size = write(fd, value, value_len);
1502
if (size < value_len) {
1507
/* wrote a valid value, store it in cache and return it */
1508
udev_list_entry_add(&dev->sysattr_value_list, sysattr, value);
1510
if (dev != udev_device)
1511
udev_device_unref(dev);
1443
1515
static int udev_device_sysattr_list_read(struct udev_device *udev_device)
1445
1517
struct dirent *dent;