taskd.pl: avoid missed connects during graceful restart
commit3bcce67f10925bf23036567e31213a46cdd70beb
authorKyle J. McKay <mackyle@gmail.com>
Wed, 30 Nov 2016 07:33:46 +0000 (29 23:33 -0800)
committerKyle J. McKay <mackyle@gmail.com>
Wed, 30 Nov 2016 07:33:46 +0000 (29 23:33 -0800)
treefb790ab5927abac8e494c37801db2e430f67adf3
parent85b6a65bf18b5ea3de0cc7a4c0ab4ffbe69bd7bd
taskd.pl: avoid missed connects during graceful restart

During a graceful restart in non-inetd mode, the old Server
(and hence the accept socket) was being closed by the exec and
then re-created by the new process.

While small, there is a window of opportunity for an incoming
connection to be lost because the taskd socket is not open and
listening for new connections during this brief restart period.

Avoid this by leaving the old Server socket open (by disabling
close-on-exec for its file descriptor) and telling the new
process to adopt it as the Server (like inetd mode does for
file descriptor 0) by passing the file descriptor in a special
new enviornment variable.

Almost all the work to support this was already done when the
inetd support was added.  As a bonus this same special environment
variable can be used to tell inetd mode to use a file descriptor
other than 0 (although that would technically then not be "inetd"
mode anymore).

A graceful restart can now be performed in non-inetd mode which is
guaranteed to not lose any incoming connections because of the
restart (this already worked in inetd mode because the inetd server
keeps the socket open while the process is restarting).

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
taskd/taskd.pl