chiark / gitweb /
elogind.git
6 years agofuzz: add initial fuzzing infrastructure
Jonathan Rudenberg [Sun, 14 Jan 2018 00:51:07 +0000 (19:51 -0500)]
fuzz: add initial fuzzing infrastructure

The fuzzers will be used by oss-fuzz to automatically and
continuously fuzz systemd.

This commit includes the build tooling necessary to build fuzz
targets, and a fuzzer for the DNS packet parser.

6 years agopath-util: don't insert duplicate "/" in path_make_absolute_cwd()
Lennart Poettering [Wed, 17 Jan 2018 10:17:55 +0000 (11:17 +0100)]
path-util: don't insert duplicate "/" in path_make_absolute_cwd()

When the working directory is "/" it's prettier not to insert a second
"/" in the path, even though it is technically correct.

6 years agotree-wide: port all code to use safe_getcwd()
Lennart Poettering [Wed, 17 Jan 2018 10:17:38 +0000 (11:17 +0100)]
tree-wide: port all code to use safe_getcwd()

6 years agopath-util: introduce new safe_getcwd() wrapper
Lennart Poettering [Wed, 17 Jan 2018 10:16:31 +0000 (11:16 +0100)]
path-util: introduce new safe_getcwd() wrapper

It's like get_current_dir_name() but protects us from
CVE-2018-1000001-style exploits:

https://www.halfdog.net/Security/2017/LibcRealpathBufferUnderflow/

6 years agopath-util: don't add extra "/" when prefix already is suffixed by slash
Lennart Poettering [Wed, 17 Jan 2018 10:15:00 +0000 (11:15 +0100)]
path-util: don't add extra "/" when prefix already is suffixed by slash

No need to insert duplicate "/" if we can avoid it. This is particularly
relevant if the prefix passed in is the root directory.

6 years agopath-util: do something useful if the prefix is "" in path_make_absolute()
Lennart Poettering [Wed, 17 Jan 2018 10:13:46 +0000 (11:13 +0100)]
path-util: do something useful if the prefix is "" in path_make_absolute()

Do not insert a "/" if the prefix we shall use is empty. It's a corner
case we should probably take care of.

6 years agofs-util: refuse taking a relative path to chase if "root" is specified and CHASE_PREF...
Lennart Poettering [Wed, 17 Jan 2018 11:00:40 +0000 (12:00 +0100)]
fs-util: refuse taking a relative path to chase if "root" is specified and CHASE_PREFIX_ROOT is set

If we take a relative path we first make it absolute, based on the
current working directory. But if CHASE_PREFIX_ROOT is passe we are
supposed to make the path absolute taking the specified root path into
account, but that makes no sense if we talk about the current working
directory as that is relative to the host's root in any case. Hence,
let's refuse this politely.

6 years agofs-util: extra chase_symlink() safety check on "path" parameter
Lennart Poettering [Wed, 17 Jan 2018 11:00:12 +0000 (12:00 +0100)]
fs-util: extra chase_symlink() safety check on "path" parameter

It's not clear what an empty "path" is even supposed to mean, hence
refuse.

6 years agofs-util: extra safety checks on chase_symlinks() root parameter
Lennart Poettering [Wed, 17 Jan 2018 10:56:52 +0000 (11:56 +0100)]
fs-util: extra safety checks on chase_symlinks() root parameter

Let's handle root="" and root="/" safely.

6 years agoparse-util: detect overflows in parse_percent_unbounded()
Lennart Poettering [Tue, 16 Jan 2018 10:50:12 +0000 (11:50 +0100)]
parse-util: detect overflows in parse_percent_unbounded()

We shouldn't accept percentages beyon INT32_MAX and consider them
valid.

6 years agoparse-util: coding style fix
Lennart Poettering [Tue, 16 Jan 2018 10:49:24 +0000 (11:49 +0100)]
parse-util: coding style fix

Let's not rely on C's downgrade-to-bool feature to check for NUL bytes

6 years agolocale-util: add freelocale() cleanup helper
Lennart Poettering [Tue, 16 Jan 2018 10:48:25 +0000 (11:48 +0100)]
locale-util: add freelocale() cleanup helper

6 years agovirt: add comment that we need to use sscanf()
Yu Watanabe [Tue, 16 Jan 2018 14:00:39 +0000 (23:00 +0900)]
virt: add comment that we need to use sscanf()

Follow-up for 13e0f9fe8334859ee86f4ff725374d1d83f5baf7.
See PR #7890 and comment in PR #7581.

6 years agoman: fix broken kernel document links (#7892)
John Lin [Tue, 16 Jan 2018 09:29:35 +0000 (17:29 +0800)]
man: fix broken kernel document links (#7892)

6 years agoFix parsing of features in detect_vm_xen_dom0 (#7890)
Olaf Hering [Tue, 16 Jan 2018 09:24:37 +0000 (10:24 +0100)]
Fix parsing of features in detect_vm_xen_dom0 (#7890)

Use sscanf instead of the built-in safe_atolu because the scanned string
lacks the leading "0x", it is generated with snprintf(b, "%08x", val).
As a result strtoull handles it as octal, and parsing fails.

The initial submission already used sscanf, then parsing was replaced by
safe_atolu without retesting the updated PR.

Fixes 575e6588d ("virt: use XENFEAT_dom0 to detect the hardware domain
(#6442, #6662) (#7581)")

6 years agoadd false option for tests (#7778)
Adam Duskett [Mon, 15 Jan 2018 11:25:46 +0000 (06:25 -0500)]
add false option for tests (#7778)

Currently there is no way to prevent tests from building using meson.
This introduces two problems:

1) It adds a extra 381 files to compile.
2) One of these tests explicitly requires libgcrypt to be built even if systemd
   is not using it.
3) It adds C++ to the requirements to build systemd.

When cross-compiling, this is uneccessary.

6 years agosd-dameon: also sent ucred when our UID differs from EUID
Lennart Poettering [Fri, 5 Jan 2018 12:24:58 +0000 (13:24 +0100)]
sd-dameon: also sent ucred when our UID differs from EUID

Let's be explicit, and always send the messages from our UID and never
our EUID. Previously this behaviour was conditionalized only on whether
the PID was specified, which made this non-obvious.

6 years agofs-util: add new chase_symlinks() flag CHASE_OPEN
Lennart Poettering [Thu, 4 Jan 2018 19:00:28 +0000 (20:00 +0100)]
fs-util: add new chase_symlinks() flag CHASE_OPEN

The new flag returns the O_PATH fd of the final component, which may be
converted into a proper fd by open()ing it again through the
/proc/self/fd/xyz path.

Together with O_SAFE this provides us with a somewhat safe way to open()
files in directories potentially owned by unprivileged code, where we
want to refuse operation if any symlink tricks are played pointing to
privileged files.

6 years agofs-util: add new CHASE_SAFE flag to chase_symlinks()
Lennart Poettering [Thu, 4 Jan 2018 18:44:27 +0000 (19:44 +0100)]
fs-util: add new CHASE_SAFE flag to chase_symlinks()

When the flag is specified we won't transition to a privilege-owned
file or directory from an unprivileged-owned one. This is useful when
privileged code wants to load data from a file unprivileged users have
write access to, and validates the ownership, but want's to make sure
that no symlink games are played to read a root-owned system file
belonging to a different context.

6 years agobash-completion: loginctl: add missing options and verbs
Yu Watanabe [Wed, 10 Jan 2018 08:10:36 +0000 (17:10 +0900)]
bash-completion: loginctl: add missing options and verbs

6 years agoupdate TODO
Lennart Poettering [Thu, 11 Jan 2018 14:10:29 +0000 (15:10 +0100)]
update TODO

6 years agolog: assign the realm to a variable first in log_full_errno_realm()
Lennart Poettering [Thu, 11 Jan 2018 12:15:19 +0000 (13:15 +0100)]
log: assign the realm to a variable first in log_full_errno_realm()

Let's avoid duplicate evaluation (which might have side-effects) and
assign the realm to an internal variable first, as we need it twice.

6 years agolog: rework log_syntax_invalid_utf8() a bit
Lennart Poettering [Thu, 11 Jan 2018 12:13:02 +0000 (13:13 +0100)]
log: rework log_syntax_invalid_utf8() a bit

The macro used utf8.h functions without including that. Let's clean this
up, by moving that code inside of log.c.

Let's also make the call return -EINVAL in all cases. This is in line
with log_oom() which also returns a well-defined error code even though
it doesn#t take one.

6 years agolog: minor modernizations to log_received_signal()
Lennart Poettering [Thu, 11 Jan 2018 12:09:30 +0000 (13:09 +0100)]
log: minor modernizations to log_received_signal()

6 years agolog: minimize includes in log.h
Lennart Poettering [Wed, 10 Jan 2018 23:39:12 +0000 (00:39 +0100)]
log: minimize includes in log.h

log.h really should only include the bare minimum of other headers, as
it is really pulled into pretty much everything else and already in
itself one of the most basic pieces of code we have.

Let's hence drop inclusion of:

1. sd-id128.h because it's entirely unneeded in current log.h
2. errno.h, dito.
3. sys/signalfd.h which we can replace by a simple struct forward
   declaration
4. process-util.h which was needed for getpid_cached() which we now hide
   in a funciton log_emergency_level() instead, which nicely abstracts
   the details away.
5. sys/socket.h which was needed for struct iovec, but a simple struct
   forward declaration suffices for that too.

Ultimately this actually makes our source tree larger (since users of
the functionality above must now include it themselves, log.h won't do
that for them), but I think it helps to untangle our web of includes a
tiny bit.

(Background: I'd like to isolate the generic bits of src/basic/ enough
so that we can do a git submodule import into casync for it)

6 years agosd-bus: drop bloom stuff, it's not needed anymore since kdbus is gone
Lennart Poettering [Wed, 10 Jan 2018 23:28:49 +0000 (00:28 +0100)]
sd-bus: drop bloom stuff, it's not needed anymore since kdbus is gone

6 years agoprocess-util: make our freeze() routine do something useful
Michal Sekletar [Fri, 12 Jan 2018 12:05:48 +0000 (13:05 +0100)]
process-util: make our freeze() routine do something useful

When we crash we freeze() our-self (or possibly we reboot the machine if
that is configured). However, calling pause() is very unhelpful thing to
do. We should at least continue to do what init systems being doing
since 70's and that is reaping zombies. Otherwise zombies start to
accumulate on the system which is a very bad thing. As that can prevent
admin from taking manual steps to reboot the machine in somewhat
graceful manner (e.g. manually stopping services, unmounting data
volumes  and calling reboot -f).

Fixes #7783

6 years agoComment the fact that some tools need to termintate their bus connect first
Franck Bui [Fri, 12 Jan 2018 15:20:36 +0000 (16:20 +0100)]
Comment the fact that some tools need to termintate their bus connect first

6 years agoRevert "tree-wide: use _cleanup_(sd_bus_flush_close_unrefp) at various appropriate...
Franck Bui [Fri, 12 Jan 2018 15:09:21 +0000 (16:09 +0100)]
Revert "tree-wide: use _cleanup_(sd_bus_flush_close_unrefp) at various appropriate places"

This reverts commit 0b3c84eb7da3a8c28ac248a68228f6a7edbb2e19.

The removal of _cleanup_() usages was done on purpose, see
cf647b69baee4c478d3909c327e3d917e1563f44.

Fixes: #3543
6 years agobus-socket: slight simplification in bus_get_peercred()
Zbigniew Jędrzejewski-Szmek [Thu, 4 Jan 2018 14:28:57 +0000 (15:28 +0100)]
bus-socket: slight simplification in bus_get_peercred()

6 years agoutil: minor tweaks to disable_core_dumps()
Lennart Poettering [Wed, 10 Jan 2018 17:37:54 +0000 (18:37 +0100)]
util: minor tweaks to disable_core_dumps()

First, let's rename it to disable_coredumps(), as in the rest of our
codebase we spell it "coredump" rather than "core_dump", so let's stick
to that.

However, also log about failures to turn off core dumpling on LOG_DEBUG,
because debug logging is always a good idea.

6 years agonss-systemd,user-util: add a way how synthesizing "nobody" can be turned off
Lennart Poettering [Wed, 10 Jan 2018 17:26:03 +0000 (18:26 +0100)]
nss-systemd,user-util: add a way how synthesizing "nobody" can be turned off

This is quite ugly, but provides us with an avenue for moving
distributions to define the "nobody" user properly without breaking legacy
systems that us the name for other stuff.

The idea is basically, that the distribution adopts the new definition
of "nobody" (and thus recompiles systemd with it) and then touches
/etc/systemd/dont-synthesize-nobody on legacy systems to turn off
possibly conflicting synthesizing of the nobody name by systemd.

6 years agoutil-lib: save/restore errno in cleanup calls
Lennart Poettering [Wed, 10 Jan 2018 16:21:15 +0000 (17:21 +0100)]
util-lib: save/restore errno in cleanup calls

We should be careful with errno in cleanup functions, and not alter it
under any circumstances. In the safe_close cleanup handlers we are
already safe in that regard, but let's add similar protections on other
cleanup handlers that invoke system calls.

Why bother? Cleanup handlers insert code at function return in
non-obvious ways. Hence, code that sets errno and returns should not be
confused by us overrding the errno from a cleanup handler.

This is a paranoia fix only, I am not aware where this actually mattered
in real-life situations.

6 years agococci: use strempty() at more places
Lennart Poettering [Wed, 10 Jan 2018 16:11:19 +0000 (17:11 +0100)]
cocci: use strempty() at more places

This shortens the code by a few lines.

6 years agomissing: add bpf() define for ARM definition
Hans-Christian Noren Egtvedt [Wed, 11 Oct 2017 08:48:39 +0000 (10:48 +0200)]
missing: add bpf() define for ARM definition

6 years agomissing: fix bpf() define for Tilera
Hans-Christian Noren Egtvedt [Tue, 17 Oct 2017 07:11:44 +0000 (09:11 +0200)]
missing: fix bpf() define for Tilera

__NR_bpf syscall uses the default generic value for Tilera, e.g. 280.

6 years agotree-wide: introduce disable_core_dumps helper and port existing users
Jan Klötzke [Wed, 10 Jan 2018 09:36:14 +0000 (10:36 +0100)]
tree-wide: introduce disable_core_dumps helper and port existing users

Changes the core_pattern to prevent any core dumps by the kernel. Does
nothing if we're in a container environment as this is system wide
setting.

6 years agoexec-util: cast to void when return value is ignored
Yu Watanabe [Wed, 10 Jan 2018 01:25:32 +0000 (10:25 +0900)]
exec-util: cast to void when return value is ignored

CID 1384262.

6 years agoprocess-util: initialize block_signals
Yu Watanabe [Wed, 10 Jan 2018 01:22:35 +0000 (10:22 +0900)]
process-util: initialize block_signals

CID 1384240.

6 years agonetworkd: add support for wireguard interface type
Jörg Thalheim [Mon, 18 Dec 2017 14:20:34 +0000 (15:20 +0100)]
networkd: add support for wireguard interface type

More information may be found at wireguard.com.

6 years agonetworkd: add support for wireguard interface type
Jörg Thalheim [Mon, 18 Dec 2017 14:20:34 +0000 (15:20 +0100)]
networkd: add support for wireguard interface type

More information may be found at wireguard.com.

6 years agosd-netlink: add generic netlink support
Jörg Thalheim [Mon, 18 Dec 2017 14:17:06 +0000 (15:17 +0100)]
sd-netlink: add generic netlink support

This also adds the ability to incorporate arrays into netlink messages
and to determine when a netlink message is too big, used by some generic
netlink protocols.

6 years agologind: fix user_object_find()
Lennart Poettering [Thu, 4 Jan 2018 10:36:35 +0000 (11:36 +0100)]
logind: fix user_object_find()

The logic was completely borked since
e4d2984bf8514ab576a66d5ac1f1cde746bb32a3, correct that.

CID #1384234

6 years agoupdate TODO
Lennart Poettering [Wed, 20 Dec 2017 18:48:23 +0000 (19:48 +0100)]
update TODO

6 years agoman: document all the new APIs we added
Lennart Poettering [Wed, 20 Dec 2017 15:31:58 +0000 (16:31 +0100)]
man: document all the new APIs we added

6 years agomeson: resurrect API documentation target
Lennart Poettering [Wed, 20 Dec 2017 11:51:14 +0000 (12:51 +0100)]
meson: resurrect API documentation target

We had this functionality back in Automake times, let's resurrect it.

6 years agosd-bus: remove 'hint_sync_call' parameter from various function calls
Lennart Poettering [Wed, 20 Dec 2017 18:48:39 +0000 (19:48 +0100)]
sd-bus: remove 'hint_sync_call' parameter from various function calls

This is unused since kdbus is gone, hence remove this too. This permits
us to get rid of sd_bus_send_internal() and just implement sd_bus_send()
directly.

6 years agosd-bus: add API to optionally set a sender field on all outgoing messages
Lennart Poettering [Wed, 20 Dec 2017 18:41:06 +0000 (19:41 +0100)]
sd-bus: add API to optionally set a sender field on all outgoing messages

This is useful on direct connections to generate messages with valid
sender fields.

This is particularly useful for services that are accessible both
through direct connections and the broker, as it allows clients to
install matches on the sender service name, and they work the same in
both cases.

6 years agoverbs: suppress debug log message if SYSTEMD_OFFLINE is not set
Lennart Poettering [Wed, 20 Dec 2017 18:38:15 +0000 (19:38 +0100)]
verbs: suppress debug log message if SYSTEMD_OFFLINE is not set

If SYSTEMD_OFFLINE is not set getenv_bool() for it will return -ENXIO,
which is nothing we should log about, not even at LOG_DEBUG level.

6 years agosd-bus: drop some unused fields from the sd_bus_message structure
Lennart Poettering [Wed, 20 Dec 2017 17:02:16 +0000 (18:02 +0100)]
sd-bus: drop some unused fields from the sd_bus_message structure

6 years agotree-wide: make the Subscribe() method calls asynchronous too
Lennart Poettering [Wed, 20 Dec 2017 15:40:47 +0000 (16:40 +0100)]
tree-wide: make the Subscribe() method calls asynchronous too

6 years agosd-bus: accept NULL callbacks in sd_bus_call_async()
Lennart Poettering [Wed, 20 Dec 2017 18:45:09 +0000 (19:45 +0100)]
sd-bus: accept NULL callbacks in sd_bus_call_async()

This way sd_bus_call_method_async() (which is just a wrapper around
sd_bus_call_async()) can be used to put method calls together that
expect no reply.

6 years agosd-bus: log about bus state changes
Lennart Poettering [Wed, 20 Dec 2017 11:50:43 +0000 (12:50 +0100)]
sd-bus: log about bus state changes

Let's unify all state changes in a new helper function, from which we
can then debug log all state changes

6 years agonetworkd,resolved: make use of watch_bind feature to connect to the bus
Lennart Poettering [Tue, 19 Dec 2017 14:54:30 +0000 (15:54 +0100)]
networkd,resolved: make use of watch_bind feature to connect to the bus

The changes both networkd and resolved to make use of the watch_bind
feature of sd-bus to connect to the system bus. This way, both daemons
can be started during early boot, and automatically and instantly
connect to the system bus as it becomes available.

This replaces prior code that used a time-based retry logic to connect
to the bus.

6 years agosd-bus: add new sd_bus_set_connected_signal() API
Lennart Poettering [Tue, 19 Dec 2017 14:50:05 +0000 (15:50 +0100)]
sd-bus: add new sd_bus_set_connected_signal() API

With this new API sd-bus can synthesize a local "Connected" signal when
the connection is fully established. It mirrors the local "Disconnected"
signal that is already generated when the connection is terminated. This
is useful to be notified when connection setup is done, in order to
start method calls then, in particular when using "slow" connection
methods (for example slow TCP, or most importantly the "watch_bind"
inotify logic).

Note that one could also use hook into the initial NameAcquired signal
received from the bus broker, but that scheme works only if we actually
connect to a bus. The benefit of "Connected" OTOH is that it works with
any kind of connection.

Ideally, we'd just generate this message unconditionally, but in order
not to break clients that do not expect this message it is opt-in.

6 years agosd-bus: add new sd_bus_is_ready() API
Lennart Poettering [Tue, 19 Dec 2017 14:47:09 +0000 (15:47 +0100)]
sd-bus: add new sd_bus_is_ready() API

This new call is much light sd_bus_is_open(), but returns true only if
the connection is fully set up, i.e. after we finished with the
authentication and Hello() phase. This API is useful for clients in
particular when using the "watch_bind" feature, as that way it can be
determined in advance whether it makes sense to sync on some operation.

6 years agosd-bus: modernize how we generate the match string in sd-bus-track
Lennart Poettering [Tue, 19 Dec 2017 14:45:30 +0000 (15:45 +0100)]
sd-bus: modernize how we generate the match string in sd-bus-track

strjoina() FTW!

6 years agosd-bus: drop references to legacy /var/run D-Bus socket
Lennart Poettering [Tue, 19 Dec 2017 14:41:58 +0000 (15:41 +0100)]
sd-bus: drop references to legacy /var/run D-Bus socket

Let's directly reference /run instead, so that we can work without /var
being around, or with /var/run being incorrectly set up.

Note that we keep the old socket path in place when referencing the
system bus of containers, as they might be foreign operating systems,
that still don't have adopted /run, and where it makes sense to use the
standardized name instead. On local systems, we insist on /run being set
up properly however, hence this limitation does not apply.

Also, get rid of the UNIX_SYSTEM_BUS_ADDRESS and
UNIX_USER_BUS_ADDRESS_FMT defines. They had a purpose when we still did
kdbus, as we then had to support two different backends. But since
that's gone, we don't need this indirection anymore, hence settle on a
one define only.

6 years agotree-wide: install matches asynchronously
Lennart Poettering [Tue, 19 Dec 2017 11:29:04 +0000 (12:29 +0100)]
tree-wide: install matches asynchronously

Let's remove a number of synchronization points from our service
startups: let's drop synchronous match installation, and let's opt for
asynchronous instead.

Also, let's use sd_bus_match_signal() instead of sd_bus_add_match()
where we can.

6 years agotree-wide: make name requesting asynchronous in all our services
Lennart Poettering [Mon, 18 Dec 2017 21:10:11 +0000 (22:10 +0100)]
tree-wide: make name requesting asynchronous in all our services

This optimizes service startup a bit, and makes it less prone to
deadlocks.

6 years agosd-bus: when disconnecting a slot, also reset its memory
Lennart Poettering [Mon, 18 Dec 2017 20:58:14 +0000 (21:58 +0100)]
sd-bus: when disconnecting a slot, also reset its memory

Yes, we aren#t accessing this anymore after, but it's still nicer if
this is actually guaranteed.

6 years agosd-bus: add new API sd_bus_match_signal() + sd_bus_match_signal_asnyc()
Lennart Poettering [Mon, 18 Dec 2017 20:52:50 +0000 (21:52 +0100)]
sd-bus: add new API sd_bus_match_signal() + sd_bus_match_signal_asnyc()

These are convenience helpers that hide the match string logic (which we
probably should never have exposed), and instead just takes regular C
arguments.

6 years agosd-bus: add asynchronous version of sd_bus_match()
Lennart Poettering [Mon, 18 Dec 2017 20:37:03 +0000 (21:37 +0100)]
sd-bus: add asynchronous version of sd_bus_match()

We usually enqueue a number of these calls on each service
initialization. Let's do this asynchronously, and thus remove
synchronization points. This improves both performance behaviour and
reduces the chances to deadlock.

6 years agosd-bus: when removing a server-side match, do so in "fire and forget" fashion
Lennart Poettering [Mon, 18 Dec 2017 19:50:26 +0000 (20:50 +0100)]
sd-bus: when removing a server-side match, do so in "fire and forget" fashion

We currently wait for the RemoveMatch() reply, but then ignore what it
actually says. Let's optimize this a bit, and not even ask for an answer
back: just enqueue the RemoveMatch() operation, and do not request not
wait for any answer.

6 years agosd-bus: remove bus_remove_match_by_string() helper which is unused
Lennart Poettering [Mon, 18 Dec 2017 19:45:35 +0000 (20:45 +0100)]
sd-bus: remove bus_remove_match_by_string() helper which is unused

6 years agosd-bus: drop unused parameters from bus_add_match_internal()
Lennart Poettering [Mon, 18 Dec 2017 19:34:21 +0000 (20:34 +0100)]
sd-bus: drop unused parameters from bus_add_match_internal()

We don't need the match components anymore, since kdbus is gone, hence
drop it.

6 years agosd-bus: add APIs to request/release names asynchronously
Lennart Poettering [Mon, 18 Dec 2017 19:10:13 +0000 (20:10 +0100)]
sd-bus: add APIs to request/release names asynchronously

They do the same thing as their synchronous counterparts, but only
enqueue the operation, thus removing synchronization points during
service initialization.

If the callback function is passed as NULL we'll fallback to generic
implementations of the reply handlers, that terminate the connection if
the requested name cannot be acquired, under the assumption that not
being able to acquire the name is a technical problem.

6 years agobus-control: remove kdbus indirection cruft
Lennart Poettering [Mon, 18 Dec 2017 13:48:16 +0000 (14:48 +0100)]
bus-control: remove kdbus indirection cruft

When kdbus was still around we always had two implementations of the
various control calls: one for dbus1 and one for kdbus. Let'sget rid of
this, simplify things, and just merge the wrappers that used to
multiplex this with the implementations.

No change in behaviour, just some merging of functions

6 years agosd-bus: get rid of kdbus flags cruft
Lennart Poettering [Mon, 18 Dec 2017 13:21:34 +0000 (14:21 +0100)]
sd-bus: get rid of kdbus flags cruft

We only need three bits from the old kdbus flags cruft, hence let's make
them proper booleans.

6 years agosd-bus: start reply callback timeouts only when the connection is established
Lennart Poettering [Mon, 18 Dec 2017 12:53:12 +0000 (13:53 +0100)]
sd-bus: start reply callback timeouts only when the connection is established

Currently, reply callback timeouts are started the instant the method
calls are enqueued, which can be very early on. For example, the Hello()
method call is enqueued right when sd_bus_start() is called, i.e. before
the socket connection and everything is established.

With this change we instead start the method timeout the moment we
actually leave the authentication phase of the connection. This way, the
timeout the kernel applies on socket connecting, and we apply on the
authentication phase no longer runs in parallel to the Hello() method
call, but all three run serially one after the other, which is
definitely a cleaner approach.

Moreover, this makes the "watch bind" feature a lot more useful, as it
allows enqueuing method calls while we are still waiting for inotify
events, without them timeouting until the connection is actually
established, i.e. when the method call actually has a chance of being
actually run.

This is a change of behaviour of course, but I think the new behaviour
is much better than the old one, since we don't race timeouts against
each other anymore...

6 years agosd-bus: optionally, use inotify to wait for bus sockets to appear
Lennart Poettering [Fri, 15 Dec 2017 21:24:52 +0000 (22:24 +0100)]
sd-bus: optionally, use inotify to wait for bus sockets to appear

This adds a "watch-bind" feature to sd-bus connections. If set and the
AF_UNIX socket we are connecting to doesn't exist yet, we'll establish
an inotify watch instead, and wait for the socket to appear. In other
words, a missing AF_UNIX just makes connecting slower.

This is useful for daemons such as networkd or resolved that shall be
able to run during early-boot, before dbus-daemon is up, and want to
connect to dbus-daemon as soon as it becomes ready.

6 years agosocket-util: explicitly ensure there's one trailing NUL byte on AF_UNIX socket addresses
Lennart Poettering [Wed, 27 Dec 2017 16:18:02 +0000 (17:18 +0100)]
socket-util: explicitly ensure there's one trailing NUL byte on AF_UNIX socket addresses

AF_UNIX socket addresses aren't necessarily NUL terminated, however
they are usually used as strings which are assumed to be NUL terminated.
Let's hence add an extra byte to the end of the sockaddr_un structure,
that contains this NUL byte, simply for safety reasons.

Note that actually this patch changes exactly nothing IRL, as the other
sockaddr structures already are large enough to accomodate for an extra
NUL byte. The size of the union hence doesn't change at all by doing
this. The entire value of this patch is hence in the philosophical
feeling of safety, and by making something explicit that before was
implicit.

6 years agosocket-util: use parse_ip_port() for parsing IP ports
Lennart Poettering [Wed, 27 Dec 2017 16:02:36 +0000 (17:02 +0100)]
socket-util: use parse_ip_port() for parsing IP ports

Let's unify some code here, and also use parse_ip_port() for all our IP
port parsing needs in socket_address_parse().

6 years agofs-util: rework touch_file() so that it can touch socket file nodes
Lennart Poettering [Wed, 27 Dec 2017 15:20:28 +0000 (16:20 +0100)]
fs-util: rework touch_file() so that it can touch socket file nodes

Let's rework touch_file() so that it works correctly on sockets, fifos,
and device nodes: let's open an O_PATH file descriptor first and operate
based on that, if we can. This is usually the better option as it this
means we can open AF_UNIX nodes in the file system, and update their
timestamps and ownership correctly. It also means we can correctly touch
symlinks and block/character devices without triggering their drivers.

Moreover, by operating on an O_PATH fd we can make sure that we
operate on the same inode the whole time, and it can't be swapped out in
the middle.

While we are at it, rework the call so that we try to adjust as much as
we can before returning on error. This is a good idea as we call the
function quite often without checking its result, and hence it's best to
leave the files around in the most "correct" fashion possible.

6 years agosd-bus: when attached to an sd-event loop, disconnect on processing errors
Lennart Poettering [Fri, 15 Dec 2017 21:24:16 +0000 (22:24 +0100)]
sd-bus: when attached to an sd-event loop, disconnect on processing errors

If we can't process the bus for some reason we shouldn't just disable
the event source, but log something and give up on the connection. Hence
do that, and disconnect.

6 years agosd-bus: propagate handling errors for Hello method reply directly
Lennart Poettering [Tue, 12 Dec 2017 22:26:36 +0000 (23:26 +0100)]
sd-bus: propagate handling errors for Hello method reply directly

Currently, when sd-bus is used to issue a method call, and we get a
reply and the specified reply handler fails, we log this locally at
debug priority and proceed. The idea is that a bad server-side reply
should not be fatal for the program, except when the developer
explicitly terminates the event loop.

The reply to the initial Hello() method call we issue when joining a bus
should not be handled like that however. Instead, propagate the error
immediately, as anything that is wrong with the Hello() reply should be
considered a fatal connection problem.

6 years agosd-bus: minor coding style fix
Lennart Poettering [Tue, 12 Dec 2017 22:26:08 +0000 (23:26 +0100)]
sd-bus: minor coding style fix

6 years agosd-bus: cast some syscall invocations explicitly to (void)
Lennart Poettering [Tue, 12 Dec 2017 22:24:44 +0000 (23:24 +0100)]
sd-bus: cast some syscall invocations explicitly to (void)

Let's clarify that we knowingly ignore the return values.

6 years agosd-bus: when debug logging about messages, show the same bits of it everywhere
Lennart Poettering [Tue, 12 Dec 2017 22:23:25 +0000 (23:23 +0100)]
sd-bus: when debug logging about messages, show the same bits of it everywhere

Also, include the message signature everywhere.

6 years agoio-util: make flush_fd() return how many bytes where flushed
Lennart Poettering [Tue, 12 Dec 2017 22:21:09 +0000 (23:21 +0100)]
io-util: make flush_fd() return how many bytes where flushed

This is useful so that callers know whether anything at all and how much
was flushed.

This patches through users of this functions to ensure that the return
values > 0 which may be returned now are not propagated in public APIs.

Also, users that ignore the return value are changed to do so explicitly
now.

6 years agoupdate TODO
Lennart Poettering [Sat, 30 Dec 2017 14:21:12 +0000 (15:21 +0100)]
update TODO

6 years agofileio: minor tweak to executable_is_script()
Lennart Poettering [Sat, 30 Dec 2017 14:44:29 +0000 (15:44 +0100)]
fileio: minor tweak to executable_is_script()

If read_line() returns ENOBFUS this means the line was overly long. When
we use this for checking whether an executable is a script, then this
shouldn't be propagated as-is, but simply as "this is not a script".

6 years agofileio: tweak write_string_stream_ts() to write out trailing \n in one go even if...
Lennart Poettering [Sat, 30 Dec 2017 14:42:03 +0000 (15:42 +0100)]
fileio: tweak write_string_stream_ts() to write out trailing \n in one go even if buffering is off

This tweaks write_string_stream_ts() in one minor way: when stdio
buffering has been turned off, let's append the newline we shall append
to the buffer we write ourselves so that the kernel only gets one
syscall for the result. When buffering is enabled stdio will take care
of that anyway.

Follow-up for #7750.

6 years agosd-bus: port one use of SO_PEERCRED by getpeercred()
Lennart Poettering [Sat, 30 Dec 2017 14:20:38 +0000 (15:20 +0100)]
sd-bus: port one use of SO_PEERCRED by getpeercred()

6 years agosd-bus: let's use mfree() where we can
Lennart Poettering [Sat, 30 Dec 2017 14:19:53 +0000 (15:19 +0100)]
sd-bus: let's use mfree() where we can

6 years agosd-bus: use SO_PEERGROUPS when available to identify groups of peer
Lennart Poettering [Sat, 30 Dec 2017 14:19:15 +0000 (15:19 +0100)]
sd-bus: use SO_PEERGROUPS when available to identify groups of peer

6 years agosocket-util: slight rework of getpeersec()
Lennart Poettering [Sat, 30 Dec 2017 14:15:44 +0000 (15:15 +0100)]
socket-util: slight rework of getpeersec()

Let's call getsockopt() in a loop, so that we can deal correctly with
the label changing while we are trying to read it.

(also, while we are at it, let's make sure that there's always one
trailing NUL byte at the end of the buffer, after all SO_PEERSEC has
zero documentation, and multiple implementing backends, hence let's
better be safe than sorry)

6 years agotree-wide: use {pid,uid,gid}_is_valid() where appropriate
Lennart Poettering [Sat, 30 Dec 2017 14:15:03 +0000 (15:15 +0100)]
tree-wide: use {pid,uid,gid}_is_valid() where appropriate

Also, drop UID/GID validity checks from getpeercred() as the kernel will
never pass us invalid UID/GID on userns, but the overflow UID/GID
instead. Add a comment about this.

6 years agouser-util: minor updates of in_gid()
Lennart Poettering [Sat, 30 Dec 2017 13:05:41 +0000 (14:05 +0100)]
user-util: minor updates of in_gid()

Let's use newa() and use the right type for storing sysconf() return
values.

6 years agosocket-util: add new getpeergroups() call
Lennart Poettering [Sat, 30 Dec 2017 13:02:36 +0000 (14:02 +0100)]
socket-util: add new getpeergroups() call

It's a wrapper around the new SO_PEERGROUPS sockopt, similar in style as
getpeersec() and getpeercred().

6 years agoprocess-util: add new FORK_NEW_MOUNTNS flag to safe_fork()
Lennart Poettering [Fri, 29 Dec 2017 17:52:20 +0000 (18:52 +0100)]
process-util: add new FORK_NEW_MOUNTNS flag to safe_fork()

That way we can move one more code location to use safe_fork()

6 years agopager: let's move static variables up, to the rest of them
Lennart Poettering [Fri, 29 Dec 2017 17:14:37 +0000 (18:14 +0100)]
pager: let's move static variables up, to the rest of them

let's keep static variables together, and before the function
definitions.

6 years agopager,agent: insist that we are called from the main thread
Lennart Poettering [Fri, 29 Dec 2017 17:13:38 +0000 (18:13 +0100)]
pager,agent: insist that we are called from the main thread

We maintain static process-wide variables in these subsystems without
locking, hence let's refuse operation unless we are called from the main
thread (which we do anyway) just as a safety precaution.

6 years agotree-wide: make use of wait_for_terminate_and_check() at various places
Lennart Poettering [Fri, 29 Dec 2017 17:07:00 +0000 (18:07 +0100)]
tree-wide: make use of wait_for_terminate_and_check() at various places

Using wait_for_terminate_and_check() instead of wait_for_terminate()
let's us simplify, shorten and unify the return value checking and
logging of waitid().  Hence, let's use it all over the place.

6 years agoprocess-spec: add another flag FORK_WAIT to safe_fork()
Lennart Poettering [Fri, 29 Dec 2017 17:01:37 +0000 (18:01 +0100)]
process-spec: add another flag FORK_WAIT to safe_fork()

This new flag will cause safe_fork() to wait for the forked off child
before returning. This allows us to unify a number of cases where we
immediately wait on the forked off child, witout running any code in the
parent after the fork, and without direct interest in the precise exit
status of the process, except recgonizing EXIT_SUCCESS vs everything
else.

6 years agoexec-util: drop redundant log message in do_spawn()
Lennart Poettering [Fri, 29 Dec 2017 16:11:49 +0000 (17:11 +0100)]
exec-util: drop redundant log message in do_spawn()

safe_fork() logs that anyway, hence no need to do this twice.

6 years agoprocess-util: rework wait_for_terminate_and_warn() to take a flags parameter
Lennart Poettering [Wed, 27 Dec 2017 23:51:19 +0000 (00:51 +0100)]
process-util: rework wait_for_terminate_and_warn() to take a flags parameter

This renames wait_for_terminate_and_warn() to
wait_for_terminate_and_check(), and adds a flags parameter, that
controls how much to log: there's one flag that means we log about
abnormal stuff, and another one that controls whether we log about
non-zero exit codes. Finally, there's a shortcut flag value for logging
in both cases, as that's what we usually use.

All callers are accordingly updated. At three occasions duplicate logging
is removed, i.e. where the old function was called but logged in the
caller, too.

6 years agoprocess-util: add another fork_safe() flag for enabling LOG_ERR/LOG_WARN logging
Lennart Poettering [Wed, 27 Dec 2017 20:49:19 +0000 (21:49 +0100)]
process-util: add another fork_safe() flag for enabling LOG_ERR/LOG_WARN logging

6 years agoraw-clone: beef up raw_clone() wrapper a bit
Lennart Poettering [Fri, 29 Dec 2017 15:45:04 +0000 (16:45 +0100)]
raw-clone: beef up raw_clone() wrapper a bit

First of all, let's return pid_t, which appears to be the correct type
given that we return PIDs, and it#s what fork() uses too.

Most importantly though, flush out our PID cache, so that the call
becomes compatible with our getpid_cached() logic.

6 years agocoverity: don't use (void)0 under coverity
Zbigniew Jędrzejewski-Szmek [Thu, 4 Jan 2018 08:45:23 +0000 (09:45 +0100)]
coverity: don't use (void)0 under coverity

I'm not sure why this is needed, but apparrently coverity doesn't like
(void)0. With this change, coverity can (almost) build systemd:

CFLAGS='-D_Float128="long double"' meson cov-build -Dman=false && \
  CCACHE_DISABLE=1 COVERITY_UNSUPPORTED=1 cov-build --dir cov-int ninja -C cov-build

Patch originially by Marek Cermak <macermak@redhat.com>.