rate: Pass through delay failures
commit6fe96ce8d42e9b963f7c1f7fd0ea95cc5cf6939b
authorEric Blake <eblake@redhat.com>
Fri, 26 Jul 2019 02:46:57 +0000 (25 21:46 -0500)
committerEric Blake <eblake@redhat.com>
Thu, 1 Aug 2019 11:06:44 +0000 (1 06:06 -0500)
treec5bce40b4a4faa53e0595c4f7d94b58b2be49540
parentfde2f886211574a79753486e956ff55a7fe78320
rate: Pass through delay failures

If nanosleep fails (typically with EINTR because we handled a signal),
we end up not sleeping long enough.  In practice, this patch seldom
makes a difference: directing signals at the nbdkit process tends to
get serviced by the thread running poll(), and when that happens, the
thread blocked in nanosleep() continues uninterrupted. As a result,
nbdkit stalls in exiting because it is waiting for the filter plugin
to quit servicing commands. But if you get lucky (or if you direct the
kill to the specific thread stuck in nanosleep rather than the process
as a whole), then this patch causes us to report early failure with
EINTR mapped to EIO over the wire, at which point, we are back to
practice: the only signals we handle trigger nbdkit to shutdown, so we
may not even have a chance to get our unusual error reported over the
wire.  In theory, we could resume nanosleep where it left off by
passing a non-null second argument, but that only matters if we have a
signal handler whose action doesn't intend to request nbdkit to shut
down soon.

A later patch will add a utility function so that the server can do a
better job, both for preventing short sleeps by resuming on EINTR
(assuming the server ever adds support for a non-fatal signal, whether
that be support for SIGHUP re-reading configuration or support for
SIGUSR1/SIGINFO in providing server statistics so far), and for
terminating sleeps with a better error than EINTR the moment we know a
particular client is shutting down (whether because a signal is
terminating all of nbdkit, or we got NBD_CMD_DISC or detected EOF on
this particular connection).  At that point, we'll only have to tweak
the delay function to use that utility function in place of nanosleep.

Signed-off-by: Eric Blake <eblake@redhat.com>
filters/rate/rate.c