Commit Graph

72 Commits

Author SHA1 Message Date
Karel Zak 7a50f117a4 kill: check errno after strto..()
Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-07-20 11:34:53 +02:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Rosen Penev bd89499e07
[clang-tidy] do not return in void functions
Found with readability-redundant-control-flow

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-19 14:03:21 -07:00
Karel Zak bba1a60198 kill: add another ifdef
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-10 11:07:30 +01:00
Karel Zak 8aab38783a kill: add missing ifdefs
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-09 16:20:06 +01:00
Karel Zak ded3735ef4 kill: deallocate follow_ups [assan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-09 13:20:04 +01:00
Karel Zak 26c2ad6c38 kill: report features on -V, add lish_header initialization
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-12-09 12:40:53 +01:00
Sami Kerola 6e6b9a1d24
kill: use pidfd system calls to implement --timeout option
At times there is need in scripts to send multiple signals to a process.
Often these cases require some amount of waiting before follow-up signal
should be sent.

One common case is process termination, where first script tries to kill
process gracefully but if that does not work SIGKILL is sent.  Functionality
like that is commonly done by periodically checking if signalled pid exist
or not, and if it does another signal is sent possibly to an unrelated
process that reused pid number.  That means polling a pid is prone to a data
race.  Also if the first signal immediately kills the process one polling
interval is lost in sleep.

Another example when multiple signal need to be sent is various daemon
process control situations, such as Upgrading Executable on the Fly (see
reference).  This happens to be the case that inspired change author to make
sequential signaling a little bit easier.

Reference: http://nginx.org/en/docs/control.html#upgrade
Pull-request: https://github.com/karelzak/util-linux/pull/902
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-11-25 21:25:50 +00:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak c61e986fd0 lib/signames: remove signame array from header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-10-23 13:18:57 +02:00
Niklas Hambüchen 6855f6e80b kill: Extract signal names into signames.h/signames.c 2017-10-14 04:46:13 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
This patch is trivial and changes nothing, because
we were always using usage(stdout)

Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 0be3ad70ad
kill: remove pid command-name to option alias
Removal was promised to happen in March 2016 and the time has come to get
rid of this unexpected feature.

Reference: c5b057b342
Reviewed-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-08-14 13:30:16 +01:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Boris Egorov 43b4f7ea5f lib/tty: Pass default width to get_terminal_width()
Almost any code calling get_terminal_width() checks returned width for
non-positive values and sets it to some default value (say, 80). So,
let's pass this default value directly to the function.

[kzak@redhat.com: - get_terminal_width() refactoring]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-06 12:22:07 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Benno Schulenberg 09af3db48e textual: fix some typos and inconsistencies in various messages
Fixing plain typos, miswordings, inconsistent periods, some missing
angular brackets, and a proper pluralization (even when it involves
a constant, because for some languages the precise value matters).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-07-23 08:56:00 +02:00
Benno Schulenberg 36a3cd56ab textual: fix the usage message of kill
Using angular brackets around each individual argument, indenting a
continuation line, not using a space before =, improving some wordings,
and the argument of --queue is a value (a piece of data), not a signal.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-07-14 16:13:37 +02:00
Sami Kerola a3443c3067 kill: use --queue option argument as sigval integer value
The sigqueue(3) takes two values, signal and sigval.  Contents of the
signal can be altered with --signal option argument, so the --queue
argument should be reserved to affect sigval_int.

This is regression fix introduced by commit
9e8dffd5cd.

Reference: http://man7.org/linux/man-pages/man3/sigqueue.3.html
Reported-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-07-14 15:49:35 +02:00
Benno Schulenberg aa06617f6e textual: remove square brackets from around three dots
Also improve some option descriptions here and there.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2014-05-06 11:12:13 +02:00
Sami Kerola d1fd774289 kill: add --verbose option to display what is killed
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-04-26 19:04:57 +01:00
Sami Kerola 3665b07cd8 kill: remove unnecessary indirection
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-04-26 18:36:40 +01:00
Sami Kerola fe6b5e321f kill: make options --pid and --queue mutually exclusive
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-04-26 18:36:40 +01:00
Karel Zak e0d4675789 kill: fix bug in --all semantic
Introduces by 2ab6683f59.

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-07 11:29:09 +02:00
Karel Zak 6853d664a0 kill: add copyrights, etc.
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-07 11:12:14 +02:00
Karel Zak a01f4d4323 kill: return 64 on partial success
Return 64 (aka SOME_OK) when more than process specified and the
operation success only for subset of the processes.

 # kill -s 0 firefox mutt xxx; echo $?
 kill: cannot find process "xxx"
 64

We already use this concept for chcpu(8) or mount(8).

Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-07 11:07:00 +02:00
Karel Zak e497557f58 kill: coding style, simplify code
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-07 10:17:23 +02:00
Karel Zak 6ca933136f kill: rename printsig() to print_signal_name()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-07 10:10:43 +02:00
Karel Zak abc7d9bfdf kill: rename printsignals() to print_all_signalsprint_all_signals()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-07 10:03:50 +02:00
Karel Zak dff74debed kill: reorder functions to make it more readable
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-04-07 09:59:51 +02:00
Sami Kerola 9e8dffd5cd kill: move sigqueue inputs to control struct
Use of global variables is messy.  The earlier implementation also
assumed queue argument never to be textual, such as 'HUP', which now
works as one might expect.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-30 21:32:36 +01:00
Sami Kerola fd393d2a02 kill: add parse_arguments() function
Long main() is difficult to read, so moving argument parsing to separate
function should make sense.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-30 21:32:36 +01:00
Sami Kerola d40c87b0a4 kill: tell what is wrong rather than output usage()
Getting usage as error message is not specific enough.  As a user I want
to know what is wrong, and if it is unclear after error message how to
recover then I run command with --help.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-30 21:32:36 +01:00
Sami Kerola 2ab6683f59 kill: use control structure to pass user input to functions
This should make it easier to understand how the program works.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-30 21:32:36 +01:00
Sami Kerola c5b057b342 kill: deprecat invocation as 'pid' command name
Enabling options by renaming command is both unexpected and undocumented.
This magic is now deprecated and with remark of removal of this
functionality in future.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-30 21:32:36 +01:00
Sami Kerola c840c5023c kill: make usage() not to return
And change the function argument to be an output stream.  Earlier the
--help option made kill exit with none-zero value, that is now corrected.

CC: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-30 21:32:36 +01:00
Sami Kerola 6e1bffa886 kill: move magic numbers in beginning of the file
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-30 21:32:36 +01:00
Sami Kerola 80af5fb046 kill: flip all comparions to be in smaller - greater order
This makes code more readable.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-30 21:32:35 +01:00
Sami Kerola d4ea8636ad kill: fix coding style
The kill was deprecated at the time lot of other tools got style
unification.  Now when deprecation is lifted it is time to get kill
cleaner.  This commit does not modify code, only various spacing issues,
removal of unecessary braces, and such are dealt.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-03-30 21:32:35 +01:00
Karel Zak f546276e22 kill: support --list=<signal>
The '=' is expected for optional arguments and required in procps version.

Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-13 16:02:55 +01:00
Sami Kerola fda84b66ee kill: add pretty printed list output (for compatibility with procps)
* add -L, --table

References: http://www.freelists.org/post/procps/kill1-consolidation
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-13 15:47:12 +01:00
Karel Zak f1e7f7d54e kill: use new API from lib/procutils.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-12 17:40:31 +01:00
Sami Kerola ea72260cbe kill, procs: use pid_t for pids
Reference: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/linux/threads.h#n30
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-12 15:24:04 +01:00
Sami Kerola 44e5fcddc0 kill: use libc error printing facilities and exit values
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-12 14:42:21 +01:00
Sami Kerola a5618319e6 kill: align with howto-usage-function.txt
[kzak@redhad.com: - s/commandname/name/
                  - improve --all description
                  - add -h/--help]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-12 14:41:13 +01:00
Sami Kerola daa54393bc kill: add long options
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-03-12 14:31:42 +01:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00