Jim Crites
|
posix_spawn and child file handles
|
Jim Crites
03/06/2013 2:17 PM
post99711
|
posix_spawn and child file handles
I am using posix_spwan (as opposed to qnx spawn) to create child processes because I need to explicitly set the uid:gid
of the child process. Additionally I need for the child to not inherit any open handles from the parent. This is where
the problem arises. From the QNX documentation I can create (and init) a posix_spawn_file_actions_t struct and then call
posix_spawn_file_actions_addclose() for each file handle I want to be closed. The rub is I don't know how many or which
handles are open. After some research I found what appeared to be a solution. Get the size of the process's file
descriptor table and then call posix_spawn_file_actions_addclose() for each slot in the table. Two functions are
available to get the table size getdtablesize() and sysconf( _SC_OPEN_MAX). Both of those functions return the same
value, 3000. If I try to call addclose() for 3000 handles I die from a memory fault. Anybody know what's up with this ?
Any alternative way to accomplish this ?
|
|
|