diff mbox series

[v2,1/5] qemu-nbd: Honor SIGINT and SIGHUP

Message ID 20200930121105.667049-2-eblake@redhat.com
State New
Headers show
Series Exposing backing-chain allocation over NBD | expand

Commit Message

Eric Blake Sept. 30, 2020, 12:11 p.m. UTC
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>
---
 qemu-nbd.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Vladimir Sementsov-Ogievskiy Oct. 7, 2020, 10:32 a.m. UTC | #1
30.09.2020 15:11, Eric Blake wrote:
> 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.


Probably not bad to update a comment [*] if you have a good wording in mind.

> 

> See also: http://bugzilla.redhat.com/1883608

> 

> Signed-off-by: Eric Blake <eblake@redhat.com>


Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>


> ---

>   qemu-nbd.c | 6 +++---

>   1 file changed, 3 insertions(+), 3 deletions(-)

> 

> diff --git a/qemu-nbd.c b/qemu-nbd.c

> index bacb69b0898b..e7520261134f 100644

> --- a/qemu-nbd.c

> +++ b/qemu-nbd.c

> @@ -581,7 +581,7 @@ int main(int argc, char **argv)

>       const char *pid_file_name = NULL;

>       BlockExportOptions *export_opts;

> 

> -#if HAVE_NBD_DEVICE

> +#ifdef CONFIG_POSIX

>       /* The client thread uses SIGTERM to interrupt the server.  A signal

>        * handler ensures that "qemu-nbd -v -c" exits with a nice status code.


[*]

>        */

> @@ -589,9 +589,9 @@ int main(int argc, char **argv)

>       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

> 



-- 
Best regards,
Vladimir
diff mbox series

Patch

diff --git a/qemu-nbd.c b/qemu-nbd.c
index bacb69b0898b..e7520261134f 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -581,7 +581,7 @@  int main(int argc, char **argv)
     const char *pid_file_name = NULL;
     BlockExportOptions *export_opts;

-#if HAVE_NBD_DEVICE
+#ifdef CONFIG_POSIX
     /* The client thread uses SIGTERM to interrupt the server.  A signal
      * handler ensures that "qemu-nbd -v -c" exits with a nice status code.
      */
@@ -589,9 +589,9 @@  int main(int argc, char **argv)
     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