Commit graph

3585 commits

Author SHA1 Message Date
Lennart Poettering a45d7127e7 tree-wide: use EXIT_SUCCESS/EXIT_FAILURE in exit() where we can 2017-12-25 11:48:21 +01:00
Lennart Poettering d00c263143 shutdown: unify shutdown.c's and async.c's sync() helper process
The helper processes are pretty much the same now, let's unify them
hence.
2017-12-25 11:48:21 +01:00
Lennart Poettering 4c253ed1ca tree-wide: introduce new safe_fork() helper and port everything over
This adds a new safe_fork() wrapper around fork() and makes use of it
everywhere. The new wrapper does a couple of things we previously did
manually and separately in a safer, more correct and automatic way:

1. Optionally resets signal handlers/mask in the child

2. Sets a name on all processes we fork off right after forking off (and
   the patch assigns useful names for all processes we fork off now,
   following a systematic naming scheme: always enclosed in () – in order
   to indicate that these are not proper, exec()ed processes, but only
   forked off children, and if the process is long-running with only our
   own code, without execve()'ing something else, it gets am "sd-" prefix.)

3. Optionally closes all file descriptors in the child

4. Optionally sets a PR_SET_DEATHSIG to SIGTERM in the child, in a safe
   way so that the parent dying before this happens being handled
   safely.

5. Optionally reopens the logs

6. Optionally connects stdin/stdout/stderr to /dev/null

7. Debug logs about the forked off processes.
2017-12-25 11:48:21 +01:00
Lennart Poettering 41bd3379ef sync: fork off sync() in a process instead of a thread
Let's fork off sync() ina process instead of a thread, as a safety
measure. This is beneficial to ensure that the original process can exit
without having to wait for the sync() to finish (note that the kernel
will delay process termination until all threads finished their
syscalls). In case of hanging NFS this increases the chance that PID 1
can safely transition to the "systemd-shutdown" process as the sync() is
initiated early on but definitely not waited for.
2017-12-25 11:48:21 +01:00
Lennart Poettering 7785da68e6
Merge pull request #7695 from yuwata/transient-socket
DBus-API: implement transient socket unit
2017-12-23 19:20:29 +01:00
Yu Watanabe 533f8a6771 load-fragment: simplify list insertion logic
LIST_FIND_TAIL and LIST_INSERT_AFTER can work for empty list.
2017-12-23 19:32:46 +09:00
Yu Watanabe 32048f5414 cgroup: IODeviceWeight= or friends can take device node files in /run/systemd/inaccessible/
systemd creates several device nodes in /run/systemd/inaccessible/.
This makes CGroup's settings related to IO can take device node
files in the directory.
2017-12-23 19:32:42 +09:00
Yu Watanabe 845001221d core/socket: shorten socket_fdname() 2017-12-23 19:32:40 +09:00
Yu Watanabe 827d9bf297 core/socket: dump more settings 2017-12-23 19:32:38 +09:00
Yu Watanabe 13ec20d42a dbus-cgroup: merge several blocks which operate almost same tasks 2017-12-23 19:32:36 +09:00
Yu Watanabe d6ff82d37c dbus-execute: use empty_to_null() where it can be applicable 2017-12-23 19:32:34 +09:00
Yu Watanabe d9f7305fd7 cgroup: move path checking logic to dbus-cgroup.c 2017-12-23 19:32:29 +09:00
Yu Watanabe b48e508db3 dbus-socket: move truncation check to bus_socket_set_transient_property() 2017-12-23 19:32:23 +09:00
Yu Watanabe e045e325df basic: introduce socket_protocol_{from,to}_name()
And use them where they can be applicable.
2017-12-23 19:32:04 +09:00
Yu Watanabe 9c0320e7ab core: implement transient socket unit 2017-12-23 18:47:33 +09:00
Yu Watanabe 038ed5a4b6 core/socket: add socket_port_type_from_string() 2017-12-23 18:46:16 +09:00
Yu Watanabe 836bb1cd42 core:socket: fix string in socket_exec_command_table 2017-12-23 18:45:59 +09:00
Yu Watanabe 9ee896d5dd core,seccomp: fix logic to parse RestrictAddressFamilies= in dbus-execute.c
If multiple RestrictAddressFamilies= settings, some of them are
whitelist and the others are blacklist, are sent to bus, then parsing
result was corrupted.
This fixes the parse logic, now it is the same as one used in
load-fragment.c
2017-12-23 18:45:52 +09:00
Yu Watanabe 898748d8b9 core,seccomp: fix logic to parse syscall filter in dbus-execute.c
If multiple SystemCallFilter= settings, some of them are whitelist
and the others are blacklist, are sent to bus, then the parse
result was corrupted.
This fixes the parse logic, now it is the same as one used in
load-fragment.c
2017-12-23 18:45:32 +09:00
Zbigniew Jędrzejewski-Szmek d49a7143fc machine-id-setup: use return log_error… pattern
No functional difference, but this way it's clearer that the original errno
value is returned.
2017-12-19 15:20:38 +01:00
Yu Watanabe e7bcff4ec4 core: move path_kill_slashes() to manager 2017-12-19 10:44:20 +09:00
Yu Watanabe 5976f1ca76 core: fix wrong validity check 2017-12-19 10:44:04 +09:00
Yu Watanabe 586290017d tree-wide: use !strv_isempty() instead of strv_length() > 0 2017-12-19 10:43:57 +09:00
Chris Down e16647c39d condition: Create AssertControlGroupController (#7630)
Up until now, the behaviour in systemd has (mostly) been to silently
ignore failures to action unit directives that refer to an unavailble
controller. The addition of AssertControlGroupController and its
conditional counterpart allow explicit specification of the desired
behaviour when such a situation occurs.

As for how this can happen, it is possible that a particular controller
is not available in the cgroup hierarchy. One possible reason for this
is that, in the running kernel, the controller simply doesn't exist --
for example, the CPU controller in cgroup v2 has only recently been
merged and was out of tree until then. Another possibility is that the
controller exists, but has been forcibly disabled by `cgroup_disable=`
on the kernel command line.

In future this will also support whatever comes out of issue #7624,
`DefaultXAccounting=never`, or similar.
2017-12-18 08:53:29 +01:00
Zbigniew Jędrzejewski-Szmek 292599e2ad
Merge pull request #7665 from poettering/main-cleanup
let's split up main() into more functions, to make it digestable
2017-12-18 08:26:36 +01:00
Lennart Poettering 8769525f57
Merge pull request #7661 from keszybz/slice-cleanups
Slice cleanups and systemd-mount --owner
2017-12-15 20:55:39 +01:00
Lennart Poettering d72a8f10b6 main: add some more comments for the early initialization phase 2017-12-15 20:52:28 +01:00
Lennart Poettering 625e8690ab main: reorder variable declarations a bit
Let's remove a bit redundancy, and list variables of the same
type/category in one declaration line.
2017-12-15 20:52:28 +01:00
Lennart Poettering aa40ff0703 main: split out 'skip_setup' check into its own functions
And let's optimize it a tiny bit, by only iterating through the argument
list once, instead of twice.
2017-12-15 20:52:28 +01:00
Lennart Poettering b9e90f3aa6 main: do bother with uid_to_name() unless we do debug logging 2017-12-15 20:52:28 +01:00
Lennart Poettering 43db615ba4 main: conditionalize fixup_environment() internally
This code is executed before we parse command line/configuration
parameters, hence let's not use arg_system to figure our how to clean up
things, but instead PID == 1. Let's move that check inside of the
function, to make things a bit more robust abstract from the outside.

Also, let's add a log message about this, that was so far missing.
2017-12-15 20:52:28 +01:00
Lennart Poettering 2d77603838 main: let's move ACTION_RUN test into initialize_runtime()
Let's hide this check inside the function and make it easier to follow
the general control flow of main().
2017-12-15 20:52:28 +01:00
Lennart Poettering 713a88757a mount-setup: fix MNT_CHECK_WRITABLE error handling, and log about the issue
Let's correct the error handling (the error is in errno, not r), and
let's add logging like the rest of the function has it.
2017-12-15 20:52:28 +01:00
Lennart Poettering 3a671cd130 main: tweak timerslack message a bit
Let's clarify that this is a non-issue, by downgrading it to LOG_WARN
and saying "ignoring" in the message.
2017-12-15 20:52:28 +01:00
Lennart Poettering 3c3c6cb95d main: move install_crash_handler() and mount_cgroup_controllers() invocations
Let's place them in initialize_runtime(), where they appear to fit best.
Effectively this is just a move a little bit down, swapping places with
log_execution_mode(), which should require neither call to be done
first.

Note that changes the conditionalization a bit for these calls, from
(PID == 1) to (arg_system && arg_action == ACTION_RUN). At this point this is pretty much the same
however, as we don't allow PID 1 without ACTION_RUN and without
arg_system set, safety_checks() ensures that.
2017-12-15 20:52:28 +01:00
Lennart Poettering db33214b52 core: move arg_show_status fix-up into load_configuration()
It's part of finalizing our runtime parameters, hence let's move this
into load_configuration() after we loaded everything else. This is safe,
since we don't use it between the location where it was and where we
place it now yet.
2017-12-15 20:52:28 +01:00
Lennart Poettering 2e51b31caf main: split out code that sets up the console/terminal and stuff
More refactoring to make main() more digestable.
2017-12-15 20:52:28 +01:00
Lennart Poettering efeb853fbd main: split out code that collects passed fds
More refactoring to make main() more digestable
2017-12-15 20:52:28 +01:00
Lennart Poettering 72c7329b6e main: slight modernizations for status_welcome()
There's no point in duplicating the complex parse_env_file() invocation,
hence let's not do it.
2017-12-15 20:52:28 +01:00
Lennart Poettering fd8c85c652 main: let's move the arg_show_status check into status_welcome()
It's kinda nice to hide this check inside of status_welcome() itself, so
that it handles all this on its own.
2017-12-15 20:52:28 +01:00
Lennart Poettering a70c72a046 main: slightly rearrange serialization fdset, and logging/console setup
Let's merge two if blocks, and move log_close()/log_open() out of the
testing codepath, as there's no reason to have it there.
2017-12-15 20:52:28 +01:00
Lennart Poettering 5a2e0c6257 main: move chdir("/") a bit earlier
There's no need to do this within the block where logging is closed,
hence move it earlier, so that this block can be kept as small as
possible.
2017-12-15 20:52:28 +01:00
Lennart Poettering 6f101b566f main: move initialize_join_controllers() invocation into load_configuration()
This just sets up some variables the loaded configuration will then
modify. Let's invoke it hence right before loading the configuration.

This moves the initialization just a tiny bit later, but that shouldn't
matter, since we never access it in-between.
2017-12-15 20:52:28 +01:00
Lennart Poettering 51e5ff02a8 main: split out taint string logging into its own function
It's sufficiently complex now, let's add our own function for this too.
2017-12-15 20:52:28 +01:00
Lennart Poettering febf46a46c core: add more safety check
Let's make sure that if we are PID 1 we are invoked in ACTION_RUN mode,
and in arg_system mode, as well as the opposite.

Everything else is untested and probably not worth supporting hence
let's bail out early if people try anyway.
2017-12-15 20:52:28 +01:00
Lennart Poettering 263162da6c core: split out test summary output into its own function
More refactoring to make main() shorter.
2017-12-15 20:52:28 +01:00
Lennart Poettering 74da609f0d main: split out security policy loading into its own function
More refactoring to make things more digestable.
2017-12-15 20:52:28 +01:00
Lennart Poettering 5625c18a47 main: invoke pager_open() only at one place
Let's just move this up a few lines and unify the invocation.
2017-12-15 20:52:28 +01:00
Lennart Poettering b0d7c98993 core: split out various startup safety checks from main() into its own function
No functional changes, just some refactoring to make main() more
digestable.
2017-12-15 20:52:28 +01:00
Lennart Poettering 97d1fb94ba main: split out all parsing of command line arguments/kernel arguments/configuration files
Let's shorten main() a bit, and split out everything that loads our
configuration and runtime parameters into a function of its own.

No changes in behaviour.
2017-12-15 20:52:28 +01:00