From: Aleksei Vereshchagin Date: Fri, 10 Aug 2018 20:06:39 +0000 (+0300) Subject: Use two buffers (statmname and statname) instead of one pidname X-Git-Tag: submit/tizen/20180820.170401~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c9dcdd50c2818b9ec09c0713acc98e2b38996486;p=sdk%2Ftools%2Fprofctl.git Use two buffers (statmname and statname) instead of one pidname --- diff --git a/profctl.c b/profctl.c index 0402ee6..288cb6d 100644 --- a/profctl.c +++ b/profctl.c @@ -109,7 +109,6 @@ static void split(char *line, char **array, int n) static void *outstat(void *arg) { - char *sline = NULL; char *pline = NULL; char *mtline = NULL; @@ -123,7 +122,8 @@ static void *outstat(void *arg) FILE *pmstat; FILE *tf = fopen("/sys/devices/system/cpu/present","r"); int tmp, ncpu; - char *pidname; + char *statmname; + char *statname; long psize = sysconf(_SC_PAGESIZE); struct statvfs fstat; @@ -149,25 +149,30 @@ static void *outstat(void *arg) exit(1); } + if (asprintf(&statmname, "/proc/%d/statm", pid) == -1) { + perror("asprintf"); + exit(1); + } - if (asprintf(&pidname, "/proc/%d/statm", pid) == -1) { + if (asprintf(&statname, "/proc/%d/stat", pid) == -1) { perror("asprintf"); exit(1); } - pmstat = fopen(pidname, "r"); + pmstat = fopen(statmname, "r"); if (pmstat == NULL) { perror("open /proc/$pid/statm"); exit(1); } - pidname[strlen(pidname) - 1] = 0; - pstat = fopen(pidname, "r"); + pstat = fopen(statname, "r"); if (pstat == NULL) { perror("open /proc/$pid/stat"); exit(1); } - free(pidname); + + free(statmname); + free(statname); while(1) { char *stats[5]; @@ -515,4 +520,3 @@ int main(int argc, char **argv) return 0; } -