standards/188173: O_NOFOLLOW visibility not POSIX 2008 conforming
Bruce Evans
brde at optusnet.com.au
Sun Apr 6 07:30:24 UTC 2014
On Sat, 5 Apr 2014, Jilles Tjoelker wrote:
> On Sat, Apr 05, 2014 at 11:16:07PM +0300, Konstantin Belousov wrote:
>
>> diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h
>> index 3461f8b..2691449 100644
>> --- a/sys/sys/fcntl.h
>> +++ b/sys/sys/fcntl.h
>> @@ -96,7 +96,7 @@ typedef __pid_t pid_t;
>> #define O_FSYNC 0x0080 /* synchronous writes */
>> #endif
>> #define O_SYNC 0x0080 /* POSIX synonym for O_FSYNC */
>> -#if __BSD_VISIBLE
>> +#if __POSIX_VISIBLE >= 200809
>> #define O_NOFOLLOW 0x0100 /* don't follow symlinks */
>> #endif
>> #define O_CREAT 0x0200 /* create if nonexistent */
>
> This looks good, but I went ahead and made the other new POSIX.1-2008
> things visible as well and removed redundant __BSD_VISIBLE condition
> parts:
That __BSD_VISIBLE is redundant is a bit confusing. Perhaps add or
expand a comment about this.
> Index: sys/sys/fcntl.h
> ===================================================================
> --- sys/sys/fcntl.h (revision 263842)
> +++ sys/sys/fcntl.h (working copy)
> ...
> @@ -211,7 +211,7 @@ typedef __pid_t pid_t;
> #define F_SETFD 2 /* set file descriptor flags */
> #define F_GETFL 3 /* get file status flags */
> #define F_SETFL 4 /* set file status flags */
> -#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
> +#if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
> #define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */
> #define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */
> #endif
__XSI_VISIBLE seems to be the only condition that is sometimes needed in
ifdefs together with __POSIX_VISIBLE.
Many or most of the XSI ifdefs are out of date, with lots of XSI stuff
having been moved into POSIX but the ifdefs not being updated. Fixing
this would probably give many more relatively complicated ifdefs like
the above.
The BSD vs POSIX redundancy is also in:
% capability.h:#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
% capability.h:#if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
Old XSI ifdefs in new FreeBSD code seem to be nonsense.
% signal.h:#if __BSD_VISIBLE || __POSIX_VISIBLE > 0 && __POSIX_VISIBLE <= 200112
Perhaps complicated enough to be correct.
% stat.h:#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
The above is from grepping <sys> for VISIBLE and selecting lines with || and
removing lines without BSD_VISIBLE. Many more lines have XSI || POSIX, but
not in enough files to give much chance that these are complete.
Sampling of errors and complications outside of <sys>:
./dirent.h:#if __BSD_VISIBLE || __XSI_VISIBLE
Seems to be redundant. I think BSD implies the latest version of XSI.
So this should use just XSI.
./langinfo.h:#if __BSD_VISIBLE || __XSI_VISIBLE <= 500
Need both here since 500 is not the latest XSI. Assuming 500 is correct.
./netdb.h:#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE <= 200112)
BSD together with POSIX is necessary when the POSIX test is reversed.
./setjmp.h:#if __BSD_VISIBLE || __XSI_VISIBLE >= 600
Another complicated test. Symbols are rarely removed, so such tests are rare.
% ./stdio.h:#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
% ./stdio.h:#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
% ./stdio.h:#if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506
Note: reversed test.
% ./stdio.h:#if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600
Note: reversed test. The previous reversed test may be broken, since
it is missing a check for '> 0'. Elsewhere, the test for '> 0' is
obfuscated by writing it as a boolean check for != 0 with implicit 0.
% ./stdio.h:#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
% ./stdio.h:#endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 */
% ./string.h:#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE
% ./string.h:#if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
% ./string.h:#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE
% ./string.h:#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE
% ./string.h:#if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE >= 500
% ./string.h:#if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
Redundancies are most dense in these 2 popular headers. The tests
(mainly the redundant parts) are also obfuscated by writing them in
random orders (mostly BSD first in stdio.h and BSD last in string.h).
All of the randomly ordered redundancies in stdio.h and string.h are
new with the 2008 or 2012 versions of POSIX. One in fcntl.h was old
with the 2001 version of POSIX.
Bruce
More information about the freebsd-standards
mailing list