Bug 80293 - sysconf() does not support well-defined unistd values
Summary: sysconf() does not support well-defined unistd values
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: standards (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-standards (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-23 23:20 UTC by Bill Middleton
Modified: 2018-05-28 19:40 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Middleton 2005-04-23 23:20:17 UTC
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));
}
Comment 1 Craig Rodrigues freebsd_committer freebsd_triage 2005-08-31 03:38:17 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-standards

sysconf() is not a kernel function, moving this to standards
Comment 2 Craig Rodrigues freebsd_committer freebsd_triage 2005-09-02 18:53:02 UTC
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().
Comment 3 Stanislav Sedov freebsd_committer freebsd_triage 2007-02-23 15:08:31 UTC
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
Comment 4 Jung-uk Kim freebsd_committer freebsd_triage 2007-04-11 19:52:17 UTC
> 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
Comment 5 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:40:38 UTC
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.