Reset errno when cmd file is not exists 60/243060/3 accepted/tizen/unified/20200904.154051 submit/tizen/20200904.044649
authorSeungha Son <seungha.son@samsung.com>
Thu, 3 Sep 2020 00:06:59 +0000 (09:06 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 4 Sep 2020 02:02:40 +0000 (02:02 +0000)
 Sometime, there is a timing issue.
 If the process is terminated before calling readdir() and
 the directory of the process is removed, the file fails to open.
 If the file fails to open, errno is set, and the logic is terminated
 without reading other process information.

Change-Id: I332e076ce035bd6d66175d6886ce223aa964513a
Signed-off-by: Seungha Son <seungha.son@samsung.com>
memps.c

diff --git a/memps.c b/memps.c
index b93dff1..c54b007 100644 (file)
--- a/memps.c
+++ b/memps.c
@@ -872,6 +872,8 @@ static int get_cmdline(unsigned int pid, char *cmdline)
        snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid);
        fp = fopen(buf, "r");
        if (fp == 0) {
+               if (errno == ENOENT)
+                       errno = 0;
                fprintf(stderr, "cannot file open %s\n", buf);
                return ret;
        }