> On Sept. 7, 2018, 2:18 a.m., James Peach wrote:
> > 3rdparty/libprocess/src/posix/subprocess.hpp
> > Lines 195 (patched)
> > <https://reviews.apache.org/r/68644/diff/1/?file=2082817#file2082817line195>
> >
> >     We need to be careful here. We are in an async-signal-safe context but 
> > hashmap and list allocate memory.
> >     
> >     Actually iterating over the directory is difficult to do in an 
> > async-signal-safe context. You can open the directory in the parent and do 
> > the iteration in the child, but I don't think there's any guarantee that 
> > the readdir in the child is safe (though AFAIK in glibc it would work).

Good catch!

Yeah, we could do `os::lsof()` in the parent (e.g., right before we fork the 
child: 
https://github.com/apache/mesos/blob/1.7.0/3rdparty/libprocess/src/posix/subprocess.hpp#L261)
 , but what if the parent opens a new fd after `os::lsof()` is called but 
before the child is forked? In such case, the new fd will be leaked to the 
child.

And it seems `opendir`, `readdir` and `closedir` are not async-signal-safe 
according to http://man7.org/linux/man-pages/man7/signal-safety.7.html

Maybe we should do something like this: 
https://github.com/python/cpython/blob/master/Modules/_posixsubprocess.c#L257:L303
 , but I see they call `getdents64` which seems not async-signal-safe too.


- Qian


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/68644/#review208417
-----------------------------------------------------------


On Sept. 6, 2018, 9:25 a.m., Qian Zhang wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/68644/
> -----------------------------------------------------------
> 
> (Updated Sept. 6, 2018, 9:25 a.m.)
> 
> 
> Review request for mesos, Gilbert Song and James Peach.
> 
> 
> Bugs: MESOS-9152
>     https://issues.apache.org/jira/browse/MESOS-9152
> 
> 
> Repository: mesos
> 
> 
> Description
> -------
> 
> Closed all file descriptors except `whitelist_fds` in posix/subprocess.
> 
> 
> Diffs
> -----
> 
>   3rdparty/libprocess/src/posix/subprocess.hpp 
> 007058b61fdcd4716aa793516c842c3cef8c0a29 
>   3rdparty/libprocess/src/subprocess.cpp 
> c0640de2dc4278b884282dfaad98c49c3b067a5b 
> 
> 
> Diff: https://reviews.apache.org/r/68644/diff/1/
> 
> 
> Testing
> -------
> 
> 
> Thanks,
> 
> Qian Zhang
> 
>

Reply via email to