psmisc/psmisc-22.21-lessnfs.patch

83 lines
2.1 KiB
Diff
Raw Normal View History

Use string comparision only if case of searching for NFS shares
---
src/fuser.c | 30 +++++++++++++++++++++---------
src/fuser.h | 2 +-
2 files changed, 22 insertions(+), 10 deletions(-)
--- src/fuser.c
+++ src/fuser.c 2017-06-20 13:57:15.420444608 +0000
@@ -1831,7 +1831,7 @@ static void clear_mntinfo(void)
static void init_mntinfo(void)
{
- char mpoint[PATH_MAX + 1];
+ char mpoint[PATH_MAX+1], type[256];
int mid, parid, max = 0;
uint maj, min;
list_t sort;
@@ -1842,8 +1842,8 @@ static void init_mntinfo(void)
if ((mnt = fopen("/proc/self/mountinfo", "r")) == (FILE *) 0)
return;
while (fscanf
- (mnt, "%i %i %u:%u %*s %s %*[^\n]", &mid, &parid, &maj, &min,
- &mpoint[0]) == 5) {
+ (mnt, "%i %i %u:%u %*s %s %*s %*s - %s %*[^\n]",
+ &mid, &parid, &maj, &min, &mpoint[0], &type[0]) == 6) {
const size_t nlen = strlen(mpoint);
mntinfo_t *restrict mnt;
if (posix_memalign
@@ -1862,6 +1862,9 @@ static void init_mntinfo(void)
mnt->parid = parid;
mnt->dev = makedev(maj, min);
mnt->id = mid;
+ if (strncmp("nfs", type, 3) == 0)
+ mnt->nfs = 1;
+ else mnt->nfs = 0;
if (mid > max)
max = mid;
}
@@ -1929,16 +1932,25 @@ static int mntstat(const char *path, str
if (nlen < mnt->nlen)
continue;
if (mnt->nlen == 1) { /* root fs is the last entry */
- buf->st_dev = mnt->dev;
- buf->st_ino = 0;
- return 0;
+ if (mnt->nfs) {
+ fprintf(stderr, "NFS %s\n", use);
+ buf->st_dev = mnt->dev;
+ buf->st_ino = 0;
+ return 0;
+ }
+ errno = 0;
+ return stat(path, buf);
}
if (use[mnt->nlen] != '\0' && use[mnt->nlen] != '/')
continue;
if (strncmp(use, mnt->mpoint, mnt->nlen) == 0) {
- buf->st_dev = mnt->dev;
- buf->st_ino = 0;
- return 0;
+ if (mnt->nfs) {
+ buf->st_dev = mnt->dev;
+ buf->st_ino = 0;
+ return 0;
+ }
+ errno = 0;
+ return stat(path, buf);
}
}
errno = ENOENT;
--- src/fuser.h
+++ src/fuser.h 2017-06-20 13:57:15.424444535 +0000
@@ -90,7 +90,7 @@ struct mount_list {
# include "lists.h"
typedef struct mntinfo_s {
list_t this;
- int id, parid;
+ int id, parid, nfs:1;
dev_t dev;
size_t nlen;
char *mpoint;