[1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-05-13 Thread Austin Group Bug Tracker


The following issue has a resolution that has been APPLIED. 
== 
https://austingroupbugs.net/view.php?id=1318 
== 
Reported By:nate_karstens
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1318
Category:   System Interfaces
Type:   Enhancement Request
Severity:   Comment
Priority:   normal
Status: Applied
Name:   Nate Karstens 
Organization:   Garmin 
User Reference:  
Section:fcntl, open, socket 
Page Number:Unknown 
Line Number:Unknown 
Interp Status:  --- 
Final Accepted Text:https://austingroupbugs.net/view.php?id=1318#c4797 
Resolution: Accepted As Marked
Fixed in Version:   
== 
Date Submitted: 2020-01-12 10:50 UTC
Last Modified:  2020-05-13 15:31 UTC
== 
Summary:Define close-on-fork flag
==
Relationships   ID  Summary
--
related to  411 adding atomic FD_CLOEXEC support
related to  0001337 Clarify socket option values after acce...
related to  0001317 Require fork handlers to be called in c...
== 

Issue History 
Date ModifiedUsername   FieldChange   
== 
2020-01-12 10:50 nate_karstens  New Issue
2020-01-12 10:50 nate_karstens  Name  => Nate Karstens   
2020-01-12 10:50 nate_karstens  Organization  => Garmin  
2020-01-12 10:50 nate_karstens  Section   => fcntl, open, socket
2020-01-12 10:50 nate_karstens  Page Number   => Unknown 
2020-01-12 10:50 nate_karstens  Line Number   => Unknown 
2020-01-13 07:28 kreNote Added: 0004725  
2020-01-13 16:37 eblake Relationship added   related to 411  
2020-01-13 16:38 eblake Note Added: 0004728  
2020-03-05 17:30 eblake Relationship added   related to 0001317  
2020-03-16 16:24 geoffclare Note Added: 0004797  
2020-03-16 16:31 geoffclare Note Edited: 0004797 
2020-03-16 16:33 geoffclare Interp Status => --- 
2020-03-16 16:33 geoffclare Final Accepted Text   =>
https://austingroupbugs.net/view.php?id=1318#c4797
2020-03-16 16:33 geoffclare Status   New => Resolved 
2020-03-16 16:33 geoffclare Resolution   Open => Accepted As
Marked
2020-03-16 16:33 geoffclare Tag Attached: issue8 
2020-03-19 15:21 geoffclare Note Edited: 0004797 
2020-03-26 15:29 geoffclare Note Edited: 0004797 
2020-03-26 15:30 geoffclare Note Edited: 0004797 
2020-03-26 15:32 geoffclare Note Added: 0004802  
2020-04-29 17:43 eblake Relationship added   related to 0001337  
2020-05-13 15:31 geoffclare Status   Resolved => Applied 
==




[1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-03-26 Thread Austin Group Bug Tracker


A NOTE has been added to this issue. 
== 
https://austingroupbugs.net/view.php?id=1318 
== 
Reported By:nate_karstens
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1318
Category:   System Interfaces
Type:   Enhancement Request
Severity:   Comment
Priority:   normal
Status: Resolved
Name:   Nate Karstens 
Organization:   Garmin 
User Reference:  
Section:fcntl, open, socket 
Page Number:Unknown 
Line Number:Unknown 
Interp Status:  --- 
Final Accepted Text:https://austingroupbugs.net/view.php?id=1318#c4797 
Resolution: Accepted As Marked
Fixed in Version:   
== 
Date Submitted: 2020-01-12 10:50 UTC
Last Modified:  2020-03-26 15:32 UTC
== 
Summary:Define close-on-fork flag
==
Relationships   ID  Summary
--
related to  411 adding atomic FD_CLOEXEC support
related to  0001317 Require fork handlers to be called in c...
== 

-- 
 (0004802) geoffclare (manager) - 2020-03-26 15:32
 https://austingroupbugs.net/view.php?id=1318#c4802 
-- 
In the March 26, 2020 teleconference
https://austingroupbugs.net/view.php?id=1318#c4797 was updated with further
changes for accept(). 

Issue History 
Date ModifiedUsername   FieldChange   
== 
2020-01-12 10:50 nate_karstens  New Issue
2020-01-12 10:50 nate_karstens  Name  => Nate Karstens   
2020-01-12 10:50 nate_karstens  Organization  => Garmin  
2020-01-12 10:50 nate_karstens  Section   => fcntl, open, socket
2020-01-12 10:50 nate_karstens  Page Number   => Unknown 
2020-01-12 10:50 nate_karstens  Line Number   => Unknown 
2020-01-13 07:28 kreNote Added: 0004725  
2020-01-13 16:37 eblake Relationship added   related to 411  
2020-01-13 16:38 eblake Note Added: 0004728  
2020-03-05 17:30 eblake Relationship added   related to 0001317  
2020-03-16 16:24 geoffclare Note Added: 0004797  
2020-03-16 16:31 geoffclare Note Edited: 0004797 
2020-03-16 16:33 geoffclare Interp Status => --- 
2020-03-16 16:33 geoffclare Final Accepted Text   =>
https://austingroupbugs.net/view.php?id=1318#c4797
2020-03-16 16:33 geoffclare Status   New => Resolved 
2020-03-16 16:33 geoffclare Resolution   Open => Accepted As
Marked
2020-03-16 16:33 geoffclare Tag Attached: issue8 
2020-03-19 15:21 geoffclare Note Edited: 0004797 
2020-03-26 15:29 geoffclare Note Edited: 0004797 
2020-03-26 15:30 geoffclare Note Edited: 0004797 
2020-03-26 15:32 geoffclare Note Added: 0004802  
==




Re: [1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-03-17 Thread Geoff Clare
casper@oracle.com  wrote, on 17 Mar 2020:
>
> It seems that this bug changes the following commands about a "wf" or "rf" 
> option for popen(); however, I do not see the additional changes needed 
> for fopen().

It doesn't make any requirement for popen() to support "wf", it just
encourages (in non-normative text) implementations to add it.  It was
done this way because it's invention.

Applications can easily arrange for FD_CLOFORK to be set on a stream by
using open() with O_CLOFORK and then fdopen(), instead of using fopen().
Doing the equivalent of popen() "wf" with lower-level calls is much harder.
So we thought encouraging fopen() "wf" was not justified, but for popen()
it is.  Of course, implementations that add "wf" for popen() may want to
add it to fopen() for consistency (and maybe also "rf" there, but a
proper "rf" for popen() is very hard to implement).  Maybe for Issue 9
there will be enough existing practice to standardise some of this.

> Another question I have is this: in fdopen(), Solaris will NOT change the 
> file flags even when "e" is given; this makes sense, I think.

The resolution of bug 411 currently requires fdopen() with "e" to set
FD_CLOEXEC.  (Without "e" it is required not to change it.)

If specifying "e" does nothing, then there's no point requiring fdopen()
to accept "e".

> 
> So we ignore "e" on fdopen and would do the same for "f"; and I'm assuming 
> that the future standard will  include "f" as the "open the file with 
> O_CLOFORK" for fopen() and ilk?

We have no plans to require anything to do with "f" flags in Issue 8.
As I said above, they may be candidates for standardising in Issue 9,
but that will depend on what implementations do.

-- 
Geoff Clare 
The Open Group, Apex Plaza, Forbury Road, Reading, RG1 1AX, England



Re: [1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-03-17 Thread Casper . Dik



It seems that this bug changes the following commands about a "wf" or "rf" 
option for popen(); however, I do not see the additional changes needed 
for fopen().

Another question I have is this: in fdopen(), Solaris will NOT change the 
file flags even when "e" is given; this makes sense, I think.

So we ignore "e" on fdopen and would do the same for "f"; and I'm assuming 
that the future standard will  include "f" as the "open the file with 
O_CLOFORK" for fopen() and ilk?

Casper



On page 1439 line 47807 section popen(), after the bug 411 text:

... any application worried about the potential file descriptor leak will 
already be using the e modifier.

add a new paragraph:

Implementations are encouraged to add support for a "wf" mode which creates 
the pipe as if by calling pipe2() with the O_CLOFORK flag and then clearing 
FD_CLOFORK for the read side of the pipe. This prevents the write side from 
leaking into child processes created by other threads, ensuring the child 
created by popen() will get end-of-file when the parent closes the write side 
(although the read side can still be leaked). Unfortunately there is no way 
(short of temporarily preventing other threads from creating child processes, 
or implementing an atomic create-pipe-and-fork system call) to implement an 
"rf" mode with the equivalent guarantee that the child created by popen() will 
be the only writer. Therefore multi-threaded applications that do not have 
complete control over process creation cannot rely on getting end-of-file on 
the stream and need to use an alternative method of indicating the end of 
communications.



[1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-03-16 Thread Austin Group Bug Tracker


The following issue has been RESOLVED. 
== 
https://austingroupbugs.net/view.php?id=1318 
== 
Reported By:nate_karstens
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1318
Category:   System Interfaces
Type:   Enhancement Request
Severity:   Comment
Priority:   normal
Status: Resolved
Name:   Nate Karstens 
Organization:   Garmin 
User Reference:  
Section:fcntl, open, socket 
Page Number:Unknown 
Line Number:Unknown 
Interp Status:  --- 
Final Accepted Text:https://austingroupbugs.net/view.php?id=1318#c4797 
Resolution: Accepted As Marked
Fixed in Version:   
== 
Date Submitted: 2020-01-12 10:50 UTC
Last Modified:  2020-03-16 16:33 UTC
== 
Summary:Define close-on-fork flag
==
Relationships   ID  Summary
--
related to  411 adding atomic FD_CLOEXEC support
related to  0001317 Require fork handlers to be called in c...
== 

Issue History 
Date ModifiedUsername   FieldChange   
== 
2020-01-12 10:50 nate_karstens  New Issue
2020-01-12 10:50 nate_karstens  Name  => Nate Karstens   
2020-01-12 10:50 nate_karstens  Organization  => Garmin  
2020-01-12 10:50 nate_karstens  Section   => fcntl, open, socket
2020-01-12 10:50 nate_karstens  Page Number   => Unknown 
2020-01-12 10:50 nate_karstens  Line Number   => Unknown 
2020-01-13 07:28 kreNote Added: 0004725  
2020-01-13 16:37 eblake Relationship added   related to 411  
2020-01-13 16:38 eblake Note Added: 0004728  
2020-03-05 17:30 eblake Relationship added   related to 0001317  
2020-03-16 16:24 geoffclare Note Added: 0004797  
2020-03-16 16:31 geoffclare Note Edited: 0004797 
2020-03-16 16:33 geoffclare Interp Status => --- 
2020-03-16 16:33 geoffclare Final Accepted Text   =>
https://austingroupbugs.net/view.php?id=1318#c4797
2020-03-16 16:33 geoffclare Status   New => Resolved 
2020-03-16 16:33 geoffclare Resolution   Open => Accepted As
Marked
==




[1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-03-16 Thread Austin Group Bug Tracker


A NOTE has been added to this issue. 
== 
https://austingroupbugs.net/view.php?id=1318 
== 
Reported By:nate_karstens
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1318
Category:   System Interfaces
Type:   Enhancement Request
Severity:   Comment
Priority:   normal
Status: New
Name:   Nate Karstens 
Organization:   Garmin 
User Reference:  
Section:fcntl, open, socket 
Page Number:Unknown 
Line Number:Unknown 
Interp Status:  --- 
Final Accepted Text: 
== 
Date Submitted: 2020-01-12 10:50 UTC
Last Modified:  2020-03-16 16:24 UTC
== 
Summary:Define close-on-fork flag
==
Relationships   ID  Summary
--
related to  411 adding atomic FD_CLOEXEC support
related to  0001317 Require fork handlers to be called in c...
== 

-- 
 (0004797) geoffclare (manager) - 2020-03-16 16:24
 https://austingroupbugs.net/view.php?id=1318#c4797 
-- 
On page 238 line 8018 section , change:The
 header shall define the following symbolic constant used
for the fcntl() file descriptor flags, which shall be suitable for
use in #if preprocessing directives.

FD_CLOEXECClose the file descriptor upon execution of an
exec family function.to:The
 header shall define the following symbolic constants used
for the fcntl() file descriptor flags. The values shall be
bitwise-distinct and shall be suitable for use in #if preprocessing
directives.

FD_CLOEXECClose the file descriptor upon successful execution
of an exec family function [SPN]and in the new process image created
by posix_spawn() or posix_spawnp()[/SPN].

FD_CLOFORKClose the file descriptor in any child process
created from a process that has the file descriptor open; that is, the
child shall not inherit the file descriptor.
On page 238 line 8032 section ,
change:O_CLOEXECThe FD_CLOEXEC flag associated with
the new descriptor shall be set to close the file descriptor upon execution
of an exec family
function.to:O_CLOEXECAtomically
set the FD_CLOEXEC flag on the new file descriptor.

O_CLOFORKAtomically set the FD_CLOFORK flag on the new file
descriptor.
On page 387 line 13167 section , after the bug 411
text:SOCK_CLOEXECCreate a socket file descriptor
with the FD_CLOEXEC flag atomically set on that file
descriptor.add:SOCK_CLOFORKCreate
a socket file descriptor with the FD_CLOFORK flag atomically set on that
file descriptor.
On page 388 line 13195 section , after the bug 411
text:MSG_CMSG_CLOEXECAtomically set the FD_CLOEXEC
flag on any file descriptors created via SCM_RIGHTS during
recvmsg().add:MSG_CMSG_CLOFORKAtomically
set the FD_CLOFORK flag on any file descriptors created via SCM_RIGHTS
during recvmsg().
On page 497 line 17263 section 2.5.1, change:A file descriptor
is closed by close(), _exit(), or the exec functions
when FD_CLOEXEC is set on that file
descriptor.to:Several functions close file
descriptors, including close(), dup2(), _exit(), the
exec functions when FD_CLOEXEC is set on a file descriptor,
fork() when FD_CLOFORK is set on a file descriptor, and
posix_spawn() when either FD_CLOEXEC or FD_CLOFORK is
set.
On page 568 line 19882 section accept(), after the bug 411
text:SOCK_CLOEXECAtomically set the FD_CLOEXEC flag
on the new file
descriptor.add:SOCK_CLOFORKAtomically
set the FD_CLOFORK flag on the new file
descriptor.
On page 569 line 19914 section accept(), after applying bug 411
change:The SOCK_CLOEXEC flag of accept4() is necessary
to avoid a data race in multi-threaded applications. Without it, a file
descriptor is leaked into a child process created by one thread in the
window between another thread creating a file descriptor with
accept() and then using fcntl() to set the FD_CLOEXEC
flag.to:The SOCK_CLOEXEC and SOCK_CLOFORK flags of
accept4() are necessary to avoid a data race in multi-threaded
applications. Without SOCK_CLOFORK, a file descriptor is leaked into a
child process created by one thread in the window between another thread
creating a file descriptor with accept() and then using
fcntl() to set the FD_CLOFORK flag.  Without 

[1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-03-05 Thread Austin Group Bug Tracker


The following issue has been set as RELATED TO issue 0001317. 
== 
https://austingroupbugs.net/view.php?id=1318 
== 
Reported By:nate_karstens
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1318
Category:   System Interfaces
Type:   Enhancement Request
Severity:   Comment
Priority:   normal
Status: New
Name:   Nate Karstens 
Organization:   Garmin 
User Reference:  
Section:fcntl, open, socket 
Page Number:Unknown 
Line Number:Unknown 
Interp Status:  --- 
Final Accepted Text: 
== 
Date Submitted: 2020-01-12 10:50 UTC
Last Modified:  2020-01-13 16:38 UTC
== 
Summary:Define close-on-fork flag
==
Relationships   ID  Summary
--
related to  411 adding atomic FD_CLOEXEC support
related to  0001317 Require fork handlers to be called in c...
== 

Issue History 
Date ModifiedUsername   FieldChange   
== 
2020-01-12 10:50 nate_karstens  New Issue
2020-01-12 10:50 nate_karstens  Name  => Nate Karstens   
2020-01-12 10:50 nate_karstens  Organization  => Garmin  
2020-01-12 10:50 nate_karstens  Section   => fcntl, open, socket
2020-01-12 10:50 nate_karstens  Page Number   => Unknown 
2020-01-12 10:50 nate_karstens  Line Number   => Unknown 
2020-01-13 07:28 kreNote Added: 0004725  
2020-01-13 16:37 eblake Relationship added   related to 411  
2020-01-13 16:38 eblake Note Added: 0004728  
2020-03-05 17:30 eblake Relationship added   related to 0001317  
==




[1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-01-13 Thread Austin Group Bug Tracker


A NOTE has been added to this issue. 
== 
http://austingroupbugs.net/view.php?id=1318 
== 
Reported By:nate_karstens
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1318
Category:   System Interfaces
Type:   Enhancement Request
Severity:   Comment
Priority:   normal
Status: New
Name:   Nate Karstens 
Organization:   Garmin 
User Reference:  
Section:fcntl, open, socket 
Page Number:Unknown 
Line Number:Unknown 
Interp Status:  --- 
Final Accepted Text: 
== 
Date Submitted: 2020-01-12 10:50 UTC
Last Modified:  2020-01-13 16:38 UTC
== 
Summary:Define close-on-fork flag
==
Relationships   ID  Summary
--
related to  411 adding atomic FD_CLOEXEC support
== 

-- 
 (0004728) eblake (manager) - 2020-01-13 16:38
 http://austingroupbugs.net/view.php?id=1318#c4728 
-- 
Standardization of dup3() and SOCK_CLOEXEC is already the subject of
http://austingroupbugs.net/view.php?id=411 

Issue History 
Date ModifiedUsername   FieldChange   
== 
2020-01-12 10:50 nate_karstens  New Issue
2020-01-12 10:50 nate_karstens  Name  => Nate Karstens   
2020-01-12 10:50 nate_karstens  Organization  => Garmin  
2020-01-12 10:50 nate_karstens  Section   => fcntl, open, socket
2020-01-12 10:50 nate_karstens  Page Number   => Unknown 
2020-01-12 10:50 nate_karstens  Line Number   => Unknown 
2020-01-13 07:28 kreNote Added: 0004725  
2020-01-13 16:37 eblake Relationship added   related to 411  
2020-01-13 16:38 eblake Note Added: 0004728  
==




[1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-01-13 Thread Austin Group Bug Tracker


The following issue has been set as RELATED TO issue 411. 
== 
http://austingroupbugs.net/view.php?id=1318 
== 
Reported By:nate_karstens
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1318
Category:   System Interfaces
Type:   Enhancement Request
Severity:   Comment
Priority:   normal
Status: New
Name:   Nate Karstens 
Organization:   Garmin 
User Reference:  
Section:fcntl, open, socket 
Page Number:Unknown 
Line Number:Unknown 
Interp Status:  --- 
Final Accepted Text: 
== 
Date Submitted: 2020-01-12 10:50 UTC
Last Modified:  2020-01-13 16:37 UTC
== 
Summary:Define close-on-fork flag
==
Relationships   ID  Summary
--
related to  411 adding atomic FD_CLOEXEC support
== 

Issue History 
Date ModifiedUsername   FieldChange   
== 
2020-01-12 10:50 nate_karstens  New Issue
2020-01-12 10:50 nate_karstens  Name  => Nate Karstens   
2020-01-12 10:50 nate_karstens  Organization  => Garmin  
2020-01-12 10:50 nate_karstens  Section   => fcntl, open, socket
2020-01-12 10:50 nate_karstens  Page Number   => Unknown 
2020-01-12 10:50 nate_karstens  Line Number   => Unknown 
2020-01-13 07:28 kreNote Added: 0004725  
2020-01-13 16:37 eblake Relationship added   related to 411  
==




[1003.1(2016)/Issue7+TC2 0001318]: Define close-on-fork flag

2020-01-12 Thread Austin Group Bug Tracker


The following issue has been SUBMITTED. 
== 
http://austingroupbugs.net/view.php?id=1318 
== 
Reported By:nate_karstens
Assigned To:
== 
Project:1003.1(2016)/Issue7+TC2
Issue ID:   1318
Category:   System Interfaces
Type:   Enhancement Request
Severity:   Comment
Priority:   normal
Status: New
Name:   Nate Karstens 
Organization:   Garmin 
User Reference:  
Section:fcntl, open, socket 
Page Number:Unknown 
Line Number:Unknown 
Interp Status:  --- 
Final Accepted Text: 
== 
Date Submitted: 2020-01-12 10:50 UTC
Last Modified:  2020-01-12 10:50 UTC
== 
Summary:Define close-on-fork flag
Description: 
Certain interfaces (like system(), popen(), etc.) are non-atomic in that
their implementation first calls a fork() and then an exec(). This creates
a race condition in certain scenarios. Please see
https://www.mail-archive.com/austin-group-l@opengroup.org/msg05324.html and
resulting discussion for a description of one such condition.

Issue 1317 already requests enhancements to these interfaces, but this
particular issue would also be solvable if there was a close-on-fork flag
(similar to close-on-exec, but the file descriptor is closed in the child
process after a fork).
Desired Action: 
Add the following to fcntl()/F_DUPFD:

The FD_CLOFORK flag associated with the new file descriptor shall be
cleared to keep the file open in the child process after a fork.

Add the following to fcntl()/F_SETFD

If the FD_CLOFORK flag in the third argument is 0, the file descriptor
shall remain open in the child process after a fork(). Otherwise, the file
descriptor shall be closed in the child process after a fork().

Add the following to fcntl():

F_DUPFD_CLOFORK
Like F_DUPFD, but the FD_CLOFORK flag associated with the new file
descriptor shall be set.

Additional changes to the RETURN VALUE and ERRORS sections may be necessary
as well.

Add the following to open():

O_CLOFORK
If set, the FD_CLOFORK flag for the new file descriptor shall be set.

POSIX does not currently specify SOCK_CLOEXEC, but this would be a useful
addition. Add the following to socket():

SOCK_CLOEXEC
If set, the close-on-exec (FD_CLOEXEC) flag for the new file descriptor
shall be set.
SOCK_CLOFORK
If set, the close-on-fork (FD_CLOFORK) flag for the new file descriptor
shall be set.

In hindsight, it seems like it would have been preferable to have the
default behavior be to close all file descriptors when the process forks,
and have flags to override that behavior on an individual basis. Submitter
cannot think of a way to do that and maintain backwards-compatibility,
short of defining new system calls, but the idea seems like it would be
worth considering.
== 

Issue History 
Date ModifiedUsername   FieldChange   
== 
2020-01-12 10:50 nate_karstens  New Issue
2020-01-12 10:50 nate_karstens  Name  => Nate Karstens   
2020-01-12 10:50 nate_karstens  Organization  => Garmin  
2020-01-12 10:50 nate_karstens  Section   => fcntl, open, socket
2020-01-12 10:50 nate_karstens  Page Number   => Unknown 
2020-01-12 10:50 nate_karstens  Line Number   => Unknown 
==