chiark / gitweb /
elogind.git
6 years agocore: parse `rd.rescue` and `rd.emergency` as initrd-specific shorthands (#3488)
Ivan Shapovalov [Mon, 13 Jun 2016 14:28:42 +0000 (18:28 +0400)]
core: parse `rd.rescue` and `rd.emergency` as initrd-specific shorthands (#3488)

Typing `rd.rescue` is easier than `rd.elogind.unit=rescue.target`.

6 years agoutil-lib: drop trailing non-printable characters from cmdline (#3512)
Max Prokhorov [Mon, 13 Jun 2016 01:13:42 +0000 (04:13 +0300)]
util-lib: drop trailing non-printable characters from cmdline (#3512)

If max_length is equal or greater than cmdline length all trailing non-printable
characters are dropped. If max_length is 0 it should do the same.

This should also fix cmdline truncation if the last character is not '\0'.

Fixes #3469.

6 years agoprocess-util: remove broken support for pid==0
Zbigniew Jędrzejewski-Szmek [Mon, 13 Jun 2016 00:57:41 +0000 (20:57 -0400)]
process-util: remove broken support for pid==0

Our functions that query /proc/pid/ support using pid==0 to mean
self. get_process_id also seemed to support that, but it was not implemented
correctly: the result should be in *uid, not returned, and also it gave
completely bogus result when called from get_process_gid(). But afaict,
get_process_{uid,gid} were never called with pid==0, so it's not an actual
bug. Remove the broken code to avoid confusion.

6 years agoFixed a small typo in a comment (#3514)
Alex Gaynor [Sun, 12 Jun 2016 14:42:13 +0000 (10:42 -0400)]
Fixed a small typo in a comment (#3514)

6 years agoEnsure kdbus isn't used (#3501)
Dave Reisner [Fri, 10 Jun 2016 13:50:16 +0000 (09:50 -0400)]
Ensure kdbus isn't used (#3501)

Delete the dbus1 generator and some critical wiring. This prevents
kdbus from being loaded or detected. As such, it will never be used,
even if the user still has a useful kdbus module loaded on their system.

Sort of fixes #3480. Not really, but it's better than the current state.

6 years agonetworkd: added support for vrf interfaces (#3316)
Andreas Rammhold [Thu, 9 Jun 2016 23:57:51 +0000 (01:57 +0200)]
networkd: added support for vrf interfaces (#3316)

6 years agobus_util: add support to map double (#3479)
Susant Sahani [Thu, 9 Jun 2016 15:41:35 +0000 (21:11 +0530)]
bus_util: add support to map double (#3479)

Now we don't support parsing double at map_basic.
when trying to  use bus_message_map_all_properties with a double
this fails. Let's add it.

6 years agoutil: introduce physical_memory_scale() to unify how we scale by physical memory
Lennart Poettering [Wed, 8 Jun 2016 18:45:32 +0000 (20:45 +0200)]
util: introduce physical_memory_scale() to unify how we scale by physical memory

The various bits of code did the scaling all different, let's unify this,
given that the code is not trivial.

6 years agoutil-lib: introduce parse_percent() for parsing percent specifications
Lennart Poettering [Wed, 8 Jun 2016 17:25:38 +0000 (19:25 +0200)]
util-lib: introduce parse_percent() for parsing percent specifications

And port a couple of users over to it.

6 years agologind: minor cleanup and use IN_SET() in manager_handle_action()
Franck Bui [Wed, 8 Jun 2016 16:16:42 +0000 (18:16 +0200)]
logind: minor cleanup and use IN_SET() in manager_handle_action()

6 years agologind: really handle *KeyIgnoreInhibited options in logind.conf
Franck Bui [Wed, 8 Jun 2016 16:08:56 +0000 (18:08 +0200)]
logind: really handle *KeyIgnoreInhibited options in logind.conf

6 years agomissing include added for build with -DDEBUG (#3424)
Tobias Jungel [Fri, 3 Jun 2016 10:33:12 +0000 (12:33 +0200)]
missing include added for build with -DDEBUG (#3424)

6 years agocore: pass Unit into cgroup_context_apply() and use log_unit*()
Tejun Heo [Thu, 2 Jun 2016 17:02:49 +0000 (13:02 -0400)]
core: pass Unit into cgroup_context_apply() and use log_unit*()

cgroup_context_apply() and friends take CGroupContext and cgroup path as input
and has no way of getting back to the associated Unit and thus uses raw cgroup
path for logging.  This makes the log messages difficult to track down.
There's no reason to avoid passing in Unit into these functions.  Pass in Unit
and use log_unit*() instead.

While at it, make cgroup_context_apply(), which has no outside users, static.
Also, drop cgroup path from log messages where the path itself isn't too
interesting and can be easily obtained from the unit.

6 years agoutil-lib: add accessors for unaligned native endian words
Lennart Poettering [Thu, 2 Jun 2016 16:12:16 +0000 (18:12 +0200)]
util-lib: add accessors for unaligned native endian words

6 years agonetworkd: add support to configure VLAN on bridge ports
Tobias Jungel [Wed, 1 Jun 2016 13:18:21 +0000 (15:18 +0200)]
networkd: add support to configure VLAN on bridge ports

6 years agopager: don't start pager if the terminal is explicitly set to TERM=dumb
Lennart Poettering [Mon, 30 May 2016 16:23:54 +0000 (18:23 +0200)]
pager: don't start pager if the terminal is explicitly set to TERM=dumb

As suggested here:

https://bugs.freedesktop.org/show_bug.cgi?id=64737#c8

This adds a new call terminal_is_dumb() and makes use of this where
appropriate.

6 years agotree-wide: check colors_enabled() before outputting ANSI color strings
Lennart Poettering [Mon, 30 May 2016 16:23:08 +0000 (18:23 +0200)]
tree-wide: check colors_enabled() before outputting ANSI color strings

6 years agoutil-lib: make localed's nonempty() generic, rename it to empty_to_null() and make...
Lennart Poettering [Mon, 30 May 2016 15:59:43 +0000 (17:59 +0200)]
util-lib: make localed's nonempty() generic, rename it to empty_to_null() and make use of it everywhere

6 years agoutil-lib: Add sparc64 support for process creation (#3348)
Michael Karcher [Mon, 30 May 2016 00:03:51 +0000 (02:03 +0200)]
util-lib: Add sparc64 support for process creation (#3348)

The current raw_clone function takes two arguments, the cloning flags and
a pointer to the stack for the cloned child. The raw cloning without
passing a "thread main" function does not make sense if a new stack is
specified, as it returns in both the parent and the child, which will fail
in the child as the stack is virgin. All uses of raw_clone indeed pass NULL
for the stack pointer which indicates that both processes should share the
stack address (so you better don't pass CLONE_VM).

This commit refactors the code to not require the caller to pass the stack
address, as NULL is the only sensible option. It also adds the magic code
needed to make raw_clone work on sparc64, which does not return 0 in %o0
for the child, but indicates the child process by setting %o1 to non-zero.
This refactoring is not plain aesthetic, because non-NULL stack addresses
need to get mangled before being passed to the clone syscall (you have to
apply STACK_BIAS), whereas NULL must not be mangled. Implementing the
conditional mangling of the stack address would needlessly complicate the
code.

raw_clone is moved to a separete header, because the burden of including
the assert machinery and sched.h shouldn't be applied to every user of
missing_syscalls.h

6 years agologin: Fix policy for org.freedesktop.login1.set-self-linger (#3365) (#3373)
Michael Biebl [Sat, 28 May 2016 09:03:03 +0000 (11:03 +0200)]
login: Fix policy for org.freedesktop.login1.set-self-linger (#3365) (#3373)

We need to explicitly define authorizations for allow_inactive and
allow_active. Otherwise one is getting "Access denied" when run from a
local console:

$ loginctl enable-linger
Could not enable linger: Access denied

6 years agocore: add cgroup memory controller support on the unified hierarchy (#3315)
Tejun Heo [Fri, 27 May 2016 16:10:18 +0000 (09:10 -0700)]
core: add cgroup memory controller support on the unified hierarchy (#3315)

On the unified hierarchy, memory controller implements three control knobs -
low, high and max which enables more useable and versatile control over memory
usage.  This patch implements support for the three control knobs.

* MemoryLow, MemoryHigh and MemoryMax are added for memory.low, memory.high and
  memory.max, respectively.

* As all absolute limits on the unified hierarchy use "max" for no limit, make
  memory limit parse functions accept "max" in addition to "infinity" and
  document "max" for the new knobs.

* Implement compatibility translation between MemoryMax and MemoryLimit.

v2:

- Fixed missing else's in config_parse_memory_limit().
- Fixed missing newline when writing out drop-ins.
- Coding style updates to use "val > 0" instead of "val".
- Minor updates to documentation.

6 years agonspawn: a bench of special fileystems that should not be shifted
Djalal Harouni [Thu, 26 May 2016 20:38:25 +0000 (22:38 +0200)]
nspawn: a bench of special fileystems that should not be shifted

Add some special filesystems that should not be shifted, most of them
relate to the host and not to containers.

6 years agonetworkd: set IFLA_INET6_ADDR_GEN_MODE as per stable_secret
Tom Yan [Wed, 25 May 2016 12:04:01 +0000 (20:04 +0800)]
networkd: set IFLA_INET6_ADDR_GEN_MODE as per stable_secret

Although networkd has option (LinkLocalAddressing=) to toggle IPv6LL autoconfiguration, when it is enabled, the address is autoconfigured by the kernel, but not networkd.

Therefore, we do not statically set IFLA_INET6_ADDR_GEN_MODE to IN6_ADDR_GEN_MODE_EUI64, but dynamically depending on whether stable_secret is set, just as what the kernel does by default.

Note that this does NOT affect the global addresses configured by networkd.

6 years agoRevert "rules: allow users to access frame buffer devices" (#3333)
Zbigniew Jędrzejewski-Szmek [Tue, 24 May 2016 09:32:30 +0000 (05:32 -0400)]
Revert "rules: allow users to access frame buffer devices" (#3333)

This reverts commit 483d8bbb4c0190f419bf9fba57fb0feb1a56bea6.

In [1] Michel Dänzer and Daniel Vetter wrote:
>> The scenario you describe isn't possible if the Wayland compositor
>> directly uses the KMS API of /dev/dri/card*, but it may be possible if
>> the Wayland compositor uses the fbdev API of /dev/fb* instead (e.g. if
>> weston uses its fbdev backend).
>
> Yeah, if both weston and your screen grabber uses native fbdev API you can
> now screenshot your desktop. And since fbdev has no concept of "current
> owner of the display hw" like the drm master, I think this is not fixable.
> At least not just in userspace. Also even with native KMS compositors
> fbdev still doesn't have the concept of ownership, which is why it doesn't
> bother clearing it's buffer before KMS takes over. I agree that this
> should be reverted or at least hidden better.

TBH, I think that privilege separation between processes running under the same
UID is tenuous. Even with drm, in common setups any user process can ptrace the
"current owner of the display" and call DROP_MASTER or do whatever. It *is*
possible to prevent that, e.g. by disabling ptrace using yama.ptrace_scope, or
selinux, and so on, but afaik this is not commonly done. E.g. all Fedora
systems pull in elfutils-default-yama-scope.rpm through dependencies which sets
yama.ptrace_scope=0. And even assuming that ptrace was disabled, it is trivial
to modify files on disk, communicate through dbus, etc; there is just to many
ways for a non-sandboxed process to interact maliciously with the display shell
to close them all off. To achieve real protection, some sort of sandboxing
must be implemented, and in that case there is no need to rely on access mode
on the device files, since much more stringent measures have to be implemented
anyway.

The situation is similar for framebuffer devices. It is common to add
framebuffer users to video group to allow them unlimited access to /dev/fb*.
Using uaccess would be better solution in that case. Also, since there is no
"current owner" limitation like in DRM, processes running under the same UID
should be able to access /proc/<pid-of-display-server>/fd/* and gain access to
the devices. Nevertheless, weston implements a suid wrapper to access the
devices and then drop privileges, and this patch would make this daemon
pointless. So if the weston developers feel that this change reduces security,
I prefer to revert it.

[1] https://lists.freedesktop.org/archives/wayland-devel/2016-May/029017.html

6 years agotreewide: fix typos
Torstein Husebø [Thu, 12 May 2016 09:23:35 +0000 (11:23 +0200)]
treewide: fix typos

6 years agoask-password: ask for passphrases not only on the first console of /dev/console
Werner Fink [Wed, 18 Nov 2015 11:28:30 +0000 (12:28 +0100)]
ask-password: ask for passphrases not only on the first console of /dev/console

but also on all other consoles.  This does help on e.g. mainframes
where often a serial console together with other consoles are
used.  Even rack based servers attachted to both a serial console
as well as having a virtual console do sometimes miss a connected
monitor.

To be able to ask on all terminal devices of /dev/console the devices
are collected. If more than one device are found, then on each of the
terminals a inquiring task for passphrase is forked and do not return
to the caller.

Every task has its own session and its own controlling terminal.
If one of the tasks does handle a password, the remaining tasks
will be terminated.

Also let contradictory options on the command of
elogind-tty-ask-password-agent fail.

Spwan for each device of the system console /dev/console a own process.
Replace the system call wait() with with system call waitid().
Use SIGTERM instead of SIGHUP to get unresponsive childs down.

Port the collect_consoles() function forward to a pulbic and strv
based function "get_kernel_consoles()" in terminal-util.c and use this
in tty-ask-password-agent.c.

6 years agoPrep v229.5: Make musl-libc utmp/wtmp stubs visible.
Sven Eden [Mon, 12 Jun 2017 11:29:24 +0000 (13:29 +0200)]
Prep v229.5: Make musl-libc utmp/wtmp stubs visible.

6 years agoPrep v229.5: Move parse-printf-format.? back to src/basic it is needed there.
Sven Eden [Mon, 12 Jun 2017 10:19:09 +0000 (12:19 +0200)]
Prep v229.5: Move parse-printf-format.? back to src/basic it is needed there.

6 years agoPrep v230: Update loginctl help text
Sven Eden [Fri, 9 Jun 2017 08:49:26 +0000 (10:49 +0200)]
Prep v230: Update loginctl help text

6 years agoPrep v230: No longer print double messages when shutting down or rebooting.
Sven Eden [Thu, 8 Jun 2017 08:56:06 +0000 (10:56 +0200)]
Prep v230: No longer print double messages when shutting down or rebooting.

6 years agoPrep v230: Add utmp support to make wall message to work properly.
Sven Eden [Thu, 8 Jun 2017 06:49:12 +0000 (08:49 +0200)]
Prep v230: Add utmp support to make wall message to work properly.

6 years agoPrep v230: Add support for scheduled shutdown/reboot and the cancellation of them.
Sven Eden [Wed, 7 Jun 2017 10:09:39 +0000 (12:09 +0200)]
Prep v230: Add support for scheduled shutdown/reboot and the cancellation of them.

6 years agoPrep v230: Return 'no' when asked whether we can reboot into firmware setup. elogind...
Sven Eden [Thu, 8 Jun 2017 06:30:23 +0000 (08:30 +0200)]
Prep v230: Return 'no' when asked whether we can reboot into firmware setup. elogind does not support EFI.

6 years agoPrep v230: Move musl_missing and parse-printf-format to libshared.
Sven Eden [Wed, 7 Jun 2017 10:10:11 +0000 (12:10 +0200)]
Prep v230: Move musl_missing and parse-printf-format to libshared.

6 years agoPrep v230: Remove possibly existing header symlinks before creating new ones.
Sven Eden [Wed, 7 Jun 2017 10:08:26 +0000 (12:08 +0200)]
Prep v230: Remove possibly existing header symlinks before creating new ones.

6 years agoPrep v230: src/logind.c: Do not call manager_free(m) if an error lead to m still...
Sven Eden [Wed, 7 Jun 2017 06:02:10 +0000 (08:02 +0200)]
Prep v230: src/logind.c: Do not call manager_free(m) if an error lead to m still being NULL.

6 years agoPrep v230: Move installed headers
Sven Eden [Fri, 2 Jun 2017 09:18:12 +0000 (11:18 +0200)]
Prep v230: Move installed headers

The headers are now installed into

  /usr/include/elogind/systemd

and the pkg-config file now returns -I/usr/include/elogind for CFLAGS.

Further
  /usr/include/elogind
contains symlinks to the headers, so existing packages already including
<elogind/sd-login.h> will not be broken.

This way no software has to change their include lines anywhere to
support elogind any more. All they have to do is either add
LIBSYSTEMD_CFLAGS or LIBELOGIND_CFLAGS from pkg-config and be done
with it.

So most patching can be avoided, just some configure adaption is
needed.

However, this can lead to systemd/elogind bug confusion if there is anything
mixed up on a system that shouldn't.

Downstreams, chose any of the two ways to your own discretion!

See https://bugs.freedesktop.org/show_bug.cgi?id=101251

6 years agoPrep v230: Apply missing upstream fixes and updates (8/8) src/systemd.
Sven Eden [Wed, 31 May 2017 05:10:24 +0000 (07:10 +0200)]
Prep v230: Apply missing upstream fixes and updates (8/8) src/systemd.

6 years agoPrep v230: Apply missing upstream fixes and updates (7/8) src/shared.
Sven Eden [Wed, 31 May 2017 05:15:22 +0000 (07:15 +0200)]
Prep v230: Apply missing upstream fixes and updates (7/8) src/shared.

6 years agoPrep v230: Apply missing upstream fixes and updates (6/8) src/login.
Sven Eden [Wed, 31 May 2017 05:35:28 +0000 (07:35 +0200)]
Prep v230: Apply missing upstream fixes and updates (6/8) src/login.

6 years agoPrep v230: Apply missing upstream fixes and updates (5/8) src/libelogind.
Sven Eden [Wed, 31 May 2017 05:39:59 +0000 (07:39 +0200)]
Prep v230: Apply missing upstream fixes and updates (5/8) src/libelogind.

6 years agoPrep v230: Apply missing upstream fixes and updates (4/8) src/core.
Sven Eden [Wed, 31 May 2017 05:08:06 +0000 (07:08 +0200)]
Prep v230: Apply missing upstream fixes and updates (4/8) src/core.

6 years agoPrep v230: Apply missing upstream fixes and updates (3/8) src/cgroups-agent.
Sven Eden [Wed, 31 May 2017 05:00:37 +0000 (07:00 +0200)]
Prep v230: Apply missing upstream fixes and updates (3/8) src/cgroups-agent.

6 years agoPrep v230: Apply missing upstream fixes and updates (2/8) src/basic.
Sven Eden [Wed, 24 May 2017 11:51:31 +0000 (13:51 +0200)]
Prep v230: Apply missing upstream fixes and updates (2/8) src/basic.

6 years agoPrep v230: Apply missing upstream fixes and updates (1/8) root build files.
Sven Eden [Tue, 23 May 2017 15:22:48 +0000 (17:22 +0200)]
Prep v230: Apply missing upstream fixes and updates (1/8) root build files.

6 years agoPrep v230: Update POT files to upstream
Sven Eden [Tue, 23 May 2017 14:44:41 +0000 (16:44 +0200)]
Prep v230: Update POT files to upstream

6 years agobasic: remove rm_rf_and_free, add rm_rf_physical_and_free, use rm_rf_physical_and_fre...
Evgeny Vereshchagin [Fri, 20 May 2016 13:08:24 +0000 (16:08 +0300)]
basic: remove rm_rf_and_free, add rm_rf_physical_and_free, use rm_rf_physical_and_freep in tests (#3292)

Some distros don't mount /tmp as tmpfs.
For example:
https://lists.ubuntu.com/archives/ubuntu-cloud/2016-January/001009.html

Some tests:
* print 'Attempted to remove disk file system, and we can't allow that.'
* don't really cleanup /tmp

6 years agocore: update CGroupBlockIODeviceBandwidth to record both rbps and wbps
Tejun Heo [Wed, 18 May 2016 20:51:46 +0000 (13:51 -0700)]
core: update CGroupBlockIODeviceBandwidth to record both rbps and wbps

CGroupBlockIODeviceBandwith is used to keep track of IO bandwidth limits for
legacy cgroup hierarchies.  Unlike the unified hierarchy counterpart
CGroupIODeviceLimit, a CGroupBlockIODeviceBandwiddth records either a read or
write limit and has a couple issues.

* There's no way to clear specific config entry.

* When configs are cleared for an IO direction of a unit, the kernel settings
  aren't cleared accordingly creating discrepancies.

This patch updates CGroupBlockIODeviceBandwidth so that it behaves similarly to
CGroupIODeviceLimit - each entry records both rbps and wbps limits and is
cleared if both are at default values after kernel settings are updated.

6 years agocore: introduce CGroupIOLimitType enums
Tejun Heo [Wed, 18 May 2016 20:50:56 +0000 (13:50 -0700)]
core: introduce CGroupIOLimitType enums

Currently, there are two cgroup IO limits, bandwidth max for read and write,
and they are hard-coded in various places.  This is fine for two limits but IO
is expected to grow more limits - low, high and max limits for bandwidth and
IOPS - and hard-coding each limit won't make sense.

This patch replaces hard-coded limits with an array indexed by
CGroupIOLimitType and accompanying string and default value tables so that new
limits can be added trivially.

6 years agobasic: define HEXDIGITS
Daniel Kahn Gillmor [Tue, 17 May 2016 13:44:32 +0000 (09:44 -0400)]
basic: define HEXDIGITS

define HEXDIGITS alongside DIGITS, and use it where it's already useful.  We'll
use it again shortly when parsing MAC addresses.

6 years agomissing.h: add BTRFS_IOC_QUOTA_RESCAN_WAIT (#3266)
Stefan Saraev [Mon, 16 May 2016 14:58:46 +0000 (17:58 +0300)]
missing.h: add BTRFS_IOC_QUOTA_RESCAN_WAIT (#3266)

6 years agologind: introduce LockedHint and SetLockedHint (#3238)
Victor Toso [Wed, 11 May 2016 17:34:13 +0000 (19:34 +0200)]
logind: introduce LockedHint and SetLockedHint (#3238)

Desktop environments can keep this property up to date to allow
applications to easily track session's Lock status.

6 years agopo, catalog - add Bulgarian translation
Alexander Shopov [Wed, 11 May 2016 07:02:04 +0000 (10:02 +0300)]
po, catalog - add Bulgarian translation

6 years agolocale-util: mark special_glyph() as _const_
Zbigniew Jędrzejewski-Szmek [Mon, 9 May 2016 15:24:08 +0000 (11:24 -0400)]
locale-util: mark special_glyph() as _const_

_const_ means that the caller can assume that the function will return the same
result every time (and will not modify global memory). special_glyph() meets
this: even though it depends on global memory, that part of global memory is
not expected to change. This allows the calls to special_glyph() to be
optimized, even if -flto is not used.

6 years agotree-wide: rename draw_special_char to special_glyph
Zbigniew Jędrzejewski-Szmek [Sat, 7 May 2016 21:30:18 +0000 (17:30 -0400)]
tree-wide: rename draw_special_char to special_glyph

That function doesn't draw anything on it's own, just returns a string, which
sometimes is more than one character. Also remove "DRAW_" prefix from character
names, TREE_* and ARROW and BLACK_CIRCLE are unambigous on their own, don't
draw anything, and are always used as an argument to special_glyph().

Rename "DASH" to "MDASH", as there's more than one type of dash.

6 years agocore: rework how we flush incoming traffic when a socket unit goes down
Lennart Poettering [Fri, 6 May 2016 11:29:26 +0000 (13:29 +0200)]
core: rework how we flush incoming traffic when a socket unit goes down

Previously, we'd simply close and reopen the socket file descriptors. This is
problematic however, as we won't transition through the SOCKET_CHOWN state
then, and thus the file ownership won't be correct for the sockets.

Rework the flushing logic, and actually read any queued data from the sockets
for flushing, and accept any queued messages and disconnect them.

6 years agocore: add io controller support on the unified hierarchy
Tejun Heo [Thu, 5 May 2016 20:42:55 +0000 (16:42 -0400)]
core: add io controller support on the unified hierarchy

On the unified hierarchy, blkio controller is renamed to io and the interface
is changed significantly.

* blkio.weight and blkio.weight_device are consolidated into io.weight which
  uses the standardized weight range [1, 10000] with 100 as the default value.

* blkio.throttle.{read|write}_{bps|iops}_device are consolidated into io.max.
  Expansion of throttling features is being worked on to support
  work-conserving absolute limits (io.low and io.high).

* All stats are consolidated into io.stats.

This patchset adds support for the new interface.  As the interface has been
revamped and new features are expected to be added, it seems best to treat it
as a separate controller rather than trying to expand the blkio settings
although we might add automatic translation if only blkio settings are
specified.

* io.weight handling is mostly identical to blkio.weight[_device] handling
  except that the weight range is different.

* Both read and write bandwidth settings are consolidated into
  CGroupIODeviceLimit which describes all limits applicable to the device.
  This makes it less painful to add new limits.

* "max" can be used to specify the maximum limit which is equivalent to no
  config for max limits and treated as such.  If a given CGroupIODeviceLimit
  doesn't contain any non-default configs, the config struct is discarded once
  the no limit config is applied to cgroup.

* lookup_blkio_device() is renamed to lookup_block_device().

Signed-off-by: Tejun Heo <htejun@fb.com>
6 years agotree-wide: introduce new SOCKADDR_UN_LEN() macro, and use it everywhere
Lennart Poettering [Thu, 5 May 2016 20:24:36 +0000 (22:24 +0200)]
tree-wide: introduce new SOCKADDR_UN_LEN() macro, and use it everywhere

The macro determines the right length of a AF_UNIX "struct sockaddr_un" to pass to
connect() or bind(). It automatically figures out if the socket refers to an
abstract namespace socket, or a socket in the file system, and properly handles
the full length of the path field.

This macro is not only safer, but also simpler to use, than the usual
offsetof() + strlen() logic.

6 years agocore: use an AF_UNIX/SOCK_DGRAM socket for cgroup agent notification
Lennart Poettering [Wed, 4 May 2016 18:43:23 +0000 (20:43 +0200)]
core: use an AF_UNIX/SOCK_DGRAM socket for cgroup agent notification

dbus-daemon currently uses a backlog of 30 on its D-bus system bus socket. On
overloaded systems this means that only 30 connections may be queued without
dbus-daemon processing them before further connection attempts fail. Our
cgroups-agent binary so far used D-Bus for its messaging, and hitting this
limit hence may result in us losing cgroup empty messages.

This patch adds a seperate cgroup agent socket of type AF_UNIX/SOCK_DGRAM.
Since sockets of these types need no connection set up, no listen() backlog
applies. Our cgroup-agent binary will hence simply block as long as it can't
enqueue its datagram message, so that we won't lose cgroup empty messages as
likely anymore.

This also rearranges the ordering of the processing of SIGCHLD signals, service
notification messages (sd_notify()...) and the two types of cgroup
notifications (inotify for the unified hierarchy support, and agent for the
classic hierarchy support). We now always process events for these in the
following order:

  1. service notification messages  (SD_EVENT_PRIORITY_NORMAL-7)
  2. SIGCHLD signals (SD_EVENT_PRIORITY_NORMAL-6)
  3. cgroup inotify and cgroup agent (SD_EVENT_PRIORITY_NORMAL-5)

This is because when receiving SIGCHLD we invalidate PID information, which we
need to process the service notification messages which are bound to PIDs.
Hence the order between the first two items. And we want to process SIGCHLD
metadata to detect whether a service is gone, before using cgroup
notifications, to decide when a service is gone, since the former carries more
useful metadata.

Related to this:
https://bugs.freedesktop.org/show_bug.cgi?id=95264
https://github.com/elogind/elogind/issues/1961

6 years agologind: enforce a limit on inhibitors we hand out
Lennart Poettering [Wed, 4 May 2016 17:40:05 +0000 (19:40 +0200)]
logind: enforce a limit on inhibitors we hand out

For similar reasons as the recent addition of a limit on sessions.

Note that we don't enforce a limit on inhibitors per-user currently, but
there's an implicit one, since each inhibitor takes up one fd, and fds are
limited via RLIMIT_NOFILE, and the limit on the number of processes per user.

6 years agologind: expose more configuration settings as bus properties
Lennart Poettering [Wed, 4 May 2016 17:22:30 +0000 (19:22 +0200)]
logind: expose more configuration settings as bus properties

6 years agologind: don't include session lists in PropertyChanged messages
Lennart Poettering [Wed, 4 May 2016 17:05:18 +0000 (19:05 +0200)]
logind: don't include session lists in PropertyChanged messages

If we have a lot of simultaneous sessions we really shouldn't send the full
list of active sessions with each PropertyChanged message for user and seat
objects, as that can become quite substantial data, we probably shouldn't dump
on the bus on each login and logout.

Note that the global list of sessions doesn't send out changes like this
either, it only supports requesting the session list with ListSessions().

If cients want to get notified about sessions coming and going they should
subscribe to SessionNew and SessionRemoved signals, and clients generally do
that already.

This is kind of an API break, but then again the fact that this was included
was never documented.

6 years agologind: process session/inhibitor fds at higher priority
Lennart Poettering [Wed, 4 May 2016 17:01:56 +0000 (19:01 +0200)]
logind: process session/inhibitor fds at higher priority

Let's make sure we process session and inhibitor pipe fds (that signal
sessions/inhibtors going away) at a higher priority
than new bus calls that might create new sessions or inhibitors. This helps
ensuring that the number of open sessions stays minimal.

6 years agologind: enforce a limit on current user sessions
Lennart Poettering [Wed, 4 May 2016 16:57:15 +0000 (18:57 +0200)]
logind: enforce a limit on current user sessions

We really should put limits on all resources we manage, hence add one to the
number of concurrent sessions, too. This was previously unbounded, hence set a
relatively high limit of 8K by default.

Note that most PAM setups will actually invoke pam_elogind prefixed with "-",
so that the return code of pam_elogind is ignored, and the login attempt
succeeds anyway. On systems like this the session will be created but is not
tracked by elogind.

6 years agocore: make unit_has_mask_realized() consider controller enable state
Tejun Heo [Sat, 30 Apr 2016 20:12:54 +0000 (16:12 -0400)]
core: make unit_has_mask_realized() consider controller enable state

unit_has_mask_realized() determines whether the specified unit has its cgroups
set up properly given the desired target_mask; however, on the unified
hierarchy, controllers need to be enabled explicitly for children and the mask
of enabled controllers can deviate from target_mask.  Only considering
target_mask in unit_has_mask_realized() can lead to false positives and
skipping enabling the requested controllers.

This patch adds unit->cgroup_enabled_mask to track which controllers are
enabled and updates unit_has_mask_realized() to also consider enable_mask.

Signed-off-by: Tejun Heo <htejun@fb.com>
6 years agomachined: support non-btrfs file systems with "machinectl clone"
Lennart Poettering [Fri, 29 Apr 2016 18:06:20 +0000 (20:06 +0200)]
machined: support non-btrfs file systems with "machinectl clone"

Fall back to a normal copy operation when the backing file system isn't btrfs,
and hence doesn't support cheap snapshotting. Of course, this will be slow, but
given that the execution is asynchronous now, this should be OK.

Fixes: #1308
6 years agocopy: adjust directory times after writing to the directory
Lennart Poettering [Fri, 29 Apr 2016 17:44:59 +0000 (19:44 +0200)]
copy: adjust directory times after writing to the directory

When recursively copying a directory tree, fix up the file times after having
created all contents in it, so that our changes don't end up altering any of
the directory times.

6 years agocopy: return the right error when we can't open a file
Lennart Poettering [Fri, 29 Apr 2016 17:42:07 +0000 (19:42 +0200)]
copy: return the right error when we can't open a file

6 years agocopy: also copy AF_UNIX sockets
Lennart Poettering [Fri, 29 Apr 2016 12:21:22 +0000 (14:21 +0200)]
copy: also copy AF_UNIX sockets

We previously would fail with EOPNOTSUPP when encountering an AF_UNIX socket in
the directory tree to copy. Fix that, and copy them too (even if they are dead
in the result).

Fixes: #2914
6 years agoparse-util: fix conversion from size_t on s390 (#3147)
Lubomir Rintel [Fri, 29 Apr 2016 09:45:07 +0000 (11:45 +0200)]
parse-util: fix conversion from size_t on s390 (#3147)

On s390 size_t is an unsigned long, nor an unsigned int. They both are
of the same size and can be cast to each other safely, but the compiler
still seems unhappy about incompatible pointers.

Fixes: 7c2da2ca8
6 years agobasic/mount-util: recognize pvfs2 as network fs (#3140)
Zbigniew Jędrzejewski-Szmek [Thu, 28 Apr 2016 17:49:16 +0000 (13:49 -0400)]
basic/mount-util: recognize pvfs2 as network fs (#3140)

Added to kernel 4.6.

6 years agotree-wide: rename hidden_file to hidden_or_backup_file and optimize
Zbigniew Jędrzejewski-Szmek [Wed, 27 Apr 2016 13:24:59 +0000 (09:24 -0400)]
tree-wide: rename hidden_file to hidden_or_backup_file and optimize

In standard linux parlance, "hidden" usually means that the file name starts
with ".", and nothing else. Rename the function to convey what the function does
better to casual readers.

Stop exposing hidden_file_allow_backup which is rather ugly and rewrite
hidden_file to extract the suffix first. Note that hidden_file_allow_backup
excluded files with "~" at the end, which is quite confusing. Let's get
rid of it before it gets used in the wrong place.

6 years agobasic/dirent-util: do not call hidden_file_allow_backup from dirent_is_file_with_suffix
Zbigniew Jędrzejewski-Szmek [Wed, 27 Apr 2016 12:59:12 +0000 (08:59 -0400)]
basic/dirent-util: do not call hidden_file_allow_backup from dirent_is_file_with_suffix

If the file name is supposed to end in a suffix, there's not need to check the
name against a list of "special" file names, which is slow. Instead, just check
that the name doens't start with a period.

6 years agopath-util: Add hidden suffixes for ucf (#3131)
Martin Pitt [Wed, 27 Apr 2016 07:58:42 +0000 (09:58 +0200)]
path-util: Add hidden suffixes for ucf (#3131)

ucf is a standard Debian helper for managing configuration file upgrades which
need more interaction or elaborate merging than conffiles managed by dpkg.
Ignore its temporary and backup files similarly to the *.dpkg-* ones to avoid
creating units for them in generators.

https://bugs.debian.org/775903

6 years agobuild-sys: improve compat with older kernel headers
Lennart Poettering [Wed, 27 Apr 2016 07:44:49 +0000 (09:44 +0200)]
build-sys: improve compat with older kernel headers

In 4.2 kernel headers, some netlink defines are missing that we need. missing.h
already can add them in, but currently makes this dependent on a definition
that these kernels already have. Change the check hence to check for the newest
definition in the table, so that the whole bunch of definitions as added in on
all kernels lacking this.

6 years agoelogind --user: call pam_loginuid when creating user@.service (#3120)
Zbigniew Jędrzejewski-Szmek [Tue, 26 Apr 2016 09:19:10 +0000 (05:19 -0400)]
elogind --user: call pam_loginuid when creating user@.service (#3120)

This way the user service will have a loginuid, and it will be inherited by
child services. This shouldn't change anything as far as elogind itself is
concerned, but is nice for various services spawned from by elogind --user
that expect a loginuid.

pam_loginuid(8) says that it should be enabled for "..., crond and atd".
user@.service should behave similarly to those two as far as audit is
concerned.

https://bugzilla.redhat.com/show_bug.cgi?id=1328947#c28

6 years agonspawn: don't try to patch UIDs/GIDs of procfs and suchlike
Lennart Poettering [Fri, 22 Apr 2016 16:10:16 +0000 (18:10 +0200)]
nspawn: don't try to patch UIDs/GIDs of procfs and suchlike

6 years agonspawn: make -U a tiny bit smarter
Lennart Poettering [Fri, 22 Apr 2016 12:10:09 +0000 (14:10 +0200)]
nspawn: make -U a tiny bit smarter

With this change -U will turn on user namespacing only if the kernel actually
supports it and otherwise gracefully degrade to non-userns mode.

6 years agotree-wide: use mdash instead of a two minuses
Zbigniew Jędrzejewski-Szmek [Fri, 22 Apr 2016 02:57:06 +0000 (22:57 -0400)]
tree-wide: use mdash instead of a two minuses

6 years agonetworkd: bump MTU to 1280 for interfaces which have IPv6 enabled (#3077)
Susant Sahani [Thu, 21 Apr 2016 00:34:13 +0000 (06:04 +0530)]
networkd: bump MTU to 1280 for interfaces which have IPv6 enabled (#3077)

IPv6 protocol requires a minimum MTU of 1280 bytes on the interface.
This fixes #3046.

Introduce helper link_ipv6_enabled() to figure out whether IPV6 is enabled.
Introduce network_has_static_ipv6_addresses() to find out if any static
ipv6 address configured.
If IPv6 is not configured on any interface that is SLAAC, DHCPv6 and static
IPv6 addresses not configured, then IPv6 will be automatically disabled for that
interface, that is we write "1" to /proc/sys/net/ipv6/conf//disable_ipv6.

6 years agotree-wide: don't assume CLOCK_BOOTIME is generally available
Lennart Poettering [Wed, 20 Apr 2016 16:12:57 +0000 (18:12 +0200)]
tree-wide: don't assume CLOCK_BOOTIME is generally available

Before we invoke now(CLOCK_BOOTTIME), let's make sure we actually have that
clock, since now() will otherwise hit an assert.

Specifically, let's refuse CLOCK_BOOTTIME early in sd-event if the kernel
doesn't actually support it.

This is a follow-up for #3037, and specifically:

https://github.com/elogind/elogind/pull/3037#issuecomment-210199167

6 years agoshared: move unit-specific code from bus-util.h to bus-unit-util.h
Lennart Poettering [Wed, 20 Apr 2016 15:43:13 +0000 (17:43 +0200)]
shared: move unit-specific code from bus-util.h to bus-unit-util.h

Previously we'd have generally useful sd-bus utilities in bust-util.h,
intermixed with code that is specifically for writing clients for PID 1,
wrapping job and unit handling. Let's split the latter out and move it into
bus-unit-util.c, to make the sources a bit short and easier to grok.

6 years agocore,systemctl: add bus API to retrieve processes of a unit
Lennart Poettering [Wed, 20 Apr 2016 13:28:28 +0000 (15:28 +0200)]
core,systemctl: add bus API to retrieve processes of a unit

This adds a new GetProcesses() bus call to the Unit object which returns an
array consisting of all PIDs, their process names, as well as their full cgroup
paths. This is then used by "systemctl status" to show the per-unit process
tree.

This has the benefit that the client-side no longer needs to access the
cgroupfs directly to show the process tree of a unit. Instead, it now uses this
new API, which means it also works if -H or -M are used correctly, as the
information from the specific host is used, and not the one from the local
system.

Fixes: #2945
6 years agologind: use type to determine graphical sessions (#3071)
Michał Bartoszkiewicz [Wed, 20 Apr 2016 08:06:26 +0000 (10:06 +0200)]
logind: use type to determine graphical sessions (#3071)

6 years agobasic: user-utils.c needs missing.h for secure_getenv (#3059)
michaelolbrich [Mon, 18 Apr 2016 13:28:00 +0000 (15:28 +0200)]
basic: user-utils.c needs missing.h for secure_getenv (#3059)

Otherwise building may fail with:

src/basic/user-util.c: In function 'get_home_dir':
src/basic/user-util.c:343:9: error: implicit declaration of function 'secure_getenv' [-Werror=implicit-function-declaration]

6 years agonetworkd: allow setting of multicast querier for linux bridge (#3051)
Susant Sahani [Mon, 18 Apr 2016 11:45:52 +0000 (17:15 +0530)]
networkd: allow setting of multicast querier for linux bridge (#3051)

6 years agoconf-parser: Set EXTRACT_RETAIN_ESCAPE when extracting words (#2917)
Dan Nicholson [Mon, 18 Apr 2016 02:52:45 +0000 (19:52 -0700)]
conf-parser: Set EXTRACT_RETAIN_ESCAPE when extracting words (#2917)

If you reference another unit with an escaped name, the escaped characters
should remain in the extracted word. This used to work correctly prior to
commit 34f253f0.

The problem can be seen when units with escaped names are referenced.

$ cat "/usr/lib/elogind/system/dev-disk-by\x2dlabel-eos\x2dswap.swap"
[Swap]
What=/dev/disk/by-label/eos-swap

[Install]
WantedBy=dev-disk-by\x2dlabel-eos\x2dswap.device

$ systemctl enable "dev-disk-by\x2dlabel-eos\x2dswap.swap"
Created symlink
/etc/elogind/system/dev-disk-byx2dlabel-eosx2dswap.device.wants/dev-disk-by\x2dlabel-eos\x2dswap.swap,
pointing to /usr/lib/elogind/system/dev-disk-by\x2dlabel-eos\x2dswap.swap.

The wants directory should be created with the x2ds escaped with \.

6 years agotree-wide: fall back to now(CLOCK_MONOTONIC) if CLOCK_BOOTTIME unsupported (#3037)
Lubomir Rintel [Mon, 18 Apr 2016 01:45:42 +0000 (03:45 +0200)]
tree-wide: fall back to now(CLOCK_MONOTONIC) if CLOCK_BOOTTIME unsupported (#3037)

It was added in 2.6.39, and causes an assertion to fail when running in mock
hosted on 2.6.32-based RHEL-6:

Assertion 'clock_gettime(map_clock_id(clock_id), &ts) == 0' failed at elogind/src/basic/time-util.c:70, function now(). Aborting.

6 years agoshared/install,systemctl,core: report offending file on installation error
Zbigniew Jędrzejewski-Szmek [Sun, 17 Apr 2016 14:16:44 +0000 (10:16 -0400)]
shared/install,systemctl,core: report offending file on installation error

Fixes #2191:

$ systemctl --root=/ enable sddm
Created symlink /etc/elogind/system/display-manager.service, pointing to /usr/lib/elogind/system/sddm.service.
$ sudo build/systemctl --root=/ enable gdm
Failed to enable unit, file /etc/elogind/system/display-manager.service already exists and is a symlink to /usr/lib/elogind/system/sddm.service.
$ sudo build/systemctl --root= enable sddm
$ sudo build/systemctl --root= enable gdm
Failed to enable unit: File /etc/elogind/system/display-manager.service already exists and is a symlink to /usr/lib/elogind/system/sddm.service.

(I tried a few different approaches to pass the error information back to the
caller. Adding a new parameter to hold the error results in a gigantic patch
and a lot of hassle to pass the args arounds. Adding this information to the
changes array is straightforward and can be more easily extended in the
future.)

In case local installation is performed, the full set of errors can be reported
and we do that. When running over dbus, only the first error is reported.

6 years agotree-wide: introduce PATH_IN_SET macro
Zbigniew Jędrzejewski-Szmek [Sun, 17 Apr 2016 02:52:06 +0000 (22:52 -0400)]
tree-wide: introduce PATH_IN_SET macro

6 years agosystemctl/core: ignore masked units in preset-all
Zbigniew Jędrzejewski-Szmek [Sat, 16 Apr 2016 23:31:53 +0000 (19:31 -0400)]
systemctl/core: ignore masked units in preset-all

With any masked unit that would that would be enabled by presets, we'd get:

test@rawhide $ sudo systemctl preset-all
Failed to execute operation: Unit file is masked.

test@rawhide $ sudo systemctl --root=/ preset-all
Operation failed: Cannot send after transport endpoint shutdown

Simply ignore those units:

test@rawhide $ sudo systemctl preset-all
Unit xxx.service is masked, ignoring.

6 years agosd-bus: use IN_SET
Zbigniew Jędrzejewski-Szmek [Sat, 16 Apr 2016 22:21:58 +0000 (18:21 -0400)]
sd-bus: use IN_SET

6 years agocore/mount-setup.c: also relabel /dev/shm for selinux (#3039)
Harald Hoyer [Thu, 14 Apr 2016 23:14:29 +0000 (01:14 +0200)]
core/mount-setup.c: also relabel /dev/shm for selinux (#3039)

daemons, which wish to transition state from the initramfs to the real
root, might use /dev/shm for their state.

As /dev is not relabeled across mount points, /dev/shm has to be
relabled explicitly.

6 years agosd-bus: query pid also when searching for supplementary gids
Ismo Puustinen [Wed, 13 Apr 2016 12:38:03 +0000 (15:38 +0300)]
sd-bus: query pid also when searching for supplementary gids

If the SD_BUS_CREDS_SUPPLEMENTARY_GIDS value is requested, the pid is
queried to find out the supplementary gids value from /proc/pid/status.
Otherwise sd_bus_creds_get_supplementary_gids() won't work unless some
other value in mask triggered fetching the pid information.

6 years agologind: allow any user to request lingering
Zbigniew Jędrzejewski-Szmek [Wed, 13 Apr 2016 02:52:28 +0000 (22:52 -0400)]
logind: allow any user to request lingering

We enable lingering for anyone who wants this. It is still disabled by
default to avoid keeping long-running processes accidentally.
Admins might want to customize this policy on multi-user sites.

6 years agocore: make sure we generate a nicer error when a linked unit is attempted to be enabled
Lennart Poettering [Mon, 11 Apr 2016 15:57:05 +0000 (17:57 +0200)]
core: make sure we generate a nicer error when a linked unit is attempted to be enabled

We don't allow using config symlinks to enable units, but the error message we
printed was awful. Fix that, and generate a more readable error.

Fixes #3010.

6 years agologind: reload config on SIGHUP
Zbigniew Jędrzejewski-Szmek [Sat, 9 Apr 2016 19:03:19 +0000 (15:03 -0400)]
logind: reload config on SIGHUP

v2:
- fix setting of kill_user_processes and
  *_ignore_inhibited settings

6 years agotree-wide: remove useless NULLs from strjoina
Zbigniew Jędrzejewski-Szmek [Sat, 9 Apr 2016 18:04:09 +0000 (14:04 -0400)]
tree-wide: remove useless NULLs from strjoina

The coccinelle patch didn't work in some places, I have no idea why.

6 years agobasic/util: check return value of dup2 in fork_agent()
Zbigniew Jędrzejewski-Szmek [Sat, 9 Apr 2016 01:08:29 +0000 (21:08 -0400)]
basic/util: check return value of dup2 in fork_agent()

CID #1304689.

6 years agotests: override XDG_RUNTIME_DIR where we use the user runtime dir
Lennart Poettering [Fri, 8 Apr 2016 16:54:05 +0000 (18:54 +0200)]
tests: override XDG_RUNTIME_DIR where we use the user runtime dir

We don#t really support systems where XDG_RUNTIME_DIR is not supported for
elogind --user. Hence, let's always set our own XDG_RUNTIME_DIR for tests that
involve elogind --user, so that we know it is set, and that it doesn't polute
the user's actual runtime dir.