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 f2d157e..bcd23c5 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,6 +1,6 @@ -From 28805c3dda0ce9c78f046974454c0bb8dfee615b Mon Sep 17 00:00:00 2001 +From d220bd127a595287be2893e5808c4d53505e65af Mon Sep 17 00:00:00 2001 From: Werner Fink -Date: Thu, 29 Jun 2017 15:18:28 +0200 +Date: Mon, 22 Oct 2018 12:02:50 +0200 Subject: [PATCH] Use mountinfo to be able to use the mount identity which allows to distinguish different mounts with the @@ -11,14 +11,16 @@ and older systems. Add support for name_to_handle_at() system call to get the real mount ID for each file +Support also btrfs with its subvolumes + Signed-off-by: Werner Fink --- configure.ac | 18 +- - src/fuser.c | 540 +++++++++++++++++++++-------- + src/fuser.c | 541 +++++++++++++++++++++++++++---------- src/fuser.h | 19 +- testsuite/Makefile.am | 3 +- testsuite/killall.test/killall.exp | 4 + - 5 files changed, 436 insertions(+), 148 deletions(-) + 5 files changed, 440 insertions(+), 145 deletions(-) diff --git configure.ac configure.ac index 176a2fc..d8d3366 100644 @@ -64,7 +66,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..e5337cd 100644 +index c44cee8..2681f74 100644 --- src/fuser.c +++ src/fuser.c @@ -32,6 +32,10 @@ @@ -78,7 +80,7 @@ index 31ef30c..e5337cd 100644 #include #include #include -@@ -78,7 +82,7 @@ static void check_map(const pid_t pid, const char *filename, +@@ -79,7 +83,7 @@ static void check_map(const pid_t pid, const char *filename, struct device_list *dev_head, struct inode_list *ino_head, const uid_t uid, const char access); @@ -87,7 +89,7 @@ index 31ef30c..e5337cd 100644 static uid_t getpiduid(const pid_t pid); static int print_matches(struct names *names_head, const opt_type opts, const int sig_number); -@@ -88,8 +92,8 @@ static int kill_matched_proc(struct procs *pptr, const opt_type opts, +@@ -89,8 +93,8 @@ static int kill_matched_proc(struct procs *pptr, const opt_type opts, /*int parse_mount(struct names *this_name, struct device_list **dev_list);*/ static void add_device(struct device_list **dev_list, struct names *this_name, dev_t device); @@ -98,7 +100,7 @@ index 31ef30c..e5337cd 100644 static void atexit_clear_unix_cache(); static dev_t find_net_dev(void); static void scan_procs(struct names *names_head, struct inode_list *ino_head, -@@ -108,9 +112,12 @@ static void debug_match_lists(struct names *names_head, +@@ -109,9 +113,12 @@ static void debug_match_lists(struct names *names_head, struct device_list *dev_head); #endif @@ -112,7 +114,7 @@ index 31ef30c..e5337cd 100644 static int mntstat(const char *path, struct stat *buf); #endif static stat_t thestat = stat; -@@ -198,6 +205,7 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, +@@ -199,6 +206,7 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, struct stat *cwd_stat = NULL; struct stat *exe_stat = NULL; struct stat *root_stat = NULL; @@ -120,7 +122,7 @@ index 31ef30c..e5337cd 100644 if (topproc_dent->d_name[0] < '0' || topproc_dent->d_name[0] > '9') /* Not a process */ continue; -@@ -207,9 +215,9 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, +@@ -208,9 +216,9 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, continue; uid = getpiduid(pid); @@ -133,7 +135,7 @@ index 31ef30c..e5337cd 100644 cwd_dev = cwd_stat ? cwd_stat->st_dev : 0; exe_dev = exe_stat ? exe_stat->st_dev : 0; root_dev = root_stat ? root_stat->st_dev : 0; -@@ -217,21 +225,21 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, +@@ -218,21 +226,21 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, /* Scan the devices */ for (dev_tmp = dev_head; dev_tmp != NULL; dev_tmp = dev_tmp->next) { @@ -165,7 +167,7 @@ index 31ef30c..e5337cd 100644 if (exe_stat && exe_stat->st_dev == ino_tmp->device && exe_stat->st_ino == ino_tmp->inode) -@@ -240,7 +248,7 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, +@@ -241,7 +249,7 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, } if (root_dev == ino_tmp->device) { if (!root_stat) @@ -174,7 +176,7 @@ index 31ef30c..e5337cd 100644 if (root_stat && root_stat->st_dev == ino_tmp->device && root_stat->st_ino == ino_tmp->inode) -@@ -249,7 +257,7 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, +@@ -250,7 +258,7 @@ scan_procs(struct names *names_head, struct inode_list *ino_head, } if (cwd_dev == ino_tmp->device) { if (!cwd_stat) @@ -183,7 +185,7 @@ index 31ef30c..e5337cd 100644 if (cwd_stat && cwd_stat->st_dev == ino_tmp->device && cwd_stat->st_ino == ino_tmp->inode) -@@ -290,6 +298,7 @@ add_inode(struct inode_list **ino_list, struct names *this_name, +@@ -291,6 +299,7 @@ add_inode(struct inode_list **ino_list, struct names *this_name, ino_tmp->name = this_name; ino_tmp->device = device; ino_tmp->inode = inode; @@ -191,7 +193,7 @@ index 31ef30c..e5337cd 100644 ino_tmp->next = ino_head; *ino_list = ino_tmp; } -@@ -309,6 +318,7 @@ add_device(struct device_list **dev_list, struct names *this_name, dev_t device) +@@ -310,6 +319,7 @@ add_device(struct device_list **dev_list, struct names *this_name, dev_t device) dev_head = *dev_list; dev_tmp->name = this_name; dev_tmp->device = device; @@ -199,7 +201,7 @@ index 31ef30c..e5337cd 100644 dev_tmp->next = dev_head; *dev_list = dev_tmp; } -@@ -450,13 +460,15 @@ add_special_proc(struct names *name_list, const char ptype, const uid_t uid, +@@ -451,13 +461,15 @@ add_special_proc(struct names *name_list, const char ptype, const uid_t uid, int parse_file(struct names *this_name, struct inode_list **ino_list, const opt_type opts) { @@ -216,7 +218,7 @@ index 31ef30c..e5337cd 100644 if (errno == ENOENT) fprintf(stderr, _("Specified filename %s does not exist.\n"), -@@ -466,10 +478,12 @@ int parse_file(struct names *this_name, struct inode_list **ino_list, +@@ -467,10 +479,12 @@ int parse_file(struct names *this_name, struct inode_list **ino_list, this_name->filename, strerror(errno)); return -1; } @@ -227,11 +229,11 @@ index 31ef30c..e5337cd 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->isremote ? "yes" : "no"); #endif /* DEBUG */ add_inode(ino_list, this_name, this_name->st.st_dev, this_name->st.st_ino); -@@ -501,11 +515,51 @@ parse_mounts(struct names *this_name, struct device_list **dev_list, +@@ -502,11 +516,51 @@ parse_mounts(struct names *this_name, struct device_list **dev_list, const opt_type opts) { dev_t match_device; @@ -283,7 +285,7 @@ index 31ef30c..e5337cd 100644 add_device(dev_list, this_name, match_device); return 0; } -@@ -620,7 +674,7 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list) +@@ -621,7 +675,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); @@ -292,7 +294,7 @@ index 31ef30c..e5337cd 100644 return -1; } freeaddrinfo(res); -@@ -683,10 +737,12 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list) +@@ -684,10 +738,12 @@ int parse_inet(struct names *this_name, struct ip_connections **ip_list) break; #endif } @@ -308,7 +310,7 @@ index 31ef30c..e5337cd 100644 } return 1; } -@@ -1161,16 +1217,11 @@ int main(int argc, char *argv[]) +@@ -1162,16 +1218,11 @@ int main(int argc, char *argv[]) skip_argv = 1; //while(option != '\0') option++; if (strcmp(argv[argc_cnt], "tcp") == 0) @@ -330,7 +332,7 @@ index 31ef30c..e5337cd 100644 else usage(_ ("Invalid namespace name")); -@@ -1210,7 +1261,7 @@ int main(int argc, char *argv[]) +@@ -1211,7 +1262,7 @@ int main(int argc, char *argv[]) } #if defined(WITH_MOUNTINFO_LIST) @@ -339,7 +341,7 @@ index 31ef30c..e5337cd 100644 thestat = mntstat; #endif /* an option */ -@@ -1524,7 +1575,7 @@ print_matches(struct names *names_head, const opt_type opts, +@@ -1525,7 +1576,7 @@ print_matches(struct names *names_head, const opt_type opts, } @@ -348,7 +350,7 @@ index 31ef30c..e5337cd 100644 { char pathname[256]; struct stat *st; -@@ -1536,6 +1587,15 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename) +@@ -1537,6 +1588,15 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename) free(st); return NULL; } @@ -364,32 +366,17 @@ index 31ef30c..e5337cd 100644 return st; } -@@ -1550,18 +1610,19 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, +@@ -1551,7 +1611,8 @@ 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; - struct stat st, lst; -- char dirpath[MAX_PATHNAME]; -- char filepath[MAX_PATHNAME]; + struct fdinfo fd; + struct stat st; -+ char dirpath[PATH_MAX+1]; -+ char filepath[PATH_MAX+1]; + char *dirpath; + char filepath[PATH_MAX]; -- snprintf(dirpath, MAX_PATHNAME, "/proc/%d/%s", pid, dirname); -+ snprintf(dirpath, PATH_MAX, "/proc/%d/%s", pid, dirname); - if ((dirp = opendir(dirpath)) == NULL) - return; - while ((direntry = readdir(dirp)) != NULL) { - if (direntry->d_name[0] < '0' || direntry->d_name[0] > '9') - continue; - -- snprintf(filepath, MAX_PATHNAME, "/proc/%d/%s/%s", -+ snprintf(filepath, PATH_MAX, "/proc/%d/%s/%s", - pid, dirname, direntry->d_name); - - if (timeout(thestat, filepath, &st, 5) != 0) { -@@ -1586,9 +1647,12 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, +@@ -1592,9 +1653,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; @@ -404,7 +391,7 @@ index 31ef30c..e5337cd 100644 add_matched_proc(dev_tmp->name, pid, uid, ACCESS_FILEWR | -@@ -1610,9 +1674,10 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, +@@ -1616,9 +1680,10 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, continue; } if (st.st_ino == ino_tmp->inode) { @@ -417,15 +404,17 @@ index 31ef30c..e5337cd 100644 add_matched_proc(ino_tmp->name, pid, uid, ACCESS_FILEWR | -@@ -1641,18 +1706,30 @@ check_map(const pid_t pid, const char *filename, +@@ -1647,7 +1712,6 @@ check_map(const pid_t pid, const char *filename, FILE *fp; unsigned long long tmp_inode; unsigned int tmp_maj, tmp_min; - dev_t tmp_device; - snprintf(pathname, MAX_PATHNAME, "/proc/%d/%s", pid, filename); - if ((fp = fopen(pathname, "r")) == NULL) - return; + if (asprintf(&pathname, "/proc/%d/%s", pid, filename) < 0) + return; +@@ -1657,12 +1721,25 @@ check_map(const pid_t pid, const char *filename, + } + free(pathname); while (fgets(line, BUFSIZ, fp)) { - if (sscanf(line, "%*s %*s %*s %x:%x %lld", - &tmp_maj, &tmp_min, &tmp_inode) == 3) { @@ -453,7 +442,7 @@ index 31ef30c..e5337cd 100644 add_matched_proc(dev_tmp->name, pid, uid, access); for (ino_tmp = ino_head; ino_tmp != NULL; -@@ -1661,7 +1738,8 @@ check_map(const pid_t pid, const char *filename, +@@ -1671,7 +1748,8 @@ check_map(const pid_t pid, const char *filename, && ino_tmp->inode == tmp_inode) add_matched_proc(ino_tmp->name, pid, uid, access); @@ -463,7 +452,7 @@ index 31ef30c..e5337cd 100644 } fclose(fp); } -@@ -1682,6 +1760,7 @@ static uid_t getpiduid(const pid_t pid) +@@ -1695,6 +1773,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 */ @@ -471,7 +460,7 @@ index 31ef30c..e5337cd 100644 void fill_unix_cache(struct unixsocket_list **unixsocket_head) { FILE *fp; -@@ -1698,6 +1777,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) +@@ -1711,6 +1790,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) while (fgets(line, BUFSIZ, fp) != NULL) { char *path; char *scanned_path = NULL; @@ -480,7 +469,7 @@ index 31ef30c..e5337cd 100644 if (sscanf(line, "%*x: %*x %*x %*x %*x %*d %d %ms", &scanned_inode, &scanned_path) != 2) { if (scanned_path) -@@ -1713,6 +1794,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) +@@ -1726,6 +1807,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) free(path); continue; } @@ -489,7 +478,7 @@ index 31ef30c..e5337cd 100644 if ((newsocket = (struct unixsocket_list *) malloc(sizeof(struct unixsocket_list))) == NULL) { free(path); -@@ -1721,6 +1804,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) +@@ -1734,6 +1817,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; @@ -497,7 +486,7 @@ index 31ef30c..e5337cd 100644 newsocket->net_inode = scanned_inode; newsocket->next = *unixsocket_head; *unixsocket_head = newsocket; -@@ -1733,6 +1817,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) +@@ -1746,6 +1830,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) /* * Free up the list of Unix sockets */ @@ -505,7 +494,7 @@ index 31ef30c..e5337cd 100644 void clear_unix_cache(struct unixsocket_list **unixsocket_head) { while(*unixsocket_head != NULL) { -@@ -1900,30 +1985,22 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, +@@ -1913,30 +1998,22 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, { struct device_list *dev_tmp; struct inode_list *ino_tmp; @@ -546,7 +535,7 @@ index 31ef30c..e5337cd 100644 add_special_proc(dev_tmp->name, PTYPE_MOUNT, 0, find_mountp); } -@@ -1935,7 +2012,6 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, +@@ -1948,7 +2025,6 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, find_mountp); } } @@ -554,7 +543,7 @@ index 31ef30c..e5337cd 100644 } static void -@@ -1985,16 +2061,42 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head, +@@ -1998,16 +2074,49 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head, fclose(fp); } @@ -562,7 +551,8 @@ index 31ef30c..e5337cd 100644 /* * Use /proc/self/mountinfo of modern linux system to determine * the device numbers of the mount points. Use this to avoid the - * stat(2) system call wherever possible. +- * stat(2) system call wherever possible. ++ * stat(2) system call for remote file system. */ -static list_t mntinfo = { &mntinfo, &mntinfo }; @@ -587,9 +577,16 @@ index 31ef30c..e5337cd 100644 + mnt->parid = parid; + mnt->dev = dev; + mnt->id = mid; -+ if (strncmp("nfs", type, 3) == 0) -+ mnt->isnfs = 1; -+ else mnt->isnfs = 0; ++ if (strncmp("nfs", type, 3) == 0 || strncmp("afs", type, 3) == 0 || strncmp("autofs", type, 6)) ++ mnt->isremote = 1; ++ else mnt->isremote = 0; ++ if (!mnt->isremote) { ++ /* E.g. sub volumes of BtrFS do not show correct device ++ * numbers in /proc/self/mountinfo */ ++ struct stat st; ++ if (stat(mpoint, &st) >= 0) ++ mnt->dev = st.st_dev; ++ } + + return mnt; +} @@ -600,7 +597,7 @@ index 31ef30c..e5337cd 100644 { list_t *ptr, *tmp; -@@ -2005,72 +2107,232 @@ static void clear_mntinfo(void) +@@ -2018,72 +2127,232 @@ static void clear_mntinfo(void) } } @@ -609,7 +606,7 @@ index 31ef30c..e5337cd 100644 +init_mntinfo(void) { + char type[256]; - char mpoint[PATH_MAX*4 + 1]; // octal escaping takes 4 chars per 1 char + char mpoint[PATH_MAX *4 + 1]; // octal escaping takes 4 chars per 1 char - int mid, parid, max = 0; + int mid, parid; +#if defined(HAS_MOUNTINFO) @@ -669,7 +666,12 @@ index 31ef30c..e5337cd 100644 +#endif fclose(mnt); +} -+ + +- /* 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) { +static int +get_fdinfo(const pid_t pid, const char *fd, struct fdinfo *info) +{ @@ -680,12 +682,7 @@ index 31ef30c..e5337cd 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; @@ -877,7 +874,7 @@ index 31ef30c..e5337cd 100644 /* * Determine device of links below /proc/ */ -@@ -2078,8 +2340,7 @@ static int mntstat(const char *path, struct stat *buf) +@@ -2091,8 +2360,7 @@ static int mntstat(const char *path, struct stat *buf) { char name[PATH_MAX + 1]; const char *use; @@ -887,7 +884,7 @@ index 31ef30c..e5337cd 100644 if ((use = realpath(path, name)) == NULL || *use != '/') { -@@ -2091,27 +2352,26 @@ static int mntstat(const char *path, struct stat *buf) +@@ -2104,27 +2372,26 @@ static int mntstat(const char *path, struct stat *buf) errno = 0; return stat(path, buf); } @@ -923,7 +920,7 @@ index 31ef30c..e5337cd 100644 - errno = ENOENT; - return -1; + -+ if (mnt->isnfs) { ++ if (mnt->isremote) { + buf->st_dev = mnt->dev; + buf->st_ino = mnt->id; /* inode substitute */ + return 0; /* found on NFS */ @@ -934,7 +931,7 @@ index 31ef30c..e5337cd 100644 #endif /* WITH_MOUNTINFO_LIST */ diff --git src/fuser.h src/fuser.h -index a4df711..4b9b1d6 100644 +index 93020d5..51c6770 100644 --- src/fuser.h +++ src/fuser.h @@ -37,10 +37,16 @@ struct procs { @@ -988,7 +985,7 @@ index a4df711..4b9b1d6 100644 typedef struct mntinfo_s { list_t this; int id, parid; -+ char isnfs; ++ char isremote; dev_t dev; size_t nlen; char *mpoint; @@ -999,8 +996,8 @@ index a4df711..4b9b1d6 100644 #define NAMESPACE_FILE 0 #define NAMESPACE_TCP 1 -@@ -108,5 +114,6 @@ typedef struct mntinfo_s { - #define MAX_CMDNAME 16 +@@ -109,5 +115,6 @@ typedef struct mntinfo_s { + #endif /* PATH_MAX */ #define KNFSD_EXPORTS "/proc/fs/nfs/exports" +#define PROC_MOUNTINFO "/proc/self/mountinfo" @@ -1026,7 +1023,7 @@ index 696a44a..739237e 100644 - EXTRA_DIST = diff --git testsuite/killall.test/killall.exp testsuite/killall.test/killall.exp -index b244893..1a10a1a 100644 +index 8bb3889..a345582 100644 --- testsuite/killall.test/killall.exp +++ testsuite/killall.test/killall.exp @@ -7,7 +7,11 @@ set fake_proc_name "afakeprocname" @@ -1042,5 +1039,5 @@ index b244893..1a10a1a 100644 set test "killall list signals" spawn $killall -l -- -2.17.1 +2.16.4 diff --git a/0002-Use-new-statx-2-system-call-to-avoid-hangs-on-NFS.patch b/0002-Use-new-statx-2-system-call-to-avoid-hangs-on-NFS.patch new file mode 100644 index 0000000..30dcccd --- /dev/null +++ b/0002-Use-new-statx-2-system-call-to-avoid-hangs-on-NFS.patch @@ -0,0 +1,952 @@ +From 7181b4125fc2a1057dffffaa643e6bcb549fd0eb Mon Sep 17 00:00:00 2001 +From: Werner Fink +Date: Fri, 2 Nov 2018 14:27:00 +0100 +Subject: [PATCH] Use new statx(2) system call to avoid hangs on NFS + +Signed-off-by: Werner Fink +--- + Makefile.am | 4 +- + configure.ac | 38 +++--- + src/fuser.c | 86 +++----------- + src/statx.c | 147 +++++++++++++++++++++++ + src/statx.h | 66 +++++++++++ + src/timeout.c | 372 ---------------------------------------------------------- + src/timeout.h | 45 ------- + 7 files changed, 247 insertions(+), 511 deletions(-) + create mode 100644 src/statx.c + create mode 100644 src/statx.h + delete mode 100644 src/timeout.c + delete mode 100644 src/timeout.h + +diff --git Makefile.am Makefile.am +index d8c4619..a76799c 100644 +--- Makefile.am ++++ Makefile.am +@@ -58,8 +58,8 @@ src_fuser_SOURCES = \ + src/fuser.h \ + src/lists.h + +-if WANT_TIMEOUT_STAT +-src_fuser_SOURCES += src/timeout.c src/timeout.h ++if HAVE_SYSCALL_STATX ++src_fuser_SOURCES += src/statx.c src/statx.h + endif + src_fuser_LDADD = @LIBINTL@ + src_killall_SOURCES = src/killall.c src/comm.h src/signals.c src/signals.h src/i18n.h +diff --git configure.ac configure.ac +index d8d3366..81d3674 100644 +--- configure.ac ++++ configure.ac +@@ -33,20 +33,6 @@ else + fi + AC_SUBST([SELINUX_LIB]) + +-# Call fork before all stat calls to stop hanging on NFS mounts +-AC_SUBST([WITH_TIMEOUT_STAT]) +-AC_ARG_ENABLE([timeout_stat], +- [AS_HELP_STRING([--enable-timeout-stat], [Use a timeout on stat calls (optional with argument "static" for a static background process)])], +- [enable_timeout_stat=$enableval], +- [enable_timeout_stat="no"]) +-if test "$enable_timeout_stat" = "yes"; then +- AC_DEFINE([WITH_TIMEOUT_STAT], [1], [Use timeout on stat calls]) +-fi +-if test "$enable_timeout_stat" = "static"; then +- AC_DEFINE([WITH_TIMEOUT_STAT], [2], [Use timeout on stat calls]) +-fi +-AM_CONDITIONAL([WANT_TIMEOUT_STAT], [test "$enable_timeout_stat" = "static"]) +- + # Use /proc/self/mountinfo if available + if test -e /proc/self/mountinfo ; then + AC_DEFINE([HAS_MOUNTINFO], [1], [System has /proc/self/mountinfo which can used instead /proc(/self)/mounts]) +@@ -60,16 +46,20 @@ fi + AC_CHECK_FUNC([name_to_handle_at],[ + AC_DEFINE([HAS_NAME_TO_HANDLE_AT], [1], [System has name_to_handle_at(2) system call])]) + +-# Use string search for network based file systems but only if the system +-# has /proc/self/mountinfo +-AC_SUBST([WITH_MOUNTINFO_LIST]) +-AC_ARG_ENABLE([mountinfo_list], +- [AS_HELP_STRING([--enable-mountinfo-list], [Use the list in /proc/self/mountinfo to replace stat(2) syscall on network file systems shares])], +- [enable_mountinfo_list="yes"], +- [enable_mountinfo_list="no"]) +-if test "$enable_mountinfo_list" = "yes" -a -e /proc/self/mountinfo ; then +- AC_DEFINE([WITH_MOUNTINFO_LIST], [1], [Use list in /proc/self/mountinfo to replace stat calls]) +-fi ++AC_CHECK_HEADERS([sys/syscall.h]) ++AC_CHECK_DECLS([SYS_statx], ++ [has_syscall_statx="yes"], ++ [has_syscall_statx="no"], ++ [[#include ]] ++) ++AC_CHECK_FUNCS([statx]) ++# Check for linux specific statx(2) system call ++AC_SUBST([HAS_SYSCALL_STATX]) ++AC_ARG_ENABLE([disable_statx], ++ [AS_HELP_STRING([--disable-statx], [Do not use linux specific statx(2) system call as replacement for stat(2), lstat(2), and fstat(2)])], ++ [enable_syscall_statx="no"], ++ [enable_syscall_statx=$has_syscall_statx]) ++AM_CONDITIONAL([HAVE_SYSCALL_STATX], [test "$enable_syscall_statx" = "yes"]) + + # Enable hardened compile and link flags + AC_ARG_ENABLE([harden_flags], +diff --git src/fuser.c src/fuser.c +index 2681f74..c717e19 100644 +--- src/fuser.c ++++ src/fuser.c +@@ -63,7 +63,7 @@ + #include "fuser.h" + #include "signals.h" + #include "i18n.h" +-#include "timeout.h" ++#include "statx.h" + #include "comm.h" + + //#define DEBUG 1 +@@ -118,10 +118,6 @@ static void clear_mntinfo(void) __attribute__ ((__destructor__)); + static void init_mntinfo(void) __attribute__ ((__constructor__)); + static int get_fdinfo(const pid_t pid, const char *fd, struct fdinfo *info); + static int find_mountpoint(const char *path, mntinfo_t **mountinfo); +-#if defined(WITH_MOUNTINFO_LIST) +-static int mntstat(const char *path, struct stat *buf); +-#endif +-static stat_t thestat = stat; + static char *expandpath(const char *path); + static struct unixsocket_list *unixsockets = NULL; + static struct names *names_head = NULL, *names_tail = NULL; +@@ -468,7 +464,7 @@ int parse_file(struct names *this_name, struct inode_list **ino_list, + free(this_name->filename); + this_name->filename = strdup(new); + } +- if (timeout(thestat, this_name->filename, &(this_name->st), 5) != 0 || ++ if (statn(this_name->filename, STATX_INO, &(this_name->st)) != 0 || + find_mountpoint(this_name->filename, &mountinfo) != 0) { + if (errno == ENOENT) + fprintf(stderr, +@@ -1193,9 +1189,7 @@ int main(int argc, char *argv[]) + opts |= OPT_INTERACTIVE; + break; + case 'I': +-#if defined(WITH_MOUNTINFO_LIST) + opts |= OPT_ALWAYSSTAT; +-#endif + break; + case 'k': + opts |= OPT_KILL; +@@ -1261,10 +1255,9 @@ int main(int argc, char *argv[]) + continue; + } + +-#if defined(WITH_MOUNTINFO_LIST) +- if ((opts & (OPT_MOUNTS|OPT_ALWAYSSTAT)) == OPT_MOUNTS) +- thestat = mntstat; +-#endif ++ if ((opts & OPT_ALWAYSSTAT)) ++ stat_flags = 0; /* Triggers sync with e.g. remote NFS server even on autofs */ ++ + /* an option */ + /* Not an option, must be a file specification */ + if ((this_name = malloc(sizeof(struct names))) == NULL) +@@ -1584,7 +1577,7 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename, int *id) + if ((st = (struct stat *)malloc(sizeof(struct stat))) == NULL) + return NULL; + snprintf(pathname, 256, "/proc/%d/%s", pid, filename); +- if (timeout(thestat, pathname, st, 5) != 0) { ++ if (statn(pathname, STATX_UID|STATX_INO|STATX_TYPE, st) != 0) { + free(st); + return NULL; + } +@@ -1631,7 +1624,7 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, + snprintf(filepath, sizeof filepath - 1, "/proc/%d/%s/%s", + pid, dirname, direntry->d_name); + +- if (timeout(thestat, filepath, &st, 5) != 0) { ++ if (statn(filepath, STATX_INO, &st) != 0) { + if (errno != ENOENT && errno != ENOTDIR) { + fprintf(stderr, _("Cannot stat file %s: %s\n"), + filepath, strerror(errno)); +@@ -1673,7 +1666,7 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, + if (thedev != ino_tmp->device) + continue; + if (!st.st_ino +- && timeout(thestat, filepath, &st, 5) != 0) { ++ && statn(filepath, STATX_INO, &st) != 0) { + fprintf(stderr, + _("Cannot stat file %s: %s\n"), + filepath, strerror(errno)); +@@ -1761,11 +1754,11 @@ static uid_t getpiduid(const pid_t pid) + + if (asprintf(&pathname, "/proc/%d", pid) < 0) + return 0; +- if (timeout(thestat, pathname, &st, 5) != 0) { +- free(pathname); ++ if (statn(pathname, STATX_UID, &st) != 0) { ++ free(pathname); + return 0; +- } +- free(pathname); ++ } ++ free(pathname); + return st.st_uid; + } + +@@ -1803,7 +1796,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) + path = scanned_path; + if (*scanned_path == '@') + scanned_path++; +- if (timeout(thestat, scanned_path, &st, 5) < 0) { ++ if (statn(scanned_path, STATX_INO, &st) < 0) { + free(path); + continue; + } +@@ -1938,7 +1931,7 @@ static dev_t find_net_dev(void) + fprintf(stderr, _("Cannot open a network socket.\n")); + return -1; + } +- if (fstat(skt, &st) != 0) { ++ if (fstatn(skt, STATX_INO, &st) != 0) { + fprintf(stderr, _("Cannot find socket's device number.\n")); + close(skt); + return -1; +@@ -1971,7 +1964,7 @@ scan_knfsd(struct names *names_head, struct inode_list *ino_head, + if ((find_space = strpbrk(line, " \t")) == NULL) + continue; + *find_space = '\0'; +- if (timeout(thestat, line, &st, 5) != 0) { ++ if (statn(line, STATX_INO, &st) != 0) { + continue; + } + /* Scan the devices */ +@@ -2006,7 +1999,7 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, + mntinfo_t *mnt = list_entry(ptr, mntinfo_t); + const char *find_mountp = mnt->mpoint; + +- if (timeout(thestat, find_mountp, &st, 5) != 0) ++ if (statn(find_mountp, STATX_INO, &st) != 0) + continue; + + /* Scan the devices */ +@@ -2053,7 +2046,7 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head, + if (*find_space == '\0') + continue; + } +- if (timeout(thestat, line, &st, 5) != 0) { ++ if (statn(line, STATX_INO, &st) != 0) { + continue; + } + /* Scan the devices */ +@@ -2209,7 +2202,7 @@ out: + struct stat lst; + + snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd); +- if (!flags && lstat(pathname, &lst) == 0) { ++ if (!flags && lstatn(pathname, STATX_MODE, &lst) == 0) { + if (lst.st_mode & S_IWUSR) + info->flags |= O_WRONLY; + ret++; +@@ -2352,49 +2345,6 @@ out: + return ret; + } + +-#if defined(WITH_MOUNTINFO_LIST) +-/* +- * Determine device of links below /proc/ +- */ +-static int mntstat(const char *path, struct stat *buf) +-{ +- char name[PATH_MAX + 1]; +- const char *use; +- mntinfo_t *mnt; +- +- if ((use = realpath(path, name)) == NULL || *use != '/') +- { +- if (errno == ENOENT) +- return -1; +- /* +- * Could be a special file (socket, pipe, inotify) +- */ +- errno = 0; +- return stat(path, buf); +- } +- if (strncmp("/dev/", use, 5) == 0) { +- /* +- * Could be a special file (socket, pipe, inotify) +- */ +- errno = 0; +- return stat(path, buf); +- } +- +- if (find_mountpoint(use, &mnt) < 0) { +- errno = ENOENT; +- return -1; +- } +- +- if (mnt->isremote) { +- buf->st_dev = mnt->dev; +- buf->st_ino = mnt->id; /* inode substitute */ +- return 0; /* found on NFS */ +- } +- +- return stat(path, buf); +-} +-#endif /* WITH_MOUNTINFO_LIST */ +- + /* + * Somehow the realpath(3) glibc function call, nevertheless + * it avoids lstat(2) system calls. +diff --git src/statx.c src/statx.c +new file mode 100644 +index 0000000..2554da7 +--- /dev/null ++++ src/statx.c +@@ -0,0 +1,147 @@ ++/* ++ * statx.c - Map modern statx(2) system call to older stat(2), lstat(2), ++ * and fstat(2) replacements named {,l,f}statn() ++ * ++ * Copyright (C) 2018 Werner Fink ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++#ifndef _GNU_SOURCE ++#define _GNU_SOURCE ++#endif ++ ++#ifdef HAVE_CONFIG_H ++#include ++#endif ++ ++#ifndef HAVE_STATX ++# define _ASM_GENERIC_FCNTL_H /* Avoid collisions between asm/fcntl.h and bits/fcntl.h ! */ ++# include /* Definition of AT_* and AT_STATX_* constants ! */ ++#endif ++#include /* Definition of AT_* constants */ ++#ifndef HAVE_STATX ++# include /* Provides 'struct statx' and STATX_* ! */ ++#endif ++#include ++#include ++#include ++#include ++#include ++ ++int stat_flags = AT_NO_AUTOMOUNT|AT_STATX_DONT_SYNC; ++ ++int statn(const char *pathname, unsigned int mask, struct stat *st) ++{ ++ int flags = stat_flags; ++ int dirfd = pathname && *pathname == '/' ? 0 : AT_FDCWD; ++ int ret; ++ struct statx stx; ++ ++#ifndef HAVE_STATX ++ ret = syscall(SYS_statx, dirfd, pathname, flags, mask, &stx); ++#else ++ ret = statx(dirfd, pathname, flags, mask, &stx); ++#endif ++ if (ret >= 0) { ++ st->st_dev = makedev(stx.stx_dev_major, stx.stx_dev_minor); ++ st->st_rdev = makedev(stx.stx_rdev_major, stx.stx_rdev_minor); ++ ++ st->st_ino = stx.stx_ino; ++ st->st_mode = stx.stx_mode; ++ st->st_nlink = stx.stx_nlink; ++ st->st_uid = stx.stx_uid; ++ st->st_gid = stx.stx_gid; ++ st->st_size = stx.stx_size; ++ st->st_blksize = stx.stx_blksize; ++ st->st_blocks = stx.stx_blocks; ++ ++ st->st_atim.tv_sec = stx.stx_atime.tv_sec; ++ st->st_atim.tv_nsec = stx.stx_atime.tv_nsec; ++ st->st_mtim.tv_sec = stx.stx_mtime.tv_sec; ++ st->st_mtim.tv_nsec = stx.stx_mtime.tv_nsec; ++ st->st_ctim.tv_sec = stx.stx_ctime.tv_sec; ++ st->st_ctim.tv_nsec = stx.stx_ctime.tv_nsec; ++ } ++ return ret; ++} ++ ++int fstatn(int fd, unsigned int mask, struct stat *st) ++{ ++ int flags = AT_EMPTY_PATH|stat_flags; ++ int ret; ++ struct statx stx; ++ ++#ifndef HAVE_STATX ++ ret = syscall(SYS_statx, fd, "", flags, mask, &stx); ++#else ++ ret = statx(fd, "", flags, mask, &stx); ++#endif ++ if (ret >= 0) { ++ st->st_dev = makedev(stx.stx_dev_major, stx.stx_dev_minor); ++ st->st_rdev = makedev(stx.stx_rdev_major, stx.stx_rdev_minor); ++ ++ st->st_ino = stx.stx_ino; ++ st->st_mode = stx.stx_mode; ++ st->st_nlink = stx.stx_nlink; ++ st->st_uid = stx.stx_uid; ++ st->st_gid = stx.stx_gid; ++ st->st_size = stx.stx_size; ++ st->st_blksize = stx.stx_blksize; ++ st->st_blocks = stx.stx_blocks; ++ ++ st->st_atim.tv_sec = stx.stx_atime.tv_sec; ++ st->st_atim.tv_nsec = stx.stx_atime.tv_nsec; ++ st->st_mtim.tv_sec = stx.stx_mtime.tv_sec; ++ st->st_mtim.tv_nsec = stx.stx_mtime.tv_nsec; ++ st->st_ctim.tv_sec = stx.stx_ctime.tv_sec; ++ st->st_ctim.tv_nsec = stx.stx_ctime.tv_nsec; ++ } ++ return ret; ++} ++ ++int lstatn(const char *pathname, unsigned int mask, struct stat *st) ++{ ++ int flags = AT_SYMLINK_NOFOLLOW|stat_flags; ++ int dirfd = pathname && *pathname == '/' ? 0 : AT_FDCWD; ++ int ret; ++ struct statx stx; ++ ++#ifndef HAVE_STATX ++ ret = syscall(SYS_statx, dirfd, pathname, flags, mask, &stx); ++#else ++ ret = statx(dirfd, pathname, flags, mask, &stx); ++#endif ++ if (ret >= 0) { ++ st->st_dev = makedev(stx.stx_dev_major, stx.stx_dev_minor); ++ st->st_rdev = makedev(stx.stx_rdev_major, stx.stx_rdev_minor); ++ ++ st->st_ino = stx.stx_ino; ++ st->st_mode = stx.stx_mode; ++ st->st_nlink = stx.stx_nlink; ++ st->st_uid = stx.stx_uid; ++ st->st_gid = stx.stx_gid; ++ st->st_size = stx.stx_size; ++ st->st_blksize = stx.stx_blksize; ++ st->st_blocks = stx.stx_blocks; ++ ++ st->st_atim.tv_sec = stx.stx_atime.tv_sec; ++ st->st_atim.tv_nsec = stx.stx_atime.tv_nsec; ++ st->st_mtim.tv_sec = stx.stx_mtime.tv_sec; ++ st->st_mtim.tv_nsec = stx.stx_mtime.tv_nsec; ++ st->st_ctim.tv_sec = stx.stx_ctime.tv_sec; ++ st->st_ctim.tv_nsec = stx.stx_ctime.tv_nsec; ++ } ++ return ret; ++} +diff --git src/statx.h src/statx.h +new file mode 100644 +index 0000000..548583d +--- /dev/null ++++ src/statx.h +@@ -0,0 +1,66 @@ ++/* ++ * statx.h - Map modern statx(2) system call to older stat(2), lstat(2), ++ * and fstat(2) replacements named {,l,f}statn() ++ * ++ * Copyright (C) 2018 Werner Fink ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++#ifndef _STATX_H ++#define _STATX_H ++ ++extern int stat_flags; ++#if defined(HAVE_DECL_SYS_STATX) && HAVE_DECL_SYS_STATX == 1 ++# ifndef HAVE_STATX ++# define _ASM_GENERIC_FCNTL_H /* Avoid collisions between asm/fcntl.h and bits/fcntl.h ! */ ++# include /* Definition of AT_* and AT_STATX_* constants ! */ ++# include /* Provides 'struct statx' and STATX_* ! */ ++# endif ++extern int statn(const char*, unsigned int, struct stat*); ++extern int fstatn(int, unsigned int, struct stat*); ++extern int lstatn(const char*, unsigned int, struct stat*); ++#else ++extern inline int ++statn(const char *path, unsigned int mask __atribute__((unused)), struct stat *st) ++{ ++ return stat(path, st); ++} ++extern inline int ++fstatn(int fd, unsigned int mask __atribute__((unused)), struct stat *st) ++{ ++ return fstat(fd, st); ++} ++extern inline int ++lstatn(const char *path, unsigned int mask __atribute__((unused)), struct stat *st) ++{ ++ lstat(path, st); ++} ++#define STATX_TYPE 0 ++#define STATX_MODE 0 ++#define STATX_NLINK 0 ++#define STATX_UID 0 ++#define STATX_GID 0 ++#define STATX_ATIME 0 ++#define STATX_MTIME 0 ++#define STATX_CTIME 0 ++#define STATX_INO 0 ++#define STATX_SIZE 0 ++#define STATX_BLOCKS 0 ++#define STATX_BASIC_STATS 0 ++#define STATX_BTIME 0 ++#define STATX_ALL 0 ++#endif ++#endif +diff --git src/timeout.c src/timeout.c +deleted file mode 100644 +index ca4a7cd..0000000 +--- src/timeout.c ++++ /dev/null +@@ -1,372 +0,0 @@ +-/* +- * timout.c Advanced timeout handling for file system calls +- * to avoid deadlocks on remote file shares. +- * +- * Version: 0.2 11-Dec-2012 Fink +- * +- * Copyright 2011,2012 Werner Fink, 2011,2012 SUSE LINUX Products GmbH, Germany. +- * +- * This program is free software; you can redistribute it and/or modify +- * it under the terms of the GNU General Public License as published by +- * the Free Software Foundation; either version 2 of the License, or +- * (at your option) any later version. +- * +- * Author: Werner Fink , 2011 +- */ +- +-#ifndef _GNU_SOURCE +-# define _GNU_SOURCE +-#endif +- +-#ifdef _FEATURES_H +-# error Include local config.h before any system header file +-#endif +-#include "config.h" +- +-#ifndef WITH_TIMEOUT_STAT +-# define WITH_TIMEOUT_STAT 0 +-#endif +- +-#ifndef USE_SOCKETPAIR +-# define USE_SOCKETPAIR 1 +-#endif +- +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#include +-#if USE_SOCKETPAIR +-# include +-# include +-# include +-# ifndef SHUT_RD +-# define SHUT_RD 0 +-# endif +-# ifndef SHUT_WR +-# define SHUT_WR 1 +-# endif +-# undef pipe +-# define pipe(v) (((socketpair(AF_UNIX,SOCK_STREAM,0,v) < 0) || \ +- (shutdown((v)[1],SHUT_RD) < 0) || (shutdown((v)[0],SHUT_WR) < 0)) ? -1 : 0) +-#endif +-#include +- +-#include "timeout.h" +- +-#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) +-# ifndef destructor +-# define destructor __destructor__ +-# endif +-# ifndef constructor +-# define constructor __constructor__ +-# endif +-# ifndef packed +-# define packed __packed__ +-# endif +-# ifndef inline +-# define inline __inline__ +-# endif +-# ifndef unused +-# define unused __unused__ +-# endif +-# ifndef volatile +-# define volatile __volatile__ +-# endif +-#endif +-#ifndef attribute +-# define attribute(attr) __attribute__(attr) +-#endif +- +-#if defined __GNUC__ +-# undef strcpy +-# define strcpy(d,s) __builtin_strcpy((d),(s)) /* Without boundary check please */ +-#endif +- +-#if WITH_TIMEOUT_STAT +-static sigjmp_buf jenv; +-static void sigjump(int sig attribute((unused))) +-{ +- siglongjmp(jenv, 1); +-} +-#endif +- +-#if WITH_TIMEOUT_STAT == 2 +-/* +- * The structure used for communication between the processes +- */ +-typedef struct _handle { +- int errcode; +- struct stat argument; +- stat_t function; +- size_t len; +- char path[0]; +-} attribute((packed)) handle_t; +- +-/* +- * Using a forked process for doing e.g. stat(2) system call as this +- * allows us to send e.g. SIGKILL to this process if it hangs in `D' +- * state on a file share due a stalled NFS server. This does not work +- * with (p)threads as SIGKILL would kill all threads including main. +- */ +- +-static volatile pid_t active; +-static int pipes[4] = {-1, -1, -1, -1}; +-static handle_t *restrict handle; +-static const size_t buflen = PATH_MAX+sizeof(handle_t)+1; +- +-static void sigchild(int sig attribute((unused))) +-{ +- pid_t pid = waitpid(active, NULL, WNOHANG|WUNTRACED); +- if (pid <= 0) +- return; +- if (errno == ECHILD) +- return; +- active = 0; +-} +- +-static void attribute((constructor)) start(void) +-{ +- sigset_t sigset, oldset; +- struct sigaction act; +- char sync[1]; +- ssize_t in; +- +- if (pipes[1] >= 0) close(pipes[1]); +- if (pipes[2] >= 0) close(pipes[2]); +- +- if (pipe(&pipes[0])) +- goto error; +- if (pipe(&pipes[2])) +- goto error; +- +- memset(&act, 0, sizeof(act)); +- sigemptyset(&act.sa_mask); +- act.sa_flags = SA_RESTART; +- act.sa_handler = sigchild; +- sigaction(SIGCHLD, &act, 0); +- +- if (!handle) +- handle = mmap(NULL, buflen, PROT_READ|PROT_WRITE, +- MAP_ANONYMOUS|MAP_SHARED, -1, 0); +- if (handle == MAP_FAILED) +- goto error; +- +- if ((active = fork()) < 0) +- goto error; +- +- if (active) { +- close(pipes[0]); +- close(pipes[3]); +- pipes[0] = pipes[3] = -1; +- return; +- } +- +- sigemptyset(&sigset); +- sigaddset(&sigset, SIGALRM); +- sigprocmask(SIG_BLOCK, &sigset, &oldset); +- +- act.sa_handler = SIG_DFL; +- sigaction(SIGCHLD, &act, 0); +- +- close(pipes[1]); +- close(pipes[2]); +- dup2(pipes[0], STDIN_FILENO); +- dup2(pipes[3], STDOUT_FILENO); +- close(pipes[0]); +- close(pipes[3]); +- pipes[1] = pipes[2] = -1; +- pipes[0] = pipes[3] = -1; +- +- while ((in = read(STDIN_FILENO, &sync, sizeof(sync))) != 0) { +- ssize_t out; +- if (in < 0) { +- if (errno == EINTR) +- continue; +- break; +- } +- if (!handle) +- break; +- if (handle->function(handle->path, &handle->argument) < 0) +- handle->errcode = errno; +- do +- out = write(STDOUT_FILENO, &sync, sizeof(sync)); +- while (out < 0 && errno == EINTR); +- } +- +- sigprocmask(SIG_SETMASK, &oldset, NULL); +- exit(0); +-error: +- if (pipes[0] >= 0) close(pipes[0]); +- if (pipes[1] >= 0) close(pipes[1]); +- if (pipes[2] >= 0) close(pipes[2]); +- if (pipes[3] >= 0) close(pipes[3]); +- if (handle && handle != MAP_FAILED) +- munmap(handle, buflen); +- handle = NULL; +-} +- +-static void /* attribute((destructor)) */ stop(void) +-{ +- if (active && waitpid(active, NULL, WNOHANG|WUNTRACED) == 0) +- kill(active, SIGKILL); +-} +- +-/* +- * External routine +- * +- * Execute stat(2) system call with timeout to avoid deadlock +- * on network based file systems. +- * +- */ +-int +-timeout(stat_t function, const char *path, struct stat *restrict argument, time_t seconds) +-{ +- struct sigaction alrm_act, pipe_act, new_act; +- sigset_t sigset, oldset; +- char sync[1] = "x"; +- +- if (active <= 0) /* Oops, last one failed therefore clear status and restart */ +- start(); +- if (!handle) /* No shared memory area */ +- return function(path, argument); +- memset(handle, 0, sizeof(handle_t)); +- handle->len = strlen(path) + 1; +- if (handle->len >= PATH_MAX) { +- errno = ENAMETOOLONG; +- goto error; +- } +- handle->errcode = 0; +- handle->argument = *argument; +- handle->function = function; +- strcpy(handle->path, path); +- +- sigemptyset(&sigset); +- sigaddset(&sigset, SIGALRM); +- sigaddset(&sigset, SIGPIPE); +- sigprocmask(SIG_UNBLOCK, &sigset, &oldset); +- +- memset(&new_act, 0, sizeof(new_act)); +- sigemptyset(&new_act.sa_mask); +- new_act.sa_flags = SA_RESETHAND; +- +- if (sigsetjmp(jenv, 1)) +- goto timed; +- +- new_act.sa_handler = sigjump; +- sigaction(SIGALRM, &new_act, &alrm_act); +- sigaction(SIGPIPE, &new_act, &pipe_act); +- alarm(seconds); +- +- write(pipes[1], &sync, sizeof(sync)); +- read(pipes[2], &sync, sizeof(sync)); +- +- alarm(0); +- sigaction(SIGPIPE, &pipe_act, NULL); +- sigaction(SIGALRM, &alrm_act, NULL); +- +- if (handle->errcode) { +- errno = handle->errcode; +- goto error; +- } +- +- *argument = handle->argument; +- sigprocmask(SIG_SETMASK, &oldset, NULL); +- +- return 0; +-timed: +- (void) alarm(0); +- sigaction(SIGPIPE, &pipe_act, NULL); +- sigaction(SIGALRM, &alrm_act, NULL); +- sigprocmask(SIG_SETMASK, &oldset, NULL); +- stop(); +- errno = ETIMEDOUT; +-error: +- return -1; +-} +-#elif WITH_TIMEOUT_STAT == 1 +-/* +- * External routine +- * +- * Execute stat(2) system call with timeout to avoid deadlock +- * on network based file systems. +- * +- */ +-int +-timeout(stat_t function, const char *path, struct stat *restrict argument, time_t seconds) +-{ +- struct sigaction alrm_act, pipe_act, new_act; +- sigset_t sigset, oldset; +- int ret = 0, pipes[4]; +- pid_t pid = 0; +- ssize_t len; +- +- if (pipe(&pipes[0]) < 0) +- goto error; +- switch ((pid = fork())) { +- case -1: +- close(pipes[0]); +- close(pipes[1]); +- goto error; +- case 0: +- new_act.sa_handler = SIG_DFL; +- sigaction(SIGALRM, &new_act, NULL); +- close(pipes[0]); +- if ((ret = function(path, argument)) == 0) +- do +- len = write(pipes[1], argument, sizeof(struct stat)); +- while (len < 0 && errno == EINTR); +- close(pipes[1]); +- exit(ret); +- default: +- close(pipes[1]); +- +- sigemptyset(&sigset); +- sigaddset(&sigset, SIGALRM); +- sigaddset(&sigset, SIGPIPE); +- sigprocmask(SIG_UNBLOCK, &sigset, &oldset); +- +- memset(&new_act, 0, sizeof(new_act)); +- sigemptyset(&new_act.sa_mask); +- +- if (sigsetjmp(jenv, 1)) +- goto timed; +- +- new_act.sa_handler = sigjump; +- sigaction(SIGALRM, &new_act, &alrm_act); +- sigaction(SIGPIPE, &new_act, &pipe_act); +- alarm(seconds); +- if (read(pipes[0], argument, sizeof(struct stat)) == 0) { +- errno = EFAULT; +- ret = -1; +- } +- (void)alarm(0); +- sigaction(SIGPIPE, &pipe_act, NULL); +- sigaction(SIGALRM, &alrm_act, NULL); +- +- close(pipes[0]); +- waitpid(pid, NULL, 0); +- break; +- } +- return ret; +-timed: +- (void)alarm(0); +- sigaction(SIGPIPE, &pipe_act, NULL); +- sigaction(SIGALRM, &alrm_act, NULL); +- if (waitpid(0, NULL, WNOHANG) == 0) +- kill(pid, SIGKILL); +- errno = ETIMEDOUT; +-error: +- return -1; +-} +-#endif +- +-/* +- * End of timeout.c +- */ +diff --git src/timeout.h src/timeout.h +deleted file mode 100644 +index f372297..0000000 +--- src/timeout.h ++++ /dev/null +@@ -1,45 +0,0 @@ +-/* +- * timout.h Advanced timeout handling for file system calls +- * to avoid deadlocks on remote file shares. +- * +- * Version: 0.1 07-Sep-2011 Fink +- * +- * Copyright 2011 Werner Fink, 2011 SUSE LINUX Products GmbH, Germany. +- * +- * This program is free software; you can redistribute it and/or modify +- * it under the terms of the GNU General Public License as published by +- * the Free Software Foundation; either version 2 of the License, or +- * (at your option) any later version. +- * +- * Author: Werner Fink , 2011 +- */ +- +-#ifndef _TIMEOUT_H +-#define _TIMEOUT_H +- +-#include "config.h" +- +-#ifndef WITH_TIMEOUT_STAT +-# define WITH_TIMEOUT_STAT 0 +-#endif +- +-#include +-#include +-#include +-#include +- +-#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) +-# ifndef restrict +-# define restrict __restrict__ +-# endif +-#endif +- +-typedef int (*stat_t)(const char *, struct stat *); +- +-#if WITH_TIMEOUT_STAT > 0 +-extern int timeout(stat_t, const char *, struct stat *restrict, time_t); +-#else +-# define timeout(func,path,buf,dummy) (func)((path),(buf)) +-#endif +- +-#endif +-- +2.16.4 + diff --git a/psmisc-23.0-killall-signals.patch b/psmisc-23.0-killall-signals.patch deleted file mode 100644 index 4e71d52..0000000 --- a/psmisc-23.0-killall-signals.patch +++ /dev/null @@ -1,87 +0,0 @@ ---- src/killall.c 2017-07-06 16:23:15.693736411 +0200 -+++ src/killall.c 2017-09-18 12:00:46.506409019 +0200 -@@ -796,6 +796,18 @@ have_proc_self_stat (void) - return stat(filename, &isproc) == 0; - } - -+typedef struct -+{ -+ int number; -+ const char *sig; -+} -+SIGNAME; -+ -+static SIGNAME signals[] = { -+#include "signames.h" -+ {0, NULL} -+}; -+ - int - main (int argc, char **argv) - { -@@ -807,7 +819,7 @@ main (int argc, char **argv) - char yt[16]; - char ot[16]; - -- //int optsig = 0; -+ int optsig; - - struct option options[] = { - {"exact", 0, NULL, 'e'}, -@@ -828,6 +840,7 @@ main (int argc, char **argv) - {"context", 1, NULL, 'Z'}, - #endif /*WITH_SELINUX*/ - {"version", 0, NULL, 'V'}, -+ {"dummy", 0, NULL, 'd'}, - {0,0,0,0 }}; - - opt_ns_pid = getpid(); -@@ -852,14 +865,46 @@ main (int argc, char **argv) - name = *argv; - sig_num = SIGTERM; - -+ optsig = argc; -+ while (--optsig) { -+ char *sig; -+ size_t len; -+ if (*(argv[optsig]) != '-') -+ continue; -+ sig = argv[optsig]+1; -+ len = strlen(sig); -+ if (*sig >= '0' && *sig <= '9') { -+ sig_num = atoi (sig); -+ memset(sig, 0, strlen(sig)); -+ *sig = 'd'; -+ } else if (len >= 3 && *sig >= 'A' && *sig <= 'Z') { -+ SIGNAME *walk; -+ char *opt = sig; -+ if (!strncmp("SIG", sig, 3)) -+ sig += 3; -+ for (walk = signals; walk->sig; walk++) { -+ if (!strcmp (walk->sig, sig)) -+ break; -+ } -+ if (walk->sig) { -+ sig_num = walk->number; -+ memset(opt, 0, strlen(opt)); -+ *opt = 'd'; -+ break; -+ } -+ } -+ } - - opterr = 0; -+ unsetenv("POSIXLY_CORRECT"); - #ifdef WITH_SELINUX -- while ( (optc = getopt_long_only(argc,argv,"egy:o:ilqrs:u:vwZ:VIn:",options,NULL)) != -1) { -+ while ( (optc = getopt_long_only(argc,argv,"degy:o:ilqrs:u:vwZ:VIn:",options,NULL)) != -1) { - #else -- while ( (optc = getopt_long_only(argc,argv,"egy:o:ilqrs:u:vwVIn:",options,NULL)) != -1) { -+ while ( (optc = getopt_long_only(argc,argv,"degy:o:ilqrs:u:vwVIn:",options,NULL)) != -1) { - #endif - switch (optc) { -+ case 'd': -+ break; - case 'e': - exact = 1; - break; diff --git a/psmisc-23.0-killall.patch b/psmisc-23.0-killall.patch deleted file mode 100644 index c342efc..0000000 --- a/psmisc-23.0-killall.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- - src/killall.c | 1 - - 1 file changed, 1 deletion(-) - ---- src/killall.c -+++ src/killall.c 2017-06-28 09:56:38.126984904 +0000 -@@ -972,7 +972,6 @@ main (int argc, char **argv) - exit (1); - } - argv = argv + myoptind; -- printf("sending signal %d to procs\n", sig_num); - #ifdef WITH_SELINUX - return kill_all(sig_num,argc - myoptind, argv, pwent, - scontext ? &scontext_reg : NULL); diff --git a/psmisc-23.0.dif b/psmisc-23.0.dif deleted file mode 100644 index 9166eac..0000000 --- a/psmisc-23.0.dif +++ /dev/null @@ -1,70 +0,0 @@ ---- - configure.ac | 4 ++-- - doc/Makefile.am | 2 +- - src/fuser.c | 5 ++++- - 3 files changed, 7 insertions(+), 4 deletions(-) - ---- configure.ac -+++ configure.ac 2018-06-22 16:47:02.758993991 +0000 -@@ -45,7 +45,7 @@ fi - if test "$enable_timeout_stat" = "static"; then - AC_DEFINE([WITH_TIMEOUT_STAT], [2], [Use timeout on stat calls]) - fi --AM_CONDITIONAL([WANT_TIMEOUT_STAT], [test "$enable_timeout_stat" = "static"]) -+AM_CONDITIONAL([WANT_TIMEOUT_STAT], [test "$enable_timeout_stat" != "no"]) - - # Use /proc/self/mountinfo if available - if test -e /proc/self/mountinfo ; then -@@ -142,7 +142,7 @@ AC_CHECK_MEMBERS([struct user_regs_struc - struct user_regs_struct.rdi, - struct user_regs_struct.rsi, - struct user_regs_struct.rdx], [],[], -- [#include -+ [#include - #include ]) - AC_CHECK_MEMBERS([struct pt_regs.orig_gpr3, - struct pt_regs.gpr], [],[], [#include ]) ---- doc/Makefile.am -+++ doc/Makefile.am 2018-06-22 16:47:02.842992443 +0000 -@@ -1,5 +1,5 @@ - --man_MANS = killall.1 peekfd.1 prtstat.1 pstree.1 -+man_MANS = killall.1 peekfd.1 prtstat.1 pstree.1 pslog.1 - EXTRA_MANS = - - if WANT_FUSER ---- src/fuser.c -+++ src/fuser.c 2018-06-22 16:47:02.926990894 +0000 -@@ -1097,6 +1097,7 @@ int main(int argc, char *argv[]) - struct option *optr; - char *nsptr; - int skip_argv; -+ int seen_file; - - struct option options[] = { - {"all", 0, NULL, 'a'}, -@@ -1140,6 +1141,7 @@ int main(int argc, char *argv[]) - #endif - atexit(atexit_free_lists); - -+ seen_file = 0; - for (argc_cnt = 1; argc_cnt < argc; argc_cnt++) { - current_argv = argv[argc_cnt]; - if (current_argv[0] == '-') { /* its an option */ -@@ -1285,6 +1287,7 @@ int main(int argc, char *argv[]) - } - } - this_name->matched_procs = NULL; -+ seen_file = 1; - if (opts & (OPT_MOUNTS | OPT_ISMOUNTPOINT) - && this_name->name_space != NAMESPACE_FILE) { - free(this_name); -@@ -1338,7 +1341,7 @@ int main(int argc, char *argv[]) - names_tail->next = this_name; - names_tail = this_name; - } /* for across the argvs */ -- if (names_head == NULL) -+ if (names_head == NULL && !seen_file) - usage(_("No process specification given")); - - /* Check if -M flag was used and if so check mounts */ diff --git a/psmisc-23.0.tar.bz2 b/psmisc-23.0.tar.bz2 deleted file mode 100644 index f878283..0000000 --- a/psmisc-23.0.tar.bz2 +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:215c6005c57e2b79606f602041f936f5e332ff1254a7d4c0bf15dd40e6c2b065 -size 156076 diff --git a/psmisc-v23.2.dif b/psmisc-v23.2.dif new file mode 100644 index 0000000..bcaf6e3 --- /dev/null +++ b/psmisc-v23.2.dif @@ -0,0 +1,51 @@ +--- + configure.ac | 2 +- + src/fuser.c | 5 ++++- + 2 files changed, 5 insertions(+), 2 deletions(-) + +--- configure.ac ++++ configure.ac 2018-11-02 13:34:07.811373984 +0000 +@@ -132,7 +132,7 @@ AC_CHECK_MEMBERS([struct user_regs_struc + struct user_regs_struct.rdi, + struct user_regs_struct.rsi, + struct user_regs_struct.rdx], [],[], +- [#include ++ [#include + #include ]) + AC_CHECK_MEMBERS([struct pt_regs.orig_gpr3, + struct pt_regs.gpr], [],[], [#include ]) +--- src/fuser.c ++++ src/fuser.c 2018-11-02 13:34:07.811373984 +0000 +@@ -1094,6 +1094,7 @@ int main(int argc, char *argv[]) + struct option *optr; + char *nsptr; + int skip_argv; ++ int seen_file; + + struct option options[] = { + {"all", 0, NULL, 'a'}, +@@ -1137,6 +1138,7 @@ int main(int argc, char *argv[]) + #endif + atexit(atexit_free_lists); + ++ seen_file = 0; + for (argc_cnt = 1; argc_cnt < argc; argc_cnt++) { + current_argv = argv[argc_cnt]; + if (current_argv[0] == '-') { /* its an option */ +@@ -1279,6 +1281,7 @@ int main(int argc, char *argv[]) + } + } + this_name->matched_procs = NULL; ++ seen_file = 1; + if (opts & (OPT_MOUNTS | OPT_ISMOUNTPOINT) + && this_name->name_space != NAMESPACE_FILE) { + free(this_name); +@@ -1332,7 +1335,7 @@ int main(int argc, char *argv[]) + names_tail->next = this_name; + names_tail = this_name; + } /* for across the argvs */ +- if (names_head == NULL) ++ if (names_head == NULL && !seen_file) + usage(_("No process specification given")); + + /* Check if -M flag was used and if so check mounts */ diff --git a/psmisc-v23.2.tar.bz2 b/psmisc-v23.2.tar.bz2 new file mode 100644 index 0000000..fd8fca5 --- /dev/null +++ b/psmisc-v23.2.tar.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f7807eb8bf8bac6835a81ef3740924755f1f3b8402d4e7b5ee1ab8a699c9679 +size 160432 diff --git a/psmisc.changes b/psmisc.changes index b3051eb..9368322 100644 --- a/psmisc.changes +++ b/psmisc.changes @@ -1,3 +1,44 @@ +------------------------------------------------------------------- +Mon Nov 5 07:48:25 UTC 2018 - Dr. Werner Fink + +- Modify patch 0002-Use-new-statx-2-system-call-to-avoid-hangs-on-NFS.patch + to support older systems with statx kernel support + +------------------------------------------------------------------- +Fri Nov 2 13:37:49 UTC 2018 - Dr. Werner Fink + +- Modify patch 0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch + to respect autofs as well as afs file system +- Add patch 0002-Use-new-statx-2-system-call-to-avoid-hangs-on-NFS.patch + to use statx(2) system call since kernel 4.12. Now it is possible + to avoid sync with remote file servers as well as trigger autofs + mounts due stat(x) calls. + +------------------------------------------------------------------- +Tue Oct 23 10:10:12 UTC 2018 - Dr. Werner Fink + +- Support also btrFS entries in mountinfo, that is use stat(2) to + determine the device of the mounted subvolume (bsc#1098697, bsc#1112780) + +------------------------------------------------------------------- +Mon Oct 22 10:52:10 UTC 2018 - Dr. Werner Fink + +- Update to version 23.2 + * misc: Command names increased from 16 to 64 characters + * buildsys: signals.c depends on signames.h !16 + * docs: Fix fuser.1 groff errors Debian #900225 + * killall: look at all namespaces by default + * killall: Fix -INT option parsing #11 + * killall: ignore -n 0 #15 + * killall: another crack at fixing getopt #12 #13 + * peekfd: Attach to all threads option !15 + * pslog: Define PATH_MAX if required Debian:#905797 +- Modify patch 0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch +- Remove patches now upstream solved + * psmisc-23.0-killall-signals.patch + * psmisc-23.0-killall.patch +- Modify and rename patch psmisc-23.0.dif which now becomes psmisc-v23.2.dif + ------------------------------------------------------------------- Mon Sep 17 12:08:31 UTC 2018 - Dr. Werner Fink diff --git a/psmisc.spec b/psmisc.spec index 347b537..3fa6122 100644 --- a/psmisc.spec +++ b/psmisc.spec @@ -12,7 +12,7 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ # @@ -24,26 +24,23 @@ BuildRequires: gcc-c++ BuildRequires: gettext-devel BuildRequires: glibc-devel BuildRequires: libselinux-devel +BuildRequires: linux-glibc-devel >= 4.12 BuildRequires: ncurses-devel Url: https://gitlab.com/psmisc/psmisc/ -Version: 23.0 +Version: 23.2 Release: 0 Provides: ps:/usr/bin/killall Recommends: %{name}-lang Summary: Utilities for managing processes on your system License: GPL-2.0-or-later Group: System/Monitoring -%define hash 67b1da268f4c0ce6859980e3dfcfaec5b2448e80 -Source: https://gitlab.com/%{name}/%{name}/repository/archive.tar.bz2?ref=v%{version}#/%{name}-%{version}.tar.bz2 -Patch0: %{name}-%{version}.dif +Source: https://gitlab.com/%{name}/%{name}/-/archive/v%{version}/%{name}-v%{version}.tar.bz2 +Patch0: %{name}-v%{version}.dif Patch2: %{name}-22.21-pstree.patch # PATCH-ADD-SUSE boo#908068, boo#1046237, boo#1046237 # https://gitlab.com/bitstreamout/psmisc/tree/mountinfo Patch3: 0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch -# PATCH-FIX-UPSTREAM boo#1046237 -- Debug output in killall from psmisc package -Patch4: %{name}-%{version}-killall.patch -# PATCH-FIX-SUSE boo#1058990 -- killall requires -s or --signal to specify signal on the command line -Patch5: %{name}-%{version}-killall-signals.patch +Patch4: 0002-Use-new-statx-2-system-call-to-avoid-hangs-on-NFS.patch %define have_peekfd %ix86 x86_64 ppc ppc64 ppc64le %arm mipsel m68k @@ -58,12 +55,10 @@ processes that are using specified files or filesystems. %lang_package %prep -ln -sf %{name}-v%{version}-%{hash} %{name}-%version -%setup -q -D -n %{name}-%version +%setup -q -n %{name}-v%{version} %patch2 -p0 -b .pstree %patch3 -p0 -b .mntinf -%patch4 -p0 -b .ka -%patch5 -p0 -b .ks +%patch4 -p0 -b .statx %patch0 -p0 -b .p0 %build