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 a89aa3f..f2d157e 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 d7487838d0c79bd007e63e9ba9f7933cec40e3c9 Mon Sep 17 00:00:00 2001 +From 28805c3dda0ce9c78f046974454c0bb8dfee615b 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 | 528 +++++++++++++++++++++++++++---------- + src/fuser.c | 540 +++++++++++++++++++++-------- src/fuser.h | 19 +- testsuite/Makefile.am | 3 +- testsuite/killall.test/killall.exp | 4 + - 5 files changed, 424 insertions(+), 148 deletions(-) + 5 files changed, 436 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..a204f08 100644 +index 31ef30c..e5337cd 100644 --- src/fuser.c +++ src/fuser.c @@ -32,6 +32,10 @@ @@ -227,11 +227,11 @@ index 31ef30c..a204f08 100644 (unsigned long)this_name->st.st_dev, - (unsigned long)this_name->st.st_ino); + (unsigned long)this_name->st.st_ino, -+ mountinfo.id, mountinfo.isnfs ? "yes" : "no"); ++ mountinfo->id, mountinfo->isnfs ? "yes" : "no"); #endif /* DEBUG */ add_inode(ino_list, this_name, this_name->st.st_dev, this_name->st.st_ino); -@@ -501,11 +515,39 @@ parse_mounts(struct names *this_name, struct device_list **dev_list, +@@ -501,11 +515,51 @@ parse_mounts(struct names *this_name, struct device_list **dev_list, const opt_type opts) { dev_t match_device; @@ -247,7 +247,17 @@ index 31ef30c..a204f08 100644 + count = 0; + list_for_each(ptr, &mntinfo) { + mntinfo_t *mnt = list_entry(ptr, mntinfo_t); -+ if (match_device != mnt->dev || this_name->mnt_id != mnt->id) ++ if (match_device != mnt->dev) ++ continue; ++ if (S_ISBLK(this_name->st.st_mode)) { ++ /* Skip mount IDs check if a block device ++ * was specified */ ++ this_name->mnt_id = mnt->id; ++ add_device(dev_list, this_name, match_device); ++ count++; ++ continue; ++ } ++ if (this_name->mnt_id != mnt->id) + continue; + if (!mountinfo) + mountinfo = mnt; @@ -264,14 +274,16 @@ index 31ef30c..a204f08 100644 + errno = ENOTUNIQ; + fprintf(stderr, + _("The device %u:%u is not unique. Please change!\n"), -+ major(mountinfo->dev), minor(mountinfo->dev)); ++ major(match_device), minor(match_device)); + /* return -1 */ + } ++ if (S_ISBLK(this_name->st.st_mode)) ++ return 0; + this_name->mnt_id = mountinfo->id; add_device(dev_list, this_name, match_device); return 0; } -@@ -620,7 +662,7 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list) +@@ -620,7 +674,7 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list) fprintf(stderr, _("Unknown local port AF %d\n"), res->ai_family); freeaddrinfo(res); @@ -280,7 +292,7 @@ index 31ef30c..a204f08 100644 return -1; } freeaddrinfo(res); -@@ -683,10 +725,12 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list) +@@ -683,10 +737,12 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list) break; #endif } @@ -296,7 +308,7 @@ index 31ef30c..a204f08 100644 } return 1; } -@@ -1161,16 +1205,11 @@ int main(int argc, char *argv[]) +@@ -1161,16 +1217,11 @@ int main(int argc, char *argv[]) skip_argv = 1; //while(option != '\0') option++; if (strcmp(argv[argc_cnt], "tcp") == 0) @@ -318,7 +330,7 @@ index 31ef30c..a204f08 100644 else usage(_ ("Invalid namespace name")); -@@ -1210,7 +1249,7 @@ int main(int argc, char *argv[]) +@@ -1210,7 +1261,7 @@ int main(int argc, char *argv[]) } #if defined(WITH_MOUNTINFO_LIST) @@ -327,7 +339,7 @@ index 31ef30c..a204f08 100644 thestat = mntstat; #endif /* an option */ -@@ -1524,7 +1563,7 @@ print_matches(struct names *names_head, const opt_type opts, +@@ -1524,7 +1575,7 @@ print_matches(struct names *names_head, const opt_type opts, } @@ -336,7 +348,7 @@ index 31ef30c..a204f08 100644 { char pathname[256]; struct stat *st; -@@ -1536,6 +1575,15 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename) +@@ -1536,6 +1587,15 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename) free(st); return NULL; } @@ -352,7 +364,7 @@ index 31ef30c..a204f08 100644 return st; } -@@ -1550,18 +1598,19 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, +@@ -1550,18 +1610,19 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, struct inode_list *ino_tmp; struct device_list *dev_tmp; struct unixsocket_list *sock_tmp; @@ -377,7 +389,7 @@ index 31ef30c..a204f08 100644 pid, dirname, direntry->d_name); if (timeout(thestat, filepath, &st, 5) != 0) { -@@ -1586,9 +1635,12 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, +@@ -1586,9 +1647,12 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, dev_tmp = dev_tmp->next) { if (thedev != dev_tmp->device) continue; @@ -392,7 +404,7 @@ index 31ef30c..a204f08 100644 add_matched_proc(dev_tmp->name, pid, uid, ACCESS_FILEWR | -@@ -1610,9 +1662,10 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, +@@ -1610,9 +1674,10 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, continue; } if (st.st_ino == ino_tmp->inode) { @@ -405,7 +417,7 @@ index 31ef30c..a204f08 100644 add_matched_proc(ino_tmp->name, pid, uid, ACCESS_FILEWR | -@@ -1641,18 +1694,30 @@ check_map(const pid_t pid, const char *filename, +@@ -1641,18 +1706,30 @@ check_map(const pid_t pid, const char *filename, FILE *fp; unsigned long long tmp_inode; unsigned int tmp_maj, tmp_min; @@ -441,7 +453,7 @@ index 31ef30c..a204f08 100644 add_matched_proc(dev_tmp->name, pid, uid, access); for (ino_tmp = ino_head; ino_tmp != NULL; -@@ -1661,7 +1726,8 @@ check_map(const pid_t pid, const char *filename, +@@ -1661,7 +1738,8 @@ check_map(const pid_t pid, const char *filename, && ino_tmp->inode == tmp_inode) add_matched_proc(ino_tmp->name, pid, uid, access); @@ -451,7 +463,7 @@ index 31ef30c..a204f08 100644 } fclose(fp); } -@@ -1682,6 +1748,7 @@ static uid_t getpiduid(const pid_t pid) +@@ -1682,6 +1760,7 @@ static uid_t getpiduid(const pid_t pid) * fill_unix_cache : Create a list of Unix sockets * This list is used later for matching purposes */ @@ -459,7 +471,7 @@ index 31ef30c..a204f08 100644 void fill_unix_cache(struct unixsocket_list **unixsocket_head) { FILE *fp; -@@ -1698,6 +1765,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) +@@ -1698,6 +1777,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) while (fgets(line, BUFSIZ, fp) != NULL) { char *path; char *scanned_path = NULL; @@ -468,7 +480,7 @@ index 31ef30c..a204f08 100644 if (sscanf(line, "%*x: %*x %*x %*x %*x %*d %d %ms", &scanned_inode, &scanned_path) != 2) { if (scanned_path) -@@ -1713,6 +1782,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) +@@ -1713,6 +1794,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) free(path); continue; } @@ -477,7 +489,7 @@ index 31ef30c..a204f08 100644 if ((newsocket = (struct unixsocket_list *) malloc(sizeof(struct unixsocket_list))) == NULL) { free(path); -@@ -1721,6 +1792,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) +@@ -1721,6 +1804,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) newsocket->sun_name = strdup(scanned_path); newsocket->inode = st.st_ino; newsocket->dev = st.st_dev; @@ -485,7 +497,7 @@ index 31ef30c..a204f08 100644 newsocket->net_inode = scanned_inode; newsocket->next = *unixsocket_head; *unixsocket_head = newsocket; -@@ -1733,6 +1805,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) +@@ -1733,6 +1817,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) /* * Free up the list of Unix sockets */ @@ -493,7 +505,7 @@ index 31ef30c..a204f08 100644 void clear_unix_cache(struct unixsocket_list **unixsocket_head) { while(*unixsocket_head != NULL) { -@@ -1900,30 +1973,22 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, +@@ -1900,30 +1985,22 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, { struct device_list *dev_tmp; struct inode_list *ino_tmp; @@ -534,7 +546,7 @@ index 31ef30c..a204f08 100644 add_special_proc(dev_tmp->name, PTYPE_MOUNT, 0, find_mountp); } -@@ -1935,7 +2000,6 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, +@@ -1935,7 +2012,6 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, find_mountp); } } @@ -542,7 +554,7 @@ index 31ef30c..a204f08 100644 } static void -@@ -1985,16 +2049,42 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head, +@@ -1985,16 +2061,42 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head, fclose(fp); } @@ -588,7 +600,7 @@ index 31ef30c..a204f08 100644 { list_t *ptr, *tmp; -@@ -2005,72 +2095,232 @@ static void clear_mntinfo(void) +@@ -2005,72 +2107,232 @@ static void clear_mntinfo(void) } } @@ -668,7 +680,12 @@ index 31ef30c..a204f08 100644 + char line[BUFSIZ]; + FILE *fp; + int mnt_id = 0, flags = 0; -+ + +- /* 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) { + snprintf(pathname, 256, "/proc/%d/fdinfo/%s", pid, fd); + if ((fp = fopen(pathname, "r")) == NULL) + goto out; @@ -747,12 +764,7 @@ index 31ef30c..a204f08 100644 + 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) { ++ +#if defined(HAS_NAME_TO_HANDLE_AT) + if (mnt_id >= 0) { + list_t *ptr; @@ -834,11 +846,11 @@ index 31ef30c..a204f08 100644 - if (mid != mnt->parid) + + if (nlen != mnt->nlen) - continue; -- move_head(ptr, &sort); ++ continue; + + if (strcmp(use, mnt->mpoint)) -+ continue; + continue; +- move_head(ptr, &sort); + + ret = 0; + errno = 0; @@ -865,7 +877,7 @@ index 31ef30c..a204f08 100644 /* * Determine device of links below /proc/ */ -@@ -2078,8 +2328,7 @@ static int mntstat(const char *path, struct stat *buf) +@@ -2078,8 +2340,7 @@ static int mntstat(const char *path, struct stat *buf) { char name[PATH_MAX + 1]; const char *use; @@ -875,7 +887,7 @@ index 31ef30c..a204f08 100644 if ((use = realpath(path, name)) == NULL || *use != '/') { -@@ -2091,27 +2340,26 @@ static int mntstat(const char *path, struct stat *buf) +@@ -2091,27 +2352,26 @@ static int mntstat(const char *path, struct stat *buf) errno = 0; return stat(path, buf); } @@ -1030,5 +1042,5 @@ index b244893..1a10a1a 100644 set test "killall list signals" spawn $killall -l -- -2.12.3 +2.17.1 diff --git a/psmisc.changes b/psmisc.changes index 85372fb..bbed613 100644 --- a/psmisc.changes +++ b/psmisc.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Fri Jun 22 16:33:00 UTC 2018 - werner@suse.de + +- Modify patch 0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch + to make fuser option -m work even with mountinfo + (bsc#1098697) + ------------------------------------------------------------------- Thu May 17 10:32:53 UTC 2018 - werner@suse.de diff --git a/psmisc.spec b/psmisc.spec index 8b99416..006bbc4 100644 --- a/psmisc.spec +++ b/psmisc.spec @@ -73,9 +73,10 @@ grep -h src/ po/*.po|\ sort -t : -k1,1 -u|\ sed -r 's/:[0-9]+$//' > po/POTFILES.in autoreconf -fi -CFLAGS="-D_GNU_SOURCE -D_DEFAULT_SOURCE ${RPM_OPT_FLAGS} -pipe" +CFLAGS="-D_GNU_SOURCE -D_DEFAULT_SOURCE ${RPM_OPT_FLAGS} -pipe -fPIE" CXXFLAGS="$CFLAGS" -export CFLAGS CXXFLAGS +LDFLAGS=-pie +export CFLAGS CXXFLAGS LDFLAGS %configure --disable-rpath \ --with-gnu-ld \ --enable-selinux \