From a7629e8423e43d1ddb2a838552f0b0950a4bcf64f02a0e093cfeb5c104bc842a Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Fri, 13 Oct 2017 07:11:59 +0000 Subject: [PATCH 1/3] . OBS-URL: https://build.opensuse.org/package/show/Base:System/psmisc?expand=0&rev=95 --- ...to-be-able-to-use-the-mount-identity.patch | 65 ++++++++++--------- psmisc.changes | 6 ++ 2 files changed, 41 insertions(+), 30 deletions(-) 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 1e781af..3d32ed6 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 02b6674c8b57db637093a1f753075a601c460c80 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 | 530 +++++++++++++++++++++++++++---------- src/fuser.h | 19 +- testsuite/Makefile.am | 3 +- testsuite/killall.test/killall.exp | 4 + - 5 files changed, 421 insertions(+), 148 deletions(-) + 5 files changed, 426 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..d5d72a9 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,234 @@ static void clear_mntinfo(void) } } @@ -666,7 +666,7 @@ index 31ef30c..4ef7cfd 100644 + char pathname[256]; + char line[BUFSIZ]; + FILE *fp; -+ int ret = 0; ++ int ret = 0, mnt_id = 0, flags = 0; + + snprintf(pathname, 256, "/proc/%d/fdinfo/%s", pid, fd); + if ((fp = fopen(pathname, "r")) == NULL) @@ -682,37 +682,42 @@ 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) { ++ char pathname[256]; ++ struct stat lst; ++ int ret = 0; + -+ 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 && ret == 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 +747,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 +836,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 +867,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 +2330,7 @@ static int mntstat(const char *path, struct stat *buf) { char name[PATH_MAX + 1]; const char *use; @@ -872,7 +877,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 +2342,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 d14787a..3f10213 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 From a9c462ff641fb7d794766bfb005c75ce84b75202d5cf317d24761af522ff357e Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Fri, 13 Oct 2017 07:45:00 +0000 Subject: [PATCH 2/3] . OBS-URL: https://build.opensuse.org/package/show/Base:System/psmisc?expand=0&rev=96 --- ...to-be-able-to-use-the-mount-identity.patch | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) 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 3d32ed6..e998de0 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 02b6674c8b57db637093a1f753075a601c460c80 Mon Sep 17 00:00:00 2001 +From 8fa126fdf938cef959bd64d8da2aff2e7bc5dd37 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 | 530 +++++++++++++++++++++++++++---------- + src/fuser.c | 528 +++++++++++++++++++++++++++---------- src/fuser.h | 19 +- testsuite/Makefile.am | 3 +- testsuite/killall.test/killall.exp | 4 + - 5 files changed, 426 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..d5d72a9 100644 +index 31ef30c..d7fd729 100644 --- src/fuser.c +++ src/fuser.c @@ -32,6 +32,10 @@ @@ -588,7 +588,7 @@ index 31ef30c..d5d72a9 100644 { list_t *ptr, *tmp; -@@ -2005,72 +2095,234 @@ static void clear_mntinfo(void) +@@ -2005,72 +2095,232 @@ static void clear_mntinfo(void) } } @@ -661,12 +661,13 @@ index 31ef30c..d5d72a9 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, mnt_id = 0, flags = 0; ++ int mnt_id = 0, flags = 0; + + snprintf(pathname, 256, "/proc/%d/fdinfo/%s", pid, fd); + if ((fp = fopen(pathname, "r")) == NULL) @@ -690,15 +691,12 @@ index 31ef30c..d5d72a9 100644 + mnt_id++; + ret++; + } -+ + } + fclose(fp); +out: +#endif + if (!flags || !mnt_id) { -+ char pathname[256]; + struct stat lst; -+ int ret = 0; + + snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd); + if (!flags && ret == lstat(pathname, &lst) == 0) { @@ -867,7 +865,7 @@ index 31ef30c..d5d72a9 100644 /* * Determine device of links below /proc/ */ -@@ -2078,8 +2330,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; @@ -877,7 +875,7 @@ index 31ef30c..d5d72a9 100644 if ((use = realpath(path, name)) == NULL || *use != '/') { -@@ -2091,27 +2342,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); } From db0df131033f6666e3e80bb68ba77fb84c8105c789947174743ee512c07149c4 Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Fri, 13 Oct 2017 07:57:27 +0000 Subject: [PATCH 3/3] . OBS-URL: https://build.opensuse.org/package/show/Base:System/psmisc?expand=0&rev=97 --- ...Use-mountinfo-to-be-able-to-use-the-mount-identity.patch | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 e998de0..c0d872a 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 8fa126fdf938cef959bd64d8da2aff2e7bc5dd37 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 @@ -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..d7fd729 100644 +index 31ef30c..1c7c496 100644 --- src/fuser.c +++ src/fuser.c @@ -32,6 +32,10 @@ @@ -699,7 +699,7 @@ index 31ef30c..d7fd729 100644 + struct stat lst; + + snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd); -+ if (!flags && ret == lstat(pathname, &lst) == 0) { ++ if (!flags && lstat(pathname, &lst) == 0) { + if (lst.st_mode & S_IWUSR) + info->flags |= O_WRONLY; + ret++;