summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyeongsik Min <hyeongsik.min@samsung.com>2017-04-18 23:54:05 +0900
committerHyeongsik Min <hyeongsik.min@samsung.com>2017-04-19 08:29:07 +0900
commitffb328612abac49c5b11f2c05a7d043091d7c7a2 (patch)
tree6b41272539cba6e0adc682c48fbedfb8f7f95407
parent00f00ad5c8d683c0ec7cba40bb06327424031a7e (diff)
downloadmemps-ffb328612abac49c5b11f2c05a7d043091d7c7a2.tar.gz
memps-ffb328612abac49c5b11f2c05a7d043091d7c7a2.tar.bz2
memps-ffb328612abac49c5b11f2c05a7d043091d7c7a2.zip
Replace deprecated readdir_r() with readdir()
Change-Id: I88e7060aecfd0cc982fd995f66a30f643b4fd292 Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
-rw-r--r--memps.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/memps.c b/memps.c
index d944aa5..d14774e 100644
--- a/memps.c
+++ b/memps.c
@@ -461,12 +461,10 @@ static void get_memcg_info(FILE *output_fp)
{
char buf[PATH_MAX];
DIR *pdir = NULL;
- struct dirent entry;
- struct dirent *result;
+ struct dirent *entry;
struct stat path_stat;
long usage_swap;
unsigned long usage, usage_with_swap;
- int ret;
fprintf(output_fp,"====================================================================\n");
fprintf(output_fp,"MEMORY CGROUPS USAGE INFO\n");
@@ -477,15 +475,16 @@ static void get_memcg_info(FILE *output_fp)
return;
}
- while (!(ret = readdir_r(pdir, &entry, &result)) && result != NULL) {
- snprintf(buf, sizeof(buf), "%s/%s", MEMCG_PATH, entry.d_name);
+ errno = 0;
+ while ((entry = readdir(pdir)) != NULL && !errno) {
+ snprintf(buf, sizeof(buf), "%s/%s", MEMCG_PATH, entry->d_name);
/* If can't stat then ignore */
if (stat(buf, &path_stat) != 0)
continue;
/* If it's not directory or it's parent path then ignore */
if (!(S_ISDIR(path_stat.st_mode) &&
- strncmp(entry.d_name, "..", 3)))
+ strncmp(entry->d_name, "..", 3)))
continue;
usage = get_memcg_usage(buf, false);
@@ -496,7 +495,7 @@ static void get_memcg_info(FILE *output_fp)
usage_swap = 0;
/* Case of root cgroup in hierarchy */
- if (!strncmp(entry.d_name, ".", 2))
+ if (!strncmp(entry->d_name, ".", 2))
fprintf(output_fp, "%13s Mem %3ld MB (%6ld kB), Mem+Swap %3ld MB (%6ld kB), Swap %3ld MB (%6ld kB) \n\n",
MEMCG_PATH, BYTE_TO_MBYTE(usage),
BYTE_TO_KBYTE(usage),
@@ -506,7 +505,7 @@ static void get_memcg_info(FILE *output_fp)
BYTE_TO_KBYTE(usage_swap));
else
fprintf(output_fp, "memcg: %13s Mem %3ld MB (%6ld kB), Mem+Swap %3ld MB (%6ld kB), Swap %3ld MB (%6ld kB)\n",
- entry.d_name, BYTE_TO_MBYTE(usage),
+ entry->d_name, BYTE_TO_MBYTE(usage),
BYTE_TO_KBYTE(usage),
BYTE_TO_MBYTE(usage_with_swap),
BYTE_TO_KBYTE(usage_with_swap),
@@ -861,14 +860,12 @@ static void get_rss(pid_t pid, unsigned long *result)
static void show_rss(int output_type, char *output_path)
{
DIR *pDir = NULL;
- struct dirent curdir;
- struct dirent *result;
+ struct dirent *curdir;
pid_t pid;
char cmdline[PATH_MAX];
FILE *output_file = NULL;
int oom_score_adj;
unsigned long rss;
- int ret;
pDir = opendir("/proc");
if (pDir == NULL) {
@@ -891,8 +888,9 @@ static void show_rss(int output_type, char *output_path)
fprintf(output_file,
" PID RSS OOM_SCORE COMMAND\n");
- while (!(ret = readdir_r(pDir, &curdir, &result)) && result != NULL) {
- pid = atoi(curdir.d_name);
+ errno = 0;
+ while ((curdir = readdir(pDir)) != NULL && !errno) {
+ pid = atoi(curdir->d_name);
if (pid < 1 || pid > 32768 || pid == getpid())
continue;
@@ -923,8 +921,7 @@ static void show_rss(int output_type, char *output_path)
static int show_map_all_new(int output_type, char *output_path)
{
DIR *pDir = NULL;
- struct dirent curdir;
- struct dirent *result;
+ struct dirent *curdir;
unsigned int pid;
mapinfo *milist;
geminfo *glist;
@@ -948,8 +945,6 @@ static int show_map_all_new(int output_type, char *output_path)
FILE *output_file = NULL;
int oom_score_adj;
- int r;
-
pDir = opendir("/proc");
if (pDir == NULL) {
fprintf(stderr, "cannot read directory /proc.\n");
@@ -982,8 +977,9 @@ static int show_map_all_new(int output_type, char *output_path)
" 3D GEM(PSS) SWAP COMMAND\n");
}
- while (!(r = readdir_r(pDir, &curdir, &result)) && result != NULL) {
- pid = atoi(curdir.d_name);
+ errno = 0;
+ while ((curdir = readdir(pDir)) != NULL && !errno) {
+ pid = atoi(curdir->d_name);
if (pid < 1 || pid > 32768 || pid == getpid())
continue;