qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Cc: stefanha@redhat.com
Subject: Re: [PATCH v2] trace/simple: Fix unauthorized enable
Date: Wed, 27 May 2020 09:38:57 +0200	[thread overview]
Message-ID: <07cfb8eb-4596-5c06-5ec3-fe529f5249d9@redhat.com> (raw)
In-Reply-To: <20200527065613.25322-1-armbru@redhat.com>

On 5/27/20 8:56 AM, Markus Armbruster wrote:
> st_set_trace_file() accidentally enables tracing.  It's called
> unconditionally during startup, which is why QEMU built with the
> simple trace backend always writes a trace file "trace-$PID".
> 
> This has been broken for quite a while.  I didn't track down the exact
> commit.
> 
> Fix st_set_trace_file() to restore the state.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
> v2: Make st_set_trace_file() less confusing [Stefan]
> 
>  trace/simple.h |  2 +-
>  trace/simple.c | 20 ++++++++++++++------
>  2 files changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/trace/simple.h b/trace/simple.h
> index 5771a0634f..26ccbc8b8a 100644
> --- a/trace/simple.h
> +++ b/trace/simple.h
> @@ -12,7 +12,7 @@
>  #define TRACE_SIMPLE_H
>  
>  void st_print_trace_file_status(void);
> -void st_set_trace_file_enabled(bool enable);
> +bool st_set_trace_file_enabled(bool enable);
>  void st_set_trace_file(const char *file);
>  bool st_init(void);
>  void st_flush_trace_buffer(void);
> diff --git a/trace/simple.c b/trace/simple.c
> index fc7106ec49..9cd2ed1fb3 100644
> --- a/trace/simple.c
> +++ b/trace/simple.c
> @@ -302,10 +302,17 @@ static int st_write_event_mapping(void)
>      return 0;
>  }
>  
> -void st_set_trace_file_enabled(bool enable)
> +/**
> + * Enable / disable tracing, return whether it was enabled.
> + *
> + * @enable: enable if %true, else disable.
> + */
> +bool st_set_trace_file_enabled(bool enable)
>  {
> +    bool was_enabled = trace_fp;
> +
>      if (enable == !!trace_fp) {
> -        return; /* no change */
> +        return was_enabled;     /* no change */
>      }
>  
>      /* Halt trace writeout */
> @@ -323,14 +330,14 @@ void st_set_trace_file_enabled(bool enable)
>  
>          trace_fp = fopen(trace_file_name, "wb");
>          if (!trace_fp) {
> -            return;
> +            return was_enabled;
>          }
>  
>          if (fwrite(&header, sizeof header, 1, trace_fp) != 1 ||
>              st_write_event_mapping() < 0) {
>              fclose(trace_fp);
>              trace_fp = NULL;
> -            return;
> +            return was_enabled;
>          }
>  
>          /* Resume trace writeout */
> @@ -340,6 +347,7 @@ void st_set_trace_file_enabled(bool enable)
>          fclose(trace_fp);
>          trace_fp = NULL;
>      }
> +    return was_enabled;
>  }
>  
>  /**
> @@ -350,7 +358,7 @@ void st_set_trace_file_enabled(bool enable)
>   */
>  void st_set_trace_file(const char *file)
>  {
> -    st_set_trace_file_enabled(false);
> +    bool saved_enable = st_set_trace_file_enabled(false);
>  
>      g_free(trace_file_name);
>  
> @@ -361,7 +369,7 @@ void st_set_trace_file(const char *file)
>          trace_file_name = g_strdup_printf("%s", file);
>      }
>  
> -    st_set_trace_file_enabled(true);
> +    st_set_trace_file_enabled(saved_enable);
>  }
>  
>  void st_print_trace_file_status(void)
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>



  reply	other threads:[~2020-05-27  7:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-27  6:56 [PATCH v2] trace/simple: Fix unauthorized enable Markus Armbruster
2020-05-27  7:38 ` Philippe Mathieu-Daudé [this message]
2020-06-17 15:26 ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=07cfb8eb-4596-5c06-5ec3-fe529f5249d9@redhat.com \
    --to=philmd@redhat.com \
    --cc=armbru@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).