chiark / gitweb /
elogind.git
6 years agosd-bus: avoid potential memory leaks
Yu Watanabe [Fri, 9 Feb 2018 07:21:29 +0000 (16:21 +0900)]
sd-bus: avoid potential memory leaks

(cherry picked from commit b4ca3f45dc5742ad76e8feebd363c490f92b804f)

6 years agoprocess-util: use raw_getpid() in getpid_cache() internally (#8115)
Lennart Poettering [Wed, 7 Feb 2018 02:10:09 +0000 (03:10 +0100)]
process-util: use raw_getpid() in getpid_cache() internally (#8115)

We have the raw_getpid() definition in place anyway, and it's certainly
beneficial to expose the same semantics on pre glibc 2.24 and after it
too, hence always bypass glibc for this, and always cache things on our
side.

Fixes: #8113
(cherry picked from commit 996def17f99bb3f41f82032860dfcb98ff19c3ae)

6 years agotest: add a simple smoke test for string_hashsum()
Zbigniew Jędrzejewski-Szmek [Mon, 5 Feb 2018 08:48:38 +0000 (09:48 +0100)]
test: add a simple smoke test for string_hashsum()

This is enough to show memory leakages pointed out by Stef Bon <stefbon@gmail.com>.

(cherry picked from commit bd181f27d4d0c16c500c9f49394213d1fbad1f09)

6 years agokernel 3.10 compat: RTAX_QUICKACK not added until 3.11.0 (#8094)
MilhouseVH [Mon, 5 Feb 2018 05:26:57 +0000 (05:26 +0000)]
kernel 3.10 compat: RTAX_QUICKACK not added until 3.11.0 (#8094)

(cherry picked from commit ec79af69a1d159a43deb68c9ec1c31fe89743b6f)

6 years agosocket-util: fix getpeergroups() assert(fd) (#8080)
Vito Caputo [Sat, 3 Feb 2018 11:09:08 +0000 (03:09 -0800)]
socket-util: fix getpeergroups() assert(fd) (#8080)

Don't assert on zero-value fds.

Fixes #8075.

(cherry picked from commit 75f40779607ea79f20441c7fb46744d04ee2c7ae)

6 years agomeson.build: make docdir configurable (#8068)
tblume [Thu, 1 Feb 2018 21:46:15 +0000 (22:46 +0100)]
meson.build: make docdir configurable (#8068)

SUSE is using a different docdir, so the path should be configurable

(cherry picked from commit 75aaade16b00ff519fbaedb4cc773b654c11a34a)

6 years agoSave last mutual commit for migration to v237 tag.
Sven Eden [Wed, 30 May 2018 05:51:02 +0000 (07:51 +0200)]
Save last mutual commit for migration to v237 tag.

6 years agoNEWS: add missing equal sign
Zbigniew Jędrzejewski-Szmek [Sun, 28 Jan 2018 15:54:18 +0000 (16:54 +0100)]
NEWS: add missing equal sign

Important!

6 years agoNEWS: reword one sentence
Zbigniew Jędrzejewski-Szmek [Sun, 28 Jan 2018 15:52:47 +0000 (16:52 +0100)]
NEWS: reword one sentence

6 years agoNEWS: let's get this thing done
Lennart Poettering [Sun, 28 Jan 2018 15:36:03 +0000 (16:36 +0100)]
NEWS: let's get this thing done

6 years agoNEWS: mention --grep (#8029)
Zbigniew Jędrzejewski-Szmek [Sun, 28 Jan 2018 14:52:06 +0000 (15:52 +0100)]
NEWS: mention --grep (#8029)

6 years agojournalctl: add highlighting for matched substring
Zbigniew Jędrzejewski-Szmek [Sat, 27 Jan 2018 12:00:09 +0000 (13:00 +0100)]
journalctl: add highlighting for matched substring

Red is used for highligting, the same as grep does. Except when the line is
highlighted red already, because it has high priority, in which case plain ansi
highlight is used for the matched substring.

Coloring is implemented for short and cat outputs, and not for other types.
I guess we could also add it for verbose output in the future.

6 years agojournalctl: make matching optionally case sensitive
Zbigniew Jędrzejewski-Szmek [Fri, 12 Jan 2018 13:31:49 +0000 (14:31 +0100)]
journalctl: make matching optionally case sensitive

Case sensitive or case insensitive matching can be requested using
--case-sensitive[=yes|no].

Unless specified, matching is case sensitive if the pattern contains any
uppercase letters, and case insensitive otherwise. This matches what
forward-search does in emacs, and recently also --ignore-case in less.  This
works surprisingly well, because usually when one is wants to do case-sensitive
matching, the pattern is usually camel-cased. In the less frequent case when
case-sensitive matching is required with an all-lowercase pattern,
--case-sensitive can be used to override the automatic logic.

6 years agojournalctl: regexp matching
Zbigniew Jędrzejewski-Szmek [Fri, 12 Jan 2018 06:55:45 +0000 (07:55 +0100)]
journalctl: regexp matching

6 years agomeson: detect pcre2 dep
Zbigniew Jędrzejewski-Szmek [Fri, 12 Jan 2018 04:47:17 +0000 (05:47 +0100)]
meson: detect pcre2 dep

6 years agoNEWS: update NEWS again, we didn't release yesterday (#8027)
Lennart Poettering [Sun, 28 Jan 2018 12:28:58 +0000 (13:28 +0100)]
NEWS: update NEWS again, we didn't release yesterday (#8027)

Fix tons of whitespace issues, also add a sysusers.d/ change and update
to contributors list again

6 years agorationalize interface for opening/closing logging
Alan Jenkins [Fri, 26 Jan 2018 13:42:53 +0000 (13:42 +0000)]
rationalize interface for opening/closing logging

log_open_console() did not switch from stderr to /dev/console, when
"always_reopen_console" was set.  It was necessary to call
log_close_console() first.

By contrast, log_open() did switch between e.g. journald and kmsg according
to the value of "prohibit_ipc".

Let's fix log_open() to respect the values of all the log options, and we
can make log_close_*() private.

Also log_close_console() is changed.  There was some precaution, avoiding
closing the console fd if we are not PID 1.  I think commit 48a601fe made
a little mistake in leaving this in, and it only served to confuse
readers :).

Also I changed systemd-shutdown. Now we have log_set_prohibit_ipc(), let's
use it to clarify that systemd-shutdown is not expected to try and log via
journald (which it is about to kill).  We avoided ever asking it to, but
it's more convenient for the reader if they don't have to think about that.
In that sense, it's similar to using assert() to validate a function's
arguments.

6 years agoNEWS: typo fix
Thomas Hindoe Paaboel Andersen [Sat, 27 Jan 2018 23:05:27 +0000 (00:05 +0100)]
NEWS: typo fix

6 years agoUpdate NEWS to reflect changes made in #8020 (#8024)
bleep_blop [Sat, 27 Jan 2018 16:33:52 +0000 (22:03 +0530)]
Update NEWS to reflect changes made in #8020 (#8024)

6 years agoString Formatting Update (#7819)
Batuhan Osman Taşkaya [Sat, 27 Jan 2018 13:03:08 +0000 (16:03 +0300)]
String Formatting Update (#7819)

Changes: % changed as .format()

6 years agoNEWS: get ready for release today (#8019)
Lennart Poettering [Sat, 27 Jan 2018 12:52:09 +0000 (13:52 +0100)]
NEWS: get ready for release today (#8019)

6 years agologin/meson.build: require ACL for uaccess rules
Andrew Jeddeloh [Thu, 25 Jan 2018 21:17:17 +0000 (13:17 -0800)]
login/meson.build: require ACL for uaccess rules

Don't install udev rules that requires the uaccess builtin if systemd is
being built without the uaccess builtin.

6 years agomeson: use env object instead of string in tags targets
Zbigniew Jędrzejewski-Szmek [Fri, 26 Jan 2018 15:15:17 +0000 (16:15 +0100)]
meson: use env object instead of string in tags targets

I used 'tags' before because this way we avoided a unnecessary
line about 'env' detection. But we cannot use 'env' in test(), so
previous commit added 'env' detection. We might just as well use
it in custom_target().

6 years agoHook up oss-fuzz test cases as tests
Zbigniew Jędrzejewski-Szmek [Fri, 19 Jan 2018 06:54:30 +0000 (17:54 +1100)]
Hook up oss-fuzz test cases as tests

This is a bit painful because a separate build of systemd is necessary. The
tests are guarded by tests!=false and slow-tests==true. Running them is not
slow, but compilation certainly is. If this proves unwieldy, we can add a
separate option controlling those builds later.

The build for each sanitizer has its own directory, and we build all fuzzer
tests there, and then pull them out one-by-one by linking into the target
position as necessary. It would be nicer to just build the desired fuzzer, but
we need to build the whole nested build as one unit.

[I also tried making systemd and nested meson subproject. This would work
nicely, but meson does not allow that because the nested target names are the
same as the outer project names. If that is ever fixed, that would be the way
to go.]

v2:
- make sure things still work if memory sanitizer is not available
v3:
- switch to syntax which works with meson 0.42.1 found in Ubuntu

6 years agologin/meson.build: require ACL for uaccess rules
Andrew Jeddeloh [Thu, 25 Jan 2018 21:17:17 +0000 (13:17 -0800)]
login/meson.build: require ACL for uaccess rules

Don't install udev rules that requires the uaccess builtin if systemd is
being built without the uaccess builtin.

6 years agoNEWS: add self to news file for this late commit
Jason A. Donenfeld [Thu, 25 Jan 2018 20:16:38 +0000 (21:16 +0100)]
NEWS: add self to news file for this late commit

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
6 years agoNews: some fixes and improvements (#8010)
Clinton Roy [Fri, 26 Jan 2018 10:44:11 +0000 (21:44 +1100)]
News: some fixes and improvements (#8010)

* missing whitespace.

* NEWS: some small fixes and improvements.

6 years agofirstboot: Include <crypt.h> for declaration of crypt() if needed (#7944)
Björn Esser [Thu, 25 Jan 2018 14:30:15 +0000 (15:30 +0100)]
firstboot: Include <crypt.h> for declaration of crypt() if needed (#7944)

Not every target system may provide a crypt() function in its stdlibc
and may use an external or replacement library, like libxcrypt, for
providing such functions.

See https://fedoraproject.org/wiki/Changes/Replace_glibc_libcrypt_with_libxcrypt.

6 years agomeson: bump so revision and systemd version in preparation for v237
Lennart Poettering [Thu, 25 Jan 2018 13:18:14 +0000 (14:18 +0100)]
meson: bump so revision and systemd version in preparation for v237

6 years agoupdate TODO
Lennart Poettering [Thu, 25 Jan 2018 13:14:35 +0000 (14:14 +0100)]
update TODO

6 years agoNEWS: start putting together an entry for v237
Lennart Poettering [Thu, 25 Jan 2018 12:18:28 +0000 (13:18 +0100)]
NEWS: start putting together an entry for v237

6 years agofirstboot: Include <crypt.h> for declaration of crypt() if needed (#7944)
Björn Esser [Thu, 25 Jan 2018 14:30:15 +0000 (15:30 +0100)]
firstboot: Include <crypt.h> for declaration of crypt() if needed (#7944)

Not every target system may provide a crypt() function in its stdlibc
and may use an external or replacement library, like libxcrypt, for
providing such functions.

See https://fedoraproject.org/wiki/Changes/Replace_glibc_libcrypt_with_libxcrypt.

6 years agobus-util: fix format of NextElapseUSecRealtime= and LastTriggerUSec=
Yu Watanabe [Thu, 25 Jan 2018 08:45:53 +0000 (17:45 +0900)]
bus-util: fix format of NextElapseUSecRealtime= and LastTriggerUSec=

Before this, `systemctl show` for calendar type timer unit outputs
something like below.
```
NextElapseUSecRealtime=48y 3w 3d 15h
NextElapseUSecMonotonic=0
LastTriggerUSec=48y 3w 3d 3h 41min 44.093095s
LastTriggerUSecMonotonic=0
```
As both NextElapseUSecRealtime= and LastTriggerUSec= are not timespan
but timestamp, this makes format these values by `format_timestamp()`.

6 years agococcinelle: O_NDELAY → O_NONBLOCK
Lennart Poettering [Wed, 24 Jan 2018 10:09:29 +0000 (11:09 +0100)]
coccinelle: O_NDELAY → O_NONBLOCK

Apparently O_NONBLOCK is the modern name used in most documentation and
for most cases in our sources. Let's hence replace the old alias
O_NDELAY and stick to O_NONBLOCK everywhere.

6 years agotmpfiles: make "f" lines behaviour match what the documentation says
Lennart Poettering [Wed, 24 Jan 2018 09:54:10 +0000 (10:54 +0100)]
tmpfiles: make "f" lines behaviour match what the documentation says

CHANGE OF BEHAVIOUR — with this commit "f" line's behaviour is altered
to match what the documentation says: if an "argument" string is
specified it is written to the file only when the file didn't exist
before. Previously, it would be appended to the file each time
systemd-tmpfiles was invoked — which is not a particularly useful
behaviour as the tool is not idempotent then and the indicated files
grow without bounds each time the tool is invoked.

I did some spelunking whether this change in behaviour would break
things, but afaics nothing relies on the previous O_APPEND behaviour of
this line type, hence I think it's relatively safe to make "f" lines
work the way the docs say, rather than adding a new modifier for it or
so.

Triggered by:

https://lists.freedesktop.org/archives/systemd-devel/2018-January/040171.html

6 years agoupdate TODO
Lennart Poettering [Wed, 17 Jan 2018 19:10:22 +0000 (20:10 +0100)]
update TODO

6 years agocore: propagate TasksMax= on the root slice to sysctls
Lennart Poettering [Wed, 17 Jan 2018 17:50:27 +0000 (18:50 +0100)]
core: propagate TasksMax= on the root slice to sysctls

The cgroup "pids" controller is not supported on the root cgroup.
However we expose TasksMax= on it, but currently don't actually apply it
to anything. Let's correct this: if set, let's propagate things to the
right sysctls.

This way we can expose TasksMax= on all units in a somewhat sensible
way.

6 years agocgroup: when querying the number of tasks in the root slice use the pid_max sysctl
Lennart Poettering [Wed, 17 Jan 2018 14:39:39 +0000 (15:39 +0100)]
cgroup: when querying the number of tasks in the root slice use the pid_max sysctl

The root cgroup doesn't expose and properties in the "pids" cgroup
controller, hence we need to get the data from somewhere else.

6 years agocgroup: add proper API to determine whether our unit manags to root cgroup
Lennart Poettering [Wed, 17 Jan 2018 17:41:42 +0000 (18:41 +0100)]
cgroup: add proper API to determine whether our unit manags to root cgroup

6 years agoutil: rework system_tasks_max() to make use of procfs_tasks_max()
Lennart Poettering [Wed, 17 Jan 2018 14:35:01 +0000 (15:35 +0100)]
util: rework system_tasks_max() to make use of procfs_tasks_max()

Let's use our new code.

6 years agoutil-lib: add new procfs-util.[ch] API for dealing with tasks limits
Lennart Poettering [Wed, 17 Jan 2018 17:40:10 +0000 (18:40 +0100)]
util-lib: add new procfs-util.[ch] API for dealing with tasks limits

As it turns out the limit on concurrent tasks on Linux nasty to
determine, hence let's appropriate helpers for this.

6 years agocgroup: use CGROUP_LIMIT_MAX where appropriate
Lennart Poettering [Wed, 17 Jan 2018 14:39:16 +0000 (15:39 +0100)]
cgroup: use CGROUP_LIMIT_MAX where appropriate

6 years agoutil: introduce more accurate definitions of TASKS_MAX
Lennart Poettering [Wed, 17 Jan 2018 14:31:23 +0000 (15:31 +0100)]
util: introduce more accurate definitions of TASKS_MAX

The maximum number of processes a tasks on the system is usually lower
than what pid_t would allow, and is compiled into the kernel (and
documented in proc(5)). Let's add proper defines for that, so that
we can adjust the pid_max sysctl without fearing invalid accesses.

6 years agolog: remove LOG_TARGET_SAFE pseudo log target
Lennart Poettering [Wed, 24 Jan 2018 17:01:01 +0000 (18:01 +0100)]
log: remove LOG_TARGET_SAFE pseudo log target

This removes LOG_TARGET_SAFE. It's made redundant by the new
"prohibit-ipc" logging flag, as it used to have a similar effect: avoid
logging to the journal/syslog, i.e. any local services in order to avoid
deadlocks when we lock from PID 1 or its utility processes (such as
generators).

All previous users of LOG_TARGET_SAFE are switched over to the new
setting. This makes things a bit safer for all, as not even the
SYSTEMD_LOG_TARGET env var can be used to accidentally log to the
journal anymore in these programs.

6 years agolog: add brief comment for log_set_open_when_needed() and log_set_always_reopen_console()
Lennart Poettering [Wed, 24 Jan 2018 16:45:14 +0000 (17:45 +0100)]
log: add brief comment for log_set_open_when_needed() and log_set_always_reopen_console()

These two deserve some explanation...

6 years agolog: add new "prohibit_ipc" flag to logging system
Lennart Poettering [Wed, 24 Jan 2018 16:36:25 +0000 (17:36 +0100)]
log: add new "prohibit_ipc" flag to logging system

If set, we'll avoid logging to any IPC log targets, i.e. syslog or the
journal, but allow stderr, kmsg, console logging.

This is useful as PID 1 wants to turn this off explicitly as long as the
journal is not up.

Previously we'd open/close the log stream to these services whenever
needed but this is incompatible with the "open_when_needed" logic
introduced in #6915, which might open the log streams whenever it likes,
including possibly inside of the child process we fork off that'll
become journald later on. Hence, let's make this all explicit, and
instead of managing when we open/close log streams add a boolean that
clearly prohibits the IPC targets when needed, so that opening can be
done at any time, but will honour this.

See: #7985

6 years agolog: make log_set_upgrade_syslog_to_journal() take effect immediately
Lennart Poettering [Wed, 24 Jan 2018 16:33:07 +0000 (17:33 +0100)]
log: make log_set_upgrade_syslog_to_journal() take effect immediately

This doesn't matter much, and we don't rely on it, but I think it's much
nicer if we log_set_target() and log_set_upgrade_syslog_to_journal() can
be called in either order and have the same effect.

6 years agoAdd fd close support to sd_event_source
Nathaniel McCallum [Wed, 24 Jan 2018 14:45:48 +0000 (09:45 -0500)]
Add fd close support to sd_event_source

It is often the case that a file descriptor and its corresponding IO
sd_event_source share a life span. When this is the case, developers will
have to unref the event source and close the file descriptor. Instead, we
can just have the event source take ownership of the file descriptor and
close it when the event source is freed. This is especially useful when
combined with cleanup attributes and sd_event_source_unrefp().

This patch adds two new public functions:

    sd_event_source_get_io_fd_own()
    sd_event_source_set_io_fd_own()

6 years agoInclude time.h in sd-event.h
Nathaniel McCallum [Wed, 24 Jan 2018 14:53:49 +0000 (09:53 -0500)]
Include time.h in sd-event.h

The time-related functions in sd-event.h take as inputs constants (CLOCK_*)
defined in time.h. By including time.h in sd-event.h, we free the developer
from having to do this manually.

6 years agoupdate TODO
Lennart Poettering [Fri, 12 Jan 2018 14:26:11 +0000 (15:26 +0100)]
update TODO

6 years agocore: rework how we track which PIDs to watch for a unit
Lennart Poettering [Fri, 12 Jan 2018 12:41:05 +0000 (13:41 +0100)]
core: rework how we track which PIDs to watch for a unit

Previously, we'd maintain two hashmaps keyed by PIDs, pointing to Unit
interested in SIGCHLD events for them. This scheme allowed a specific
PID to be watched by exactly 0, 1 or 2 units.

With this rework this is replaced by a single hashmap which is primarily
keyed by the PID and points to a Unit interested in it. However, it
optionally also keyed by the negated PID, in which case it points to a
NULL terminated array of additional Unit objects also interested. This
scheme means arbitrary numbers of Units may now watch the same PID.

Runtime and memory behaviour should not be impact by this change, as for
the common case (i.e. each PID only watched by a single unit) behaviour
stays the same, but for the uncommon case (a PID watched by more than
one unit) we only pay with a single additional memory allocation for the
array.

Why this all? Primarily, because allowing exactly two units to watch a
specific PID is not sufficient for some niche cases, as processes can
belong to more than one unit these days:

1. sd_notify() with MAINPID= can be used to attach a process from a
   different cgroup to multiple units.

2. Similar, the PIDFile= setting in unit files can be used for similar
   setups,

3. By creating a scope unit a main process of a service may join a
   different unit, too.

4. On cgroupsv1 we frequently end up watching all processes remaining in
   a scope, and if a process opens lots of scopes one after the other it
   might thus end up being watch by many of them.

This patch hence removes the 2-unit-per-PID limit. It also makes a
couple of other changes, some of them quite relevant:

- manager_get_unit_by_pid() (and the bus call wrapping it) when there's
  ambiguity will prefer returning the Unit the process belongs to based on
  cgroup membership, and only check the watch-pids hashmap if that
  fails. This change in logic is probably more in line with what people
  expect and makes things more stable as each process can belong to
  exactly one cgroup only.

- Every SIGCHLD event is now dispatched to all units interested in its
  PID. Previously, there was some magic conditionalization: the SIGCHLD
  would only be dispatched to the unit if it was only interested in a
  single PID only, or the PID belonged to the control or main PID or we
  didn't dispatch a signle SIGCHLD to the unit in the current event loop
  iteration yet. These rules were quite arbitrary and also redundant as
  the the per-unit handlers would filter the PIDs anyway a second time.
  With this change we'll hence relax the rules: all we do now is
  dispatch every SIGCHLD event exactly once to each unit interested in
  it, and it's up to the unit to then use or ignore this. We use a
  generation counter in the unit to ensure that we only invoke the unit
  handler once for each event, protecting us from confusion if a unit is
  both associated with a specific PID through cgroup membership and
  through the "watch_pids" logic. It also protects us from being
  confused if the "watch_pids" hashmap is altered while we are
  dispatching to it (which is a very likely case).

- sd_notify() message dispatching has been reworked to be very similar
  to SIGCHLD handling now. A generation counter is used for dispatching
  as well.

This also adds a new test that validates that "watch_pid" registration
and unregstration works correctly.

6 years agocore: unify call we use to synthesize cgroup empty events when we stopped watching...
Lennart Poettering [Fri, 12 Jan 2018 12:06:48 +0000 (13:06 +0100)]
core: unify call we use to synthesize cgroup empty events when we stopped watching any unit PIDs

This code is very similar in scope and service units, let's unify it in
one function. This changes little for service units, but for scope units
makes sure we go through the cgroup queue, which is something we should
do anyway.

6 years agocore: fix manager_get_unit_by_pid() special casing of manager PID
Lennart Poettering [Thu, 11 Jan 2018 22:38:46 +0000 (23:38 +0100)]
core: fix manager_get_unit_by_pid() special casing of manager PID

Previously, we'd hard map PID 1 to the manager scope unit. That's wrong
however when we are run in --user mode, as the PID 1 is outside of the
subtree we manage and the manager PID might be very differently. Correct
that by checking for getpid() rather than hardcoding 1.

6 years agotest: test-process-util additions
Lennart Poettering [Thu, 11 Jan 2018 15:02:47 +0000 (16:02 +0100)]
test: test-process-util additions

Add some extra paranoia tests that PTR_TO_PID() and PID_TO_PTR() deals
correctly with negative PID.

6 years agoprocess-util: replace PTR_TO_PID() and PID_TO_PTR macro by inline functions
Lennart Poettering [Thu, 11 Jan 2018 15:02:13 +0000 (16:02 +0100)]
process-util: replace PTR_TO_PID() and PID_TO_PTR macro by inline functions

This way we gain some typesafety at no cost.

6 years agoAdd support for SD_BUS_DEFAULT*
Nathaniel McCallum [Mon, 22 Jan 2018 21:26:44 +0000 (16:26 -0500)]
Add support for SD_BUS_DEFAULT*

Currently, sd-bus supports the ability to have thread-local default busses.
However, this is less useful than it can be since all functions which
require an sd_bus* as input require the caller to pass it. This patch adds
a new macro which allows the developer to pass a constant SD_BUS_DEFAULT,
SD_BUS_DEFAULT_USER or SD_BUS_DEFAULT_SYSTEM instead. This reduces work for
the caller.

For example:

    r = sd_bus_default(&bus);
    r = sd_bus_call_method(bus, ...);
    sd_bus_unref(bus);

Becomes:

    r = sd_bus_call_method(SD_BUS_DEFAULT, ...);

If the specified thread-local default bus does not exist, the function
calls will return -ENOPKG. No bus will ever be implicitly created.

6 years agoAdd support for SD_EVENT_DEFAULT
Nathaniel McCallum [Mon, 22 Jan 2018 20:38:07 +0000 (15:38 -0500)]
Add support for SD_EVENT_DEFAULT

Currently, sd-event supports the ability to have a thread-local default
event loop. However, this is less useful than it can be since all functions
which require an sd_event* as input require the caller to pass it. This
patch adds a new macro which allows the developer to pass a constant
SD_EVENT_DEFAULT instead. This reduces work for the caller.

For example:

    r = sd_event_default(&e);
    r = sd_event_add_io(e, ...);
    sd_event_unref(e);

Becomes:

    r = sd_event_add_io(SD_EVENT_DEFAULT, ...);

If no thread-local default event loop exists, the function calls will
return -ENOPKG. No event loop will ever be implicitly created.

6 years agopid1: add option to disable service watchdogs
Jan Klötzke [Mon, 20 Mar 2017 12:10:43 +0000 (13:10 +0100)]
pid1: add option to disable service watchdogs

Add a "systemd.service_watchdogs=" option to the command line which
disables all service runtime watchdogs and emergency actions.

6 years agobus-util: add bool property setter
Jan Klötzke [Thu, 11 Jan 2018 09:42:27 +0000 (10:42 +0100)]
bus-util: add bool property setter

6 years agohwdb: map zoomin/out keys to up/down
Martin Pitt [Mon, 22 Jan 2018 20:17:08 +0000 (21:17 +0100)]
hwdb: map zoomin/out keys to up/down

Some keyboards come with a zoom see-saw or rocker which until now got
mapped to the Linux "zoomin/out" keys in hwdb. However, these keycodes
are not recognized by any major desktop. They now produce Up/Down key
events so that they can be used for scrolling.

The internet is full of instructions how to "unbreak" these keys, e. g.

  https://askubuntu.com/questions/471802/make-the-zoom-slider-of-microsoft-natural-ergonomic-keyboard-4000-and-7000-scrol
  https://unix.stackexchange.com/questions/322075/how-to-get-ms-natural-ergonomic-4000-slider-work-on-linux-mint

So let's make it official. But keep their physical meaning in comments
in case desktops start to do something useful with them at some point.

Thanks to Finn Christiansen for the original patch!

Replaces #6953

6 years agoupdate TODO
Lennart Poettering [Mon, 22 Jan 2018 14:33:26 +0000 (15:33 +0100)]
update TODO

6 years agoremove canonicalize_file_name() mention from TODO
Reverend Homer [Mon, 22 Jan 2018 14:26:52 +0000 (17:26 +0300)]
remove canonicalize_file_name() mention from TODO

canonicalize_file_name() invocations were replaced by chase_symlinks() in
Decemeber 2016 with PR #4694, so we don't need this mention in the TODO anymore

6 years agofs-util: chase_symlinks(): prevent double free
Yu Watanabe [Sun, 21 Jan 2018 10:19:25 +0000 (19:19 +0900)]
fs-util: chase_symlinks(): prevent double free

Fixes CID #1385316.

6 years agofs-util: use _cleanup_close_ attribute
Yu Watanabe [Sun, 21 Jan 2018 10:07:10 +0000 (19:07 +0900)]
fs-util: use _cleanup_close_ attribute

The commit f14f1806e329fe92d01f15c22a384702f0cb4ae0 introduced CHASE_SAFE
flag. When the flag is set, then `fd_parent` may not be properly closed.
This sets `_cleanup_close_` attribute to `fd_parent`.
Thus, now `fd_parent` is always closed properly.

6 years agoNEWS: fix typo
Zbigniew Jędrzejewski-Szmek [Sat, 20 Jan 2018 03:04:17 +0000 (14:04 +1100)]
NEWS: fix typo

6 years agounaligned: let gcc generate optimal code
Shawn Landden [Sun, 17 Dec 2017 05:44:56 +0000 (21:44 -0800)]
unaligned: let gcc generate optimal code

on some architectures such as MIPS there are special unaligned load/store
sequences, instead of having to do bitwise accesses

https://www.linux-mips.org/wiki/Alignment

6 years agofs-util: chase_symlinks(): support empty root
Yu Watanabe [Fri, 19 Jan 2018 09:05:28 +0000 (18:05 +0900)]
fs-util: chase_symlinks(): support empty root

The commit b1bfb848046e457f3cd623286b8cc1a5e5440023 makes chase_symlinks()
recognize empty string for root as an invalid parameter. However,
empty root is often used e.g. systemd-nspawn.
This makes chase_symlinks() support empty string safely.

Fixes #7927.

6 years agobus-message: avoid -Wnull-pointer-arithmetic warning on new clang
Zbigniew Jędrzejewski-Szmek [Thu, 18 Jan 2018 05:23:09 +0000 (16:23 +1100)]
bus-message: avoid -Wnull-pointer-arithmetic warning on new clang

We just need some pointer, so use alignment directly converted
to the right type.

6 years agocore: un-break PrivateDevices= by allowing it to mknod /dev/ptmx
Alan Jenkins [Thu, 18 Jan 2018 12:07:31 +0000 (12:07 +0000)]
core: un-break PrivateDevices= by allowing it to mknod /dev/ptmx

#7886 caused PrivateDevices= to silently fail-open.
https://github.com/systemd/systemd/pull/7886#issuecomment-358542849

Allow PrivateDevices= to succeed, in creating /dev/ptmx, even though
DeviceControl=closed applies.

No specific justification was given for blocking mknod of /dev/ptmx.  Only
that we didn't seem to need it, because we weren't creating it correctly as
a device node.

6 years agofuzz: allow building fuzzers outside of oss-fuzz
Jonathan Rudenberg [Tue, 16 Jan 2018 15:25:43 +0000 (10:25 -0500)]
fuzz: allow building fuzzers outside of oss-fuzz

Add a new -Dllvm-fuzz=true option that can be used to build against
libFuzzer and update the oss-fuzz script to work outside of the
oss-fuzz build environment.

6 years agofuzz: disable all deps when building with oss-fuzz
Jonathan Rudenberg [Mon, 15 Jan 2018 23:27:37 +0000 (18:27 -0500)]
fuzz: disable all deps when building with oss-fuzz

The fuzz targets are intended to be fast and only target systemd
code, so they don't need to call out to any dependencies. They also
shouldn't depend on shared libraries outside of libc, so we disable
every dependency when compiling against oss-fuzz. This also
simplifies the upstream build environment significantly.

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