|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] libxl: Be more careful with error handling in libxl__dm_runas_helper()
On 11/27/2015 04:40 AM, Ian Campbell wrote: On Thu, 2015-11-26 at 17:45 +0000, Ian Jackson wrote: So this appears to be common with Linux implementation(s) and therefore is what we should use as indication of "non-success". After that I think we can state that the entry was not found (bit not a "real" error occurred) if (!ret || (ret==ENOENT) || (ret==ESRCH) || (errno==ENOENT) || (errno==ESRCH)) based on this statement from man pages' NOTES:The formulation given above under "RETURN VALUE" is from POSIX.1-2001. It does not call "not found" an error, and hence does not specify what value errno might have in this situation. But that makes it impossible to recognize errors. One might argue that according to POSIX errno should
be left unchanged if an entry is not found.
(followed by what IanC quotes below --- something that I missed during
my first reading)
To answer the question asked earlier in this thread --- the two systems I tested this on are
Fedora 18 and 20.
This piece of code:
errno = 0;
s = getpwnam_r(argv[1], &pwd, buf, bufsize, &result);
printf("s = %d errno = %d result = %p\n", s, errno, result);
if (result == NULL) {
if (s == 0)
printf("Not found\n");
else {
errno = s;
perror("getpwnam_r");
}
exit(EXIT_FAILURE);
}
results in:
root@haswell> cat /etc/redhat-release
Fedora release 18 (Spherical Cow)
root@haswell> ./a.out foobar
s = 0 errno = 0 result = (nil)
Not found
root@haswell>
and
root@orochi-c> cat /etc/redhat-release
Fedora release 20 (Heisenbug)
root@orochi-c> ./a.out foobar
s = 2 errno = 2 result = (nil)
getpwnam_r: No such file or directory
root@orochi-c>
which does look like a bug in F20 since the code above is taken from man
pages' EXAMPLE and doesn't look like it works as intended (which was to
produce "Not found" string)
-boris I also just realised (long after everyone else, apparently) that this function returns (+ve) Exxx values, not -1 and setting errno. Together with combining getpwnam and getpwnam_r in the same doc it's almost like someone was wilfully trying to make this function difficult to figure out... _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |