[CRIU] [PATCH 06/21] proc_parse.c: Add read_proc_selffd_link helper
Cyrill Gorcunov
gorcunov at openvz.org
Wed Jun 6 18:21:46 EDT 2012
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
include/proc_parse.h | 1 +
proc_parse.c | 15 +++++++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/include/proc_parse.h b/include/proc_parse.h
index 21e43ce..6dac56b 100644
--- a/include/proc_parse.h
+++ b/include/proc_parse.h
@@ -105,5 +105,6 @@ extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s);
extern int parse_pid_stat_small(pid_t pid, struct proc_pid_stat_small *s);
extern int parse_smaps(pid_t pid, struct list_head *vma_area_list, bool use_map_files);
extern int parse_pid_status(pid_t pid, struct proc_status_creds *);
+extern char *read_proc_selffd_link(int fd, int *len);
#endif /* PROC_PARSE_H__ */
diff --git a/proc_parse.c b/proc_parse.c
index 6ca23b9..2f943c0 100644
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -665,3 +665,18 @@ err:
}
goto out;
}
+
+char *read_proc_selffd_link(int fd, int *len)
+{
+ char local[64];
+
+ snprintf(local, sizeof(local), "/proc/self/fd/%d", fd);
+ *len = readlink(local, buf, BUF_SIZE);
+ if (*len < 0) {
+ pr_perror("Can't readlink %s", local);
+ return NULL;
+ } else
+ buf[*len] = '\0';
+
+ return buf;
+}
--
1.7.7.6
More information about the CRIU
mailing list