platform/upstream/systemd.git
6 years agoRename "system-preset" source dir to "presets"
Zbigniew Jędrzejewski-Szmek [Thu, 23 Nov 2017 12:23:42 +0000 (13:23 +0100)]
Rename "system-preset" source dir to "presets"

I want to add presets/user/ later. This mirrors the layout for units:
we have units/ and units/user. The advantage is that we avoid having yet
another directory at the top level.

6 years agoutil-lib: kill duplicate slashes in lookup paths
Zbigniew Jędrzejewski-Szmek [Thu, 23 Nov 2017 12:02:21 +0000 (13:02 +0100)]
util-lib: kill duplicate slashes in lookup paths

Since we're munging the array anyway, we can make the output a bit
nicer too.

6 years agoshared: export xdg_user_dirs() and xdg_user_*_dir()
Zbigniew Jędrzejewski-Szmek [Thu, 23 Nov 2017 10:41:28 +0000 (11:41 +0100)]
shared: export xdg_user_dirs() and xdg_user_*_dir()

6 years agotmpfiles: "e" takes globs
Zbigniew Jędrzejewski-Szmek [Wed, 22 Nov 2017 14:16:48 +0000 (15:16 +0100)]
tmpfiles: "e" takes globs

Fixes #7369.

6 years agotmpfiles: fix typo in error message
Zbigniew Jędrzejewski-Szmek [Wed, 22 Nov 2017 13:55:14 +0000 (14:55 +0100)]
tmpfiles: fix typo in error message

Fixes #4097.

As of current master, systemd-tmpfiles behaves correctly, apart from a trivial
typo. So let's tell github to close the bug.

With current git:

$ sudo SYSTEMD_LOG_LEVEL=debug build/systemd-tmpfiles --create `pwd`/test/tmpfiles.d/link-loop.conf
Successfully loaded SELinux database in 2.385ms, size on heap is 321K.
Reading config file "/home/zbyszek/src/systemd-work/test/tmpfiles.d/link-loop.conf".
Running create action for entry D /run/hello2
Found existing directory "/run/hello2".
"/run/hello2" has right mode 41777
Running create action for entry f /run/hello2/hello2.test
"/run/hello2/hello2.test" has been created.
"/run/hello2/hello2.test" has right mode 101777
chown "/run/hello2/hello2.test" to 0.84
Running create action for entry L /run/hello2/hello2.link
Found existing symlink "/run/hello2/hello2.link".
Running create action for entry z /run/hello2/hello2.test
"/run/hello2/hello2.test" has right mode 101777
chown "/run/hello2/hello2.test" to 0.0
Running create action for entry z /run/hello2/hello2.link
Skipping mode an owner fix for symlink /run/hello2/hello2.link.

and the permissions are:
$ ls -dl /run/hello2/ /run/hello2/*
drwxrwxrwt. 2 foo   bar    80 Nov 22 14:40 /run/hello2/
lrwxrwxrwx. 1 root  root   23 Nov 22 14:40 /run/hello2/hello2.link -> /run/hello2/hello2.test
-rwxrwxrwt. 1 root  root    0 Nov 22 14:40 /run/hello2/hello2.test

Everything seems correct.

6 years agotmpfiles: downgrade warning about duplicate line
Zbigniew Jędrzejewski-Szmek [Wed, 22 Nov 2017 13:19:13 +0000 (14:19 +0100)]
tmpfiles: downgrade warning about duplicate line

This happens occasionally, especially when moving lines between configuration files
in different packages, and usually is not a big deal.

6 years agoFail on unknown (alphanumerical) specifiers
Zbigniew Jędrzejewski-Szmek [Fri, 24 Nov 2017 11:19:40 +0000 (12:19 +0100)]
Fail on unknown (alphanumerical) specifiers

The code intentionally ignored unknown specifiers, treating them as text. This
needs to change because otherwise we can never add a new specifier in a backwards
compatible way. So just treat an unknown (potential) specifier as an error.

In principle this is a break of backwards compatibility, but the previous
behaviour was pretty much useless, since the expanded value could change every
time we add new specifiers, which we do all the time.

As a compromise for backwards compatibility, only fail on alphanumerical
characters. This should cover the most cases where an unescaped percent
character is used, like size=5% and such, which behave the same as before with
this patch. OTOH, this means that we will not be able to use non-alphanumerical
specifiers without breaking backwards compatibility again. I think that's an
acceptable compromise.

v2:
- add NEWS entry

v3:
- only fail on alphanumerical

6 years agoman: specifiers are allow for argument field in tmpfiles
Zbigniew Jędrzejewski-Szmek [Fri, 24 Nov 2017 11:05:03 +0000 (12:05 +0100)]
man: specifiers are allow for argument field in tmpfiles

6 years agounits: use SuccessExitStatus to ignore syntax errors in tmpfiles
Zbigniew Jędrzejewski-Szmek [Wed, 22 Nov 2017 13:18:25 +0000 (14:18 +0100)]
units: use SuccessExitStatus to ignore syntax errors in tmpfiles

This makes sense from the point of view of the whole distribution:
if there are some specific files that have syntax problems, or unknown
users or groups, or use unsupported features, failing the whole service
is not useful.

In particular, services with tmpfiles --boot should not be started after boot.
The premise of --boot is that there are actions which are only safe to do once
during boot, because the state evolves later through other means and re-running
the boot-time setup would destroy it. If services with --boot fail in the
initial transaction, they would be re-run later on when a unit which
(indirectly) depends on them is started, causing problems.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1507501.

(If we had a mode where a service would at most run once, and would not be
started in subsequent transactions, that'd be a good additional safeguard.
Using ExecStart=-... is a bit like that, but it causes all failure to be
ignored, which is too big of a hammer.)

6 years agotmpfiles: add a special return code for syntax failures
Zbigniew Jędrzejewski-Szmek [Wed, 22 Nov 2017 13:13:32 +0000 (14:13 +0100)]
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.

6 years agoMerge pull request #7237 from keszybz/growfs
Lennart Poettering [Fri, 1 Dec 2017 16:58:58 +0000 (17:58 +0100)]
Merge pull request #7237 from keszybz/growfs

Create and grow filesystems

6 years agoNEWS: update the text a bit (#7524)
Zbigniew Jędrzejewski-Szmek [Fri, 1 Dec 2017 15:25:19 +0000 (16:25 +0100)]
NEWS: update the text a bit (#7524)

This fixes various typos, removes some duplications, and adds a bit more
detail in the few places which are potential pitfalls for users.
Also change the way the paragraphs about new options begin, because having
a paragraph saying "Two new options have been added", and then bit lower
again "Two new options have been added" is confusing.

6 years agoMerge pull request #7481 from poettering/bpf-test-fix
Michael Biebl [Fri, 1 Dec 2017 12:52:32 +0000 (13:52 +0100)]
Merge pull request #7481 from poettering/bpf-test-fix

bpf-firewall: actually invoke BPF_PROG_ATTACH to check whether cgroup/bpf is available

6 years agomount-util: tape over name_to_handle_at() flakiness (#7517)
Lennart Poettering [Fri, 1 Dec 2017 11:59:16 +0000 (12:59 +0100)]
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

6 years agosd-bus: validate the message type (#7520)
Lennart Poettering [Fri, 1 Dec 2017 10:59:42 +0000 (11:59 +0100)]
sd-bus: validate the message type (#7520)

Now that sd_bus_message_new() is public API, we should insist on valid
message types.

6 years agosystemctl: don't use get_process_comm() on non-local PIDs (#7518)
Lennart Poettering [Fri, 1 Dec 2017 10:21:58 +0000 (11:21 +0100)]
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

6 years agoMerge pull request #7521 from yuwata/news-236
Zbigniew Jędrzejewski-Szmek [Fri, 1 Dec 2017 07:31:20 +0000 (08:31 +0100)]
Merge pull request #7521 from yuwata/news-236

NEWS update

6 years agoutil-lib: handle empty string in last_path_component
Zbigniew Jędrzejewski-Szmek [Thu, 30 Nov 2017 19:54:31 +0000 (20:54 +0100)]
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.

6 years agoNEWS: systemd-mount also support -G option
Yu Watanabe [Thu, 30 Nov 2017 19:49:21 +0000 (04:49 +0900)]
NEWS: systemd-mount also support -G option

6 years agoNEWS: fix typo
Yu Watanabe [Thu, 30 Nov 2017 19:48:57 +0000 (04:48 +0900)]
NEWS: fix typo

6 years agoman: add docs for systemd-growfs and systemd-makefs
Zbigniew Jędrzejewski-Szmek [Thu, 30 Nov 2017 11:55:00 +0000 (12:55 +0100)]
man: add docs for systemd-growfs and systemd-makefs

6 years agodissect-image: return error if results are ambiguous
Zbigniew Jędrzejewski-Szmek [Thu, 30 Nov 2017 11:09:36 +0000 (12:09 +0100)]
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.

6 years agoAdd x-systemd.growfs option for fstab
Zbigniew Jędrzejewski-Szmek [Wed, 29 Nov 2017 19:02:11 +0000 (20:02 +0100)]
Add x-systemd.growfs option for fstab

6 years agoAdd x-systemd.makefs option for fstab
Zbigniew Jędrzejewski-Szmek [Tue, 21 Nov 2017 22:18:05 +0000 (23:18 +0100)]
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.

6 years agofstab-generator: convert separate booleans to a flag field
Zbigniew Jędrzejewski-Szmek [Wed, 29 Nov 2017 14:49:25 +0000 (15:49 +0100)]
fstab-generator: convert separate booleans to a flag field

It's pretty unwieldy with just three flags, and I want to add more.

6 years agoAdd mkfs wrapper which first checks if the partition is empty
Zbigniew Jędrzejewski-Szmek [Sun, 26 Nov 2017 21:51:29 +0000 (22:51 +0100)]
Add mkfs wrapper which first checks if the partition is empty

6 years agogrowfs: add option parsing and --help/--version/--dry-run
Zbigniew Jędrzejewski-Szmek [Fri, 24 Nov 2017 20:34:36 +0000 (21:34 +0100)]
growfs: add option parsing and --help/--version/--dry-run

v2:
- use arg_target

6 years agoshared/dissect-image: fix return value for probe_filesystem()
Zbigniew Jędrzejewski-Szmek [Fri, 24 Nov 2017 20:31:47 +0000 (21:31 +0100)]
shared/dissect-image: fix return value for probe_filesystem()

blkid_new_probe_from_filename() sets errno, for example EPERM.

6 years agogrowfs: add support for resizing encrypted partitions
Zbigniew Jędrzejewski-Szmek [Tue, 21 Nov 2017 17:56:52 +0000 (18:56 +0100)]
growfs: add support for resizing encrypted partitions

6 years agoDefine CRYPT_LUKS in crypt-util.h
Zbigniew Jędrzejewski-Szmek [Wed, 29 Nov 2017 14:06:53 +0000 (15:06 +0100)]
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.

6 years agogrowfs: do not try to resize btrfs partitions smaller then 256MB
Zbigniew Jędrzejewski-Szmek [Tue, 21 Nov 2017 17:55:07 +0000 (18:55 +0100)]
growfs: do not try to resize btrfs partitions smaller then 256MB

This will not work, but the kernel does not give any useful message.

6 years agoAdd systemd-growfs tool
Zbigniew Jędrzejewski-Szmek [Mon, 23 Oct 2017 11:40:38 +0000 (13:40 +0200)]
Add systemd-growfs tool

6 years agoutil-lib: export cryptsetup logging glue function
Zbigniew Jędrzejewski-Szmek [Wed, 1 Nov 2017 14:56:25 +0000 (15:56 +0100)]
util-lib: export cryptsetup logging glue function

6 years agoutil-lib: add cleanup function for crypt_free
Zbigniew Jędrzejewski-Szmek [Thu, 2 Nov 2017 08:16:47 +0000 (09:16 +0100)]
util-lib: add cleanup function for crypt_free

6 years agoutil-lib: rename path_check_fstype to path_is_fs_type
Zbigniew Jędrzejewski-Szmek [Tue, 31 Oct 2017 15:13:05 +0000 (16:13 +0100)]
util-lib: rename path_check_fstype to path_is_fs_type

6 years agoutil-lib: rename fd_check_fstype to fd_is_fs_type
Zbigniew Jędrzejewski-Szmek [Tue, 31 Oct 2017 12:02:10 +0000 (13:02 +0100)]
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".

6 years agoutil-lib: use trailing slash in chase_symlinks, fd_is_mount_point, path_is_mount_point
Zbigniew Jędrzejewski-Szmek [Tue, 31 Oct 2017 10:08:30 +0000 (11:08 +0100)]
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.

6 years agoNEWS: some preliminary work for v236 (#7519)
Lennart Poettering [Thu, 30 Nov 2017 19:07:18 +0000 (20:07 +0100)]
NEWS: some preliminary work for v236 (#7519)

Totally not complete, but let's get this started.

6 years agoAdd a "RequiredForOnline=" Link attribute for .network files (#7347)
Mathieu Trudel-Lapierre [Thu, 30 Nov 2017 17:03:50 +0000 (12:03 -0500)]
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.

6 years agotest-string-util: add another test for stripping slashes
Zbigniew Jędrzejewski-Szmek [Wed, 1 Nov 2017 15:59:30 +0000 (16:59 +0100)]
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.

6 years agoAdd a helper for /dev/block/major:minor paths
Zbigniew Jędrzejewski-Szmek [Tue, 31 Oct 2017 10:30:40 +0000 (11:30 +0100)]
Add a helper for /dev/block/major:minor paths

6 years agoAdd a little helper to make /sys/dev/block/major:minor paths
Zbigniew Jędrzejewski-Szmek [Tue, 31 Oct 2017 08:37:15 +0000 (09:37 +0100)]
Add a little helper to make /sys/dev/block/major:minor paths

6 years agotest-mount-util: move test_path_is_mount_point here
Zbigniew Jędrzejewski-Szmek [Tue, 31 Oct 2017 09:52:30 +0000 (10:52 +0100)]
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.

6 years agocore/dbus-execute: actually set PassEnvironment= (#7510)
Yu Watanabe [Thu, 30 Nov 2017 11:34:58 +0000 (20:34 +0900)]
core/dbus-execute: actually set PassEnvironment= (#7510)

Follow-up for #7444.

6 years agoman: fix typo (#7511)
Yu Watanabe [Thu, 30 Nov 2017 11:02:20 +0000 (20:02 +0900)]
man: fix typo (#7511)

6 years agoFix SELinux labels in cgroup filesystem root directory (#7496)
Krzysztof Nowicki [Thu, 30 Nov 2017 10:59:29 +0000 (11:59 +0100)]
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.

6 years agocore: support upgrading from DynamicUser=0 to DynamicUser=1 for unit directories...
Lennart Poettering [Thu, 30 Nov 2017 10:52:39 +0000 (11:52 +0100)]
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.

6 years agoMerge pull request #7444 from poettering/dbus-no-spec
Yu Watanabe [Thu, 30 Nov 2017 05:50:36 +0000 (14:50 +0900)]
Merge pull request #7444 from poettering/dbus-no-spec

unit writing escaping fixes + related fixes and additions

6 years agoMerge pull request #7508 from poettering/journal-n-drop
Vito Caputo [Wed, 29 Nov 2017 22:05:21 +0000 (14:05 -0800)]
Merge pull request #7508 from poettering/journal-n-drop

journal: fix log message when dropping messages

6 years agojournal: fix log message when dropping messages
Lennart Poettering [Wed, 29 Nov 2017 21:11:59 +0000 (22:11 +0100)]
journal: fix log message when dropping messages

Fixes: #7506

6 years agobpf-firewall: actually invoke BPF_PROG_ATTACH to check whether cgroup/bpf is available
Lennart Poettering [Mon, 27 Nov 2017 11:42:40 +0000 (12:42 +0100)]
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

6 years agoupdate TODO
Lennart Poettering [Mon, 27 Nov 2017 11:42:35 +0000 (12:42 +0100)]
update TODO

6 years agoupdate TODO
Lennart Poettering [Wed, 22 Nov 2017 12:56:10 +0000 (13:56 +0100)]
update TODO

6 years agobus-unit-util: slightly tweak log output for unknown props
Lennart Poettering [Wed, 29 Nov 2017 19:07:08 +0000 (20:07 +0100)]
bus-unit-util: slightly tweak log output for unknown props

Pretty:

        Unknown assignment Foo=bar.

Prettier:

        Unknown assignment: Foo=bar

6 years agorun: rearrange error handling when adding unit properties
Lennart Poettering [Wed, 29 Nov 2017 19:05:22 +0000 (20:05 +0100)]
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).

6 years agobus-unit-util: add proper MemorySwapMax= serialization
Lennart Poettering [Wed, 29 Nov 2017 18:55:42 +0000 (19:55 +0100)]
bus-unit-util: add proper MemorySwapMax= serialization

Fixes: #7505

6 years agocore: accept MemorySwapMax= properties that are scaled, too
Lennart Poettering [Wed, 29 Nov 2017 18:55:01 +0000 (19:55 +0100)]
core: accept MemorySwapMax= properties that are scaled, too

Let's do what we already do for MemoryMax= and friends for
MemorySwapMax= too.

6 years agotty-ask-password-agent: drop NULL sentinel
Lennart Poettering [Wed, 29 Nov 2017 18:53:53 +0000 (19:53 +0100)]
tty-ask-password-agent: drop NULL sentinel

found by coccinelle

6 years agococcinelle: add a run-coccinelle.sh script that runs all scripts
Lennart Poettering [Wed, 29 Nov 2017 18:49:05 +0000 (19:49 +0100)]
coccinelle: add a run-coccinelle.sh script that runs all scripts

One day we should start running something like this as part of CI so
that non-well-formed commits are not even accepted...

6 years agococcinelle: fix IN_SET/!IN_SET scripts, and apply some changes it found
Lennart Poettering [Wed, 29 Nov 2017 12:05:24 +0000 (13:05 +0100)]
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.

6 years agoMerge pull request #7493 from keszybz/revert-revert
Lennart Poettering [Wed, 29 Nov 2017 17:56:26 +0000 (18:56 +0100)]
Merge pull request #7493 from keszybz/revert-revert

Revert "meson: drop rootprefix option"

6 years agoMerge pull request #7504 from keszybz/two-mkosi-ideas
Lennart Poettering [Wed, 29 Nov 2017 15:24:14 +0000 (16:24 +0100)]
Merge pull request #7504 from keszybz/two-mkosi-ideas

Two mkosi tweaks

6 years agoMerge pull request #7500 from poettering/journal-field-count
Lennart Poettering [Wed, 29 Nov 2017 15:21:48 +0000 (16:21 +0100)]
Merge pull request #7500 from poettering/journal-field-count

fix journald field counts

6 years agoAdd mkosi.output/ to .gitignore
Zbigniew Jędrzejewski-Szmek [Tue, 21 Nov 2017 17:52:15 +0000 (18:52 +0100)]
Add mkosi.output/ to .gitignore

It's not something that would ever be checked in, and mkosi along
with systemd, so this directory is likely to appear.

6 years agomkosi: do not build man pages
Zbigniew Jędrzejewski-Szmek [Tue, 31 Oct 2017 08:44:00 +0000 (09:44 +0100)]
mkosi: do not build man pages

6 years agomeson: emit a warning if rootprefix is set
Zbigniew Jędrzejewski-Szmek [Tue, 28 Nov 2017 20:46:53 +0000 (21:46 +0100)]
meson: emit a warning if rootprefix is set

It's printed at the end because it's the easiest to spot there.

When meson is upgraded to 0.43.1, we'll be able to use warning() instead.

6 years agotree-wide: use strv_isempty() instead of strv_length() == 0
Lennart Poettering [Wed, 29 Nov 2017 11:40:22 +0000 (12:40 +0100)]
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).

6 years agobus-unit-util: properly serialize EnvironmentFile= empty assignment
Lennart Poettering [Wed, 29 Nov 2017 10:33:26 +0000 (11:33 +0100)]
bus-unit-util: properly serialize EnvironmentFile= empty assignment

In that case we need to generate an empty array.

6 years agotests: fix description of TEST-14-MACHINE-ID
Lennart Poettering [Tue, 28 Nov 2017 20:25:49 +0000 (21:25 +0100)]
tests: fix description of TEST-14-MACHINE-ID

It used the same description as TEST-01, and that's hardly helpful.

6 years agocore: use safe_fclose() where we can
Lennart Poettering [Tue, 28 Nov 2017 20:24:20 +0000 (21:24 +0100)]
core: use safe_fclose() where we can

6 years agofileio: document why fileio-label.c and fileio.c are two different modules
Lennart Poettering [Mon, 27 Nov 2017 15:06:39 +0000 (16:06 +0100)]
fileio: document why fileio-label.c and fileio.c are two different modules

6 years agodocumentation: add document listing all unit file settings also supported for transie...
Lennart Poettering [Thu, 23 Nov 2017 19:26:02 +0000 (20:26 +0100)]
documentation: add document listing all unit file settings also supported for transient units

Unfortunately, there are far too many properties currently not
accessible to transient units. The first step to opening them all up is
to figure out which ones they are.

6 years agocore: open up all ExecXYZ= fields of service units to transient units
Lennart Poettering [Thu, 23 Nov 2017 16:58:34 +0000 (17:58 +0100)]
core: open up all ExecXYZ= fields of service units to transient units

Fixes: #7400

6 years agocore: never remove "transient" and "control" directories from unit search path
Lennart Poettering [Thu, 23 Nov 2017 16:45:58 +0000 (17:45 +0100)]
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)

6 years agocore: don't reference rescue/emergency targets in --user mode
Lennart Poettering [Thu, 23 Nov 2017 16:39:53 +0000 (17:39 +0100)]
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

6 years agocore: minor simplification
Lennart Poettering [Thu, 23 Nov 2017 16:39:25 +0000 (17:39 +0100)]
core: minor simplification

6 years agopath-lookup: LookupPathsFlags are a flags type, hence define it like one
Lennart Poettering [Thu, 23 Nov 2017 16:37:49 +0000 (17:37 +0100)]
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.

6 years agosystemctl: reword "needs-reload" message a bit
Lennart Poettering [Thu, 23 Nov 2017 16:36:30 +0000 (17:36 +0100)]
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.

6 years agocore: allow changing the description for units dynamically at runtime
Lennart Poettering [Wed, 22 Nov 2017 15:34:56 +0000 (16:34 +0100)]
core: allow changing the description for units dynamically at runtime

This makes "systemctl set-property foobar.service Description=waldo"
work.

See: #7245

6 years agotree-wide: generate SD_BUS_ERROR_INVALID_ARGS when we get invalid arguments on bus...
Lennart Poettering [Wed, 22 Nov 2017 14:15:11 +0000 (15:15 +0100)]
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.

6 years agocore: add proper escaping to writing of drop-ins/transient unit files
Lennart Poettering [Wed, 22 Nov 2017 14:03:51 +0000 (15:03 +0100)]
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)

6 years agologind: fix sysfs change trigger code
Lennart Poettering [Wed, 22 Nov 2017 11:10:39 +0000 (12:10 +0100)]
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.

6 years agogenerators: be more careful when writing unit settings that support specifier expansion
Lennart Poettering [Tue, 21 Nov 2017 19:09:31 +0000 (20:09 +0100)]
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.

6 years agocore: enable specifier expansion for What=/Where=/Type=/SourcePath= too
Lennart Poettering [Tue, 21 Nov 2017 19:03:51 +0000 (20:03 +0100)]
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.

6 years agocore: process C-style escapes in UnsetEnvironment=
Lennart Poettering [Tue, 21 Nov 2017 18:50:52 +0000 (19:50 +0100)]
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.

6 years agocore: use config_parse_unit_string_printf() for decoding RebootArgument=
Lennart Poettering [Tue, 21 Nov 2017 18:23:31 +0000 (19:23 +0100)]
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.

6 years agoCODING_STYLE: document the order in which unescaping + specifier expansion should...
Lennart Poettering [Tue, 21 Nov 2017 16:58:51 +0000 (17:58 +0100)]
CODING_STYLE: document the order in which unescaping + specifier expansion should be done

6 years agospecifier: unify specifier implementations for user-related specifiers
Lennart Poettering [Tue, 21 Nov 2017 16:57:56 +0000 (17:57 +0100)]
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.

6 years agospecifier: add helper for escaping '%' characters to avoid making them subject for...
Lennart Poettering [Tue, 21 Nov 2017 16:52:31 +0000 (17:52 +0100)]
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.

6 years agostring-util: update strreplace() a bit, use GREEDY_REALLOC()
Lennart Poettering [Tue, 21 Nov 2017 18:38:49 +0000 (19:38 +0100)]
string-util: update strreplace() a bit, use GREEDY_REALLOC()

6 years agocore: drop specifier expansion when parsing transient dbus properties
Lennart Poettering [Tue, 21 Nov 2017 16:32:01 +0000 (17:32 +0100)]
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.

6 years agojournald: correct field counts
Lennart Poettering [Wed, 29 Nov 2017 10:37:21 +0000 (11:37 +0100)]
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.

6 years agojournal: driver messages can now contain object fields, account for that
Lennart Poettering [Wed, 29 Nov 2017 10:36:22 +0000 (11:36 +0100)]
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.

6 years agoMerge pull request #7492 from keszybz/coverity-fixes
Yu Watanabe [Wed, 29 Nov 2017 03:50:49 +0000 (12:50 +0900)]
Merge pull request #7492 from keszybz/coverity-fixes

A few more cleanups based on coverity and valgrind

6 years agoudev/collect: use _cleanup_ in one more place
Zbigniew Jędrzejewski-Szmek [Tue, 28 Nov 2017 12:26:15 +0000 (13:26 +0100)]
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.

6 years agoudev/collect: remove dead conditional
Zbigniew Jędrzejewski-Szmek [Tue, 28 Nov 2017 12:18:09 +0000 (13:18 +0100)]
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.

6 years agojournal: avoid undefined behaviour in float division by 0.0
Zbigniew Jędrzejewski-Szmek [Tue, 28 Nov 2017 12:11:35 +0000 (13:11 +0100)]
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.

6 years agonetworkd: fix memleak of Rules
Zbigniew Jędrzejewski-Szmek [Tue, 28 Nov 2017 12:02:33 +0000 (13:02 +0100)]
networkd: fix memleak of Rules

This was the issue mentioned in 93f9da6e0a.

6 years agojournal: use new helpers with journal_file_close
Zbigniew Jędrzejewski-Szmek [Tue, 28 Nov 2017 11:40:14 +0000 (12:40 +0100)]
journal: use new helpers with journal_file_close

journal_file_close_set() is not necessary anymore.

6 years agojournal-remote: add helper function and use hashmap_free_with_destructor
Zbigniew Jędrzejewski-Szmek [Tue, 28 Nov 2017 11:38:15 +0000 (12:38 +0100)]
journal-remote: add helper function and use hashmap_free_with_destructor