Commit Graph

5751 Commits

Author SHA1 Message Date
Jörg Thalheim d7aa78c32f meson: add option to skip installing to $sysconfdir
This is useful for development where overwriting files out side
the configured prefix will affect the host as well as stateless
systems such as NixOS that don't let packages install to /etc but handle
configuration on their own.

Alternative to https://github.com/systemd/systemd/pull/17501

tested with:

$ mkdir inst build && cd build
$ meson \
  -Dcreate-log-dirs=false \
  -Dsysvrcnd-path=$(realpath ../inst)/etc/rc.d \
  -Dsysvinit-path=$(realpath ../inst)/etc/init.d \
  -Drootprefix=$(realpath ../inst) \
  -Dinstall-sysconfdir=false \
  --prefix=$(realpath ../inst) ..
$ ninja install
2020-11-12 11:21:46 +01:00
Yu Watanabe 9429ee6a89
Merge pull request #17567 from keszybz/various-small-cleanups
Various small cleanups
2020-11-12 16:30:06 +09:00
Lennart Poettering 23dce98e89
Merge pull request #16603 from benzea/benzea/special-app-slice
Use app.slice by default in user manager (and define special user slices)
2020-11-11 14:11:02 +01:00
Zbigniew Jędrzejewski-Szmek 5ee24fa0a0 user: move "extrinsic" units to their root slice
With the grandparent change to move most units to app.slice,
those units would be ordered After=app.slice which doesn't make any sense.
Actually they appear earlier, before the manager is even started, and
conceputally it doesn't seem useful to put them under any slice.
2020-11-10 17:33:32 +01:00
Zbigniew Jędrzejewski-Szmek 44ee03d111 tree-wide: unsetenv cannot fail
... when called with a valid environment variable name. This means that
any time we call it with a fixed string, it is guaranteed to return 0.
(Also when the variable is not present in the environment block.)
2020-11-10 15:52:32 +01:00
Zbigniew Jędrzejewski-Szmek 39c79477ac pid1: expose "extrinsic" status of swaps and mounts
The only visible change from this is that we show Extrinsic: yes/no
in dumps for swap units (this was already done for mount units).
2020-11-10 14:42:42 +01:00
Lennart Poettering 394131d5be
Merge pull request #17497 from anitazha/randomizeonce
timer: add new feature FixedRandomDelay=
2020-11-10 13:29:04 +01:00
Yu Watanabe 72585a584d core: add missing oom check
Fixes #17552.
2020-11-10 09:22:43 +01:00
Lennart Poettering df80c98cde
Merge pull request #17549 from yuwata/tiny-fixes
tiny fixes
2020-11-09 16:04:01 +01:00
Yu Watanabe 601844b71d core: reduce scope of variants
Fixes #17543.
2020-11-09 14:40:05 +09:00
Yu Watanabe db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Kristijan Gjoshev acf24a1a84 timer: add new feature FixedRandomDelay=
FixedRandomDelay=yes will use
`siphash24(sd_id128_get_machine() || MANAGER_IS_SYSTEM(m) || getuid() || u->id)`,
where || is concatenation, instead of a random number to choose a value between
0 and RandomizedDelaySec= as the timer delay.
This essentially sets up a fixed, but seemingly random, offset for each timer
iteration rather than having a random offset recalculated each time it fires.

Closes #10355

Co-author: Anita Zhang <the.anitazha@gmail.com>
2020-11-05 10:59:33 -08:00
Lennart Poettering d3dcf4e3b9 fileio: beef up READ_FULL_FILE_CONNECT_SOCKET to allow setting sender socket name
This beefs up the READ_FULL_FILE_CONNECT_SOCKET logic of
read_full_file_full() a bit: when used a sender socket name may be
specified. If specified as NULL behaviour is as before: the client
socket name is picked by the kernel. But if specified as non-NULL the
client can pick a socket name to use when connecting. This is useful to
communicate a minimal amount of metainformation from client to server,
outside of the transport payload.

Specifically, these beefs up the service credential logic to pass an
abstract AF_UNIX socket name as client socket name when connecting via
READ_FULL_FILE_CONNECT_SOCKET, that includes the requesting unit name
and the eventual credential name. This allows servers implementing the
trivial credential socket logic to distinguish clients: via a simple
getpeername() it can be determined which unit is requesting a
credential, and which credential specifically.

Example: with this patch in place, in a unit file "waldo.service" a
configuration line like the following:

    LoadCredential=foo:/run/quux/creds.sock

will result in a connection to the AF_UNIX socket /run/quux/creds.sock,
originating from an abstract namespace AF_UNIX socket:

    @$RANDOM/unit/waldo.service/foo

(The $RANDOM is replaced by some randomized string. This is included in
the socket name order to avoid namespace squatting issues: the abstract
socket namespace is open to unprivileged users after all, and care needs
to be taken not to use guessable names)

The services listening on the /run/quux/creds.sock socket may thus
easily retrieve the name of the unit the credential is requested for
plus the credential name, via a simpler getpeername(), discarding the
random preifx and the /unit/ string.

This logic uses "/" as separator between the fields, since both unit
names and credential names appear in the file system, and thus are
designed to use "/" as outer separators. Given that it's a good safe
choice to use as separators here, too avoid any conflicts.

This is a minimal patch only: the new logic is used only for the unit
file credential logic. For other places where we use
READ_FULL_FILE_CONNECT_SOCKET it is probably a good idea to use this
scheme too, but this should be done carefully in later patches, since
the socket names become API that way, and we should determine the right
amount of info to pass over.
2020-11-03 09:48:04 +01:00
Lennart Poettering acd156d197 automount: make user unmounting for automount units more debuggable
Let's add an explicit log message plus an error state for automount
units, if users explicitly unmounted our autofs mount.

Prompted by: #17448
2020-10-30 13:10:42 +01:00
Lennart Poettering bfeb927a55 pid1: various minor watchdog modernizations
Just some clean-ups.
2020-10-30 13:02:06 +01:00
Lennart Poettering 9b1915256c core: add Timestamping= option for socket units
This adds a way to control SO_TIMESTAMP/SO_TIMESTAMPNS socket options
for sockets PID 1 binds to.

This is useful in journald so that we get proper timestamps even for
ingress log messages that are submitted before journald is running.

We recently turned on packet info metadata from PID 1 for these sockets,
but the timestamping info was still missing. Let's correct that.
2020-10-27 14:12:39 +01: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
Anita Zhang e08dabfec7 core: clean up inactive/failed {service|scope}'s cgroups when the last process exits
If processes remain in the unit's cgroup after the final SIGKILL is
sent and the unit has exceeded stop timeout, don't release the unit's
cgroup information. Pid1 will have failed to `rmdir` the cgroup path due
to processes remaining in the cgroup and releasing would leave the cgroup
path on the file system with no tracking for pid1 to clean it up.

Instead, keep the information around until the last process exits and pid1
sends the cgroup empty notification. The service/scope can then prune
the cgroup if the unit is inactive/failed.
2020-10-27 13:20:40 +01:00
Benjamin Berg 7f3b86a497 core: Move user units into app.slice by default
This changes the default from putting all units into the root slice to
placing them into the app slice in the user manager. The advantage is
that we get the right behaviour in most cases, and we'll need special
case handling in all other cases anyway.

Note that we have currently defined that applications *should* start
their unit names with app-, so we could also move only these by creating
a drop-in for app-.scope and app-.service.
However, that would not answer the question on how we should manage
session.slice. And we would end up placing anything that does not fit
the system (e.g. anything started by dbus-broker currently) into the
root slice.
2020-10-23 09:58:41 +02:00
Zbigniew Jędrzejewski-Szmek fcb7138ca7 test-path: do not fail the test if we fail to start a service because of cgroup setup
The test was failing because it couldn't start the service:

path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
Failed to connect to system bus: No such file or directory
-.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied
path-modified.service: Failed to create cgroup /system.slice/kojid.service/path-modified.service: Permission denied
path-modified.service: Failed to attach to cgroup /system.slice/kojid.service/path-modified.service: No such file or directory
path-modified.service: Failed at step CGROUP spawning /bin/true: No such file or directory
path-modified.service: Main process exited, code=exited, status=219/CGROUP
path-modified.service: Failed with result 'exit-code'.
Test timeout when testing path-modified.path

In fact any of the services that we try to start may fail, especially
considering that we're doing some rogue cgroup operations. See
https://github.com/systemd/systemd/pull/16603#issuecomment-679133641.
2020-10-22 11:05:17 +02:00
Yu Watanabe 0ce8a9d6e5
Merge pull request #16939 from Rahix/robust-first-boot-machine-id
Make ConditionFirstBoot safe against power failures
2020-10-20 14:01:41 +09:00
Lennart Poettering 115fae8a07
Merge pull request #17387 from anitazha/systoomd_fixups
oomd fixups
2020-10-19 17:29:22 +02:00
Harald Seiler c261a5d014 machine-id-setup: sync before committing machine-id
sync() before committing a transient machine-id to disk.  This will
ensure that any filesystem changes made by first-boot units will have
been persisted before the first boot is marked as completed.
2020-10-19 16:28:22 +02:00
Harald Seiler 3023f2fead core: keep machine-id transient until first boot completes
Currently, a loss of power after the machine-id was written but before
all units with ConditionFirstBoot=yes ran would lead to the next boot
finding a valid machine-id, thus not being marked first boot and not
re-running these units.

To make the first boot mechanism more robust, instead of writing
/etc/machine-id very early, fill it with a marker value "uninitialized"
and overmount it with a transiently provisioned machine-id.  Then, after
the first boots completes (when systemd-machine-id-commit.service runs),
write the real machine-id to disk.

This mechanism is of course only invoked on first boot.  If a first boot
is not detected, the machine-id is handled as previously.

Fixes: #4511
2020-10-19 16:28:22 +02:00
Harald Seiler 583cef3b73 core: treat "uninitialized" in /etc/machine-id as first boot as well
When /etc/machine-id contains the string "uninitialized" instead of
a valid machine-id, treat this like the file was missing and mark this
boot as the first (-> units with ConditionFirstBoot=yes will run).
2020-10-19 12:33:39 +02:00
Anita Zhang f561e8c659 core: move where we send unit change updates to oomd
Post-merge suggestion from #15206
2020-10-19 02:46:07 -07:00
Anita Zhang 620ed14e44 core: reindent and align table in load-fragment-gperf.gperf.m4 2020-10-19 02:46:07 -07:00
Anita Zhang 2801d36e25 core: varlink tweaks
Suggested post-merge in #15206
2020-10-19 02:46:00 -07:00
Lennart Poettering d991100291 core: log about "systemctl kill" requests
let's add informational logging about each client requested signal
sending. While we are at, let's beef up error handling/log messages in
this case quite a bit: let's log errors both to syslog and report errors
back to client.

Fixes: #17254
2020-10-16 17:21:51 +02:00
Lennart Poettering 2ae0508e6d core: correct handling of "systemctl kill --kill-who=main-fail"
--kill-who=main-fail never worked correctly, due to a copy and paste
mistake in ac5e3a505e, where the same item
was listed twice. The mistake was
later noticed, but fixed incorrectly, in
201f0c916d.

Let's list all *-fail types correctly, finally.

And while we are at it, add a nice comment and generate a prettier D-Bus
error about this.
2020-10-16 17:19:20 +02:00
Lennart Poettering 8aff7ac4a7 core: add comment explaining unit_kill_context() vs. unit_kill_common() a bit 2020-10-16 17:16:02 +02:00
Lennart Poettering 6f997852c8 pid1: ignore whole /run/host hierarchy
Let's mark the whole /run/host hierarchy as something to ignore by PID 1
for generation of .mount units, i.e. consider it as "extrinsic".

By unifying container mgr supplied resources in one dir it's also easy
to exclude the whole lot from PID1's management inside the container.
This is the right thing to do, since from the payload's PoV these mounts
are just API and not manipulatable as they are established, managed and
owned by the container manager, not the payload.

(While we are it, also add the boot ID mount to the existing list, as
nspawn and other container managers overmount that too, typically, and
it is thus owned by the container manager and not the payload
typically.)
2020-10-15 17:16:36 +02:00
Zbigniew Jędrzejewski-Szmek 69c0807432
Merge pull request #15206 from anitazha/systoomd-v0
systemd-oomd
2020-10-15 14:16:52 +02:00
Lennart Poettering 1008f5b069
Merge pull request #17351 from poettering/exec-rt-typo-fix
fix one character typo in execute.c
2020-10-14 19:41:27 +02:00
Lennart Poettering fc8bc57f6b
Merge pull request #16968 from yuwata/remove-old-device-on-move-event
core, udev: remove old device on move event
2020-10-14 17:49:37 +02:00
Lennart Poettering 670eed4c8c core: debug log about received fds 2020-10-14 16:41:37 +02:00
Lennart Poettering 74aaf59b1a execute: make sure some more functions follow coding style
Initialize all return values on success, as our usual coding style
suggests.
2020-10-14 16:41:37 +02:00
Lennart Poettering f5fa352f1e execute: fix single character typo
Corrects: c413bb28df

Fixes: #17313
2020-10-14 16:41:37 +02:00
Frantisek Sumsal d46b79bbe0 tree-wide: drop if braces around single line expressions as well 2020-10-09 15:11:55 +02:00
Frantisek Sumsal d7a0f1f4f9 tree-wide: assorted coccinelle fixes 2020-10-09 15:02:23 +02:00
Anita Zhang a2db02253c core: add systemd-oomd implicit dependencies 2020-10-07 17:12:24 -07:00
Anita Zhang fe8d22fb09 core: systemd-oomd pid1 integration 2020-10-07 17:12:24 -07:00
Anita Zhang e30bbc90c9 core: add varlink call to get cgroup paths of units using ManagedOOM*= 2020-10-07 16:17:23 -07:00
Anita Zhang 4d824a4e0b core: add ManagedOOM*= properties to configure systemd-oomd on the unit
This adds the hook ups so it can be read with the usual systemd
utilities. Used in later commits by sytemd-oomd.
2020-10-07 16:17:23 -07:00
Renaud Métrich 5177cb0a9a unit: don't emit PropertiesChanged signal if adding a dependency to a unit is a no-op 2020-10-07 18:16:08 +02:00
Frantisek Sumsal 1d6cc5d0e5 tree-wide: coccinelle fixes 2020-10-04 12:32:21 +02:00
Lennart Poettering c14ebe07a9
Merge pull request #17172 from keszybz/read-login-defs
Read /etc/login.defs
2020-10-02 11:01:30 +02:00
Zbigniew Jędrzejewski-Szmek fc1a5d1a70 Also parse the minimum uid/gid values
We don't (and shouldn't I think) look at them when determining the type of the
user, but they should be used during user/group allocation. (For example, an
admin may specify SYS_UID_MIN==200 to allow statically numbered users that are
shared with other systems in the range 1–199.)
2020-10-01 17:52:41 +02:00
Lennart Poettering 14eb3285ab execute: use empty_to_root() a bit more 2020-10-01 11:02:11 +02:00
Lennart Poettering 74e1252072 execute: add helper for checking if root_directory/root_image are set in ExecContext 2020-10-01 11:02:11 +02:00