Compare commits
1 Commits
Author | SHA256 | Date | |
---|---|---|---|
6075276f53 |
211
0001-fuser-Fix-expandpath.patch
Normal file
211
0001-fuser-Fix-expandpath.patch
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
From b61e3c44b636691d5d2d2519efc934eac03e0f22 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Craig Small <csmall@dropbear.xyz>
|
||||||
|
Date: Sat, 3 May 2025 11:10:11 +1000
|
||||||
|
Subject: [PATCH] fuser: Fix expandpath
|
||||||
|
|
||||||
|
The function expandpath had some issues:
|
||||||
|
* It would fail if you looked at non-Unix sockets
|
||||||
|
* get_pidfd called it twice most times
|
||||||
|
* it would try to find symlinks in /proc/<PID>/fd
|
||||||
|
* it kept scanning /proc/self/net/unix over and over
|
||||||
|
|
||||||
|
This meant fuser ran really slow, and would never find
|
||||||
|
any TCP/UDP sockets (and probably anything else that wasn't
|
||||||
|
a normal file/directory or Unix socket).
|
||||||
|
|
||||||
|
The main changes are:
|
||||||
|
If we know we are looking at procfs, skip over scanning for
|
||||||
|
directories.
|
||||||
|
Use the already parsed unix sockets list
|
||||||
|
If we find a socket and its not a unix socket, return the orginal path
|
||||||
|
|
||||||
|
References:
|
||||||
|
commit 366b0071aa889d2620b78f1cf4e197771171aea8
|
||||||
|
issue #57
|
||||||
|
|
||||||
|
Signed-off-by: Craig Small <csmall@dropbear.xyz>
|
||||||
|
---
|
||||||
|
ChangeLog | 1 +
|
||||||
|
src/fuser.c | 73 +++++++++++++++++++----------------------------------
|
||||||
|
2 files changed, 27 insertions(+), 47 deletions(-)
|
||||||
|
|
||||||
|
|diff --git a/ChangeLog b/ChangeLog
|
||||||
|
|index 4222066..edf164e 100644
|
||||||
|
|--- a/ChangeLog
|
||||||
|
|+++ b/ChangeLog
|
||||||
|
|@@ -1,6 +1,7 @@
|
||||||
|
| Changes in NEXT
|
||||||
|
| ===============
|
||||||
|
| * fuser: Use mountinfo to distinguish NFS mounts !40
|
||||||
|
|+ * fuser: Make TCP/UDP sockets work again #57
|
||||||
|
| * killall,pstree: Use gettime instead of uptime Debian 1066090
|
||||||
|
| * pstree: Add -P to show path of exe !38
|
||||||
|
|
|
||||||
|
diff --git a/src/fuser.c b/src/fuser.c
|
||||||
|
index b31338e..d3622d6 100644
|
||||||
|
--- a/src/fuser.c
|
||||||
|
+++ b/src/fuser.c
|
||||||
|
@@ -134,7 +134,7 @@ static ino_t get_namespace(const pid_t pid);
|
||||||
|
static int get_mountid(const char *path);
|
||||||
|
#endif
|
||||||
|
static int find_mountpoint(const char *path, mntinfo_t **mountinfo);
|
||||||
|
-static char *expandpath(const char *path);
|
||||||
|
+static char *expandpath(const char *path, const bool isproc);
|
||||||
|
static struct unixsocket_list *unixsockets = NULL;
|
||||||
|
static struct names *names_head = NULL, *names_tail = NULL;
|
||||||
|
static struct ip_connections *tcp_connection_list = NULL;
|
||||||
|
@@ -541,7 +541,7 @@ int parse_file(
|
||||||
|
const opt_type opts)
|
||||||
|
{
|
||||||
|
mntinfo_t *mountinfo;
|
||||||
|
- char *new = expandpath(this_name->filename);
|
||||||
|
+ char *new = expandpath(this_name->filename, false);
|
||||||
|
if (new)
|
||||||
|
{
|
||||||
|
if (this_name->filename)
|
||||||
|
@@ -1722,7 +1722,7 @@ static struct stat *get_pidstat(
|
||||||
|
if (id)
|
||||||
|
{
|
||||||
|
mntinfo_t *info;
|
||||||
|
- char *new = expandpath(pathname);
|
||||||
|
+ char *new = expandpath(pathname, true);
|
||||||
|
if (new && find_mountpoint(new, &info) == 0)
|
||||||
|
*id = info->id;
|
||||||
|
else *id = -1;
|
||||||
|
@@ -2442,11 +2442,10 @@ static int get_fdinfo(
|
||||||
|
const static char delimiters[] = ": \t\n";
|
||||||
|
char line[BUFSIZ];
|
||||||
|
FILE *fp;
|
||||||
|
-# if defined(HAS_NAME_TO_HANDLE_AT)
|
||||||
|
char *realname;
|
||||||
|
-# endif
|
||||||
|
|
||||||
|
snprintf(pathname, sizeof(pathname)-1, "/proc/%d/fdinfo/%s", pid, fd);
|
||||||
|
+
|
||||||
|
if ((fp = fopen(pathname, "r")) == NULL)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
@@ -2470,9 +2469,9 @@ static int get_fdinfo(
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
out:
|
||||||
|
-# if defined(HAS_NAME_TO_HANDLE_AT)
|
||||||
|
snprintf(pathname, sizeof(pathname)-1, "/proc/%d/fd/%s", pid, fd);
|
||||||
|
- realname = expandpath(pathname);
|
||||||
|
+ realname = expandpath(pathname, true);
|
||||||
|
+# if defined(HAS_NAME_TO_HANDLE_AT)
|
||||||
|
if (realname)
|
||||||
|
{
|
||||||
|
info->mnt_id = get_mountid(realname);
|
||||||
|
@@ -2485,7 +2484,6 @@ out:
|
||||||
|
{
|
||||||
|
struct stat lst;
|
||||||
|
|
||||||
|
- snprintf(pathname, sizeof(pathname)-1, "/proc/%d/fd/%s", pid, fd);
|
||||||
|
if (!flags && lstatn(pathname, STATX_MODE, &lst) == 0)
|
||||||
|
{
|
||||||
|
if (lst.st_mode & S_IWUSR)
|
||||||
|
@@ -2495,7 +2493,6 @@ out:
|
||||||
|
|
||||||
|
if (!mnt_id)
|
||||||
|
{
|
||||||
|
- realname = expandpath(pathname);
|
||||||
|
if (realname)
|
||||||
|
{
|
||||||
|
mntinfo_t *mountinfo;
|
||||||
|
@@ -2699,7 +2696,8 @@ out:
|
||||||
|
*/
|
||||||
|
static char real[PATH_MAX + 1];
|
||||||
|
char *expandpath(
|
||||||
|
- const char *path)
|
||||||
|
+ const char *path,
|
||||||
|
+ const bool isproc)
|
||||||
|
{
|
||||||
|
char tmpbuf[PATH_MAX + 1];
|
||||||
|
const char *start, *end;
|
||||||
|
@@ -2726,7 +2724,10 @@ char *expandpath(
|
||||||
|
while (*start == '/')
|
||||||
|
++start;
|
||||||
|
|
||||||
|
- for (end = start; *end && *end != '/'; ++end) ;
|
||||||
|
+ if (isproc)
|
||||||
|
+ end = start + strlen(start);
|
||||||
|
+ else
|
||||||
|
+ for (end = start; *end && *end != '/'; ++end) ;
|
||||||
|
|
||||||
|
if (end - start == 0)
|
||||||
|
break;
|
||||||
|
@@ -2741,6 +2742,7 @@ char *expandpath(
|
||||||
|
char lnkbuf[PATH_MAX + 1];
|
||||||
|
size_t len;
|
||||||
|
ssize_t n;
|
||||||
|
+ unsigned long long lnk_inode;
|
||||||
|
|
||||||
|
if (dest[-1] != '/')
|
||||||
|
*dest++ = '/';
|
||||||
|
@@ -2773,49 +2775,26 @@ char *expandpath(
|
||||||
|
/*
|
||||||
|
* Expand to real path of named socket if any
|
||||||
|
*/
|
||||||
|
- if (lnkbuf[0] != '/' && strncmp("socket:[", lnkbuf, 8) == 0)
|
||||||
|
+ if (lnkbuf[0] != '/' && sscanf(lnkbuf, "socket:[%llu]", &lnk_inode) == 1)
|
||||||
|
{
|
||||||
|
- FILE *fp;
|
||||||
|
- char *inode;
|
||||||
|
- char line[BUFSIZ];
|
||||||
|
- if ((inode = strchr(&lnkbuf[8], ']')))
|
||||||
|
- {
|
||||||
|
- *inode = '\0';
|
||||||
|
- inode = &lnkbuf[8];
|
||||||
|
- }
|
||||||
|
-
|
||||||
|
- if (!inode || (fp = fopen(PROC_SOCKETS, "r")) == NULL)
|
||||||
|
- {
|
||||||
|
- /*fprintf(stderr, "Cannot open %s\n", PROC_SOCKETS); */
|
||||||
|
- return (char *)0;
|
||||||
|
- }
|
||||||
|
- while (fgets(line, BUFSIZ, fp) != NULL)
|
||||||
|
+ struct unixsocket_list *sock_tmp;
|
||||||
|
+ for (sock_tmp = unixsockets; sock_tmp != NULL; sock_tmp = sock_tmp->next)
|
||||||
|
{
|
||||||
|
- char *named = NULL;
|
||||||
|
- unsigned long snode;
|
||||||
|
-
|
||||||
|
- if (*line == 'N')
|
||||||
|
- continue;
|
||||||
|
-
|
||||||
|
- if (sscanf(line, "%*x: %*x %*x %*x %*x %*x %lu %ms",
|
||||||
|
- &snode, &named) == 2)
|
||||||
|
+ if (sock_tmp->net_inode == lnk_inode)
|
||||||
|
{
|
||||||
|
- char *ep;
|
||||||
|
- unsigned long oul = strtoul(inode, &ep, 0);
|
||||||
|
- if (oul == snode) {
|
||||||
|
- ep = named;
|
||||||
|
- if (*ep == '@')
|
||||||
|
- ep++;
|
||||||
|
- n = strlen(ep);
|
||||||
|
- memcpy(lnkbuf, ep, n);
|
||||||
|
- lnkbuf[n] = '\0';
|
||||||
|
- }
|
||||||
|
- free (named);
|
||||||
|
+ strncpy(lnkbuf, sock_tmp->sun_name, PATH_MAX);
|
||||||
|
+ n = strlen(sock_tmp->sun_name);
|
||||||
|
+ break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
- fclose(fp);
|
||||||
|
+ if (sock_tmp == NULL) // socket, but not unix socket
|
||||||
|
+ {
|
||||||
|
+ strcpy(real, path);
|
||||||
|
+ return curr;
|
||||||
|
+ }
|
||||||
|
}
|
||||||
|
|
||||||
|
+ lnkbuf[n] = '\0';
|
||||||
|
len = strlen(end);
|
||||||
|
if ((n + len) > PATH_MAX)
|
||||||
|
{
|
||||||
|
--
|
||||||
|
GitLab
|
||||||
|
|
16
psmisc-gcc15.patch
Normal file
16
psmisc-gcc15.patch
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
Index: psmisc-v23.7/src/lists.h
|
||||||
|
===================================================================
|
||||||
|
--- psmisc-v23.7.orig/src/lists.h
|
||||||
|
+++ psmisc-v23.7/src/lists.h
|
||||||
|
@@ -18,9 +18,10 @@
|
||||||
|
#define _LISTS_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
+#include <stdbool.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
-typedef enum _boolean {false, true} boolean;
|
||||||
|
+typedef bool boolean;
|
||||||
|
typedef unsigned char uchar;
|
||||||
|
#ifndef __USE_MISC
|
||||||
|
typedef unsigned short ushort;
|
@@ -1,3 +1,17 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Tue Jul 15 11:31:55 UTC 2025 - Dr. Werner Fink <werner@suse.de>
|
||||||
|
|
||||||
|
- Add patch 0001-fuser-Fix-expandpath.patch
|
||||||
|
* Is an upstream commit which fixes https://gitlab.com/psmisc/psmisc/-/issues/57
|
||||||
|
as well as bug boo#1242093
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
Thu Mar 13 09:45:47 UTC 2025 - pgajdos@suse.com
|
||||||
|
|
||||||
|
- fix build with gcc15
|
||||||
|
- added patches
|
||||||
|
+ psmisc-gcc15.patch
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Tue Feb 18 12:04:10 UTC 2025 - Dr. Werner Fink <werner@suse.de>
|
Tue Feb 18 12:04:10 UTC 2025 - Dr. Werner Fink <werner@suse.de>
|
||||||
|
|
||||||
|
@@ -46,6 +46,10 @@ Patch2: %{name}-22.21-pstree.patch
|
|||||||
# PATCH-ADD-SUSE boo#908068, boo#1046237, boo#1046237
|
# PATCH-ADD-SUSE boo#908068, boo#1046237, boo#1046237
|
||||||
# https://gitlab.com/bitstreamout/psmisc/tree/mountinfo
|
# https://gitlab.com/bitstreamout/psmisc/tree/mountinfo
|
||||||
Patch3: 0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch
|
Patch3: 0001-Use-mountinfo-to-be-able-to-use-the-mount-identity.patch
|
||||||
|
# https://gitlab.com/psmisc/psmisc/-/issues/59
|
||||||
|
Patch4: psmisc-gcc15.patch
|
||||||
|
# https://gitlab.com/psmisc/psmisc/-/issues/57
|
||||||
|
Patch5: 0001-fuser-Fix-expandpath.patch
|
||||||
|
|
||||||
%define have_peekfd %ix86 x86_64 ppc ppc64 ppc64le %arm mipsel m68k aarch64 loongarch64
|
%define have_peekfd %ix86 x86_64 ppc ppc64 ppc64le %arm mipsel m68k aarch64 loongarch64
|
||||||
|
|
||||||
@@ -64,7 +68,9 @@ processes that are using specified files or filesystems.
|
|||||||
%patch -P 1 -p0 -b .uptime
|
%patch -P 1 -p0 -b .uptime
|
||||||
%patch -P 2 -p0 -b .pstree
|
%patch -P 2 -p0 -b .pstree
|
||||||
%patch -P 3 -p0 -b .mntinf
|
%patch -P 3 -p0 -b .mntinf
|
||||||
|
%patch -P 5 -p1 -b .tcp
|
||||||
%patch -P 0 -p0 -b .p0
|
%patch -P 0 -p0 -b .p0
|
||||||
|
%patch -P 4 -p1
|
||||||
|
|
||||||
%build
|
%build
|
||||||
grep -h src/ po/*.po|\
|
grep -h src/ po/*.po|\
|
||||||
|
Reference in New Issue
Block a user