Commit 50ff1438 authored by Pavel Emelyanov's avatar Pavel Emelyanov

anon: Factor out checking for anon inode link types

Funny, but kernel reports some of them with []-s and some (well,
ok, inotofy only) without...
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 6cebc484
...@@ -29,20 +29,7 @@ struct eventfd_file_info { ...@@ -29,20 +29,7 @@ struct eventfd_file_info {
/* Checks if file desciptor @lfd is eventfd */ /* Checks if file desciptor @lfd is eventfd */
int is_eventfd_link(int lfd) int is_eventfd_link(int lfd)
{ {
char link[PATH_MAX], path[32]; return is_anon_link_type(lfd, "[eventfd]");
ssize_t ret;
snprintf(path, sizeof(path), "/proc/self/fd/%d", lfd);
ret = readlink(path, link, sizeof(link));
if (ret < 0) {
pr_perror("Can't read link of fd %d\n", lfd);
return 0;
}
link[ret] = 0;
if (!strcmp(link, "anon_inode:[eventfd]"))
return 1;
return 0;
} }
static void pr_info_eventfd(char *action, struct eventfd_file_entry *efe) static void pr_info_eventfd(char *action, struct eventfd_file_entry *efe)
......
...@@ -36,20 +36,7 @@ static LIST_HEAD(eventpoll_tfds); ...@@ -36,20 +36,7 @@ static LIST_HEAD(eventpoll_tfds);
/* Checks if file desciptor @lfd is eventfd */ /* Checks if file desciptor @lfd is eventfd */
int is_eventpoll_link(int lfd) int is_eventpoll_link(int lfd)
{ {
char link[PATH_MAX], path[32]; return is_anon_link_type(lfd, "[eventpoll]");
ssize_t ret;
snprintf(path, sizeof(path), "/proc/self/fd/%d", lfd);
ret = readlink(path, link, sizeof(link));
if (ret < 0) {
pr_perror("Can't read link of fd %d\n", lfd);
return 0;
}
link[ret] = 0;
if (!strcmp(link, "anon_inode:[eventpoll]"))
return 1;
return 0;
} }
static void pr_info_eventpoll_tfd(char *action, struct eventpoll_tfd_entry *e) static void pr_info_eventpoll_tfd(char *action, struct eventpoll_tfd_entry *e)
......
...@@ -279,5 +279,6 @@ static inline dev_t kdev_to_odev(u32 kdev) ...@@ -279,5 +279,6 @@ static inline dev_t kdev_to_odev(u32 kdev)
int copy_file(int fd_in, int fd_out, size_t bytes); int copy_file(int fd_in, int fd_out, size_t bytes);
bool is_anon_inode(struct statfs *statfs); bool is_anon_inode(struct statfs *statfs);
int is_anon_link_type(int lfd, char *type);
#endif /* UTIL_H_ */ #endif /* UTIL_H_ */
...@@ -52,20 +52,7 @@ static char fdinfo_buf[PAGE_SIZE]; ...@@ -52,20 +52,7 @@ static char fdinfo_buf[PAGE_SIZE];
/* Checks if file desciptor @lfd is inotify */ /* Checks if file desciptor @lfd is inotify */
int is_inotify_link(int lfd) int is_inotify_link(int lfd)
{ {
char link[PATH_MAX], path[32]; return is_anon_link_type(lfd, "inotify");
ssize_t ret;
snprintf(path, sizeof(path), "/proc/self/fd/%d", lfd);
ret = readlink(path, link, sizeof(link));
if (ret < 0) {
pr_perror("Can't read link of fd %d\n", lfd);
return 0;
}
link[ret] = 0;
if (!strcmp(link, "anon_inode:inotify"))
return 1;
return 0;
} }
void show_inotify_wd(int fd_inotify_wd, struct cr_options *o) void show_inotify_wd(int fd_inotify_wd, struct cr_options *o)
......
...@@ -310,3 +310,19 @@ bool is_anon_inode(struct statfs *statfs) ...@@ -310,3 +310,19 @@ bool is_anon_inode(struct statfs *statfs)
{ {
return statfs->f_type == ANON_INODE_FS_MAGIC; return statfs->f_type == ANON_INODE_FS_MAGIC;
} }
int is_anon_link_type(int lfd, char *type)
{
char link[PATH_MAX], aux[32];
ssize_t ret;
snprintf(aux, sizeof(aux), "/proc/self/fd/%d", lfd);
ret = readlink(aux, link, sizeof(link));
if (ret < 0) {
pr_perror("Can't read link of fd %d\n", lfd);
return 0;
}
link[ret] = 0;
snprintf(aux, sizeof(aux), "anon_inode:%s", type);
return !strcmp(link, aux);
}
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