How Can I Check if a FD is Guarded?

How does one check if a file descriptor is guarded? Is there any guarded FD numbers that are determinate? I've seen 12 being NPOLICY in a few things -- is there documentation for which FDs might be guarded? Thanks. The platform is Mac Catalyst.

Answered by DTS Engineer in 839389022

What are you trying to do here?

Generally it doesn’t make sense to test whether a file descriptor is guarded because:

  • Either the file descriptor is something you guarded, in which case you already know the answer.

  • Or it’s not, in which case the check is subject to the very TOC/TOU issues that guards protect against.

Is there any guarded FD numbers that are determinate?

No. In general the only determinate file descriptors are 0, 1, and 2 for std{in,out,err}.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

What are you trying to do here?

Generally it doesn’t make sense to test whether a file descriptor is guarded because:

  • Either the file descriptor is something you guarded, in which case you already know the answer.

  • Or it’s not, in which case the check is subject to the very TOC/TOU issues that guards protect against.

Is there any guarded FD numbers that are determinate?

No. In general the only determinate file descriptors are 0, 1, and 2 for std{in,out,err}.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How Can I Check if a FD is Guarded?
 
 
Q