Calling sysconf() on an defined value, including _SC_GETGR_R_SIZE_MAX, is supposed to return -1 and not set errno(), if I understand the man page correctly. However, in CURRENT, errno is set to "Invalid argument", even though the value is defined in unistd.h. Fix: Make sysconf() support all values defined in unistd.h, or don't define them, perhaps. How-To-Repeat: The following C snippet will print: Errno is currently Unknown error: 0 _SC_GETGR_R_SIZE_MAX is Errno is now Invalid argument Arguably, errno should not have been set? #include <unistd.h> #include <sys/errno.h> int main(int argc, char **argv) { long fbufsize; printf("Errno is currently %s\n", strerror(errno)); printf("_SC_GETGR_R_SIZE_MAX is %l\n",_SC_GETGR_R_SIZE_MAX); fbufsize = sysconf (_SC_GETGR_R_SIZE_MAX); printf("Errno is now %s\n", strerror(errno)); }
Responsible Changed From-To: freebsd-bugs->freebsd-standards sysconf() is not a kernel function, moving this to standards
State Changed From-To: open->analyzed Whether or not a constant is defined in <unistd.h> is not relevant to whether sysconf() accepts it or not (unfortunately). The list of constants supported by sysconf() are handled in /usr/src/lib/libc/gen/sysconf.c Any constant which is not handled there will return a -1, and set errno to EINVAL, which is legal behavior with respect to the Single Unix Specification. For _SC_GETGR_R_SIZE_MAX, it is difficult to return a single value, because in the file where this implemented ( /usr/src/lib/libc/gen/getgrgent.c ), the getgr*_r functions are delegated down to _nsdispatch().
We could probably return GRP_STORAGE_MAX as the limit value (1Mb currently). Non-threaded versions of these functions is limited by this value anyway. -- Stanislav Sedov ST4096-RIPE
> We could probably return GRP_STORAGE_MAX as the limit value (1Mb > currently). Non-threaded versions of these functions is limited by > this value anyway. _SC_GETGR_R_SIZE_MAX is specifically for threaded versions and we should not use non-threaded version's limit. Interestingly, Mac OS 10.4 returns -1 without changing errno, which means it is unlimited. (FYI, Mac OS 10.3 used to return -1 with errno EINVAL.) NetBSD returns 1024 (which is arbitrary number chosen to shut up ports, I believe). SUSv3 says: 'If name is an invalid value, sysconf() shall return -1 and set errno to indicate the error. If the variable corresponding to name has no limit, sysconf() shall return -1 without changing the value of errno. Note that indefinite limits do not imply infinite limits; see <limits.h>.' Unfortunately FreeBSD falls under indefinite category and SUSv3 is not clear on this although it says indefinite does not imply infinite. :-( I am wondering how Mac OS 10.4 can claim that it is infinite. Jung-uk Kim
batch change: For bugs that match the following - Status Is In progress AND - Untouched since 2018-01-01. AND - Affects Base System OR Documentation DO: Reset to open status. Note: I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.