]> git.tuebingen.mpg.de Git - paraslash.git/commit
server: Let stat command handler perform cleanup on signals.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 12 Aug 2017 21:27:55 +0000 (23:27 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Tue, 13 Mar 2018 02:28:10 +0000 (03:28 +0100)
commit0ce0301d8184fcebb1aafda396d6a9ae71bf1301
tree732c3537bae6acecb76170b77279e6e67f4c0701
parent42c6dc96316660fe476a6baadd87a2c79da07c83
server: Let stat command handler perform cleanup on signals.

The stat command is special because it is the only command which may
run for a very long time, and because it catches SIGUSR1 which is sent
by the server to notify the command handler process when the status
items have changed and the command handler should update the client.

The stat command handler catches neither SIGINT nor SIGTERM, though,
so these signals terminate the process. This happens when para_server
is started without --daemon and CTRL+C is pressed (causing SIGINT
to be sent to the all processes in the foreground process group)
or when the server is about to exit, because in this case the main
process sends SIGTERM to all child processes.

If the command handler process terminates because it received SIGINT
or SIGTERM, valgrind reports various memory leaks. Although the leaks
are harmless, they clutter the valgrind output and make real memory
leaks hard to spot.

This commit changes com_stat() to ignore SIGINT and catch SIGTERM in
addition to SIGUSR1. We don't need to care about SIGINT in com_stat()
because in the above scenario, the main process sends SIGTERM to all
command handlers after it received SIGINT. With the patch applied, if
com_stat() received SIGTERM, it returns and the normal cleanup on exit
is performed.

We have to employ pselect(2) to avoid race conditions.
command.c