Craig Small [Sat, 14 Mar 2015 22:08:12 +0000 (09:08 +1100)]
fuser: -k return status based on any found
In [bugs:#66] the ever-helpful "Anonymous" reported that
fuser with -k would only return correctly if the process
was found last and not if it was found anywhere.
While I have solved this problem a different way, the report
was enough to narrow down what was going wrong. Now fuser -k
returns 1 if it finds any process to kill, not just if the last
one was; just like fuser with no -k works.
Werner Fink [Sat, 14 Mar 2015 21:39:12 +0000 (08:39 +1100)]
Avoid possible crash and memory leak in killall
By reading the current HEAD I stumbled on a memory leak in killall.c
as well as a not assigned pointer got_long in load_proc_cmdline()
which may lead to SIGSEGV.
References: [patches:#67] https://sourceforge.net/p/psmisc/bugs/67 Signed-off-by: Werner Fink <werner@suse.de>
Craig Small [Tue, 23 Dec 2014 21:35:34 +0000 (08:35 +1100)]
killall younger and older flags
The -y and -o flags were not being used if you used the
regex (-r) flag. I initially moved those flags to the
right part of the loop.
However looking at that giant loop of code it was very difficult
to debug so I have also taken the opportunity to re-work it
with some functions, so its clearer what is going on.
Craig Small [Mon, 22 Dec 2014 21:58:47 +0000 (08:58 +1100)]
Removed early free on name_len
name_len was being freed too early and in a loop so
sometimes you would hit a double-free problem
The locale changes were to keep efence happy though
i suspect something strange was going on with locales there
too.
Martin Schwenke [Tue, 25 Feb 2014 19:55:21 +0000 (06:55 +1100)]
pstree: Ignore processes that disappear before reading cmdline
The worst case here is that the user has specific a PID on the
command-line, read_proc() fails to read cmdline for an irrelevant,
transient process and fails.
It is better to simply ignore processes that have disappeared. That
way pstree can provide useful output in more cases.
An alternative is to read cmdline only for processes that the user is
interested in. However, this probably increases the chances of an
interesting process exiting before the cmdline is read.
Signed-off-by: Martin Schwenke <martin@meltin.net>
Craig Small [Mon, 19 May 2014 12:56:50 +0000 (22:56 +1000)]
Fixed v4 versus v6 problem
fuser -n tcp 80 always worked because the v4 or v6 problem didnt hit
single ports, but any ipv4 or ipv6 remote address wouldn't work.
Caught by Coverity CID46269
Allan Wirth [Fri, 28 Feb 2014 22:09:19 +0000 (09:09 +1100)]
Full thread display for pstree an option
Commit [9de89a] made pstree show the correct thread names. This had
the unintended consequence of making a lot of thread views
uncompact, as the names would be different.
Allan suggested that if you want to see the real thread names, then
explictly ask for them. I agree and pstree now has a new option -t
for showing thread names.
Allan Wirth [Fri, 28 Feb 2014 22:09:19 +0000 (09:09 +1100)]
Full thread display for pstree an option
Commit [9de89a] made pstree show the correct thread names. This had
the unintended consequence of making a lot of thread views
uncompact, as the names would be different.
Allan suggested that if you want to see the real thread names, then
explictly ask for them. I agree and pstree now has a new option -t
for showing thread names.
Craig Small [Sun, 2 Feb 2014 06:02:36 +0000 (17:02 +1100)]
pstree: fclose fopened files
Commit [9de89a] uses fopen to find the tasks, but doesn't fclose
them afterward. Thanks for the anonymous and somewhat obscure
bug commenter for pointing it out.
Craig Small [Sun, 29 Sep 2013 05:16:08 +0000 (15:16 +1000)]
pstree shows threads correct names.
pstree would only show the process name, not the thread name. This
change now makes pstree read /proc/<PID>/task/<TID>/stat to find the
threads' real names.
$ pstree -p 1187
udisksd(1187)─┬─{udisksd}(1189)
├─{udisksd}(1191)
├─{udisksd}(1192)
├─{udisksd}(1195)
└─{udisksd}(27395)
./pstree -p 1187
udisksd(1187)─┬─{cleanup}(1195)
├─{gdbus}(1191)
├─{gmain}(1189)
├─{pool}(27395)
└─{probing-thread}(1192)
Craig Small [Tue, 16 Jul 2013 11:39:09 +0000 (21:39 +1000)]
pstree uses COLUMNS environement variable
pstree previously only used the window size for determining number of
columns, then a default of 132. With this change, pstree now checks
the COLUMNS environment variable first and uses that if valid.
env checking code nicked from top.c, by Jim Warner.
Han Pingtian [Thu, 20 Dec 2012 03:31:50 +0000 (11:31 +0800)]
doesn't complain about "not a directory"
If /proc/#/fd points to a path which has component removed, fuser
will complain like "Cannot stat file /proc/29322/fd/16: Not a
directory". Looks like it can be disabled just like commit 898dc70a1f
did.
Mike Frysinger [Tue, 19 Feb 2013 19:44:50 +0000 (14:44 -0500)]
use AC_CANONICAL_HOST
--host is used for the system where the compiled code will run.
--target is not the correct system to look that up.
http://www.gnu.org/software/autoconf/manual/html_node/Manual-Configuration.html#Manual-Configuration
Signed-off-by: Mike Frysinger <vapier@gentoo.org> Signed-off-by: Craig Small <csmall@enc.com.au>
Craig Small [Sat, 6 Oct 2012 23:52:46 +0000 (10:52 +1100)]
pstree compiles with SE Linux
pstree failed to compile with SE Linux enabled because one of the
scontext was missed and without it enabled the bug doesn't appear.
pstree is now re-worked so scontext is defined as a dummy meaning
most of the code except the reall SE Linux specific stuff is compilied
meaning this sort of thing shouldn't happen too much again.
Craig Small [Fri, 31 Aug 2012 04:21:19 +0000 (14:21 +1000)]
fuser finds unix sockets
in check_dir() stat was replaced with device() which found the right
device but zeroed out the inode, making that check always fail. This
meant fuser never found unix sockets.
Craig Small [Fri, 31 Aug 2012 00:05:24 +0000 (10:05 +1000)]
pstree finds orphans
Commit 26f9b6c1553d021c0bf9dd85f0647dc6e210948d while fixing the missing
root pid problem introduced another problem where PIDs are out of order.
A process that has a lower PID than its PPID would appear twice with
the tree breaking in strange ways.
We now scan the entire process tree first then perform two checks
if PID==1 is missing add it
if a process has no parent, then make it a child of PID==1, either the
real one or the faked one made in step 1
As this is done after all procsses are found, we don't get the previous
breakage.
Craig Small [Thu, 30 Aug 2012 22:09:45 +0000 (08:09 +1000)]
fuser -m regression
While fuser -m /boot worked, fuser -m /dev/blah would show everything.
This was because the filesystem for /dev was added as a target, not the
filesystem /dev/blah.
This simple fix suggested by SF user hanpt works well.
Ref: https://sourceforge.net/tracker/?func=detail&aid=3559232&group_id=15273&atid=115273 Signed-off-by: Craig Small <csmall@users.sourceforge.net>
Craig Small [Fri, 20 Jul 2012 12:32:27 +0000 (22:32 +1000)]
pstree sorts properly on names
pstree added temporary parents to processes, so if a child process
was lexigraphically before the parents or its "aunties and uncles"
then they were sorted with the parent temporary name "?".
This patch reorders the children in the parents list when they
are renamed.
Craig Small [Mon, 11 Jun 2012 01:36:55 +0000 (11:36 +1000)]
sed uses proper BRE
Apparently even though [0-9]+ works most of the time, its not proper BRE
and doesn't work ALL of the time. Replacing this with [0-9][0-9]* makes
everyone happy.
Noticed by Rich from the busybox project and reported by John Spencer
of the same project.
Corinna Vinschen [Sat, 19 May 2012 08:54:35 +0000 (18:54 +1000)]
3 fixes for Cygwin
The attached patch fixes three issues of fuser on Cygwin.:
- Cygwin does not support /proc/net/unix. The call to fill_unix_cache
always generates an error message that /proc/net/unix couldn't be
found, so the patch disables the call for Cygwin. An alternative
fix would be to avoid the error message entirely.
- `ls /dev' on Cygwin only lists manually added entries to /dev, not the
default files suported by Cygwin internally. Also,
/proc/$PID/mountinfo doesn't exist up to Cygwin 1.7.11. This
breaks fuser when using the _LISTS_H option.
- If you don't include lists.h, the code in check_dir doesn't work well.
st.st_ino is never set to 0, so the timeout(stat, ...) is never
called. Also, thedev never gets a valid value in this case, but it's
used subsequently for comparisons.
Samuel Thibault [Sat, 19 May 2012 08:09:41 +0000 (18:09 +1000)]
Remove fuser out of target for hurd-i386
hurd-i386 does not have PATH_MAX which means fuser won't compile.
However the archtecture cannot use fuser anyway so we now don't
even try to compile it for hurd-i386
Bug-Debian: http://bugs.debian.org/673485 Signed-off-by: Craig Small <csmall@enc.com.au>
Craig Small [Fri, 27 Jan 2012 02:11:25 +0000 (13:11 +1100)]
Added hardened CFLAGS
Debian and Ubuntu (at the least) have some CFLAGS that harden the binary
for some typical attacks. psmisc now will have these flags on by default
but checks the compilier supports them.
Sami Kerola [Wed, 4 Jan 2012 13:49:08 +0000 (14:49 +0100)]
build-sys: fix AC_TRY_LINK warnings
configure.ac:71: warning: The macro `AC_TRY_LINK' is obsolete.
configure.ac:71: You should run autoupdate.
../../lib/autoconf/general.m4:2688: AC_TRY_LINK is expanded from...
../../lib/m4sugar/m4sh.m4:606: AS_IF is expanded from...
../../lib/autoconf/general.m4:2032: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:2053: AC_CACHE_CHECK is expanded from...
m4/gettext.m4:367: gt_INTL_MACOSX is expanded from...
m4/gettext.m4:57: AM_GNU_GETTEXT is expanded from...
configure.ac:71: the top level
configure.ac:71: warning: The macro `AC_TRY_LINK' is obsolete.
configure.ac:71: You should run autoupdate.
../../lib/autoconf/general.m4:2688: AC_TRY_LINK is expanded from...
../../lib/m4sugar/m4sh.m4:606: AS_IF is expanded from...
../../lib/autoconf/general.m4:2032: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:2053: AC_CACHE_CHECK is expanded from...
m4/gettext.m4:57: AM_GNU_GETTEXT is expanded from...
configure.ac:71: the top level
configure.ac:71: warning: The macro `AC_TRY_LINK' is obsolete.
configure.ac:71: You should run autoupdate.
../../lib/autoconf/general.m4:2688: AC_TRY_LINK is expanded from...
../../lib/m4sugar/m4sh.m4:606: AS_IF is expanded from...
../../lib/autoconf/general.m4:2032: AC_CACHE_VAL is expanded from...
../../lib/autoconf/general.m4:2053: AC_CACHE_CHECK is expanded from...
Signed-off-by: Sami Kerola <sami.kerola@tomtom.com>