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: <1314023913.2307.63.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>
Date:	Mon, 22 Aug 2011 16:38:33 +0200
From:	Eric Dumazet <eric.dumazet@...il.com>
To:	Jiri Olsa <jolsa@...hat.com>
Cc:	acme@...hat.com, a.p.zijlstra@...llo.nl, mingo@...e.hu,
	paulus@...ba.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf, tool, record: Fix the header generation for pipe

Le lundi 22 août 2011 à 16:23 +0200, Jiri Olsa a écrit :
> The generation of the perf data file fails when using pipe
> as the output file descriptor.
> 
> When record command generates the data header, several files are put
> inside and the file size is stored ahead of the file contents itself.
> 
> The problem is that debugfs files cannot be stat-ed for size so we
> need to read the whole file, count the size and update the file size
> via seek&write (pwrite call).
> This cannot be done for pipes, since it's not allowed to seek on it.
> 
> The attached patch changes current behaviour for pipes to get the
> file size first and write correct data within the first pass.
> For other than pipe files, the current behaviour stands.
> 
> This issue was caught when running the script command:
> 
> 	# perf script  syscall-counts ls
> 
> since it connects record and report via pipe.
> 
> Signed-off-by: Jiri Olsa <jolsa@...hat.com>
> ---
>  tools/perf/util/trace-event-info.c |   81 +++++++++++++++++++++++++++++++-----
>  1 files changed, 70 insertions(+), 11 deletions(-)
> 
> diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
> index 3403f81..62ab9a2 100644
> --- a/tools/perf/util/trace-event-info.c
> +++ b/tools/perf/util/trace-event-info.c
> @@ -59,6 +59,7 @@ unsigned int page_size;
>  
>  static const char *output_file = "trace.info";
>  static int output_fd;
> +static int output_is_pipe;
>  
>  struct event_list {
>  	struct event_list *next;
> @@ -183,20 +184,59 @@ int bigendian(void)
>  	return *ptr == 0x01020304;
>  }
>  
> +static off_t get_file_size(int fd)
> +{
> +	off_t size = 0;
> +	char buf[BUFSIZ];
> +	int r;
> +
> +	do {
> +		r = read(fd, buf, BUFSIZ);
> +		if (r > 0)
> +			size += r;
> +	} while (r > 0);
> +
> +	if (lseek(fd, 0, SEEK_SET))
> +		die("seek failed");
> +
> +	return size;
> +}

This part makes no sense :

If fd is a pipe, you'll call die("seek failed")

If it's not a pipe, you can try lseek(fd, 0, SEEK_END)+lseek(fd, 0,
SEEK_SET) or fstat(fd, &st) instead of the read() loop.



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ