[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [solved] C program launched by start-stop-daemon fails to catch signals



On Sat, May 7, 2016, at 02:43 PM, Christian Seiler wrote:
> 
> 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.
> 

Dear Christian,

You have saved me from resorting to debuggers after days' fruitless
digging.
Big thanks to your kind enlightenment!

Best regards,
CN

-- 
http://www.fastmail.com - Does exactly what it says on the tin


Reply to: