[asterisk-users] Explication for ast_safe_system
Tilghman Lesher
tilghman at mail.jeffandtilghman.com
Sat Jul 19 08:17:49 CDT 2008
On Saturday 19 July 2008 06:41:04 Eric Dantie wrote:
> Can someone please explain the reason on the following code (in
> asterisk.c, function ast_safe_system()):
>
> /* Close file descriptors and launch system command */
> for (x = STDERR_FILENO + 1; x < 4096; x++)
> close(x);
>
>
> Why to close so many descriptors?
There's no way to know how many file descriptors are actually open, and every
file descriptor that is open when a process is forked is duplicated in the new
process. Also, if the process being forked is long running (such as an AGI),
then there could be side effects to not closing all descriptors in a child
process (such as receiving a SIGPIPE when the other end closes).
Eventually, we could probably start registering the highest file descriptor to
a central function, ensuring that we close all of them. It is admittedly a
hack to pick an arbitrary number like this.
--
Tilghman
More information about the asterisk-users
mailing list