Commit graph

291 commits

Author SHA1 Message Date
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
Daniel Mack 79bec997c9 Merge pull request #1484 from poettering/ask-pass-kernel-keyring
cache harddisk passwords in the kernel keyring
2015-10-07 15:32:42 +02:00
Michal Schmidt 7d06dad900 core: always let the kernel reap zombies when we're about to freeze
Regardless of whether we're going to spawn a crash shell or not, let the
kernel reap zombies. It's more consistent this way.
2015-10-07 14:25:51 +02:00
Michal Schmidt 4cf0b03b97 core: change how crash_shell and crash_reboot interact
Instead of freezing in PID1 and letting the forked child freeze or
reboot when exec("/bin/sh") fails, just wait for the child's
exit and then do the freeze_or_reboot in PID1 as usual.

This means that when both crash_shell and crash_reboot are enabled, the
system will reboot after the shell exits.
2015-10-07 14:24:49 +02:00
Michal Schmidt 647cb08bc3 core: remove spurious assert in parsing CrashChangeVT=
"data" is always NULL (and unused) in config_parse_crash_chvt().
2015-10-07 14:24:49 +02:00
Michal Schmidt f7cd3d5fcb core: adjust error message about /etc/mtab
Since having /etc/mtab as a regular file is now a fatal error, stop
mentioning irrelevant minor consequences.
2015-10-07 13:08:05 +02:00
Lennart Poettering e287086b8a ask-password: add support for caching passwords in the kernel keyring
This adds support for caching harddisk passwords in the kernel keyring
if it is available, thus supporting caching without Plymouth being
around.

This is also useful for hooking up "gdm-auto-login" with the collected
boot-time harddisk password, in order to support gnome keyring
passphrase unlocking via the HDD password, if it is the same.

Any passwords added to the kernel keyring this way have a timeout of
2.5min at which time they are purged from the kernel.
2015-10-07 12:26:14 +02:00
Lennart Poettering 618234a525 basic: split out cpu set specific APIs into cpu-set-util.[ch] 2015-09-30 22:26:16 +02:00
Lennart Poettering 765d143b5f util: rename parse_cpu_set() to parse_cpu_set_and_warn()
It's pretty untypical for our parsing functions to log on their own.
Clarify in the name that this one does.
2015-09-30 22:26:16 +02:00
Lennart Poettering 12ca818ffd tree-wide: clean up log_syntax() usage
- Rely everywhere that we use abs() on the error code passed in anyway,
  thus don't need to explicitly negate what we pass in

- Never attach synthetic error number information to log messages. Only
  log about errors we *receive* with the error number we got there,
  don't log any synthetic error, that don#t even propagate, but just eat
  up.

- Be more careful with attaching exactly the error we get, instead of
  errno or unrelated errors randomly.

- Fix one occasion where the error number and line number got swapped.

- Make sure we never tape over OOM issues, or inability to resolve
  specifiers
2015-09-30 22:26:16 +02:00
Lennart Poettering b9e74c3994 core: rework crash handling
This introduces a new systemd.crash_reboot=1 kernel command line option
that triggers a reboot after crashing.

This also cleans up crash VT handling. Specifically, it cleans up the
configuration setting, to be between 1..63 or a boolean. This is to
replace the previous logic where "-1" meant disabled. We continue to
accept that setting, but only document the boolean syntax instead.

This also brings the documentation of the default settings in sync with
what actually happens.

The CrashChVT= configuration file setting is renamed to CrashChangeVT=,
following our usual logic of not abbreviating unnecessarily. The old
setting stays support for compat reasons.

Fixes #1300
2015-09-29 21:55:51 +02:00
Lennart Poettering 97792515b4 core: properly use the ExitCode bus property when exiting is --user instance 2015-09-29 21:55:51 +02:00
Lennart Poettering 3f6fd1ba65 util: introduce common version() implementation and use it everywhere
This also allows us to drop build.h from a ton of files, hence do so.
Since we touched the #includes of those files, let's order them properly
according to CODING_STYLE.
2015-09-29 21:08:37 +02:00
Lennart Poettering 189d5bac5c util: unify implementation of NOP signal handler
This is highly complex code after all, we really should make sure to
only keep one implementation of this extremely difficult function
around.
2015-09-29 21:08:37 +02:00
Lennart Poettering e6e242ad2d core: remove set_default_unit()
The new free_and_strdup() call does pretty much the same thing these
days, no need to keep a private limited purpose version around.
2015-09-29 21:08:37 +02:00
Lennart Poettering 48b9085914 core: modernize prepare_reexecute() 2015-09-29 21:08:37 +02:00
Lennart Poettering aa8aeac050 core: exit early if we hit OOM 2015-09-29 21:08:37 +02:00
Lennart Poettering d1cefe0ae2 core: use %m rather than strerror() where we can 2015-09-29 21:08:37 +02:00
Lennart Poettering 92ca4cac43 main: minor clean-ups
Add (void) casting for a couple of functions where we knowingly ignore
the returning error code.

Use EXIT_FAILURE where appropriate.

Try to initialize structures at declaration time, or at once.
2015-09-29 21:08:37 +02:00
Lennart Poettering 2feceb5eb9 tree-wide: take benefit of the fact that fdset_free() returns NULL 2015-09-29 21:08:37 +02:00
Lennart Poettering 3dfc97634e core: order #includes in main.c 2015-09-29 21:08:37 +02:00
Lennart Poettering fe382237ca strv: add strv_free_free() to strv.c and make use of it
Let's teach it a new trick, and make it return NULL.
2015-09-29 21:08:37 +02:00
Filipe Brandenburger f5c72b739e util: refactor cpu_set parsing into its own function
Use the new code in config_parse_cpu_affinity2.

Tested by modifying CPUAffinity=... setting in /etc/systemd/system.conf
and reloading the daemon, then checking ^Cpus_allowed in /proc/1/status
to confirm the correct CPU mask is in place.
2015-09-24 18:01:36 -07:00
David Herrmann 8ebfe0cbaa core: fix shutdown of --user
Shutting down a user session currently fails with:

Sep 22 22:35:38 david-t2 systemd[640]: Reached target Shutdown.
Sep 22 22:35:38 david-t2 systemd[640]: Starting Exit the Session...
Sep 22 22:35:38 david-t2 systemd[640]: Received SIGRTMIN+24 from PID 659 (kill).
Sep 22 22:35:38 david-t2 systemd[640]: Shutting down.
Sep 22 22:35:38 david-t2 systemd[640]: Not executed by init (PID 1).
Sep 22 22:35:38 david-t2 systemd[640]: Critical error while doing system shutdown: Operation not permitted

This is a regression from:

    commit 287419c119
    Author: Alban Crequy <alban.crequy@gmail.com>
    Date:   Fri Sep 18 13:37:34 2015 +0200

        containers: systemd exits with non-zero code

Make sure we never ever execute systemd-shutdown from within a
user-manager. Restore the previous behavior by partially reverting given
commit.
2015-09-22 22:56:01 +02:00
Lennart Poettering 1fc464f6fb cgtop: underline table header
Let's underline the header line of the table shown by cgtop, how it is
customary for tables. In order to do this, let's introduce new ANSI
underline macros, and clean up the existing ones as side effect.
2015-09-22 16:30:42 +02:00
Alban Crequy 287419c119 containers: systemd exits with non-zero code
When a systemd service running in a container exits with a non-zero
code, it can be useful to terminate the container immediately and get
the exit code back to the host, when systemd-nspawn returns. This was
not possible to do. This patch adds the following to make it possible:

- Add a read-only "ExitCode" property on PID 1's "Manager" bus object.
  By default, it is 0 so the behaviour stays the same as previously.
- Add a method "SetExitCode" on the same object. The method fails when
  called on baremetal: it is only allowed in containers or in user
  session.
- Add support in systemctl to call "systemctl exit 42". It reuses the
  existing code for user session.
- Add exit.target and systemd-exit.service to the system instance.
- Change main() to actually call systemd-shutdown to exit() with the
  correct value.
- Add verb 'exit' in systemd-shutdown with parameter --exit-code
- Update systemctl manpage.

I used the following to test it:

| $ sudo rkt --debug --insecure-skip-verify run \
|            --mds-register=false --local docker://busybox \
|            --exec=/bin/chroot -- /proc/1/root \
|            systemctl --force exit 42
| ...
| Container rkt-895a0cba-5c66-4fa5-831c-e3f8ddc5810d failed with error code 42.
| $ echo $?
| 42

Fixes https://github.com/systemd/systemd/issues/1290
2015-09-21 17:32:45 +02:00
Lennart Poettering 03a7b521e3 core: add support for the "pids" cgroup controller
This adds support for the new "pids" cgroup controller of 4.3 kernels.
It allows accounting the number of tasks in a cgroup and enforcing
limits on it.

This adds two new setting TasksAccounting= and TasksMax= to each unit,
as well as a gloabl option DefaultTasksAccounting=.

This also updated "cgtop" to optionally make use of the new
kernel-provided accounting.

systemctl has been updated to show the number of tasks for each service
if it is available.

This patch also adds correct support for undoing memory limits for units
using a MemoryLimit=infinity syntax. We do the same for TasksMax= now
and hence keep things in sync here.
2015-09-10 18:41:06 +02:00
Lennart Poettering 525d3cc746 tree-wide: take benefit of the fact that hashmap_free() returns NULL
And set_free() too.

Another Coccinelle patch.
2015-09-09 23:12:07 +02:00
Daniel Mack 01da201420 Merge pull request #1218 from poettering/safe-fclose
util: introduce safe_fclose() and port everything over to it
2015-09-09 15:45:03 +02:00
Lennart Poettering 74ca738f6a util: introduce safe_fclose() and port everything over to it
Adds a coccinelle script to port things over automatically.
2015-09-09 15:26:11 +02:00
Daniel Mack d7acddde05 Merge pull request #1216 from poettering/coccinelle-fixes-2
Coccinelle fixes 2
2015-09-09 15:12:28 +02:00
Lennart Poettering 1f6b411372 tree-wide: update empty-if coccinelle script to cover empty-while and more
Let's also clean up single-line while and for blocks.
2015-09-09 14:59:51 +02:00
Daniel Mack bcce71873b core: freeze execution if /etc/mtab exists
The mount monitor that was added to libmount v2.27 requires /etc/mtab to be
non-existant. As systemd now uses that functionality, we cannot monitor any
mounts anymore, and hence not support .mount units.

Systems that have /etc/mtab around as regular file are unsupported by
systemd since a long time.

This patch makes that condition fatal, so we do not boot up with
non-working mount monitor support.
2015-09-09 14:00:23 +02:00
Lennart Poettering ece174c543 tree-wide: drop {} from one-line if blocks
Patch via coccinelle.
2015-09-09 08:20:20 +02:00
Lennart Poettering a1e58e8ee1 tree-wide: use coccinelle to patch a lot of code to use mfree()
This replaces this:

        free(p);
        p = NULL;

by this:

        p = mfree(p);

Change generated using coccinelle. Semantic patch is added to the
sources.
2015-09-09 08:19:27 +02:00
Lennart Poettering 75f86906c5 basic: rework virtualization detection API
Introduce a proper enum, and don't pass around string ids anymore. This
simplifies things quite a bit, and makes virtualization detection more
similar to architecture detection.
2015-09-07 13:42:47 +02:00
Lennart Poettering b85ec419cb Merge pull request #1098 from filbranden/cpuaffinity2
Getting rid of FOREACH_WORD_QUOTED and some more cleanup in config_parse_cpu_affinity2
2015-09-01 20:52:52 +02:00
Filipe Brandenburger 5cc623e644 core: Log parse errors in config_parse_cpu_affinity2 2015-09-01 11:10:09 -07:00
Tom Gundersen fc94c32605 Merge pull request #1111 from poettering/more-cgroup-fixes
More cgroup fixes
2015-09-01 19:48:04 +02:00
Lennart Poettering e155a0aa04 cgroup: small cleanups and coding style fixes
A number of simplications and adjustments to brings things closer to our
coding style.
2015-09-01 18:37:01 +02:00
Filipe Brandenburger 1592ec21b3 core: add OOM check in config_parse_join_controllers 2015-09-01 08:35:54 -07:00
Filipe Brandenburger 3875c85bae core: Log parse errors in config_parse_join_controllers 2015-09-01 08:35:54 -07:00
Filipe Brandenburger d4ebeb4fb3 core: Use extract_first_word in config_parse_join_controllers
Related to the TODO item to replace FOREACH_WORD_QUOTED with it.

Tested by setting `JoinControllers=cpu,cpuacct,memory net_cls,blkio' in
/etc/systemd/system.conf, rebooting the system with the patched binaries
and checking that the desired setup was created by inspecting the
entries under /sys/fs/cgroup.

No regressions observed in test cases.
2015-08-31 17:33:35 -07:00
Filipe Brandenburger 4b40bc38b4 util: Declare a cleanup routine for a cpu_set_t
Make use of it in config_parse_cpu_affinity2.

Tested by tweaking the `CPUAffinity' setting in /etc/systemd/system.conf
and reloading the daemon to confirm it is working as expected.

No regressions observed in test cases.
2015-08-31 17:15:56 -07:00
Filipe Brandenburger 4457c2279e core: Use extract_first_word in config_parse_cpu_affinity2
Related to the TODO item to replace FOREACH_WORD_QUOTED with it.

Tested by setting `CPUAfinity=0 1' (and other similar settings) in
/etc/systemd/system.conf, booting the system with the patched binaries
(and also using `systemctl daemon-reload` to reconfigure) and checking
that /proc/1/status indicates only CPUs 0 and 1 are allowed for PID 1.

No regressions observed in test cases.
2015-08-31 17:15:56 -07:00
Lennart Poettering 6513d561ce core: use DUAL_TIMESTAMP_NULL where we can 2015-08-31 13:20:43 +02:00
Jan Pokorný 6b9af96321
core: s/reexection/reexecution/ typo fix
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2015-08-07 17:13:15 +02:00
David Herrmann 97b11eedff tree-wide: introduce mfree()
Pretty trivial helper which wraps free() but returns NULL, so we can
simplify this:
        free(foobar);
        foobar = NULL;
to this:
        foobar = mfree(foobar);
2015-07-31 19:56:38 +02:00
Thomas Blume 06af2a04fb Reload manager defaults at daemon-reload
"systemctl daemon-reload" should also update the manager defaults from
/etc/systemd/system.conf.
For details, see:
http://lists.freedesktop.org/archives/systemd-devel/2015-June/033062.html

Amended to use  manager_set_defaults() as common function.
2015-07-09 10:22:30 +02:00
Daniel Mack 4c1fc3e404 fileio: consolidate write_string_file*()
Merge write_string_file(), write_string_file_no_create() and
write_string_file_atomic() into write_string_file() and provide a flags mask
that allows combinations of atomic writing, newline appending and automatic
file creation. Change all users accordingly.
2015-07-06 19:19:25 -04:00