335584f
From: Max Reitz <mreitz@redhat.com>
335584f
Date: Sun, 11 Jun 2017 14:37:14 +0200
335584f
Subject: [PATCH] qemu-nbd: Ignore SIGPIPE
335584f
335584f
qemu proper has done so for 13 years
335584f
(8a7ddc38a60648257dc0645ab4a05b33d6040063), qemu-img and qemu-io have
335584f
done so for four years (526eda14a68d5b3596be715505289b541288ef2a).
335584f
Ignoring this signal is especially important in qemu-nbd because
335584f
otherwise a client can easily take down the qemu-nbd server by dropping
335584f
the connection when the server wants to send something, for example:
335584f
335584f
$ qemu-nbd -x foo -f raw -t null-co:// &
335584f
[1] 12726
335584f
$ qemu-io -c quit nbd://localhost/bar
335584f
can't open device nbd://localhost/bar: No export with name 'bar' available
335584f
[1]  + 12726 broken pipe  qemu-nbd -x foo -f raw -t null-co://
335584f
335584f
In this case, the client sends an NBD_OPT_ABORT and closes the
335584f
connection (because it is not required to wait for a reply), but the
335584f
server replies with an NBD_REP_ACK (because it is required to reply).
335584f
335584f
Signed-off-by: Max Reitz <mreitz@redhat.com>
335584f
Message-Id: <20170611123714.31292-1-mreitz@redhat.com>
335584f
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
335584f
(cherry picked from commit 041e32b8d9d076980b4e35317c0339e57ab888f1)
335584f
---
335584f
 qemu-nbd.c | 4 ++++
335584f
 1 file changed, 4 insertions(+)
335584f
335584f
diff --git a/qemu-nbd.c b/qemu-nbd.c
335584f
index 483dd77a77..5deb37e03e 100644
335584f
--- a/qemu-nbd.c
335584f
+++ b/qemu-nbd.c
335584f
@@ -581,6 +581,10 @@ int main(int argc, char **argv)
335584f
     sa_sigterm.sa_handler = termsig_handler;
335584f
     sigaction(SIGTERM, &sa_sigterm, NULL);
335584f
 
335584f
+#ifdef CONFIG_POSIX
335584f
+    signal(SIGPIPE, SIG_IGN);
335584f
+#endif
335584f
+
335584f
     module_call_init(MODULE_INIT_TRACE);
335584f
     qcrypto_init(&error_fatal);
335584f