Commit Graph

407 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Lennart Poettering fb3ae275cb main: bump RLIMIT_NOFILE for the root user substantially
On current kernels BPF_MAP_TYPE_LPM_TRIE bpf maps are charged against
RLIMIT_MEMLOCK even for privileged users that have CAP_IPC_LOCK. Given
that mlock() generally ignores RLIMIT_MEMLOCK if CAP_IPC_LOCK is set
this appears to be an oversight in the kernel. Either way, until that's
fixed, let's just bump RLIMIT_MEMLOCK for the root user considerably, as
the default is quite limiting, and doesn't permit us to create more than
a few TRIE maps.
2017-09-22 15:28:05 +02:00
Daniel Mack 377bfd2d49 manager: hook up IP accounting defaults 2017-09-22 15:24:55 +02:00
Zbigniew Jędrzejewski-Szmek e0a3da1fd2 Make test_run into a flags field and disable generators again
Now generators are only run in systemd --test mode, where this makes
most sense (how are you going to test what would happen otherwise?).

Fixes #6842.

v2:
- rename test_run to test_run_flags
2017-09-19 20:14:05 +02:00
Lennart Poettering dea374e898 main: skip many initialization steps when running in --test mode
Most importantly, don't collect open socket activation fds when in
--test mode. This specifically created a problem because we invoke
pager_open() beforehand (which these days makes copies of the original
stdout/stderr in order to be able to restore them when the pager goes
away) and we might mistakenly the fd copies it creates as socket
activation fds.

Fixes: #6383
2017-09-13 10:37:52 +02:00
Luca Bruno 28dd66ecfc core: evaluate presets after generators have run (#6526)
This commit moves the first-boot system preset-settings evaluation out
of main and into the manager startup logic itself. Notably, it reverses
the order between generators and presets evaluation, so that any changes
performed by first-boot generators are taken into the account by presets
logic.

After this change, units created by a generator can be enabled as part
of a preset.
2017-08-06 09:24:24 -04:00
Zbigniew Jędrzejewski-Szmek a132bef023 Drop kdbus bits
Some kdbus_flag and memfd related parts are left behind, because they
are entangled with the "legacy" dbus support.

test-bus-benchmark is switched to "manual". It was already broken before
(in the non-kdbus mode) but apparently nobody noticed. Hopefully it can
be fixed later.
2017-07-23 12:01:54 -04:00
Lennart Poettering df0ff12775 tree-wide: make use of getpid_cached() wherever we can
This moves pretty much all uses of getpid() over to getpid_raw(). I
didn't specifically check whether the optimization is worth it for each
replacement, but in order to keep things simple and systematic I
switched over everything at once.
2017-07-20 20:27:24 +02:00
IPv4v6 cb4069d95e add version argument to help function (#6377)
Signed-off-by: Stefan Pietsch <mail.ipv4v6+gh@gmail.com>
2017-07-15 13:53:21 +02:00
Lennart Poettering 0d787d5ff8 Only drop the capabilities from the bounding set if we are running as PID1 (#6204)
The CapabilityBoundingSet option only makes sense if we are running as
PID1.

The system.conf.d(5) manpage, already states that the CapabilityBoundingSet
option:
  Controls which capabilities to include in the capability bounding set
  for PID 1 and its children.

https://github.com/systemd/systemd/issues/6080
2017-06-28 13:29:45 -04:00
Zbigniew Jędrzejewski-Szmek 25f027c5ef tree-wide: when %m is used in log_*, always specify errno explicitly
All those uses were correct, but I think it's better to be explicit.
Using implicit errno is too error prone, and with this change we can require
(in the sense of a style guideline) that the code is always specified.

Helpful query: git grep -n -P 'log_[^s][a-z]+\(.*%m'
2017-05-19 14:24:03 -04:00
Christian Brauner 6385cb31ef main: improve RLIMIT_NOFILE handling (#5795)
This has systemd look at /proc/sys/fs/nr_open to find the current maximum of
open files compiled into the kernel and tries to set the RLIMIT_NOFILE max to
it. This has the advantage the value chosen as limit is less arbitrary and also
improves the behavior of systemd in containers that have an rlimit set: When
systemd currently starts in a container that has RLIMIT_NOFILE set to e.g.
100000 systemd will lower it to 65536. With this patch systemd will try to set
the nofile limit to the allowed kernel maximum. If this fails, it will compute
the minimum of the current set value (the limit that is set on the container)
and the maximum value as soft limit and the currently set maximum value as the
maximum value. This way it retains the limit set on the container.
2017-04-26 07:18:10 +03:00
Lennart Poettering 48a601fe5d log: never log into foreign fd #2 in PID 1 or its pre-execve() children
Fixes: #5401
2017-02-21 21:55:43 +01:00
Zbigniew Jędrzejewski-Szmek 58f88d929f manager: fix handling of failure in initialization
We would warn and continue after failure in manager_startup, but there's no
way we can continue. We must fail.
2017-02-11 18:21:06 -05:00
Zbigniew Jędrzejewski-Szmek 5b3637b44a Merge pull request #4991 from poettering/seccomp-fix 2017-01-17 23:10:46 -05:00
Lennart Poettering 469830d142 seccomp: rework seccomp code, to improve compat with some archs
This substantially reworks the seccomp code, to ensure better
compatibility with some architectures, including i386.

So far we relied on libseccomp's internal handling of the multiple
syscall ABIs supported on Linux. This is problematic however, as it does
not define clear semantics if an ABI is not able to support specific
seccomp rules we install.

This rework hence changes a couple of things:

- We no longer use seccomp_rule_add(), but only
  seccomp_rule_add_exact(), and fail the installation of a filter if the
  architecture doesn't support it.

- We no longer rely on adding multiple syscall architectures to a single filter,
  but instead install a separate filter for each syscall architecture
  supported. This way, we can install a strict filter for x86-64, while
  permitting a less strict filter for i386.

- All high-level filter additions are now moved from execute.c to
  seccomp-util.c, so that we can test them independently of the service
  execution logic.

- Tests have been added for all types of our seccomp filters.

- SystemCallFilters= and SystemCallArchitectures= are now implemented in
  independent filters and installation logic, as they semantically are
  very much independent of each other.

Fixes: #4575
2017-01-17 22:14:27 -05:00
Lennart Poettering 1d84ad9445 util-lib: various improvements to kernel command line parsing
This improves kernel command line parsing in a number of ways:

a) An kernel option "foo_bar=xyz" is now considered equivalent to
   "foo-bar-xyz", i.e. when comparing kernel command line option names "-" and
   "_" are now considered equivalent (this only applies to the option names
   though, not the option values!). Most of our kernel options used "-" as word
   separator in kernel command line options so far, but some used "_". With
   this change, which was a source of confusion for users (well, at least of
   one user: myself, I just couldn't remember that it's systemd.debug-shell,
   not systemd.debug_shell). Considering both as equivalent is inspired how
   modern kernel module loading normalizes all kernel module names to use
   underscores now too.

b) All options previously using a dash for separating words in kernel command
   line options now use an underscore instead, in all documentation and in
   code. Since a) has been implemented this should not create any compatibility
   problems, but normalizes our documentation and our code.

c) All kernel command line options which take booleans (or are boolean-like)
   have been reworked so that "foobar" (without argument) is now equivalent to
   "foobar=1" (but not "foobar=0"), thus normalizing the handling of our
   boolean arguments. Specifically this means systemd.debug-shell and
   systemd_debug_shell=1 are now entirely equivalent.

d) All kernel command line options which take an argument, and where no
   argument is specified will now result in a log message. e.g. passing just
   "systemd.unit" will no result in a complain that it needs an argument. This
   is implemented in the proc_cmdline_missing_value() function.

e) There's now a call proc_cmdline_get_bool() similar to proc_cmdline_get_key()
   that parses booleans (following the logic explained in c).

f) The proc_cmdline_parse() call's boolean argument has been replaced by a new
   flags argument that takes a common set of bits with proc_cmdline_get_key().

g) All kernel command line APIs now begin with the same "proc_cmdline_" prefix.

h) There are now tests for much of this. Yay!
2016-12-21 19:09:08 +01:00
Lennart Poettering eee8b7ab2e core: minor coding style/wording fixes 2016-12-20 20:00:08 +01:00
Zbigniew Jędrzejewski-Szmek eb56bec413 core: remove spurious newline 2016-12-17 17:26:59 -05:00
Franck Bui 7d5ceb6416 core: allow to redirect confirmation messages to a different console
It's rather hard to parse the confirmation messages (enabled with
systemd.confirm_spawn=true) amongst the status messages and the kernel
ones (if enabled).

This patch gives the possibility to the user to redirect the confirmation
message to a different virtual console, either by giving its name or its path,
so those messages are separated from the other ones and easier to read.
2016-11-17 18:16:16 +01:00
Zbigniew Jędrzejewski-Szmek a809cee582 Merge pull request #4612 from keszybz/format-strings
Format string tweaks (and a small fix on 32bit)
2016-11-08 08:09:40 -05: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
Zbigniew Jędrzejewski-Szmek 9a82ab9592 tree-wide: drop unneded WHITESPACE param to extract_first_word
It's the default, and NULL is shorter.
2016-11-05 15:35:51 -04:00
Lennart Poettering 229ba9fd57 Merge pull request #4459 from keszybz/commandline-parsing
Commandline parsing simplification and udev fix
2016-10-24 17:20:37 +02:00
Jan Synacek b3796dd834 install: introduce UnitFileFlags
Introduce a new enum to get rid of some boolean arguments of unit_file_*
functions. It unifies the code, makes it a bit cleaner and extensible.
2016-10-24 10:19:08 +02:00
Zbigniew Jędrzejewski-Szmek d7f69e16f1 tree-wide: make parse_proc_cmdline() strip "rd." prefix automatically
This stripping is contolled by a new boolean parameter. When the parameter
is true, it means that the caller does not care about the distinction between
initrd and real root, and wants to act on both rd-dot-prefixed and unprefixed
parameters in the initramfs, and only on the unprefixed parameters in real
root. If the parameter is false, behaviour is the same as before.

Changes by caller:
log.c (systemd.log_*):      changed to accept rd-dot-prefix params
pid1:                       no change, custom logic
cryptsetup-generator:       no change, still accepts rd-dot-prefix params
debug-generator:            no change, does not accept rd-dot-prefix params
fsck:                       changed to accept rd-dot-prefix params
fstab-generator:            no change, custom logic
gpt-auto-generator:         no change, custom logic
hibernate-resume-generator: no change, does not accept rd-dot-prefix params
journald:                   changed to accept rd-dot-prefix params
modules-load:               no change, still accepts rd-dot-prefix params
quote-check:                no change, does not accept rd-dot-prefix params
udevd:                      no change, still accepts rd-dot-prefix params

I added support for "rd." params in the three cases where I think it's
useful: logging, fsck options, journald forwarding options.
2016-10-22 16:08:55 -04:00
Zbigniew Jędrzejewski-Szmek 96287a4916 tree-wide: allow state to be passed through to parse_proc_cmdline_item
No functional change.
2016-10-22 14:24:52 -04:00
Lukas Nykryn ae8c7939df core: use emergency_action for ctr+alt+del burst
Fixes #4306
2016-10-21 15:13:50 +02:00
Zbigniew Jędrzejewski-Szmek 3ce40911bd pid1: downgrade some rlimit warnings
Since we ignore the result anyway, downgrade errors to warning.

log_oom() will still emit an error, but that's mostly theoretical, so it
is not worth complicating the code to avoid the small inconsistency
2016-10-19 22:17:16 -04:00
0xAX 74e7579c17 core/main: get rid from excess check of ACTION_TEST (#4350)
If `--test` command line option was passed, the systemd set skip_setup
to true during bootup. But after this we check again that arg_action is
test or help and opens pager depends on result.

We should skip setup in a case when `--test` is passed, but it is also
safe to set skip_setup in a case of `--help`. So let's remove first
check and move skip_setup = true to the second check.
2016-10-11 17:30:04 -04:00
Zbigniew Jędrzejewski-Szmek ec72b96366 Merge pull request #4337 from poettering/exit-code
Fix for #4275 and more
2016-10-10 21:24:57 -04:00
Lennart Poettering 38107f5a4a core: lower exit status "level" at one place
When we print information about PID 1's crashdump subprocess failing. In this
case we *know* that we do not generate LSB exit codes, as it's basically PID 1
itself that exited there.
2016-10-10 22:56:55 +02:00
0xAX f6dd106c73 main: use strdup instead of free_and_strdup to initialize default unit (#4335)
Previously we've used free_and_strdup() to fill arg_default_unit with unit
name, If we didn't pass default unit name through a kernel command line or
command line arguments. But we can use just strdup() instead of
free_and_strdup() for this, because we will start fill arg_default_unit
only if it wasn't set before.
2016-10-10 22:11:36 +02:00
0xAX c76cf844d6 tree-wide: pass return value of make_null_stdio() to warning instead of errno (#4328)
as @poettering suggested in the #4320
2016-10-10 19:51:33 +02:00
0xAX 10c961b9c9 main: initialize default unit little later (#4321)
systemd fills arg_default_unit during startup with default.target
value. But arg_default_unit may be overwritten in parse_argv() or
parse_proc_cmdline_item().

Let's check value of arg_default_unit after calls of parse_argv()
and parse_proc_cmdline_item() and fill it with default.target if
it wasn't filled before. In this way we will not spend unnecessary
time to for filling arg_default_unit with default.target.
2016-10-09 22:57:03 -04:00
0xAX 9fc932bff1 tree-wide: print warning in a failure case of make_null_stdio() (#4320)
The make_null_stdio() may fail. Let's check its result and print
warning message instead of keeping silence.
2016-10-09 22:55:24 -04:00
Lukáš Nykrýn 24dd31c19e core: add possibility to set action for ctrl-alt-del burst (#4105)
For some certification, it should not be possible to reboot the machine through ctrl-alt-delete. Currently we suggest our customers to mask the ctrl-alt-delete target, but that is obviously not enough.

Patching the keymaps to disable that is really not a way to go for them, because the settings need to be easily checked by some SCAP tools.
2016-10-06 21:08:21 -04:00
Lennart Poettering 54500613a4 main: minor simplification 2016-09-25 10:52:57 +02:00
Zbigniew Jędrzejewski-Szmek 43688c49d1 tree-wide: rename config_parse_many to …_nulstr
In preparation for adding a version which takes a strv.
2016-09-16 10:32:03 -04:00
Felipe Sateler 83f12b27d1 core: do not fail at step SECCOMP if there is no kernel support (#4004)
Fixes #3882
2016-08-22 22:40:58 +03:00
Lennart Poettering 16d901e251 Merge pull request #3987 from keszybz/console-color-setup
Rework console color setup
2016-08-19 19:36:09 +02:00
Tejun Heo f50582649f logind: update empty and "infinity" handling for [User]TasksMax (#3835)
The parsing functions for [User]TasksMax were inconsistent.  Empty string and
"infinity" were interpreted as no limit for TasksMax but not accepted for
UserTasksMax.  Update them so that they're consistent with other knobs.

* Empty string indicates the default value.
* "infinity" indicates no limit.

While at it, replace opencoded (uint64_t) -1 with CGROUP_LIMIT_MAX in TasksMax
handling.

v2: Update empty string to indicate the default value as suggested by Zbigniew
    Jędrzejewski-Szmek.

v3: Fixed empty UserTasksMax handling.
2016-08-18 22:57:53 -04:00
Zbigniew Jędrzejewski-Szmek bd64d82c1c Revert "pid1: reconnect to the console before being re-executed"
This reverts commit affd7ed1a9.

> So it looks like make_console_stdio() has bad side effect. More specifically it
> does a TIOCSCTTY ioctl (via acquire_terminal()) which sees to disturb the
> process which was using/owning the console.

Fixes #3842.
https://bugs.debian.org/834367
https://bugzilla.redhat.com/show_bug.cgi?id=1367766
2016-08-18 22:30:15 -04:00
Zbigniew Jędrzejewski-Szmek 206fc4b284 systemd: warn when setrlimit fails
This should make it easier to figure things out.
2016-08-18 22:29:56 -04:00
0xAX 13811bf909 main: use pager for --dump-configuration-items (#3894) 2016-08-04 22:52:24 +02:00
Lennart Poettering 6af760f3b2 core: inherit TERM from PID 1 for all services started on /dev/console
This way, invoking nspawn from a shell in the best case inherits the TERM
setting all the way down into the login shell spawned in the container.

Fixes: #3697
2016-08-03 14:52:16 +02:00
Ismo Puustinen 96694e998b main: load Smack policy before IMA policy (#3859)
IMA wiki says: "If the IMA policy contains LSM labels, then the LSM
policy must be loaded prior to the IMA policy." Right now, in case of
Smack, the IMA policy is loaded before the Smack policy. Move the order
around to allow Smack labels to be used in IMA policy.
2016-08-02 08:58:30 -04:00
0xAX 494294d6f8 main: get rid of ACTION_DONE (#3849)
the ACTION_DONE was introduced in the 4288f61921 (dbus: automatically
generate and install introspection files ) commit and was used in
systemd --introspect command.

Later 'introspect' command was removed in the ca2871d9b (bus: remove
static introspection file export) commit and have no users anymore.

So we can remove it.
2016-08-01 12:38:25 +02:00
Zbigniew Jędrzejewski-Szmek 31b14fdb6f Merge pull request #3777 from poettering/id128-rework
uuid/id128 code rework
2016-07-22 21:18:41 -04:00
Lennart Poettering 79baeeb96d core: change TasksMax= default for system services to 15%
As it turns out 512 is max number of tasks per service is hit by too many
applications, hence let's bump it a bit, and make it relative to the system's
maximum number of PIDs. With this change the new default is 15%. At the
kernel's default pids_max value of 32768 this translates to 4915. At machined's
default TasksMax= setting of 16384 this translates to 2457.

Why 15%? Because it sounds like a round number and is close enough to 4096
which I was going for, i.e. an eight-fold increase over the old 512

Summary:

            | on the host | in a container
old default |         512 |           512
new default |        4915 |          2457
2016-07-22 15:33:13 +02:00