[libvirt] FreeBSD and sysconf(_SC_GETPW_R_SIZE_MAX)

On FreeBSD virsh fails to enter interactive mode because vshReadlineInit fails, because virGetUserDirectory fails, because virGetUserEnt fails, because sysconf(_SC_GETPW_R_SIZE_MAX) returns -1 and sets errno to EINVAL. Is this something that gnulib should/could deal with, Eric? Or should we work around it in libvrt and fallback to PATH_MAX when sysconf(_SC_GETPW_R_SIZE_MAX) fails? Matthias

On Sun, May 15, 2011 at 07:22:46AM +0200, Matthias Bolte wrote:
On FreeBSD virsh fails to enter interactive mode because vshReadlineInit fails, because virGetUserDirectory fails, because virGetUserEnt fails, because sysconf(_SC_GETPW_R_SIZE_MAX) returns -1 and sets errno to EINVAL.
Is this something that gnulib should/could deal with, Eric?
Or should we work around it in libvrt and fallback to PATH_MAX when sysconf(_SC_GETPW_R_SIZE_MAX) fails?
Hum, I'm also seeing a number of use of sysconf for _SC_GETGR_R_SIZE_MAX which also isn't listed in my linux man page as one of the possible values, so I'm wondering how portable this actually is ... Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Sun, May 15, 2011 at 07:22:46AM +0200, Matthias Bolte wrote:
On FreeBSD virsh fails to enter interactive mode because vshReadlineInit fails, because virGetUserDirectory fails, because virGetUserEnt fails, because sysconf(_SC_GETPW_R_SIZE_MAX) returns -1 and sets errno to EINVAL.
Is this something that gnulib should/could deal with, Eric?
Or should we work around it in libvrt and fallback to PATH_MAX when sysconf(_SC_GETPW_R_SIZE_MAX) fails?
PATH_MAX isn't expected to be available on all platforms either which is one of the reasons for us removing its use. getpwnam() returns ERANGE if the allocated buffer is too small. So we should do something along the lines of size_t len = sysconf(_SC_GETPW_R_SIZE_MAX) if (len < 0) len = 1024; while (1) { ... err = getpwnam() if (err < 0) { if (errno == ERANGE) { len += 1024; continue; } } } Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On 05/16/2011 03:27 AM, Daniel P. Berrange wrote:
On Sun, May 15, 2011 at 07:22:46AM +0200, Matthias Bolte wrote:
On FreeBSD virsh fails to enter interactive mode because vshReadlineInit fails, because virGetUserDirectory fails, because virGetUserEnt fails, because sysconf(_SC_GETPW_R_SIZE_MAX) returns -1 and sets errno to EINVAL.
Is this something that gnulib should/could deal with, Eric?
sysconf() is a can of worms; no chance that gnulib will touch it any time soon.
Or should we work around it in libvrt and fallback to PATH_MAX when sysconf(_SC_GETPW_R_SIZE_MAX) fails?
PATH_MAX isn't expected to be available on all platforms either which is one of the reasons for us removing its use.
getpwnam() returns ERANGE if the allocated buffer is too small. So we should do something along the lines of
size_t len = sysconf(_SC_GETPW_R_SIZE_MAX)
Guarded by #ifdef, and defaulting to -1 if _SC_GETPW_R_SIZE_MAX is not defined (since it is a handy extension, but not present everywhere).
if (len < 0) len = 1024; while (1) { ... err = getpwnam() if (err < 0) { if (errno == ERANGE) { len += 1024;
Or len <<= 1, to avoid quadratic performance. But indeed this is the correct response. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 05/16/2011 03:03 PM, Eric Blake wrote:
getpwnam() returns ERANGE if the allocated buffer is too small. So we should do something along the lines of
size_t len = sysconf(_SC_GETPW_R_SIZE_MAX)
Guarded by #ifdef, and defaulting to -1 if _SC_GETPW_R_SIZE_MAX is not defined (since it is a handy extension, but not present everywhere).
Or not - we only use it inside #if HAVE_FUNC_GETPWNAM_R and friends; so far, all platforms that have the *_r functions also happen to have a decent set of sysconf() names where we aren't running into compilation errors by trying to use _SC_GETPW_R_SIZE_MAX.
But indeed this is the correct response.
I've posted https://www.redhat.com/archives/libvir-list/2011-May/msg01074.html -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (4)
-
Daniel P. Berrange
-
Daniel Veillard
-
Eric Blake
-
Matthias Bolte