Commit Graph

134 Commits

Author SHA1 Message Date
William Orr
9742c74e7c pgrep: Enable case-insensitive process matching
FreeBSD has case-insensitive matching of processes in pgrep and
pkill, which can be super-useful. This patch uncomments and
documents the code needed to make this work.

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-05-10 17:42:09 +10:00
Vadim Kaushan
6ed8cf3444 pgrep: Off by one in realloc in option handling
The loop that parses options has a of by one bug where the realloc
adds one byte, instead of one list element.  This is exposed when
you try things like:
  pgrep -t,,,,

Signed-off-by: Craig Small <csmall@enc.com.au>
2015-04-03 18:17:08 +11:00
Eero Häkkinen
0f649e2cd2 pgrep: avoid SEGV when lightweight and list-full options are used together
do not segfault
2014-09-06 00:35:16 +03:00
Beni Cherniavsky-Paskin
b4951bfea3 Add -a/--list-full to --help output. 2014-08-19 21:05:30 +02:00
Jaromir Capik
4ba9ff5c0d pgrep: Fixing regression in exitcodes
The pgrep usage() rework commit from 26-Sep-2011 introduced
a regression in exitcodes and the pgrep tool now returns
EXIT_FAILURE (1) or even EXIT_SUCCESS (0) instead
of the documented EXIT_USAGE (2). This commit fixes
the usage() so that the exitcodes match the manual.
2014-07-02 17:42:08 +02:00
Craig Small
8e7ef322e2 Update help files
Benno Schulenberg suggested some changes to the help messages
to provide some consistency and clarity for both the users and
translators of procps.

The test needed to be updated as the pmap output changed too.

Signed-off-by: Craig Small <csmall@enc.com.au>
2014-02-02 18:13:01 +11:00
Craig Small
ca99070012 Merge branch 'merge-requests/23' 2014-01-30 22:12:28 +11:00
Elliott Forney
6f1c04259d pgrep fails to show full command line with -au
pgrep does not show the full command line when the -a and -u flags are
combined. The -a flag is ignored when the -u flag is used as well.

In addition, the supplied patch by Elliot did not fix the problem
when invert flag ( -v ) was used; a very small tweak to the patch
fixed this problem as well. This problem existed before.

Signed-off-by: Craig Small <csmall@enc.com.au>
2014-01-30 21:36:26 +11:00
Jaromir Capik
69de8db3e2 pgrep: Fixing memory leak in do_regcomp() 2014-01-02 18:39:27 +01:00
Ryan Cox
c304ffa994 fail on null string for arguments 2013-10-28 21:05:35 -06:00
Craig Small
6437aa08d4 Update options to single strings
To assist the translators, each option is a separate string.
This means if we add/change/delete an option the remaining ones
will just keep working and only the impacted option needs some
translation work on it.
2013-10-11 10:07:10 +11:00
Jim Warner
e6bbcdb492 misc: correct additional errors from merge request #13
Additional errors resulting from merge request #13 are
being addressed in this commit. They involve two cases
of trailing whitespace and one xwarnx printf type arg.

Reference(s):
http://gitorious.org/procps/procps/merge_requests/13
. earlier build-sys fix
commit e2242cb943
. original merge
commit dd6f24dbed

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-09-17 20:27:02 +02:00
Craig Small
dd6f24dbed Merge commit 'refs/merge-requests/13' of git://gitorious.org/procps/procps into merge-requests/13
Conflicts:
	pgrep.c
	ps/output.c
	ps/ps.1
2013-09-11 21:34:05 +10:00
Aristeu Rozanski
de7b3b9222 pgrep: introduce support for namespaces
A PID should be specified with --ns:
	$ pgrep --ns 12345
which will only match the processes which belong to to the same 6
namespaces. It is also possible to specify which namespaces to test:
	$ pgrep --ns 12345 --nslist mnt,net,ipc
which will match processes that belong to the same mount, network and
IPC namespaces as PID 12345.

Signed-off-by: Aristeu Rozanski <arozansk@redhat.com>
2013-04-16 15:05:31 -04:00
Jim Warner
7888f6a679 miscellaneous: clean up trailing whitespace once again
An earlier commit attempted to cleanse our environment
of all useless trailing whitespace. But the effort did
not catch 'empty' lines with a single space before ^J.

This commit hopefully finishes off the earlier effort.
In the meantime, let's pray that contributors' editors
are configured so that such wasted crap is disallowed!

Reference(s):
commit fe75e26ab6

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-04-07 18:05:01 +10:00
Rainer Müller
042776e04c configure: check for program_invocation_name
For portabiliy, check for program_invocation_name during configure and
define HAVE_PROGRAM_INVOCATION_NAME accordingly. Use of this symbol is
now enclosed with the appropriate #ifdef block.

The symbol program_invocation_name is only used for error message
handling using error(), so it's safe to omit this if it is not
available.
2013-03-20 16:32:06 +01:00
Roberto Polli
aa5a19620b support for listing thread ids (useful with iotop) 2013-03-18 11:58:47 +01:00
Jim Warner
fe75e26ab6 miscellaneous: clean up trailing whitespace throughout
The entire tree's polluted with inappropriate trailing
whitespace. This commit rids our environment of all of
those useless keystrokes. Unfortunately, it sure ain't
a permanent solution and requires every contributor to
instruct their editor(s) to prevent or eliminate them.

Plus it's strongly recommended we all insert something
like what's shown below to our '.gitconfig' file so as
to provide at least some warnings when we try to apply
any patches (git am) that do contain the #@!%& things!

References(s):
~/.gitconfig excerpt ---------------------------------
[core]
  whitespace = trailing-space, space-before-tab, blank-at-eof
[apply]
  whitespace = warn
--------------------------------- ~/.gitconfig excerpt

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-14 12:36:47 +01:00
static.vortex@gmx.com
cff3960c4a pgrep: Documentation fixes
Minor fixes to the help output and manpage of pgrep.
2013-02-18 21:41:31 +11:00
Craig Small
ce95dd53eb Add -c count option to pkill
Possibly by a side-effect but pkill -c option used to work which would
print the number of killed processes.  This small change restores this
functionality.

Bug-Debian: http://bugs.debian.org/693783

Signed-off-by: Craig Small <csmall@enc.com.au>
2012-11-21 22:11:17 +11:00
Sami Kerola
9ba7f3abdb pgrep: fix compiler warnings
pgrep.c:195:12: warning: 'fcntl_lock' defined but not used [-Wunused-function]
pgrep.c:575:5: warning: no previous declaration for 'signal_option' [-Wmissing-declarations]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-06 22:27:48 +11:00
Craig Small
9a60202b81 pgrep delimeter to delimiter
pgrep used delimiter and delimeter, the correct spelling is delimiter.
Thanks to Alexander Kobel for the heads-up.

Signed-off-by: Craig Small <csmall@enc.com.au>
2012-10-11 21:34:50 +11:00
Alfredo Esteban
f12277c74d Debian Bug report #526355
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=526355

Flag -f doesn't modify output anymore.

There is a new flag -a to show full command line processes.

Signed-off-by: Alfredo Esteban <aedelatorre@gmail.com>
2012-08-29 16:47:51 +10:00
Alfredo Esteban
7696bd200e pgrep/pkill -F expects \n (Debian Bug report #676709)
Hi,

I'm sending the patch to fix Debian bug report #676709:

pgrep/pkill -F expects "\n". If not present, no process is found/killed:

> wc -l /run/atd.pid
1 /run/atd.pid

> pgrep -F /run/atd.pid
1213

> wc -l /run/NetworkManager.pid
0 /run/NetworkManager.pid

> pgrep -F /run/NetworkManager.pid

Alfredo
2012-07-14 15:55:45 +10:00
Sami Kerola
d45456fb8a pkill: fix signal spec regression
Commig a5d9c40262 caused signal spec,
again, to be required as first option; for example

pkill -3 <program>	# worked
pkill <program> -3	# did not

This commit fixes the regression, without breaking option -u <numeric>
argument, assuming no-one is using negative numeric UID specifications
with space after -u && the argument.  IMHO such use case is rare enough
to be broken.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-24 13:30:22 +02:00
Craig Small
1d899453da minor fix for -u fix
Commit a5d9c40262 had one small problem.
In that function its *argc not argc. This stops pgrep with no commands
from segfaulting, thankyou dejagnu!!

Signed-Off-By: Craig Small <csmall@enc.com.au>
2012-06-17 18:19:48 +10:00
Alfredo Esteban
a5d9c40262 pkill -u uid fix
pkill would not parse -u <uid> options correctly and needed no space
between the flag and uid.

Bug-Debian: http://bugs.debian.org/676239
Signed-Of-By: Craig Small <csmall@enc.com.au>
2012-06-11 22:30:01 +10:00
Sami Kerola
52269d22f3 all: check stdout and stderr status at exit
If stream status is not checked at the end of execution below problem
would not report error, or non-zero exit code.  The uptime is just an
example same was true with all commands of the project.

$ uptime >&- ; echo $?
uptime: write error: Bad file descriptor
1
$ uptime >/dev/full ; echo $?
uptime: write error: No space left on device
1

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-23 15:57:53 +01:00
Sami Kerola
ce61089059 docs: clarification to license headers in files
Add license header to all files.  The summary of licensing is below,
taken from Craig Small's email which is referred in commit message
tail.

sysctl and pgrep are GPL 2+
The rest is LGPL 2.1+

Reference: http://www.freelists.org/post/procps/Incorrect-FSF-address-in-the-license-files,8
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=797962
CC: Craig Small <csmall@enc.com.au>
CC: Jaromir Capik <jcapik@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:41:11 +11:00
Sami Kerola
2f6b9bbfb8 pgrep: fix compiler warnings
pgrep.c:539:10: warning: unused variable 'buff' [-Wunused-variable]
pgrep.c:648:1: warning: "/*" within comment [-Wcomment]
pgrep.c:803:4: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long int' [-Wformat]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>

Conflicts:

	pgrep.c
2012-03-03 18:29:40 +11:00
Craig Small
502a79e02f Merge remote-tracking branch 'sami/to-craig' into sami-merge
Conflicts:
	pgrep.c
	w.c
2012-03-03 13:56:32 +11:00
Sami Kerola
1af18c260a pkill: remove -v match inversion option
The option -v does not make much sense in pkill context.

Reported-By: "Jason A. Spiro" <jasonspiro4@gmail.com>
Bug-Debian: http://bugs.debian.org/558044
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-11 21:43:13 +01:00
Sami Kerola
a1f8166642 pgrep: allow signal definition to be anywhere in command line
I as user often try to pkill something, notice that program did not
die and pkill again with signal -9.  Before this commit previous one
could not add signal at the end of command line, as the signal
definition had to be first argument, which was annoying.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-11 21:42:42 +01:00
Sami Kerola
e756a3db40 pgrep: use c style comments
The c++ comments e.g.  // should not be used in c code.  Additionally
white spaces are converted to tabs as a small clean up.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-11 21:42:40 +01:00
Sami Kerola
b2ebca4a60 pgrep: fix potential null derefences [smatch scan]
pgrep.c:137 split_list(19) error: potential null derefence 'list'.
pgrep.c:540 select_procs(106) error: potential null derefence 'list'.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-02-05 21:13:36 +01:00
Mike Frysinger
0da6537c5f fix printf format warnings
pgrep.c: In function 'main':
pgrep.c:793:4: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long int' [-Wformat]

vmstat.c: In function 'diskpartition_format':
vmstat.c:382:9: warning: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'long long unsigned int' [-Wformat]
vmstat.c:408:10: warning: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'long long unsigned int' [-Wformat]

w.c: In function 'main':
w.c:394:4: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long unsigned int' [-Wformat]

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-01-26 21:15:42 +01:00
Sami Kerola
bc974b3c33 pkill: enable displaying what is killed
Add new command line options -e, --echo to display what is
killed. Cost of this change is greater run time memory footprint,
because an union had to be changed to struct to allow name and
pid printing which what I as an user would expect to see in
verbose kill output.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-21 13:44:00 +01:00
Sami Kerola
12dce9f83b pgrep: fix compiler warning
pgrep.c:786:4: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'int' [-Wformat]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-21 12:15:41 +01:00
Sami Kerola
3489b9343e pkill: fix error printing
Print correct pid number of process that was where not killed
because of kill was not successful. Incorrect behaviour before
this fix is bello.

-- snip
$ ps -elf | grep dh[c]
1 S root      1409     1  0  80   0 -  1782 poll_s 02:01 ?        00:00:00 dhclient wlan0
$ pkill dhc
pkill: killing pid 1 failed: Operation not permitted
-- snip

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-21 12:15:40 +01:00
Sami Kerola
62316be69a pgrep: correction to usage output
Signed-off-by: Sami Kerola <sami.kerola@tomtom.com>
2012-01-06 00:17:44 +11:00
Craig Small
fb11e1fe0a Changed the err and warns to macros
err and warn are BSD format but they are not recommended by library
developers.  However their consiseness is useful!

The solution is to use some macros that create xerr etc which then
just map to the error() function.  The next problem is error() uses
program_invocation_name so we set this to program_invovation_short_name

This is a global set but seems to be the convention (or at least errors
are on the short name only) used everywhere else.
2012-01-03 18:48:43 +11:00
Sami Kerola
c3405fab1a translations: group usage texts
Reference: http://www.freelists.org/post/procps/backporting,5
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-01-02 16:29:03 +11:00
Sami Kerola
46d5d44734 pgrep: exit with error message instead of usage()
Printing usage() output at error is too noisy.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:54 +01:00
Sami Kerola
0022b6ec5d nls: improve translations and provide translator help comments
Reference: http://www.freelists.org/post/procps/backporting,1
Reported-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:54 +01:00
Sami Kerola
c862a4caa5 nls: add functions which take translations to be used
Add the following three functions to most of the commands.

setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);

Reference: http://www.freelists.org/post/procps/backporting,1
Reported-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:53 +01:00
Sami Kerola
4bfc4a00fb pgrep: use libc error printing facilities
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:50 +01:00
Sami Kerola
1ef14f4bf9 includes: add xalloc.h to unify memory allocations
The xalloc.h provides necessary error checking.

Signed-off-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:30:50 +01:00
Sami Kerola
ad6054b372 pgrep: add gettext support
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:04 +01:00
Sami Kerola
4581ac2240 pgrep: add long options & new usage
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-12-20 17:17:02 +01:00
Jan Christoph Nordholz
c73a449482 pgrep: distinguish between invalid commandline parameters and '-?'
A patch from Debian.

Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=413383
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:38:03 +11:00
Craig Small
551d7e4114 pgrep: fix compiler warning saved_start_time might be used uninitialized
A patch from Debian.

Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=197342
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:34:11 +11:00
Craig Small
6bc22a379f pgrep: add -c option for counting number of matched proceesses
A patch from Debian.

Bug-Debian: http://bugs.debian.org/375791
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:30:41 +11:00
Craig Small
618c52167b reversed the frees added to pgrep 2011-11-23 21:31:43 +11:00
Sami Kerola
2e96bc3771 pgrep: core dropped nearly always
The do_regcomp() tries to free command line argument.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-11-20 22:16:35 +01:00
Jim Warner
b23baee15c redhat analysis: pgrep 2011-10-15 08:26:28 +02:00
albert
e5b2b8614d pgrep: usage error should exit with 2 2007-05-28 00:16:39 +00:00
albert
47d33e7ed4 g is criteria 2006-06-24 20:12:29 +00:00
albert
7e2f073fbd better -L support 2006-06-23 03:18:12 +00:00
albert
6baa2fd34e FreeBSD -F and -L options (but -L may be useless) with sucky error messages 2006-06-21 05:45:16 +00:00
albert
93ed75edc9 correct description of some currently-foreign options 2006-06-21 04:41:58 +00:00
albert
492acac001 pgrep cleanup 2006-06-21 04:18:02 +00:00
albert
ffc32c6f8b fix more of the pgrep memory-related brokenness 2006-06-18 23:19:30 +00:00
albert
5b13bb93c7 new foreign-OS research noted 2006-06-18 20:55:02 +00:00
albert
5c591b836f fix "ps sm" bug involving 1-thread-proc optimization 2006-06-17 04:14:57 +00:00
albert
29cbc63561 fputs instead of fprintf 2005-10-30 23:45:47 +00:00
albert
d89cf44470 pkill should be quiet about processes that have gone away 2004-10-19 18:04:31 +00:00
albert
9e52b5aa29 sort cmd args and document OpenBSD differences 2004-07-21 14:27:56 +00:00
albert
c462dcfad5 ps thread support 2003-09-20 08:29:55 +00:00
albert
70599c3d3f last bits 2002-12-21 14:13:33 +00:00
albert
3e67b58ec2 satisfy GPL section 2a and LGPL section 2b name+date requirement 2002-12-15 00:30:17 +00:00
albert
b657e7e08a NORETURN 2002-12-09 07:53:09 +00:00
albert
eefbbef08b ChangeLog 2002-12-08 20:28:40 +00:00
albert
7ac9a0e1f5 present for Jim 2002-12-03 09:07:59 +00:00
albert
f40af35b77 c99 2002-11-25 21:36:43 +00:00
albert
19e565177b pgrep dead code 2002-11-25 21:14:36 +00:00
albert
c941d496a2 reorder pgrep functions, c99 vmstat 2002-11-25 21:12:25 +00:00
albert
501e740a31 new -o option: only the oldest that matches 2002-10-23 07:53:16 +00:00
albert
81a4a3d281 gcc 3.0 warnings 2002-10-12 04:25:57 +00:00
albert
e4d350522e mention -a 2002-10-09 04:28:48 +00:00
csmall
cca86db7ba added version stuff for kill and pgrep, tried to understand alberts groff and failed 2002-10-03 23:08:14 +00:00
albert
84ed57020d ifdef and cruft removal 2002-09-30 07:11:30 +00:00
albert
bce2da1f9a 64-bit time for Linux 2.5.xx 2002-05-28 04:18:55 +00:00
csmall
e4c67b2724 Put most of the Debian patches in
added a lot of cvsignore files
2002-02-01 23:40:38 +00:00
csmall
03a9b5a30f procps 010114 2002-02-01 22:47:29 +00:00