chiark / gitweb /
elogind.git
6 years agoPrep v234: Eventually fix the cgroup stuff. elogind is not init.
Sven Eden [Thu, 27 Jul 2017 08:18:44 +0000 (10:18 +0200)]
Prep v234: Eventually fix the cgroup stuff. elogind is not init.

6 years agoPrep 234: Fix Makefile.am to install elogind in rootlibexecdir, like upstream does...
Sven Eden [Thu, 27 Jul 2017 08:17:16 +0000 (10:17 +0200)]
Prep 234: Fix Makefile.am to install elogind in rootlibexecdir, like upstream does with systemd-login.

6 years agoPrep 234: Rename pam-systemd to pam-elogind in pam module init log message.
Sven Eden [Wed, 26 Jul 2017 13:13:56 +0000 (15:13 +0200)]
Prep 234: Rename pam-systemd to pam-elogind in pam module init log message.

6 years agoPrep v234: Re-add user/session to the gc_queue when stopping.
Sven Eden [Wed, 26 Jul 2017 08:26:15 +0000 (10:26 +0200)]
Prep v234: Re-add user/session to the gc_queue when stopping.

If manager_gc() does not find the user/session, their respective
finalize_*() method is never called, leaving stale state files in
/run/systemd/sessions and run/systemd/users.

6 years agoPrep v233.4: Update LTO usage to be more convenient.
Sven Eden [Fri, 21 Jul 2017 11:37:31 +0000 (13:37 +0200)]
Prep v233.4: Update LTO usage to be more convenient.

- Add -fuse-linker-plugin to work around odd compiler and binutils
  installs. Should fix most "plugin needed to handle lto object"
  issues.
- Read back whether LTO really has been enabled or not, so we can
  display a status line at the end of configure.
- Only enforce gold linker if LTO has been enabled.

These checks can still be disabled with the --disable-lto option,
which will make configure to skip all checks regarding LTO.

6 years agoPrep v234: Apply missing upstream fixes in src/test (6/6)
Sven Eden [Tue, 25 Jul 2017 08:20:12 +0000 (10:20 +0200)]
Prep v234: Apply missing upstream fixes in src/test (6/6)

6 years agoPrep v234: Apply missing upstream fixes in src/systemd (5/6)
Sven Eden [Tue, 25 Jul 2017 08:20:01 +0000 (10:20 +0200)]
Prep v234: Apply missing upstream fixes in src/systemd (5/6)

6 years agoPrep v234: Apply missing upstream fixes in src/shared (4/6)
Sven Eden [Tue, 25 Jul 2017 09:41:55 +0000 (11:41 +0200)]
Prep v234: Apply missing upstream fixes in src/shared (4/6)

6 years agoPrep v234: Apply missing upstream fixes in src/login (3/6)
Sven Eden [Tue, 25 Jul 2017 08:19:45 +0000 (10:19 +0200)]
Prep v234: Apply missing upstream fixes in src/login (3/6)

6 years agoPrep v234: Apply missing upstream fixes in src/libelogind (2/6)
Sven Eden [Tue, 25 Jul 2017 09:41:55 +0000 (11:41 +0200)]
Prep v234: Apply missing upstream fixes in src/libelogind (2/6)

6 years agoPrep v234: Apply missing upstream fixes in src/basic (1/6)
Sven Eden [Tue, 25 Jul 2017 08:19:24 +0000 (10:19 +0200)]
Prep v234: Apply missing upstream fixes in src/basic (1/6)

6 years agoPrep v234: Clarify status of $XDG_RUNTIME_DIR
Sven Eden [Tue, 25 Jul 2017 08:18:10 +0000 (10:18 +0200)]
Prep v234: Clarify status of $XDG_RUNTIME_DIR

6 years agoPrep v234: Remove now obsolete text files from src/libelogind/sd-bus
Sven Eden [Tue, 25 Jul 2017 07:49:53 +0000 (09:49 +0200)]
Prep v234: Remove now obsolete text files from src/libelogind/sd-bus

6 years agoPrep v234: Update root build files to upstream.
Sven Eden [Tue, 25 Jul 2017 06:32:29 +0000 (08:32 +0200)]
Prep v234: Update root build files to upstream.

6 years agoRevert "core: link user keyring to session keyring (#6275)" (#6342)
Lennart Poettering [Wed, 12 Jul 2017 14:00:44 +0000 (16:00 +0200)]
Revert "core: link user keyring to session keyring (#6275)" (#6342)

This reverts commit 437a85112e02042b62751395b9e7225628c1b708.

The outcome of this isn't that clear, let's revert this for now, see
discussion on #6286.

6 years agotime-util: make parse_timestamp() return -EINVAL if the input is very old date (...
Yu Watanabe [Tue, 11 Jul 2017 17:12:48 +0000 (02:12 +0900)]
time-util: make parse_timestamp() return -EINVAL if the input is very old date (#6327)

This reverts 7635ab8e74ea4a94e81143c3077570a986df375c and makes parse_timestamp()
return -EINVAL if the input is older than 1970-01-01.

Fixes #6290.

6 years agoAdd comments to log_functions which shouldn't be called from library code (#6326)
Zbigniew Jędrzejewski-Szmek [Tue, 11 Jul 2017 08:40:11 +0000 (04:40 -0400)]
Add comments to log_functions which shouldn't be called from library code (#6326)

6 years agorandom-util: we are fine if ints are 16 bytes actually
Lennart Poettering [Tue, 11 Jul 2017 08:36:53 +0000 (10:36 +0200)]
random-util: we are fine if ints are 16 bytes actually

Not that it matters IRL, but let's make this less surprising to read...

6 years agorandom-util: always cast from smaller to bigger type when comparing
Lennart Poettering [Tue, 11 Jul 2017 08:35:47 +0000 (10:35 +0200)]
random-util: always cast from smaller to bigger type when comparing

When we compare two size values, let's make sure we cast from the
smaller to the bigger type first, if both types differ, rather than the
reverse in order to not run into overflows.

6 years agobasic/strv: use existing qsort_safe() helper
Zbigniew Jędrzejewski-Szmek [Mon, 10 Jul 2017 18:55:14 +0000 (14:55 -0400)]
basic/strv: use existing qsort_safe() helper

strv_sort() predates qsort_safe(), but we can convert it to it to
save a few lines.

6 years agosd_uid_get_state: do not return -ENOENT if state is "offline" (#6302)
Yu, Li-Yu [Sat, 8 Jul 2017 22:59:29 +0000 (17:59 -0500)]
sd_uid_get_state: do not return -ENOENT if state is "offline" (#6302)

6 years agosd-login: fix memleak when output argument is NULL
Zbigniew Jędrzejewski-Szmek [Sat, 8 Jul 2017 22:04:44 +0000 (18:04 -0400)]
sd-login: fix memleak when output argument is NULL

6 years agotime-util: make parse_timestamp() set 0 if the input is very old date (#6297)
Yu Watanabe [Sat, 8 Jul 2017 19:59:07 +0000 (04:59 +0900)]
time-util: make parse_timestamp() set 0 if the input is very old date (#6297)

If the input is older than "1970-01-01 UTC", then `parse_timestamp()`
fails and returns -EINVAL. However, if the input is e.g. `-100years`,
then the function succeeds and sets `usec = 0`.
This commit makes the function also succeed for old dates and set
`usec = 0`.

Fixes #6290.

6 years agocore/load-fragment: refuse units with errors in RootDirectory/RootImage/DynamicUser
Zbigniew Jędrzejewski-Szmek [Thu, 6 Jul 2017 17:54:42 +0000 (13:54 -0400)]
core/load-fragment: refuse units with errors in RootDirectory/RootImage/DynamicUser

Behaviour of the service is completely different with the option off, so the
service would probably mess up state on disk and do unexpected things.

6 years agobasic/log: use getenv instead of secure_getenv
Zbigniew Jędrzejewski-Szmek [Wed, 5 Jul 2017 03:54:00 +0000 (23:54 -0400)]
basic/log: use getenv instead of secure_getenv

secure_getenv does not work when the process has a nonempty permitted
capability set, which means that it's unduly hard to configure logging in
elogind-logind, elogind-resolved, and others.

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

Fixes #4900.

6 years agotest-fs-util: re-order test_readlink_and_make_absolute and test_get_files_in_director...
Mike Gilbert [Wed, 5 Jul 2017 03:22:47 +0000 (23:22 -0400)]
test-fs-util: re-order test_readlink_and_make_absolute and test_get_files_in_directory (#6288)

test_readlink_and_make_absolute switches to a temp directory, and then
removes it.

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

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

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

Bug: https://bugs.gentoo.org/590084

6 years agobasic: Fix build warning in random-util (#6284)
Benjamin Robin [Tue, 4 Jul 2017 21:42:20 +0000 (23:42 +0200)]
basic: Fix build warning in random-util (#6284)

6 years agoudev: move the KEY_* defines to missing.h (#6278)
Peter Hutterer [Tue, 4 Jul 2017 07:41:46 +0000 (17:41 +1000)]
udev: move the KEY_* defines to missing.h (#6278)

6 years agocore: link user keyring to session keyring (#6275)
Christian Hesse [Tue, 4 Jul 2017 07:38:31 +0000 (09:38 +0200)]
core: link user keyring to session keyring (#6275)

Commit  74dd6b515fa968c5710b396a7664cac335e25ca8 (core: run each system
service with a fresh session keyring) broke adding keys to user keyring.
Added keys could not be accessed with error message:

keyctl_read_alloc: Permission denied

So link the user keyring to our session keyring.

6 years agoParse "timeout=0" as infinity in various generators (#6264)
Zbigniew Jędrzejewski-Szmek [Mon, 3 Jul 2017 12:29:32 +0000 (08:29 -0400)]
Parse "timeout=0" as infinity in various generators (#6264)

This extends 2d79a0bbb9f651656384a0a86ed814e6306fb5dd to the kernel
command line parsing.

The parsing is changed a bit to only understand "0" as infinity. If units are
specified, parse normally, e.g. "0s" is just 0. This makes it possible to
provide a zero timeout if necessary.

Simple test is added.

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

6 years agoBe slightly more verbose in error message
Zbigniew Jędrzejewski-Szmek [Sun, 2 Jul 2017 16:03:25 +0000 (12:03 -0400)]
Be slightly more verbose in error message

Including the full path is always useful.

Also use PID_FMT in one more place.

6 years agobus-util: replace non-printable values with [unprintable]
Zbigniew Jędrzejewski-Szmek [Sat, 1 Jul 2017 20:49:15 +0000 (16:49 -0400)]
bus-util: replace non-printable values with [unprintable]

Like I said in the previous commit, such values do not seem to appear in normal
use, but it's pretty hard to prove that all paths to assign values properly
check that they contain no spaces. So just in case some slip through, replace
values with spaces (in case of single-valued properties) or spaces and newlines
(in case of array proprties) with "[unprintable]". We were already doing it
in case of properties which we didn't know how to print, so this fits in well.
The advantage is the previous code which used escaping that a) this is easier
to spot, b) does not mess up printing of properties which were properly escaped
already.

v2:
- add comments

6 years agoRevert "bus: when dumping string property values escape the chars we use as end-of...
Zbigniew Jędrzejewski-Szmek [Sat, 1 Jul 2017 20:17:12 +0000 (16:17 -0400)]
Revert "bus: when dumping string property values escape the chars we use as end-of-line and end-of-item marks"

This reverts commit 27e9c5af817147ea1c678769e45e83f2e4b4ae96.

Property values already use escaping, so escaping them a second time is
confusing. It also should be mostly unnecessary: we take care to make property
values only contains strings which (after the initial escaping) are printable
and parseable without any futher escaping.

Before revert:
$ systemctl list-dependencies 'dev-mapper-luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.device'
dev-mapper-luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.device
● ├─dev-mapper-luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.swap
● └─elogind-cryptsetup@luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.service
$ systemctl show -p Wants,Requires 'dev-mapper-luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.device'
Requires=elogind-cryptsetup@luks\x5cx2d8db85dcf\x5cx2d6230\x5cx2d4e88\x5cx2d940d\x5cx2dba176d062b31.service
Wants=dev-mapper-luks\x5cx2d8db85dcf\x5cx2d6230\x5cx2d4e88\x5cx2d940d\x5cx2dba176d062b31.swap

Difference between systemctl show before revert and now:
-Slice=system-elogind\x5cx2dcryptsetup.slice
+Slice=system-elogind\x2dcryptsetup.slice

-Id=elogind-cryptsetup@luks\x5cx2d8db85dcf\x5cx2d6230\x5cx2d4e88\x5cx2d940d\x5cx2dba176d062b31.service
+Id=elogind-cryptsetup@luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.service

-Names=elogind-cryptsetup@luks\x5cx2d8db85dcf\x5cx2d6230\x5cx2d4e88\x5cx2d940d\x5cx2dba176d062b31.service
+Names=elogind-cryptsetup@luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.service

-Requires=system-elogind\x5cx2dcryptsetup.slice
+Requires=system-elogind\x2dcryptsetup.slice

-BindsTo=dev-mapper-luks\x5cx2d8db85dcf\x5cx2d6230\x5cx2d4e88\x5cx2d940d\x5cx2dba176d062b31.device dev-disk-by\x5cx2duuid-8db85dcf\x5cx2d6230\x5cx2d4e88\x5cx2d940d\x5cx2dba176d062b31.device
+BindsTo=dev-mapper-luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.device dev-disk-by\x2duuid-8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.device

-RequiredBy=dev-mapper-luks\x5cx2d8db85dcf\x5cx2d6230\x5cx2d4e88\x5cx2d940d\x5cx2dba176d062b31.device cryptsetup.target
+RequiredBy=dev-mapper-luks\x2d8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.device cryptsetup.target

-WantedBy=dev-disk-by\x5cx2duuid-8db85dcf\x5cx2d6230\x5cx2d4e88\x5cx2d940d\x5cx2dba176d062b31.device
+WantedBy=dev-disk-by\x2duuid-8db85dcf\x2d6230\x2d4e88\x2d940d\x2dba176d062b31.device

6 years agoman: fix spelling error of sd_bus_error_set_const (#6246)
Lars Karlitski [Fri, 30 Jun 2017 09:57:13 +0000 (11:57 +0200)]
man: fix spelling error of sd_bus_error_set_const (#6246)

6 years agosd-bus: never augment creds when we are operating on remote connections (#6217)
Lennart Poettering [Wed, 28 Jun 2017 17:20:16 +0000 (19:20 +0200)]
sd-bus: never augment creds when we are operating on remote connections (#6217)

It's not always clear when something is a remote connection, hence only
flag the obvious cases as local.

Fixes: #6207
6 years agologind: filter out input devices that have none of the keys/switche we care about
Lennart Poettering [Tue, 27 Jun 2017 15:46:28 +0000 (17:46 +0200)]
logind: filter out input devices that have none of the keys/switche we care about

Let's check what keys are there, before we actually hang on to the
opened devices.

6 years agologind: relax udev rules matching devices logind watches for
Lennart Poettering [Tue, 27 Jun 2017 14:14:30 +0000 (16:14 +0200)]
logind: relax udev rules matching devices logind watches for

Now that we have support for key/switch masking in logind, we can relax
the rules by which logind picks the devices to watch a bit, after all we
won't wake up anymore for every single event, but instead only the
events we actually care about.

This should make power/suspend keys on normal usb/atkbd keyboards just
work.

6 years agologind: make use of EVIOCSMASK input ioctl to mask out events we aren't interested in
Lennart Poettering [Mon, 26 Jun 2017 19:35:12 +0000 (21:35 +0200)]
logind: make use of EVIOCSMASK input ioctl to mask out events we aren't interested in

This way logind will get woken up only when an actual event took place,
and not for every key press on the system.

The ioctl EVIOCSMASK was added by @dvdhrm already in October 2015, for
the use in logind, among others, hence let's actually make use of it
now.

While we are at it, also fix usage of the EVIOCGSW ioctl, where we
assumed a byte array, even though a unsigned long native endian array is
returned.

6 years agosd-bus: use GetConnectionCredentials() when querying credentials, if available
Lennart Poettering [Mon, 26 Jun 2017 16:52:47 +0000 (18:52 +0200)]
sd-bus: use GetConnectionCredentials() when querying credentials, if available

Newer D-Bus versions implement the GetConnectionCredentials() driver
call to get all connection creds in one go. Make use of that to reduce
the number of bus calls we do.

When only a single credential field is queried we will still use the old
calls, which we'll also use if the new call isn't implemented.

6 years agosd-bus: when credentials of the "org.freedesktop.DBus" service are queried return...
Lennart Poettering [Mon, 26 Jun 2017 16:24:58 +0000 (18:24 +0200)]
sd-bus: when credentials of the "org.freedesktop.DBus" service are queried return the bus owner's credentials

The bus driver service is always implemented by the owner of the bus,
hence let's shortcut the credential operation and use our cached data.
This makes sure things simply work, given that dbus itself doesn't
support GetConnectionSELinuxSecurityContext() on the bus driver name
itself.

Fixes: #6120
6 years agocore: make IOSchedulingClass= and IOSchedulingPriority= settable for transient units
Lennart Poettering [Mon, 26 Jun 2017 15:40:08 +0000 (17:40 +0200)]
core: make IOSchedulingClass= and IOSchedulingPriority= settable for transient units

This patch is a bit more complex thant I hoped. In particular the single
IOScheduling= property exposed on the bus is split up into
IOSchedulingClass= and IOSchedulingPriority= (though compat is
retained). Otherwise the asymmetry between setting props and getting
them is a bit too nasty.

Fixes #5613

6 years agoCopy defines for renameat2 from casync (#6181)
Zbigniew Jędrzejewski-Szmek [Mon, 26 Jun 2017 07:34:03 +0000 (03:34 -0400)]
Copy defines for renameat2 from casync (#6181)

6 years agobasic/random-util: do not fall back to /dev/urandom if getrandom() returns short
Zbigniew Jędrzejewski-Szmek [Sun, 25 Jun 2017 21:09:05 +0000 (17:09 -0400)]
basic/random-util: do not fall back to /dev/urandom if getrandom() returns short

During early boot, we'd call getrandom(), and immediately fall back to
reading from /dev/urandom unless we got the full requested number of bytes.
Those two sources are the same, so the most likely result is /dev/urandom
producing some pseudorandom numbers for us, complaining widely on the way.

Let's change our behaviour to be more conservative:
- if the numbers are only used to initialize a hash table, a short read is OK,
  we don't really care if we get the first part of the seed truly random and
  then some pseudorandom bytes. So just do that and return "success".

- if getrandom() returns -EAGAIN, fall back to rand() instead of querying
  /dev/urandom again.

  The idea with those two changes is to avoid generating a warning about
  reading from an /dev/urandom when the kernel doesn't have enough entropy.

- only in the cases where we really need to make the best effort possible
  (sd_id128_randomize and firstboot password hashing), fall back to
  /dev/urandom.

When calling getrandom(), drop the checks whether the argument fits in an int —
getrandom() should do that for us already, and we call it with small arguments
only anyway.

Note that this does not really change the (relatively high) number of random
bytes we request from the kernel. On my laptop, during boot, PID 1 and all
other processes using this code through libelogind request:
  74780 bytes with high_quality_required == false
    464 bytes with high_quality_required == true
and it does not eliminate reads from /dev/urandom completely. If the kernel was
short on entropy and getrandom() would fail, we would fall back to /dev/urandom
for those 464 bytes.

When falling back to /dev/urandom, don't lose the short read we already got,
and just read the remaining bytes.

If getrandom() syscall is not available, we fall back to /dev/urandom same
as before.

Fixes #4167 (possibly partially, let's see).

6 years agotests: add tests for environment serialization
Zbigniew Jędrzejewski-Szmek [Sat, 24 Jun 2017 00:43:48 +0000 (20:43 -0400)]
tests: add tests for environment serialization

6 years agobasic/env-util: when serializing, actually use escaping
Zbigniew Jędrzejewski-Szmek [Sat, 24 Jun 2017 00:27:12 +0000 (20:27 -0400)]
basic/env-util: when serializing, actually use escaping

Fixes #6152.

6 years agomanager: just warn about an invalid environment entry
Zbigniew Jędrzejewski-Szmek [Fri, 23 Jun 2017 23:20:54 +0000 (19:20 -0400)]
manager: just warn about an invalid environment entry

Apart from bugs (as in #6152), this can happen if we ever make
our requirements for environment entries more stringent. As with
the rest of deserialization, we should just warn and continue.

6 years agotime-util: add new call usec_shift_clock() for converting times between clocks
Lennart Poettering [Thu, 22 Jun 2017 18:52:23 +0000 (20:52 +0200)]
time-util: add new call usec_shift_clock() for converting times between clocks

We use that quite often, let's implement one clean version of it.

6 years agotime-util: rename usec_sub() to usec_sub_signed() and add usec_sub_unsigned()
Lennart Poettering [Thu, 22 Jun 2017 18:49:12 +0000 (20:49 +0200)]
time-util: rename usec_sub() to usec_sub_signed() and add usec_sub_unsigned()

Quite often we just want to subtract two normal usec_t values, hence
provide an implementation for that.

6 years agolog: pass the correct length to vsnprintf (#6168)
Evgeny Vereshchagin [Thu, 22 Jun 2017 01:10:29 +0000 (04:10 +0300)]
log: pass the correct length to vsnprintf (#6168)

This prevents log_object_internalv from corrupting the stack.
Closes #6147.

Many thanks to Walter Doekes for the code review.

6 years agosd-bus: make sure propagate all errors with vtable callbacks back to clients
Lennart Poettering [Wed, 21 Jun 2017 18:42:28 +0000 (20:42 +0200)]
sd-bus: make sure propagate all errors with vtable callbacks back to clients

Previously we'd propagate errors returned by user callbacks configured
in vtables back to the users only for method handlers and property
get/set handlers. This does the same for child enumeration and when we
check whether a fallback unit exists.

Without this the failure will be treated as a non-recoverable connection
error and result in connection termination.

Fixes: #6059
6 years agocore: make NotifyAccess= and FileDescriptorStoreMax= available to transient services
Lennart Poettering [Wed, 21 Jun 2017 17:17:38 +0000 (19:17 +0200)]
core: make NotifyAccess= and FileDescriptorStoreMax= available to transient services

This is helpful for debugging/testing #5606.

6 years agocore: permit FDSTORE=1 messages with non-pollable fds
Lennart Poettering [Tue, 20 Jun 2017 21:30:30 +0000 (23:30 +0200)]
core: permit FDSTORE=1 messages with non-pollable fds

This also alters the documentation to recommend memfds rather than /run
for serializing state across reboots. That's because /run doesn't
actually have the same lifecycle as the fd store, as it is cleared out
on restarts.

Fixes: #5606
6 years agobasic/rm-rf: allow a symlink to / to be removed
Zbigniew Jędrzejewski-Szmek [Sat, 17 Jun 2017 16:41:08 +0000 (12:41 -0400)]
basic/rm-rf: allow a symlink to / to be removed

We open the target path with O_DIRECTORY|O_NOFOLLOW, and if that doesn't work,
we call unlink() on the path. In neither case we will follow the symlink, so
we can relax our check to also not follow symlinks.

Fixes #5864.

6 years agobasic/path-util: allow flags for path_equal_or_files_same
Zbigniew Jędrzejewski-Szmek [Sat, 17 Jun 2017 16:37:16 +0000 (12:37 -0400)]
basic/path-util: allow flags for path_equal_or_files_same

No functional change, just a new parameters and the tests that
AT_SYMLINK_NOFOLLOW works as expected.

6 years agoMake IDN support conditional
Waldemar Brodkorb [Thu, 15 Jun 2017 15:44:59 +0000 (17:44 +0200)]
Make IDN support conditional

[zj: rename HAVE_IDN to ENABLE_IDN]

6 years agoUse "dollar-single-quotes" to escape shell-sensitive strings
Zbigniew Jędrzejewski-Szmek [Sun, 11 Jun 2017 19:24:07 +0000 (15:24 -0400)]
Use "dollar-single-quotes" to escape shell-sensitive strings

Also called "ANSI-C Quoting" in info:(bash) ANSI-C Quoting.

The escaping rules are a POSIX proposal, and are described in
http://austingroupbugs.net/view.php?id=249. There's a lot of back-and-forth on
the details of escaping of control characters, but we'll be only using a small
subset of the syntax that is common to all proposals and is widely supported.
Unfortunately dash and fish and maybe some other shells do not support it (see
the man page patch for a list).

This allows environment variables to be safely exported using show-environment
and imported into the shell. Shells which do not support this syntax will have
to do something like
    export $(systemctl show-environment|grep -v '=\$')
or whatever is appropriate in their case. I think csh and fish do not support
the A=B syntax anyway, so the change is moot for them.

Fixes #5536.

v2:
- also escape newlines (which currently disallowed in shell values, so this
  doesn't really matter), and tabs (as $'\t'), and ! (as $'!'). This way quoted
  output can be included directly in both interactive and noninteractive bash.

6 years agosd-bus: silence format warnings in kdbus code (#6072)
Zbigniew Jędrzejewski-Szmek [Sat, 3 Jun 2017 09:41:17 +0000 (05:41 -0400)]
sd-bus: silence format warnings in kdbus code (#6072)

The code is mostly correct, but gcc is trying to outsmart us, and emits a
warning for a "llu vs lu" mismatch, even though they are the same size (on alpha):

src/libelogind/sd-bus/bus-control.c: In function ‘kernel_get_list’:
src/libelogind/sd-bus/bus-control.c:267:42: error: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘__u64 {aka long unsigned int}’ [-Werror=format=]
                         if (asprintf(&n, ":1.%llu", name->id) < 0) {
                                          ^
src/libelogind/sd-bus/bus-control.c: In function ‘bus_get_name_creds_kdbus’:
src/libelogind/sd-bus/bus-control.c:714:47: error: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘__u64 {aka long unsigned int}’ [-Werror=format=]
                 if (asprintf(&c->unique_name, ":1.%llu", conn_info->id) < 0) {
                                               ^
This is hard to work around properly, because kdbus.h uses __u64 which is
defined-differently-despite-being-the-same-size then uint64_t. Thus the simple
solution of using %PRIu64 fails on amd64:

src/libelogind/sd-bus/bus-control.c:714:47: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘__u64 {aka long long unsigned int}’ [-Werror=format=]
                 if (asprintf(&c->unique_name, ":1.%"PRIu64, conn_info->id) < 0) {
                                               ^~~~~~

Let's just avoid the whole issue for now by silencing the warning.
After the next release, we should just get rid of the kdbus code.

Fixes #5561.

6 years agologinctl: also use $XDG_SESSION_ID for session-status
Zbigniew Jędrzejewski-Szmek [Thu, 1 Jun 2017 02:42:14 +0000 (22:42 -0400)]
loginctl: also use $XDG_SESSION_ID for session-status

6 years agologinctl: use $XDG_SESSION_ID for "our" session
Zbigniew Jędrzejewski-Szmek [Thu, 1 Jun 2017 02:23:30 +0000 (22:23 -0400)]
loginctl: use $XDG_SESSION_ID for "our" session

Instead of always letting logind guess what the caller's session is, let's
give it the value from $XDG_SESSION_ID when it is present in the caller's
environment.

Nowadays terminal emulators are often running as services under elogind --user,
and not as part of an actual session, so all loginctl calls which depend on
logind guessing the session will fail. I don't see a reason not to honour
$XDG_SESSION_ID.

This applies to LockSession, UnlockSession, TerminateSession, ActivateSession,
SetUserLinger.

Fixes #6032.

6 years agologind: nicer error message when we cannot guess the caller's session
Zbigniew Jędrzejewski-Szmek [Thu, 1 Jun 2017 02:10:15 +0000 (22:10 -0400)]
logind: nicer error message when we cannot guess the caller's session

Partial fix for #6032.

6 years agoman: update sd_get_seats(3)
Yu Watanabe [Wed, 31 May 2017 15:27:47 +0000 (00:27 +0900)]
man: update sd_get_seats(3)

6 years agosd-login: sd_get_machine_names(): do not return -EINVAL when output parameter is...
Yu Watanabe [Wed, 31 May 2017 15:12:32 +0000 (00:12 +0900)]
sd-login: sd_get_machine_names(): do not return -EINVAL when output parameter is NULL

Other functions in sd-login generally allow the output parameter to be NULL, in
which case only the number of items that would be stored in the array is returned.
Be nice and do the same here.

6 years agosd-login: treat missing /run/elogind/{seats,sessions,users} the same as empty
Yu Watanabe [Wed, 31 May 2017 14:48:47 +0000 (23:48 +0900)]
sd-login: treat missing /run/elogind/{seats,sessions,users} the same as empty

C.f. 0543105b0fb13e4243b71a78f62f81fb9dde5d51.
This makes if /run/elogind/{seats,sessions,users} are missing, then
sd_get_seats(), sd_get_sessions() and sd_get_uids() return 0, that is,
an empty list, instead of -ENOENT.

6 years agosd-login: translate -ENOMEDIUM to -ENODATA
Zbigniew Jędrzejewski-Szmek [Wed, 31 May 2017 00:21:45 +0000 (20:21 -0400)]
sd-login: translate -ENOMEDIUM to -ENODATA

The -ENOMEDIUM return value was introduced in v232-1001-g2977724b09,
('core: make hybrid cgroup unified mode keep compat /sys/fs/cgroup/elogind hierarchy'),
and would be returned by cg_pid_get_path_shifted(), but the documented and
expected return value is -ENODATA. Let's just catch ENXIO/ENOMEDIUM and translate
it to ENODATA in all cases.

Complements 171f8f591ff27ebb5ff475b7a9d1f13a846c9331, fixes #6012.

6 years agologn: tests - don't compare signed with unsigned
Tom Gundersen [Thu, 25 May 2017 14:11:04 +0000 (16:11 +0200)]
logn: tests - don't compare signed with unsigned

6 years agobasic/time-util: make parsing of dual_timestamp more strict
Zbigniew Jędrzejewski-Szmek [Fri, 19 May 2017 18:49:06 +0000 (14:49 -0400)]
basic/time-util: make parsing of dual_timestamp more strict

*scanf functions set errno on i/o error. For sscanf, this doesn't really apply,
so (based on the man page), it seems that errno is unlikely to be ever set to a
useful value. So just ignore errno. The error message includes the string that
was parsed, so it should be always pretty clear why parsing failed.

On the other hand, detect trailing characters and minus prefix that weren't
converted properly. This matches what our safe_ato* functions do. Add tests to
elucidate various edge cases.

6 years agotest-parse-util: verify that ato[ui] actually rejects trailing garbage
Zbigniew Jędrzejewski-Szmek [Fri, 19 May 2017 18:37:48 +0000 (14:37 -0400)]
test-parse-util: verify that ato[ui] actually rejects trailing garbage

6 years agoarchitecture: add Synopsys DesignWare ARC cores support (#5992)
Alexey Brodkin [Fri, 19 May 2017 14:55:24 +0000 (16:55 +0200)]
architecture: add Synopsys DesignWare ARC cores support (#5992)

DesignWare ARC Processors are a family of 32-bit CPUs from Synopsys
used extensively in SoCs of different vendors.

6 years agoFix includes (#5980)
Matija Skala [Fri, 19 May 2017 14:01:35 +0000 (16:01 +0200)]
Fix includes (#5980)

Needed on musl.

6 years agocore: open /proc/self/mountinfo early to allow mounts over /proc (#5985)
Timothée Ravier [Fri, 19 May 2017 12:38:40 +0000 (14:38 +0200)]
core: open /proc/self/mountinfo early to allow mounts over /proc (#5985)

Enable masking the /proc folder using the 'InaccessiblePaths' unit
option.

This also slightly simplify mounts setup as the bind_remount_recursive
function will only open /proc/self/mountinfo once.

This is based on the suggestion at:
https://lists.freedesktop.org/archives/elogind-devel/2017-April/038634.html

6 years agotimesync/timesyncd-manager: fix format-specifier issues
Matija Skala [Fri, 19 May 2017 12:36:12 +0000 (14:36 +0200)]
timesync/timesyncd-manager: fix format-specifier issues

timex::time::tv_usec and timex::freq can have different sizes
depending on the host architecture. On x32 in particular,
it is 8 bytes long while the long int type is only 4 bytes
long. Hence, using li as a format specifier will trigger
a format error. Thus, introduce a new format specifier
PRI_TIMEX which is defined as PRIi64 on x32 and li
everywhere else.

6 years agosd-login: fix querying machines when machined is not running
Zbigniew Jędrzejewski-Szmek [Fri, 19 May 2017 11:52:00 +0000 (07:52 -0400)]
sd-login: fix querying machines when machined is not running

We should not leak the internal error from missing directory and treat
that case the same as no machines.

6 years agosd-login,test-login: return -ENODATA from sd_pid_get_unit too
Zbigniew Jędrzejewski-Szmek [Fri, 19 May 2017 02:32:19 +0000 (22:32 -0400)]
sd-login,test-login: return -ENODATA from sd_pid_get_unit too

After all, we might be running on a non-elogind system.

6 years agosd-login: fix return value of sd_pid_get_user_unit
Zbigniew Jędrzejewski-Szmek [Fri, 19 May 2017 02:11:08 +0000 (22:11 -0400)]
sd-login: fix return value of sd_pid_get_user_unit

E.g. "/user.slice/user-1000.slice/session-15.scope" would cause -ENXIO to be
returned.

6 years agosd-login: fix return value of sd_pid_get_session
Zbigniew Jędrzejewski-Szmek [Fri, 19 May 2017 01:55:44 +0000 (21:55 -0400)]
sd-login: fix return value of sd_pid_get_session

We'd return -ENXIO, even thoug -ENODATA is documented.

6 years agosd-login: read list of uids of sessions from UIDS not ACTIVE_SESSIONS
Zbigniew Jędrzejewski-Szmek [Fri, 19 May 2017 00:58:23 +0000 (20:58 -0400)]
sd-login: read list of uids of sessions from UIDS not ACTIVE_SESSIONS

As described by Luke Shumaker:

  sd_seat_get_sessions looks at /run/elogind/seats/${seat_name}:SESSIONS to get
  the list of sessions (which I believe is correct), and at
  /run/elogind/seats/${seat_name}:ACTIVE_SESSIONS for the list of users (which
  I believe is incorrect); I believe that it should look at the UIDS field for
  the list of users. As far as I can tell, the ACTIVE_SESSIONS field is never
  even present in the seats file. I also believe that this has been broken
  since the function was first committed almost 6 years ago.

Fixes #5743.

6 years agosd-login: always return two arrays of same length from sd_seat_get_sessions
Zbigniew Jędrzejewski-Szmek [Fri, 19 May 2017 00:48:09 +0000 (20:48 -0400)]
sd-login: always return two arrays of same length from sd_seat_get_sessions

sd_seat_get_sessions returns two arrays, that in principle should always match:
the session names and corresponding uids. The second array could be shorter only
if parsing or uid conversion fails. But in that case there is no way to tell
*which* uid is wrong, so they are *all* useless. It's better to simplify things and
just return an error if parsing fails.

6 years agoman: extend documentation on sd_bus_add_match a bit()
Lennart Poettering [Thu, 18 May 2017 16:24:17 +0000 (18:24 +0200)]
man: extend documentation on sd_bus_add_match a bit()

Explain briefly how the concept of "sd_bus_slot" works.

This recently came up on the mailing list, hence let's document this for
the next time.

6 years agoenv-util: fix memory leak (#5962)
Ronny Chevalier [Sun, 14 May 2017 14:30:40 +0000 (16:30 +0200)]
env-util: fix memory leak (#5962)

If cunescape succeeds, but the assignment is not valid, uce is not freed.

6 years agotest-conf-parser: add valid and invalid utf8 test for config_parse_path
Ronny Chevalier [Sun, 14 May 2017 11:19:11 +0000 (13:19 +0200)]
test-conf-parser: add valid and invalid utf8 test for config_parse_path

6 years agoconf-parser: fix wrong argument given to log_syntax_invalid_utf8
Ronny Chevalier [Sun, 14 May 2017 11:19:11 +0000 (13:19 +0200)]
conf-parser: fix wrong argument given to log_syntax_invalid_utf8

The condition is on "word", hence we give word instead of rvalue.

An assert would be triggered if !utf8_is_valid(word) is true and
rvalue == NULL, since log_syntax_invalid_utf8 calls utf8_escape_invalid
which calls assert(str).

A test case has been added to test with valid and invalid utf8.

6 years agotree-wide: drop assert.h includes
Zbigniew Jędrzejewski-Szmek [Sat, 13 May 2017 15:44:51 +0000 (11:44 -0400)]
tree-wide: drop assert.h includes

We provide an independent reimplementation in macro.h, and that's the one
we want to use. Including the system header is unnecessary and confusing.

6 years agotree-wide: when %m is used in log_*, always specify errno explicitly
Zbigniew Jędrzejewski-Szmek [Sat, 13 May 2017 15:26:55 +0000 (11:26 -0400)]
tree-wide: when %m is used in log_*, always specify errno explicitly

All those uses were correct, but I think it's better to be explicit.
Using implicit errno is too error prone, and with this change we can require
(in the sense of a style guideline) that the code is always specified.

Helpful query: git grep -n -P 'log_[^s][a-z]+\(.*%m'

6 years agotest-login: make the test non-manual
Zbigniew Jędrzejewski-Szmek [Fri, 12 May 2017 18:25:17 +0000 (14:25 -0400)]
test-login: make the test non-manual

test-login.c is largely rewritten to use _cleanup_ and give more meaningful
messages (function names are used instead of creative terms like "active
session", so that when something unexpected is returned, it's much easier to
see what function is responsible).

The monitoring part is only activated if '-m' is passed on the command line.

It runs against the information from /run/elogind/ in the live system, but that
should be OK: logind/sd-login interface is supposed to be stable and both
backwards and forwards compatible.

If not running in a login session, some tests are skipped.

Those two changes together mean that it's possible to run test-login in the
test suite.

Tests for sd_pid_get_{unit,user_unit,slice} are added.

6 years agosd-bus: fix c++ compatibility (#5941)
Matthijs van Duin [Thu, 11 May 2017 22:55:26 +0000 (00:55 +0200)]
sd-bus: fix c++ compatibility (#5941)

g++ annoyingly requires a non-empty struct-initializer to initialize all
struct members, in order of declaration.

Signed-off-by: Matthijs van Duin <matthijsvanduin@gmail.com>
6 years agobasic/fileio: extend atomic file writing with timestamp setting
Zbigniew Jędrzejewski-Szmek [Thu, 11 May 2017 14:23:36 +0000 (10:23 -0400)]
basic/fileio: extend atomic file writing with timestamp setting

There should be no functional change.

6 years agoAdd short-iso-precise for journalctl output (#5884)
Ian Wienand [Mon, 8 May 2017 00:23:49 +0000 (10:23 +1000)]
Add short-iso-precise for journalctl output (#5884)

This adds a short-iso-precise option for journalctl output.  It is similar to
short-iso, but includes microseconds.

6 years agoMark python scripts executable
Zbigniew Jędrzejewski-Szmek [Sun, 7 May 2017 15:35:32 +0000 (11:35 -0400)]
Mark python scripts executable

Since all our python scripts have a proper python3 shebang, there is no benefit
to letting meson autodetect them. On linux, meson will just uses exec(), so the
shebang is used anyway. The only difference should be in how meson reports the
script and that the detection won't fail for (most likely misconfigured)
non-UTF8 locales.

Closes #5855.

6 years agoman: fix links to external man pages
Zbigniew Jędrzejewski-Szmek [Sun, 7 May 2017 15:29:40 +0000 (11:29 -0400)]
man: fix links to external man pages

linkchecker ftw!

6 years agoRevert "selinux: split up mac_selinux_have() from mac_selinux_use()"
Gary Tierney [Tue, 2 May 2017 16:42:19 +0000 (17:42 +0100)]
Revert "selinux: split up mac_selinux_have() from mac_selinux_use()"

This reverts commit 6355e75610a8d47fc3ba5ab8bd442172a2cfe574.

The previously mentioned commit inadvertently broke a lot of SELinux related
functionality for both unprivileged users and elogind instances running as
MANAGER_USER.  In particular, setting the correct SELinux context after a User=
directive is used would fail to work since we attempt to set the security
context after changing UID.  Additionally, it causes activated socket units to
be mislabeled for elogind --user processes since setsockcreatecon() would never
be called.

Reverting this fixes the issues with labeling outlined above, and reinstates
SELinux access checks on unprivileged user services.

6 years agocore: introduce cg_mask_from_string()/cg_mask_to_string()
Franck Bui [Tue, 2 May 2017 07:59:17 +0000 (09:59 +0200)]
core: introduce cg_mask_from_string()/cg_mask_to_string()

6 years agoconfig parser: Introduce config_parse_ip_port
Susant Sahani [Thu, 27 Apr 2017 05:11:46 +0000 (10:41 +0530)]
config parser: Introduce config_parse_ip_port

6 years agoimprove readability (#5814)
Matija Skala [Thu, 27 Apr 2017 00:08:52 +0000 (02:08 +0200)]
improve readability (#5814)

6 years agoparse-util: introduce parse_dev() helper
Franck Bui [Wed, 26 Apr 2017 16:18:03 +0000 (18:18 +0200)]
parse-util: introduce parse_dev() helper

6 years agologind: when setting a new controller, don't prepare the VT if logind is restarted
Franck Bui [Wed, 26 Apr 2017 12:20:41 +0000 (14:20 +0200)]
logind: when setting a new controller, don't prepare the VT if logind is restarted

When assigning a new session controller to a session, the VT is prepared so the
controller can expect the VT to be in a good default state.

However when logind is restarted and a session controller already took control
of a session, there's no need to prepare th VT otherwise logind may screw up
the VT state set by the controller.

This patch prevents the preparation of the VT in this case.

6 years agotmpfiles: use safe_glob()
Zbigniew Jędrzejewski-Szmek [Wed, 26 Apr 2017 03:50:35 +0000 (23:50 -0400)]
tmpfiles: use safe_glob()

This filters out "." and ".." from glob results. Fixes #5655 and #5644.

Any judgements on whether the path is "safe" are removed. We will not remove
"/" under any name (including "/../" and such), but we will remove stuff that
is specified using paths that include "//", "/./" and "/../". Such paths can be
created when joining strings automatically, or for other reasons, and people
generally know what ".." and "." is.

Tests are added to make sure that the helper functions behave as expected.

6 years agobasic: add readdir_no_dot and safe_glob functions
Zbigniew Jędrzejewski-Szmek [Wed, 26 Apr 2017 03:44:34 +0000 (23:44 -0400)]
basic: add readdir_no_dot and safe_glob functions

safe_glob filters out "." and "..".

This converts all users of glob_extend() and glob_exists() to safe_glob.

6 years agotest-sizeof: print the size of an enum
Zbigniew Jędrzejewski-Szmek [Wed, 26 Apr 2017 01:14:59 +0000 (21:14 -0400)]
test-sizeof: print the size of an enum

6 years agobus: report builtins in GetManagedObjects() (#5799)
David Herrmann [Wed, 26 Apr 2017 00:36:30 +0000 (02:36 +0200)]
bus: report builtins in GetManagedObjects() (#5799)

We already report builtin interfaces with InterfacesAdded and InterfacesRemoved. However,
we never reported them in GetManagedObjects(). This might end up confusing callers that
want to use those interfaces (or simply rely on the interface count to be coherent).

Report the builtins for all objects that are queried.

6 years agoconfig parser: Introduce config_parse_uint8
Susant Sahani [Tue, 25 Apr 2017 13:11:50 +0000 (18:41 +0530)]
config parser: Introduce config_parse_uint8