chiark / gitweb /
elogind.git
7 years agocore: rework unit name validation and manipulation logic
Lennart Poettering [Thu, 30 Apr 2015 18:21:00 +0000 (20:21 +0200)]
core: rework unit name validation and manipulation logic

A variety of changes:

- Make sure all our calls distuingish OOM from other errors if OOM is
  not the only error possible.

- Be much stricter when parsing escaped paths, do not accept trailing or
  leading escaped slashes.

- Change unit validation to take a bit mask for allowing plain names,
  instance names or template names or an combination thereof.

- Refuse manipulating invalid unit name

7 years agoutil: be a bit safer in path_is_safe()
Lennart Poettering [Thu, 30 Apr 2015 17:44:10 +0000 (19:44 +0200)]
util: be a bit safer in path_is_safe()

We should be more strict when verifying paths with path_is_safe() for
potentially dangerous constructs, and that includes lengths of
PATH_MAX-1 and larger. Be more accurate here.

7 years agocore: catch some special cases in cg_slice_to_path()
Lennart Poettering [Thu, 30 Apr 2015 10:33:35 +0000 (12:33 +0200)]
core: catch some special cases in cg_slice_to_path()

7 years agosym: adding missing symbols to .sym file
Lennart Poettering [Thu, 30 Apr 2015 10:01:19 +0000 (12:01 +0200)]
sym: adding missing symbols to .sym file

7 years agosd-bus,sd-login: add api for querying the slice within the the user systemd instance...
Lennart Poettering [Thu, 30 Apr 2015 09:58:06 +0000 (11:58 +0200)]
sd-bus,sd-login: add api for querying the slice within the the user systemd instance of a process

units are organized in slice trees, not only for the system instance,
but also for user systemd instances, expose this properly.

7 years agosd-bus: when we get ENOTTY on the HELLO ioctl assume incompatible API version
Lennart Poettering [Wed, 29 Apr 2015 23:24:48 +0000 (01:24 +0200)]
sd-bus: when we get ENOTTY on the HELLO ioctl assume incompatible API version

As perparation for future incompatible kdbus kernel API changes.

7 years agocore: rework cgroup path parse logic
Lennart Poettering [Wed, 29 Apr 2015 22:47:41 +0000 (00:47 +0200)]
core: rework cgroup path parse logic

Various cleanups, be stricter when parsing unit paths.

Most importantly: return the root slice "-.slice" when asked for slice
of paths that contain no slice component.

7 years agoman: document when the various sd-login.h calls return ENXIO
Lennart Poettering [Wed, 29 Apr 2015 19:45:45 +0000 (21:45 +0200)]
man: document when the various sd-login.h calls return ENXIO

7 years agosd-bus: properly handle creds that are known but undefined for a process
Lennart Poettering [Wed, 29 Apr 2015 19:40:54 +0000 (21:40 +0200)]
sd-bus: properly handle creds that are known but undefined for a process

A number of fields do not apply to all processes, including: there a
processes without a controlling tty, without parent process, without
service, user services or session. To distuingish these cases from the
case where we simply don't have the data, always return ENXIO for them,
while returning ENODATA for the case where we really lack the
information.

Also update the credentials dumping code to show this properly. Fields
that are known but do not apply are now shown as "n/a".

Note that this also changes some of the calls in process-util.c and
cgroup-util.c to return ENXIO for these cases.

7 years agosd-bus: allow passing NULL as bus parameter to sd_bus_send()
Lennart Poettering [Wed, 29 Apr 2015 16:58:30 +0000 (18:58 +0200)]
sd-bus: allow passing NULL as bus parameter to sd_bus_send()

If NULL is specified for the bus it is now automatically derived from
the passed in message.

This commit also changes a number of invocations of sd_bus_send() to
make use of this.

7 years agosd-bus: drop bus parameter from message callback prototype
Lennart Poettering [Wed, 29 Apr 2015 16:35:10 +0000 (18:35 +0200)]
sd-bus: drop bus parameter from message callback prototype

This should simplify the prototype a bit. The bus parameter is redundant
in most cases, and in the few where it matters it can be derived from
the message via sd_bus_message_get_bus().

7 years agobus-util: drop redundant bus argument from bus_message_map_all_properties() and relat...
Lennart Poettering [Tue, 28 Apr 2015 18:48:54 +0000 (20:48 +0200)]
bus-util: drop redundant bus argument from bus_message_map_all_properties() and related calls

7 years agoexit-status: introduce common exit_status_set_test() call for testing exit status...
Lennart Poettering [Tue, 28 Apr 2015 16:24:20 +0000 (18:24 +0200)]
exit-status: introduce common exit_status_set_test() call for testing exit status set membership

7 years agobus-util: print correct warnings for units that fail but for which we have a NULL...
Lennart Poettering [Tue, 28 Apr 2015 10:12:29 +0000 (12:12 +0200)]
bus-util: print correct warnings for units that fail but for which we have a NULL result only

7 years agopath-util: fix fstat fallback in fd_is_mount_point
Thomas Hindoe Paaboel Andersen [Sun, 26 Apr 2015 13:57:29 +0000 (15:57 +0200)]
path-util: fix fstat fallback in fd_is_mount_point

7 years agosd-device: don't retry loading uevent/db files more than once
Tom Gundersen [Sat, 25 Apr 2015 23:07:42 +0000 (01:07 +0200)]
sd-device: don't retry loading uevent/db files more than once

If for whatever reason there was nothing to load or loading failed, don't keep trying.

7 years agosd-device: don't complain if the uevent file is missing
Tom Gundersen [Sat, 25 Apr 2015 23:04:33 +0000 (01:04 +0200)]
sd-device: don't complain if the uevent file is missing

Only 'real' devices are required to have an uevent file.

7 years agologind: kill newline characters from log_error_errno() calls
Daniel Mack [Fri, 24 Apr 2015 19:44:51 +0000 (21:44 +0200)]
logind: kill newline characters from log_error_errno() calls

log_error_errno() already adds a newline, so drop them.

7 years agosysctl: minor simplifications
Lennart Poettering [Fri, 24 Apr 2015 17:56:24 +0000 (19:56 +0200)]
sysctl: minor simplifications

7 years agoUpdate Spanish translation
Daniel Mustieles [Fri, 24 Apr 2015 13:13:34 +0000 (09:13 -0400)]
Update Spanish translation

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

7 years agosd-bus: add controlling tty field to sd_creds object
Lennart Poettering [Thu, 23 Apr 2015 17:43:40 +0000 (19:43 +0200)]
sd-bus: add controlling tty field to sd_creds object

This is useful to print wall messages from logind with the right client
tty. (to be added in a later patch)

7 years agoshutdownd: kill the old implementation
Daniel Mack [Thu, 23 Apr 2015 15:30:23 +0000 (17:30 +0200)]
shutdownd: kill the old implementation

Not that all functionality has been ported over to logind, the old
implementation can be removed. There goes one of the oldest parts of
the systemd code base.

7 years agologind: add support for /run/nologin and /run/systemd/shutdown/scheduled
Daniel Mack [Thu, 23 Apr 2015 15:11:28 +0000 (17:11 +0200)]
logind: add support for /run/nologin and /run/systemd/shutdown/scheduled

Port over more code from shutdownd and teach logind to write /run/nologin at
least 5 minutes before the system is going down, and
/run/systemd/shutdown/scheduled when a shutdown is scheduled.

7 years agosd-bus: when bus operations are to be executed on direct connections always fail
Lennart Poettering [Thu, 23 Apr 2015 14:23:15 +0000 (16:23 +0200)]
sd-bus: when bus operations are to be executed on direct connections always fail

Also, don't consider this an loggable event, so that code that tries to
read creds from a direct connection, doesn't generate logs.

7 years agoudevd: fix REMOVE handling
Tom Gundersen [Thu, 23 Apr 2015 13:19:13 +0000 (15:19 +0200)]
udevd: fix REMOVE handling

This reverts b67f944. Lazy loading of device properties does not work for devices
that are received over netlink, as these are sealed. Reinstate the unconditional
loading of the device db.

Reported by: Mantas Mikulėnas <grawity@gmail.com>.

7 years agosd-bus: don't inherit connection creds into message creds when we have a direct conne...
Lennart Poettering [Thu, 23 Apr 2015 11:37:03 +0000 (13:37 +0200)]
sd-bus: don't inherit connection creds into message creds when we have a direct connection

It's never a good idea, let's just not do it, not even on dierct
connections.

7 years agopath-util: make use of "mnt_id" field exported in /proc/self/fdinfo/<fd> to test...
Lennart Poettering [Thu, 23 Apr 2015 11:23:03 +0000 (13:23 +0200)]
path-util: make use of "mnt_id" field exported in /proc/self/fdinfo/<fd> to test for mount points

It's a very recent kernel addition, but certainly makes sense to
support.

7 years agohwdb: fix typo - "sort by by..." -> "sort by..."
Peter Hutterer [Thu, 23 Apr 2015 01:10:04 +0000 (11:10 +1000)]
hwdb: fix typo - "sort by by..." -> "sort by..."

7 years agocore: explicitly specify credentials for direct connections, too
Lennart Poettering [Wed, 22 Apr 2015 22:37:47 +0000 (00:37 +0200)]
core: explicitly specify credentials for direct connections, too

So far we authenticate direct connections primarily at connection time,
but let's also do this for each method individually, by attaching the
creds we need for that right away.

7 years agojournalctl: rework code that checks whether we have access to /var/log/journal
Lennart Poettering [Wed, 22 Apr 2015 20:54:23 +0000 (22:54 +0200)]
journalctl: rework code that checks whether we have access to /var/log/journal

- fix some memory leaks on error conditions

- handle all error cases properly, and log about failures

- move HAVE_ACL and no-HAVE_ACL code closer to each other

7 years agolibudev-device: fix lazy loading of devlinks, properties and tags
Tom Gundersen [Wed, 22 Apr 2015 17:01:50 +0000 (19:01 +0200)]
libudev-device: fix lazy loading of devlinks, properties and tags

If the underlying device has not read in the properties yet, the generation will be 0, so
make sure we trigger the reading at least once.

7 years agologind: add code for UTMP wall messages
Daniel Mack [Wed, 22 Apr 2015 15:20:42 +0000 (17:20 +0200)]
logind: add code for UTMP wall messages

Add a timer to print UTMP wall messages so that it repeatedly informs users
about a scheduled shutdown:

 * every 1 minute with less than 10 minutes to go
 * every 15 minutes with less than 60 minutes to go
 * every 30 minutes with less than 180 minutes (3 hours) to go
 * every 60 minutes if more than that to go

This functionality only active if the .EnableWallMessages DBus property
is set to true. Also, a custom string can be added to the wall message,
set through the WallMessagePrefix property.

7 years agobtrfs-util: support recursive removal of read-only subvolumes
Lennart Poettering [Wed, 22 Apr 2015 15:09:20 +0000 (17:09 +0200)]
btrfs-util: support recursive removal of read-only subvolumes

When deleting a read-only subsvolume with a sub-subvolume, we need to
mark it writable first, otherwise the removal will not work.

7 years agobtrfs-util: fix creating recursive read-only snapshots
Lennart Poettering [Wed, 22 Apr 2015 14:52:53 +0000 (16:52 +0200)]
btrfs-util: fix creating recursive read-only snapshots

When creating recursive read-only snapshots we need to mark the snapshot
writable immediately before creating subsnapshots within it, otherwise
the operation for it will fail.

7 years agosd-bus: handle ppid=0 more gracefully (which happens for pid=1)
Lennart Poettering [Wed, 22 Apr 2015 11:27:29 +0000 (13:27 +0200)]
sd-bus: handle ppid=0 more gracefully (which happens for pid=1)

7 years agobtrfs-util: be more careful when invoking btrfs file system ioctls
Lennart Poettering [Wed, 22 Apr 2015 11:11:19 +0000 (13:11 +0200)]
btrfs-util: be more careful when invoking btrfs file system ioctls

If we get passed an fd that does not refer to a regular file or
directory, we should not issue btrfs ioctls on it, since it might end up
in a device driver or similar (note that DRM for example uses the same
ioctl numbers as some file system ioctls).

Hence, let's make sure to always check if something is a regular file or
directory, or is on btrfs before invoking the respective ioctls. It's
better to be safe than sorry.

7 years agobtrfs-util: introduce btrfs_is_filesystem() and make use of it where appropriate
Lennart Poettering [Wed, 22 Apr 2015 11:08:19 +0000 (13:08 +0200)]
btrfs-util: introduce btrfs_is_filesystem() and make use of it where appropriate

Let's unify the code that checks whether an fd is on btrfs a bit.

(Also, rename btrfs_is_snapshot() to btrfs_is_subvol(), since that's
usually how this is referred to in our code)

7 years agoutil: make sure fd refers to regular file or directory when applying file attributes
Lennart Poettering [Wed, 22 Apr 2015 11:05:26 +0000 (13:05 +0200)]
util: make sure fd refers to regular file or directory when applying file attributes

Before invoking file system ioctls we need to make sure that the
specified fd actually refers to a file system object, and not a device
node or similar. Otherwise we might by accident invoke unrelated device
driver ioctls. For example, DRM ioctls use the same ioctl numbers as the
various file system ioctls.

7 years agonetworkd: introduce vti6 tunnel
Susant Sahani [Wed, 22 Apr 2015 08:44:55 +0000 (14:14 +0530)]
networkd: introduce vti6 tunnel

This patch add support to create vti6 tunnel

test:

vt6.network
[Match]
Name=wlan0

[Network]
Tunnel=ip6vti

vti6.netdev
[NetDev]
Name=ip6vti
Kind=vti6

[Tunnel]
Local=2a00:ffde:4567:edde::4987
Remote=2001:473:fece:cafe::5179

ip link

11: ip6_vti0@NONE: <NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT
group default
    link/tunnel6 :: brd ::
12: ip6vti@wlan0: <POINTOPOINT,NOARP> mtu 1500 qdisc noop state DOWN
mode DEFAULT group default
    link/tunnel6 2a00:ffde:4567:edde::4987 peer 2001:473:fece:cafe::5179

7 years agosd-bus: expose ppid field
Lennart Poettering [Tue, 21 Apr 2015 18:58:09 +0000 (20:58 +0200)]
sd-bus: expose ppid field

kdbus has been passing us the ppid file for a while, actually make use
of it.

7 years agocore: make unit deserialization more defensive
Lennart Poettering [Tue, 21 Apr 2015 18:22:51 +0000 (20:22 +0200)]
core: make unit deserialization more defensive

7 years agotree-wide: get rid of more strerror() calls
Lennart Poettering [Tue, 21 Apr 2015 16:05:44 +0000 (18:05 +0200)]
tree-wide: get rid of more strerror() calls

7 years agotmpfiles: make /home and /var btrfs subvolumes by default when booted up with them...
Lennart Poettering [Tue, 21 Apr 2015 15:28:16 +0000 (17:28 +0200)]
tmpfiles: make /home and /var btrfs subvolumes by default when booted up with them missing

This way the root subvolume can be left read-only easily, and variable
and user data writable with explicit quota set.

7 years agotmpfiles: there's no systemd-forbid-user-logins.service service
Lennart Poettering [Tue, 21 Apr 2015 15:26:56 +0000 (17:26 +0200)]
tmpfiles: there's no systemd-forbid-user-logins.service service

7 years agolog: move log_syntax() into src/shared/log.c, and make it more similar to the other...
Lennart Poettering [Tue, 21 Apr 2015 15:26:04 +0000 (17:26 +0200)]
log: move log_syntax() into src/shared/log.c, and make it more similar to the other log functions

7 years agosd-device: set_syspath - return ENODEV when passed something that is not a device
Tom Gundersen [Tue, 21 Apr 2015 12:41:13 +0000 (14:41 +0200)]
sd-device: set_syspath - return ENODEV when passed something that is not a device

7 years agosd-bus: when augmenting creds, remember which ones were augmented
Lennart Poettering [Mon, 20 Apr 2015 22:58:08 +0000 (00:58 +0200)]
sd-bus: when augmenting creds, remember which ones were augmented

Also, when we do permissions checks using creds, verify that we don't do
so based on augmented creds, as extra safety check.

7 years agosd-bus: augmenting cgroups-based creds when we have the cgroup path already is free
Lennart Poettering [Mon, 20 Apr 2015 22:53:43 +0000 (00:53 +0200)]
sd-bus: augmenting cgroups-based creds when we have the cgroup path already is free

7 years agosd-bus: when augmenting creds, don't override any creds in any case
Lennart Poettering [Mon, 20 Apr 2015 22:52:24 +0000 (00:52 +0200)]
sd-bus: when augmenting creds, don't override any creds in any case

Let's better be safe than sorry.

7 years agosd-bus: when copying creds objects, make sure we copy even the implicit well known...
Lennart Poettering [Mon, 20 Apr 2015 22:50:43 +0000 (00:50 +0200)]
sd-bus: when copying creds objects, make sure we copy even the implicit well known names

7 years agologind: add .ScheduleShutdown and .CancelScheduledShutdown methods
Daniel Mack [Mon, 20 Apr 2015 13:27:15 +0000 (15:27 +0200)]
logind: add .ScheduleShutdown and .CancelScheduledShutdown methods

Add a method called ScheduleShutdown in org.freedesktop.login1.Manager
which adds a timer to shut down the system at a later point in time.

The first argument holds the type of the schedule that is about to
happen, and must be one of 'reboot', 'halt' or 'poweroff'.

The second argument specifies the absolute time, based on
CLOCK_REALTIME in nanoseconds, at which the the operation should be
executed.

To cancel a previously scheduled shutdown, the CancelScheduledShutdown()
can be called, which returns a bool, indicating whether a scheduled
timeout was cancelled.

Also add a new property called ScheduledShutdown which returns the
equivalent to what was passed in via ScheduleShutdown, as '(st)' type.

7 years agologind: factor out polkit checks
Daniel Mack [Mon, 20 Apr 2015 13:19:26 +0000 (15:19 +0200)]
logind: factor out polkit checks

Factor out the code to ask polkit for authorization from
method_do_shutdown_or_sleep() into an own function called
verify_shutdown_creds().

This is needed in order to also use the same checks when shutdown
operations are scheduled. For that, it's also necessary to allow
NULL values for that action{,_multiple_sessions,_ignore_inhibit)
arguments, which will suppress the call if no action string is
passed.

7 years agoutil: fix typo
Raul Gutierrez S [Mon, 20 Apr 2015 05:27:45 +0000 (22:27 -0700)]
util: fix typo

7 years agoexit-status: Fix "NOTINSSTALLED" typo
Martin Pitt [Sat, 18 Apr 2015 21:38:13 +0000 (22:38 +0100)]
exit-status: Fix "NOTINSSTALLED" typo

7 years agosd-device: uniformly handle missing devices
Tom Gundersen [Fri, 17 Apr 2015 12:53:02 +0000 (14:53 +0200)]
sd-device: uniformly handle missing devices

sd_device_new_from_* now returns -ENODEV when the device does not exist, and the enumerator
silently drops these errors as missing devices is exepected.

7 years agosd-device: enumerator - match only on initialized devices by default
Tom Gundersen [Fri, 17 Apr 2015 12:11:00 +0000 (14:11 +0200)]
sd-device: enumerator - match only on initialized devices by default

It is still possible to include uninitialized ones, but now that is opt-in. In most
cases people only want initialized devices. Exception is if you want to work without
udev running.

Suggested by David Herrmann.

7 years agosd-device: enumerator - don't expose add_device()
Tom Gundersen [Fri, 17 Apr 2015 11:50:10 +0000 (13:50 +0200)]
sd-device: enumerator - don't expose add_device()

This is rarely, if ever, used. Drop it from the new public API and only keep it for
the legacy API.

Suggested by David Herrmann.

7 years agosd-bus: add more comments to the credential decision logic
Lennart Poettering [Thu, 16 Apr 2015 15:27:51 +0000 (17:27 +0200)]
sd-bus: add more comments to the credential decision logic

7 years agoautomount: add expire support
Michael Olbrich [Tue, 14 Apr 2015 20:01:48 +0000 (22:01 +0200)]
automount: add expire support

7 years agosd-device: fix typo
Zbigniew Jędrzejewski-Szmek [Tue, 14 Apr 2015 16:39:40 +0000 (12:39 -0400)]
sd-device: fix typo

7 years agosd-devcie: fix typo
Tom Gundersen [Tue, 14 Apr 2015 14:55:18 +0000 (16:55 +0200)]
sd-devcie: fix typo

7 years agojournal: use audit event names instead of numbers
Zbigniew Jędrzejewski-Szmek [Tue, 14 Apr 2015 14:29:03 +0000 (10:29 -0400)]
journal: use audit event names instead of numbers

<audit-1400> is replaced by AVC, etc.

A fallback mechanism is provided for unlisted event types.
Occasionally new types are added to the kernel, but not too often.

Add a simple "test", which simply prints the mapping.

7 years agolibudev: make libudev-enumerate a thin wrapper around sd-device
Tom Gundersen [Tue, 14 Apr 2015 14:25:06 +0000 (16:25 +0200)]
libudev: make libudev-enumerate a thin wrapper around sd-device

7 years agosd-device: add device-enumerator library
Tom Gundersen [Tue, 14 Apr 2015 14:22:39 +0000 (16:22 +0200)]
sd-device: add device-enumerator library

7 years agosd-device: fix reading of subsystem
Tom Gundersen [Tue, 14 Apr 2015 14:05:53 +0000 (16:05 +0200)]
sd-device: fix reading of subsystem

7 years agosd-device: allow uevent files to be write-only
Tom Gundersen [Tue, 14 Apr 2015 13:15:49 +0000 (15:15 +0200)]
sd-device: allow uevent files to be write-only

7 years agopam_system: use (void) to silence coverity
Zbigniew Jędrzejewski-Szmek [Mon, 13 Apr 2015 02:41:20 +0000 (22:41 -0400)]
pam_system: use (void) to silence coverity

CID #996284.

7 years agoshared/hashmap: normalize whitespace
Zbigniew Jędrzejewski-Szmek [Sun, 12 Apr 2015 20:04:51 +0000 (16:04 -0400)]
shared/hashmap: normalize whitespace

7 years agopo: update Polish translation
Piotr Drąg [Sat, 11 Apr 2015 23:45:11 +0000 (01:45 +0200)]
po: update Polish translation

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

7 years agobus-util: add articles to explanation messages
Zbigniew Jędrzejewski-Szmek [Sat, 11 Apr 2015 23:39:30 +0000 (19:39 -0400)]
bus-util: add articles to explanation messages

We are talking about one member of a group of things (resource limits, signals,
timeouts), without specifying which one. An indenfinite article is in order.

When we are talking about the control process, it's a specific one, so the
definite article is used.

7 years agologind: make local functions static
Daniel Mack [Sat, 11 Apr 2015 17:47:12 +0000 (19:47 +0200)]
logind: make local functions static

make manager_gc(), manager_startup(), manager_new(), manager_free()
and manager_run() static, and kill their forward declarations.

7 years agologind: use sd_event timer source for inhibitor logic
Daniel Mack [Sat, 11 Apr 2015 16:44:51 +0000 (18:44 +0200)]
logind: use sd_event timer source for inhibitor logic

Instead of open-coding the delayed action and inhibit timeout logic,
switch over to a real sd_event_source based implementation.

This is not only easier to read but also allows us to add more timers
in the future.

7 years agoshared: move replace_env* from util to env-util
Ronny Chevalier [Fri, 10 Apr 2015 22:25:43 +0000 (00:25 +0200)]
shared: move replace_env* from util to env-util

7 years agoshared: add terminal-util.[ch]
Ronny Chevalier [Fri, 10 Apr 2015 21:15:59 +0000 (23:15 +0200)]
shared: add terminal-util.[ch]

7 years agoshared: add random-util.[ch]
Ronny Chevalier [Fri, 10 Apr 2015 20:27:10 +0000 (22:27 +0200)]
shared: add random-util.[ch]

7 years agoshared: add formats-util.h
Ronny Chevalier [Fri, 10 Apr 2015 18:43:52 +0000 (20:43 +0200)]
shared: add formats-util.h

7 years agoshared: move assert_return_errno() from libudev
Tom Gundersen [Fri, 10 Apr 2015 18:39:43 +0000 (20:39 +0200)]
shared: move assert_return_errno() from libudev

This should not be used for any new code, as we don't set errno in new code,
but there are several legacy users, so let's keep it in shared.

7 years agoshared: add process-util.[ch]
Ronny Chevalier [Fri, 10 Apr 2015 17:10:00 +0000 (19:10 +0200)]
shared: add process-util.[ch]

7 years agosd-event: simplify sd_event_run()
Lennart Poettering [Fri, 10 Apr 2015 16:45:39 +0000 (18:45 +0200)]
sd-event: simplify sd_event_run()

7 years agobus: implement bus_path_{en,de}code_unique()
David Herrmann [Fri, 10 Apr 2015 15:44:30 +0000 (17:44 +0200)]
bus: implement bus_path_{en,de}code_unique()

Whenever we provide a bus API that allows clients to create and manage
server-side objects, we need to provide a unique name for these objects.
There are two ways to provide them:
  1) Let the server choose a name and return it as method reply.
  2) Let the client pass its name of choice in the method arguments.

The first method is the easiest one to implement. However, it suffers from
a race condition: If a client creates an object asynchronously, it cannot
destroy that object until it received the method reply. It cannot know the
name of the new object, thus, it cannot destroy it. Furthermore, this
method enforces a round-trip. If the client _depends_ on the method call
to succeed (eg., it would close() the connection if it failed), the client
usually has no reason to wait for the method reply. Instead, the client
can immediately schedule further method calls on the newly created object
(in case the API guarantees in-order method-call handling).

The second method fixes both problems: The client passes an object name
with the method-call. The server uses it to create the object. Therefore,
the client can schedule object destruction even if the object-creation
hasn't finished, yet (again, requiring in-order method-call handling).
Furthermore, the client can schedule further method calls on the newly
created object, before the constructor returned.

There're two problems to solve, though:
  1) Object names are usually defined via dbus object paths, which are
     usually globally namespaced. Therefore, multiple clients must be able
     to choose unique object names without interference.
  2) If multiple libraries share the same bus connection, they must be
     able to choose unique object names without interference.

The first problem is solved easily by prefixing a name with the
unique-bus-name of a connection. The server side must enforce this and
reject any other name.
The second problem is solved by providing unique suffixes from within
sd-bus. As long as sd-bus always returns a fresh new ID, if requested,
multiple libraries will never interfere. This implementation re-uses
bus->cookie as ID generator, which already provides unique IDs for each
bus connection.

This patch introduces two new helpers:
  bus_path_encode_unique(sd_bus *bus,
                         const char *prefix,
                         const char *sender_id,
                         const char *external_id,
                         char **ret_path);
    This creates a new object-path via the template
    '/prefix/sender_id/external_id'. That is, it appends two new labels to
    the given prefix. If 'sender_id' is NULL, it will use
    bus->unique_name, if 'external_id' is NULL, it will allocate a fresh,
    unique cookie from bus->cookie.

  bus_path_decode_unique(const char *path,
                         const char *prefix,
                         char **ret_sender,
                         char **ret_external);
    This reverses what bus_path_encode_unique() did. It parses 'path' from
    the template '/prefix/sender/external' and returns both suffix-labels
    in 'ret_sender' and 'ret_external'. In case the template does not
    match, 0 is returned and both output arguments are set to NULL.
    Otherwise, 1 is returned and the output arguments contain the decoded
    labels.

Note: Client-side allocated IDs are inspired by the Wayland protocol
      (which itself was inspired by X11). Wayland uses those IDs heavily
      to avoid round-trips. Clients can create server-side objects and
      send method calls without any round-trip and waiting for any object
      IDs to be returned. But unlike Wayland, DBus uses gobally namespaced
      object names. Therefore, we have to add the extra step by adding the
      unique-name of the bus connection.

7 years agobus: implement bus_label_unescape_n()
David Herrmann [Fri, 10 Apr 2015 15:43:04 +0000 (17:43 +0200)]
bus: implement bus_label_unescape_n()

This is like bus_label_unescape() but takes a maximum length instead of
relying on NULL-terminated strings. This is highly useful to unescape
labels that are not at the end of a path.

7 years agocore: set_put never returns -EEXIST
Ronny Chevalier [Fri, 10 Apr 2015 14:53:17 +0000 (16:53 +0200)]
core: set_put never returns -EEXIST

When the value is already there it returns 0.

Also add a test to ensure this

7 years agobus-util: be more verbose if dbus job fails
Michal Sekletar [Fri, 10 Apr 2015 13:56:52 +0000 (15:56 +0200)]
bus-util: be more verbose if dbus job fails

Users might have hard time figuring out why exactly their systemctl request
failed. If dbus job fails try to figure out more details about failure by
examining Result property of the service.

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

7 years agoshared: fix memleak
Ronny Chevalier [Fri, 10 Apr 2015 13:44:02 +0000 (15:44 +0200)]
shared: fix memleak

path was used for 2 purposes but it was not freed before being reused.

7 years agodevice-nodes: minor simplifications
Lennart Poettering [Fri, 10 Apr 2015 12:43:37 +0000 (14:43 +0200)]
device-nodes: minor simplifications

7 years agoutil: unify how we parse mode_t strings
Lennart Poettering [Fri, 10 Apr 2015 12:43:06 +0000 (14:43 +0200)]
util: unify how we parse mode_t strings

7 years agoutil: remove normalize_env_assignment(), it's unused
Lennart Poettering [Fri, 10 Apr 2015 10:21:44 +0000 (12:21 +0200)]
util: remove normalize_env_assignment(), it's unused

7 years agoutil: mark unquote() static, so that new code doesn't use this anymore
Lennart Poettering [Fri, 10 Apr 2015 10:16:54 +0000 (12:16 +0200)]
util: mark unquote() static, so that new code doesn't use this anymore

7 years agoutil: fix unicode decoding in unquote_first_word()
Lennart Poettering [Fri, 10 Apr 2015 09:56:04 +0000 (11:56 +0200)]
util: fix unicode decoding in unquote_first_word()

7 years agoutil: when unescaping C escape sequences support C++11 \u and \U unicode literals
Lennart Poettering [Fri, 10 Apr 2015 09:27:47 +0000 (11:27 +0200)]
util: when unescaping C escape sequences support C++11 \u and \U unicode literals

We simply recode them in utf8.

7 years agohashmap: return NULL from destructor
David Herrmann [Fri, 10 Apr 2015 09:15:12 +0000 (11:15 +0200)]
hashmap: return NULL from destructor

We _always_ return NULL from destructors to allow direct assignments to
the variable holding the object. Especially on hashmaps, which treat NULL
as empty hashmap, this is pretty neat.

7 years agoutil: fix a typo in comment
Thomas Hindoe Paaboel Andersen [Thu, 9 Apr 2015 21:57:35 +0000 (23:57 +0200)]
util: fix a typo in comment

7 years agoutil: add shell_maybe_quote() call for preparing a string for shell cmdline inclusion
Lennart Poettering [Thu, 9 Apr 2015 16:32:21 +0000 (18:32 +0200)]
util: add shell_maybe_quote() call for preparing a string for shell cmdline inclusion

If necessary the passed string is enclosed in "", and all special
characters escapes.

This also ports over usage in bus-util.c and job.c to use this, instead
of a incorrect local implementation that forgets to properly escape.

7 years agologind: drop unused argument from method_do_shutdown_or_sleep()
Daniel Mack [Thu, 9 Apr 2015 14:44:51 +0000 (16:44 +0200)]
logind: drop unused argument from method_do_shutdown_or_sleep()

7 years agoutil: cunescape - fix memleak in error path
Ronny Chevalier [Thu, 9 Apr 2015 09:00:35 +0000 (11:00 +0200)]
util: cunescape - fix memleak in error path

7 years agoutil: merge change_attr_fd() and chattr_fd()
Lennart Poettering [Wed, 8 Apr 2015 18:47:35 +0000 (20:47 +0200)]
util: merge change_attr_fd() and chattr_fd()

7 years agomissing.h: Define IFA_F_NOPREFIXROUTE
Alexander Sverdlin [Wed, 8 Apr 2015 10:59:40 +0000 (12:59 +0200)]
missing.h: Define IFA_F_NOPREFIXROUTE

Fixes second systemd compilation problem against Linux 3.12 uapi
headers.

IFA_F_NOPREFIXROUTE is a usual #define appeared in Linux 3.14, so
AC_CHECK_DECLS is not necessary.

7 years agosd-rtnl: properly size attribute array if IFA_FLAGS was missing
Lennart Poettering [Wed, 8 Apr 2015 10:53:50 +0000 (12:53 +0200)]
sd-rtnl: properly size attribute array if IFA_FLAGS was missing

7 years agobus: simplify bus_message_read_strv_extend()
David Herrmann [Wed, 8 Apr 2015 09:20:10 +0000 (11:20 +0200)]
bus: simplify bus_message_read_strv_extend()

Avoid unbound for(;;) loop and use the established coding-style:
  while ((r = sd_bus_message_read*(...)) > 0) {
  }
  if (r < 0)
          return r;

This is much easier to read and used all over the code base.

7 years agoremove duplicated includes
Ronny Chevalier [Tue, 7 Apr 2015 23:15:32 +0000 (01:15 +0200)]
remove duplicated includes