.
OBS-URL: https://build.opensuse.org/package/show/Base:System/psmisc?expand=0&rev=36
This commit is contained in:
parent
6f744a908d
commit
edff8db17e
3
_service:download_files:psmisc-22.14.tar.gz
Normal file
3
_service:download_files:psmisc-22.14.tar.gz
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:22bbf4561837af475c0d8d14e3b9cab453998c787212c107fac7faf2f281e26e
|
||||||
|
size 382024
|
BIN
_service:download_files:psmisc-22.14.tar.gz.1
Normal file
BIN
_service:download_files:psmisc-22.14.tar.gz.1
Normal file
Binary file not shown.
105
_service:format_spec_file:psmisc.spec
Normal file
105
_service:format_spec_file:psmisc.spec
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#
|
||||||
|
# spec file for package psmisc
|
||||||
|
#
|
||||||
|
# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||||
|
#
|
||||||
|
# All modifications and additions to the file contributed by third parties
|
||||||
|
# remain the property of their copyright owners, unless otherwise agreed
|
||||||
|
# upon. The license for this file, and modifications and additions to the
|
||||||
|
# file, is the same license as for the pristine package itself (unless the
|
||||||
|
# license for the pristine package is not an Open Source License, in which
|
||||||
|
# case the license is the MIT License). An "Open Source License" is a
|
||||||
|
# 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/
|
||||||
|
#
|
||||||
|
|
||||||
|
# norootforbuild
|
||||||
|
|
||||||
|
|
||||||
|
Name: psmisc
|
||||||
|
BuildRequires: gcc-c++ glibc-devel ncurses-devel
|
||||||
|
BuildRequires: libselinux-devel
|
||||||
|
Url: http://sourceforge.net/projects/psmisc/
|
||||||
|
License: GPLv2+
|
||||||
|
Group: System/Monitoring
|
||||||
|
PreReq: %fillup_prereq %insserv_prereq
|
||||||
|
Version: 22.14
|
||||||
|
Release: 1
|
||||||
|
Provides: ps:/usr/bin/killall
|
||||||
|
Summary: Utilities for managing processes on your system
|
||||||
|
Source: http://sourceforge.net/projects/psmisc/files/psmisc/%{name}-%{version}.tar.gz
|
||||||
|
Patch0: %name-22.14.dif
|
||||||
|
Patch1: %name-22.12-tigetstr.patch
|
||||||
|
Patch2: %name-22.12-pstree_overflow.patch
|
||||||
|
Patch3: %name-22.12-pstree.patch
|
||||||
|
Patch4: %name-22.14-toomuch.dif
|
||||||
|
|
||||||
|
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||||
|
%define nopeek s390 s390x ia64 %sparc hppa
|
||||||
|
|
||||||
|
|
||||||
|
%description
|
||||||
|
The psmisc package contains utilities for managing processes on your
|
||||||
|
system: pstree, killall and fuser. The pstree command displays a tree
|
||||||
|
structure of all of the running processes on your system. The killall
|
||||||
|
command sends a specified signal (SIGTERM if nothing is specified) to
|
||||||
|
processes identified by name. The fuser command identifies the PIDs of
|
||||||
|
processes that are using specified files or filesystems.
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%setup -q
|
||||||
|
%patch1 -p0 -b .tigetstr
|
||||||
|
%patch2 -p0 -b .pstreeovfl
|
||||||
|
%patch3 -p0 -b .pstree
|
||||||
|
%patch4 -p0 -b .2much
|
||||||
|
%patch0 -p0 -b .0
|
||||||
|
|
||||||
|
|
||||||
|
%build
|
||||||
|
autoreconf -fi
|
||||||
|
CFLAGS="-D_GNU_SOURCE ${RPM_OPT_FLAGS} -pipe"
|
||||||
|
CXXFLAGS="$CFLAGS"
|
||||||
|
CC=gcc
|
||||||
|
CXX=g++
|
||||||
|
export CFLAGS CXXFLAGS CC CXX
|
||||||
|
sh ./configure --prefix=%{_prefix} --mandir=%{_mandir} --enable-selinux
|
||||||
|
make %{?_smp_mflags} CFLAGS="$CFLAGS" "CC=$CC"
|
||||||
|
|
||||||
|
|
||||||
|
%install
|
||||||
|
make DESTDIR=$RPM_BUILD_ROOT install
|
||||||
|
mkdir -p $RPM_BUILD_ROOT/bin/
|
||||||
|
mv $RPM_BUILD_ROOT/usr/bin/fuser $RPM_BUILD_ROOT/bin/
|
||||||
|
%ifarch %nopeek
|
||||||
|
rm -f $RPM_BUILD_ROOT%{_mandir}/man1/peekfd.1*
|
||||||
|
%endif
|
||||||
|
%find_lang psmisc
|
||||||
|
|
||||||
|
|
||||||
|
%clean
|
||||||
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
|
||||||
|
|
||||||
|
%files -f psmisc.lang
|
||||||
|
%defattr (-,root,root,755)
|
||||||
|
/bin/fuser
|
||||||
|
%{_bindir}/killall
|
||||||
|
%ifnarch %nopeek
|
||||||
|
%{_bindir}/peekfd
|
||||||
|
%endif
|
||||||
|
%{_bindir}/prtstat
|
||||||
|
%{_bindir}/pstree
|
||||||
|
%{_bindir}/pstree.x11
|
||||||
|
%{_mandir}/man1/fuser.1*
|
||||||
|
%{_mandir}/man1/killall.1*
|
||||||
|
%ifnarch %nopeek
|
||||||
|
%{_mandir}/man1/peekfd.1*
|
||||||
|
%endif
|
||||||
|
%{_mandir}/man1/prtstat.1*
|
||||||
|
%{_mandir}/man1/pstree.1*
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%changelog
|
@ -1,269 +0,0 @@
|
|||||||
--- src/fuser.c
|
|
||||||
+++ src/fuser.c 2010-07-13 14:42:02.762926098 +0000
|
|
||||||
@@ -148,18 +148,12 @@ scan_procs(struct names *names_head, str
|
|
||||||
{
|
|
||||||
DIR *topproc_dir;
|
|
||||||
struct dirent *topproc_dent;
|
|
||||||
- char *fd_dirpath, *fd_pathname;
|
|
||||||
struct inode_list *ino_tmp;
|
|
||||||
struct device_list *dev_tmp;
|
|
||||||
pid_t pid, my_pid;
|
|
||||||
uid_t uid;
|
|
||||||
struct stat *cwd_stat, *exe_stat, *root_stat;
|
|
||||||
|
|
||||||
- if ((fd_dirpath = malloc(MAX_PATHNAME)) == NULL)
|
|
||||||
- return;
|
|
||||||
- if ((fd_pathname = malloc(MAX_PATHNAME)) == NULL)
|
|
||||||
- return;
|
|
||||||
-
|
|
||||||
if ((topproc_dir = opendir("/proc")) == NULL) {
|
|
||||||
fprintf(stderr, _("Cannot open /proc directory: %s\n"),
|
|
||||||
strerror(errno));
|
|
||||||
@@ -219,6 +213,9 @@ scan_procs(struct names *names_head, str
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+ if (root_stat) free(root_stat);
|
|
||||||
+ if (cwd_stat) free(cwd_stat);
|
|
||||||
+ if (exe_stat) free(exe_stat);
|
|
||||||
check_dir(pid, "lib", dev_head, ino_head, uid, ACCESS_MMAP,
|
|
||||||
sockets, netdev);
|
|
||||||
check_dir(pid, "mmap", dev_head, ino_head, uid, ACCESS_MMAP,
|
|
||||||
@@ -237,10 +234,9 @@ add_inode(struct inode_list **ino_list,
|
|
||||||
{
|
|
||||||
struct inode_list *ino_tmp, *ino_head;
|
|
||||||
|
|
||||||
- ino_head = *ino_list;
|
|
||||||
-
|
|
||||||
- if ((ino_tmp = malloc(sizeof(struct inode_list))) == NULL)
|
|
||||||
+ if ((ino_tmp = (struct inode_list*)malloc(sizeof(struct inode_list))) == NULL)
|
|
||||||
return;
|
|
||||||
+ ino_head = *ino_list;
|
|
||||||
ino_tmp->name = this_name;
|
|
||||||
ino_tmp->device = device;
|
|
||||||
ino_tmp->inode = inode;
|
|
||||||
@@ -254,10 +250,10 @@ add_device(struct device_list **dev_list
|
|
||||||
struct device_list *dev_tmp, *dev_head;
|
|
||||||
|
|
||||||
/*printf("Adding device %s %d\n", this_name->filename, device); */
|
|
||||||
- dev_head = *dev_list;
|
|
||||||
|
|
||||||
- if ((dev_tmp = malloc(sizeof(struct device_list))) == NULL)
|
|
||||||
+ if ((dev_tmp = (struct device_list*)malloc(sizeof(struct device_list))) == NULL)
|
|
||||||
return;
|
|
||||||
+ dev_head = *dev_list;
|
|
||||||
dev_tmp->name = this_name;
|
|
||||||
dev_tmp->device = device;
|
|
||||||
dev_tmp->next = dev_head;
|
|
||||||
@@ -271,10 +267,9 @@ add_ip_conn(struct ip_connections **ip_l
|
|
||||||
{
|
|
||||||
struct ip_connections *ip_tmp, *ip_head;
|
|
||||||
|
|
||||||
- ip_head = *ip_list;
|
|
||||||
-
|
|
||||||
- if ((ip_tmp = malloc(sizeof(struct ip_connections))) == NULL)
|
|
||||||
+ if ((ip_tmp = (struct ip_connections*)malloc(sizeof(struct ip_connections))) == NULL)
|
|
||||||
return;
|
|
||||||
+ ip_head = *ip_list;
|
|
||||||
ip_tmp->name = this_name;
|
|
||||||
ip_tmp->lcl_port = lcl_port;
|
|
||||||
ip_tmp->rmt_port = rmt_port;
|
|
||||||
@@ -292,10 +287,9 @@ add_ip6_conn(struct ip6_connections **ip
|
|
||||||
{
|
|
||||||
struct ip6_connections *ip_tmp, *ip_head;
|
|
||||||
|
|
||||||
- ip_head = *ip_list;
|
|
||||||
-
|
|
||||||
- if ((ip_tmp = malloc(sizeof(struct ip6_connections))) == NULL)
|
|
||||||
+ if ((ip_tmp = (struct ip6_connections*)malloc(sizeof(struct ip6_connections))) == NULL)
|
|
||||||
return;
|
|
||||||
+ ip_head = *ip_list;
|
|
||||||
ip_tmp->name = this_name;
|
|
||||||
ip_tmp->lcl_port = lcl_port;
|
|
||||||
ip_tmp->rmt_port = rmt_port;
|
|
||||||
@@ -326,7 +320,7 @@ add_matched_proc(struct names *name_list
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Not found */
|
|
||||||
- if ((pptr = malloc(sizeof(struct procs))) == NULL) {
|
|
||||||
+ if ((pptr = (struct procs*)malloc(sizeof(struct procs))) == NULL) {
|
|
||||||
fprintf(stderr,
|
|
||||||
_("Cannot allocate memory for matched proc: %s\n"),
|
|
||||||
strerror(errno));
|
|
||||||
@@ -339,10 +333,13 @@ add_matched_proc(struct names *name_list
|
|
||||||
pptr->next = NULL;
|
|
||||||
/* set command name */
|
|
||||||
pptr->command = NULL;
|
|
||||||
+
|
|
||||||
+ fp = NULL;
|
|
||||||
+ pathname = NULL;
|
|
||||||
if ((asprintf(&pathname, "/proc/%d/stat", pid) > 0) &&
|
|
||||||
((fp = fopen(pathname, "r")) != NULL) &&
|
|
||||||
(fscanf(fp, "%*d (%100[^)]", cmdname) == 1))
|
|
||||||
- if ((pptr->command = malloc(MAX_CMDNAME + 1)) != NULL) {
|
|
||||||
+ if ((pptr->command = (char*)malloc(MAX_CMDNAME + 1)) != NULL) {
|
|
||||||
cmdlen = 0;
|
|
||||||
for (cptr = cmdname; cmdlen < MAX_CMDNAME && *cptr;
|
|
||||||
cptr++) {
|
|
||||||
@@ -359,6 +356,10 @@ add_matched_proc(struct names *name_list
|
|
||||||
name_list->matched_procs = pptr;
|
|
||||||
else
|
|
||||||
last_proc->next = pptr;
|
|
||||||
+ if (pathname)
|
|
||||||
+ free(pathname);
|
|
||||||
+ if (fp)
|
|
||||||
+ fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Adds a knfsd etc process */
|
|
||||||
@@ -680,7 +681,7 @@ find_net_sockets(struct inode_list **ino
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
- return;
|
|
||||||
+ fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef WITH_IPV6
|
|
||||||
@@ -753,6 +754,7 @@ find_net6_sockets(struct inode_list **in
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+ fclose(fp);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -1253,13 +1255,15 @@ static struct stat *get_pidstat(const pi
|
|
||||||
char pathname[256];
|
|
||||||
struct stat *st;
|
|
||||||
|
|
||||||
- if ((st = malloc(sizeof(struct stat))) == NULL)
|
|
||||||
+ if ((st = (struct stat*)malloc(sizeof(struct stat))) == NULL)
|
|
||||||
return NULL;
|
|
||||||
snprintf(pathname, 256, "/proc/%d/%s", pid, filename);
|
|
||||||
if (stat(pathname, st) != 0)
|
|
||||||
- return NULL;
|
|
||||||
- else
|
|
||||||
- return st;
|
|
||||||
+ goto out;
|
|
||||||
+ return st;
|
|
||||||
+out:
|
|
||||||
+ free(st);
|
|
||||||
+ return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
@@ -1267,7 +1271,7 @@ check_dir(const pid_t pid, const char *d
|
|
||||||
struct inode_list *ino_head, const uid_t uid, const char access,
|
|
||||||
struct unixsocket_list *sockets, dev_t netdev)
|
|
||||||
{
|
|
||||||
- char *dirpath, *filepath;
|
|
||||||
+ char *dirpath = NULL, *filepath = NULL;
|
|
||||||
DIR *dirp;
|
|
||||||
struct dirent *direntry;
|
|
||||||
struct inode_list *ino_tmp;
|
|
||||||
@@ -1275,14 +1279,14 @@ check_dir(const pid_t pid, const char *d
|
|
||||||
struct unixsocket_list *sock_tmp;
|
|
||||||
struct stat st, lst;
|
|
||||||
|
|
||||||
- if ((dirpath = malloc(MAX_PATHNAME)) == NULL)
|
|
||||||
- return;
|
|
||||||
- if ((filepath = malloc(MAX_PATHNAME)) == NULL)
|
|
||||||
- return;
|
|
||||||
+ if ((dirpath = (char*)malloc(MAX_PATHNAME)) == NULL)
|
|
||||||
+ goto out;
|
|
||||||
+ if ((filepath = (char*)malloc(MAX_PATHNAME)) == NULL)
|
|
||||||
+ goto out;
|
|
||||||
|
|
||||||
snprintf(dirpath, MAX_PATHNAME, "/proc/%d/%s", pid, dirname);
|
|
||||||
if ((dirp = opendir(dirpath)) == NULL)
|
|
||||||
- return;
|
|
||||||
+ goto out;
|
|
||||||
while ((direntry = readdir(dirp)) != NULL) {
|
|
||||||
if (direntry->d_name[0] < '0' || direntry->d_name[0] > '9')
|
|
||||||
continue;
|
|
||||||
@@ -1341,6 +1345,11 @@ check_dir(const pid_t pid, const char *d
|
|
||||||
}
|
|
||||||
} /* while fd_dent */
|
|
||||||
closedir(dirp);
|
|
||||||
+out:
|
|
||||||
+ if (dirpath)
|
|
||||||
+ free(dirpath);
|
|
||||||
+ if (filepath)
|
|
||||||
+ free(filepath);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
@@ -1400,7 +1409,6 @@ void fill_unix_cache(struct unixsocket_l
|
|
||||||
{
|
|
||||||
FILE *fp;
|
|
||||||
char line[BUFSIZ];
|
|
||||||
- char *scanned_path;
|
|
||||||
int scanned_inode;
|
|
||||||
struct stat st;
|
|
||||||
struct unixsocket_list *newsocket;
|
|
||||||
@@ -1411,24 +1419,38 @@ void fill_unix_cache(struct unixsocket_l
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while (fgets(line, BUFSIZ, fp) != NULL) {
|
|
||||||
+ char * path;
|
|
||||||
+ char * scanned_path = NULL;
|
|
||||||
if (sscanf(line, "%*x: %*x %*x %*x %*x %*d %d %as",
|
|
||||||
- &scanned_inode, &scanned_path) != 2)
|
|
||||||
+ &scanned_inode, &scanned_path) != 2) {
|
|
||||||
+ if (scanned_path)
|
|
||||||
+ free(scanned_path);
|
|
||||||
continue;
|
|
||||||
+ }
|
|
||||||
+ if (scanned_path == NULL)
|
|
||||||
+ continue;
|
|
||||||
+ path = scanned_path;
|
|
||||||
+ if (*scanned_path == '@')
|
|
||||||
+ scanned_path++;
|
|
||||||
if (stat(scanned_path, &st) < 0) {
|
|
||||||
- free(scanned_path);
|
|
||||||
+ free(path);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
- if ((newsocket =
|
|
||||||
- malloc(sizeof(struct unixsocket_list))) == NULL)
|
|
||||||
+ if ((newsocket = (struct unixsocket_list*)
|
|
||||||
+ malloc(sizeof(struct unixsocket_list))) == NULL) {
|
|
||||||
+ free(path);
|
|
||||||
continue;
|
|
||||||
+ }
|
|
||||||
newsocket->sun_name = strdup(scanned_path);
|
|
||||||
newsocket->inode = st.st_ino;
|
|
||||||
newsocket->dev = st.st_dev;
|
|
||||||
newsocket->net_inode = scanned_inode;
|
|
||||||
newsocket->next = *unixsocket_head;
|
|
||||||
*unixsocket_head = newsocket;
|
|
||||||
+ free(path);
|
|
||||||
} /* while */
|
|
||||||
|
|
||||||
+ fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
@@ -1567,6 +1589,7 @@ scan_knfsd(struct names *names_head, str
|
|
||||||
line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+ fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
@@ -1610,6 +1633,7 @@ scan_mounts(struct names *names_head, st
|
|
||||||
find_mountp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+ fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
@@ -1656,4 +1680,5 @@ scan_swaps(struct names *names_head, str
|
|
||||||
line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+ fclose(fp);
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:37c986a604ebfc72ddeea7dde48a5ddb0c0d8bdd7d81147626157e098243024b
|
|
||||||
size 6533
|
|
@ -1,129 +0,0 @@
|
|||||||
--- doc/fuser.1
|
|
||||||
+++ doc/fuser.1 2010-07-13 13:19:57.000000000 +0000
|
|
||||||
@@ -12,6 +12,7 @@ fuser \- identify processes using files
|
|
||||||
.RB [ \-k
|
|
||||||
.RB [ \-i ]
|
|
||||||
.RB [ \-M ]
|
|
||||||
+.RB [ \-w ]
|
|
||||||
.RB [ \- \fISIGNAL
|
|
||||||
] ]
|
|
||||||
.IR name " ..."
|
|
||||||
@@ -102,6 +103,10 @@ Request will be fulfilled only if \fINAM
|
|
||||||
This is an invaluable seatbelt which prevents you from killing the machine
|
|
||||||
if \fINAME\fR happens to not be a filesystem.
|
|
||||||
.TP
|
|
||||||
+\fB\-w\fP
|
|
||||||
+Kill only processes which have write access. This option is
|
|
||||||
+silently ignored if \fB\-k\fP is not present too.
|
|
||||||
+.TP
|
|
||||||
\fB\-n \fISPACE\fR, \fB\-\-namespace\fR \fISPACE\fR
|
|
||||||
Select a different name space. The name spaces \fBfile\fR (file names, the
|
|
||||||
default), \fBudp\fR (local UDP ports), and \fBtcp\fR (local TCP ports) are
|
|
||||||
--- src/fuser.c
|
|
||||||
+++ src/fuser.c 2010-07-13 13:25:44.000000000 +0000
|
|
||||||
@@ -75,7 +75,7 @@ static struct stat *get_pidstat(const op
|
|
||||||
static uid_t getpiduid(const pid_t pid);
|
|
||||||
static int print_matches(struct names *names_head, const opt_type opts,
|
|
||||||
const int sig_number);
|
|
||||||
-static void kill_matched_proc(struct procs *pptr, const opt_type opts,
|
|
||||||
+static int kill_matched_proc(struct procs *pptr, const opt_type opts,
|
|
||||||
const int sig_number);
|
|
||||||
|
|
||||||
/*int parse_mount(struct names *this_name, struct device_list **dev_list);*/
|
|
||||||
@@ -127,6 +127,7 @@ static void usage(const char *errormsg)
|
|
||||||
" -SIGNAL send this signal instead of SIGKILL\n"
|
|
||||||
" -u,--user display user IDs\n"
|
|
||||||
" -v,--verbose verbose output\n"
|
|
||||||
+ " -w,--writeonly kill only processes with write access\n"
|
|
||||||
" -V,--version display version information\n"));
|
|
||||||
#ifdef WITH_IPV6
|
|
||||||
fprintf(stderr, _(
|
|
||||||
@@ -1133,6 +1134,7 @@ int main(int argc, char *argv[])
|
|
||||||
{"silent", 0, NULL, 's'},
|
|
||||||
{"user", 0, NULL, 'u'},
|
|
||||||
{"verbose", 0, NULL, 'v'},
|
|
||||||
+ {"writeonly", 0, NULL, 'w'},
|
|
||||||
{"version", 0, NULL, 'V'},
|
|
||||||
#ifdef WITH_IPV6
|
|
||||||
{"ipv4", 0, NULL, '4'},
|
|
||||||
@@ -1244,6 +1246,9 @@ int main(int argc, char *argv[])
|
|
||||||
case 'v':
|
|
||||||
opts |= OPT_VERBOSE;
|
|
||||||
break;
|
|
||||||
+ case 'w':
|
|
||||||
+ opts |= OPT_WRITE;
|
|
||||||
+ break;
|
|
||||||
case 'V':
|
|
||||||
print_version();
|
|
||||||
return 0;
|
|
||||||
@@ -1406,6 +1411,7 @@ print_matches(struct names *names_head,
|
|
||||||
int len = 0;
|
|
||||||
struct passwd *pwent = NULL;
|
|
||||||
int have_match = 0;
|
|
||||||
+ int have_kill = 0;
|
|
||||||
int name_has_procs;
|
|
||||||
|
|
||||||
for (nptr = names_head; nptr != NULL; nptr = nptr->next) {
|
|
||||||
@@ -1546,8 +1552,8 @@ print_matches(struct names *names_head,
|
|
||||||
}
|
|
||||||
} /* be silent */
|
|
||||||
if (opts & OPT_KILL)
|
|
||||||
- kill_matched_proc(nptr->matched_procs, opts,
|
|
||||||
- sig_number);
|
|
||||||
+ have_kill = kill_matched_proc(nptr->matched_procs,
|
|
||||||
+ opts, sig_number);
|
|
||||||
|
|
||||||
} /* next name */
|
|
||||||
return (have_match == 1 ? 0 : 1);
|
|
||||||
@@ -1857,12 +1863,13 @@ static int ask(const pid_t pid)
|
|
||||||
} /* while */
|
|
||||||
}
|
|
||||||
|
|
||||||
-static void
|
|
||||||
+static int
|
|
||||||
kill_matched_proc(struct procs *proc_head, const opt_type opts,
|
|
||||||
const int sig_number)
|
|
||||||
{
|
|
||||||
struct procs *pptr;
|
|
||||||
pid_t mypid;
|
|
||||||
+ int ret = 0;
|
|
||||||
|
|
||||||
mypid = getpid();
|
|
||||||
|
|
||||||
@@ -1871,13 +1878,18 @@ kill_matched_proc(struct procs *proc_hea
|
|
||||||
continue; /* dont kill myself */
|
|
||||||
if ( pptr->proc_type != PTYPE_NORMAL )
|
|
||||||
continue;
|
|
||||||
+ if ((opts & OPT_WRITE) && ((pptr->access & ACCESS_FILEWR) == 0))
|
|
||||||
+ continue;
|
|
||||||
if ((opts & OPT_INTERACTIVE) && (ask(pptr->pid) == 0))
|
|
||||||
continue;
|
|
||||||
if ( kill(pptr->pid, sig_number) < 0) {
|
|
||||||
fprintf(stderr, _("Could not kill process %d: %s\n"),
|
|
||||||
pptr->pid, strerror(errno));
|
|
||||||
+ continue;
|
|
||||||
}
|
|
||||||
+ ret = 1;
|
|
||||||
}
|
|
||||||
+ return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static dev_t find_net_dev(void)
|
|
||||||
--- src/fuser.h
|
|
||||||
+++ src/fuser.h 2010-07-13 13:26:15.000000000 +0000
|
|
||||||
@@ -1,6 +1,6 @@
|
|
||||||
|
|
||||||
/* Option Flags */
|
|
||||||
-typedef unsigned char opt_type;
|
|
||||||
+typedef unsigned short opt_type;
|
|
||||||
|
|
||||||
#define OPT_VERBOSE 1
|
|
||||||
#define OPT_ALLFILES 2
|
|
||||||
@@ -10,6 +10,7 @@ typedef unsigned char opt_type;
|
|
||||||
#define OPT_SILENT 32
|
|
||||||
#define OPT_USER 64
|
|
||||||
#define OPT_ISMOUNTPOINT 128
|
|
||||||
+#define OPT_WRITE 256
|
|
||||||
|
|
||||||
struct procs {
|
|
||||||
pid_t pid;
|
|
@ -1,933 +0,0 @@
|
|||||||
--- src/fuser.c
|
|
||||||
+++ src/fuser.c 2011-02-09 09:39:51.116426890 +0000
|
|
||||||
@@ -32,9 +32,11 @@
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
+#include <sys/param.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
+#include <sys/wait.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <pwd.h>
|
|
||||||
@@ -45,6 +47,7 @@
|
|
||||||
#include <mntent.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
+#include <setjmp.h>
|
|
||||||
|
|
||||||
#include "fuser.h"
|
|
||||||
#include "signals.h"
|
|
||||||
@@ -95,6 +98,16 @@ static void debug_match_lists(struct nam
|
|
||||||
struct device_list *dev_head);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
+#ifdef _LISTS_H
|
|
||||||
+static void clear_mntinfo(void) __attribute__((__destructor__));
|
|
||||||
+static void init_mntinfo(void) __attribute__((__constructor__));
|
|
||||||
+static dev_t device(const char *path);
|
|
||||||
+#endif
|
|
||||||
+static char *expandpath(const char *path);
|
|
||||||
+
|
|
||||||
+typedef int (*stat_t)(const char*, struct stat*);
|
|
||||||
+static int timeout(stat_t func, const char *path, struct stat *buf, unsigned int seconds);
|
|
||||||
+
|
|
||||||
static void usage(const char *errormsg)
|
|
||||||
{
|
|
||||||
if (errormsg != NULL)
|
|
||||||
@@ -152,7 +165,7 @@ scan_procs(struct names *names_head, str
|
|
||||||
struct device_list *dev_tmp;
|
|
||||||
pid_t pid, my_pid;
|
|
||||||
uid_t uid;
|
|
||||||
- struct stat *cwd_stat, *exe_stat, *root_stat;
|
|
||||||
+ int dfd;
|
|
||||||
|
|
||||||
if ((topproc_dir = opendir("/proc")) == NULL) {
|
|
||||||
fprintf(stderr, _("Cannot open /proc directory: %s\n"),
|
|
||||||
@@ -160,7 +173,17 @@ scan_procs(struct names *names_head, str
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
my_pid = getpid();
|
|
||||||
+ dfd = dirfd(topproc_dir);
|
|
||||||
while ((topproc_dent = readdir(topproc_dir)) != NULL) {
|
|
||||||
+ dev_t cwd_dev, exe_dev, root_dev;
|
|
||||||
+ struct stat *cwd_stat = NULL;
|
|
||||||
+ struct stat *exe_stat = NULL;
|
|
||||||
+ struct stat *root_stat = NULL;
|
|
||||||
+#ifdef _LISTS_H
|
|
||||||
+ char path[256] = "/proc/", *slash;
|
|
||||||
+ ssize_t len;
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
if (topproc_dent->d_name[0] < '0' || topproc_dent->d_name[0] > '9') /* Not a process */
|
|
||||||
continue;
|
|
||||||
pid = atoi(topproc_dent->d_name);
|
|
||||||
@@ -169,57 +192,72 @@ scan_procs(struct names *names_head, str
|
|
||||||
continue;
|
|
||||||
uid = getpiduid(pid);
|
|
||||||
|
|
||||||
- root_stat = get_pidstat(pid, "root");
|
|
||||||
+#ifdef _LISTS_H
|
|
||||||
+ strcpy(&path[6], topproc_dent->d_name);
|
|
||||||
+ len = strlen(path);
|
|
||||||
+ slash = &path[len];
|
|
||||||
+
|
|
||||||
+ *slash = '\0';
|
|
||||||
+ strcat(slash, "/cwd");
|
|
||||||
+ cwd_dev = device(path);
|
|
||||||
+
|
|
||||||
+ *slash = '\0';
|
|
||||||
+ strcat(slash, "/exe");
|
|
||||||
+ exe_dev = device(path);
|
|
||||||
+
|
|
||||||
+ *slash = '\0';
|
|
||||||
+ strcat(slash, "/root");
|
|
||||||
+ root_dev = device(path);
|
|
||||||
+#else
|
|
||||||
cwd_stat = get_pidstat(pid, "cwd");
|
|
||||||
exe_stat = get_pidstat(pid, "exe");
|
|
||||||
+ root_stat = get_pidstat(pid, "root");
|
|
||||||
+ 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;
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
/* Scan the devices */
|
|
||||||
- for (dev_tmp = dev_head; dev_tmp != NULL;
|
|
||||||
- dev_tmp = dev_tmp->next) {
|
|
||||||
- if (exe_stat != NULL
|
|
||||||
- && exe_stat->st_dev == dev_tmp->device)
|
|
||||||
- add_matched_proc(dev_tmp->name, pid, uid,
|
|
||||||
- ACCESS_EXE);
|
|
||||||
- if (root_stat != NULL
|
|
||||||
- && root_stat->st_dev == dev_tmp->device)
|
|
||||||
- add_matched_proc(dev_tmp->name, pid, uid,
|
|
||||||
- ACCESS_ROOT);
|
|
||||||
- if (cwd_stat != NULL
|
|
||||||
- && cwd_stat->st_dev == dev_tmp->device)
|
|
||||||
- add_matched_proc(dev_tmp->name, pid, uid,
|
|
||||||
- ACCESS_CWD);
|
|
||||||
- }
|
|
||||||
- for (ino_tmp = ino_head; ino_tmp != NULL;
|
|
||||||
- ino_tmp = ino_tmp->next) {
|
|
||||||
- if (exe_stat != NULL) {
|
|
||||||
- if (exe_stat->st_dev == ino_tmp->device
|
|
||||||
- && exe_stat->st_ino == ino_tmp->inode) {
|
|
||||||
- add_matched_proc(ino_tmp->name, pid,
|
|
||||||
- uid, ACCESS_EXE);
|
|
||||||
- }
|
|
||||||
+ for (dev_tmp = dev_head; dev_tmp != NULL; dev_tmp = dev_tmp->next) {
|
|
||||||
+ if (exe_dev == dev_tmp->device)
|
|
||||||
+ add_matched_proc(dev_tmp->name, pid, uid, ACCESS_EXE);
|
|
||||||
+ if (root_dev == dev_tmp->device)
|
|
||||||
+ add_matched_proc(dev_tmp->name, pid, uid, ACCESS_ROOT);
|
|
||||||
+ if (cwd_dev == dev_tmp->device)
|
|
||||||
+ add_matched_proc(dev_tmp->name, pid, uid, ACCESS_CWD);
|
|
||||||
+ }
|
|
||||||
+ for (ino_tmp = ino_head; ino_tmp != NULL; ino_tmp = ino_tmp->next) {
|
|
||||||
+ if (exe_dev == ino_tmp->device) {
|
|
||||||
+ if (!exe_stat)
|
|
||||||
+ exe_stat = get_pidstat(pid, "exe");
|
|
||||||
+ if (exe_stat && exe_stat->st_dev == ino_tmp->device
|
|
||||||
+ && exe_stat->st_ino == ino_tmp->inode)
|
|
||||||
+ add_matched_proc(ino_tmp->name, pid, uid, ACCESS_EXE);
|
|
||||||
}
|
|
||||||
- if (root_stat != NULL) {
|
|
||||||
- if (root_stat->st_dev == ino_tmp->device
|
|
||||||
- && root_stat->st_ino == ino_tmp->inode) {
|
|
||||||
- add_matched_proc(ino_tmp->name, pid,
|
|
||||||
- uid, ACCESS_ROOT);
|
|
||||||
- }
|
|
||||||
-
|
|
||||||
+ if (root_dev == ino_tmp->device) {
|
|
||||||
+ if (!root_stat)
|
|
||||||
+ root_stat = get_pidstat(pid, "root");
|
|
||||||
+ if (root_stat && root_stat->st_dev == ino_tmp->device
|
|
||||||
+ && root_stat->st_ino == ino_tmp->inode)
|
|
||||||
+ add_matched_proc(ino_tmp->name, pid, uid, ACCESS_ROOT);
|
|
||||||
}
|
|
||||||
- if (cwd_stat != NULL) {
|
|
||||||
- if (cwd_stat->st_dev == ino_tmp->device
|
|
||||||
- && cwd_stat->st_ino == ino_tmp->inode) {
|
|
||||||
- add_matched_proc(ino_tmp->name, pid,
|
|
||||||
- uid, ACCESS_CWD);
|
|
||||||
- }
|
|
||||||
+ if (cwd_dev == ino_tmp->device) {
|
|
||||||
+ if (!cwd_stat)
|
|
||||||
+ cwd_stat = get_pidstat(pid, "cwd");
|
|
||||||
+ if (cwd_stat && cwd_stat->st_dev == ino_tmp->device
|
|
||||||
+ && cwd_stat->st_ino == ino_tmp->inode)
|
|
||||||
+ add_matched_proc(ino_tmp->name, pid, uid, ACCESS_CWD);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (root_stat) free(root_stat);
|
|
||||||
if (cwd_stat) free(cwd_stat);
|
|
||||||
if (exe_stat) free(exe_stat);
|
|
||||||
+#ifndef __linux__
|
|
||||||
check_dir(pid, "lib", dev_head, ino_head, uid, ACCESS_MMAP,
|
|
||||||
sockets, netdev);
|
|
||||||
check_dir(pid, "mmap", dev_head, ino_head, uid, ACCESS_MMAP,
|
|
||||||
sockets, netdev);
|
|
||||||
+#endif
|
|
||||||
check_dir(pid, "fd", dev_head, ino_head, uid, ACCESS_FILE,
|
|
||||||
sockets, netdev);
|
|
||||||
check_map(pid, "maps", dev_head, ino_head, uid, ACCESS_MMAP);
|
|
||||||
@@ -392,9 +430,24 @@ add_special_proc(struct names *name_list
|
|
||||||
pptr->command = strdup(command);
|
|
||||||
}
|
|
||||||
|
|
||||||
-int parse_file(struct names *this_name, struct inode_list **ino_list)
|
|
||||||
+int parse_file(struct names *this_name, struct inode_list **ino_list, const char opts)
|
|
||||||
{
|
|
||||||
- if (stat(this_name->filename, &(this_name->st)) != 0) {
|
|
||||||
+ char * new = expandpath(this_name->filename);
|
|
||||||
+ if (new) {
|
|
||||||
+ if (this_name->filename)
|
|
||||||
+ free(this_name->filename);
|
|
||||||
+ this_name->filename = strdup(new);
|
|
||||||
+ }
|
|
||||||
+#ifdef _LISTS_H
|
|
||||||
+ if (opts & OPT_MOUNTS) {
|
|
||||||
+ this_name->st.st_dev = device(this_name->filename);
|
|
||||||
+ this_name->st.st_ino = 0;
|
|
||||||
+ add_inode(ino_list, this_name, this_name->st.st_dev, this_name->st.st_ino);
|
|
||||||
+ return 0;
|
|
||||||
+ }
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
+ if (timeout(stat, this_name->filename, &(this_name->st), 5) != 0) {
|
|
||||||
if (errno == ENOENT)
|
|
||||||
fprintf(stderr, _("Specified filename %s does not exist.\n"), this_name->filename);
|
|
||||||
else
|
|
||||||
@@ -1030,11 +1083,12 @@ int main(int argc, char *argv[])
|
|
||||||
break;
|
|
||||||
default: /* FILE */
|
|
||||||
this_name->filename = strdup(current_argv);
|
|
||||||
- if (parse_file(this_name, &match_inodes) == 0) {
|
|
||||||
- parse_unixsockets(this_name, &match_inodes, unixsockets);
|
|
||||||
+ if (parse_file(this_name, &match_inodes, opts) == 0) {
|
|
||||||
if (opts & OPT_MOUNTS)
|
|
||||||
parse_mounts(this_name, &match_devices, opts);
|
|
||||||
- }
|
|
||||||
+ else
|
|
||||||
+ parse_unixsockets(this_name, &match_inodes, unixsockets);
|
|
||||||
+ }
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1258,7 +1312,7 @@ static struct stat *get_pidstat(const pi
|
|
||||||
if ((st = (struct stat*)malloc(sizeof(struct stat))) == NULL)
|
|
||||||
return NULL;
|
|
||||||
snprintf(pathname, 256, "/proc/%d/%s", pid, filename);
|
|
||||||
- if (stat(pathname, st) != 0)
|
|
||||||
+ if (timeout(stat, pathname, st, 5) != 0)
|
|
||||||
goto out;
|
|
||||||
return st;
|
|
||||||
out:
|
|
||||||
@@ -1278,6 +1332,7 @@ check_dir(const pid_t pid, const char *d
|
|
||||||
struct device_list *dev_tmp;
|
|
||||||
struct unixsocket_list *sock_tmp;
|
|
||||||
struct stat st, lst;
|
|
||||||
+ dev_t thedev;
|
|
||||||
|
|
||||||
if ((dirpath = (char*)malloc(MAX_PATHNAME)) == NULL)
|
|
||||||
goto out;
|
|
||||||
@@ -1293,53 +1348,68 @@ check_dir(const pid_t pid, const char *d
|
|
||||||
|
|
||||||
snprintf(filepath, MAX_PATHNAME, "/proc/%d/%s/%s",
|
|
||||||
pid, dirname, direntry->d_name);
|
|
||||||
- if (stat(filepath, &st) != 0) {
|
|
||||||
+
|
|
||||||
+#ifdef _LISTS_H
|
|
||||||
+ st.st_ino = 0;
|
|
||||||
+ if ((thedev = device(filepath)) < 0)
|
|
||||||
+#else
|
|
||||||
+ if (!st.st_ino && timeout(stat, filepath, &st, 5) != 0)
|
|
||||||
+#endif
|
|
||||||
+ {
|
|
||||||
fprintf(stderr, _("Cannot stat file %s: %s\n"),
|
|
||||||
filepath, strerror(errno));
|
|
||||||
} else {
|
|
||||||
- if (st.st_dev == netdev) {
|
|
||||||
+ if (thedev == netdev) {
|
|
||||||
for (sock_tmp = sockets; sock_tmp != NULL;
|
|
||||||
sock_tmp = sock_tmp->next) {
|
|
||||||
if (sock_tmp->net_inode == st.st_ino) {
|
|
||||||
st.st_ino = sock_tmp->inode;
|
|
||||||
st.st_dev = sock_tmp->dev;
|
|
||||||
+ thedev = sock_tmp->dev;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (dev_tmp = dev_head; dev_tmp != NULL;
|
|
||||||
dev_tmp = dev_tmp->next) {
|
|
||||||
- if (st.st_dev == dev_tmp->device) {
|
|
||||||
- if (access == ACCESS_FILE
|
|
||||||
- && (lstat(filepath, &lst) == 0)
|
|
||||||
- && (lst.st_mode & S_IWUSR)) {
|
|
||||||
- add_matched_proc(dev_tmp->name,
|
|
||||||
- pid, uid,
|
|
||||||
- ACCESS_FILEWR |
|
|
||||||
- access);
|
|
||||||
- } else {
|
|
||||||
- add_matched_proc(dev_tmp->name,
|
|
||||||
- pid, uid,
|
|
||||||
- access);
|
|
||||||
- }
|
|
||||||
+ if (thedev != dev_tmp->device)
|
|
||||||
+ continue;
|
|
||||||
+ if (access == ACCESS_FILE
|
|
||||||
+ && (lstat(filepath, &lst) == 0)
|
|
||||||
+ && (lst.st_mode & S_IWUSR)) {
|
|
||||||
+ add_matched_proc(dev_tmp->name,
|
|
||||||
+ pid, uid,
|
|
||||||
+ ACCESS_FILEWR |
|
|
||||||
+ access);
|
|
||||||
+ } else {
|
|
||||||
+ add_matched_proc(dev_tmp->name,
|
|
||||||
+ pid, uid,
|
|
||||||
+ access);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (ino_tmp = ino_head; ino_tmp != NULL;
|
|
||||||
ino_tmp = ino_tmp->next) {
|
|
||||||
- if (st.st_dev == ino_tmp->device
|
|
||||||
- && st.st_ino == ino_tmp->inode) {
|
|
||||||
- if (access == ACCESS_FILE
|
|
||||||
- && (lstat(filepath, &lst) == 0)
|
|
||||||
- && (lst.st_mode & S_IWUSR)) {
|
|
||||||
- add_matched_proc(ino_tmp->name,
|
|
||||||
- pid, uid,
|
|
||||||
- ACCESS_FILEWR |
|
|
||||||
- access);
|
|
||||||
- } else {
|
|
||||||
- add_matched_proc(ino_tmp->name,
|
|
||||||
- pid, uid,
|
|
||||||
- access);
|
|
||||||
- }
|
|
||||||
+ if (thedev != ino_tmp->device)
|
|
||||||
+ continue;
|
|
||||||
+ if (!st.st_ino && timeout(stat, filepath, &st, 5) != 0) {
|
|
||||||
+ fprintf(stderr,
|
|
||||||
+ _("Cannot stat file %s: %s\n"),
|
|
||||||
+ filepath, strerror(errno));
|
|
||||||
+ continue;
|
|
||||||
+ }
|
|
||||||
+ if (st.st_ino == ino_tmp->inode) {
|
|
||||||
+ if (access == ACCESS_FILE
|
|
||||||
+ && (lstat(filepath, &lst) == 0)
|
|
||||||
+ && (lst.st_mode & S_IWUSR)) {
|
|
||||||
+ add_matched_proc(ino_tmp->name,
|
|
||||||
+ pid, uid,
|
|
||||||
+ ACCESS_FILEWR |
|
|
||||||
+ access);
|
|
||||||
+ } else {
|
|
||||||
+ add_matched_proc(ino_tmp->name,
|
|
||||||
+ pid, uid,
|
|
||||||
+ access);
|
|
||||||
+ }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1396,7 +1466,7 @@ static uid_t getpiduid(const pid_t pid)
|
|
||||||
|
|
||||||
if (snprintf(pathname, MAX_PATHNAME, "/proc/%d", pid) < 0)
|
|
||||||
return 0;
|
|
||||||
- if (stat(pathname, &st) != 0)
|
|
||||||
+ if (timeout(stat, pathname, &st, 5) != 0)
|
|
||||||
return 0;
|
|
||||||
return st.st_uid;
|
|
||||||
}
|
|
||||||
@@ -1432,7 +1502,7 @@ void fill_unix_cache(struct unixsocket_l
|
|
||||||
path = scanned_path;
|
|
||||||
if (*scanned_path == '@')
|
|
||||||
scanned_path++;
|
|
||||||
- if (stat(scanned_path, &st) < 0) {
|
|
||||||
+ if (timeout(stat, scanned_path, &st, 5) < 0) {
|
|
||||||
free(path);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
@@ -1571,7 +1641,7 @@ scan_knfsd(struct names *names_head, str
|
|
||||||
if ((find_space = strpbrk(line, " \t")) == NULL)
|
|
||||||
continue;
|
|
||||||
*find_space = '\0';
|
|
||||||
- if (stat(line, &st) != 0) {
|
|
||||||
+ if (timeout(stat, line, &st, 5) != 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Scan the devices */
|
|
||||||
@@ -1615,7 +1685,7 @@ scan_mounts(struct names *names_head, st
|
|
||||||
if ((find_space = strchr(find_mountp, ' ')) == NULL)
|
|
||||||
continue;
|
|
||||||
*find_space = '\0';
|
|
||||||
- if (stat(find_mountp, &st) != 0) {
|
|
||||||
+ if (timeout(stat, find_mountp, &st, 5) != 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Scan the devices */
|
|
||||||
@@ -1662,7 +1732,7 @@ scan_swaps(struct names *names_head, str
|
|
||||||
if (*find_space == '\0')
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
- if (stat(line, &st) != 0) {
|
|
||||||
+ if (timeout(stat, line, &st, 5) != 0) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* Scan the devices */
|
|
||||||
@@ -1682,3 +1752,281 @@ scan_swaps(struct names *names_head, str
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * Execute stat(2) system call with timeout to avoid deadlock
|
|
||||||
+ * on network based file systems.
|
|
||||||
+ */
|
|
||||||
+static sigjmp_buf jenv;
|
|
||||||
+
|
|
||||||
+static void
|
|
||||||
+sigalarm(int sig)
|
|
||||||
+{
|
|
||||||
+ if (sig == SIGALRM)
|
|
||||||
+ siglongjmp(jenv, 1);
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static int
|
|
||||||
+timeout(stat_t func, const char *path, struct stat *buf, unsigned int seconds)
|
|
||||||
+{
|
|
||||||
+ pid_t pid = 0;
|
|
||||||
+ int ret = 0, pipes[4];
|
|
||||||
+ ssize_t len;
|
|
||||||
+
|
|
||||||
+ if (pipe(&pipes[0]) < 0)
|
|
||||||
+ goto err;
|
|
||||||
+ switch ((pid = fork ())) {
|
|
||||||
+ case -1:
|
|
||||||
+ close(pipes[0]);
|
|
||||||
+ close(pipes[1]);
|
|
||||||
+ goto err;
|
|
||||||
+ case 0:
|
|
||||||
+ (void) signal(SIGALRM, SIG_DFL);
|
|
||||||
+ close(pipes[0]);
|
|
||||||
+ if ((ret = func(path, buf)) == 0)
|
|
||||||
+ do len = write(pipes[1], buf, sizeof(struct stat));
|
|
||||||
+ while (len < 0 && errno == EINTR);
|
|
||||||
+ close(pipes[1]);
|
|
||||||
+ exit(ret);
|
|
||||||
+ default:
|
|
||||||
+ close(pipes[1]);
|
|
||||||
+ if (sigsetjmp(jenv, 1)) {
|
|
||||||
+ (void) alarm(0);
|
|
||||||
+ (void) signal(SIGALRM, SIG_DFL);
|
|
||||||
+ if (waitpid(0, (int*)0, WNOHANG) == 0)
|
|
||||||
+ kill(pid, SIGKILL);
|
|
||||||
+ errno = ETIMEDOUT;
|
|
||||||
+ seconds = 1;
|
|
||||||
+ goto err;
|
|
||||||
+ }
|
|
||||||
+ (void) signal(SIGALRM, sigalarm);
|
|
||||||
+ (void) alarm(seconds);
|
|
||||||
+ if (read(pipes[0], buf, sizeof(struct stat)) == 0) {
|
|
||||||
+ errno = EFAULT;
|
|
||||||
+ ret = -1;
|
|
||||||
+ }
|
|
||||||
+ (void) alarm(0);
|
|
||||||
+ (void) signal(SIGALRM, SIG_DFL);
|
|
||||||
+ close(pipes[0]);
|
|
||||||
+ break;
|
|
||||||
+ }
|
|
||||||
+ return ret;
|
|
||||||
+err:
|
|
||||||
+ return -1;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+#ifdef _LISTS_H
|
|
||||||
+/*
|
|
||||||
+ * 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.
|
|
||||||
+ */
|
|
||||||
+
|
|
||||||
+static list_t mntinfo = {&mntinfo, &mntinfo};
|
|
||||||
+
|
|
||||||
+static void
|
|
||||||
+clear_mntinfo(void)
|
|
||||||
+{
|
|
||||||
+ list_t *ptr, *tmp;
|
|
||||||
+
|
|
||||||
+ list_for_each_safe(ptr, tmp, &mntinfo) {
|
|
||||||
+ mntinfo_t *mnt = list_entry(ptr, mntinfo_t);
|
|
||||||
+ delete(ptr);
|
|
||||||
+ free(mnt);
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+
|
|
||||||
+static void
|
|
||||||
+init_mntinfo(void)
|
|
||||||
+{
|
|
||||||
+ char mpoint[PATH_MAX+1];
|
|
||||||
+ int mid, parid, max = 0;
|
|
||||||
+ uint maj, min;
|
|
||||||
+ list_t sort;
|
|
||||||
+ FILE * mnt;
|
|
||||||
+
|
|
||||||
+ if (!list_empty(&mntinfo))
|
|
||||||
+ return;
|
|
||||||
+ 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) {
|
|
||||||
+ const size_t nlen = strlen(mpoint);
|
|
||||||
+ mntinfo_t *restrict mnt;
|
|
||||||
+ if (posix_memalign((void*)&mnt, sizeof(void*), alignof(mntinfo_t)+(nlen+1)) != 0) {
|
|
||||||
+ fprintf(stderr, _("Cannot allocate memory for matched proc: %s\n"),
|
|
||||||
+ strerror(errno));
|
|
||||||
+ exit(1);
|
|
||||||
+ }
|
|
||||||
+ 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;
|
|
||||||
+ }
|
|
||||||
+ 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) {
|
|
||||||
+ mntinfo_t *mnt = list_entry(ptr, mntinfo_t);
|
|
||||||
+ if (mid != mnt->id)
|
|
||||||
+ continue;
|
|
||||||
+ move_head(ptr, &sort);
|
|
||||||
+ break;
|
|
||||||
+ }
|
|
||||||
+ list_for_each_safe(ptr, tmp, &mntinfo) {
|
|
||||||
+ mntinfo_t *mnt = list_entry(ptr, mntinfo_t);
|
|
||||||
+ if (mid != mnt->parid)
|
|
||||||
+ continue;
|
|
||||||
+ move_head(ptr, &sort);
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ if (!list_empty(&mntinfo)) {
|
|
||||||
+ errno = EBADE;
|
|
||||||
+ }
|
|
||||||
+ join(&sort, &mntinfo);
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * Determine device of links below /proc/
|
|
||||||
+ */
|
|
||||||
+static dev_t
|
|
||||||
+device(const char * path)
|
|
||||||
+{
|
|
||||||
+ char name[PATH_MAX+1];
|
|
||||||
+ const char *use;
|
|
||||||
+ ssize_t nlen;
|
|
||||||
+ list_t *ptr;
|
|
||||||
+
|
|
||||||
+ if ((nlen = readlink(path, name, PATH_MAX)) < 0) {
|
|
||||||
+ nlen = strlen(path);
|
|
||||||
+ use = &path[0];
|
|
||||||
+ } else {
|
|
||||||
+ name[nlen] = '\0';
|
|
||||||
+ use = &name[0];
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ if (*use != '/') { /* special file (socket, pipe, inotify) */
|
|
||||||
+ struct stat st;
|
|
||||||
+ if (timeout(stat, path, &st, 5) != 0)
|
|
||||||
+ return (dev_t)-1;
|
|
||||||
+ return st.st_dev;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ list_for_each(ptr, &mntinfo) {
|
|
||||||
+ mntinfo_t *mnt = list_entry(ptr, mntinfo_t);
|
|
||||||
+ if (nlen < mnt->nlen)
|
|
||||||
+ continue;
|
|
||||||
+ if (mnt->nlen == 1) /* root fs is the last entry */
|
|
||||||
+ return mnt->dev;
|
|
||||||
+ if (use[mnt->nlen] != '\0' && use[mnt->nlen] != '/')
|
|
||||||
+ continue;
|
|
||||||
+ if (strncmp(use, mnt->mpoint, mnt->nlen) == 0)
|
|
||||||
+ return mnt->dev;
|
|
||||||
+ }
|
|
||||||
+ return (dev_t)-1;
|
|
||||||
+}
|
|
||||||
+#endif /* _LISTS_H */
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * Somehow the realpath(3) glibc function call, nevertheless
|
|
||||||
+ * it avoids lstat(2) system calls.
|
|
||||||
+ */
|
|
||||||
+static char real[PATH_MAX+1];
|
|
||||||
+char* expandpath(const char * path)
|
|
||||||
+{
|
|
||||||
+ char tmpbuf[PATH_MAX+1];
|
|
||||||
+ const char *start, *end;
|
|
||||||
+ char *curr, *dest;
|
|
||||||
+ int deep = MAXSYMLINKS;
|
|
||||||
+
|
|
||||||
+ if (!path || *path == '\0')
|
|
||||||
+ return (char*)0;
|
|
||||||
+
|
|
||||||
+ curr = &real[0];
|
|
||||||
+
|
|
||||||
+ if (*path != '/') {
|
|
||||||
+ if (!getcwd(curr, PATH_MAX))
|
|
||||||
+ return (char*)0;
|
|
||||||
+ dest = rawmemchr(curr, '\0');
|
|
||||||
+ } else {
|
|
||||||
+ *curr = '/';
|
|
||||||
+ dest = curr + 1;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ for (start = end = path; *start; start = end) {
|
|
||||||
+
|
|
||||||
+ while (*start == '/')
|
|
||||||
+ ++start;
|
|
||||||
+
|
|
||||||
+ for (end = start; *end && *end != '/'; ++end)
|
|
||||||
+ ;
|
|
||||||
+
|
|
||||||
+ if (end - start == 0)
|
|
||||||
+ break;
|
|
||||||
+ else if (end - start == 1 && start[0] == '.') {
|
|
||||||
+ ;
|
|
||||||
+ } else if (end - start == 2 && start[0] == '.' && start[1] == '.') {
|
|
||||||
+ if (dest > curr + 1)
|
|
||||||
+ while ((--dest)[-1] != '/')
|
|
||||||
+ ;
|
|
||||||
+ } else {
|
|
||||||
+ char lnkbuf[PATH_MAX+1];
|
|
||||||
+ size_t len;
|
|
||||||
+ ssize_t n;
|
|
||||||
+
|
|
||||||
+ if (dest[-1] != '/')
|
|
||||||
+ *dest++ = '/';
|
|
||||||
+
|
|
||||||
+ if (dest + (end - start) > curr + PATH_MAX) {
|
|
||||||
+ errno = ENAMETOOLONG;
|
|
||||||
+ return (char*)0;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ dest = mempcpy(dest, start, end - start);
|
|
||||||
+ *dest = '\0';
|
|
||||||
+
|
|
||||||
+ if (deep-- < 0) {
|
|
||||||
+ errno = ELOOP;
|
|
||||||
+ return (char*)0;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ errno = 0;
|
|
||||||
+ if ((n = readlink(curr, lnkbuf, PATH_MAX)) < 0) {
|
|
||||||
+ deep = MAXSYMLINKS;
|
|
||||||
+ if (errno == EINVAL)
|
|
||||||
+ continue; /* Not a symlink */
|
|
||||||
+ return (char*)0;
|
|
||||||
+ }
|
|
||||||
+ lnkbuf[n] = '\0'; /* Don't be fooled by readlink(2) */
|
|
||||||
+
|
|
||||||
+ len = strlen(end);
|
|
||||||
+ if ((n + len) > PATH_MAX) {
|
|
||||||
+ errno = ENAMETOOLONG;
|
|
||||||
+ return (char*)0;
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ memmove(&tmpbuf[n], end, len + 1);
|
|
||||||
+ path = end = memcpy(tmpbuf, lnkbuf, n);
|
|
||||||
+
|
|
||||||
+ if (lnkbuf[0] == '/')
|
|
||||||
+ dest = curr + 1;
|
|
||||||
+ else if (dest > curr + 1)
|
|
||||||
+ while ((--dest)[-1] != '/');
|
|
||||||
+
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ if (dest > curr + 1 && dest[-1] == '/')
|
|
||||||
+ --dest;
|
|
||||||
+ *dest = '\0';
|
|
||||||
+
|
|
||||||
+ return curr;
|
|
||||||
+}
|
|
||||||
--- src/fuser.h
|
|
||||||
+++ src/fuser.h 2011-02-09 09:38:34.764426085 +0000
|
|
||||||
@@ -85,6 +85,17 @@ struct mount_list {
|
|
||||||
struct mount_list *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
+#if defined (__GNUC__) && defined(__OPTIMIZE__)
|
|
||||||
+# include "lists.h"
|
|
||||||
+typedef struct mntinfo_s {
|
|
||||||
+ list_t this;
|
|
||||||
+ int id, parid;
|
|
||||||
+ dev_t dev;
|
|
||||||
+ size_t nlen;
|
|
||||||
+ char *mpoint;
|
|
||||||
+} mntinfo_t;
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
#define NAMESPACE_FILE 0
|
|
||||||
#define NAMESPACE_TCP 1
|
|
||||||
#define NAMESPACE_UDP 2
|
|
||||||
--- src/lists.h
|
|
||||||
+++ src/lists.h 2011-02-07 12:01:52.000000000 +0000
|
|
||||||
@@ -0,0 +1,249 @@
|
|
||||||
+/*
|
|
||||||
+ * lists.h Simple doubly linked list implementation,
|
|
||||||
+ * based on <linux/list.h> and <linux/prefetch.h>.
|
|
||||||
+ *
|
|
||||||
+ * Version: 0.1 01-Feb-2011 Fink
|
|
||||||
+ *
|
|
||||||
+ * Copyright 2011 Werner Fink, 2005 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 <werner@suse.de>, 2011
|
|
||||||
+ */
|
|
||||||
+
|
|
||||||
+#ifndef _LISTS_H
|
|
||||||
+#define _LISTS_H
|
|
||||||
+
|
|
||||||
+#include <stddef.h>
|
|
||||||
+#include <sys/types.h>
|
|
||||||
+
|
|
||||||
+typedef enum _boolean {false, true} boolean;
|
|
||||||
+typedef unsigned char uchar;
|
|
||||||
+#ifndef __USE_MISC
|
|
||||||
+typedef unsigned short ushort;
|
|
||||||
+typedef unsigned int uint;
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
+#ifndef __OPTIMIZE__
|
|
||||||
+# warning This will not compile without -O at least
|
|
||||||
+#endif
|
|
||||||
+#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
|
|
||||||
+# ifndef inline
|
|
||||||
+# define inline __inline__
|
|
||||||
+# endif
|
|
||||||
+# ifndef restrict
|
|
||||||
+# define restrict __restrict__
|
|
||||||
+# endif
|
|
||||||
+# ifndef volatile
|
|
||||||
+# define volatile __volatile__
|
|
||||||
+# endif
|
|
||||||
+# ifndef asm
|
|
||||||
+# define asm __asm__
|
|
||||||
+# endif
|
|
||||||
+# ifndef extension
|
|
||||||
+# define extension __extension__
|
|
||||||
+# endif
|
|
||||||
+#endif
|
|
||||||
+#ifndef attribute
|
|
||||||
+# define attribute(attr) __attribute__(attr)
|
|
||||||
+#endif
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * This is lent from the kernel by e.g. using
|
|
||||||
+ *
|
|
||||||
+ * echo '#include <asm-i386/processor.h>\nint main () { prefetch(); return 0; }' | \
|
|
||||||
+ * gcc -I/usr/src/linux/include -D__KERNEL__ -x c -E -P - | \
|
|
||||||
+ * sed -rn '/void[[:blank:]]+prefetch[[:blank:]]*\(/,/^}/p'
|
|
||||||
+ *
|
|
||||||
+ * on the appropiate architecture (here on i686 for i586).
|
|
||||||
+ */
|
|
||||||
+extern inline void attribute((used,__gnu_inline__,always_inline,__artificial__)) prefetch(const void *restrict x)
|
|
||||||
+{
|
|
||||||
+#if defined(__x86_64__)
|
|
||||||
+ asm volatile ("prefetcht0 %0" :: "m" (*(unsigned long *)x))
|
|
||||||
+#elif defined(__ia64__)
|
|
||||||
+ asm volatile ("lfetch [%0]" :: "r" (x))
|
|
||||||
+#elif defined(__powerpc64__)
|
|
||||||
+ asm volatile ("dcbt 0,%0" :: "r" (x))
|
|
||||||
+#elif 1 && defined(__i386__)
|
|
||||||
+ asm volatile ("661:\n\t"
|
|
||||||
+ ".byte 0x8d,0x74,0x26,0x00\n"
|
|
||||||
+ "\n662:\n"
|
|
||||||
+ ".section .altinstructions,\"a\"\n"
|
|
||||||
+ " .align 4\n"
|
|
||||||
+ " .long 661b\n"
|
|
||||||
+ " .long 663f\n"
|
|
||||||
+ " .byte %c0\n"
|
|
||||||
+ " .byte 662b-661b\n"
|
|
||||||
+ " .byte 664f-663f\n"
|
|
||||||
+ ".previous\n"
|
|
||||||
+ ".section .altinstr_replacement,\"ax\"\n"
|
|
||||||
+ " 663:\n\t"
|
|
||||||
+ " prefetchnta (%1)"
|
|
||||||
+ " \n664:\n"
|
|
||||||
+ ".previous"
|
|
||||||
+ :: "i" ((0*32+25)), "r" (x))
|
|
||||||
+#else
|
|
||||||
+ __builtin_prefetch ((x), 0, 1);
|
|
||||||
+#endif
|
|
||||||
+ ;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+#if defined(DEBUG) && (DEBUG > 0)
|
|
||||||
+# define __align attribute((packed))
|
|
||||||
+#else
|
|
||||||
+# define __align attribute((aligned(sizeof(struct list_struct*))))
|
|
||||||
+#endif
|
|
||||||
+#define __packed attribute((packed))
|
|
||||||
+
|
|
||||||
+#define alignof(type) ((sizeof(type)+(sizeof(void*)-1)) & ~(sizeof(void*)-1))
|
|
||||||
+#define strsize(string) ((strlen(string)+1)*sizeof(char))
|
|
||||||
+
|
|
||||||
+typedef struct list_struct {
|
|
||||||
+ struct list_struct * next, * prev;
|
|
||||||
+} __align list_t;
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * Linked list handling
|
|
||||||
+ * ====================
|
|
||||||
+ * The structures which will be linked into such lists have to be of the
|
|
||||||
+ * same type. The structures may have alway a list identifier of the type
|
|
||||||
+ * `list_t' as very first element. With this the macro list_entry() can
|
|
||||||
+ * be used to cast the memory address of a list member to the corresponding
|
|
||||||
+ * allocated structure.
|
|
||||||
+ */
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * Insert new entry as next member.
|
|
||||||
+ */
|
|
||||||
+static inline void _insert(list_t *restrict new, list_t *restrict here) attribute((always_inline,nonnull(1,2)));
|
|
||||||
+static inline void _insert(list_t *restrict new, list_t *restrict here)
|
|
||||||
+{
|
|
||||||
+ list_t * prev = here;
|
|
||||||
+ list_t * next = here->next;
|
|
||||||
+
|
|
||||||
+ next->prev = new;
|
|
||||||
+ new->next = next;
|
|
||||||
+ new->prev = prev;
|
|
||||||
+ prev->next = new;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+#define insert(new, list) _insert(&((new)->this), (&(list)));
|
|
||||||
+#define append(new, list) _insert(&((new)->this), (&(list))->prev);
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * Set head
|
|
||||||
+ */
|
|
||||||
+static inline void initial(list_t *restrict head) attribute((always_inline,nonnull(1)));
|
|
||||||
+static inline void initial(list_t *restrict head)
|
|
||||||
+{
|
|
||||||
+ head->prev = head->next = head;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * Remove entries, note that the pointer its self remains.
|
|
||||||
+ */
|
|
||||||
+static inline void delete(list_t *restrict entry) attribute((always_inline,nonnull(1)));
|
|
||||||
+static inline void delete(list_t *restrict entry)
|
|
||||||
+{
|
|
||||||
+ list_t * prev = entry->prev;
|
|
||||||
+ list_t * next = entry->next;
|
|
||||||
+
|
|
||||||
+ next->prev = prev;
|
|
||||||
+ prev->next = next;
|
|
||||||
+
|
|
||||||
+ initial(entry);
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * Replace an entry by a new one.
|
|
||||||
+ */
|
|
||||||
+static inline void replace(list_t *restrict old, list_t *restrict new) attribute((always_inline,nonnull(1,2)));
|
|
||||||
+static inline void replace(list_t *restrict old, list_t *restrict new)
|
|
||||||
+{
|
|
||||||
+ new->next = old->next;
|
|
||||||
+ new->next->prev = new;
|
|
||||||
+ new->prev = old->prev;
|
|
||||||
+ new->prev->next = new;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static inline void join(list_t *restrict list, list_t *restrict head) attribute((always_inline,nonnull(1,2)));
|
|
||||||
+static inline void join(list_t *restrict list, list_t *restrict head)
|
|
||||||
+{
|
|
||||||
+ list_t * first = list->next;
|
|
||||||
+
|
|
||||||
+ if (first != list) {
|
|
||||||
+ list_t * last = list->prev;
|
|
||||||
+ list_t * at = head->next;
|
|
||||||
+
|
|
||||||
+ first->prev = head;
|
|
||||||
+ head->next = first;
|
|
||||||
+
|
|
||||||
+ last->next = at;
|
|
||||||
+ at->prev = last;
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static inline boolean list_empty(const list_t *restrict const head) attribute((always_inline,nonnull(1)));
|
|
||||||
+static inline boolean list_empty(const list_t *restrict const head)
|
|
||||||
+{
|
|
||||||
+ return head->next == head;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static inline void move_head(list_t *restrict entry, list_t *restrict head) attribute((always_inline,nonnull(1,2)));
|
|
||||||
+static inline void move_head(list_t *restrict entry, list_t *restrict head)
|
|
||||||
+{
|
|
||||||
+ list_t * prev = entry->prev;
|
|
||||||
+ list_t * next = entry->next;
|
|
||||||
+
|
|
||||||
+ next->prev = prev; /* remove entry from old list */
|
|
||||||
+ prev->next = next;
|
|
||||||
+
|
|
||||||
+ prev = head;
|
|
||||||
+ next = head->next;
|
|
||||||
+
|
|
||||||
+ next->prev = entry; /* and add it at head of new list */
|
|
||||||
+ entry->next = next;
|
|
||||||
+ entry->prev = prev;
|
|
||||||
+ prev->next = entry;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+static inline void move_tail(list_t *restrict entry, list_t *restrict head) attribute((always_inline,nonnull(1,2)));
|
|
||||||
+static inline void move_tail(list_t *restrict entry, list_t *restrict head)
|
|
||||||
+{
|
|
||||||
+ list_t * prev = entry->prev;
|
|
||||||
+ list_t * next = entry->next;
|
|
||||||
+
|
|
||||||
+ next->prev = prev; /* remove entry from old list */
|
|
||||||
+ prev->next = next;
|
|
||||||
+
|
|
||||||
+ prev = head->prev;
|
|
||||||
+ next = head;
|
|
||||||
+
|
|
||||||
+ next->prev = entry; /* and add it at tail of new list */
|
|
||||||
+ entry->next = next;
|
|
||||||
+ entry->prev = prev;
|
|
||||||
+ prev->next = entry;
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
+/*
|
|
||||||
+ * The handle of the list is named `this'
|
|
||||||
+ */
|
|
||||||
+#define list_entry(ptr, type) (__extension__ ({ \
|
|
||||||
+ const typeof( ((type *)0)->this ) *__mptr = (ptr); \
|
|
||||||
+ ((type *)( (char *)(__mptr) - offsetof(type,this) )); }))
|
|
||||||
+#define list_for_each(pos, head) \
|
|
||||||
+ for (pos = (head)->next; prefetch(pos->next), pos != (head); pos = pos->next)
|
|
||||||
+#define np_list_for_each(pos, head) \
|
|
||||||
+ for (pos = (head)->next; pos != (head); pos = pos->next)
|
|
||||||
+#define list_for_each_safe(pos, safe, head) \
|
|
||||||
+ for (pos = (head)->next, safe = pos->next; pos != (head); pos = safe, safe = pos->next)
|
|
||||||
+#define list_for_each_prev(pos, head) \
|
|
||||||
+ for (pos = (head)->prev; prefetch(pos->prev), pos != (head); pos = pos->prev)
|
|
||||||
+#define np_list_for_each_prev(pos, head) \
|
|
||||||
+ for (pos = (head)->prev; pos != (head); pos = pos->prev)
|
|
||||||
+
|
|
||||||
+#endif /* _LISTS_H */
|
|
@ -1,13 +0,0 @@
|
|||||||
diff --git a/src/peekfd.c b/src/peekfd.c
|
|
||||||
index 2c30f25..6d759b9 100644
|
|
||||||
--- a/src/peekfd.c
|
|
||||||
+++ b/src/peekfd.c
|
|
||||||
@@ -199,7 +199,7 @@ int main(int argc, char **argv)
|
|
||||||
numfds = argc - optind;
|
|
||||||
fds = malloc(sizeof(int) * numfds);
|
|
||||||
for (i = 0; i < numfds; i++)
|
|
||||||
- fds[i] = atoi(argv[optind + i + 1]);
|
|
||||||
+ fds[i] = atoi(argv[optind + i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
attach(target_pid);
|
|
@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:45531c27bae46be5168a98edcbfc5f68c811176261631249880bc454e551c712
|
|
||||||
size 303260
|
|
255
psmisc-22.14-toomuch.dif
Normal file
255
psmisc-22.14-toomuch.dif
Normal file
@ -0,0 +1,255 @@
|
|||||||
|
--- src/lists.h
|
||||||
|
+++ src/lists.h 2011-06-21 13:38:35.696426015 +0000
|
||||||
|
@@ -247,252 +247,3 @@ static inline void move_tail(list_t *res
|
||||||
|
for (pos = (head)->prev; pos != (head); pos = pos->prev)
|
||||||
|
|
||||||
|
#endif /* _LISTS_H */
|
||||||
|
-/*
|
||||||
|
- * lists.h Simple doubly linked list implementation,
|
||||||
|
- * based on <linux/list.h> and <linux/prefetch.h>.
|
||||||
|
- *
|
||||||
|
- * Version: 0.1 01-Feb-2011 Fink
|
||||||
|
- *
|
||||||
|
- * Copyright 2011 Werner Fink, 2005 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 <werner@suse.de>, 2011
|
||||||
|
- */
|
||||||
|
-
|
||||||
|
-#ifndef _LISTS_H
|
||||||
|
-#define _LISTS_H
|
||||||
|
-
|
||||||
|
-#include <stddef.h>
|
||||||
|
-#include <sys/types.h>
|
||||||
|
-
|
||||||
|
-typedef enum _boolean {false, true} boolean;
|
||||||
|
-typedef unsigned char uchar;
|
||||||
|
-#ifndef __USE_MISC
|
||||||
|
-typedef unsigned short ushort;
|
||||||
|
-typedef unsigned int uint;
|
||||||
|
-#endif
|
||||||
|
-
|
||||||
|
-#ifndef __OPTIMIZE__
|
||||||
|
-# warning This will not compile without -O at least
|
||||||
|
-#endif
|
||||||
|
-#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
|
||||||
|
-# ifndef inline
|
||||||
|
-# define inline __inline__
|
||||||
|
-# endif
|
||||||
|
-# ifndef restrict
|
||||||
|
-# define restrict __restrict__
|
||||||
|
-# endif
|
||||||
|
-# ifndef volatile
|
||||||
|
-# define volatile __volatile__
|
||||||
|
-# endif
|
||||||
|
-# ifndef asm
|
||||||
|
-# define asm __asm__
|
||||||
|
-# endif
|
||||||
|
-# ifndef extension
|
||||||
|
-# define extension __extension__
|
||||||
|
-# endif
|
||||||
|
-#endif
|
||||||
|
-#ifndef attribute
|
||||||
|
-# define attribute(attr) __attribute__(attr)
|
||||||
|
-#endif
|
||||||
|
-
|
||||||
|
-/*
|
||||||
|
- * This is lent from the kernel by e.g. using
|
||||||
|
- *
|
||||||
|
- * echo '#include <asm-i386/processor.h>\nint main () { prefetch(); return 0; }' | \
|
||||||
|
- * gcc -I/usr/src/linux/include -D__KERNEL__ -x c -E -P - | \
|
||||||
|
- * sed -rn '/void[[:blank:]]+prefetch[[:blank:]]*\(/,/^}/p'
|
||||||
|
- *
|
||||||
|
- * on the appropiate architecture (here on i686 for i586).
|
||||||
|
- */
|
||||||
|
-extern inline void attribute((used,__gnu_inline__,always_inline,__artificial__)) prefetch(const void *restrict x)
|
||||||
|
-{
|
||||||
|
-#if defined(__x86_64__)
|
||||||
|
- asm volatile ("prefetcht0 %0" :: "m" (*(unsigned long *)x))
|
||||||
|
-#elif defined(__ia64__)
|
||||||
|
- asm volatile ("lfetch [%0]" :: "r" (x))
|
||||||
|
-#elif defined(__powerpc64__)
|
||||||
|
- asm volatile ("dcbt 0,%0" :: "r" (x))
|
||||||
|
-#elif 1 && defined(__i386__)
|
||||||
|
- asm volatile ("661:\n\t"
|
||||||
|
- ".byte 0x8d,0x74,0x26,0x00\n"
|
||||||
|
- "\n662:\n"
|
||||||
|
- ".section .altinstructions,\"a\"\n"
|
||||||
|
- " .align 4\n"
|
||||||
|
- " .long 661b\n"
|
||||||
|
- " .long 663f\n"
|
||||||
|
- " .byte %c0\n"
|
||||||
|
- " .byte 662b-661b\n"
|
||||||
|
- " .byte 664f-663f\n"
|
||||||
|
- ".previous\n"
|
||||||
|
- ".section .altinstr_replacement,\"ax\"\n"
|
||||||
|
- " 663:\n\t"
|
||||||
|
- " prefetchnta (%1)"
|
||||||
|
- " \n664:\n"
|
||||||
|
- ".previous"
|
||||||
|
- :: "i" ((0*32+25)), "r" (x))
|
||||||
|
-#else
|
||||||
|
- __builtin_prefetch ((x), 0, 1);
|
||||||
|
-#endif
|
||||||
|
- ;
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-#if defined(DEBUG) && (DEBUG > 0)
|
||||||
|
-# define __align attribute((packed))
|
||||||
|
-#else
|
||||||
|
-# define __align attribute((aligned(sizeof(struct list_struct*))))
|
||||||
|
-#endif
|
||||||
|
-#define __packed attribute((packed))
|
||||||
|
-
|
||||||
|
-#define alignof(type) ((sizeof(type)+(sizeof(void*)-1)) & ~(sizeof(void*)-1))
|
||||||
|
-#define strsize(string) ((strlen(string)+1)*sizeof(char))
|
||||||
|
-
|
||||||
|
-typedef struct list_struct {
|
||||||
|
- struct list_struct * next, * prev;
|
||||||
|
-} __align list_t;
|
||||||
|
-
|
||||||
|
-/*
|
||||||
|
- * Linked list handling
|
||||||
|
- * ====================
|
||||||
|
- * The structures which will be linked into such lists have to be of the
|
||||||
|
- * same type. The structures may have alway a list identifier of the type
|
||||||
|
- * `list_t' as very first element. With this the macro list_entry() can
|
||||||
|
- * be used to cast the memory address of a list member to the corresponding
|
||||||
|
- * allocated structure.
|
||||||
|
- */
|
||||||
|
-
|
||||||
|
-/*
|
||||||
|
- * Insert new entry as next member.
|
||||||
|
- */
|
||||||
|
-static inline void _insert(list_t *restrict new, list_t *restrict here) attribute((always_inline,nonnull(1,2)));
|
||||||
|
-static inline void _insert(list_t *restrict new, list_t *restrict here)
|
||||||
|
-{
|
||||||
|
- list_t * prev = here;
|
||||||
|
- list_t * next = here->next;
|
||||||
|
-
|
||||||
|
- next->prev = new;
|
||||||
|
- new->next = next;
|
||||||
|
- new->prev = prev;
|
||||||
|
- prev->next = new;
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-#define insert(new, list) _insert(&((new)->this), (&(list)));
|
||||||
|
-#define append(new, list) _insert(&((new)->this), (&(list))->prev);
|
||||||
|
-
|
||||||
|
-/*
|
||||||
|
- * Set head
|
||||||
|
- */
|
||||||
|
-static inline void initial(list_t *restrict head) attribute((always_inline,nonnull(1)));
|
||||||
|
-static inline void initial(list_t *restrict head)
|
||||||
|
-{
|
||||||
|
- head->prev = head->next = head;
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-/*
|
||||||
|
- * Remove entries, note that the pointer its self remains.
|
||||||
|
- */
|
||||||
|
-static inline void delete(list_t *restrict entry) attribute((always_inline,nonnull(1)));
|
||||||
|
-static inline void delete(list_t *restrict entry)
|
||||||
|
-{
|
||||||
|
- list_t * prev = entry->prev;
|
||||||
|
- list_t * next = entry->next;
|
||||||
|
-
|
||||||
|
- next->prev = prev;
|
||||||
|
- prev->next = next;
|
||||||
|
-
|
||||||
|
- initial(entry);
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-/*
|
||||||
|
- * Replace an entry by a new one.
|
||||||
|
- */
|
||||||
|
-static inline void replace(list_t *restrict old, list_t *restrict new) attribute((always_inline,nonnull(1,2)));
|
||||||
|
-static inline void replace(list_t *restrict old, list_t *restrict new)
|
||||||
|
-{
|
||||||
|
- new->next = old->next;
|
||||||
|
- new->next->prev = new;
|
||||||
|
- new->prev = old->prev;
|
||||||
|
- new->prev->next = new;
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-static inline void join(list_t *restrict list, list_t *restrict head) attribute((always_inline,nonnull(1,2)));
|
||||||
|
-static inline void join(list_t *restrict list, list_t *restrict head)
|
||||||
|
-{
|
||||||
|
- list_t * first = list->next;
|
||||||
|
-
|
||||||
|
- if (first != list) {
|
||||||
|
- list_t * last = list->prev;
|
||||||
|
- list_t * at = head->next;
|
||||||
|
-
|
||||||
|
- first->prev = head;
|
||||||
|
- head->next = first;
|
||||||
|
-
|
||||||
|
- last->next = at;
|
||||||
|
- at->prev = last;
|
||||||
|
- }
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-static inline boolean list_empty(const list_t *restrict const head) attribute((always_inline,nonnull(1)));
|
||||||
|
-static inline boolean list_empty(const list_t *restrict const head)
|
||||||
|
-{
|
||||||
|
- return head->next == head;
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-static inline void move_head(list_t *restrict entry, list_t *restrict head) attribute((always_inline,nonnull(1,2)));
|
||||||
|
-static inline void move_head(list_t *restrict entry, list_t *restrict head)
|
||||||
|
-{
|
||||||
|
- list_t * prev = entry->prev;
|
||||||
|
- list_t * next = entry->next;
|
||||||
|
-
|
||||||
|
- next->prev = prev; /* remove entry from old list */
|
||||||
|
- prev->next = next;
|
||||||
|
-
|
||||||
|
- prev = head;
|
||||||
|
- next = head->next;
|
||||||
|
-
|
||||||
|
- next->prev = entry; /* and add it at head of new list */
|
||||||
|
- entry->next = next;
|
||||||
|
- entry->prev = prev;
|
||||||
|
- prev->next = entry;
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-static inline void move_tail(list_t *restrict entry, list_t *restrict head) attribute((always_inline,nonnull(1,2)));
|
||||||
|
-static inline void move_tail(list_t *restrict entry, list_t *restrict head)
|
||||||
|
-{
|
||||||
|
- list_t * prev = entry->prev;
|
||||||
|
- list_t * next = entry->next;
|
||||||
|
-
|
||||||
|
- next->prev = prev; /* remove entry from old list */
|
||||||
|
- prev->next = next;
|
||||||
|
-
|
||||||
|
- prev = head->prev;
|
||||||
|
- next = head;
|
||||||
|
-
|
||||||
|
- next->prev = entry; /* and add it at tail of new list */
|
||||||
|
- entry->next = next;
|
||||||
|
- entry->prev = prev;
|
||||||
|
- prev->next = entry;
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
-/*
|
||||||
|
- * The handle of the list is named `this'
|
||||||
|
- */
|
||||||
|
-#define list_entry(ptr, type) (__extension__ ({ \
|
||||||
|
- const typeof( ((type *)0)->this ) *__mptr = (ptr); \
|
||||||
|
- ((type *)( (char *)(__mptr) - offsetof(type,this) )); }))
|
||||||
|
-#define list_for_each(pos, head) \
|
||||||
|
- for (pos = (head)->next; prefetch(pos->next), pos != (head); pos = pos->next)
|
||||||
|
-#define np_list_for_each(pos, head) \
|
||||||
|
- for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||||
|
-#define list_for_each_safe(pos, safe, head) \
|
||||||
|
- for (pos = (head)->next, safe = pos->next; pos != (head); pos = safe, safe = pos->next)
|
||||||
|
-#define list_for_each_prev(pos, head) \
|
||||||
|
- for (pos = (head)->prev; prefetch(pos->prev), pos != (head); pos = pos->prev)
|
||||||
|
-#define np_list_for_each_prev(pos, head) \
|
||||||
|
- for (pos = (head)->prev; pos != (head); pos = pos->prev)
|
||||||
|
-
|
||||||
|
-#endif /* _LISTS_H */
|
3
psmisc-22.14.tar.gz
Normal file
3
psmisc-22.14.tar.gz
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:42c30ad9a9a85429edd0e84763e1333a1d0711d90e4f1943ecb1211d6f98ee42
|
||||||
|
size 382041
|
@ -1,3 +1,27 @@
|
|||||||
|
-------------------------------------------------------------------
|
||||||
|
Tue Jun 21 15:56:45 CEST 2011 - werner@suse.de
|
||||||
|
|
||||||
|
- Update to version 22.14:
|
||||||
|
+ Fix file descriptor as weel as memory leaks in fuser
|
||||||
|
+ Strip @ symbol from file names read from /proc/net/unix
|
||||||
|
+ Above 2 changes close openSuSE bugs #536209, #529520, and #417841
|
||||||
|
and provided by Werner Fink
|
||||||
|
+ Applied patch from Werner Fink to avoid stat(2) on NFS mounts
|
||||||
|
+ Zeros process group memory - Patch by jgorig SF#3152925 RH#666213
|
||||||
|
+ fuser -m -s flags work - Patch by jgorig SF#31110178 RH#651794
|
||||||
|
+ fuser silent if /proc/swaps not available SF#3072134
|
||||||
|
+ ppc 64 support for peekfd by jgorig SF#3166444
|
||||||
|
+ jiffies now ULL in killall SF#3138538
|
||||||
|
+ pstree can show parents of a process. Patch supplied by Curtis
|
||||||
|
Hawthorne SF#3135157
|
||||||
|
+ killall creates right size buffer instead of MAX_PATH Debian #623425
|
||||||
|
+ check for /proc/$$/stat not /proc/self/stat which is not available
|
||||||
|
on hurd platforms. Same Debian bug as above
|
||||||
|
+ fuser understands IPv6 addresses, removed comment in fuser.1 that it
|
||||||
|
doesn't Debian #609904
|
||||||
|
+ fuser -k only returns 0 if you kill something.
|
||||||
|
+ fuser doesn't complain if /proc/#/fd disappears SF#3310990
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
Tue Feb 8 17:43:57 CET 2011 - werner@suse.de
|
Tue Feb 8 17:43:57 CET 2011 - werner@suse.de
|
||||||
|
|
||||||
|
24
psmisc.spec
24
psmisc.spec
@ -1,7 +1,7 @@
|
|||||||
#
|
#
|
||||||
# spec file for package psmisc (Version 22.13)
|
# spec file for package psmisc
|
||||||
#
|
#
|
||||||
# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||||
#
|
#
|
||||||
# All modifications and additions to the file contributed by third parties
|
# All modifications and additions to the file contributed by third parties
|
||||||
# remain the property of their copyright owners, unless otherwise agreed
|
# remain the property of their copyright owners, unless otherwise agreed
|
||||||
@ -21,23 +21,20 @@
|
|||||||
Name: psmisc
|
Name: psmisc
|
||||||
BuildRequires: gcc-c++ glibc-devel ncurses-devel
|
BuildRequires: gcc-c++ glibc-devel ncurses-devel
|
||||||
BuildRequires: libselinux-devel
|
BuildRequires: libselinux-devel
|
||||||
Url: http://switch.dl.sourceforge.net/sourceforge/psmisc/
|
Url: http://sourceforge.net/projects/psmisc/
|
||||||
License: GPLv2+
|
License: GPLv2+
|
||||||
Group: System/Monitoring
|
Group: System/Monitoring
|
||||||
PreReq: %fillup_prereq %insserv_prereq
|
PreReq: %fillup_prereq %insserv_prereq
|
||||||
Version: 22.13
|
Version: 22.14
|
||||||
Release: 2
|
Release: 1
|
||||||
Provides: ps:/usr/bin/killall
|
Provides: ps:/usr/bin/killall
|
||||||
Summary: Utilities for managing processes on your system
|
Summary: Utilities for managing processes on your system
|
||||||
Source: http://switch.dl.sourceforge.net/sourceforge/psmisc/%{name}-%{version}.tar.bz2
|
Source: http://sourceforge.net/projects/psmisc/files/psmisc/%{name}-%{version}.tar.gz
|
||||||
Patch0: %name-22.13.dif
|
Patch0: %name-22.14.dif
|
||||||
Patch1: %name-22.12-tigetstr.patch
|
Patch1: %name-22.12-tigetstr.patch
|
||||||
Patch2: %name-22.12-pstree_overflow.patch
|
Patch2: %name-22.12-pstree_overflow.patch
|
||||||
Patch3: %name-22.12-pstree.patch
|
Patch3: %name-22.12-pstree.patch
|
||||||
Patch4: %name-22.12-leaks.patch
|
Patch4: %name-22.14-toomuch.dif
|
||||||
Patch5: %name-22.13-nfs4fuser.patch
|
|
||||||
Patch6: %name-22.12-writeonly.patch
|
|
||||||
Patch7: %name-22.13-peekfd-segv.patch
|
|
||||||
|
|
||||||
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
BuildRoot: %{_tmppath}/%{name}-%{version}-build
|
||||||
%define nopeek s390 s390x ia64 %sparc hppa
|
%define nopeek s390 s390x ia64 %sparc hppa
|
||||||
@ -55,10 +52,7 @@ processes that are using specified files or filesystems.
|
|||||||
%patch1 -p0 -b .tigetstr
|
%patch1 -p0 -b .tigetstr
|
||||||
%patch2 -p0 -b .pstreeovfl
|
%patch2 -p0 -b .pstreeovfl
|
||||||
%patch3 -p0 -b .pstree
|
%patch3 -p0 -b .pstree
|
||||||
%patch4 -p0 -b .leaks
|
%patch4 -p0 -b .2much
|
||||||
%patch5 -p0 -b .nfs4fuser
|
|
||||||
%patch6 -p0 -b .wrtonly
|
|
||||||
%patch7 -p1 -b .peekfd
|
|
||||||
%patch0 -p0 -b .0
|
%patch0 -p0 -b .0
|
||||||
|
|
||||||
%build
|
%build
|
||||||
|
Loading…
Reference in New Issue
Block a user