[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 6/8] qemu-nbd: Honor SIGINT and SIGHUP
From: |
Eric Blake |
Subject: |
[PULL 6/8] qemu-nbd: Honor SIGINT and SIGHUP |
Date: |
Thu, 8 Oct 2020 13:59:49 -0500 |
Honoring just SIGTERM on Linux is too weak; we also want to handle
other common signals, and do so even on BSD. Why? Because at least
'qemu-nbd -B bitmap' needs a chance to clean up the in-use bit on
bitmaps when the server is shut down via a signal.
See also: http://bugzilla.redhat.com/1883608
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200930121105.667049-2-eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
[eblake: apply comment tweak suggested by Vladimir]
Signed-off-by: Eric Blake <eblake@redhat.com>
---
qemu-nbd.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index bacb69b0898b..c731dda04ec0 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -581,17 +581,18 @@ int main(int argc, char **argv)
const char *pid_file_name = NULL;
BlockExportOptions *export_opts;
-#if HAVE_NBD_DEVICE
- /* The client thread uses SIGTERM to interrupt the server. A signal
- * handler ensures that "qemu-nbd -v -c" exits with a nice status code.
+#ifdef CONFIG_POSIX
+ /*
+ * Exit gracefully on various signals, which includes SIGTERM used
+ * by 'qemu-nbd -v -c'.
*/
struct sigaction sa_sigterm;
memset(&sa_sigterm, 0, sizeof(sa_sigterm));
sa_sigterm.sa_handler = termsig_handler;
sigaction(SIGTERM, &sa_sigterm, NULL);
-#endif /* HAVE_NBD_DEVICE */
+ sigaction(SIGINT, &sa_sigterm, NULL);
+ sigaction(SIGHUP, &sa_sigterm, NULL);
-#ifdef CONFIG_POSIX
signal(SIGPIPE, SIG_IGN);
#endif
--
2.28.0
- [PULL 0/8] NBD patches through 2020-10-08, Eric Blake, 2020/10/08
- [PULL 4/8] block/nbd: fix reconnect-delay, Eric Blake, 2020/10/08
- [PULL 2/8] block/nbd: fix drain dead-lock because of nbd reconnect-delay, Eric Blake, 2020/10/08
- [PULL 5/8] block/nbd: nbd_co_reconnect_loop(): don't connect if drained, Eric Blake, 2020/10/08
- [PULL 3/8] block/nbd: correctly use qio_channel_detach_aio_context when needed, Eric Blake, 2020/10/08
- [PULL 7/8] nbd/server: Reject embedded NUL in NBD strings, Eric Blake, 2020/10/08
- [PULL 1/8] nbd: silence maybe-uninitialized warnings, Eric Blake, 2020/10/08
- [PULL 6/8] qemu-nbd: Honor SIGINT and SIGHUP,
Eric Blake <=
- [PULL 8/8] nbd: Simplify meta-context parsing, Eric Blake, 2020/10/08
- Re: [PULL 0/8] NBD patches through 2020-10-08, Peter Maydell, 2020/10/09