chiark / gitweb /
elogind.git
5 years agomeson: fix indentation for systemd-time-sync-wait(5) entries
Zbigniew Jędrzejewski-Szmek [Mon, 16 Apr 2018 15:08:21 +0000 (17:08 +0200)]
meson: fix indentation for systemd-time-sync-wait(5) entries

Those files should not be updated manually, because then automatic updates
contain spurious "changes".

5 years agopolkit: normalize exit values of polkit_agent_open_if_enabled()
Lennart Poettering [Mon, 16 Apr 2018 19:37:12 +0000 (21:37 +0200)]
polkit: normalize exit values of polkit_agent_open_if_enabled()

It's strange eating up the errors here, hence don't. Let's leave this
to the caller.

5 years agopath-util: Finish DEFAULT_PATH_NULSTR with an extra NUL (#8745)
Filipe Brandenburger [Wed, 18 Apr 2018 05:46:03 +0000 (22:46 -0700)]
path-util: Finish DEFAULT_PATH_NULSTR with an extra NUL (#8745)

The NULSTR_FOREACH iterator needs to see an empty string at the end, so
we need to insert an extra NUL explicitly.

Also update PATH0_BIN_SBIN(x) to include an extra NUL terminator, rename
it to PATH_BIN_SBIN_NULSTR(x), which is more consistent with the similar
CONF_PATHS_NULSTR(x) macro.

Fixes: 5008da1ec1cf2cf8c15b702c4052e3a49583095d
5 years agobus-util: introduce bus_open_system_watch_bind_with_description()
Yu Watanabe [Tue, 17 Apr 2018 14:37:52 +0000 (23:37 +0900)]
bus-util: introduce bus_open_system_watch_bind_with_description()

Similar to 56fbd7187a5af44a90c258fbeb1f17114f226bb3, this adds
bus_open_system_watch_bind_with_description() to set description
for busses.

5 years agobasic/copy: fix awkward sentence
Zbigniew Jędrzejewski-Szmek [Fri, 13 Apr 2018 10:40:11 +0000 (12:40 +0200)]
basic/copy: fix awkward sentence

5 years agobasic/unit-name: remove duplicate check
Zbigniew Jędrzejewski-Szmek [Fri, 13 Apr 2018 10:38:11 +0000 (12:38 +0200)]
basic/unit-name: remove duplicate check

The check that was right below already covers this case.

5 years agologind: enable limiting of user session scopes using pam context objects (#8397)
Jan Synacek [Tue, 17 Apr 2018 14:42:44 +0000 (16:42 +0200)]
logind: enable limiting of user session scopes using pam context objects (#8397)

5 years agotest-execute: make find invocation a bit more efficent, increase timeout
Zbigniew Jędrzejewski-Szmek [Wed, 11 Apr 2018 14:50:48 +0000 (16:50 +0200)]
test-execute: make find invocation a bit more efficent, increase timeout

We go through the whole file system, so this test can take arbitrary time.  But
this test is still quite useful, so let's at least try to make it more efficent
by not descending at all into the directories we would filter out later on
anyway.

Also increase the timeout, in case the previous step doesn't help enough.

5 years agosystemd: do not require absolute paths in ExecStart
Zbigniew Jędrzejewski-Szmek [Sun, 25 Mar 2018 18:50:15 +0000 (20:50 +0200)]
systemd: do not require absolute paths in ExecStart

Absolute paths make everything simple and quick, but sometimes this requirement
can be annoying. A good example is calling 'test', which will be located in
/usr/bin/ or /bin depending on the distro. The need the provide the full path
makes it harder a portable unit file in such cases.

This patch uses a fixed search path (DEFAULT_PATH which was already used as the
default value of $PATH), and if a non-absolute file name is found, it is
immediately resolved to a full path using this search path when the unit is
loaded. After that, everything behaves as if an absolute path was specified. In
particular, the executable must exist when the unit is loaded.

5 years agotime-wait-sync: use watchfile to coordinate with timesyncd
Peter A. Bigot [Mon, 9 Apr 2018 18:39:16 +0000 (13:39 -0500)]
time-wait-sync: use watchfile to coordinate with timesyncd

Systems that have an accurate real-time clock may have an initial
unsynchronized time that is close enough to the synchronized time that
the final adjustment doesn't trigger a waking "clock set" event.  Have
timesyncd touch a file in its runtime directory as a secondary signal
for synchronization.  Continue to support the timerfd-based trigger as a
sufficient condition when the watchfile is not present.

Closes issue #8683

5 years agounit-name: add new unit_name_build_from_type() helper
Lennart Poettering [Thu, 22 Feb 2018 17:24:57 +0000 (18:24 +0100)]
unit-name: add new unit_name_build_from_type() helper

The new helper is much like unit_name_build() but expects a UnitType
value instead of a suffix.

5 years agocopy: rearrange flags field definition
Lennart Poettering [Fri, 23 Mar 2018 17:27:31 +0000 (18:27 +0100)]
copy: rearrange flags field definition

Let's use the usual 1U << 0,1,2,3,4 spelling for definiting flags enums.

5 years agocopy: reduce number of checks
Lennart Poettering [Fri, 23 Mar 2018 17:26:58 +0000 (18:26 +0100)]
copy: reduce number of checks

We check max_bytes twice here, let's simplify that, and reduce one level
of indentation.

5 years agocopy: drop _unlikely_() that isn't obviously the case
Lennart Poettering [Fri, 23 Mar 2018 17:24:07 +0000 (18:24 +0100)]
copy: drop _unlikely_() that isn't obviously the case

If a tool only invokes copy_bytes() a single time the _unlikely_() will always be
wrong, and is hence not useful. Let's drop it and let the compiler
figure our what to do, instead of misleading it.

Also, some coding style imprvoements.

5 years agocopy: hide in copy_bytes() the strange way splice() handles O_NONBLOCK
Lennart Poettering [Fri, 23 Mar 2018 16:44:15 +0000 (17:44 +0100)]
copy: hide in copy_bytes() the strange way splice() handles O_NONBLOCK

splice() ignores O_NONBLOCK on pipes but not on other fds. Let's handle
that properly, and query O_ONBLOCK manually in that case, ensuring
systematic behaviour in either case.

5 years agocopy: extend copy_bytes() a bit
Lennart Poettering [Fri, 23 Mar 2018 15:41:42 +0000 (16:41 +0100)]
copy: extend copy_bytes() a bit

Optionally, when we copy between fds with simple read/write, let's
return any remaining data we already read into the buffer if write
fails. This is useful to allow callers to use the read data otherwise,
perhaps implementing a different fallback for copying.

5 years agocopy: tweak reflink logic in copy_bytes() a bit
Lennart Poettering [Fri, 23 Mar 2018 15:36:56 +0000 (16:36 +0100)]
copy: tweak reflink logic in copy_bytes() a bit

Let's use btrfs_clone_range() if partial copies are desired. And use
btrfs_reflink() only for full-file reflinks.

5 years agocopy: add brief comment to copy_bytes() explaining its return values
Lennart Poettering [Fri, 9 Mar 2018 21:44:47 +0000 (22:44 +0100)]
copy: add brief comment to copy_bytes() explaining its return values

5 years agomacro: don't rely on C's downgrade-to-bool feature for numeric comparisons
Lennart Poettering [Wed, 11 Apr 2018 19:36:52 +0000 (21:36 +0200)]
macro: don't rely on C's downgrade-to-bool feature for numeric comparisons

5 years agoupdate TODO
Lennart Poettering [Fri, 6 Apr 2018 16:57:48 +0000 (18:57 +0200)]
update TODO

5 years agopath-util: document a few other special cases for last_path_component()
Lennart Poettering [Thu, 5 Apr 2018 16:00:39 +0000 (18:00 +0200)]
path-util: document a few other special cases for last_path_component()

5 years agoprocess-util: add TAKE_PID(), similar to TAKE_PTR/TAKE_FD, but for child process...
Lennart Poettering [Tue, 27 Mar 2018 13:01:02 +0000 (15:01 +0200)]
process-util: add TAKE_PID(), similar to TAKE_PTR/TAKE_FD, but for child process PIDs

5 years agoutil: introduce typesafe_qsort(), a typesafe version of qsort()/qsort_safe()
Lennart Poettering [Tue, 27 Mar 2018 12:56:29 +0000 (14:56 +0200)]
util: introduce typesafe_qsort(), a typesafe version of qsort()/qsort_safe()

It does two things:

1. It derives the element size from the array argument type

2. It derives the right type for the function from the array argument
   type

Using this macro call should make the invocations of qsort() quite a bit
safer.

5 years agoshared/sleep-config: rename misnamed function
Zbigniew Jędrzejewski-Szmek [Wed, 11 Apr 2018 07:27:32 +0000 (09:27 +0200)]
shared/sleep-config: rename misnamed function

5 years agoshared/sleep-config: return a custom message when not enough swap for hibernation
Zbigniew Jędrzejewski-Szmek [Wed, 11 Apr 2018 06:51:06 +0000 (08:51 +0200)]
shared/sleep-config: return a custom message when not enough swap for hibernation

$ sudo swapoff -av
swapoff /dev/vda4
$ sudo systemctl hibernate
Failed to hibernate system via logind: Not enough swap space for hibernation

Fixes #6729.

5 years agologind: refuse operations if the target unit is masked or unavailable
Zbigniew Jędrzejewski-Szmek [Tue, 10 Apr 2018 11:15:00 +0000 (13:15 +0200)]
logind: refuse operations if the target unit is masked or unavailable

If hibernate.target is masked, and systemctl hibernate is invoked, havoc ensues.
logind starts the hibernation operation, but then doesn't go through with it;
gnome-shell segfaults. Let's be nice to the user and refuse doing anything in
that case.

$ sudo systemctl mask hibernate.target
$ busctl call org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager CanHibernate
s "no"
$ sudo systemctl hibernate
Failed to hibernate system via logind: Access denied
Failed to start hibernate.target: Unit hibernate.target is masked.

https://bugzilla.redhat.com/show_bug.cgi?id=1468003#c4

5 years agoshared/sleep-fix: fix check if s-then-h is possible
Zbigniew Jędrzejewski-Szmek [Tue, 10 Apr 2018 09:39:14 +0000 (11:39 +0200)]
shared/sleep-fix: fix check if s-then-h is possible

can_sleep() returns 0 if the operation is impossible, but
the code assumed that negative is returned in that case,
in effect reporting s2h was possible even if hibernation or
suspend were not possible.

5 years agoshared/sleep-config: get rid of explicit allocation size calculation
Zbigniew Jędrzejewski-Szmek [Tue, 10 Apr 2018 09:23:46 +0000 (11:23 +0200)]
shared/sleep-config: get rid of explicit allocation size calculation

5 years agotree-wide: drop license boilerplate
Zbigniew Jędrzejewski-Szmek [Fri, 6 Apr 2018 16:58:55 +0000 (18:58 +0200)]
tree-wide: drop license boilerplate

Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.

5 years agoupdate TODO
Lennart Poettering [Thu, 5 Apr 2018 11:07:31 +0000 (13:07 +0200)]
update TODO

5 years agotmpfiles: add a new return code for "operational failure" when processing
Zbigniew Jędrzejewski-Szmek [Thu, 29 Mar 2018 14:19:33 +0000 (16:19 +0200)]
tmpfiles: add a new return code for "operational failure" when processing

Things can fail, and we have no control over it:
- file system issues (immutable bits, file system errors, MAC refusals, etc)
- kernel refusing certain arguments when writing to /proc/sys or /sys
Let's add a new code for the case where we parsed configuration but failed
to execute it because of external errors.

5 years agotree-wide: use TAKE_PTR() and TAKE_FD() macros
Yu Watanabe [Thu, 5 Apr 2018 05:26:26 +0000 (14:26 +0900)]
tree-wide: use TAKE_PTR() and TAKE_FD() macros

5 years agofs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)
Lennart Poettering [Mon, 26 Mar 2018 14:34:54 +0000 (16:34 +0200)]
fs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)

Let's optimize things, and let the kernel chase the paths if none of the
features chase_symlinks() offers are actually used.

5 years agofs-util: add calls that combine chase_symlinks() and open()/opendir() in one
Lennart Poettering [Mon, 26 Mar 2018 12:15:43 +0000 (14:15 +0200)]
fs-util: add calls that combine chase_symlinks() and open()/opendir() in one

This is useful when opening files within disk images, as we'll then take
the relative root directory properly into account.

5 years agofd-util: introduce fd_reopen() helper for reopening an fd
Lennart Poettering [Mon, 26 Mar 2018 11:25:51 +0000 (13:25 +0200)]
fd-util: introduce fd_reopen() helper for reopening an fd

We have the same code for this in place at various locations, let's
unify that. Also, let's repurpose test-fs-util.c as a test for this new
helper cal..

5 years agoupdate TODO
Lennart Poettering [Thu, 29 Mar 2018 15:47:03 +0000 (17:47 +0200)]
update TODO

5 years agosd-bus: allow description to be set for system/user busses (#8594)
Zbigniew Jędrzejewski-Szmek [Thu, 29 Mar 2018 14:14:11 +0000 (16:14 +0200)]
sd-bus: allow description to be set for system/user busses (#8594)

sd_bus_open/sd_bus_open_system/sd_bus_open_user are convenient, but
don't allow the description to be set. After they return, the bus is
is already started, and sd_bus_set_description() fails with -EBUSY.
It would be possible to allow sd_bus_set_description() to update the
description "live", but messages are already emitted from sd_bus_open
functions, so it's better to allow the description to be set in
sd_bus_open/sd_bus_open_system/sd_bus_open_user.

Fixes message like:
Bus n/a: changing state UNSET → OPENING

5 years agomeson_options.txt: Fix some trailing whitespaces in mask blocks.
Sven Eden [Fri, 29 Jun 2018 05:49:28 +0000 (07:49 +0200)]
meson_options.txt: Fix some trailing whitespaces in mask blocks.

5 years agosleep: Move the error level debugging for write_mode and write_state
Mario Limonciello [Thu, 29 Mar 2018 13:56:23 +0000 (08:56 -0500)]
sleep: Move the error level debugging for write_mode and write_state

This makes it more consistent with other code used in the file.

Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
5 years agosleep: Add support for setting a disk offset when hibernating
Mario Limonciello [Thu, 8 Mar 2018 08:41:50 +0000 (02:41 -0600)]
sleep: Add support for setting a disk offset when hibernating

The Linux kernel is adding support for configuring the offset
into a disk.  This allows swapfiles to be more usable as users
will no longer need to set the offset on their kernel command
line.

Use this API in systemd when hibernating as well.

Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
5 years agosd-event: use _cleanup_ to manage temporary references
Zbigniew Jędrzejewski-Szmek [Sat, 7 Apr 2018 17:14:37 +0000 (19:14 +0200)]
sd-event: use _cleanup_ to manage temporary references

5 years agoupdate TODO
Lennart Poettering [Thu, 5 Apr 2018 11:07:31 +0000 (13:07 +0200)]
update TODO

5 years agotmpfiles: add a new return code for "operational failure" when processing
Zbigniew Jędrzejewski-Szmek [Thu, 29 Mar 2018 14:19:33 +0000 (16:19 +0200)]
tmpfiles: add a new return code for "operational failure" when processing

Things can fail, and we have no control over it:
- file system issues (immutable bits, file system errors, MAC refusals, etc)
- kernel refusing certain arguments when writing to /proc/sys or /sys
Let's add a new code for the case where we parsed configuration but failed
to execute it because of external errors.

5 years agotree-wide: use TAKE_PTR() and TAKE_FD() macros
Yu Watanabe [Thu, 5 Apr 2018 05:26:26 +0000 (14:26 +0900)]
tree-wide: use TAKE_PTR() and TAKE_FD() macros

5 years agobus-util: fix a meaningless assertion
Yu Watanabe [Thu, 29 Mar 2018 12:20:30 +0000 (21:20 +0900)]
bus-util: fix a meaningless assertion

5 years agofs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)
Lennart Poettering [Mon, 26 Mar 2018 14:34:54 +0000 (16:34 +0200)]
fs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)

Let's optimize things, and let the kernel chase the paths if none of the
features chase_symlinks() offers are actually used.

5 years agofs-util: add calls that combine chase_symlinks() and open()/opendir() in one
Lennart Poettering [Mon, 26 Mar 2018 12:15:43 +0000 (14:15 +0200)]
fs-util: add calls that combine chase_symlinks() and open()/opendir() in one

This is useful when opening files within disk images, as we'll then take
the relative root directory properly into account.

5 years agofd-util: introduce fd_reopen() helper for reopening an fd
Lennart Poettering [Mon, 26 Mar 2018 11:25:51 +0000 (13:25 +0200)]
fd-util: introduce fd_reopen() helper for reopening an fd

We have the same code for this in place at various locations, let's
unify that. Also, let's repurpose test-fs-util.c as a test for this new
helper cal..

5 years agounits: use `systemctl exit` to kill the user manager (#8648)
Filipe Brandenburger [Wed, 4 Apr 2018 09:14:37 +0000 (02:14 -0700)]
units: use `systemctl exit` to kill the user manager (#8648)

Use `systemctl --user --force exit` to implement the systemd-exit
user service.

This removes our dependence on an external `kill` binary and the
concerns about whether they recognize SIGRTMIN+n by name or what their
interpretation of SIGRTMIN is.

Tested: `systemctl --user start systemd-exit.service` kills the
  `systemd --user` instance for my user.

5 years agooss-fuzz: Fallback to `ninja-build` when available (#8641)
Filipe Brandenburger [Wed, 4 Apr 2018 07:32:59 +0000 (00:32 -0700)]
oss-fuzz: Fallback to `ninja-build` when available (#8641)

The ninja binary is deployed as `ninja-build` in older distros such as
RHEL 7/CentOS 7.  Detect that and use `ninja-build` instead of `ninja`
when it's available.

5 years agoupdate TODO
Lennart Poettering [Thu, 29 Mar 2018 15:47:03 +0000 (17:47 +0200)]
update TODO

5 years agocore: skip the removal of cgroups in the TEST_RUN_MINIMAL mode (#8622)
Evgeny Vereshchagin [Tue, 3 Apr 2018 13:04:22 +0000 (16:04 +0300)]
core: skip the removal of cgroups in the TEST_RUN_MINIMAL mode (#8622)

When `systemd` is run in the TEST_RUN_MINIMAL mode, it doesn't really
set up cgroups, so it shouldn't try to remove anything.

Closes https://github.com/systemd/systemd/issues/8474.

5 years agosd-bus: allow description to be set for system/user busses (#8594)
Zbigniew Jędrzejewski-Szmek [Thu, 29 Mar 2018 14:14:11 +0000 (16:14 +0200)]
sd-bus: allow description to be set for system/user busses (#8594)

sd_bus_open/sd_bus_open_system/sd_bus_open_user are convenient, but
don't allow the description to be set. After they return, the bus is
is already started, and sd_bus_set_description() fails with -EBUSY.
It would be possible to allow sd_bus_set_description() to update the
description "live", but messages are already emitted from sd_bus_open
functions, so it's better to allow the description to be set in
sd_bus_open/sd_bus_open_system/sd_bus_open_user.

Fixes message like:
Bus n/a: changing state UNSET → OPENING

5 years agotree-wide: remove unused variables (#8612)
Yu Watanabe [Thu, 29 Mar 2018 10:50:50 +0000 (19:50 +0900)]
tree-wide: remove unused variables (#8612)

5 years agoRename suspend-to-hibernate to suspend-then-hibernate
Mario Limonciello [Wed, 28 Mar 2018 16:00:06 +0000 (11:00 -0500)]
Rename suspend-to-hibernate to suspend-then-hibernate

Per some discussion with Gnome folks, they would prefer this name
as it's more descriptive of what's happening.

5 years agomachine-image,mount-setup: minor coding style fixes
Lennart Poettering [Wed, 28 Mar 2018 15:07:42 +0000 (17:07 +0200)]
machine-image,mount-setup: minor coding style fixes

5 years agoinhibit: make use of EXIT_SUCCESS where appropriate
Lennart Poettering [Tue, 27 Mar 2018 12:58:21 +0000 (14:58 +0200)]
inhibit: make use of EXIT_SUCCESS where appropriate

5 years agoutil: check for overflows in xbsearch_r()
Lennart Poettering [Tue, 27 Mar 2018 12:56:04 +0000 (14:56 +0200)]
util: check for overflows in xbsearch_r()

5 years agoupdate TODO
Lennart Poettering [Tue, 20 Mar 2018 19:26:15 +0000 (20:26 +0100)]
update TODO

5 years agodoc: merge docs/ dir → doc/
Lennart Poettering [Wed, 28 Mar 2018 14:58:37 +0000 (16:58 +0200)]
doc: merge docs/ dir → doc/

It's weird having two subdirs for documentation, let's unify this in
one.

5 years agobus-util: add flags for bus_map_all_properties() (#8546)
Yu Watanabe [Wed, 28 Mar 2018 11:37:27 +0000 (20:37 +0900)]
bus-util: add flags for bus_map_all_properties() (#8546)

This adds flags BUS_MAP_STRDUP and BUS_MAP_BOOLEAN_AS_BOOL.
If BUS_MAP_STRDUP is set, then each "s" message is duplicated.
If BUS_MAP_BOOLEAN_AS_BOOL is set, then each "b" message is
written to a bool pointer.

Follow-up for #8488.
See https://github.com/systemd/systemd/pull/8488#discussion_r175816270.

5 years agocore: dont't remount /sys/fs/cgroup for relabel if not needed (#8595)
Krzysztof Nowicki [Wed, 28 Mar 2018 11:36:33 +0000 (13:36 +0200)]
core: dont't remount /sys/fs/cgroup for relabel if not needed (#8595)

The initial fix for relabelling the cgroup filesystem for
SELinux delivered in commit 8739f23e3 was based on the assumption that
the cgroup filesystem is already populated once mount_setup() is
executed, which was true for my system. What I wasn't aware is that this
is the case only when another instance of systemd was running before
this one, which can happen if systemd is used in the initrd (for ex. by
dracut).

In case of a clean systemd start-up the cgroup filesystem is actually
being populated after mount_setup() and does not need relabelling as at
that moment the SELinux policy is already loaded. Since however the root
cgroup filesystem was remounted read-only in the meantime this operation
will now fail.

To fix this check for the filesystem mount flags before relabelling and
only remount ro->rw->ro if necessary and leave the filesystem read-write
otherwise.

Fixes #7901.

5 years agoNEWS: Warn about predictable network naming changes
Stuart Hayes [Wed, 14 Feb 2018 20:44:47 +0000 (15:44 -0500)]
NEWS: Warn about predictable network naming changes

5 years agoFix compilation w/o smack (#8593)
Zbigniew Jędrzejewski-Szmek [Wed, 28 Mar 2018 10:54:26 +0000 (12:54 +0200)]
Fix compilation w/o smack (#8593)

5 years agotree-wide: add bsearch_safe and use where appropriate
Zbigniew Jędrzejewski-Szmek [Sun, 25 Mar 2018 20:43:43 +0000 (22:43 +0200)]
tree-wide: add bsearch_safe and use where appropriate

Should fix #8557.

5 years agofuzz-unit-file: add __has_feature(memory_sanitizer) when skipping ListenNetlink=
Zbigniew Jędrzejewski-Szmek [Sun, 25 Mar 2018 20:26:13 +0000 (22:26 +0200)]
fuzz-unit-file: add __has_feature(memory_sanitizer) when skipping ListenNetlink=

https://clang.llvm.org/docs/MemorySanitizer.html#id5 documents this
check as the way to detect MemorySanitizer at compilation time. We
only need to skip the test if MemorySanitizer is used.

Also, use this condition in cg_slice_to_path(). There, the code that is
conditionalized is not harmful in any way (it's just unnecessary), so remove
the FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION condition.

Fixes #8482.

5 years agolabel: rework label_fix() implementations (#8583)
Lennart Poettering [Tue, 27 Mar 2018 05:38:26 +0000 (07:38 +0200)]
label: rework label_fix() implementations (#8583)

This reworks the SELinux and SMACK label fixing calls in a number of
ways:

1. The two separate boolean arguments of these functions are converted
   into a flags type LabelFixFlags.

2. The operations are now implemented based on O_PATH. This should
   resolve TTOCTTOU races between determining the label for the file
   system object and applying it, as it it allows to pin the object
   while we are operating on it.

3. When changing a label fails we'll query the label previously set, and
   if matches what we want to set anyway we'll suppress the error.

Also, all calls to label_fix() are now (void)ified, when we ignore the
return values.

Fixes: #8566
5 years agofs-util: add new CHASE_TRAIL_SLASH flag for chase_symlinks()
Lennart Poettering [Thu, 22 Mar 2018 18:54:24 +0000 (19:54 +0100)]
fs-util: add new CHASE_TRAIL_SLASH flag for chase_symlinks()

This rearranges chase_symlinks() a bit: if no special flags are
specified it will now revert to behaviour before
b12d25a8d631af00b200e7aa9dbba6ba4a4a59ff. However, if the new
CHASE_TRAIL_SLASH flag is specified it will follow the behaviour
introduced by that commit.

I wasn't sure which one to make the beaviour that requires specification
of a flag to enable. I opted to make the "append trailing slash"
behaviour the one to enable by a flag, following the thinking that the
function should primarily be used to generate a normalized path, and I
am pretty sure a path without trailing slash is the more "normalized"
one, as the trailing slash is not really a part of it, but merely a
"decorator" that tells various system calls to generate ENOTDIR if the
path doesn't refer to a path.

Or to say this differently: if the slash was part of normalization then
we really should add it in all cases when the final path is a directory,
not just when the user originally specified it.

Fixes: #8544
Replaces: #8545

5 years agoman: add a note about $XDG_SEAT and $XDG_VTNR to pam_systemd(8)
Zbigniew Jędrzejewski-Szmek [Fri, 23 Mar 2018 12:15:19 +0000 (13:15 +0100)]
man: add a note about $XDG_SEAT and $XDG_VTNR to pam_systemd(8)

Issue #6499 requests that a mention that those varibles can be set in the
environment is added. But the man page already says that. There isn't much
detail, but a man page does not need to and in this case should not include
all the details. Instead a note is added that those vars can be derived from
$DISPLAY.

Closes #6499.

5 years agoman: add missing headers to glib-event-glue.c
Zbigniew Jędrzejewski-Szmek [Wed, 21 Mar 2018 15:38:51 +0000 (16:38 +0100)]
man: add missing headers to glib-event-glue.c

5 years agoman: drop license header in glib-event-glue.c
Zbigniew Jędrzejewski-Szmek [Wed, 21 Mar 2018 19:02:49 +0000 (20:02 +0100)]
man: drop license header in glib-event-glue.c

We're moving towards just SPDX license identifiers, and the boilerplate
is especially annoying in a man page. Also adjust to the smaller indentation
to make the code fit better on a page.

5 years agotree-wide: warn when a directory path already exists but has bad mode/owner/type
Zbigniew Jędrzejewski-Szmek [Thu, 22 Mar 2018 12:03:41 +0000 (13:03 +0100)]
tree-wide: warn when a directory path already exists but has bad mode/owner/type

When we are attempting to create directory somewhere in the bowels of /var/lib
and get an error that it already exists, it can be quite hard to diagnose what
is wrong (especially for a user who is not aware that the directory must have
the specified owner, and permissions not looser than what was requested). Let's
print a warning in most cases. A warning is appropriate, because such state is
usually a sign of borked installation and needs to be resolved by the adminstrator.

$ build/test-fs-util

Path "/tmp/test-readlink_and_make_absolute" already exists and is not a directory, refusing.
   (or)
Directory "/tmp/test-readlink_and_make_absolute" already exists, but has mode 0775 that is too permissive (0755 was requested), refusing.
   (or)
Directory "/tmp/test-readlink_and_make_absolute" already exists, but is owned by 1001:1000 (1000:1000 was requested), refusing.

Assertion 'mkdir_safe(tempdir, 0755, getuid(), getgid(), MKDIR_WARN_MODE) >= 0' failed at ../src/test/test-fs-util.c:320, function test_readlink_and_make_absolute(). Aborting.

No functional change except for the new log lines.

5 years agobasic/mkdir: convert bool flag to enum
Zbigniew Jędrzejewski-Szmek [Thu, 22 Mar 2018 11:38:01 +0000 (12:38 +0100)]
basic/mkdir: convert bool flag to enum

In preparation for subsequent changes...

5 years agotests: skip udev-test when perl is not installed
Zbigniew Jędrzejewski-Szmek [Thu, 22 Mar 2018 07:34:21 +0000 (08:34 +0100)]
tests: skip udev-test when perl is not installed

5 years agotree-wide: tabs suck (#8527)
Lennart Poettering [Fri, 23 Mar 2018 14:21:35 +0000 (15:21 +0100)]
tree-wide: tabs suck (#8527)

5 years agologind: drop obsolete comment
Lennart Poettering [Wed, 21 Mar 2018 18:06:59 +0000 (19:06 +0100)]
logind: drop obsolete comment

The code matching this comment was removed in
a50df72b37ce2a7caf7775c70d18c3f9504b9e80 in 2014, let's drop the comment
too.

5 years agologind: use manager_get_user_by_pid() where appropriate
Lennart Poettering [Wed, 21 Mar 2018 18:06:21 +0000 (19:06 +0100)]
logind: use manager_get_user_by_pid() where appropriate

The current code reimplemented something like the
manager_get_user_by_pid() logic on its own, manually. Let's unify this.

5 years agologind: rework manager_get_{user|session}_by_pid() a bit
Lennart Poettering [Wed, 21 Mar 2018 18:04:45 +0000 (19:04 +0100)]
logind: rework manager_get_{user|session}_by_pid() a bit

Let's make sure we always initialize the return value if we return
non-negative.

Just a matter of coding style: we should always initialize our return
values when we return >= 0, and leave them unclobbered if we return < 0.

5 years agoconf-parse: small prettification
Lennart Poettering [Fri, 23 Feb 2018 19:50:22 +0000 (20:50 +0100)]
conf-parse: small prettification

Let's use first_word() instead of startswith(), it's more explanatory
and a bit more correct. Also, let's use the return value instead of
adding +9 when looking for the second part of the directive.

5 years agoconf-parser: let's explicitly deprecate .include in unit files
Lennart Poettering [Fri, 23 Feb 2018 19:46:38 +0000 (20:46 +0100)]
conf-parser: let's explicitly deprecate .include in unit files

.include lines are already deprecated somewhat, and for example
explicitly not mentioned in the documentation for this reason. Let's get
one step further and generatea warning when we encounter them (but still
process them).

Why are they deprecated? Because they are semantically awful — they
complicate stat() based mtime checks for configuration files and they
allow arbitrary loops we currently have zero protection against and
really shouldn't have to have.

5 years agoparse-util: similar to safe_atou16_full() add safe_atou_full()
Lennart Poettering [Wed, 21 Mar 2018 21:31:40 +0000 (22:31 +0100)]
parse-util: similar to safe_atou16_full() add safe_atou_full()

What's good for uint16_t is also good for unsigned.

This is preparation for: #8140

5 years agoparse-util: introduce safe_atou16_full()
Lennart Poettering [Wed, 21 Mar 2018 21:27:19 +0000 (22:27 +0100)]
parse-util: introduce safe_atou16_full()

safe_atou16_full() is like safe_atou16() but also takes a base
parameter. safe_atou16() is then implemented as inline function on top
of it, passing 0 as base. Similar safe_atoux16() is reworked as inline
function too, with 16 as base.

5 years agomacro: introduce new TAKE_FD() macro
Lennart Poettering [Thu, 22 Mar 2018 16:04:29 +0000 (17:04 +0100)]
macro: introduce new TAKE_FD() macro

This is similar to TAKE_PTR() but operates on file descriptors, and thus
assigns -1 to the fd parameter after returning it.

Removes 60 lines from our codebase. Pretty good too I think.

5 years agosleep-config: replace USE() macro with TAKE_PTR() usage
Lennart Poettering [Thu, 22 Mar 2018 15:59:46 +0000 (16:59 +0100)]
sleep-config: replace USE() macro with TAKE_PTR() usage

let's use the new generic macor instead of the locally defined, specific
one.

5 years agomacro: introduce TAKE_PTR() macro
Lennart Poettering [Thu, 22 Mar 2018 15:53:26 +0000 (16:53 +0100)]
macro: introduce TAKE_PTR() macro

This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.

This takes inspiration from Rust:

https://doc.rust-lang.org/std/option/enum.Option.html#method.take

and was suggested by Alan Jenkins (@sourcejedi).

It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)

5 years agoWhen mangling names, optionally emit a warning (#8400)
Zbigniew Jędrzejewski-Szmek [Wed, 21 Mar 2018 14:26:47 +0000 (15:26 +0100)]
When mangling names, optionally emit a warning (#8400)

The warning is not emitted for absolute paths like /dev/sda or /home, which are
converted to .device and .mount unit names without any fuss.

Most of the time it's unlikely that users use invalid unit names on purpose,
so let's warn them. Warnings are silenced when --quiet is used.

$ build/systemctl show -p Id hello@foo-bar/baz
Invalid unit name "hello@foo-bar/baz" was escaped as "hello@foo-bar-baz" (maybe you should use systemd-escape?)
Id=hello@foo-bar-baz.service

$ build/systemd-run --user --slice foo-bar/baz --unit foo-bar/foo true
Invalid unit name "foo-bar/foo" was escaped as "foo-bar-foo" (maybe you should use systemd-escape?)
Invalid unit name "foo-bar/baz" was escaped as "foo-bar-baz" (maybe you should use systemd-escape?)
Running as unit: foo-bar-foo.service

Fixes #8302.

5 years agoshared/conf-parser: fix outdated comment
Zbigniew Jędrzejewski-Szmek [Wed, 21 Mar 2018 12:15:01 +0000 (13:15 +0100)]
shared/conf-parser: fix outdated comment

5 years agouser-util: add new wrappers for reading/writing {passwd,shadow,gshadow} database...
Franck Bui [Wed, 21 Mar 2018 14:26:02 +0000 (15:26 +0100)]
user-util: add new wrappers for reading/writing {passwd,shadow,gshadow} database files (#8521)

The API povided by the glibc is too error-prone as one has to deal directly
with errno in order to detect if errors occured.

Suggested by Zbigniew.

5 years agococcinelle: always use fcntl(fd, FD_DUPFD, 3) instead of dup(fd)
Lennart Poettering [Tue, 20 Mar 2018 19:57:37 +0000 (20:57 +0100)]
coccinelle: always use fcntl(fd, FD_DUPFD, 3) instead of dup(fd)

Let's avoid fds 0…2 for safety reasons.

5 years agococcinelle: make use of DIV_ROUND_UP() wherever appropriate
Lennart Poettering [Tue, 20 Mar 2018 19:36:09 +0000 (20:36 +0100)]
coccinelle: make use of DIV_ROUND_UP() wherever appropriate

Let's use our macros where we can

5 years agotime-sync-wait: add service (#8494)
Peter A. Bigot [Wed, 21 Mar 2018 11:42:04 +0000 (06:42 -0500)]
time-sync-wait: add service (#8494)

This one-shot service waits until the kernel time has been set to
synchronized.

5 years agodissect: add dissect_image_and_warn() that unifies error message generation for disse...
Lennart Poettering [Wed, 21 Mar 2018 11:10:01 +0000 (12:10 +0100)]
dissect: add dissect_image_and_warn() that unifies error message generation for dissect_image() (#8517)

5 years agodoc: update TODO
Yu Watanabe [Thu, 8 Mar 2018 03:53:43 +0000 (12:53 +0900)]
doc: update TODO

5 years agodissect: add dissect_image_and_warn() that unifies error message generation for disse...
Lennart Poettering [Wed, 21 Mar 2018 11:10:01 +0000 (12:10 +0100)]
dissect: add dissect_image_and_warn() that unifies error message generation for dissect_image() (#8517)

5 years agodoc: update TODO
Yu Watanabe [Thu, 8 Mar 2018 03:53:43 +0000 (12:53 +0900)]
doc: update TODO

5 years agomeson.build: Fix wron mask ending and some missing trailing whitespaces on mask blocks.
Sven Eden [Fri, 29 Jun 2018 05:37:43 +0000 (07:37 +0200)]
meson.build: Fix wron mask ending and some missing trailing whitespaces on mask blocks.

5 years agojournal: make the compression threshold tunable
Alex Gartrell [Tue, 27 Feb 2018 17:37:23 +0000 (09:37 -0800)]
journal: make the compression threshold tunable

Allow a user to set a number of bytes as Compress to use as the compression
threshold.

5 years agodissect: add dissect_image_and_warn() that unifies error message generation for disse...
Lennart Poettering [Wed, 21 Mar 2018 11:10:01 +0000 (12:10 +0100)]
dissect: add dissect_image_and_warn() that unifies error message generation for dissect_image() (#8517)

5 years agodoc: update TODO
Yu Watanabe [Thu, 8 Mar 2018 03:53:43 +0000 (12:53 +0900)]
doc: update TODO

5 years agodissect: add dissect_image_and_warn() that unifies error message generation for disse...
Lennart Poettering [Wed, 21 Mar 2018 11:10:01 +0000 (12:10 +0100)]
dissect: add dissect_image_and_warn() that unifies error message generation for dissect_image() (#8517)