Commit Graph

54 Commits

Author SHA1 Message Date
Lennart Poettering c2bc710b24 string-util: imply NULL termination of strextend() argument list
The trailing NULL in the argument list is now implied (similar to
what we already have in place in strjoin()).
2021-01-06 17:24:46 +01:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Lennart Poettering 74d6421da0 tree-wide: cast result of get_process_comm() to (void) where we ignore it 2020-10-27 14:06:49 +01:00
Zbigniew Jędrzejewski-Szmek 90e74a66e6 tree-wide: define iterator inside of the macro 2020-09-08 12:14:05 +02:00
Lennart Poettering 0bdd282a4e killall: update reference to root storage daemon interface docs 2020-01-13 18:53:46 +01:00
Lennart Poettering 60cd367649 killall: bump log message about unkilled processes to LOG_WARNING
By raising this, we can raise the kernel kmsg log level safely, and
still see these messages.
2019-07-13 11:05:07 +02:00
Benjamin Robin 763e7b5da6 core/killall: Add documentation about broadcast_signal() 2019-04-10 19:30:38 +02:00
Benjamin Robin 2c32f4f47d core/killall: Log the process names not killed after 10s 2019-04-10 19:27:38 +02:00
Benjamin Robin a012f9f7cf core/killall: Propagate errors and return the number of process left 2019-04-08 19:41:16 +02:00
Lennart Poettering d3a94b3e80 killall: (void)ify more things 2018-09-25 12:50:35 +02:00
Lennart Poettering 20ca2d10bd killall: filter out bogus PIDs
we might as well filter these too since negative PIDs have special
semantics in kill(), and we should never trigger that...
2018-09-25 12:50:35 +02:00
Lennart Poettering e45154c770 killall: use is_kernel_thread() during killing spree process filtering too
Apparently the new "bpfilter" subsystem otherwise confuses us.

See: https://lists.freedesktop.org/archives/systemd-devel/2018-September/041392.html
2018-09-25 12:50:35 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Lennart Poettering 5d13a15b1d tree-wide: drop spurious newlines (#8764)
Double newlines (i.e. one empty lines) are great to structure code. But
let's avoid triple newlines (i.e. two empty lines), quadruple newlines,
quintuple newlines, …, that's just spurious whitespace.

It's an easy way to drop 121 lines of code, and keeps the coding style
of our sources a bit tigther.
2018-04-19 12:13:23 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Jan Klötzke e73c54b838 shutdown: make kill timeout configurable (#7835)
By default systemd-shutdown will wait for 90s after SIGTERM was sent
for all processes to exit. This is way too long and effectively defeats
an emergency watchdog reboot via "reboot-force" actions. Instead now
use DefaultTimeoutStopSec which is configurable.
2018-01-10 19:00:20 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Alan Jenkins 3448a96980 core: remove "misuse" of getpgid() in systemd-shutdown
Using `kill()`  with a signal of 0 is a slightly more documented idiom for
checking whether a process still exists.  It is mentioned explicitly in
man pages.  This avoids the need to comment the call as "misuse".
A comment is still necessary - in fact this idiom is even more confusing if
you don't know how it works.  But it's easy enough to explain.
2017-10-30 16:10:37 +00:00
Andreas Rammhold ec2ce0c5d7
tree-wide: use `!IN_SET(..)` for `a != b && a != c && …`
The included cocci was used to generate the changes.

Thanks to @flo-wer for pointing this case out.
2017-10-02 13:09:56 +02:00
Zbigniew Jędrzejewski-Szmek 5c5d9f26d6 core/killall: add (void)
CID #1368238.
2017-02-20 16:02:18 -05:00
Zbigniew Jędrzejewski-Szmek 9e615117da pid1: rewrite check in ignore_proc() to not check condition twice
It's harmless, but it seems nicer to evaluate a condition just a single time.
2017-01-31 00:49:53 -05:00
Reverend Homer 8fb3f00997 tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853) 2016-12-09 10:04:30 +01:00
Zbigniew Jędrzejewski-Szmek f97b34a629 Rename formats-util.h to format-util.h
We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.
2016-11-07 10:15:08 -05:00
Lennart Poettering d450612953 shutdown: use 90s SIGKILL timeout
There's really no reason to use 10s here, let's instead default to 90s like we
do for everything else.

The SIGKILL during the final killing spree is in most regards the fourth level
of a safety net, after all: any normal service should have already been stopped
during the normal service shutdown logic, first via SIGTERM and then SIGKILL,
and then also via SIGTERM during the finall killing spree before we send
SIGKILL. And as a fourth level safety net it should only be required in
exceptional cases, which means it's safe to rais the default timeout, as normal
shutdowns should never be delayed by it.

Note that journald excludes itself from the normal service shutdown, and relies
on the final killing spree to terminate it (this is because it wants to cover
the normal shutdown phase's complete logging). If the system's IO is
excessively slow, then the 10s might not be enough for journald to sync
everything to disk and logs might get lost during shutdown.
2016-07-12 17:32:30 +02:00
Torstein Husebø 61233823aa treewide: fix typos and remove accidental repetition of words 2016-07-11 16:18:43 +02:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Michal Sekletar 1359fffa57 shutdown: complain if process excluded from killing spree runs of the same rootfs as PID1 2016-01-26 14:13:13 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering fea72cc033 macro: introduce new PID_TO_PTR macros and make use of them
This adds a new PID_TO_PTR() macro, plus PTR_TO_PID() and makes use of
it wherever we maintain processes in a hash table. Previously we
sometimes used LONG_TO_PTR() and other times ULONG_TO_PTR() for that,
hence let's make this more explicit and clean up things.
2015-09-04 09:07:30 +02:00
Thomas Hindoe Paaboel Andersen 60053efbba core: log oom during killing spree
but don't do anything else. We still want to kill as much as
possible.

Coverity CID#996306
2015-06-09 22:07:27 +02:00
Ronny Chevalier 288a74cce5 shared: add terminal-util.[ch] 2015-04-11 00:34:02 +02:00
Ronny Chevalier 0b452006de shared: add process-util.[ch] 2015-04-10 23:54:49 +02:00
Ronny Chevalier 6482f6269c shared: add formats-util.h 2015-04-10 23:54:48 +02:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt d5099efc47 hashmap: introduce hash_ops to make struct Hashmap smaller
It is redundant to store 'hash' and 'compare' function pointers in
struct Hashmap separately. The functions always comprise a pair.
Store a single pointer to struct hash_ops instead.

systemd keeps hundreds of hashmaps, so this saves a little bit of
memory.
2014-09-15 16:08:50 +02:00
Ronny Chevalier e1d758033d use more _cleanup_ macro 2014-06-24 19:09:57 +02:00
Andreas Henriksson 3e09eb5c83 core: fix invalid free() in killall()
static int killall(....) in ./src/core/killall.c tries to get "s"
initialized by calling get_process_comm(...) which calls
read_one_line_file(...) which if it fails will mean it is left
uninitialized.
It is then used in argument to strna(s) call where it is
dereferenced(!), in addition to nothing else initializing it before
the scope it is in finishes.
2014-06-13 19:00:13 +02:00
Simon Peeters b68fa010f7 shared: procfs_file_alloca: handle pid==0
when pid is set to 0 use /proc/self
2014-01-05 00:59:13 -05:00
Zbigniew Jędrzejewski-Szmek ccd06097c7 Use format patterns for usec_t, pid_t, nsec_t, usec_t
It is nicer to predefine patterns using configure time check instead of
using casts everywhere.

Since we do not need to use any flags, include "%" in the format instead
of excluding it like PRI* macros.
2014-01-02 19:45:47 -05:00
Lennart Poettering 6301a98cdf core: fix order of parameters in broadcast_signal() 2013-11-25 23:03:03 +01:00
Lennart Poettering 0bee65f062 shutdown: during final killing spree also send SIGHUP in addition to SIGTERM to deal with shells
This makes shutdown a bit faster if debug-shell.service is enabled.
2013-11-25 22:10:22 +01:00
Zbigniew Jędrzejewski-Szmek 5841bd803f killall: do not use alloca() in argument list
It is not allowed.
2013-06-26 19:52:00 -04:00
Zbigniew Jędrzejewski-Szmek 31885cd5e3 core/killall: use procfs_file_alloca 2013-04-19 10:10:41 -04:00
Harald Hoyer b6e8f1f03d core/killall.c: prevent segfault and initialize pids 2013-04-03 15:17:51 +02:00
Lennart Poettering aaf7eb81be shutdown: correctly wait for processes we killed in the killall spree
Previously we simply counted how many processes we killed and expected
as many waitpid() calls to succeed. That however is incorrect to do.

As we might kill processes that are not our immediate children, and as
there might be left-over processes in the waitpid() queue from earlier
the we might get more ore less waitpid() events that we expect.

Hence: keep precise track of the processes we kill, remove the ones we
get waitpid() for, and after each time we get SIGCHLD check if all
others still exist. We use getpgid() to check if a PID still exists.

This should fix issues with journald not setting journal files offline
correctly on shutdown, because we'd too quickly proceed from SIGTERM to
SIGKILL because some left-over process was in our waitpid() queue.
2013-04-02 01:28:01 +02:00