xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools: Improve signal handling in xen-vmtrace
@ 2021-02-26 10:59 Hubert Jasudowicz
  2021-02-26 11:23 ` Hubert Jasudowicz
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Hubert Jasudowicz @ 2021-02-26 10:59 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Wei Liu, Michał Leszczyński

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@cert.pl>
---
 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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools: Improve signal handling in xen-vmtrace
  2021-02-26 10:59 [PATCH] tools: Improve signal handling in xen-vmtrace Hubert Jasudowicz
@ 2021-02-26 11:23 ` Hubert Jasudowicz
  2021-02-26 17:44 ` Andrew Cooper
  2021-03-01 17:34 ` Ian Jackson
  2 siblings, 0 replies; 5+ messages in thread
From: Hubert Jasudowicz @ 2021-02-26 11:23 UTC (permalink / raw)
  To: xen-devel; +Cc: Ian Jackson, Wei Liu, Michał Leszczyński

On 2021-02-26, Hubert Jasudowicz wrote:
> 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@cert.pl>
> ---
>  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
> 
> 

Oops, forgot 4.15 tag. But IMO this should be included.

Thanks
Hubert Jasudowicz
CERT Polska


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools: Improve signal handling in xen-vmtrace
  2021-02-26 10:59 [PATCH] tools: Improve signal handling in xen-vmtrace Hubert Jasudowicz
  2021-02-26 11:23 ` Hubert Jasudowicz
@ 2021-02-26 17:44 ` Andrew Cooper
  2021-03-01 17:39   ` Ian Jackson
  2021-03-01 17:34 ` Ian Jackson
  2 siblings, 1 reply; 5+ messages in thread
From: Andrew Cooper @ 2021-02-26 17:44 UTC (permalink / raw)
  To: Hubert Jasudowicz, xen-devel
  Cc: Ian Jackson, Wei Liu, Michał Leszczyński

On 26/02/2021 10:59, Hubert Jasudowicz wrote:
> 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@cert.pl>

Ok, so this is being used in production.

In which case, what other signals potentially need dealing with?  Lets
get them all fixed in one go.

When that's done, we should make it installed by default, to match its
expected usecase.

~Andrew


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools: Improve signal handling in xen-vmtrace
  2021-02-26 10:59 [PATCH] tools: Improve signal handling in xen-vmtrace Hubert Jasudowicz
  2021-02-26 11:23 ` Hubert Jasudowicz
  2021-02-26 17:44 ` Andrew Cooper
@ 2021-03-01 17:34 ` Ian Jackson
  2 siblings, 0 replies; 5+ messages in thread
From: Ian Jackson @ 2021-03-01 17:34 UTC (permalink / raw)
  To: Hubert Jasudowicz; +Cc: xen-devel, Wei Liu, Michał Leszczyński

Hubert Jasudowicz writes ("[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.

Release-Acked-by: Ian Jackson <iwj@xenproject.org>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] tools: Improve signal handling in xen-vmtrace
  2021-02-26 17:44 ` Andrew Cooper
@ 2021-03-01 17:39   ` Ian Jackson
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Jackson @ 2021-03-01 17:39 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: Hubert Jasudowicz, xen-devel, Wei Liu, Michał Leszczyński

Andrew Cooper writes ("Re: [PATCH] tools: Improve signal handling in xen-vmtrace"):
> In which case, what other signals potentially need dealing with?  Lets
> get them all fixed in one go.
> 
> When that's done, we should make it installed by default, to match its
> expected usecase.

With my tools maintainer hat on:

TERM INT HUP PIPE QUIT

Not sure if we can be bothered with SIGTSTP.

If you want to be nice, when a signal occurs. arrange to re-raise it
after cleanup.  After all, exiting with stderr blather and a non-zero
exit status, merely for SIGPIPE, is rather unfriendly.

This means writing the signal number to the volatile.


With my release manager hat on:

I do not intend to give a release ack to install this by default, at
this stage.  It would have been better to have made this program a
proper utility from the start, but it has now missed the boat for
being a supported feature for 4.15.

OTOH given that it is not installed by default, nor supported, I would
welcome impreovements to it that I don't think will break the build.


Ian.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-01 17:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26 10:59 [PATCH] tools: Improve signal handling in xen-vmtrace Hubert Jasudowicz
2021-02-26 11:23 ` Hubert Jasudowicz
2021-02-26 17:44 ` Andrew Cooper
2021-03-01 17:39   ` Ian Jackson
2021-03-01 17:34 ` Ian Jackson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).