Commit graph

19086 commits

Author SHA1 Message Date
Lukáš Nykrýn dfeec916b5 shared/dropin: ignore ENAMETOOLONG when checking drop-in directories (#7525)
This usually happens for device units with long
path in /sys. But users can't even create such drop-ins,
so lets just ignore the error here.

Fixes #6867
2017-12-01 20:34:49 +01:00
Zbigniew Jędrzejewski-Szmek d9daae55d5 tmpfiles: add a special return code for syntax failures
In this way, individual errors in files can be treated differently than a
failure of the whole service.

A test is added to check that the expected value is returned.
Some parts are commented out, because it is not. This will be fixed in
a subsequent commit.
2017-12-01 18:58:54 +01:00
Lennart Poettering 1a2d4d7084
Merge pull request #7237 from keszybz/growfs
Create and grow filesystems
2017-12-01 17:58:58 +01:00
Michael Biebl 35ccaf9332
Merge pull request #7481 from poettering/bpf-test-fix
bpf-firewall: actually invoke BPF_PROG_ATTACH to check whether cgroup/bpf is available
2017-12-01 13:52:32 +01:00
Lennart Poettering 976c047841 mount-util: tape over name_to_handle_at() flakiness (#7517)
Apparently, the kernel returns EINVAL on NFS4 sometimes, even if we do
everything right, let's fallback in that case and find a different
approach to determine if something's a mount point.

See discussion at:

https://github.com/systemd/systemd/issues/7082#issuecomment-348001289
2017-12-01 12:59:16 +01:00
Lennart Poettering 41f23fe856 sd-bus: validate the message type (#7520)
Now that sd_bus_message_new() is public API, we should insist on valid
message types.
2017-12-01 11:59:42 +01:00
Lennart Poettering a081b9cea0 systemctl: don't use get_process_comm() on non-local PIDs (#7518)
Let's not use local process data for remote processes, that can only
show nonsense.

Maybe one day we should add a bus API to query the comm field of a
process remotely, but for now, let's not bother, the information is
redundant anyway, as the cgroup data shows it too (and the cgroup tree
is show as part of status as well, and is requested from remote through
dbus, without local kernel calls).

Fixes: #7516
2017-12-01 11:21:58 +01:00
Zbigniew Jędrzejewski-Szmek 69f9ccf140 util-lib: handle empty string in last_path_component
Now the function returns an empty string when given an empty string.
Not sure if this is the best option (maybe this should be an error?),
but at least the behaviour is well defined.
2017-11-30 20:54:31 +01:00
Zbigniew Jędrzejewski-Szmek 7cc84b2cd3 dissect-image: return error if results are ambiguous
We let the caller make the decision. Existing callers are OK with treating an
ambiguous result the same as no content, but makefs and growfs should refuse such
partitions.
2017-11-30 20:46:30 +01:00
Zbigniew Jędrzejewski-Szmek 7f2806d509 Add x-systemd.growfs option for fstab 2017-11-30 20:46:30 +01:00
Zbigniew Jędrzejewski-Szmek da495a0385 Add x-systemd.makefs option for fstab
I opted to completely generate a unit for both mount points and swaps. For
swaps, it would be possible to use fixed template unit like systemd-mkswap@.service,
because there's no information passed except the device name. For mount points,
that's not possible because both the device name and file system type need to
be passed. Nevertheless, I expect that options will need to passed to both mkfs
and mkswap, in which case it'll be necessary to create units of both types
anyway.
2017-11-30 20:46:30 +01:00
Zbigniew Jędrzejewski-Szmek 4191418baf fstab-generator: convert separate booleans to a flag field
It's pretty unwieldy with just three flags, and I want to add more.
2017-11-30 20:46:30 +01:00
Zbigniew Jędrzejewski-Szmek b7f28ac51f Add mkfs wrapper which first checks if the partition is empty 2017-11-30 20:46:30 +01:00
Zbigniew Jędrzejewski-Szmek 385de88a68 growfs: add option parsing and --help/--version/--dry-run
v2:
- use arg_target
2017-11-30 20:46:17 +01:00
Zbigniew Jędrzejewski-Szmek 995fa2e5e1 shared/dissect-image: fix return value for probe_filesystem()
blkid_new_probe_from_filename() sets errno, for example EPERM.
2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek c34b75a124 growfs: add support for resizing encrypted partitions 2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek c116b03595 Define CRYPT_LUKS in crypt-util.h
Also do not include libcryptsetup.h directly, but only through crypt-util.h.
This way we do not have to repeat the define in every file where it is used.
2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek 76d3e0834a growfs: do not try to resize btrfs partitions smaller then 256MB
This will not work, but the kernel does not give any useful message.
2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek 80750adb22 Add systemd-growfs tool 2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek 691c2e2e88 util-lib: export cryptsetup logging glue function 2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek 294bd45470 util-lib: add cleanup function for crypt_free 2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek 40fd52f28d util-lib: rename path_check_fstype to path_is_fs_type 2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek a66fee2e97 util-lib: rename fd_check_fstype to fd_is_fs_type
Let's use "is" and "fs_type" for consistency with "is_fs_type".
"check" is also more ambiguous than "is".
2017-11-30 20:43:25 +01:00
Zbigniew Jędrzejewski-Szmek b12d25a8d6 util-lib: use trailing slash in chase_symlinks, fd_is_mount_point, path_is_mount_point
The kernel will reply with -ENOTDIR when we try to access a non-directory under
a name which ends with a slash. But our functions would strip the trailing slash
under various circumstances. Keep the trailing slash, so that

path_is_mount_point("/path/to/file/") return -ENOTDIR when /path/to/file/ is a file.

Tests are added for this change in behaviour.

Also, when called with a trailing slash, path_is_mount_point() would get
"" from basename(), and call name_to_handle_at(3, "", ...), and always
return -ENOENT. Now it'll return -ENOTDIR if the mount point is a file, and
true if it is a directory and a mount point.

v2:
- use strip_trailing_chars()

v3:
- instead of stripping trailing chars(), do the opposite — preserve them.
2017-11-30 20:43:25 +01:00
Mathieu Trudel-Lapierre c1a3890410 Add a "RequiredForOnline=" Link attribute for .network files (#7347)
RequiredForOnline= denotes a link/network that does/does not require being up
for systemd-networkd-wait-online to consider the system online; this makes it
possible to ignore devices without modifying parameters to wait-online.
2017-11-30 18:03:50 +01:00
Zbigniew Jędrzejewski-Szmek ca4d708dc4 test-string-util: add another test for stripping slashes
I wrote this for my own "strip_trailing_chars" function, which was in the
meanwhile obsoleted by "delete_trailing_chars". Let's just keep the test.
2017-11-30 12:59:23 +01:00
Zbigniew Jędrzejewski-Szmek c67f84b025 Add a helper for /dev/block/major:minor paths 2017-11-30 12:59:23 +01:00
Zbigniew Jędrzejewski-Szmek 553e15f21b Add a little helper to make /sys/dev/block/major:minor paths 2017-11-30 12:59:23 +01:00
Zbigniew Jędrzejewski-Szmek ee3467c6bd test-mount-util: move test_path_is_mount_point here
path-util.c and mount-util.c are intertwined, but path_is_mount_point() is
defined in mount-util.c.

No functional difference.
2017-11-30 12:59:23 +01:00
Yu Watanabe 9d4f242a53 core/dbus-execute: actually set PassEnvironment= (#7510)
Follow-up for #7444.
2017-11-30 12:34:58 +01:00
Krzysztof Nowicki 8739f23e3c Fix SELinux labels in cgroup filesystem root directory (#7496)
When using SELinux with legacy cgroups the tmpfs on /sys/fs/cgroup is by
default labelled as tmpfs_t. This label is also inherited by the "cpu"
and "cpuacct" symbolic links. Unfortunately the policy expects them to
be labelled as cgroup_t, which is used for all the actual cgroup
filesystems. Failure to do so results in a stream of denials.

This state cannot be fixed reliably when the cgroup filesystem structure
is set-up as the SELinux policy is not yet loaded at this
moment. It also cannot be fixed later as the root of the cgroup
filesystem is remounted read-only. In order to fix it the root of the
cgroup filesystem needs to be temporary remounted read-write, relabelled
and remounted back read-only.
2017-11-30 11:59:29 +01:00
Lennart Poettering 949befd3f0
core: support upgrading from DynamicUser=0 to DynamicUser=1 for unit directories (#7507)
This makes sure we migrate /var/lib/<foo> if it exists to
/var/lib/private/<foo> if DynamicUser=1 is set. This is useful to allow
turning on DynamicUser= on services that previously didn't use it, and
we can deal with this, and migrate the relevant directories as
necessary.

Note that "downgrading" from DynamicUser=1 backto DynamicUser=0 works
too. However in that case we simply continue to use
/var/lib/private/<foo>, which works because /var/lib/<foo> is a symlink
there after all.
2017-11-30 11:52:39 +01:00
Yu Watanabe 191e9ef87d
Merge pull request #7444 from poettering/dbus-no-spec
unit writing escaping fixes + related fixes and additions
2017-11-30 14:50:36 +09:00
Lennart Poettering 5908ff1c4b journal: fix log message when dropping messages
Fixes: #7506
2017-11-29 22:11:59 +01:00
Lennart Poettering e583759bd1 bpf-firewall: actually invoke BPF_PROG_ATTACH to check whether cgroup/bpf is available
Apparently that's the only way to really know whether the kernel has
CONFIG_CGROUP_BPF turned on.

Fixes: #7054
2017-11-29 20:15:23 +01:00
Lennart Poettering c2288ade1e bus-unit-util: slightly tweak log output for unknown props
Pretty:

        Unknown assignment Foo=bar.

Prettier:

        Unknown assignment: Foo=bar
2017-11-29 20:12:26 +01:00
Lennart Poettering f53bddf308 run: rearrange error handling when adding unit properties
Let's always leave logging to the call that actually added the fields to
the bus message. This way we don't get duplicate logging whenver
bus_append_unit_property_assignment() ends up being called, which does
all its logging on its own (and probably should do, as it can output
much more precise errors).
2017-11-29 20:12:26 +01:00
Lennart Poettering 147fe484c1 bus-unit-util: add proper MemorySwapMax= serialization
Fixes: #7505
2017-11-29 20:12:26 +01:00
Lennart Poettering 66a892ae3d core: accept MemorySwapMax= properties that are scaled, too
Let's do what we already do for MemoryMax= and friends for
MemorySwapMax= too.
2017-11-29 20:12:26 +01:00
Lennart Poettering 421eaea0d1 tty-ask-password-agent: drop NULL sentinel
found by coccinelle
2017-11-29 20:12:26 +01:00
Lennart Poettering a2d61f0746 coccinelle: fix IN_SET/!IN_SET scripts, and apply some changes it found
IN_SET only works for constant values, hence clarify that. Moreover, we
declared a statement "s" we never made use of. Drop it.

Also, for both scripts, let's support 10 items. More causes spatch to
die with "Stack overflow" for me.
2017-11-29 20:12:26 +01:00
Lennart Poettering 7b943bb7e3 tree-wide: use strv_isempty() instead of strv_length() == 0
It's a lot faster in many cases, since it's O(1) rather than O(n).
2017-11-29 12:41:08 +01:00
Lennart Poettering 5716965132 bus-unit-util: properly serialize EnvironmentFile= empty assignment
In that case we need to generate an empty array.
2017-11-29 12:34:12 +01:00
Lennart Poettering 50fb00b707 core: use safe_fclose() where we can 2017-11-29 12:34:12 +01:00
Lennart Poettering 7d7a99ac9f fileio: document why fileio-label.c and fileio.c are two different modules 2017-11-29 12:34:12 +01:00
Lennart Poettering f6c66be1dc core: open up all ExecXYZ= fields of service units to transient units
Fixes: #7400
2017-11-29 12:34:12 +01:00
Lennart Poettering 45639f1be5 core: never remove "transient" and "control" directories from unit search path
This changes the unit search path logic to never drop the transient and
control directories from the unit search path. This is necessary as we
add new entries to both during runtime, due to the "systemctl
set-property" and transient unit logic.

Previously, the "transient" directory was created during early boot to
deal with this, but the "control" directories were not covered like
that. Creating the control directories early at boot is not possible
however, as /etc might be read-only then, and we do define a persistent
control directory. Hence, let's create these dirs on-demand when we need
them, and make sure the search path clean-up logic never drops them from
the search path even if they are initially missing.

(Also, always create these paths properly labelled)
2017-11-29 12:34:12 +01:00
Lennart Poettering 45a7b16bae core: don't reference rescue/emergency targets in --user mode
They are only defined for system mode, hence let's not check for them in
--user mode.

Follow-up for #7433
2017-11-29 12:34:12 +01:00
Lennart Poettering 0126c8f3f6 core: minor simplification 2017-11-29 12:34:12 +01:00
Lennart Poettering fbc5883523 path-lookup: LookupPathsFlags are a flags type, hence define it like one
We shouldn't rely on C's incremental assignment of values of enums for
bit fields. That'll work only between the first two flags, but for
everything following will break horrible. Hence, let's avoid any
ambiguity here, and let's clearly define the flags as shifts of 1.
2017-11-29 12:34:12 +01:00
Lennart Poettering e9f4aabd80 systemctl: reword "needs-reload" message a bit
This message is displayed either when the unit file itself is newer than
what is loaded, but also when any of the drop-ins is newer. Say so in
the message, in order not to confuse the user unnecessarily.
2017-11-29 12:34:12 +01:00
Lennart Poettering 721060d446 core: allow changing the description for units dynamically at runtime
This makes "systemctl set-property foobar.service Description=waldo"
work.

See: #7245
2017-11-29 12:34:12 +01:00
Lennart Poettering e74f76ca86 tree-wide: generate SD_BUS_ERROR_INVALID_ARGS when we get invalid arguments on bus calls
Let's make sure that when we return a D-Bus error, we return a native
one, if we generate it ourselves, and use errno-based error
synthetization only if we received an errno ourselves. Yes, this makes
things slightly longer, but is highly misleading as we propagate D-Bus
errors, and not errnos to the client.
2017-11-29 12:34:12 +01:00
Lennart Poettering 2e59b241ca core: add proper escaping to writing of drop-ins/transient unit files
This majorly refactors the transient unit file and drop-in writing
logic, so that we properly C-escape and specifier-escape (% → %%)
everything we write out, so that when we read it back again, specifiers
are parsed that aren't supposed to be parsed.

This renames unit_write_drop_in() and friends by unit_write_setting().
The name change is supposed to clarify that the functions are not only
used to write drop-in files, but also transient unit files.

The previous "mode" parameter to this function is replaced by a more
generic "flags", which knows additional flags for implicit C-style and
specifier escaping before writing things out. This can cover most
properties where either form of escaping is defined. For the cases where
this isn't sufficient, we add helpers unit_escape_setting() and
unit_concat_strv() for escaping individual strings or strvs properly.

While we are at it, we also prettify generation of transient unit files:
we try to reduce the number of section headers written out: previously
we'd write the right section header our for each setting. With this
change we do so only if the setting lives in a different section than
the one before.

(This should also be considered preparation for when we add proper APIs
to systemd to write normal, persistant unit files through the bus API)
2017-11-29 12:34:12 +01:00
Lennart Poettering ddd59d0c7f logind: fix sysfs change trigger code
We can't create files in sysfs, hence don't bother. Also if we ignore
the return value, do so explicitly by casting to void.
2017-11-29 12:32:57 +01:00
Lennart Poettering 98bad05e75 generators: be more careful when writing unit settings that support specifier expansion
Let's always escape strings we receive from the user before writing them
out to unit file settings that suppor specifier expansion, so that user
strings are transported as-is.
2017-11-29 12:32:57 +01:00
Lennart Poettering b238be1e0d core: enable specifier expansion for What=/Where=/Type=/SourcePath= too
Using specifiers in these settings isn't particularly useful by itself,
but it unifies behaviour a bit. It's kinda surprising that What= in
mount units resolves specifies, but Where= does not. Hence let's add
that too. Also, it's surprising Where=/What= in mount units behaves
differently than in automount and swap units, hence resolve specifiers
there too. Then, Type= in mount units is nowadays an arbitrary,
sometimes non-trivial string (think fuse!), hence let's also expand
specifiers there, to match the rest of the mount settings.

This has the benefit that when writing code that generates unit files,
less care has to be taken to check whether escaping of specifiers is
necessary or not: broadly everything that takes arbitrary user strings
now does specifier expansion, while enums/numerics/booleans do not.
2017-11-29 12:32:57 +01:00
Lennart Poettering 6c5def2ff2 core: process C-style escapes in UnsetEnvironment=
We process C-style escapes in Environment=, hence we should process it
in UnsetEnvironment= too, as the latter accepts assignments much like
the former, including arbitrary values specified by the user.
2017-11-29 12:32:56 +01:00
Lennart Poettering 613613f1ee core: use config_parse_unit_string_printf() for decoding RebootArgument=
All other cases where we accept a reboot argument are decoded with
config_parse_unit_string_printf() rather than
config_parse_unit_path_printf(), and that's really the only thing what
makes sense here, hence adjust this here, too.
2017-11-29 12:32:56 +01:00
Lennart Poettering 36444d2213 specifier: unify specifier implementations for user-related specifiers
The code in install-printf.c and unit-printf.c for these is pretty much
the same and very generic. Let's move this all over to the generic
specifier.c, and share the implementations.
2017-11-29 12:32:56 +01:00
Lennart Poettering e82f30d17f specifier: add helper for escaping '%' characters to avoid making them subject for expansion
This is ultimately just a wrapper around strreplace(), but it makes
things a bit more self-descriptive.
2017-11-29 12:32:56 +01:00
Lennart Poettering 9d73565ac0 string-util: update strreplace() a bit, use GREEDY_REALLOC() 2017-11-29 12:32:56 +01:00
Lennart Poettering 6171b8225f core: drop specifier expansion when parsing transient dbus properties
Specifier expansion (much like C escape handling) should be a helper for
writing unit files, but should be nothing we do on programatic APIs. For
those, the client can do the necessary replacements anyway, and we
really should be careful with doing such string processing of data we
get via lower level programmatic APIs.

We currently do specifier expansion only for the env var transient unit
APIs, no other properties do this. Let's remove it here too, to be fully
systematic.

Yes, in a way this is API breakage, but then again this API isn't
documented yet, and an outlier, hence let's clear this up now, before it
is too late.
2017-11-29 12:32:53 +01:00
Lennart Poettering e61ad5c283 journald: correct field counts
N_IOVEC_OBJECT_FIELDS is bumped 14 → 18 (see dispatch_message_real() and
count!)

N_IOVEC_PAYLOAD_FIELDS is bumped 15 → 16 (see
server_space_usage_message() and count!)

Also, add comments, to make clear what is what.
2017-11-29 11:37:21 +01:00
Lennart Poettering f643ae7171 journal: driver messages can now contain object fields, account for that
In some cases we can now log about processes, hence we must keep room
for that.
2017-11-29 11:36:22 +01:00
Yu Watanabe 3235b4e70c
Merge pull request #7492 from keszybz/coverity-fixes
A few more cleanups based on coverity and valgrind
2017-11-29 12:50:49 +09:00
Zbigniew Jędrzejewski-Szmek ae34a10bac udev/collect: use _cleanup_ in one more place
This doesn't make the code pretty, but it at least makes it a tiny bit shorter.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek 3176084ff2 udev/collect: remove dead conditional
Coverity rightly says that 'word' is assigned to 'ptr', and 'word'
was assigned from 'ptr' (yikes) right after a non-null check.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek 2504834861 journal: avoid undefined behaviour in float division by 0.0
Coverity says that's undefined. I'm pretty sure we always would get a nan, but
let's avoid (formally) undefined behaviour since that can cause compilers to do
strange things.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek b921fcb2ac networkd: fix memleak of Rules
This was the issue mentioned in 93f9da6e0a.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek f916819053 journal: use new helpers with journal_file_close
journal_file_close_set() is not necessary anymore.
2017-11-28 21:34:50 +01:00
Zbigniew Jędrzejewski-Szmek 1599f593d6 journal-remote: add helper function and use hashmap_free_with_destructor 2017-11-28 21:34:46 +01:00
Zbigniew Jędrzejewski-Szmek 6dd1c36839 cryptsetup-generator: add helper function and use hashmap_free_with_destructor 2017-11-28 21:34:41 +01:00
Zbigniew Jędrzejewski-Szmek 39ab16e397 coredump: fix typo and use hashmap_free_with_destructor 2017-11-28 21:34:34 +01:00
Zbigniew Jędrzejewski-Szmek e85b096b43 machine-image: convert image_hashmap_free() to an static inline helper 2017-11-28 21:30:43 +01:00
Zbigniew Jędrzejewski-Szmek 224b0e7ad0 Add set/hashmap helpers for non-trivial freeing and use where straighforward
A macro is needed because otherwise we couldn't ensure type safety.
Some simple tests are included.
No functional change intended.
2017-11-28 21:30:30 +01:00
Zbigniew Jędrzejewski-Szmek ec1d290903 Use hashmap_free_free where appropriate 2017-11-28 21:26:37 +01:00
Zbigniew Jędrzejewski-Szmek 5c4912ea61
Merge pull request #7490 from yuwata/test-basic
add more tests for basic functions
2017-11-28 18:15:30 +01:00
Susant Sahani fbdb6605b5 networkd: Add comment for setting_mtu #7460 (#7489)
Follow up #7460
2017-11-28 17:24:52 +01:00
Lennart Poettering 4de8d3f59e
Merge pull request #7486 from keszybz/coverity-fixes
Fixes for issues spotted by coverity (and some cleanups)
2017-11-28 15:04:11 +01:00
Yu Watanabe 23cc81e7c2 test-cap-list: add more tests about capability_set_{from,to}_string() 2017-11-28 22:17:00 +09:00
Yu Watanabe 4c1a95fd84 test: move tests about cap_list_cap() from test-cap-list to test-capability 2017-11-28 22:14:54 +09:00
Yu Watanabe db4bd5bd62 cap-list: check range of numeric value 2017-11-28 22:06:34 +09:00
Yu Watanabe 6b86b9e65d test-bitmap: add tests for bitmap_copy() 2017-11-28 20:34:36 +09:00
Yu Watanabe ade0eb2190 test-architecture: add more tests 2017-11-28 20:34:32 +09:00
Yu Watanabe f30788ee23 test-alloc-util: add tests for memdup_suffix0() and greedy_realloc() 2017-11-28 20:33:58 +09:00
Yu Watanabe a4e6e06bc7 tests: add tests for empty string 2017-11-28 20:21:25 +09:00
Yu Watanabe d40c54fe56 alloc-util: coding style fix 2017-11-28 20:21:15 +09:00
Lennart Poettering b39367a1a7
Merge pull request #7398 from keszybz/udev-list
udev: use list.h instead of udev_list_node
2017-11-28 11:35:02 +01:00
Lennart Poettering c9f034a10a
Merge pull request #7484 from poettering/sd-resolve-timeout
timeout sd-resolve tests
2017-11-28 11:33:38 +01:00
Zbigniew Jędrzejewski-Szmek ba77dac291 pid1: improve syntax in error message 2017-11-28 09:26:14 +01:00
Zbigniew Jędrzejewski-Szmek d387cfdddd pid1: clarify that min_max is always initialized
read_one_line_file() always returns <= 0, so the code was OK, but let's write
the check a bit differently to make it obvious that min_max is always set.
2017-11-28 09:26:14 +01:00
Zbigniew Jędrzejewski-Szmek 7beb3baf16 test-hostname-util: add assert_se's to make coverity happy 2017-11-28 09:26:14 +01:00
Zbigniew Jędrzejewski-Szmek c47a9f909a test-process-util: add (void) cast to make coverity happy
The intent is for the call to succeed only when privileged, so make
that clear.
2017-11-28 09:25:39 +01:00
Zbigniew Jędrzejewski-Szmek ca9b2b4dc1 test-fd-util: add assert_se to make coverity happy 2017-11-28 09:25:39 +01:00
Zbigniew Jędrzejewski-Szmek b0fe73d740 udevadm-monitor: add some assert_se's to make coverity happy
We do that elsewhere and it's nice to be consistent.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 595c66a3db core/umount: use _cleanup_ in one more place 2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 1a96c8e1cc sd-resolve: check that name fits in the specified packet length
Coverity complained that we didn't check if the data is long enough.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 8d44f5a637 shim: fix logically dead code
The alternate verification path could never be taken.

Found by coverity.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 1e40b7490a networkd: remove dead code
Found by coverity.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek ef51180b62 test-ndisc-ra: add assert_se() to make coverity happy 2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 10a6e01eaa boot/shim: fix char ** vs char * mismatch
This code cannot have ever worked ;(

Found by coverity, obvious when the type is not obfuscated to void*.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek bceda88b52 boot/efi: fix NULL dereference
The comment above makes the intent of the code pretty clear:
"use security2_protocol == NULL as indicator".
So revert the condition in the check and fix the logic in the comment while
at it.

The question is how this could have ever worked: if BS->LocateProtocol
(which is supposedly optional) ever failed, we'd crash here. Strange.

Found by coverity.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek bdd73ac5c2 dissect-image: simplify check for passphrase presence
m->encrypted is set when fstype=="crypto_LUKS", but this is not obvious when
reading decrypt_partition(). Just check if passphrase is set before using
it.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek bbd1590085 networkd: fix reversed arguments
Found by coverity.

Also drop unused return value while at it.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 93f9da6e0a networkd: plug some memleaks in rule serialization/deserialization
This fixes the (mostly theoretical, since we're only parsing data that we write
ourselves) memleak when iif or oif is deserialized multiple times. Unfortunately
it does not fix the memleak when rule is freed, but that'll require a bigger
effort.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 9491f55f74 networkd: fix serialization of {Incoming,Outgoing}Interface
Let's just say that the code wasn't fully functional ;(

Since we only had the parser for serialization, and not the writer, we are
free to change the format. So while at it, let's use shorter names in the
serialization format that match the surrounding style.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 7379f3de7f Add test-routing-policy-rule 2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 6f349a4f9c test-network: use automatic cleanup 2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek e4aca57df8 networkd: parse the rvalue, not the option name
:(
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 458d8ae302 networkd: move rule loading to a separate function
No functional change.
2017-11-28 09:25:38 +01:00
Lennart Poettering 5bf5510b8f test-resolve: make sure we don't hang forever
If test-resolve is running in some CI environment that doesn't have
reliably working DNS, it's a good idea not to hang forever, let's
time-out after 20s
2017-11-27 17:08:34 +01:00
Lennart Poettering 971fea3203 sd-resolve: propagate timeouts in sd_resolve_wait() the same way as in sd_bus_wait(): ETIMEDOUT
Thankfully this is an internal API still, so we can mkae changes like
this.
2017-11-27 17:08:34 +01:00
Lennart Poettering f3b900311f service: shortcut operations if the MAINPID= doesn't actually cause a change 2017-11-27 17:04:57 +01:00
Lennart Poettering 2fa40742a4 service: use parse_errno() for parsing error numbers
Let's always use the same logic when parsing error numbers, i.e. use
parse_errno() here too, to unify some code, and tighten the checks a
bit.

This also allows clients to pass errors as symbolic names. Probably
nothing we want to advertise too eagerly (since new daemons generating
this on old service managers won't understand), but still pretty
useful I think, in particular in scripting languages and such, where the
numeric error numbers might not be readily available.
2017-11-27 17:04:57 +01:00
Lennart Poettering 4050e47976 logind: use the new FDSTOREREMOVE=1 sd_notify() message
Let's explicitly tell PID 1 that we don't need an fd anymore, instead of
relying exclusively on POLLERR/POLLHUP for it to be removed.

Fixes: #6908
2017-11-27 17:04:04 +01:00
Lennart Poettering e78ee06de1 core: add a new sd_notify() message for removing fds from the FD store again
Currenly the only way to remove fds from the fdstore is to fully
stop the service, or to somehow trigger POLLERR/POLLHUP on the fd, in
which case systemd will remove the fd automatically.

Let's add another way: a new message that can be sent to remove fds
explicitly, given their name.
2017-11-27 17:04:04 +01:00
Lennart Poettering cc2b7b11b4 core: only process one of READY=1, STOPPING=1 or RELOADING=1 in sd_notify() handling
Of course, it's not really a valid sd_notify() message if multiple of
these fields are used in one, but let's handle this somewhat gracefully,
by only processing one of them, and ignoring the rest.
2017-11-27 17:01:00 +01:00
Lennart Poettering c45d11cb30 service: reorder sd_notify() handling a bit
Let's keep handling of WATCHDOG= and WATCHDOG_USEC= together. No
functional changes.
2017-11-27 16:59:52 +01:00
Lennart Poettering e328523777 service: split out sd_notify() message authorization code into a function of its own
Let's shorten service_notify_message() a bit, and do the authentication
outside of the main function body.

No functional changes.
2017-11-27 16:59:52 +01:00
Lennart Poettering 9711848ff1 core: only log about sd_notify() message contents, when debug logging is on
Let's optimize things a bit for the non-debug case. No change in
behaviour.

Main reason to do this is not so much the speed benefit though, but
merely to isolate the code from its surroundings more.
2017-11-27 16:39:43 +01:00
Patrik Flykt a86d329f22 networkd: Free Prefix in case allocation fails (#7480)
Set the code to call _cleanup_prefix_free_ in case the next allocation
fails so that Prefix does not leak memory.

Reported by evverx.
2017-11-27 13:07:22 +01:00
Zbigniew Jędrzejewski-Szmek cfc4529b01 networkd: unbork rule serialization
We'd write something like

RULE=from=250.250.240.0/24 to=(null)/0 tos=0 fwmark=0/0 table=12
RULE=from=250.250.250.0/24 to=(null)/0 tos=0 fwmark=0/0 table=11
2017-11-27 10:06:55 +00:00
Lennart Poettering 401e33ed56 logind: make sure we don't acces m->action_what if it's not initialized (#7475)
Fixes: #7466
2017-11-27 08:15:07 +01:00
Lennart Poettering c8ace1bf5d
Merge pull request #7472 from keszybz/tests-on-a-slow-disk
Tests on a slow disk
2017-11-26 18:37:00 +01:00
Susant Sahani 97e7fb39a8 networkd: DHCP client do not get into a loop while setting MTU (#7460)
Some devices get reset itself while setting the MTU. we get in to a LOOP .
Once the MTU changed then the DHCP client talking with DHCP server never stops.
networkd gets into a loop and generates endless DHCP requests.

fixes #6593
fixes #7380
2017-11-26 15:21:45 +01:00
Zbigniew Jędrzejewski-Szmek 76b38997c9 test: increase timeout for test-journal-enum
This reads the journal from the host system, and in case of a slow
disk, the 30s default can be easily exceeded.
2017-11-26 15:07:53 +01:00
Evgeny Vereshchagin 3f19974091 exec-util: initialize new before using it (#7471)
CID #1383004
2017-11-26 12:46:56 +01:00
Zbigniew Jędrzejewski-Szmek b45f436f61
Merge pull request #7464 from poettering/cgroup-control-fix
various cgroup fixes
2017-11-26 11:34:24 +01:00
Yu Watanabe dd5082a9de
Merge pull request #7468 from yuwata/fix-7362
test and meson cleanups
2017-11-26 12:35:07 +09:00
Zbigniew Jędrzejewski-Szmek 07920ba095
Merge pull request #7467 from yuwata/fix-7302
nspawn: adjust path to static resolv.conf to support split usr
2017-11-25 23:13:12 +01:00
Yu Watanabe 7accca234d fileio: include sys/mman.h 2017-11-26 02:40:23 +09:00
Lennart Poettering a4634b214c core: warn about left-over processes in cgroup on unit start
Now that we don't kill control processes anymore, let's at least warn
about any processes left-over in the unit cgroup at the moment of
starting the unit.
2017-11-25 17:08:21 +01:00
Lennart Poettering e98b2fbbe9 core: generalize the cgroup empty check on GC
Let's move the cgroup empty check for all unit types into the generic
unit_check_gc() call, out of the per-unit-type _check_gc() type. This
not only allows us to share some code, but also hooks up mount and
socket units with this kind of check, for free, as it was missing there
previously.
2017-11-25 17:08:21 +01:00
Lennart Poettering e9a4f67609 cgroup: remove logic for maintaining /control subcgroup for the service unit type
Previously, in the service unit type we ran all control processes in a
special subcgroup /control of the unit's main cgroup. Remove that, and
run the control program in the main cgroup instead.

The concept conflicts with cgroupv2's logic of "no processes in inner
nodes": if a unit has a main daemon process running in the main cgroup,
and a reload control process would be started in the /control subcgroup,
then this would necessarily fail, as the main daemon process would
become an inner node process that way.

We could in theory continue to support this in cgroupv1, but in the
interest in keeping behaviour similar in both hierarchies, let's drop
this altogether.

Philosophically maybe it wasn't the greatest idea anyway to just go
berserk and SIGKILL all those processes — loud warning logging might
have sufficed, too.
2017-11-25 17:08:21 +01:00
Lennart Poettering 60c728adf7 unit: initialize bpf cgroup realization state properly
Before this patch, the bpf cgroup realization state was implicitly set
to "NO", meaning that the bpf configuration was realized but was turned
off. That means invalidation requests for the bpf stuff (which we issue
in blanket fashion when doing a daemon reload) would actually later
result in a us re-realizing the unit, under the assumption it was
already realized once, even though in reality it never was realized
before.

This had the effect that after each daemon-reload we'd end up realizing
*all* defined units, even the unloaded ones, populating cgroupfs with
lots of unneeded empty cgroups.

With this fix we properly set the realiazation state to "INVALIDATED",
i.e. indicating the bpf stuff was never set up for the unit, and hence
when we try to invalidate it later we won't do anything.
2017-11-25 17:08:21 +01:00
Lennart Poettering 2aa57a6550 cgroup: when dispatching the cgroup realization queue, check again if we shall actually realize
We add units to the cgroup realization queue when propagating realizing
requests to sibling units, and when invalidating cgroup settings because
some cgroup setting changed. In the time between where we add the unit
to the queue until the cgroup is actually dispatched the unit's state
might have changed however, so that the unit doesn't actually need to be
realized anymore, for example because the unit went down. To handle
that, check the unit state again, if realization makes sense.

Redundant realization is usually not a problem, except when the unit is
not actually running, hence check exactly for that.
2017-11-25 17:08:21 +01:00
Lennart Poettering 0f2d84d2cc cgroup: drop unused parameter from function 2017-11-25 17:08:21 +01:00
Lennart Poettering 62b9bb2661 cgroup-util: merge cg_set_tasks_access() and cg-set_group_access() into one
We never use these functions seperately, hence don't bother splitting
them into to.

Also, simplify things a bit, and maintain tables for the attribute files
to chown. Let's also update those tables a bit, and include thenew
"cgroup.threads" file in it, that needs to be delegated too, according
to the documentation.
2017-11-25 17:08:21 +01:00
Yu Watanabe 62b1e758d3 nspawn: adjust path to static resolv.conf to support split usr
Fixes #7302.
2017-11-25 21:11:07 +09:00
Yu Watanabe a7353b4d14 firstboot: do not write vconsole.conf when arg_keymap is empty 2017-11-25 19:11:57 +09:00
Yu Watanabe 4540ae7400 machine: remove unused variables 2017-11-25 19:00:49 +09:00
Yu Watanabe 5354b0b7c0 journald: add _printf_ attribute to server_driver_message() 2017-11-25 19:00:44 +09:00
Lennart Poettering 2482f88d2a tests: make "test-execute" work in "sudo ninja -C build test" (#7463)
In this mode USER/LOGNAME still point to the original caller, and our
tests get confused by that.

Follow-up for: #7450
2017-11-24 22:56:44 +01:00
Lukasz Rubaszewski 3d22bc8636 tmpfiles: check if not too many symbolic links. (#7423)
Some filesystems do not set d_type value when
readdir is called, so entry type is unknown.
Therefore check if accessing entry does not
return ELOOP error.
2017-11-24 22:28:14 +01:00
Christian Brauner 1ff654e28b core: remove empty cgroups (#7457)
When we skip an unwritable cgroup also remove the empty mountpoint.
2017-11-24 21:05:16 +01:00
Michael Vogt 64b21ece8c networkd: auto promote links if "promote_secondaries" is unset (#7167)
The DHCP code in systemd-networkd relies on the
`net.ipv4.conf.{default,all,<if>}.promote_secondaries` sysctl to be set
(the kernels default is that it is unset). If this sysctl is not set
DHCP will work most of the time, however when the IP address changes
between leases then the system will loose its IP.

Because some distributions decided to not ship these defaults (Debian
is an example and via downstream Ubuntu) networkd by default will now
enable this sysctl opton automatically.
2017-11-24 21:03:05 +01:00
Lennart Poettering d381c8a6bf nspawn: hash the machine name, when looking for a suitable UID base (#7437)
When "-U" is used we look for a UID range we can use for our container.
We start with the UID the tree is already assigned to, and if that
didn't work we'd pick random ranges so far. With this change we'll first
try to hash a suitable range from the container name, and use that if it
works, in order to make UID assignments more likely to be stable.

This follows a similar logic PID 1 follows when using DynamicUser=1.
2017-11-24 20:57:19 +01:00
Lennart Poettering a8027a18f1
Merge pull request #7442 from poettering/scope-fixes
some fixes to the scope unit type
2017-11-24 17:15:09 +01:00
Lennart Poettering b068c6f587 systemctl: ignore shutdown's "-t" argument (#7459)
We should not only ignore "-t" itself, but also whatever is passed to
it.

This pretty much reverts the core of
a4420f7b8e, and adds back in the status
quo ante. What a difference a ':' can make.

This also adds a quick comment for this, so that we don't make this
mistake again.

Fixes: #7413
2017-11-24 17:01:32 +01:00