fallback of name_to_handle_at
OBS-URL: https://build.opensuse.org/package/show/Base:System/psmisc?expand=0&rev=139
This commit is contained in:
parent
3269f8ae05
commit
9d6e21a714
@ -1,6 +1,6 @@
|
||||
From fe73905beaf1f7a7ec5a5c2796031987e5336fd7 Mon Sep 17 00:00:00 2001
|
||||
From 1066ab018235e9981d8770f6c94b294f8b16c7fe Mon Sep 17 00:00:00 2001
|
||||
From: Werner Fink <werner@suse.de>
|
||||
Date: Tue, 1 Feb 2022 13:15:39 +0100
|
||||
Date: Wed, 23 Feb 2022 13:58:32 +0100
|
||||
Subject: [PATCH] Use mountinfo to be able to use the mount identity
|
||||
|
||||
which allows to distinguish different mounts with the
|
||||
@ -25,13 +25,16 @@ determine the appropriate mount ID for e.g. qcow2 files.
|
||||
Determine the namespace of a process only once to speed
|
||||
up the parsing of fdinfo.
|
||||
|
||||
Add a fallback if the system call name_to_handle_at() is
|
||||
not supported by the used file system.
|
||||
|
||||
Signed-off-by: Werner Fink <werner@suse.de>
|
||||
---
|
||||
configure.ac | 15 +-
|
||||
src/fuser.c | 701 +++++++++++++++++++++++++++++++++++++++-----------
|
||||
src/fuser.c | 734 +++++++++++++++++++++++++++++++++++++++-----------
|
||||
src/fuser.h | 25 +-
|
||||
src/timeout.c | 5 +-
|
||||
4 files changed, 585 insertions(+), 161 deletions(-)
|
||||
4 files changed, 618 insertions(+), 161 deletions(-)
|
||||
|
||||
diff --git configure.ac configure.ac
|
||||
index 182a0df..d4dee51 100644
|
||||
@ -67,7 +70,7 @@ index 182a0df..d4dee51 100644
|
||||
dnl Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_CONST
|
||||
diff --git src/fuser.c src/fuser.c
|
||||
index 03e6237..79d44ef 100644
|
||||
index 03e6237..ee2ba15 100644
|
||||
--- src/fuser.c
|
||||
+++ src/fuser.c
|
||||
@@ -32,6 +32,8 @@
|
||||
@ -674,11 +677,11 @@ index 03e6237..79d44ef 100644
|
||||
- continue;
|
||||
- find_mountp++;
|
||||
- if ((find_space = strchr(find_mountp, ' ')) == NULL)
|
||||
- continue;
|
||||
- *find_space = '\0';
|
||||
- if (timeout(thestat, find_mountp, &st, 5) != 0) {
|
||||
+ if (timeout(thestat, find_mountp, &st, 5) != 0)
|
||||
continue;
|
||||
- *find_space = '\0';
|
||||
- if (timeout(thestat, find_mountp, &st, 5) != 0) {
|
||||
- continue;
|
||||
- }
|
||||
+
|
||||
/* Scan the devices */
|
||||
@ -747,7 +750,7 @@ index 03e6237..79d44ef 100644
|
||||
{
|
||||
list_t *ptr, *tmp;
|
||||
|
||||
@@ -2053,72 +2240,286 @@ static void clear_mntinfo(void)
|
||||
@@ -2053,72 +2240,319 @@ static void clear_mntinfo(void)
|
||||
}
|
||||
}
|
||||
|
||||
@ -801,8 +804,17 @@ index 03e6237..79d44ef 100644
|
||||
+ stat(mpoint, &st);
|
||||
+ mntinf->dev = st.st_dev; /* stat(2) on binary does not see subvol dev */
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
- append(mnt, mntinfo);
|
||||
- mnt->mpoint = ((char *)mnt) + alignof(mntinfo_t);
|
||||
- strcpy(mnt->mpoint, mpoint);
|
||||
- mnt->nlen = nlen;
|
||||
- mnt->parid = parid;
|
||||
- mnt->dev = makedev(maj, min);
|
||||
- mnt->id = mid;
|
||||
- if (mid > max)
|
||||
- max = mid;
|
||||
}
|
||||
+#else
|
||||
+ if ((mnt = fopen(PROC_MOUNTS, "r")) == (FILE *) 0)
|
||||
+ return;
|
||||
@ -822,17 +834,8 @@ index 03e6237..79d44ef 100644
|
||||
+ if (mntinf && strncmp(devname, "/dev/", 5) == 0 && stat(devname, &st) == 0) {
|
||||
+ if (st.st_rdev != 0 && mntinf->dev != st.st_rdev)
|
||||
+ mntinf->vol = st.st_rdev;
|
||||
}
|
||||
- append(mnt, mntinfo);
|
||||
- mnt->mpoint = ((char *)mnt) + alignof(mntinfo_t);
|
||||
- strcpy(mnt->mpoint, mpoint);
|
||||
- mnt->nlen = nlen;
|
||||
- mnt->parid = parid;
|
||||
- mnt->dev = makedev(maj, min);
|
||||
- mnt->id = mid;
|
||||
- if (mid > max)
|
||||
- max = mid;
|
||||
}
|
||||
+ }
|
||||
+ }
|
||||
+#endif
|
||||
fclose(mnt);
|
||||
+}
|
||||
@ -920,7 +923,12 @@ index 03e6237..79d44ef 100644
|
||||
+ }
|
||||
+ return ret == 2 ? 0 : -1;
|
||||
+}
|
||||
+
|
||||
|
||||
- /* 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) {
|
||||
+#if defined(HAS_NAME_TO_HANDLE_AT)
|
||||
+static ino_t
|
||||
+get_namespace(const pid_t pid)
|
||||
@ -943,8 +951,41 @@ index 03e6237..79d44ef 100644
|
||||
+ int mnt_id = -1;
|
||||
+
|
||||
+ errno = 0;
|
||||
+ if (name_to_handle_at(0, path, &fh.handle, &mnt_id, 0) == -1)
|
||||
+ mnt_id = -1;
|
||||
+ if (name_to_handle_at(0, path, &fh.handle, &mnt_id, 0) == -1) {
|
||||
+ const static char delimiters[] = ": \t\n";
|
||||
+ char fdinfo[PATH_MAX+1];
|
||||
+ char line[BUFSIZ];
|
||||
+ FILE* fp;
|
||||
+ int fd;
|
||||
+
|
||||
+ if (errno != EOPNOTSUPP)
|
||||
+ return -1;
|
||||
+ fd = open(path, O_PATH);
|
||||
+ if (fd < 0)
|
||||
+ return -1;
|
||||
+
|
||||
+ snprintf(fdinfo, PATH_MAX, "/proc/self/fdinfo/%d", fd);
|
||||
+ if ((fp = fopen(fdinfo, "r")) == NULL) {
|
||||
+ close(fd);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ while (fgets(line, BUFSIZ, fp)) {
|
||||
+ char *xp, *vp, *ep;
|
||||
+ unsigned long ul;
|
||||
+ xp = strtok(&line[0], delimiters);
|
||||
+ if (!xp || *xp == 0)
|
||||
+ continue;
|
||||
+ vp = strtok(NULL, delimiters);
|
||||
+ if (!vp || *vp == 0)
|
||||
+ continue;
|
||||
+ if (strcmp(xp, "mnt_id") == 0 && (ul = strtoul(vp, &ep, 0)) != ULONG_MAX && ep && *ep == 0) {
|
||||
+ mnt_id = (int)ul;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ fclose(fp);
|
||||
+ close(fd);
|
||||
+ }
|
||||
+ return mnt_id;
|
||||
+}
|
||||
+#endif
|
||||
@ -964,12 +1005,7 @@ index 03e6237..79d44ef 100644
|
||||
+#if defined(HAS_NAME_TO_HANDLE_AT)
|
||||
+ if (mnt_id >= 0) {
|
||||
+ list_t *ptr;
|
||||
|
||||
- /* 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) {
|
||||
+
|
||||
+ errno = ENOENT;
|
||||
+ list_for_each(ptr, &mntinfo) {
|
||||
mntinfo_t *mnt = list_entry(ptr, mntinfo_t);
|
||||
@ -1047,12 +1083,12 @@ index 03e6237..79d44ef 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;
|
||||
@ -1078,7 +1114,7 @@ index 03e6237..79d44ef 100644
|
||||
/*
|
||||
* Determine device of links below /proc/
|
||||
*/
|
||||
@@ -2126,8 +2527,7 @@ static int mntstat(const char *path, struct stat *buf)
|
||||
@@ -2126,8 +2560,7 @@ static int mntstat(const char *path, struct stat *buf)
|
||||
{
|
||||
char name[PATH_MAX + 1];
|
||||
const char *use;
|
||||
@ -1088,7 +1124,7 @@ index 03e6237..79d44ef 100644
|
||||
|
||||
if ((use = realpath(path, name)) == NULL || *use != '/')
|
||||
{
|
||||
@@ -2139,27 +2539,26 @@ static int mntstat(const char *path, struct stat *buf)
|
||||
@@ -2139,27 +2572,26 @@ static int mntstat(const char *path, struct stat *buf)
|
||||
errno = 0;
|
||||
return stat(path, buf);
|
||||
}
|
||||
|
@ -1,3 +1,10 @@
|
||||
-------------------------------------------------------------------
|
||||
Wed Feb 23 13:04:06 UTC 2022 - Dr. Werner Fink <werner@suse.de>
|
||||
|
||||
- Change patch 0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch
|
||||
* Add a fallback if the system call name_to_handle_at() is
|
||||
not supported by the used file system.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Tue Feb 1 12:39:16 UTC 2022 - Dr. Werner Fink <werner@suse.de>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user