setsid() makes opened "/dev/tty" unusable

Originator:fedor.indutny
Number:rdar://23994737 Date Originated:22-12-2015
Status:Open Resolved:
Product:OS X Product Version:10.11.2
Classification: Reproducible:
 
Summary:
Calling `setsid()` after `fork` makes opened "/dev/tty" fds unusable: any write/read/ioctl returns EIO.

Steps to Reproduce:
1. Download attached files
2. Run `make` or just compile `test.c` with `clang`
3. Run `./test`

Expected Results:
It should print `0`.

Actual Results:
It prints `5`, which actually means EIO. FreeBSD and every other system handles this differently, so I believe that the current OS X behavior is not compliant to POSIX.

Version:
10.11.2

Notes:
The reason for this appears to be the way it is implemented in xnu. `cttyioctl` and all of `ctty*` which seem to be responsible for "/dev/tty" file ops, calls `cttyvp` which tries to tty from the current session. `setsid()` on other hand leaves the terminal in a new session empty.

Configuration:


Attachments:
'test.c' and 'Makefile' were successfully uploaded.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!