[PATCH] smemcap: keep outputting by ignoring transient processes
andre.rosa
andre.rosa at lge.com
Fri Aug 24 16:44:47 UTC 2018
Hi Walter,
Patch solves the problem where the output of smemcap is incomplete
(it aborts with a short/truncated output) in the presence of short lived processes.
It's basically a race condition between reading the /proc/ directory contents
(to get the list of folders representing each PID) and trying to read them.
We shouldn't abort (xopen) if we can't read a specific process (as it may have vanished
between directory listing and traversal) and it should keep iterating on the other processes
which are present. Otherwise we may miss long running processes which are there but are
reported "sometimes" due to the truncated output when the race occurs.
Thanks,
Andre
-----Original Message-----
From: Walter Harms [mailto:wharms at bfs.de]
Sent: Friday, August 24, 2018 12:15 AM
To: busybox at busybox.net
Cc: Andre Rosa/LGEUS Advanced Platform Technology(andre.rosa at lge.com) <andre.rosa at lge.com>
Subject: Re: [PATCH] smemcap: keep outputting by ignoring transient processes
I am sorry i missed the point,
this patch solves what probelm ?
re,
wh
Am 23.08.2018 23:44, schrieb Andre Goddard Rosa:
> Signed-off-by: Andre Goddard Rosa <andre.rosa at lge.com>
> ---
> procps/smemcap.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/procps/smemcap.c b/procps/smemcap.c index
> 81f4cafad..1fa27a6c4 100644
> --- a/procps/smemcap.c
> +++ b/procps/smemcap.c
> @@ -65,14 +65,22 @@ static void archivefile(const char *path)
> struct stat s;
>
> /* buffer the file */
> - fd = xopen(path, O_RDONLY);
> + fd = open(path, O_RDONLY);
> + if (fd == -1) {
> + // Skip vanished processes between dir listing and traversal
> + return;
> + }
> do {
> cur = xzalloc(sizeof(*cur));
> *prev = cur;
> prev = &cur->next;
> r = full_read(fd, cur->data, TAR_BLOCK_SIZE);
> - if (r > 0)
> + if (r > 0) {
> size += r;
> + } else if (r == -1) {
> + close(fd);
> + return;
> + }
> } while (r == TAR_BLOCK_SIZE);
>
> /* write archive header */
More information about the busybox
mailing list