Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - posix_spawn and child file handles: (3 Items)
   
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 ? 
Re: posix_spawn and child file handles  
search on 'iofdinfo' at this link 
http://www.qnx.com/developers/docs/6.5.0_sp1/index.jsp
I haven't tried it and the docs don't say so but I think you will get 
back EBADF (or some other error) on unopened fd's

On 03/06/2013 02:17 PM, Jim Crites wrote:
> 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 ?
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post99711
> To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com


RE: posix_spawn and child file handles  
As Mike says, probably your best bet is to narrow down the descriptor list to just those which you know are open.  If 
iofdinfo() doesn't do the trick, fstat() definitely will.
________________________________________
From: Michael Kisel [community-noreply@qnx.com]
Sent: March-06-13 3:01 PM
To: ostech-core_os@community.qnx.com
Subject: Re: posix_spawn and child file handles

search on 'iofdinfo' at this link
http://www.qnx.com/developers/docs/6.5.0_sp1/index.jsp
I haven't tried it and the docs don't say so but I think you will get
back EBADF (or some other error) on unopened fd's

On 03/06/2013 02:17 PM, Jim Crites wrote:
> 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 ?
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post99711
> To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com






_______________________________________________

OSTech
http://community.qnx.com/sf/go/post99712
To cancel your subscription to this discussion, please e-mail ostech-core_os-unsubscribe@community.qnx.com