lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAM9d7ciF+_s+MqNou4szVSStBObtB87UznMMG8SsZkuRyR1dNg@mail.gmail.com>
Date:   Tue, 29 Dec 2020 14:53:36 +0900
From:   Namhyung Kim <namhyung@...nel.org>
To:     Jiri Olsa <jolsa@...nel.org>
Cc:     Arnaldo Carvalho de Melo <acme@...nel.org>,
        lkml <linux-kernel@...r.kernel.org>,
        Peter Zijlstra <a.p.zijlstra@...llo.nl>,
        Ingo Molnar <mingo@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Michael Petlan <mpetlan@...hat.com>,
        Ian Rogers <irogers@...gle.com>,
        Stephane Eranian <eranian@...gle.com>,
        Alexei Budankov <abudankov@...wei.com>
Subject: Re: [PATCH] perf tools: Detect when pipe is passed as perf data

On Sat, Dec 26, 2020 at 7:21 AM Jiri Olsa <jolsa@...nel.org> wrote:
>
> Currently we allow pipe input/output only through '-' string
> being passed to '-o' or '-i' options, like:
>
>   # mkfifo perf.pipe
>   # perf record --no-buffering -e 'sched:sched_switch' -o - > perf.pipe &
>   [1] 354406
>   # cat perf.pipe | ./perf --no-pager script -i - | head -3
>             perf 354406 [000] 168190.164921: sched:sched_switch: perf:354406..
>      migration/0    12 [000] 168190.164928: sched:sched_switch: migration/0:..
>             perf 354406 [001] 168190.164981: sched:sched_switch: perf:354406..
>   ...
>
> This patch detects if given path is pipe and set the perf data
> object accordingly, so it's possible now to do above with:
>
>   # mkfifo perf.pipe
>   # perf record --no-buffering -e 'sched:sched_switch' -o perf.pipe &
>   [1] 360188
>   # perf --no-pager script -i ./perf.pipe | head -3
>             perf 354442 [000] 168275.464895: sched:sched_switch: perf:354442..
>      migration/0    12 [000] 168275.464902: sched:sched_switch: migration/0:..
>             perf 354442 [001] 168275.464953: sched:sched_switch: perf:354442..
>
> It's of course possible to combine any of above ways.
>
> Signed-off-by: Jiri Olsa <jolsa@...nel.org>
> ---
>  tools/perf/util/data.c | 27 +++++++++++++++++++++------
>  1 file changed, 21 insertions(+), 6 deletions(-)
>
> diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c
> index f29af4fc3d09..767b6c903cf5 100644
> --- a/tools/perf/util/data.c
> +++ b/tools/perf/util/data.c
> @@ -159,7 +159,7 @@ int perf_data__update_dir(struct perf_data *data)
>         return 0;
>  }
>
> -static bool check_pipe(struct perf_data *data)
> +static int check_pipe(struct perf_data *data)
>  {
>         struct stat st;
>         bool is_pipe = false;
> @@ -172,6 +172,15 @@ static bool check_pipe(struct perf_data *data)
>         } else {
>                 if (!strcmp(data->path, "-"))
>                         is_pipe = true;
> +               else if (!stat(data->path, &st) && S_ISFIFO(st.st_mode)) {
> +                       int flags = perf_data__is_read(data) ?
> +                                   O_RDONLY : O_WRONLY|O_CREAT|O_TRUNC;

I don't think we need O_CREAT here (maybe O_TRUNC as well).

Thanks,
Namhyung


> +
> +                       fd = open(data->path, flags);
> +                       if (fd < 0)
> +                               return -EINVAL;
> +                       is_pipe = true;
> +               }
>         }
>
>         if (is_pipe) {
> @@ -190,7 +199,8 @@ static bool check_pipe(struct perf_data *data)
>                 }
>         }
>
> -       return data->is_pipe = is_pipe;
> +       data->is_pipe = is_pipe;
> +       return 0;
>  }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ