I agree with Steve here: Upstart is careful to set CLOEXEC on all the fds it has control over, so I would much prefer this be fixed at source.
A temporary work-around for jobs that are affected by this issue is to add the following code at the top of all appropriate script sections - remember that all script and exec sections run as different processes so if you have a pre-start and a script section, the code below should be added to the top of *both* those sections:
script
# close unexpectedly open fds
# The 'readlink' ensures we don't try to close the fd we're using to read the /proc/self/fd directory.
for fd in /proc/self/fd/*
do
fd=$(basename $fd)
case "$fd" in
0|1|2) ;;
*) readlink $fd && eval "exec $fd>&-" || :;;
esac
done
I agree with Steve here: Upstart is careful to set CLOEXEC on all the fds it has control over, so I would much prefer this be fixed at source.
A temporary work-around for jobs that are affected by this issue is to add the following code at the top of all appropriate script sections - remember that all script and exec sections run as different processes so if you have a pre-start and a script section, the code below should be added to the top of *both* those sections:
script
# close unexpectedly open fds
# The 'readlink' ensures we don't try to close the fd we're using to read the /proc/self/fd directory.
for fd in /proc/self/fd/*
do
fd=$(basename $fd)
case "$fd" in
0|1|2) ;;
*) readlink $fd && eval "exec $fd>&-" || :;;
esac
done
# << do something useful here >>
end script