Commit 1a7c7d04 authored by Pavel Emelyanov's avatar Pavel Emelyanov

fd: Consolidate . and .. checks in various readdir callers

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 86886b63
...@@ -168,9 +168,7 @@ static int collect_fds(pid_t pid, struct parasite_drain_fd *dfds) ...@@ -168,9 +168,7 @@ static int collect_fds(pid_t pid, struct parasite_drain_fd *dfds)
n = 0; n = 0;
while ((de = readdir(fd_dir))) { while ((de = readdir(fd_dir))) {
if (!strcmp(de->d_name, ".")) if (dir_dots(de))
continue;
if (!strcmp(de->d_name, ".."))
continue; continue;
if (n > PARASITE_MAX_FDS - 1) if (n > PARASITE_MAX_FDS - 1)
...@@ -1029,9 +1027,7 @@ static int parse_children(pid_t pid, pid_t **_c, int *_n) ...@@ -1029,9 +1027,7 @@ static int parse_children(pid_t pid, pid_t **_c, int *_n)
return -1; return -1;
while ((de = readdir(dir))) { while ((de = readdir(dir))) {
if (!strcmp(de->d_name, ".")) if (dir_dots(de))
continue;
if (!strcmp(de->d_name, ".."))
continue; continue;
file = fopen_proc(pid, "task/%s/children", de->d_name); file = fopen_proc(pid, "task/%s/children", de->d_name);
......
...@@ -507,9 +507,7 @@ static int close_old_fds(struct pstree_item *me) ...@@ -507,9 +507,7 @@ static int close_old_fds(struct pstree_item *me)
return -1; return -1;
while ((de = readdir(dir))) { while ((de = readdir(dir))) {
if (!strcmp(de->d_name, ".")) if (dir_dots(de))
continue;
if (!strcmp(de->d_name, ".."))
continue; continue;
ret = sscanf(de->d_name, "%d", &fd); ret = sscanf(de->d_name, "%d", &fd);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/statfs.h> #include <sys/statfs.h>
#include <dirent.h> #include <dirent.h>
...@@ -325,4 +325,9 @@ extern int run_scripts(char *action); ...@@ -325,4 +325,9 @@ extern int run_scripts(char *action);
extern int cr_system(int in, int out, int err, char *cmd, char *const argv[]); extern int cr_system(int in, int out, int err, char *cmd, char *const argv[]);
static inline bool dir_dots(struct dirent *de)
{
return !strcmp(de->d_name, ".") || !strcmp(de->d_name, "..");
}
#endif /* UTIL_H_ */ #endif /* UTIL_H_ */
...@@ -308,9 +308,7 @@ static int binfmt_misc_dump(struct mount_info *pm) ...@@ -308,9 +308,7 @@ static int binfmt_misc_dump(struct mount_info *pm)
return -1; return -1;
while ((de = readdir(fdir))) { while ((de = readdir(fdir))) {
if (!strcmp(de->d_name, ".")) if (dir_dots(de))
continue;
if (!strcmp(de->d_name, ".."))
continue; continue;
if (!strcmp(de->d_name, "register")) if (!strcmp(de->d_name, "register"))
continue; continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment