On Tue, Mar 06, 2018 at 11:47:51AM -0500, John Ferlan wrote: > > > On 03/05/2018 09:43 AM, Erik Skultety wrote: > > When commit 3545cbef moved the sysfs attribute reading logic from > > _udev.c module to virmdev.c, it had to replace our udev read wrappers > > with the ones available from virfile.c. The problem is that the original > > logic worked correctly with udev read wrappers which don't return an > > error code for a missing attribute, virfile.c readers however - not so > > much. Therefore add another parameter to the macro, so we can again > > accept the fact that optional attributes may be missing. > > > > Signed-off-by: Erik Skultety <eskul...@redhat.com> > > --- > > src/util/virmdev.c | 17 +++++++++++------ > > 1 file changed, 11 insertions(+), 6 deletions(-) > > > > The virFileReadValue* API's return -2 for non existing file, so instead > of messing with errno, you should be able to > > rc = cb(); > if (rc == -2 && optional) > rc = 0; > if (rc < 0) > goto cleanup; > > As it seems to be the more common way to use the functions.
Honestly, that was my first approach, but then I told myself that rather than comparing against a "magic" value which in order to understand the caller has to go and read the function being called, so I went for the errno and I liked it more, it's standardized (you don't care what the function does and under what circumstances it returns, you just want the errno), there was less lines of code involved, I can change it if you insist, but I wanted to express my intentions first. Erik -- libvir-list mailing list firstname.lastname@example.org https://www.redhat.com/mailman/listinfo/libvir-list