Commit 401b4b89 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

util: Add read_fd_link helper

To fetch name of file opened from procfs.
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b7960d77
......@@ -303,4 +303,6 @@ static inline bool dir_dots(struct dirent *de)
return !strcmp(de->d_name, ".") || !strcmp(de->d_name, "..");
}
extern int read_fd_link(int lfd, char *buf, size_t size);
#endif /* __CR_UTIL_H__ */
......@@ -420,6 +420,22 @@ bool is_anon_inode(struct statfs *statfs)
return statfs->f_type == ANON_INODE_FS_MAGIC;
}
int read_fd_link(int lfd, char *buf, size_t size)
{
char t[32];
ssize_t ret;
snprintf(t, sizeof(t), "/proc/self/fd/%d", lfd);
ret = readlink(t, buf, size);
if (ret < 0) {
pr_perror("Can't read link of fd %d\n", lfd);
return -1;
}
buf[ret] = 0;
return 0;
}
int is_anon_link_type(int lfd, char *type)
{
char link[32], aux[32];
......
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