From: Martin Mares Date: Mon, 14 Sep 2015 15:43:04 +0000 (+0200) Subject: Sysfs: Read failures of optional attributes are not fatal X-Git-Tag: v3.4.0~4 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=e5bb28afa6124b26cd25506892214a5d3cb9eb60;p=pciutils.git Sysfs: Read failures of optional attributes are not fatal Ameya Palande reported that with some kernels, reads of such attributes fail on some hardware. He suggested to ignore read failures completely, but I decided to turn the errors into warnings in such cases. At least, the user will know that something fishy is going on. --- diff --git a/lib/sysfs.c b/lib/sysfs.c index a16c92a..986ecc9 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -93,21 +93,28 @@ sysfs_get_string(struct pci_dev *d, char *object, char *buf, int mandatory) struct pci_access *a = d->access; int fd, n; char namebuf[OBJNAMELEN]; + void (*warn)(char *msg, ...) = (mandatory ? a->error : a->warning); sysfs_obj_name(d, object, namebuf); fd = open(namebuf, O_RDONLY); if (fd < 0) { - if (mandatory) - a->error("Cannot open %s: %s", namebuf, strerror(errno)); + if (mandatory || errno != ENOENT) + warn("Cannot open %s: %s", namebuf, strerror(errno)); return 0; } n = read(fd, buf, OBJBUFSIZE); close(fd); if (n < 0) - a->error("Error reading %s: %s", namebuf, strerror(errno)); + { + warn("Error reading %s: %s", namebuf, strerror(errno)); + return 0; + } if (n >= OBJBUFSIZE) - a->error("Value in %s too long", namebuf); + { + warn("Value in %s too long", namebuf); + return 0; + } buf[n] = 0; return 1; }