chiark / gitweb /
elogind.git
5 years agoresolve: rename PrivateDNS to DNSOverTLS
Iwan Timmer [Wed, 13 Jun 2018 18:26:24 +0000 (20:26 +0200)]
resolve: rename PrivateDNS to DNSOverTLS

PrivateDNS is not considered a good name for this option, so rename it to DNSOverTLS

5 years agopid1: preserve current value of log target across re-{load,execution}
Franck Bui [Fri, 1 Jun 2018 16:21:03 +0000 (18:21 +0200)]
pid1: preserve current value of log target across re-{load,execution}

To make debugging easier, this patches allows one to change the log target and
do reload/reexec without modifying configuration permanently, which makes
debugging easier.

Indeed if one changed the log target at runtime (via the bus or via signals),
the change was lost on the next reload/reexecution.

In order to restore back the default value (set via system.conf, environment
variables or any other means ), the empty string in the "LogTarget" property is
now supported as well as sending SIGTRMIN+26 signal.

5 years agopid1: preserve current value of log level across re-{load,execution}
Franck Bui [Wed, 30 May 2018 15:57:23 +0000 (17:57 +0200)]
pid1: preserve current value of log level across re-{load,execution}

To make debugging easier, this patches allows one to change the log level and
do reload/reexec without modifying configuration permanently, which makes
debugging easier.

Indeed if one changed the log max level at runtime (via the bus or via
signals), the change was lost on the next daemon reload/reexecution.

In order to restore the original value back (set via system.conf, environment
variables or any other means), the empty string in the "LogLevel" property is
now supported as well as sending SIGRTMIN+23 signal.

5 years agotest-alloc-util: add casts to bools from p ointers
Zbigniew Jędrzejewski-Szmek [Wed, 13 Jun 2018 08:34:30 +0000 (10:34 +0200)]
test-alloc-util: add casts to bools from p ointers

C++03: "An rvalue of arithmetic, enumeration, pointer, or pointer to member
type can be converted to an rvalue of type bool. A zero value, null pointer
value, or null member pointer value is converted to false; any other value is
converted to true"

C should behave the same because pointers are scalars in C, but let's verify
that.

5 years agotree-wide: drop !! casts to booleans
Zbigniew Jędrzejewski-Szmek [Mon, 11 Jun 2018 14:02:03 +0000 (16:02 +0200)]
tree-wide: drop !! casts to booleans

They are not needed, because anything that is non-zero is converted
to true.

C11:
> 6.3.1.2: When any scalar value is converted to _Bool, the result is 0 if the
> value compares equal to 0; otherwise, the result is 1.

https://stackoverflow.com/questions/31551888/casting-int-to-bool-in-c-c

5 years agotest-alloc-util: add a "test" for bool casts
Zbigniew Jędrzejewski-Szmek [Mon, 11 Jun 2018 14:07:45 +0000 (16:07 +0200)]
test-alloc-util: add a "test" for bool casts

Just in case ;)

There is no good place, test-alloc-util.c is as good as any, and it's quite
short so far, so let's add this there.

5 years agobasic/parse-util: remove unnecessary parentheses
Zbigniew Jędrzejewski-Szmek [Mon, 11 Jun 2018 11:47:25 +0000 (13:47 +0200)]
basic/parse-util: remove unnecessary parentheses

5 years agoterminal-util: make file names in --cat-config output clickable links
Lennart Poettering [Tue, 12 Jun 2018 13:43:59 +0000 (15:43 +0200)]
terminal-util: make file names in --cat-config output clickable links

5 years agoNEWS: add an example that actually applies
Lennart Poettering [Tue, 12 Jun 2018 13:20:05 +0000 (15:20 +0200)]
NEWS: add an example that actually applies

5 years agoNEWS: the tool is called resolvconf, without the inner e
Lennart Poettering [Tue, 12 Jun 2018 13:19:54 +0000 (15:19 +0200)]
NEWS: the tool is called resolvconf, without the inner e

5 years agoNEWS: break lines with emacs once more
Lennart Poettering [Tue, 12 Jun 2018 13:18:50 +0000 (15:18 +0200)]
NEWS: break lines with emacs once more

Let's follow the line break rules our .dir-locals.el file defines

5 years agoNEWS: some .mailmap work to clean up contributors list
Lennart Poettering [Tue, 12 Jun 2018 13:18:25 +0000 (15:18 +0200)]
NEWS: some .mailmap work to clean up contributors list

5 years agoconf-parser: simplify conf_parse_path()
Yu Watanabe [Mon, 4 Jun 2018 12:27:57 +0000 (21:27 +0900)]
conf-parser: simplify conf_parse_path()

Follow-up for 97651797e83d0548aef9f808657d3518d89e5aee.

5 years agobash-completion/resolvectl: support privatedns command
Yu Watanabe [Wed, 13 Jun 2018 02:16:26 +0000 (11:16 +0900)]
bash-completion/resolvectl: support privatedns command

5 years agoNEWS: add more news
Yu Watanabe [Wed, 13 Jun 2018 05:52:57 +0000 (14:52 +0900)]
NEWS: add more news

5 years agoNEWS: announce DNS-over-TLS too
Lennart Poettering [Tue, 12 Jun 2018 18:50:15 +0000 (20:50 +0200)]
NEWS: announce DNS-over-TLS too

5 years agoupdate NEWS with new PrivateMounts= blurb
Lennart Poettering [Tue, 12 Jun 2018 14:26:36 +0000 (16:26 +0200)]
update NEWS with new PrivateMounts= blurb

5 years agoNEWS: announce DNS-over-TLS too
Lennart Poettering [Tue, 12 Jun 2018 18:50:15 +0000 (20:50 +0200)]
NEWS: announce DNS-over-TLS too

5 years agocore: when applying io/blkio per-device rules, don't remove them if they fail
Lennart Poettering [Tue, 12 Jun 2018 17:37:22 +0000 (19:37 +0200)]
core: when applying io/blkio per-device rules, don't remove them if they fail

These devices might show up later, hence leave the rules as they are.
Applying the limits should not alter configuration.

5 years agotree-wide: unify how we define bit mak enums
Lennart Poettering [Thu, 7 Jun 2018 14:03:43 +0000 (16:03 +0200)]
tree-wide: unify how we define bit mak enums

Let's always write "1 << 0", "1 << 1" and so on, except where we need
more than 31 flag bits, where we write "UINT64(1) << 0", and so on to force
64bit values.

5 years agoresolved: support for DNS-over-TLS
Iwan Timmer [Fri, 27 Apr 2018 15:50:38 +0000 (17:50 +0200)]
resolved: support for DNS-over-TLS

Add support for DNS-over-TLS using GnuTLS. To reduce latency also TLS False Start and TLS session resumption is supported.

5 years agodoc: more spelling fixes
Michael Biebl [Tue, 12 Jun 2018 14:19:21 +0000 (16:19 +0200)]
doc: more spelling fixes

5 years agoNEWS: typo fixes
Michael Biebl [Tue, 12 Jun 2018 13:41:38 +0000 (15:41 +0200)]
NEWS: typo fixes

5 years agoNEWS: mention "bad-setting" load state and other small additions
Zbigniew Jędrzejewski-Szmek [Tue, 12 Jun 2018 12:06:47 +0000 (14:06 +0200)]
NEWS: mention "bad-setting" load state and other small additions

5 years agoNEWS, CODE_QUALITY: wording fixes
Zbigniew Jędrzejewski-Szmek [Tue, 12 Jun 2018 12:06:13 +0000 (14:06 +0200)]
NEWS, CODE_QUALITY: wording fixes

No additions, just moving stuff around and wording cleanups.

5 years agotree-wide: drop trailing whitespace
Lennart Poettering [Tue, 12 Jun 2018 10:03:28 +0000 (12:03 +0200)]
tree-wide: drop trailing whitespace

5 years agoprepare an initial NEWS file for v239
Lennart Poettering [Tue, 12 Jun 2018 10:02:51 +0000 (12:02 +0200)]
prepare an initial NEWS file for v239

5 years agotree-wide: use PATH_STARTSWITH_SET() at two more places
Lennart Poettering [Mon, 11 Jun 2018 10:32:37 +0000 (12:32 +0200)]
tree-wide: use PATH_STARTSWITH_SET() at two more places

5 years agocore: rework how we validate DeviceAllow= settings
Lennart Poettering [Mon, 11 Jun 2018 10:22:58 +0000 (12:22 +0200)]
core: rework how we validate DeviceAllow= settings

Let's make sure we don't validate "char-*" and "block-*" expressions as
paths.

5 years agocgroup: beef up device lookup logic for block devices
Lennart Poettering [Mon, 11 Jun 2018 10:17:32 +0000 (12:17 +0200)]
cgroup: beef up device lookup logic for block devices

Let's chase block devices through btrfs and LUKS like we do elsewhere.

5 years agopid1: do not reset subtree_control on already-existing units with delegation
Zbigniew Jędrzejewski-Szmek [Tue, 29 May 2018 10:19:09 +0000 (12:19 +0200)]
pid1: do not reset subtree_control on already-existing units with delegation

Fixes #8364.

Reproducer:
$ sudo systemd-run -t -p Delegate=yes bash
# mkdir /sys/fs/cgroup/system.slice/run-u6958.service/supervisor
# echo $$ > /sys/fs/cgroup/system.slice/run-u6958.service/supervisor/cgroup.procs
# echo +memory > /sys/fs/cgroup/system.slice/run-u6958.service/cgroup.subtree_control
# cat /sys/fs/cgroup/system.slice/run-u6958.service/cgroup.subtree_control
memory
# systemctl daemon-reload
# cat /sys/fs/cgroup/system.slice/run-u6958.service/cgroup.subtree_control
(empty)

With patch, the last command shows 'memory'.

5 years agomeson: also reject shifts that change the sign bit
Zbigniew Jędrzejewski-Szmek [Mon, 11 Jun 2018 11:17:43 +0000 (13:17 +0200)]
meson: also reject shifts that change the sign bit

../src/test/test-sizeof.c: In function ‘main’:
../src/test/test-sizeof.c:70:24: error: result of ‘1 << 31’ requires 33 bits to represent, but ‘int’ only has 32 bits [-Werror=shift-overflow=]
                 X = (1 << 31),
                        ^~
cc1: some warnings being treated as errors

Follow-up for b05ecb8cadd8c32d31b1aabcff4e507bd89b5465.

5 years agobasic/path-util: fix ordering in error message
Zbigniew Jędrzejewski-Szmek [Mon, 11 Jun 2018 12:37:36 +0000 (14:37 +0200)]
basic/path-util: fix ordering in error message

Jun 11 14:29:12 krowka systemd[1]: /etc/systemd/system/workingdir.service:6: = path is not normalizedWorkingDirectory: /../../etc
   ↓
Jun 11 14:32:12 krowka systemd[1]: /etc/systemd/system/workingdir.service:6: WorkingDirectory= path is not normalized: /../../etc

5 years agocore: introduce a new load state "bad-setting"
Lennart Poettering [Fri, 1 Jun 2018 15:46:01 +0000 (17:46 +0200)]
core: introduce a new load state "bad-setting"

Since bb28e68477a3a39796e4999a6cbc6ac6345a9159 parsing failures of
certain unit file settings will result in load failures of units. This
introduces a new load state "bad-setting" that is entered in precisely
this case.

With this addition error messages on bad settings should be a lot more
explicit, as we don't have to show some generic "errno" error in that
case, but can explicitly say that a bad setting is at fault.

Internally this unit load state is entered as soon as any configuration
loader call returns ENOEXEC. Hence: config parser calls should return
ENOEXEC now for such essential unit file settings. Turns out, they
generally already do.

Fixes: #9107
5 years agoconf-parser: add config_parse_permille()
Marc Kleine-Budde [Tue, 5 Jun 2018 14:08:29 +0000 (16:08 +0200)]
conf-parser: add config_parse_permille()

5 years agoparse-util: add permille parser + tests
Marc Kleine-Budde [Tue, 5 Jun 2018 13:15:33 +0000 (15:15 +0200)]
parse-util: add permille parser + tests

5 years agobasic/format-table: remove parameter with constant value
Zbigniew Jędrzejewski-Szmek [Mon, 11 Jun 2018 07:57:05 +0000 (09:57 +0200)]
basic/format-table: remove parameter with constant value

5 years agobasic/ellipsize: do not assume the string is NUL-terminated when length is given
Zbigniew Jędrzejewski-Szmek [Sat, 9 Jun 2018 11:41:44 +0000 (13:41 +0200)]
basic/ellipsize: do not assume the string is NUL-terminated when length is given

oss-fuzz flags this as:

==1==WARNING: MemorySanitizer: use-of-uninitialized-value

0. 0x7fce77519ca5 in ascii_is_valid systemd/src/basic/utf8.c:252:9
1. 0x7fce774d203c in ellipsize_mem systemd/src/basic/string-util.c:544:13
2. 0x7fce7730a299 in print_multiline systemd/src/shared/logs-show.c:244:37
3. 0x7fce772ffdf3 in output_short systemd/src/shared/logs-show.c:495:25
4. 0x7fce772f5a27 in show_journal_entry systemd/src/shared/logs-show.c:1077:15
5. 0x7fce772f66ad in show_journal systemd/src/shared/logs-show.c:1164:29
6. 0x4a2fa0 in LLVMFuzzerTestOneInput systemd/src/fuzz/fuzz-journal-remote.c:64:21
...

I didn't reproduce the issue, but this looks like an obvious error: the length
is specified, so we shouldn't use the string with any functions for normal
C-strings.

5 years agobasic/utf8: add ascii_is_valid_n()
Zbigniew Jędrzejewski-Szmek [Sat, 9 Jun 2018 11:41:24 +0000 (13:41 +0200)]
basic/utf8: add ascii_is_valid_n()

5 years agoutil-lib: reject too long path for timedate_is_valid()
Yu Watanabe [Mon, 11 Jun 2018 03:31:02 +0000 (12:31 +0900)]
util-lib: reject too long path for timedate_is_valid()

This should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8827.

5 years agomeson: do not allow bit-shift overflows
Zbigniew Jędrzejewski-Szmek [Sat, 9 Jun 2018 11:12:52 +0000 (13:12 +0200)]
meson: do not allow bit-shift overflows

The primary motivation is to catch enum values created through a shift that is
too big:

../src/test/test-sizeof.c:26:29: error: left shift count >= width of type [-Werror=shift-count-overflow]
         enum_with_shift = 1 << 32,
                             ^~
cc1: some warnings being treated as errors

The compiler will now reject those.

This is an alternative to #9224.

5 years agosd-event: document sd_event_source_set_io_fd_own()
Lennart Poettering [Thu, 7 Jun 2018 11:07:52 +0000 (13:07 +0200)]
sd-event: document sd_event_source_set_io_fd_own()

With this we have 100% of the sd-event symbols documented again. Yay!

5 years agosd-event: add destroy callback logic to sd-event too
Lennart Poettering [Thu, 7 Jun 2018 10:40:35 +0000 (12:40 +0200)]
sd-event: add destroy callback logic to sd-event too

This adds what has been added to sd_bus_slot and sd_bus_track to
sd_event too.

5 years agosd-bus: also add destroy callbacks to sd_bus_track objects
Lennart Poettering [Thu, 7 Jun 2018 10:29:52 +0000 (12:29 +0200)]
sd-bus: also add destroy callbacks to sd_bus_track objects

This augments previous work for this for sd_bus_slot objects, and adds
the same concept to sd_bus_track objects, too.

5 years agocopy: put a depth limit on copying file system trees recursively
Lennart Poettering [Thu, 7 Jun 2018 11:24:03 +0000 (13:24 +0200)]
copy: put a depth limit on copying file system trees recursively

This is a safety net against bind mount cycles, as such pick it
relatively high at 2048 for now.

As suggested by @filbranden on #9213

5 years agocopy: extend check for mount point crossing
Lennart Poettering [Wed, 6 Jun 2018 15:33:28 +0000 (17:33 +0200)]
copy: extend check for mount point crossing

We do this checks as protection against bind mount cycles on the same
file system. However, the check wasn't really effective for that, as
it would only detect cycles A → B → A this way. By using
fs_is_mount_point() we'll also detect cycles A → A.

Also, while we are at it, make these file system boundary checks
optional. This is not used anywhere, but might be eventually...

Most importantly though add a longer blurb explanation the why.

5 years agocopy: only check for traversing mount points on directories
Filipe Brandenburger [Mon, 4 Jun 2018 21:23:14 +0000 (14:23 -0700)]
copy: only check for traversing mount points on directories

This fixes the copy routines on overlay filesystem, which typically
returns the underlying st_dev for files, symlinks, etc.

The value of st_dev is guaranteed to be the same for directories, so
checking it on directories only fixes this code on overlay filesystem
and still keeps it from traversing mount points (which was the original
intent.)

There's a small side effect here, by which regular (non-directory) files
with bind mounts will be copied by the new logic (while they were
skipped by the previous logic.)

Tested: ./build/test-copy with an overlay on /tmp.

Fixes: #9134
5 years agoupdate TODO
Lennart Poettering [Thu, 7 Jun 2018 16:20:04 +0000 (18:20 +0200)]
update TODO

5 years agoupdate TODO
Lennart Poettering [Thu, 7 Jun 2018 15:35:58 +0000 (17:35 +0200)]
update TODO

The three ancient entries marked "bugfixes" are already fixed (in two
cases), or are not really bugs (in the other case). Let's clean this up
a bit.

5 years agoupdate TODO
Lennart Poettering [Mon, 4 Jun 2018 19:00:44 +0000 (21:00 +0200)]
update TODO

5 years agotree-wide: fix a number of log calls that use %m but have no errno set
Lennart Poettering [Tue, 5 Jun 2018 18:18:47 +0000 (20:18 +0200)]
tree-wide: fix a number of log calls that use %m but have no errno set

This is mostly fall-out from d1a1f0aaf0d2f08c60d1e0d32e646439d99f58dc,
however some cases are older bugs.

There might be more issues lurking, this was a simple grep for "%m"
across the tree, with all lines removed that mention "errno" at all.

5 years agoudev: add helper udev_device_new_from_stat_rdev()
Lennart Poettering [Mon, 4 Jun 2018 20:52:02 +0000 (22:52 +0200)]
udev: add helper udev_device_new_from_stat_rdev()

This is a simple wrapper around udev_device_new_from_devnum(), and uses
the data from a struct stat's .st_rdev field to derive the udev_device
object.

5 years agoCODING_STYLE: allow c99-style mixed code and declarations
Zbigniew Jędrzejewski-Szmek [Thu, 7 Jun 2018 13:08:02 +0000 (15:08 +0200)]
CODING_STYLE: allow c99-style mixed code and declarations

We already allowed variables to be declared in the middle of a function
(whenever a new scope was opened), so this isn't such a big change. Sometimes
we would open a scope just to work around this prohibition.

But sometimes the code can be much clearer if the variable is declared
somewhere in the middle of a scope, in particular if the declaration is
combined with initialization or acquisition of some resources. So let's allow
this, but keep things in the old style, unless there's a good reason to move
the variable declaration to a different place.

5 years agotools: make various scripts find the top-levle git dir automatically
Lennart Poettering [Thu, 7 Jun 2018 13:07:14 +0000 (15:07 +0200)]
tools: make various scripts find the top-levle git dir automatically

5 years agoshared/bus-util: use the new cleanup functionality to avoid a memleak
Zbigniew Jędrzejewski-Szmek [Wed, 6 Jun 2018 09:12:25 +0000 (11:12 +0200)]
shared/bus-util: use the new cleanup functionality to avoid a memleak

If the async callbacks didn't get a chance to finish properly, we'd leak
memory.

The output from test-bus-util with additional log line in the callbacks to show
what is happening:

$ build/test-bus-util

/* test_name_async (0) */
Bus test-bus: changing state UNSET → OPENING
Bus test-bus: changing state OPENING → AUTHENTICATING
Bus test-bus: changing state AUTHENTICATING → HELLO
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RequestName cookie=2 reply_cookie=0 signature=su error-name=n/a error-message=n/a
Got message type=method_return sender=org.freedesktop.DBus destination=:1.732 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=1 signature=s error-name=n/a error-message=n/a
Bus test-bus: changing state HELLO → RUNNING
Bus test-bus: changing state RUNNING → CLOSED
request_name_destroy_callback n_ref=1

/* test_name_async (20) */
Bus test-bus: changing state UNSET → OPENING
Bus test-bus: changing state OPENING → AUTHENTICATING
Bus test-bus: changing state AUTHENTICATING → HELLO
stage 0: sd_bus_process returned 1
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RequestName cookie=2 reply_cookie=0 signature=su error-name=n/a error-message=n/a
stage 1: sd_bus_process returned 1
Got message type=method_return sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=1 signature=s error-name=n/a error-message=n/a
Bus test-bus: changing state HELLO → RUNNING
stage 2: sd_bus_process returned 1
Got message type=signal sender=org.freedesktop.DBus.Local destination=n/a path=/org/freedesktop/DBus/Local interface=org.freedesktop.DBus.Local member=Connected cookie=4294967295 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a
stage 3: sd_bus_process returned 1
Got message type=signal sender=org.freedesktop.DBus destination=:1.733 path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameAcquired cookie=4294967295 reply_cookie=0 signature=s error-name=n/a error-message=n/a
stage 4: sd_bus_process returned 1
Got message type=error sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=2 signature=s error-name=org.freedesktop.DBus.Error.AccessDenied error-message=Request to own name refused by policy
Unable to request name, will retry after reloading DBus configuration: Request to own name refused by policy
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=ReloadConfig cookie=3 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a
request_name_destroy_callback n_ref=2
stage 5: sd_bus_process returned 1
Got message type=method_return sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=3 signature= error-name=n/a error-message=n/a
Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RequestName cookie=4 reply_cookie=0 signature=su error-name=n/a error-message=n/a
request_name_destroy_callback n_ref=1
stage 6: sd_bus_process returned 1
Got message type=error sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=4 signature=s error-name=org.freedesktop.DBus.Error.AccessDenied error-message=Request to own name refused by policy
Unable to request name, failing connection: Request to own name refused by policy
Bus test-bus: changing state RUNNING → CLOSING
stage 7: sd_bus_process returned 1
Bus test-bus: changing state CLOSING → CLOSED
stage 8: sd_bus_process returned 1
stage 9: sd_bus_process returned -104
Processing failed: Connection reset by peer

5 years agobus: optionally call a callbacks for cleanup
Zbigniew Jędrzejewski-Szmek [Wed, 6 Jun 2018 09:07:02 +0000 (11:07 +0200)]
bus: optionally call a callbacks for cleanup

This adds a function sd_bus_slot_set_destroy_callback() to set a function
which can free userdata or perform other cleanups.

sd_bus_slot_get_destory_callback() queries the callback, and is included
for completeness.

Without something like this, for floating asynchronous callbacks, which might
be called or not, depending on the sequence of events, it's hard to perform
resource cleanup. The alternative would be to always perform the cleanup from
the caller too, but that requires more coordination and keeping of some shared
state. It's nicer to keep the cleanup contained between the callback and the
function that requests the callback.

5 years agotest-bus-util: add a simple test for bus_request_name_async_may_reload_dbus()
Zbigniew Jędrzejewski-Szmek [Mon, 4 Jun 2018 13:15:17 +0000 (15:15 +0200)]
test-bus-util: add a simple test for bus_request_name_async_may_reload_dbus()

This shows a minor memleak:
==1883== 24 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1883==    at 0x4C2DBAB: malloc (vg_replace_malloc.c:299)
==1883==    by 0x4E9D385: malloc_multiply (alloc-util.h:69)
==1883==    by 0x4EA2959: bus_request_name_async_may_reload_dbus (bus-util.c:1841)
==1883==    by ...

The exchange of messages is truncated at two different points: once right
after the first callback is requested, and the second time after the full
sequence has run (usually resulting in an error because of policy).

5 years agobus-util: avoid unneeded initalization to zero
Zbigniew Jędrzejewski-Szmek [Mon, 4 Jun 2018 11:04:40 +0000 (13:04 +0200)]
bus-util: avoid unneeded initalization to zero

5 years agoman: xinclude the generic text to talk about libsystemd pkgconfig
Zbigniew Jędrzejewski-Szmek [Wed, 6 Jun 2018 09:59:04 +0000 (11:59 +0200)]
man: xinclude the generic text to talk about libsystemd pkgconfig

The only difference is that functions are not individually listed by name,
but that seems completely pointless, since all functions that are documented
are always exported, so the generic text tells the user all she or he needs
to know.

5 years agoRemove NULL terminator from two log_struct calls
Zbigniew Jędrzejewski-Szmek [Wed, 6 Jun 2018 12:44:34 +0000 (14:44 +0200)]
Remove NULL terminator from two log_struct calls

Fixup for a1230ff972. I forgot to press "save" ;(

5 years agoutil: add new write_string_filef() helper
Lennart Poettering [Tue, 5 Jun 2018 14:02:32 +0000 (16:02 +0200)]
util: add new write_string_filef() helper

This new helper combines asprintf() and write_string_file() in one,
which is useful at various places to shorten the code a bit.

5 years agomain: split out reading of /proc/sys/fs/nr_open into its own function
Lennart Poettering [Tue, 5 Jun 2018 13:21:47 +0000 (15:21 +0200)]
main: split out reading of /proc/sys/fs/nr_open into its own function

This doesn't really reduce the code size over all, but it does make main.c
shorter and more readable, and that's always a good thing.

5 years agostring-util: put together strstrip() from skip_leading_chars() and delete_trailing_ch...
Lennart Poettering [Wed, 6 Jun 2018 09:58:38 +0000 (11:58 +0200)]
string-util: put together strstrip() from skip_leading_chars() and delete_trailing_chars()

5 years agoprocess-util: make use of delete_trailing_chars() in get_process_cmdline()
Lennart Poettering [Wed, 6 Jun 2018 09:58:18 +0000 (11:58 +0200)]
process-util: make use of delete_trailing_chars() in get_process_cmdline()

5 years agoupdate TODO
Lennart Poettering [Tue, 29 May 2018 14:20:46 +0000 (16:20 +0200)]
update TODO

5 years agosd-event: use structure initialization instead of new0() where possible
Lennart Poettering [Wed, 6 Jun 2018 08:49:27 +0000 (10:49 +0200)]
sd-event: use structure initialization instead of new0() where possible

5 years agotime-util: introduce common implementation of TFD_TIMER_CANCEL_ON_SET client code
Lennart Poettering [Tue, 29 May 2018 10:55:33 +0000 (12:55 +0200)]
time-util: introduce common implementation of TFD_TIMER_CANCEL_ON_SET client code

We now use pretty much the same code at three places, let's unify that.

5 years agoman: document the new sd_event_add_inotify() call
Lennart Poettering [Tue, 29 May 2018 13:59:26 +0000 (15:59 +0200)]
man: document the new sd_event_add_inotify() call

5 years agosd-event: add test for the new sd_event_add_inotify() API
Lennart Poettering [Mon, 28 May 2018 15:25:14 +0000 (17:25 +0200)]
sd-event: add test for the new sd_event_add_inotify() API

This tests a couple of corner cases of the sd-event API including
changing priorities of existing event sources, as well as overflow
conditions of the inotify queue.

5 years agosd-event: add new API for subscribing to inotify events
Lennart Poettering [Mon, 28 May 2018 14:26:50 +0000 (16:26 +0200)]
sd-event: add new API for subscribing to inotify events

This adds a new call sd_event_add_inotify() which allows watching for
inotify events on specified paths.

sd-event will try to minimize the number of inotify fds allocated, and
will try to add file watches to the same inotify fd objects as far as
that's possible. Doing this kind of inotify object should optimize
behaviour in programs that watch a limited set of mostly independent
files as in most cases a single inotify object will suffice for watching
all files.

Traditionally, this kind of coalescing logic (i.e. that multiple event
sources are implemented on top of a single inotify object) was very hard
to do, as the inotify API had serious limitations: it only allowed
adding watches by path, and would implicitly merge watches installed on
the same node via different path, without letting the caller know about
whether such merging took place or not.

With the advent of O_PATH this issue can be dealt with to some point:
instead of adding a path to watch to an inotify object with
inotify_add_watch() right away, we can open the path with O_PATH first,
call fstat() on the fd, and check the .st_dev/.st_ino fields of that
against a list of watches we already have in place. If we find one we
know that the inotify_add_watch() will update the watch mask of the
existing watch, otherwise it will create a new watch. To make this
race-free we use inotify_add_watch() on the /proc/self/fd/ path of the
O_PATH fd, instead of the original path, so that we do the checking and
watch updating with guaranteed the same inode.

This approach let's us deal safely with inodes that may appear under
various different paths (due to symlinks, hardlinks, bind mounts, fs
namespaces). However it's not a perfect solution: currently the kernel
has no API for changing the watch mask of an existing watch -- unless
you have a path or fd to the original inode. This means we can "merge"
the watches of the same inode of multiple event sources correctly, but
we cannot "unmerge" it again correctly in many cases, as access to the
original inode might have been lost, due to renames, mount/unmount, or
deletions. We could in theory always keep open an O_PATH fd of the inode
to watch so that we can change the mask anytime we want, but this is
highly problematics, as it would consume too many fds (and in fact the
scarcity of fds is the reason why watch descriptors are a separate
concepts from fds) and would keep the backing mounts busy (wds do not
keep mounts busy, fds do). The current implemented approach to all this:
filter in userspace and accept that the watch mask on some inode might
be higher than necessary due to earlier installed event sources that
might have ceased to exist. This approach while ugly shouldn't be too
bad for most cases as the same inodes are probably wacthed for the same
masks in most implementations.

In order to implement priorities correctly a seperate inotify object is
allocated for each priority that is used. This way we get separate
per-priority event queues, of which we never dequeue more than a few
events at a time.

Fixes: #3982
5 years agosd-event: voidify more things
Lennart Poettering [Fri, 25 May 2018 15:09:26 +0000 (17:09 +0200)]
sd-event: voidify more things

5 years agosd-event: propagate errors from source_set_pending() in all cases
Lennart Poettering [Fri, 25 May 2018 15:08:40 +0000 (17:08 +0200)]
sd-event: propagate errors from source_set_pending() in all cases

5 years agosd-event: drop pending events when we turn off/on an event source
Lennart Poettering [Fri, 25 May 2018 15:06:39 +0000 (17:06 +0200)]
sd-event: drop pending events when we turn off/on an event source

5 years agosd-event: use symbolic name for normal priority
Lennart Poettering [Fri, 25 May 2018 15:05:30 +0000 (17:05 +0200)]
sd-event: use symbolic name for normal priority

5 years agosd-event: use structure initialization for epoll_event
Lennart Poettering [Fri, 25 May 2018 15:05:07 +0000 (17:05 +0200)]
sd-event: use structure initialization for epoll_event

5 years agoNEWS: add note about --runtime
Zbigniew Jędrzejewski-Szmek [Tue, 5 Jun 2018 12:25:43 +0000 (14:25 +0200)]
NEWS: add note about --runtime

5 years agoupdate TODO
Lennart Poettering [Wed, 6 Jun 2018 09:44:58 +0000 (11:44 +0200)]
update TODO

5 years agoutil: tighten on_tty() check a bit, also check stderr
Lennart Poettering [Tue, 5 Jun 2018 19:53:54 +0000 (21:53 +0200)]
util: tighten on_tty() check a bit, also check stderr

Let's detect output redirection a bit better, cover both stdout and
stderr.

Fixes: #9192
5 years agocgroup: tiny log message tweak, say that we ignore one kind of failure
Lennart Poettering [Thu, 31 May 2018 13:40:54 +0000 (15:40 +0200)]
cgroup: tiny log message tweak, say that we ignore one kind of failure

5 years agoupdate NEWS to explain new OnFailure= behaviour
Lennart Poettering [Fri, 1 Jun 2018 17:13:38 +0000 (19:13 +0200)]
update NEWS to explain new OnFailure= behaviour

5 years agoconf-parser: fix memleak (#9177)
Yu Watanabe [Mon, 4 Jun 2018 12:18:28 +0000 (21:18 +0900)]
conf-parser: fix memleak (#9177)

Fixes CID#1391437.

Closes #9180.

5 years agobasic/log: add the log_struct terminator to macro
Zbigniew Jędrzejewski-Szmek [Mon, 4 Jun 2018 10:59:22 +0000 (12:59 +0200)]
basic/log: add the log_struct terminator to macro

This way all callers do not need to specify it.
Exhaustively tested by running test-log under valgrind ;)

5 years agobasic/path-util: use FLAGS_SET in one more place
Zbigniew Jędrzejewski-Szmek [Mon, 4 Jun 2018 08:29:23 +0000 (10:29 +0200)]
basic/path-util: use FLAGS_SET in one more place

5 years agoAdd macro for checking if some flags are set
Zbigniew Jędrzejewski-Szmek [Fri, 20 Apr 2018 13:36:20 +0000 (15:36 +0200)]
Add macro for checking if some flags are set

This way we don't need to repeat the argument twice.
I didn't replace all instances. I think it's better to leave out:
- asserts
- comparisons like x & y == x, which are mathematically equivalent, but
  here we aren't checking if flags are set, but if the argument fits in the
  flags.

5 years agotest-ellipsize: add tests for ellipsize_mem, fix bugs
Zbigniew Jędrzejewski-Szmek [Sat, 2 Jun 2018 15:08:46 +0000 (17:08 +0200)]
test-ellipsize: add tests for ellipsize_mem, fix bugs

First, ellipsize() and ellipsize_mem() should not read past the input
buffer. Those functions take an explicit length for the input data, so they
should not assume that the buffer is terminated by a nul.

Second, ellipsization was off in various cases where wide on multi-byte
characters were used.

We had some basic test for ellipsize(), but apparently it wasn't enough to
catch more serious cases.

Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8686.

5 years agobasic/string-util: make ellipsize() inline
Zbigniew Jędrzejewski-Szmek [Sat, 2 Jun 2018 15:52:07 +0000 (17:52 +0200)]
basic/string-util: make ellipsize() inline

Once the redundant check is removed, it's a very simple wrapper around
ellipsize_mem().

5 years agologin: log session state "closing" (as well as New/Removed)
Alan Jenkins [Fri, 1 Jun 2018 18:03:21 +0000 (19:03 +0100)]
login: log session state "closing" (as well as New/Removed)

Let's show a message at the time of logout i.e. entering the "closing"
state, not just e.g. once the user closes `tmux` and the session can be
removed completely.  (At least when KillUserProcesses=no applies.  My
thinking was we can spare the log noise if we're killing the processes
anyway).

These are two independent events.  I think the logout event is quite
significant in the session lifecycle.  It will be easier for a user who
does not know logind details to understand why "Removed session" doesn't
appear at logout time, if we have a specific message we can show at this
time :).

Tested using tmux and KillUserProcesses=no.  I can also confirm the extra
message doesn't show when using KillUserProcesses=yes.  Maybe it looks a
bit mysterious when you use KillOnlyUsers= / KillExcludeUsers=, but
hopefully not alarmingly so.

I was looking at systemd-logind messages on my system, because I can
reproduce two separate problems with Gnome on Fedora 28 where
sessions are unexpectedly in state "closing".  (One where a GUI session
limps along in a degraded state[1], and another where spice-vdagent is left
alive after logout, keeping the session around[2]).  It logged when
sessions were created and removed, but it didn't log when the session
entered the "closing" state.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1583240#c1
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1583261

Closes #9096

5 years agoconf-parser: remove redundant utf8-validity check
Yu Watanabe [Sun, 3 Jun 2018 15:36:46 +0000 (00:36 +0900)]
conf-parser: remove redundant utf8-validity check

5 years agoconf-parse: use free_and_replace()
Yu Watanabe [Sun, 3 Jun 2018 15:30:36 +0000 (00:30 +0900)]
conf-parse: use free_and_replace()

Also removes unnecessary empty lines.

5 years agoconf-parser: reject utf8-invalid lines
Yu Watanabe [Sun, 3 Jun 2018 15:30:18 +0000 (00:30 +0900)]
conf-parser: reject utf8-invalid lines

5 years agoconf-parse: use path_simplify_and_warn() in config_parse_path()
Yu Watanabe [Sun, 3 Jun 2018 14:57:30 +0000 (23:57 +0900)]
conf-parse: use path_simplify_and_warn() in config_parse_path()

5 years agopath-util: introduce path_simplify_and_warn()
Yu Watanabe [Fri, 1 Jun 2018 05:11:37 +0000 (14:11 +0900)]
path-util: introduce path_simplify_and_warn()

5 years agopath-util: make path_make_relative() support path including dots
Yu Watanabe [Sun, 3 Jun 2018 14:54:32 +0000 (23:54 +0900)]
path-util: make path_make_relative() support path including dots

5 years agopath-util: introduce path_simplify()
Yu Watanabe [Thu, 31 May 2018 14:39:31 +0000 (23:39 +0900)]
path-util: introduce path_simplify()

The function is similar to path_kill_slashes() but also removes
initial './', trailing '/.', and '/./' in the path.
When the second argument of path_simplify() is false, then it
behaves as the same as path_kill_slashes(). Hence, this also
replaces path_kill_slashes() with path_simplify().

5 years agotime-util: fix build with gcc8 -Werror=format-truncation=
Martin Jansa [Fri, 1 Jun 2018 15:22:28 +0000 (15:22 +0000)]
time-util: fix build with gcc8 -Werror=format-truncation=

* it fails with gcc8 when -O1 or -Os is used (and -ftree-vrp which is added by -O2 and higher isn't used)

../git/src/basic/time-util.c: In function 'format_timespan':
../git/src/basic/time-util.c:508:46: error: '%0*llu' directive output between 1 and 2147483647 bytes may cause result to exceed 'INT_MAX' [-Werror=format-truncation=]
                                              "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                              ^~~~
../git/src/basic/time-util.c:508:60: note: format string is defined here
                                              "%s"USEC_FMT".%0*"PRI_USEC"%s",
../git/src/basic/time-util.c:508:46: note: directive argument in the range [0, 18446744073709551614]
                                              "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                              ^~~~
../git/src/basic/time-util.c:507:37: note: 'snprintf' output 4 or more bytes (assuming 2147483651) into a destination of size 4294967295
                                 k = snprintf(p, l,
                                     ^~~~~~~~~~~~~~
                                              "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                              p > buf ? " " : "",
                                              ~~~~~~~~~~~~~~~~~~~
                                              a,
                                              ~~
                                              j,
                                              ~~
                                              b,
                                              ~~
                                              table[i].suffix);
                                              ~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

[zj: change 'char' to 'signed char']

5 years agobasic: set errno in raw_clone() on sparc
Mike Gilbert [Thu, 31 May 2018 03:06:33 +0000 (23:06 -0400)]
basic: set errno in raw_clone() on sparc

sparc sets the carry bit when a syscall fails. Use this information to
set errno and return -1 as appropriate.

The added test case calls raw_clone() with flags known to be invalid
according to the clone(2) manpage.

5 years agoprocess-util: also filter non-printable characters in get_process_com()
Lennart Poettering [Thu, 17 May 2018 01:50:35 +0000 (21:50 -0400)]
process-util: also filter non-printable characters in get_process_com()

We already do that in get_process_cmdline(), which is very similar in
behaviour otherwise. Hence, let's be safe and also filter them in
get_process_comm(). Let's try to retain as much information as we can
though and escape rather than suppress unprintable characters. Let's not
increase comm names beyond the kernel limit on such names however.

Also see discussion about this here:

https://marc.info/?l=linux-api&m=152649570404881&w=2

5 years agostring-util: tweak cellescape() a bit
Lennart Poettering [Fri, 1 Jun 2018 19:45:23 +0000 (21:45 +0200)]
string-util: tweak cellescape() a bit

For short buffer sizes cellescape() was a bit wasteful, as it might
suffice to to drop a single character to find enough place for the full
four byte ellipsis, if that one character was a four character escape.
With this rework we'll guarantee to drop the minimum number of
characters from the end to fit in the ellipsis.

If the buffers we write to are large this doesn't matter much. However,
if they are short (as they are when talking about the process comm
field) then it starts to matter that we put as much information as we
can in the space we get.

5 years agoescape: add an explanatory comment about buffer sizes
Lennart Poettering [Fri, 1 Jun 2018 19:45:06 +0000 (21:45 +0200)]
escape: add an explanatory comment about buffer sizes

5 years agomissing: define kernel internal limit TASK_COMM_LEN in userspace too
Lennart Poettering [Fri, 1 Jun 2018 19:43:43 +0000 (21:43 +0200)]
missing: define kernel internal limit TASK_COMM_LEN in userspace too

We already use it at two places, and we are about to add one too.
Arbitrary literally hardcoded limits suck.