Commit graph

5111 commits

Author SHA1 Message Date
Kevin Kuehler 1f0f9f21c1 core: Add triggering job mode
When used with systemctl stop, follows TRIGGERED_BY dependencies and
adds them to the same transaction.

Fixes: #3043
2019-11-05 11:17:38 -08:00
Yu Watanabe f5947a5e92 tree-wide: drop missing.h 2019-10-31 17:57:03 +09:00
Lennart Poettering a93503e86f
Merge pull request #13866 from keszybz/nspawn-restarts
Make 'machinectl reboot' functional
2019-10-30 10:53:28 +01:00
Zbigniew Jędrzejewski-Szmek ebc57b89c6 pid1: log the reason why restart will or will not happen
I was trying to figure out why the restart was not happening, and it wasn't
at all obvious. Let's add a nice debug message.
2019-10-29 10:54:45 +01:00
Franck Bui d336ba9fa6 core: drop 'wants' parameter from unit_add_node_dependency()
Since Wants dependency is no more automagically added to swap and mount units,
this parameter is no more used hence this patch drops it.
2019-10-28 18:51:23 +01:00
Franck Bui 9b88bb5023 swap: do not make swap units wanted by its device unit anymore
It was done for mount units already (see commit 142b8142d7). For the
same reasons and for consistency we should also stop activating automagically
swaps when their device is hot-plugged.
2019-10-28 18:46:26 +01:00
Zbigniew Jędrzejewski-Szmek a5f6f346d3
Merge pull request #13423 from pwithnall/12035-session-time-limits
Add `RuntimeMaxSec=` support to scope units (time-limited login sessions)
2019-10-28 14:57:00 +01:00
Zbigniew Jędrzejewski-Szmek 9432f882a5 pid1: order .automount units after local-fs-pre.target
From the bug:
> According to the documentation of systemd.automount if the automoint point is
> automagically created if it doesn't exist yet. This ofcourse means the
> filesystem underneath has to be writable, which for / means not only does
> -.mount need to be started but also systemd-remount-fs.service has to be run,
> which isn't guaranteed by the default automount dependencies.
>
> For .mount units there is an automatic default After= dependency on
> local-fs-pre.target, would probably make sense to do the same for automount
> units to avoid it failing on the corner-case where it has to create directory.

Fixes #13306.
2019-10-28 22:44:32 +09:00
Philip Withnall 9ed7de605d scope: Support RuntimeMaxSec= directive in scope units
Just as `RuntimeMaxSec=` is supported for service units, add support for
it to scope units. This will gracefully kill a scope after the timeout
expires from the moment the scope enters the running state.

This could be used for time-limited login sessions, for example.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Fixes: #12035
2019-10-28 09:44:31 +01:00
Zbigniew Jędrzejewski-Szmek e9cfc71222
Merge pull request #13635 from fbuihuu/no-aliases-with-enable
man: alias names can't be used with enable command
2019-10-28 09:23:08 +01:00
Yu Watanabe f2106b1789
Merge pull request #13836 from systemd/assert-cleanups-and-constification
Assert cleanups and constification
2019-10-25 13:36:00 +09:00
Zbigniew Jędrzejewski-Szmek a5648b8094 basic/fs-util: change CHASE_OPEN flag into a separate output parameter
chase_symlinks() would return negative on error, and either a non-negative status
or a non-negative fd when CHASE_OPEN was given. This made the interface quite
complicated, because dependning on the flags used, we would get two different
"types" of return object. Coverity was always confused by this, and flagged
every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it
would this that an fd is returned). This patch uses a saparate output parameter,
so there is no confusion.

(I think it is OK to have functions which return either an error or an fd. It's
only returning *either* an fd or a non-fd that is confusing.)
2019-10-24 22:44:24 +09:00
Zbigniew Jędrzejewski-Szmek 0e7f5ad9d3 Move PLYMOUTH_SOCKET define to def.h and nuke plymouth-util.h
Let's not have a file with a single define.
2019-10-24 11:48:08 +02:00
Chris Down 959daf9bfc
Merge pull request #13743 from anitazha/dropin_all_the_things
core: support top level drop-ins through -.service.d for service units
2019-10-16 23:10:05 -04:00
Yu Watanabe 7f66ff56eb
Merge pull request #13784 from keszybz/constify-unit-pointers
Constify unit pointers
2019-10-17 09:41:36 +09:00
Anita Zhang d727acb650
Merge pull request #13754 from claudiozz/master
Allow restart for oneshot units
2019-10-16 14:21:59 -07:00
Claudio Zumbo 10e72727ee Allow restart for oneshot units
Picked up from https://github.com/systemd/systemd/pull/7474 , so
coauthored by @robermorales.
2019-10-16 09:44:20 -07:00
Zbigniew Jędrzejewski-Szmek abc9fa1cf1 core/load-fragment: remove unnecessary intialization
manager_load_unit() better set it on success, and unit_set_slice() asserts
that the argument is not NULL, so initializing it to NULL is not useful.
2019-10-16 16:33:54 +02:00
Zbigniew Jędrzejewski-Szmek 47538b7686 core/load-fragment: constify Unit* arguments where possible
This makes it easy to tell that the function only uses the Unit* for
reporting, and only makes changes to the other argument (which most likely
also points at the same Unit structure) for modifications.
2019-10-16 16:32:45 +02:00
Zbigniew Jędrzejewski-Szmek a2262bcafa core: mark unit_*_printf() functions as taking a const Unit*
They should never modify the unit argument, let's make this clear.
Also see 303ee60151.
2019-10-16 16:21:56 +02:00
Anita Zhang d272467882 shared/dropin: support -.service.d/ top level drop-in for service units
Closes #12830
2019-10-15 11:14:54 -07:00
Zbigniew Jędrzejewski-Szmek 2cea199ec1 core: pass around pointer, not struct
Since this is a static function, the compiler is likely to optimize it away
anyway, but let's do the normal thing here.
2019-10-11 13:46:05 +02:00
Zbigniew Jędrzejewski-Szmek 75193d4128 core: adjust load functions for other unit types to be more like service
No functional change, just adjusting code to follow the same pattern
everywhere. In particular, never call _verify() on an already loaded unit,
but return early from the caller instead. This makes the code a bit easier
to follow.
2019-10-11 13:46:05 +02:00
Zbigniew Jędrzejewski-Szmek c3784a7d78 core: simplify unit_load() a bit
Now all unit types define .load. But even if it wasn't defined, we'd need
to call unit_load_fragment_and_dropin() anyway, so this code would not have
worked correctly.

Also, unit_load_fragment_and_dropin() either returns -ENOENT or changes
UNIT_STUB to UNIT_LOADED, so we don't need to repeat this here.
2019-10-11 11:25:04 +02:00
Zbigniew Jędrzejewski-Szmek e0cfed4c59 core/service: use common implementation of unit_load_fragment_and_dropin()
There is a slight functional change when load_state == UNIT_MERGED. Before,
we would not call unit_load_dropin(), but now we do. I'm not sure if this
causes an actual difference in behaviour, but since all other unit types do
this, I think it's better to do the same thing here too.
2019-10-11 11:25:04 +02:00
Zbigniew Jędrzejewski-Szmek c362077087 core: turn unit_load_fragment_and_dropin_optional() into a flag
unit_load_fragment_and_dropin() and unit_load_fragment_and_dropin_optional()
are really the same, with one minor difference in behaviour. Let's drop
the second function.

"_optional" in the name suggests that it's the "dropin" part that is optional.
(Which it is, but in this case, we mean the fragment to be optional.)
I think the new version with a flag is easier to understand.
2019-10-11 10:45:33 +02:00
Anita Zhang e23d911664 core: disallow using '-.service' as a service name
-.service.d will become a special top level drop in so don't let it be a
usable service name (otherwise the interaction gets complicated).
2019-10-07 12:02:12 -07:00
Franck Bui 27c3112dcb fs-util: introduce inotify_add_watch_and_warn() helper
The default message for ENOSPC is very misleading: it says that the disk is
filled, but in fact the inotify watch limit is the problem.

So let's introduce and use a wrapper that simply calls inotify_add_watch(2) and
which fixes the error message up in case ENOSPC is returned.
2019-10-05 08:08:20 +02:00
Zbigniew Jędrzejewski-Szmek 3509e678f8
Merge pull request #13690 from cdown/cgroup_rework
cgroup: Add support to check systemd-internal cgroup limits against the kernel
2019-10-03 22:09:56 +02:00
Franck Bui a5cede8c24 pid1: restore the original environment passed by the kernel when switching to a new system manager
PID1 may modified the environment passed by the kernel when it starts
running. Commit 9d48671c62 unset $HOME for
example.

In case PID1 is going to switch to a new root and execute a new system manager
which is not systemd, we should restore the original environment as the new
manager might expect some variables to be set by default (more specifically
$HOME).
2019-10-03 22:08:13 +02:00
Chris Down bc0623df16 cgroup: analyze: Report memory configurations that deviate from systemd
This is the most basic consumer of the new systemd-vs-kernel checker,
both acting as a reasonable standalone exerciser of the code, and also
as a way for easy inspection of deviations from systemd internal state.
2019-10-03 15:06:25 +01:00
Chris Down 6dfb92823f cgroup: analyze: Match standard dump format
We're the only ones left using = as the delimiter, which looks really
weird in `systemd-analyze dump`. Use `: ` like everyone else.
2019-10-03 15:06:25 +01:00
Chris Down 74b5fb272f cgroup: Allow checking systemd-internal limits against the kernel
We currently don't have any mitigations against another privileged user
on the system messing with the cgroup hierarchy, bringing the system out
of line with what we've set in systemd. We also don't have any real way
to surface this to the user (we do have logs, but you have to know to
look in the first place).

There are a few possible solutions:

1. Maintaining our own cgroup tree with the new fsopen API and having a
   read-only copy for everyone else. However, there are some
   complications on this front, and this may be infeasible in some
   environments. I'd rate this as a longer term effort that's tangential
   to this patch.
2. Actively checking for changes with {fa,i}notify and changing them
   back afterwards to match our configuration again. This is also
   possible, but it's also good to have a way to do passive monitoring
   of the situation without taking hard action. Also, currently daemons
   like senpai do actually need to modify the tree behind systemd's
   back (although hopefully this should be more integrated soon).

This patch implements another option, where one can, on demand, monitor
deviations in cgroup memory configuration from systemd's internal state.
Currently the only consumer is `systemd-analyze dump`, but the interface
is generic enough that it can also be exposed elsewhere later (for
example, over D-Bus).

Currently only memory limit style properties are supported, but later I
also plan to expand this out to other properties that systemd should
have ultimate control over.
2019-10-03 15:06:25 +01:00
Mike Kazantsev fc103b3e34 cgroup: fix typo in BPF firewall support warning message 2019-10-03 15:48:57 +02:00
Zbigniew Jędrzejewski-Szmek 86e94d95d0
Merge pull request #13246 from keszybz/add-SystemdOptions-efi-variable
Add efi variable to augment /proc/cmdline
2019-10-03 12:19:44 +02:00
Zbigniew Jędrzejewski-Szmek 6e2d361d53
Merge pull request #13696 from keszybz/keep-dhcp-on-restart
Add a way to differentiate restart from stop and keep dhcp config on restart
2019-10-03 11:25:12 +02:00
Franck Bui c0000de87d pid1: fix DefaultTasksMax initialization
Otherwise DefaultTasksMax is always set to "inifinity".

This was broken by fb39af4ce4.
2019-10-03 11:24:27 +02:00
Dan Streetman 8084dcb9d7 src/core/automount: use DirectoryMode when calling mkdir -p
mkdir -p is called both when setting up the autofs mount, as well
as after being notified that the real mount unit should be called.
However the first mkdir -p is hardcoded with 0555, while the second
uses the value specified to DirectoryMode in the automount unit; the
second mkdir -p is only needed when called from coldplug, so under
normal operation the dirs are incorrectly created with mode 0555.

This replaces the hardcoded 0555 mode with the value of DirectoryMode.

Closes #13683.
2019-10-02 16:11:02 +02:00
Zbigniew Jędrzejewski-Szmek 4ab1670f3d core: rework how logging level is calculated for kill operations
Setting the log level based on the signal made sense when signals that
were used were fixed. Since we allow signals to be configured, it doesn't
make sense to log at notice level about e.g. a restart or stop operation
just because the signal used is different.

This avoids messages like:
  six.service: Killing process 210356 (sleep) with signal SIGINT.
2019-10-02 14:01:40 +02:00
Zbigniew Jędrzejewski-Szmek a232ebcc2c core: add support for RestartKillSignal= to override signal used for restart jobs
v2:
- if RestartKillSignal= is not specified, fall back to KillSignal=. This is necessary
  to preserve backwards compatibility (and keep KillSignal= generally useful).
2019-10-02 14:01:25 +02:00
Chris Down 2bfd08ce38
Merge pull request #13691 from mrc0mmand/coverity-fixes
Coverity fixes for unchecked return values
2019-10-02 10:42:53 +01:00
Zbigniew Jędrzejewski-Szmek 28a2dfe801 core: add helper function to check job status
Since job.h includes unit.h, and unit.h includes job.h, imports need to
be adjusted to make sure unit.h is included first if the helper is used.
2019-10-01 15:05:27 +02:00
Zbigniew Jędrzejewski-Szmek fa036b6114 core: remove unused prototypes 2019-10-01 14:25:10 +02:00
Zbigniew Jędrzejewski-Szmek c436a4981e core: minor formatting adjustment 2019-10-01 14:13:35 +02:00
Frantisek Sumsal 54756dce57 execute: explicitly ignore fd_wait_for_event()'s return value
Fixes CID#1402316
2019-10-01 10:25:36 +02:00
Chris Down 184e989d7d cgroup: Mark memory protections as explicitly set in transient units
A later version of the DefaultMemory{Low,Min} patch changed these to
require explicitly setting memory_foo_set, but we only set that in
load-fragment, not dbus-cgroup.

Without these, we may fall back to either DefaultMemoryFoo or
CGROUP_LIMIT_MIN when we really shouldn't.
2019-09-30 22:27:21 +01:00
Chris Down 64fe532e90 cgroup: Respect DefaultMemoryMin when setting memory.min
This is an oversight from https://github.com/systemd/systemd/pull/12332.

Sadly the tests didn't catch it since it requires a real cgroup
hierarchy to see, and it wasn't seen in prod since we're only currently
using DefaultMemoryLow, not DefaultMemoryMin. :-(
2019-09-30 18:41:21 +01:00
Chris Down 7c9d2b7993 cgroup: Check ancestor memory min for unified memory config
Otherwise we might not enable it when we should, ie. DefaultMemoryMin is
set in a parent, but not MemoryMin in the current unit.
2019-09-30 18:24:26 +01:00
Michael Olbrich 28e68bb235 Handle d_type == DT_UNKNOWN correctly
As documented in the man-page, readdir() may return a directory entry with
d_type == DT_UNKNOWN. This must be handled for regular filesystems.

dirent_ensure_type() is available to set d_type if necessary. Use it in
some more places.

Without this systemd will fail to boot correctly with nfsroot and some
other filesystems.

Closes #13609
2019-09-30 13:29:59 +01:00
Filipe Brandenburger 28b77ab246 log: Add missing "%" in "%m" log format strings
These were clearly intended to be "%m" to display the human readable version
of the error stored in errno.
2019-09-25 09:28:26 +02:00