mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 15:55:53 +00:00
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: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
15
eventfd.c
15
eventfd.c
@@ -29,20 +29,7 @@ struct eventfd_file_info {
|
||||
/* Checks if file desciptor @lfd is eventfd */
|
||||
int is_eventfd_link(int lfd)
|
||||
{
|
||||
char link[PATH_MAX], path[32];
|
||||
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;
|
||||
return is_anon_link_type(lfd, "[eventfd]");
|
||||
}
|
||||
|
||||
static void pr_info_eventfd(char *action, struct eventfd_file_entry *efe)
|
||||
|
15
eventpoll.c
15
eventpoll.c
@@ -36,20 +36,7 @@ static LIST_HEAD(eventpoll_tfds);
|
||||
/* Checks if file desciptor @lfd is eventfd */
|
||||
int is_eventpoll_link(int lfd)
|
||||
{
|
||||
char link[PATH_MAX], path[32];
|
||||
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;
|
||||
return is_anon_link_type(lfd, "[eventpoll]");
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
int copy_file(int fd_in, int fd_out, size_t bytes);
|
||||
bool is_anon_inode(struct statfs *statfs);
|
||||
int is_anon_link_type(int lfd, char *type);
|
||||
|
||||
#endif /* UTIL_H_ */
|
||||
|
15
inotify.c
15
inotify.c
@@ -52,20 +52,7 @@ static char fdinfo_buf[PAGE_SIZE];
|
||||
/* Checks if file desciptor @lfd is inotify */
|
||||
int is_inotify_link(int lfd)
|
||||
{
|
||||
char link[PATH_MAX], path[32];
|
||||
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;
|
||||
return is_anon_link_type(lfd, "inotify");
|
||||
}
|
||||
|
||||
void show_inotify_wd(int fd_inotify_wd, struct cr_options *o)
|
||||
|
16
util.c
16
util.c
@@ -310,3 +310,19 @@ bool is_anon_inode(struct statfs *statfs)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user