mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 22:05:36 +00:00
fd: Consolidate . and .. checks in various readdir callers
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
@@ -168,9 +168,7 @@ static int collect_fds(pid_t pid, struct parasite_drain_fd *dfds)
|
||||
|
||||
n = 0;
|
||||
while ((de = readdir(fd_dir))) {
|
||||
if (!strcmp(de->d_name, "."))
|
||||
continue;
|
||||
if (!strcmp(de->d_name, ".."))
|
||||
if (dir_dots(de))
|
||||
continue;
|
||||
|
||||
if (n > PARASITE_MAX_FDS - 1)
|
||||
@@ -1029,9 +1027,7 @@ static int parse_children(pid_t pid, pid_t **_c, int *_n)
|
||||
return -1;
|
||||
|
||||
while ((de = readdir(dir))) {
|
||||
if (!strcmp(de->d_name, "."))
|
||||
continue;
|
||||
if (!strcmp(de->d_name, ".."))
|
||||
if (dir_dots(de))
|
||||
continue;
|
||||
|
||||
file = fopen_proc(pid, "task/%s/children", de->d_name);
|
||||
|
4
files.c
4
files.c
@@ -507,9 +507,7 @@ static int close_old_fds(struct pstree_item *me)
|
||||
return -1;
|
||||
|
||||
while ((de = readdir(dir))) {
|
||||
if (!strcmp(de->d_name, "."))
|
||||
continue;
|
||||
if (!strcmp(de->d_name, ".."))
|
||||
if (dir_dots(de))
|
||||
continue;
|
||||
|
||||
ret = sscanf(de->d_name, "%d", &fd);
|
||||
|
@@ -7,7 +7,7 @@
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/statfs.h>
|
||||
#include <dirent.h>
|
||||
@@ -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[]);
|
||||
|
||||
static inline bool dir_dots(struct dirent *de)
|
||||
{
|
||||
return !strcmp(de->d_name, ".") || !strcmp(de->d_name, "..");
|
||||
}
|
||||
|
||||
#endif /* UTIL_H_ */
|
||||
|
Reference in New Issue
Block a user