[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tools: Improve signal handling in xen-vmtrace



Make sure xen-vmtrace exits cleanly in case SIGPIPE is sent. This can
happen when piping the output to some other program.

Additionaly, add volatile qualifier to interrupted flag to avoid
it being optimized away by the compiler.

Signed-off-by: Hubert Jasudowicz <hubert.jasudowicz@xxxxxxx>
---
 tools/misc/xen-vmtrace.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/misc/xen-vmtrace.c b/tools/misc/xen-vmtrace.c
index 7572e880c5..e2da043058 100644
--- a/tools/misc/xen-vmtrace.c
+++ b/tools/misc/xen-vmtrace.c
@@ -43,7 +43,7 @@ static uint32_t domid, vcpu;
 static size_t size;
 static char *buf;
 
-static sig_atomic_t interrupted;
+static volatile sig_atomic_t interrupted;
 static void int_handler(int signum)
 {
     interrupted = 1;
@@ -81,6 +81,9 @@ int main(int argc, char **argv)
     if ( signal(SIGINT, int_handler) == SIG_ERR )
         err(1, "Failed to register signal handler\n");
 
+    if ( signal(SIGPIPE, int_handler) == SIG_ERR )
+        err(1, "Failed to register signal handler\n");
+
     if ( argc != 3 )
     {
         fprintf(stderr, "Usage: %s <domid> <vcpu_id>\n", argv[0]);
-- 
2.30.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.