Commit graph

17986 commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek a6c97fc460 Drop bus-policy bits 2017-07-23 09:29:02 -04:00
Zbigniew Jędrzejewski-Szmek 4bc5d27b94 Drop busname unit type
Since busname units are only useful with kdbus, they weren't actively
used. This was dead code, only compile-tested. If busname units are
ever added back, it'll be cleaner to start from scratch (possibly reverting
parts of this patch).
2017-07-23 09:29:02 -04:00
Zbigniew Jędrzejewski-Szmek 924775e8ce core: when logging about dependency cycles, add UNIT= entries for all involved units
Example log:
Jul 22 15:55:21 fedora systemd[1]: a1.service: Found ordering cycle on a2.service/start
Jul 22 15:55:21 fedora systemd[1]: a1.service: Found dependency on a3.service/start
Jul 22 15:55:21 fedora systemd[1]: a1.service: Found dependency on a1.service/start
Jul 22 15:55:21 fedora systemd[1]: a1.service: Job a2.service/start deleted to break ordering cycle starting with a1.service/start
Jul 22 15:55:21 fedora systemd[1]: Starting a1.service...
Jul 22 15:55:21 fedora systemd[1]: Started a1.service.

Example log entry:

Sat 2017-07-22 15:55:21.372389 EDT [s=0004bb6302d94ac3aa69987fb6157338;i=9ae;b=a96eb6153d4f4f3686c7b4
    _BOOT_ID=a96eb6153d4f4f3686c7b4db8a432908
    _MACHINE_ID=ad18f69b80264b52bb3b766240742383
    _HOSTNAME=fedora
    PRIORITY=3
    SYSLOG_FACILITY=3
    SYSLOG_IDENTIFIER=systemd
    _UID=0
    _GID=0
    _PID=1
    _TRANSPORT=journal
    _CAP_EFFECTIVE=3fffffffff
    _COMM=systemd
    _EXE=/usr/lib/systemd/systemd
    _SYSTEMD_CGROUP=/init.scope
    _SYSTEMD_UNIT=init.scope
    _SYSTEMD_SLICE=-.slice
    _SELINUX_CONTEXT=system_u:system_r:kernel_t:s0
    CODE_FILE=../src/core/transaction.c
    CODE_FUNC=transaction_verify_order_one
    UNIT=a3.service
    UNIT=a1.service
    UNIT=a2.service
    CODE_LINE=430
    MESSAGE=a1.service: Job a2.service/start deleted to break ordering cycle starting with a1.service
    _CMDLINE=/usr/lib/systemd/systemd --system --deserialize 28
    _SOURCE_REALTIME_TIMESTAMP=1500753321372389

This should make it easier to see when any of the units are involved in an
ordering cycle.

Fixes #6336.

v2:
- also update the "Unable to break cycle" message.
2017-07-22 18:57:16 -04:00
Zbigniew Jędrzejewski-Szmek 3f6de63bf7 shared/dropin: improve error message
We're not just sorting, but actually creating the list. We can
also use the output parameter directly, without a temporary variable.
2017-07-22 16:03:00 -04:00
Zbigniew Jędrzejewski-Szmek 9e4ea9cc34 Revert "core: don't load dropin data multiple times for the same unit (#5139)"
This reverts commit 2d058a87ff.

When we add another name to a unit (by following an alias), we need to
reload all drop-ins. This is necessary to load any additional dropins
found in the dirs created from the alias name.

Fixes #6334.
2017-07-22 16:03:00 -04:00
Zbigniew Jędrzejewski-Szmek 0926f3489d resolved: make sure idn2 conversions are roundtrippable
While working on the gateway→_gateway conversion, I noticed that
libidn2 strips the leading underscore in some names.
https://gitlab.com/libidn/libidn2/issues/30 was resolved in
05d753ea69,
which disabled "STD3 ASCII rules" by default, i.e. disabled stripping
of underscores. So the situation is that with previously released libidn2
versions we would get incorrect behaviour, and once new libidn2 is released,
we should be OK.

Let's implement a simple test which checks that the name survives the
roundtrip, and if it doesn't, skip IDN resolution. Under old libidn2 this will
fail in more cases, and under new libidn2 in fewer, but should be the right
thing to do also under new libidn2.
2017-07-21 08:00:23 -04:00
Yu Watanabe 8ae12e733c core: fix typo (#6417) 2017-07-21 10:36:39 +02:00
Lennart Poettering 4b61c87511 tree-wide: fput[cs]() → fput[cs]_unlocked() wherever that makes sense (#6396)
As a follow-up for db3f45e2d2 let's do the
same for all other cases where we create a FILE* with local scope and
know that no other threads hence can have access to it.

For most cases this shouldn't change much really, but this should speed
dbus introspection and calender time formatting up a bit.
2017-07-21 10:35:45 +02:00
Zbigniew Jędrzejewski-Szmek 52b1478414 Merge pull request #6413 from poettering/getpid
speed up getpid() again
2017-07-20 15:14:13 -04:00
Lennart Poettering 8cb5743079 nspawn: downgrade warning when we get sd_notify() message from unexpected process (#6416)
Given that we set NOTIFY_SOCKET unconditionally it's not surprising that
processes way down the process tree think it's smart to send us a
notification message.

It's still useful to keep this message, for debugging things, but it
shouldn't be generated by default.
2017-07-20 14:46:58 -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
Lennart Poettering 5c30a6d2b8 process-util: add getpid_cached() as a caching wrapper for getpid()
Let's make getpid() fast again.
2017-07-20 20:27:24 +02:00
Lennart Poettering f7a2b4213c Merge pull request #6266 from keszybz/drop-autotools
Drop support for autotools / automake / make
2017-07-20 19:56:07 +02:00
Harald Hoyer 98eda38aed call chase_symlinks without the /sysroot prefix (#6411)
In case fstab-generator is called in the initrd, chase_symlinks()
returns with a canonical path "/sysroot/sysroot/<mountpoint>", if the
"/sysroot" prefix is present in the path.

This patch skips the "/sysroot" prefix for the chase_symlinks() call,
because "/sysroot" is already the root directory and chase_symlinks()
prepends the root directory in the canonical path returned.
2017-07-20 13:13:09 -04:00
Lennart Poettering fccb44863b sd-path: make sure to use tmp_dir() and var_tmp_dir() (#6397)
Let's reuse the common code wherever appropriate.
2017-07-20 14:19:57 +02:00
Felipe Sateler 708d423915 test-condition: don't assume that all non-root users are normal users (#6409)
Automated builders may run under a dedicated system user, and this test would fail that

Fixes #6366
2017-07-19 20:48:23 -04:00
Daniel Berrange 5588612e9e virt: enable detecting QEMU (TCG) via CPUID (#6399)
QEMU >= 2.10 will include a CPUID leaf with value "TCGTCGTCGTCG"
on x86 when running with the TCG CPU emulator:

  https://lists.gnu.org/archive/html/qemu-devel/2017-07/msg05231.html

Existing methods of detecting QEMU are left unchanged for sake of
backcompatibility.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2017-07-19 11:06:07 +02:00
Yu Watanabe a04efff8a7 test-unit-name: setup fake runtime directory before starting manager (#6401)
Since 3536f49e8f, manager_new() in
user mode requires XDG_RUNTIME_DIR is set. So, in this commit,
setup_fake_runtime_directory() is added in the beginning of test.

Fixes an issue comment in #6384.
2017-07-18 20:26:09 +03:00
Yu Watanabe 35aba85a73 core/manager: fix memory leak (#6400)
This fixes the memory leak introduced by 3536f49e8f,
which forgot to free the prefixes in the manager.

Fixes #6398.
2017-07-18 17:30:52 +03:00
Zbigniew Jędrzejewski-Szmek 18b9ad1f61 build-sys: rename SD_BOOT_LOG_TPM to ENABLE_TPM
This makes it more like other configure defines.

Also, it fixes meson status output which was looking for HAVE_ and ENABLE_
prefixes only (the define under meson was OK, just the summary message was
wrong.)
2017-07-18 10:05:06 -04:00
Zbigniew Jędrzejewski-Szmek e5f752082e build-sys: drop gitignore patterns for in-tree builds
... and other autotools-generated files.
2017-07-18 10:05:06 -04:00
Zbigniew Jędrzejewski-Szmek 72cdb3e783 build-sys: drop automake support
v2:
- also mention m4
2017-07-18 10:04:44 -04:00
Yu Watanabe 3536f49e8f core: add {State,Cache,Log,Configuration}Directory= (#6384)
This introduces {State,Cache,Log,Configuration}Directory= those are
similar to RuntimeDirectory=. They create the directories under
/var/lib, /var/cache/, /var/log, or /etc, respectively, with the mode
specified in {State,Cache,Log,Configuration}DirectoryMode=.

This also fixes #6391.
2017-07-18 14:34:52 +02:00
Vito Caputo db3f45e2d2 basic: use _unlocked() stdio in strip_tab_ansi() (#6385)
Trivial performance boost by explicitly bypassing the implicit
locking of stdio.

This significantly affects common cases of `journalctl` usage:

 Before:

  # time ./journalctl -b -1 > /dev/null
   real    0m26.628s
   user    0m26.495s
   sys     0m0.125s

  # time ./journalctl -b -1 > /dev/null
   real    0m27.069s
   user    0m26.936s
   sys     0m0.134s

  # time ./journalctl -b -1 > /dev/null
   real    0m26.727s
   user    0m26.607s
   sys     0m0.119s

 After:

  # time ./journalctl -b -1 > /dev/null
   real    0m23.394s
   user    0m23.244s
   sys     0m0.142s

  # time ./journalctl -b -1 > /dev/null
   real    0m23.283s
   user    0m23.160s
   sys     0m0.121s

  # time ./journalctl -b -1 > /dev/null
   real    0m23.274s
   user    0m23.125s
   sys     0m0.144s

Fixes https://github.com/systemd/systemd/issues/6341
2017-07-18 00:05:52 +02:00
Lennart Poettering e758bc9132 Merge pull request #6387 from keszybz/fix-timeout-0
Fix x-systemd.timeout=0 in fstab
2017-07-18 00:04:24 +02:00
Zbigniew Jędrzejewski-Szmek 4a06cbf838 Use config_parse_sec_fix_0() also for JobRunningTimeoutSec
2d79a0bbb9 did that for TimeoutSec=,
89beff89ed did that for JobTimeoutSec=,
and 0004f698df did that for
x-systemd.device-timeout=. But after parsing x-systemd.device-timeout=xxx
we write it out as JobRunningTimeoutSec=xxx. Two options:
- write out JobRunningTimeoutSec=<a very big number>,
- change JobRunningTimeoutSec= to behave like the other options.

I think it would be confusing for JobRunningTimeoutSec= to have different
syntax then TimeoutSec= and JobTimeoutSec=, so this patch implements the
second option.

Fixes #6264, https://bugzilla.redhat.com/show_bug.cgi?id=1462378.
2017-07-17 16:03:49 -04:00
Lennart Poettering 688230d3a7 Merge pull request #6354 from walyong/smack_process_label_free
core: modify resource leak and missed security context dump
2017-07-17 10:04:12 +02:00
Lennart Poettering ddf1819bc2 Merge pull request #6355 from vcaputo/journal_avoid_mmap_cache_get_calls
journal: avoid unnecessary mmap_cache_get() calls
2017-07-17 10:03:52 +02:00
NeilBrown c67bd1f758 fstab-generator: ignore x-systemd.device-timeout for non-devices (#6368)
If you specify "x-systemd.device-timeout" for an NFS mount
point, you get no warning and a meaningless device unit
dependency created.

Better to have a warning and no dependency.
2017-07-17 10:03:34 +02:00
Lennart Poettering 981778e212 Merge pull request #6324 from keszybz/generator-add-symlink
Add helper function for creation of unit symlinks in generators
2017-07-17 10:02:54 +02:00
Lennart Poettering 7398320f9a Merge pull request #6328 from yuwata/runtime-preserve
core: Allow preserving contents of RuntimeDirectory over process restart
2017-07-17 10:02:19 +02:00
Yu Watanabe 23a7448efa core: support subdirectories in RuntimeDirectory= option 2017-07-17 16:30:53 +09:00
Yu Watanabe 53f47dfc7b core: allow preserving contents of RuntimeDirectory= over process restart
This introduces RuntimeDirectoryPreserve= option which takes a boolean
argument or 'restart'.

Closes #6087.
2017-07-17 16:22:25 +09:00
Zbigniew Jędrzejewski-Szmek f60a865a49 test-seccomp: arm64 does not have access() and poll()
glibc uses faccessat and ppoll, so just add a filters for that.

(cherry picked from commit abc0213839fef92e2e2b98a434914f22ece48490)
2017-07-15 17:18:22 -04:00
Zbigniew Jędrzejewski-Szmek 79873bc850 seccomp: arm64 does not have mmap2
I messed up when adding the definitions in 4278d1f531.
Unfortunately I didn't have the hardware at hand and went by
looking at the kernel headers.

(cherry picked from commit 53196fafcb7b24b45ed4f48ab894d00a24a6d871)
2017-07-15 17:18:22 -04:00
Zbigniew Jędrzejewski-Szmek 2e64e8f46d seccomp: arm64/x32 do not have _sysctl
So don't even try to added the filter to reduce noise.
The test is updated to skip calling _sysctl because the kernel prints
an oops-like message that is confusing and unhelpful:

Jul 15 21:07:01 rpi3 kernel: test-seccomp[8448]: syscall -10080
Jul 15 21:07:01 rpi3 kernel: Code: aa0503e4 aa0603e5 aa0703e6 d4000001 (b13ffc1f)
Jul 15 21:07:01 rpi3 kernel: CPU: 3 PID: 8448 Comm: test-seccomp Tainted: G        W       4.11.8-300.fc26.aarch64 #1
Jul 15 21:07:01 rpi3 kernel: Hardware name: raspberrypi rpi/rpi, BIOS 2017.05 06/24/2017
Jul 15 21:07:01 rpi3 kernel: task: ffff80002bb0bb00 task.stack: ffff800036354000
Jul 15 21:07:01 rpi3 kernel: PC is at 0xffff8669c7c4
Jul 15 21:07:01 rpi3 kernel: LR is at 0xaaaac64b6750
Jul 15 21:07:01 rpi3 kernel: pc : [<0000ffff8669c7c4>] lr : [<0000aaaac64b6750>] pstate: 60000000
Jul 15 21:07:01 rpi3 kernel: sp : 0000ffffdc640fd0
Jul 15 21:07:01 rpi3 kernel: x29: 0000ffffdc640fd0 x28: 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x27: 0000000000000000 x26: 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x25: 0000000000000000 x24: 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x23: 0000000000000000 x22: 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x21: 0000aaaac64b4940 x20: 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x19: 0000aaaac64b88f8 x18: 0000000000000020
Jul 15 21:07:01 rpi3 kernel: x17: 0000ffff8669c7a0 x16: 0000aaaac64d2ee0
Jul 15 21:07:01 rpi3 kernel: x15: 0000000000000000 x14: 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x13: 203a657275746365 x12: 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x11: 0000ffffdc640418 x10: 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x9 : 0000000000000005 x8 : 00000000ffffd8a0
Jul 15 21:07:01 rpi3 kernel: x7 : 7f7f7f7f7f7f7f7f x6 : 7f7f7f7f7f7f7f7f
Jul 15 21:07:01 rpi3 kernel: x5 : 65736d68716f7277 x4 : 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x3 : 0000000000000008 x2 : 0000000000000000
Jul 15 21:07:01 rpi3 kernel: x1 : 0000000000000000 x0 : 0000000000000000
Jul 15 21:07:01 rpi3 kernel:

(cherry picked from commit 1e20e640132c700c23494bb9e2619afb83878380)
2017-07-15 17:18:22 -04:00
Zbigniew Jędrzejewski-Szmek e7854c46be shared/seccomp-util: add parentheses and no. after syscall name
"Failed to add rule for system call access, ignoring: Numerical argument out of domain"
is confusing. Make that "... system call access() / 238".

(cherry picked from commit 977dc6ca5acb8069a2966ec63e7378576bc2ca51)
2017-07-15 17:18:22 -04:00
Susant Sahani b2392ff31c journald: make reading /dev/kmsg optional (#6362)
Closes #6022
2017-07-15 13:57:52 +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
Tejun Heo 4095205ecc core: support "nsdelegate" cgroup v2 mount option (#6294)
cgroup namespace wasn't useful for delegation because it allowed resource
control interface files (e.g. memory.high) to be written from inside the
namespace - this allowed the namespace parent's resource distribution to be
disturbed by its namespace-scoped children.

A new mount option, "nsdelegate", was added to cgroup v2 to address this issue.
The flag is meangingful only when mounting cgroup v2 in the init namespace and
makes a cgroup namespace a delegation boundary.  The kernel feature is pending
for v4.13.

This should have been the default behavior on cgroup namespaces and this commit
makes systemd try "nsdelegate" first when trying to mount cgroup v2 and fall
back if the option is not supported.

Note that this has danger of breaking usages which depend on modifying the
parent's resource settings from the namespace root, which isn't a valid thing
to do, but such usages may still exist.
2017-07-14 19:27:13 +02:00
Vito Caputo 8c3d9662ed journal: elide fd matching from window_matches() (#6340)
Introduces window_matches_fd() for the fd matching case in try_context(),

In find_mmap() we're already walking a list of windows by fd, checking
this is pointless work in a potentially hot loop with many windows.
2017-07-14 19:26:01 +02:00
Vito Caputo c7884da9e4 journal: use context_attach_window() in add_mmap() (#6339)
Instead of context_detach_window() and a manual attach of the new
window, simply call context_attach_window() which performs the
detach first if appropriate.
2017-07-14 19:24:46 +02:00
Zbigniew Jędrzejewski-Szmek 7f0cc63771 sysv-generator: use generator_add_symlink()
generator_add_symlink() is extended to ignore EEXIST. This should be fine
for all existing callers.

There's a small difference in behaviour when adding symlinks in sysv-generator:
the message is more generic and does not include ", ignored". But creation of
symlinks shouldn't ever fail except if things are very wrong, so in practice
this shouldn't matter.

Test needed updating: os.path.exists(os.readlink(link)) only works if the link
is absolute (or if we are in the right directory). Let's just use
os.path.exists(link), which properly tests that the symlink target exists.
2017-07-13 18:56:36 -04:00
Zbigniew Jędrzejewski-Szmek f06dcdca6a test-daemon: sleep just a little bit by default
With previous commits, test-daemon is one of the slowest tests.
Under normal circumstances, the notifications go nowhere anyway,
because the test process does not have privileges.

The timeout can be specified as an argument. This is useful to
e.g. test handling of the notifications, which is much easier
with a longer timeout.
2017-07-13 17:55:02 -04:00
Zbigniew Jędrzejewski-Szmek 86d0608929 test-resolved-packet: skip most of the loop
We want to test the edge cases, but testing all the values in between
is mostly pointless and slow on slow architectures (>1s on rpi).
2017-07-13 17:55:02 -04:00
Zbigniew Jędrzejewski-Szmek da1e72f482 test-watchdog: wait just one cycle unless $SYSTEMD_SLOW_TESTS
Also, if we fail to set the watchdog, run through the rest of the test
without waiting. I think it's useful to still start the commands to
test the error paths, but we can do it quickly.
2017-07-13 17:54:59 -04:00
Zbigniew Jędrzejewski-Szmek 245d3d3c95 test-compress-benchmark: look at $SYSTEMD_SLOW_TESTS 2017-07-13 17:52:49 -04:00
Zbigniew Jędrzejewski-Szmek 3d14a30082 test-hashmap: use $SYSTEMD_SLOW_TESTS variable
test-hashmap is a very good test, but it gets in the way when one wants to
compile and quickly test changes.
2017-07-13 17:52:49 -04:00
Jeremy Bicha 303608c1bc escape: Fix help description (#6352)
Resolves: #6351
2017-07-13 16:44:33 +02:00
Vito Caputo b439282e0b journal: avoid unnecessary mmap_cache_get() calls
journal_file_move_to_object() can skip the second
journal_file_move_to() call if the first one already mapped a
sufficiently large area.

Now that mmap_cache_get() returns the size of the mapped area
when asked, ask for the size and only perform the second call if
the required size exceeds the mapped size instead of the object
header size.

This results in a nice performance boost in my testing, even with
a corpus of many small logs burning much CPU time elsewhere:

 Before:

  # time ./journalctl -b -1 --no-pager > /dev/null
  real    0m16.330s
  user    0m16.281s
  sys     0m0.046s

  # time ./journalctl -b -1 --no-pager > /dev/null
  real    0m16.409s
  user    0m16.358s
  sys     0m0.048s

  # time ./journalctl -b -1 --no-pager > /dev/null
  real    0m16.625s
  user    0m16.558s
  sys     0m0.061s

 After:

  # time ./journalctl -b -1 --no-pager > /dev/null
  real    0m15.311s
  user    0m15.257s
  sys     0m0.046s

  # time ./journalctl -b -1 --no-pager > /dev/null
  real    0m15.201s
  user    0m15.135s
  sys     0m0.062s

  # time ./journalctl -b -1 --no-pager > /dev/null
  real    0m15.170s
  user    0m15.113s
  sys     0m0.053s
2017-07-12 23:59:29 -07:00
Vito Caputo b42549ad69 journal: return mapped size from mmap_cache_get()
If requested, return the actual mapping size to the caller in
addition to the address.

journal_file_move_to_object() often performs two successive
mmap_cache_get() calls via journal_file_move_to(); one to get the
object header, then another to get the entire object when it's
larger than the header's size.

If mmap_cache_get() returned the actual mapping's size, it's
probable that the second mmap_cache_get() could be skipped when
the established mapping already encompassed the desired size.
2017-07-12 23:58:48 -07:00
WaLyong Cho 80c21aea11 core: dump also missed security context 2017-07-13 13:12:24 +09:00
WaLyong Cho 5b8e1b7755 core: modify resource leak by SmackProcessLabel= 2017-07-13 13:12:15 +09:00
Zbigniew Jędrzejewski-Szmek ab430161ee libudev: unused variable 2017-07-12 14:26:38 -04:00
florianjacob c1edab7ad1 resolved: consider pointopoint links for local multicast (#6343)
Resolves #6313.
2017-07-12 10:01:10 -04:00
Lennart Poettering 782c925f7f Revert "core: link user keyring to session keyring (#6275)" (#6342)
This reverts commit 437a85112e.

The outcome of this isn't that clear, let's revert this for now, see
discussion on #6286.
2017-07-12 10:00:43 -04:00
Lennart Poettering 6297d07b82 Merge pull request #6300 from keszybz/refuse-to-load-some-units
Refuse to load some units
2017-07-12 09:28:20 +02:00
Zbigniew Jędrzejewski-Szmek 2c75fb7330 core/load-fragment: refuse units with errors in RootDirectory/RootImage/DynamicUser
Behaviour of the service is completely different with the option off, so the
service would probably mess up state on disk and do unexpected things.
2017-07-11 13:38:13 -04:00
Zbigniew Jędrzejewski-Szmek bb28e68477 core/load-fragment: refuse units with errors in certain directives
If an error is encountered in any of the Exec* lines, WorkingDirectory,
SELinuxContext, ApparmorProfile, SmackProcessLabel, Service (in .socket
units), User, or Group, refuse to load the unit. If the config stanza
has support, ignore the failure if '-' is present.

For those configuration directives, even if we started the unit, it's
pretty likely that it'll do something unexpected (like write files
in a wrong place, or with a wrong context, or run with wrong permissions,
etc). It seems better to refuse to start the unit and have the admin
clean up the configuration without giving the service a chance to mess
up stuff.

Note that all "security" options that restrict what the unit can do
(Capabilities, AmbientCapabilities, Restrict*, SystemCallFilter, Limit*,
PrivateDevices, Protect*, etc) are _not_ treated like this. Such options are
only supplementary, and are not always available depending on the architecture
and compilation options, so unit authors have to make sure that the service
runs correctly without them anyway.

Fixes #6237, #6277.
2017-07-11 13:38:02 -04:00
Yu Watanabe 68bdd2d2d3 time-util: make parse_timestamp() return -EINVAL if the input is very old date (#6327)
This reverts 7635ab8e74 and makes parse_timestamp()
return -EINVAL if the input is older than 1970-01-01.

Fixes #6290.
2017-07-11 19:12:48 +02:00
Colin Walters 634735b56b fstab-generator: Chase symlinks where possible (#6293)
This has a long history; see see 5261ba9018
which originally introduced the behavior.  Unfortunately that commit
doesn't include any rationale, but IIRC the basic issue is that
systemd wants to model the real mount state as units, and symlinks
make canonicalization much more difficult.

At the same time, on a RHEL6 system (upstart), one can make e.g. `/home` a
symlink, and things work as well as they always did; but one doesn't have
access to the sophistication of mount units (dependencies, introspection, etc.)
Supporting symlinks here will hence make it easier for people to do upgrades to
RHEL7 and beyond.

The `/home` as symlink case also appears prominently for OSTree; see
https://ostree.readthedocs.io/en/latest/manual/adapting-existing/

Further work has landed in the nspawn case for this; see e.g.
d944dc9553

A basic limitation with doing this in the fstab generator (and that I hit while
doing some testing) is that we obviously can't chase symlinks into mounts,
since the generator runs early before mounts. Or at least - doing so would
require multiple passes over the fstab data (as well as looking at existing
mount units), and potentially doing multi-phase generation. I'm not sure it's
worth doing that without a real world use case. For now, this will fix at least
the OSTree + `/home` <https://bugzilla.redhat.com/show_bug.cgi?id=1382873> case
mentioned above, and in general anyone who for whatever reason has symlinks in
their `/etc/fstab`.
2017-07-11 18:48:57 +02:00
Yu Watanabe cd2d4c7f68 bootctl: allow non-root user to run bootctl status (#5964) 2017-07-11 11:30:29 -04:00
Zbigniew Jędrzejewski-Szmek 3616ca15f0 Merge pull request #6329 from poettering/random-mini-fixes
random-util.c mini fixes
2017-07-11 11:25:26 -04:00
Zbigniew Jędrzejewski-Szmek 13ddc3fc2b systemd: do not stop units bound to inactive units while coldplugging (#6316)
When running systemd-analyze verify I would get a random subset of warnings
(sometimes none, sometimes one or two):

dev-mapper-luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.swap: Unit is bound to inactive unit dev-mapper-luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.device. Stopping, too.
home.mount: Unit is bound to inactive unit dev-disk-by\x2duuid-75751556\x2d6e31\x2d438b\x2d99c9\x2dd626330d9a1b.device. Stopping, too.
boot.mount: Unit is bound to inactive unit dev-disk-by\x2duuid-56c56bfd\x2d93f0\x2d48fb\x2dbc4b\x2d90aa67144ea5.device. Stopping, too.

When running with debug on, it's pretty obvious what is happening:

home.mount: Changed dead -> mounted
home.mount: Unit is bound to inactive unit dev-disk-by\x2duuid-75751556\x2d6e31\x2d438b\x2d99c9\x2dd626330d9a1b.device. Stopping, too.
home.mount: Trying to enqueue job home.mount/stop/fail
home.mount: Installed new job home.mount/stop as 27
home.mount: Enqueued job home.mount/stop as 27
...
dev-disk-by\x2duuid-75751556\x2d6e31\x2d438b\x2d99c9\x2dd626330d9a1b.device: Installed new job dev-disk-by\x2duuid-75751556\x2d6e31\x2d438b\x2d99c9\x2dd626330d9a1b.device/start as 47
dev-disk-by\x2duuid-75751556\x2d6e31\x2d438b\x2d99c9\x2dd626330d9a1b.device: Changed dead -> plugged
dev-disk-by\x2duuid-75751556\x2d6e31\x2d438b\x2d99c9\x2dd626330d9a1b.device: Job dev-disk-by\x2duuid-75751556\x2d6e31\x2d438b\x2d99c9\x2dd626330d9a1b.device/start finished, result=done

Fixes #2206, https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=808151.
2017-07-11 10:45:03 +02:00
Zbigniew Jędrzejewski-Szmek ad1f3fe6a8 resolved: allow resolution of names which libidn2 considers invalid (#6315)
https://tools.ietf.org/html/rfc5891#section-4.2.3.1 says that
> The Unicode string MUST NOT contain "--" (two consecutive hyphens) in the third
> and fourth character positions and MUST NOT start or end with a "-" (hyphen).
This means that libidn2 refuses to encode such names.
Let's just resolve them without trying to use IDN.
2017-07-11 10:42:21 +02:00
Zbigniew Jędrzejewski-Szmek e3e42fc2b5 Add comments to log_functions which shouldn't be called from library code (#6326) 2017-07-11 10:40:11 +02:00
Lennart Poettering b5fa4c7706 random-util: we are fine if ints are 16 bytes actually
Not that it matters IRL, but let's make this less surprising to read...
2017-07-11 10:37:40 +02:00
Lennart Poettering 7b54715d19 random-util: always cast from smaller to bigger type when comparing
When we compare two size values, let's make sure we cast from the
smaller to the bigger type first, if both types differ, rather than the
reverse in order to not run into overflows.
2017-07-11 10:37:40 +02:00
Lennart Poettering f3b57eaf45 Merge pull request #6325 from keszybz/make-delta-boring-again
Make delta output repeatable
2017-07-11 10:00:21 +02:00
Zbigniew Jędrzejewski-Szmek 3f7a2973a5 Merge pull request #6322 from poettering/mount-mini-fixes
a bunch of mini fixes for mount-tool.c
2017-07-10 19:25:27 -04:00
Vito Caputo be7cdd8ec9 journal: explicitly add fds to mmap-cache (#6307)
This way we have a MMapFileDescriptor reference external to the cache,
and can supply the handle directly to mmap_cache_get(), eliminating
hashmap lookups entirely from the hot path.
2017-07-10 19:24:56 -04:00
Lennart Poettering 514368adfb mount: add missing validation error message
We really should generate exactly one log message for each error, hence
let's do that in this one case too.
2017-07-10 21:42:39 +02:00
Zbigniew Jędrzejewski-Szmek 9f5ebb8ac9 delta: sort files and dirs before processing
This should make output deterministic, and independent of the directory
layout on disk. Just using ordered hashmaps would be enough to make
the output deterministic on a specific machine, but to make it
identical on different machines with the same set of files and
directories, names are sorted after being use.

Fixes #6157.
2017-07-10 15:41:28 -04:00
Lennart Poettering aa46fa6420 mount: change find_loop_device() error code when no loop device is found to ENXIO
ENOENT is a bit too likely to be returned for various reasons, for
example if /sys or /proc are not mounted and hence the files we need not
around. Hence, let's use ENXIO instead, which is equally fitting for the
purpose but has the benefit that the underlying calls won't generate
this error on their own, hence any ambiguity is removed.
2017-07-10 21:41:14 +02:00
Lennart Poettering a53dceb709 mount: add debug logging for the case when we knowingly ignore an error 2017-07-10 21:41:02 +02:00
Zbigniew Jędrzejewski-Szmek f6d703c395 basic/strv: use existing qsort_safe() helper
strv_sort() predates qsort_safe(), but we can convert it to it to
save a few lines.
2017-07-10 15:40:47 -04:00
Lennart Poettering 5c6803f5bd mount: rework find_loop_device() to log about no errors
We should either log about all errors in a function, or about none (and
then leave the logging about it to the caller who we propagate the error
to). Given that the callers of find_loop_device() already log about the
returned errors let's hence suppress the log messages in
find_loop_device() itself.
2017-07-10 21:39:23 +02:00
Lennart Poettering 290843c385 mount: fix potential bad memory access when /proc/self/mountinfo is empty
It's unlikely this can ever be triggered, but let's be safe rather than
sorry, and handle the case where the list of mount points is zero, and
the "l" array thus NULL. let's ensure we allocate at least one entry.
2017-07-10 21:38:36 +02:00
Zbigniew Jędrzejewski-Szmek 9cdcf3681c gpt-auto-generator: use generator_add_symlink() 2017-07-10 00:16:37 -04:00
Zbigniew Jędrzejewski-Szmek 630d30d370 fstab-generator: use generator_add_symlink() 2017-07-10 00:16:37 -04:00
Zbigniew Jędrzejewski-Szmek b559616f23 cryptsetup-generator: add a helper utility to create symlinks
It seems that there's a common pattern among the various generators. Let's add
a helper function for it and make use of it in cryptsetup-generator.

This fixes a bunch of theoretical memleaks in error paths, since *to wasn't
generally freed properly. Not thath it matters.
2017-07-10 00:16:36 -04:00
Boucman decd79829a expand path of systemctl link argument (#6186)
systemctl link is the only systemctl verb that takes a filename (and not
a unit name) as argument

use path_strv_make_absolute_cwd to expand the provided filename in order
to make it easier to use from the command line

keep the absolute pathname requirement when --root is used

[zj: add explicit error messages for the cases of --root and plain filename
instead of skipping normalization and just relying on systemd to refuse
to link non-absolute arguments. This allows us to make the error message
more informative.]
2017-07-09 19:52:25 -04:00
Djalal Harouni 09b4922aff Merge pull request #6289 from keszybz/config-tweaks
Config parsing tweaks
2017-07-10 00:19:44 +02:00
Djalal Harouni df6d1a29b8 Merge pull request #6311 from keszybz/memleak
Fix trivial memleak in sd-login code
2017-07-09 17:58:52 +02:00
Yu, Li-Yu 4c4bc54697 sd_uid_get_state: do not return -ENOENT if state is "offline" (#6302) 2017-07-08 18:59:29 -04:00
Zbigniew Jędrzejewski-Szmek 964806347b sd-login: fix memleak when output argument is NULL 2017-07-08 18:04:44 -04:00
Zbigniew Jędrzejewski-Szmek c1db1a8058 networkd: trivial style cleanup 2017-07-08 17:58:44 -04:00
Yu Watanabe 7635ab8e74 time-util: make parse_timestamp() set 0 if the input is very old date (#6297)
If the input is older than "1970-01-01 UTC", then `parse_timestamp()`
fails and returns -EINVAL. However, if the input is e.g. `-100years`,
then the function succeeds and sets `usec = 0`.
This commit makes the function also succeed for old dates and set
`usec = 0`.

Fixes #6290.
2017-07-08 15:59:07 -04:00
Vito Caputo b1aa5ced45 shared: leave output_journal() output in buffer (#6304)
e268b81e moved an fflush() from output_json() to the generic
output_journal(), when it probably should have deleted all fflush()
calls from logs-show.c altogether.

The caller supplies the FILE * to these functions, and should be in
charge of flushing as needed.  The current implementation essentially
defeats any buffering stdio was bringing to the table, resulting in
extraneous tiny write() calls in commands like `journalctl -b`.

This commit removes the fflush() call from output_journal(), and adds
them to journalctl before waiting for more entries and at completion.
This way in the hot path when journalctl loops on entries stdio can
combine multiple entries into bulkier write() calls.
2017-07-07 14:32:21 -04:00
Benjamin Robin 46a5859673 resolve: Try to remove the ambiguity about the mtu parameter of dns_packet_new (#6285)
Actually the caller of dns_packet_new() pass 0 or the data size of the UDP message.
So try to reflect that, so rename the `mtu` parameter to `min_alloc_dsize`.

In fact `mtu` is the size of the whole UDP message, including the UDP header,
and here we just need to pass the size of data (without header). This was confusing.

Also add a check on the requested allocated size, since some caller do not check what is really allocated.
Indeed the function do not allocate more than DNS_PACKET_SIZE_MAX whatever the value of the `mtu` parameter.
2017-07-05 22:56:17 -04:00
NeilBrown 86086fce66 fstab-generator: fix new NULL dereference. (#6296)
fstype can be NULL, particularly when called from add_sysroot_mount(),
so we need to use STRPTR_IN_SET().
2017-07-05 22:53:41 -04:00
Zbigniew Jędrzejewski-Szmek 0d5e394c01 Merge pull request #6236 from yuwata/mount-loop
systemd-mount: support discovery of loop backing file
2017-07-05 10:27:58 -04:00
Yu Watanabe afde5b1630 systemd-mount: support relative paths 2017-07-05 21:55:50 +09:00
Yu Watanabe 3747daa2e5 systemd-mount: support unmounting devices on remote host
The commit 9017f5d88d prohibits
to unmount devices on remote host. This makes reenable such feature.
2017-07-05 21:55:39 +09:00
Yu Watanabe f0aac575fc systemd-mount: support discovery of loop backing file
```
$ suro systemd-mount /path/to/disk.img
Started unit run-media-system-disk.img.mount for mount point: /run/media/system/disk.img
```

Closes #6226.
2017-07-05 21:54:40 +09:00
Zbigniew Jędrzejewski-Szmek a99e002cc8 basic/log: use getenv instead of secure_getenv
secure_getenv does not work when the process has a nonempty permitted
capability set, which means that it's unduly hard to configure logging in
systemd-logind, systemd-resolved, and others.

secure_getenv is useful for code in libraries which might get called from a
setuid application. log_parse_environment() is never called from our library
code, but directly form various top-level executables. None of them are
installed suid, and none are prepared to be used this way, since many
additional changes would be required to make that safe. We may just as well
drop the check and allow SYSTEMD_LOG_* to properly parsed.

Fixes #4900.
2017-07-05 00:16:50 -04:00
Zbigniew Jędrzejewski-Szmek 5ce497b59a resolved: treat failure to parse config as non-fatal
Fixes #6014.
2017-07-05 00:16:50 -04:00
Mike Gilbert 496c486f12 test-fs-util: re-order test_readlink_and_make_absolute and test_get_files_in_directory (#6288)
test_readlink_and_make_absolute switches to a temp directory, and then
removes it.

test_get_files_in_directory calls opendir(".") from a directory that has
been removed from the filesystem.

This call sequence triggers a bug in Gentoo's sandbox library. This
library attempts to resolve the "." to an absolute path, and aborts when
it ultimately fails to do so.

Re-ordering the calls works around the issue until the sandbox library
can be fixed to more gracefully deal with this.

Bug: https://bugs.gentoo.org/590084
2017-07-04 23:22:47 -04:00
Giedrius Statkevičius 601b08420d systemctl: print next timer trigger time with the status verb (#6242)
It is useful to know when a timer will trigger next when looking at a
timer status message so calculate and print that information.

Closes #5738.

Example output:
$ systemctl status dnf-makecache.timer
● dnf-makecache.timer - dnf makecache timer
   Loaded: loaded (/usr/lib/systemd/system/dnf-makecache.timer; enabled; vendor preset: enabled)
   Active: active (waiting) since Tue 2017-07-04 17:24:02 EDT; 24min ago
  Trigger: Tue 2017-07-04 18:15:56 EDT; 27min left
2017-07-04 17:51:02 -04:00
Benjamin Robin 218f467111 basic: Fix build warning in random-util (#6284) 2017-07-04 17:42:20 -04:00