Dr. Werner Fink 2017-10-13 07:11:59 +00:00 committed by Git OBS Bridge
parent 19f4960744
commit a7629e8423
2 changed files with 41 additions and 30 deletions

View File

@ -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 <werner@suse.de> From: Werner Fink <werner@suse.de>
Date: Thu, 29 Jun 2017 15:18:28 +0200 Date: Thu, 29 Jun 2017 15:18:28 +0200
Subject: [PATCH] Use mountinfo to be able to use the mount identity 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 <werner@suse.de> Signed-off-by: Werner Fink <werner@suse.de>
--- ---
configure.ac | 18 +- configure.ac | 18 +-
src/fuser.c | 525 +++++++++++++++++++++++++++---------- src/fuser.c | 530 +++++++++++++++++++++++++++----------
src/fuser.h | 19 +- src/fuser.h | 19 +-
testsuite/Makefile.am | 3 +- testsuite/Makefile.am | 3 +-
testsuite/killall.test/killall.exp | 4 + 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 diff --git configure.ac configure.ac
index 176a2fc..d8d3366 100644 index 176a2fc..d8d3366 100644
@ -64,7 +64,7 @@ index 176a2fc..d8d3366 100644
dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST AC_C_CONST
diff --git src/fuser.c src/fuser.c diff --git src/fuser.c src/fuser.c
index 31ef30c..4ef7cfd 100644 index 31ef30c..d5d72a9 100644
--- src/fuser.c --- src/fuser.c
+++ src/fuser.c +++ src/fuser.c
@@ -32,6 +32,10 @@ @@ -32,6 +32,10 @@
@ -588,7 +588,7 @@ index 31ef30c..4ef7cfd 100644
{ {
list_t *ptr, *tmp; 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 pathname[256];
+ char line[BUFSIZ]; + char line[BUFSIZ];
+ FILE *fp; + FILE *fp;
+ int ret = 0; + int ret = 0, mnt_id = 0, flags = 0;
+ +
+ snprintf(pathname, 256, "/proc/%d/fdinfo/%s", pid, fd); + snprintf(pathname, 256, "/proc/%d/fdinfo/%s", pid, fd);
+ if ((fp = fopen(pathname, "r")) == NULL) + if ((fp = fopen(pathname, "r")) == NULL)
@ -682,37 +682,42 @@ index 31ef30c..4ef7cfd 100644
+ continue; + continue;
+ if (strcmp(fp, "flags") == 0 && (ul = strtoul(vp, &ep, 0)) != ULONG_MAX && ep && *ep == 0) { + if (strcmp(fp, "flags") == 0 && (ul = strtoul(vp, &ep, 0)) != ULONG_MAX && ep && *ep == 0) {
+ info->flags = (mode_t)ul; + info->flags = (mode_t)ul;
+ flags++;
+ ret++; + ret++;
+ } + }
+ if (strcmp(fp, "mnt_id") == 0 && (ul = strtoul(vp, &ep, 0)) != ULONG_MAX && ep && *ep == 0) { + if (strcmp(fp, "mnt_id") == 0 && (ul = strtoul(vp, &ep, 0)) != ULONG_MAX && ep && *ep == 0) {
+ info->mnt_id = (int)ul; + info->mnt_id = (int)ul;
+ mnt_id++;
+ ret++; + ret++;
+ } + }
+ +
+ } + }
+ fclose(fp); + fclose(fp);
+out: +out:
+#else +#endif
+ char pathname[256], *realname; + if (!flags || !mnt_id) {
+ struct stat lst; + char pathname[256];
+ int ret = 0; + struct stat lst;
+ int ret = 0;
+ +
+ snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd); + snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd);
+ if (lstat(pathname, &lst) == 0) { + if (!flags && ret == lstat(pathname, &lst) == 0) {
+ if (lst.st_mode & S_IWUSR) + if (lst.st_mode & S_IWUSR)
+ info->flags |= O_WRONLY; + info->flags |= O_WRONLY;
+ ret++;
+ }
+
+ realname = expandpath(pathname);
+ if (realname) {
+ mntinfo_t *mountinfo;
+ if (find_mountpoint(realname, &mountinfo) == 0) {
+ info->mnt_id = mountinfo->id;
+ ret++; + 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; + return ret == 2 ? 0 : -1;
+} +}
+ +
@ -742,14 +747,14 @@ index 31ef30c..4ef7cfd 100644
+ int mnt_id = get_mountid(path); + int mnt_id = get_mountid(path);
+#endif +#endif
+ int ret = -1; + int ret = -1;
+
+ *mountinfo = NULL;
- /* Sort mount points accordingly to the reverse mount order */ - /* Sort mount points accordingly to the reverse mount order */
- initial(&sort); - initial(&sort);
- for (mid = 1; mid <= max; mid++) { - for (mid = 1; mid <= max; mid++) {
- list_t *ptr, *tmp; - list_t *ptr, *tmp;
- list_for_each_safe(ptr, tmp, &mntinfo) { - list_for_each_safe(ptr, tmp, &mntinfo) {
+ *mountinfo = NULL;
+
+#if defined(HAS_NAME_TO_HANDLE_AT) +#if defined(HAS_NAME_TO_HANDLE_AT)
+ if (mnt_id >= 0) { + if (mnt_id >= 0) {
+ list_t *ptr; + list_t *ptr;
@ -831,12 +836,12 @@ index 31ef30c..4ef7cfd 100644
- if (mid != mnt->parid) - if (mid != mnt->parid)
+ +
+ if (nlen != mnt->nlen) + if (nlen != mnt->nlen)
+ continue;
+
+ if (strcmp(use, mnt->mpoint))
continue; continue;
- move_head(ptr, &sort); - move_head(ptr, &sort);
+ +
+ if (strcmp(use, mnt->mpoint))
+ continue;
+
+ ret = 0; + ret = 0;
+ errno = 0; + errno = 0;
+ *mountinfo = mnt; + *mountinfo = mnt;
@ -862,7 +867,7 @@ index 31ef30c..4ef7cfd 100644
/* /*
* Determine device of links below /proc/ * 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]; char name[PATH_MAX + 1];
const char *use; const char *use;
@ -872,7 +877,7 @@ index 31ef30c..4ef7cfd 100644
if ((use = realpath(path, name)) == NULL || *use != '/') 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; errno = 0;
return stat(path, buf); return stat(path, buf);
} }

View File

@ -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 Mon Sep 18 10:17:52 UTC 2017 - werner@suse.de