On 05/07/2016 06:39 AM, CN wrote:
> The following compilable C++ program catches signals as expected if it
> runs directly from shell /tmp/a.out.
>
> However, this program fails to catch any signal and silently terminates
> if it is fired by Debian's start-stop-daemon.
No, it does catch the signal without a problem. But start-stop-daemon
closes the standard filedescriptors and replaces them with /dev/null.
Try it:
/tmp/t.sh start
ps ax | grep a.out
lsof -p $PID
-> look for FD = 0u, 1u and 2u, those are all /dev/null
That means that the error output is dropped, because it goes to
/dev/null.
If you alter your test code to include #include <fstream> and replace
the following function:
void signal_handler(int signal_number)
{
std::ofstream error_out("/tmp/daemon-error.out");
error_out << "Caught signal# " << signal_number << std::endl;
caught_signal=signal_number;
}
Then you will see that /tmp/daemon-error.out is generated and that
there is the text "Caught signal#15" inside, if you terminate the
daemon via the init script.
> (My real life multiple
> threaded program does not silently terminates. Instead, segmentation
> fault occurs from pthread libray.)
Well, then your problem is likely to be a bit more complicated. :(
Regards,
Christian
Attachment:
signature.asc
Description: OpenPGP digital signature