diff --git a/0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch b/0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch index 5a1cd71..432506c 100644 --- a/0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch +++ b/0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch @@ -1,4 +1,4 @@ -From 60bbf03a076374e20aa62e1f3297be170403fcb7 Mon Sep 17 00:00:00 2001 +From c0652a4686d259dabdb3e96498d8dda7cdc9da03 Mon Sep 17 00:00:00 2001 From: Werner Fink Date: Thu, 29 Jun 2017 15:18:28 +0200 Subject: [PATCH] Use mountinfo to be able to use the mount identity @@ -14,11 +14,11 @@ get the real mount ID for each file Signed-off-by: Werner Fink --- configure.ac | 18 +- - src/fuser.c | 525 +++++++++++++++++++++++++++---------- + src/fuser.c | 528 +++++++++++++++++++++++++++---------- src/fuser.h | 19 +- testsuite/Makefile.am | 3 +- testsuite/killall.test/killall.exp | 4 + - 5 files changed, 421 insertions(+), 148 deletions(-) + 5 files changed, 424 insertions(+), 148 deletions(-) diff --git configure.ac configure.ac index 176a2fc..d8d3366 100644 @@ -64,7 +64,7 @@ index 176a2fc..d8d3366 100644 dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST diff --git src/fuser.c src/fuser.c -index 31ef30c..4ef7cfd 100644 +index 31ef30c..1c7c496 100644 --- src/fuser.c +++ src/fuser.c @@ -32,6 +32,10 @@ @@ -588,7 +588,7 @@ index 31ef30c..4ef7cfd 100644 { list_t *ptr, *tmp; -@@ -2005,72 +2095,229 @@ static void clear_mntinfo(void) +@@ -2005,72 +2095,232 @@ static void clear_mntinfo(void) } } @@ -661,12 +661,13 @@ index 31ef30c..4ef7cfd 100644 +static int +get_fdinfo(const pid_t pid, const char *fd, struct fdinfo *info) +{ ++ int ret = 0; ++ char pathname[256]; +#if defined(HAS_FDINFO) + const static char delimiters[] = ": \t\n"; -+ char pathname[256]; + char line[BUFSIZ]; + FILE *fp; -+ int ret = 0; ++ int mnt_id = 0, flags = 0; + + snprintf(pathname, 256, "/proc/%d/fdinfo/%s", pid, fd); + if ((fp = fopen(pathname, "r")) == NULL) @@ -682,37 +683,39 @@ index 31ef30c..4ef7cfd 100644 + continue; + if (strcmp(fp, "flags") == 0 && (ul = strtoul(vp, &ep, 0)) != ULONG_MAX && ep && *ep == 0) { + info->flags = (mode_t)ul; ++ flags++; + ret++; + } + if (strcmp(fp, "mnt_id") == 0 && (ul = strtoul(vp, &ep, 0)) != ULONG_MAX && ep && *ep == 0) { + info->mnt_id = (int)ul; ++ mnt_id++; + ret++; + } -+ + } + fclose(fp); +out: -+#else -+ char pathname[256], *realname; -+ struct stat lst; -+ int ret = 0; ++#endif ++ if (!flags || !mnt_id) { ++ struct stat lst; + -+ snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd); -+ if (lstat(pathname, &lst) == 0) { -+ if (lst.st_mode & S_IWUSR) -+ info->flags |= O_WRONLY; -+ ret++; -+ } -+ -+ realname = expandpath(pathname); -+ if (realname) { -+ mntinfo_t *mountinfo; -+ if (find_mountpoint(realname, &mountinfo) == 0) { -+ info->mnt_id = mountinfo->id; ++ snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd); ++ if (!flags && lstat(pathname, &lst) == 0) { ++ if (lst.st_mode & S_IWUSR) ++ info->flags |= O_WRONLY; + ret++; + } ++ ++ if (!mnt_id) { ++ char *realname = expandpath(pathname); ++ if (realname) { ++ mntinfo_t *mountinfo; ++ if (find_mountpoint(realname, &mountinfo) == 0) { ++ info->mnt_id = mountinfo->id; ++ ret++; ++ } ++ } ++ } + } -+#endif + return ret == 2 ? 0 : -1; +} + @@ -742,14 +745,14 @@ index 31ef30c..4ef7cfd 100644 + int mnt_id = get_mountid(path); +#endif + int ret = -1; ++ ++ *mountinfo = NULL; - /* Sort mount points accordingly to the reverse mount order */ - initial(&sort); - for (mid = 1; mid <= max; mid++) { - list_t *ptr, *tmp; - list_for_each_safe(ptr, tmp, &mntinfo) { -+ *mountinfo = NULL; -+ +#if defined(HAS_NAME_TO_HANDLE_AT) + if (mnt_id >= 0) { + list_t *ptr; @@ -831,12 +834,12 @@ index 31ef30c..4ef7cfd 100644 - if (mid != mnt->parid) + + if (nlen != mnt->nlen) -+ continue; -+ -+ if (strcmp(use, mnt->mpoint)) continue; - move_head(ptr, &sort); + ++ if (strcmp(use, mnt->mpoint)) ++ continue; ++ + ret = 0; + errno = 0; + *mountinfo = mnt; @@ -862,7 +865,7 @@ index 31ef30c..4ef7cfd 100644 /* * Determine device of links below /proc/ */ -@@ -2078,8 +2325,7 @@ static int mntstat(const char *path, struct stat *buf) +@@ -2078,8 +2328,7 @@ static int mntstat(const char *path, struct stat *buf) { char name[PATH_MAX + 1]; const char *use; @@ -872,7 +875,7 @@ index 31ef30c..4ef7cfd 100644 if ((use = realpath(path, name)) == NULL || *use != '/') { -@@ -2091,27 +2337,26 @@ static int mntstat(const char *path, struct stat *buf) +@@ -2091,27 +2340,26 @@ static int mntstat(const char *path, struct stat *buf) errno = 0; return stat(path, buf); } diff --git a/psmisc.changes b/psmisc.changes index a95f39c..77cbf11 100644 --- a/psmisc.changes +++ b/psmisc.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Oct 13 07:10:39 UTC 2017 - werner@suse.de + +- Modify patch 0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch + to run even on older kernels missing mnt_id tag in fdinfo + ------------------------------------------------------------------- Mon Sep 18 10:17:52 UTC 2017 - werner@suse.de