[CRIU] [PATCH 1/3] proc_parse: Add helpers for debug sake
Cyrill Gorcunov
gorcunov at gmail.com
Fri Dec 7 15:43:29 MSK 2018
Suitable when need to look into details of data without
calling some external tools.
Note there is no real use of these helpers now but I've
been using them a lot when inspecting problems with
restore: instead of stopping restore I simply call
the helpers from various restore stages and compared
the outputs.
Still feel free to simply drop the patch.
Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
criu/include/proc_parse.h | 4 ++
criu/proc_parse.c | 77 +++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
diff --git a/criu/include/proc_parse.h b/criu/include/proc_parse.h
index 96a097b3d8f3..01bac412f3d9 100644
--- a/criu/include/proc_parse.h
+++ b/criu/include/proc_parse.h
@@ -102,4 +102,8 @@ extern bool is_vma_range_fmt(char *line);
extern void parse_vmflags(char *buf, u32 *flags, u64 *madv, int *io_pf);
extern int parse_uptime(uint64_t *upt);
+extern void debug_mountinfo(char *prefix, pid_t pid);
+extern void debug_lsdir(char *prefix, char *path);
+extern void debug_lsdirfd(char *prefix, int rfd, char *path);
+
#endif /* __CR_PROC_PARSE_H__ */
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index 1a5722eaf42b..b62c4395e5cb 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -41,6 +41,7 @@
#include "timerfd.h"
#include "path.h"
#include "fault-injection.h"
+#include "criu-log.h"
#include "protobuf.h"
#include "images/fdinfo.pb-c.h"
@@ -1465,6 +1466,82 @@ static bool should_skip_mount(const char *mountpoint)
return false;
}
+void debug_mountinfo(char *prefix, pid_t pid)
+{
+ char buf[4096];
+ char path[64];
+ FILE *f;
+
+ if (pr_quelled(LOG_DEBUG))
+ return;
+
+ snprintf(path, sizeof(path), "/proc/%d/mountinfo", pid);
+ f = fopen(path, "r");
+ if (!f) {
+ pr_perror("%s:%s %d: Can't open %s", __func__, prefix, pid, path);
+ return;
+ }
+
+ while (fgets(buf, sizeof(buf), f))
+ pr_debug("%s:%s %d: %s", __func__, prefix, pid, buf);
+ fclose(f);
+}
+
+void debug_lsdirfd(char *prefix, int rfd, char *path)
+{
+ struct dirent *de;
+ DIR *dir;
+ int fd;
+
+ if (pr_quelled(LOG_DEBUG))
+ return;
+
+ fd = openat(rfd, path, O_RDONLY | O_DIRECTORY, 0);
+ if (fd < 0) {
+ pr_perror("%s:%s Can't open %d:%s", __func__, prefix, rfd, path);
+ return;
+ }
+
+ dir = fdopendir(fd);
+ if (!dir) {
+ pr_perror("%s:%s Can't open %d:%s", __func__, prefix, rfd, path);
+ close(fd);
+ return;
+ }
+ for (de = readdir(dir); de; de = readdir(dir)) {
+ if (!strcmp(de->d_name, ".") ||
+ !strcmp(de->d_name, ".."))
+ continue;
+ pr_debug("%s:%s d_ino %8ld d_name %s\n",
+ __func__, prefix, de->d_ino, de->d_name);
+ }
+ closedir(dir);
+ close(fd);
+}
+
+void debug_lsdir(char *prefix, char *path)
+{
+ struct dirent *de;
+ DIR *dir;
+
+ if (pr_quelled(LOG_DEBUG))
+ return;
+
+ dir = opendir(path);
+ if (!dir) {
+ pr_perror("%s:%s Can't open %s", __func__, prefix, path);
+ return;
+ }
+ for (de = readdir(dir); de; de = readdir(dir)) {
+ if (!strcmp(de->d_name, ".") ||
+ !strcmp(de->d_name, ".."))
+ continue;
+ pr_debug("%s:%s d_ino %8ld d_name %s\n",
+ __func__, prefix, de->d_ino, de->d_name);
+ }
+ closedir(dir);
+}
+
struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid, bool for_dump)
{
struct mount_info *list = NULL;
--
2.17.2
More information about the CRIU
mailing list