chiark / gitweb /
elogind.git
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.

5 years agoprocess-util: mention that wait_for_terminate_with_timeout() should be called with...
Lennart Poettering [Thu, 17 May 2018 02:14:59 +0000 (22:14 -0400)]
process-util: mention that wait_for_terminate_with_timeout() should be called with SIGCHLD blocked

5 years agobuild-sys: Add option to link systemctl statically
Felipe Sateler [Tue, 22 May 2018 19:08:57 +0000 (15:08 -0400)]
build-sys: Add option to link systemctl statically

Systemctl is special because it is required for many tasks that may need to
be performed when the system is not fully configured and/or partially
broken:

1. Installing/Uninstalling services during OS installs and upgrades
2. Shutting down the system

Therefore reduce the number of dependencies that systemctl pulls in, by
not linking to systemd-shared. This brings a bit of resilience to
systemctl (and its aliases shutdown, reboot, etc), by linking against
less external libraries.

Because this extra resilience comes at a cost of approximately 580 KB
extra space, this is done behind a meson build option.

5 years agoUse const char* for timestamp strings which we don't plan to modify
Zbigniew Jędrzejewski-Szmek [Thu, 24 May 2018 07:36:56 +0000 (09:36 +0200)]
Use const char* for timestamp strings which we don't plan to modify

Makes the intent a bit clearer.

5 years agoAlways allow timestamps to be printed
Zbigniew Jędrzejewski-Szmek [Mon, 21 May 2018 18:39:09 +0000 (20:39 +0200)]
Always allow timestamps to be printed

If the timestamp is above 9999-12-30, (or 2038-something-something on 32 bit),
use XXXX-XX-XX XX:XX:XX as the replacement.

The problem with refusing to print timestamps is that our code accepts such
timestamps, so we can't really just refuse to process them afterwards. Also, it
makes journal files non-portable, because suddently we might completely refuse
to print entries which are totally OK on a different machine.

5 years agobasic/random-util: do not use getrandom() under msan
Evgeny Vereshchagin [Sun, 20 May 2018 13:07:07 +0000 (15:07 +0200)]
basic/random-util: do not use getrandom() under msan

`fuzz-journal-remote` seems to be failing under `msan` as soon as it starts:

$ sudo infra/helper.py run_fuzzer systemd fuzz-journal-remote
Running: docker run --rm -i --privileged -e FUZZING_ENGINE=libfuzzer -v /home/vagrant/oss-fuzz/build/out/systemd:/out -t gcr.io/oss-fuzz-base/base-runner run_fuzzer fuzz-journal-remote
Using seed corpus: fuzz-journal-remote_seed_corpus.zip
/out/fuzz-journal-remote -rss_limit_mb=2048 -timeout=25 /tmp/fuzz-journal-remote_corpus -max_len=65536 < /dev/null
INFO: Seed: 3380449479
INFO: Loaded 2 modules   (36336 inline 8-bit counters): 36139 [0x7ff36ea31d39, 0x7ff36ea3aa64), 197 [0x9998c8, 0x99998d),
INFO: Loaded 2 PC tables (36336 PCs): 36139 [0x7ff36ea3aa68,0x7ff36eac7d18), 197 [0x999990,0x99a5e0),
INFO:        2 files found in /tmp/fuzz-journal-remote_corpus
INFO: seed corpus: files: 2 min: 4657b max: 7790b total: 12447b rss: 97Mb
Uninitialized bytes in __interceptor_pwrite64 at offset 24 inside [0x7fffdd4d7230, 240)
==15==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x7ff36e685e8a in journal_file_init_header /work/build/../../src/systemd/src/journal/journal-file.c:436:13
    #1 0x7ff36e683a9d in journal_file_open /work/build/../../src/systemd/src/journal/journal-file.c:3333:21
    #2 0x7ff36e68b8f6 in journal_file_open_reliably /work/build/../../src/systemd/src/journal/journal-file.c:3520:13
    #3 0x4a3f35 in open_output /work/build/../../src/systemd/src/journal-remote/journal-remote.c:70:13
    #4 0x4a34d0 in journal_remote_get_writer /work/build/../../src/systemd/src/journal-remote/journal-remote.c:136:21
    #5 0x4a550f in get_source_for_fd /work/build/../../src/systemd/src/journal-remote/journal-remote.c:183:13
    #6 0x4a46bd in journal_remote_add_source /work/build/../../src/systemd/src/journal-remote/journal-remote.c:235:13
    #7 0x4a271c in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-journal-remote.c:36:9
    #8 0x4f27cc in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/libfuzzer/FuzzerLoop.cpp:524:13
    #9 0x4efa0b in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) /src/libfuzzer/FuzzerLoop.cpp:448:3
    #10 0x4f8e96 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) /src/libfuzzer/FuzzerLoop.cpp:732:7
    #11 0x4f9f73 in fuzzer::Fuzzer::Loop(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) /src/libfuzzer/FuzzerLoop.cpp:752:3
    #12 0x4bf329 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/libfuzzer/FuzzerDriver.cpp:756:6
    #13 0x4ac391 in main /src/libfuzzer/FuzzerMain.cpp:20:10
    #14 0x7ff36d14982f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
    #15 0x41f9d8 in _start (/out/fuzz-journal-remote+0x41f9d8)

  Uninitialized value was stored to memory at
    #0 0x7ff36e61cd41 in sd_id128_randomize /work/build/../../src/systemd/src/libsystemd/sd-id128/sd-id128.c:288:16
    #1 0x7ff36e685cec in journal_file_init_header /work/build/../../src/systemd/src/journal/journal-file.c:426:13
    #2 0x7ff36e683a9d in journal_file_open /work/build/../../src/systemd/src/journal/journal-file.c:3333:21
    #3 0x7ff36e68b8f6 in journal_file_open_reliably /work/build/../../src/systemd/src/journal/journal-file.c:3520:13
    #4 0x4a3f35 in open_output /work/build/../../src/systemd/src/journal-remote/journal-remote.c:70:13
    #5 0x4a34d0 in journal_remote_get_writer /work/build/../../src/systemd/src/journal-remote/journal-remote.c:136:21
    #6 0x4a550f in get_source_for_fd /work/build/../../src/systemd/src/journal-remote/journal-remote.c:183:13
    #7 0x4a46bd in journal_remote_add_source /work/build/../../src/systemd/src/journal-remote/journal-remote.c:235:13
    #8 0x4a271c in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-journal-remote.c:36:9
    #9 0x4f27cc in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/libfuzzer/FuzzerLoop.cpp:524:13
    #10 0x4efa0b in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool*) /src/libfuzzer/FuzzerLoop.cpp:448:3
    #11 0x4f8e96 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) /src/libfuzzer/FuzzerLoop.cpp:732:7
    #12 0x4f9f73 in fuzzer::Fuzzer::Loop(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, fuzzer::fuzzer_allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) /src/libfuzzer/FuzzerLoop.cpp:752:3
    #13 0x4bf329 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/libfuzzer/FuzzerDriver.cpp:756:6
    #14 0x4ac391 in main /src/libfuzzer/FuzzerMain.cpp:20:10
    #15 0x7ff36d14982f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

  Uninitialized value was created by an allocation of 't' in the stack frame of function 'sd_id128_randomize'
    #0 0x7ff36e61cb00 in sd_id128_randomize /work/build/../../src/systemd/src/libsystemd/sd-id128/sd-id128.c:274

SUMMARY: MemorySanitizer: use-of-uninitialized-value /work/build/../../src/systemd/src/journal/journal-file.c:436:13 in journal_file_init_header
Exiting
MS: 0 ; base unit: 0000000000000000000000000000000000000000
artifact_prefix='./'; Test unit written to ./crash-847911777b3096783f4ee70a69ab6d28380c810b
[vagrant@localhost oss-fuzz]$ sudo infra/helper.py check_build --sanitizer=memory systemd
Running: docker run --rm -i --privileged -e FUZZING_ENGINE=libfuzzer -e SANITIZER=memory -v /home/vagrant/oss-fuzz/build/out/systemd:/out -t gcr.io/oss-fuzz-base/base-runner test_all
INFO: performing bad build checks for /out/fuzz-dhcp-server.
INFO: performing bad build checks for /out/fuzz-journal-remote.
INFO: performing bad build checks for /out/fuzz-unit-file.
INFO: performing bad build checks for /out/fuzz-dns-packet.
4 fuzzers total, 0 seem to be broken (0%).
Check build passed.

It's a false positive which is most likely caused by
https://github.com/google/sanitizers/issues/852. I think it could be got around
by avoiding `getrandom` when the code is compiled with `msan`

5 years agobasic/journal-importer: escape & ellipsize bad data in log entries
Zbigniew Jędrzejewski-Szmek [Thu, 17 May 2018 09:09:07 +0000 (11:09 +0200)]
basic/journal-importer: escape & ellipsize bad data in log entries

We shouldn't just log arbitrary stuff, in particular newlines and control chars
Now:
Unknown dunder line __CURSORFACILITY=6\nSYSLOG_IDENTIFIER=/USR/SBIN/CRON\nMES…, ignoring.
Unknown dunder line __REALTIME_TIME[TAMP=1404101101501874\n__MONOTONIC_TIMEST…, ignoring.

5 years agobasic/string-util: add a convenience function to cescape mostly-ascii fields
Zbigniew Jędrzejewski-Szmek [Thu, 17 May 2018 08:55:21 +0000 (10:55 +0200)]
basic/string-util: add a convenience function to cescape mostly-ascii fields

It's not supposed to be the most efficient, but instead fast and simple to use.

I kept the logic in ellipsize_mem() to use unicode ellipsis even in non-unicode
locales. I'm not quite convinced things should be this way, especially that with
this patch it'd actually be simpler to always use "…" in unicode locale and "..."
otherwise, but Lennart wanted it this way for some reason.

5 years agobasic/journal-importer: do not write non-unicode char to log
Zbigniew Jędrzejewski-Szmek [Thu, 17 May 2018 08:04:24 +0000 (10:04 +0200)]
basic/journal-importer: do not write non-unicode char to log

The type of cescape_char() is changed to int to make it easier to use
in "%.*s". We know the value is between 1 and 4, so size_t is overkill.

5 years agofuzz-journal-remote: a fuzzer for journal-remote over-the-wire input
Zbigniew Jędrzejewski-Szmek [Wed, 16 May 2018 10:05:07 +0000 (12:05 +0200)]
fuzz-journal-remote: a fuzzer for journal-remote over-the-wire input

5 years agosd-id128: return -ENOMEDIUM on null id
Zbigniew Jędrzejewski-Szmek [Wed, 16 May 2018 11:55:12 +0000 (13:55 +0200)]
sd-id128: return -ENOMEDIUM on null id

We currently return -ENOMEDIUM when /etc/machine-id is empty, and -EINVAL when
it is all zeros. But -EINVAL is also used for invalid args. The distinction
between empty and all-zero is not very important, let's use the same return
code.

Also document -ENOENT and -ENOMEDIUM since they can be a bit surprising.

5 years agojournal-remote: split out µhttpd support and main() into a separate file
Zbigniew Jędrzejewski-Szmek [Wed, 16 May 2018 08:21:58 +0000 (10:21 +0200)]
journal-remote: split out µhttpd support and main() into a separate file

This is in preparation to reusing the RemoteServer in other concepts.
I tried to keep changes to minimum:
- arg_* global variables are now passed as state in RemoteServer
- exported functions get the "journal_remote_" prefix
- some variables are renamed

In particular, there is an ugly global RemoveServer* variable. It was originally
added because µhttpd did not allow state to be passed to the callbacks. I'm not
sure if this has been remediated in µhttpd, but either way, this is not changed
here, the global variable is only renamed for clarity.

5 years agodoc: update TODO
Yu Watanabe [Thu, 31 May 2018 08:39:13 +0000 (17:39 +0900)]
doc: update TODO

5 years agotree-wide: make use of memory_startswith() at various places
Lennart Poettering [Wed, 30 May 2018 11:09:03 +0000 (13:09 +0200)]
tree-wide: make use of memory_startswith() at various places

5 years agostring-util: add new memory_startswith() helper
Lennart Poettering [Wed, 30 May 2018 11:07:37 +0000 (13:07 +0200)]
string-util: add new memory_startswith() helper

We have code like this at various placer, let's make things shorter and
more readable with a helper for it.

5 years agosocket-util: rename parse_socket_address_bind_ipv6_only_or_bool() to socket_address_b...
Yu Watanabe [Tue, 29 May 2018 03:40:28 +0000 (12:40 +0900)]
socket-util: rename parse_socket_address_bind_ipv6_only_or_bool() to socket_address_bind_ipv6_only_or_bool_from_string()

Hence, we can define config_parse_socket_bind() by using
DEFINE_CONFIG_PARSE_ENUM() macro.

5 years agoconf-parser: introduce DEFINE_CONFIG_PARSE*() macros
Yu Watanabe [Sat, 26 May 2018 16:39:12 +0000 (01:39 +0900)]
conf-parser: introduce DEFINE_CONFIG_PARSE*() macros

This introduces several macros for defining config parsers.
Also this fixes errno in DEFINE_CONFIG_PARSE_ENUM() and _ENUMV()
and makes the log level lower when a duplicated item is
specified to the settings parsed by the function defined by
DEFINE_CONFIG_PARSE_ENUMV().

5 years agosmack: make mac_smack_fix() deal somewhat sensible with non-absolute paths
Lennart Poettering [Wed, 30 May 2018 16:21:58 +0000 (18:21 +0200)]
smack: make mac_smack_fix() deal somewhat sensible with non-absolute paths

This tries to improve the mac_smack_fix() logic a bit, by properly
handling non-absolute paths.

It's still pretty broken though, which is sad for security technology:
non-normalized paths (for example "/usr/../dev/sda") will still not be
treated correctly. I am not sure how to fix that properly though, and I
don't understand SMACK well enough to do so. This fix hence just fixes
to most obvious glaring issue.

5 years agosd-bus: make add match method callback slot "floating"
Lennart Poettering [Wed, 30 May 2018 14:35:36 +0000 (16:35 +0200)]
sd-bus: make add match method callback slot "floating"

When we allocate an asynchronous match object we will allocate an
asynchronous bus call object to install the match server side.
Previously the call slot would be created as regular slot, i.e.
non-floating which meant installing the match even if it was itself
floating would result in a non-floating slot to be created internally,
which ultimately would mean the sd_bus object would be referenced by it,
and thus never be freed.

Let's fix that by making the match method callback floating in any case
as we have no interest in leaving the bus allocated beyond the match
slot.

Fixes: #8551
5 years agobus-slot: for bus slot objects with no explicit description use the match string...
Lennart Poettering [Wed, 30 May 2018 14:34:06 +0000 (16:34 +0200)]
bus-slot: for bus slot objects with no explicit description use the match string as description

Let's make debugging a but easier with implicit descriptions for some
match objects.

5 years agoman: document the new sd_bus_slot_set_floating() call
Lennart Poettering [Wed, 30 May 2018 14:33:12 +0000 (16:33 +0200)]
man: document the new sd_bus_slot_set_floating() call

Also extend the memory management description of sd-bus highlighting the
effect of "floating" slot objects a bit.

5 years agosd-bus: add new sd_bus_slot_set_floating() call
Lennart Poettering [Wed, 30 May 2018 14:29:33 +0000 (16:29 +0200)]
sd-bus: add new sd_bus_slot_set_floating() call

This new call allows explicit control of the "floating" state of a bus
slot object. This is useful for creating a bus slot object first,
retaining a reference to it, using it for making changes to the slot
object (for example, set a description) and then handing it over to
sd-bus for lifecycle management.

It's also useful to fix #8551.

5 years agoman: fix minor typo
Lennart Poettering [Wed, 30 May 2018 14:28:28 +0000 (16:28 +0200)]
man: fix minor typo

5 years agotree-wide: fix typo in comments and NEWS
Yu Watanabe [Tue, 29 May 2018 16:07:37 +0000 (01:07 +0900)]
tree-wide: fix typo in comments and NEWS

5 years agoconf-parser: add a bit more whitespace
Lennart Poettering [Mon, 28 May 2018 19:47:43 +0000 (21:47 +0200)]
conf-parser: add a bit more whitespace

We usually seperate case statements within a switch from each other by
empty lines. We also often add an empty line after multi-line function
prototypes, let's do so here too

Also, no trailing ; after }...

5 years agoupdate TODO
Lennart Poettering [Tue, 29 May 2018 09:40:49 +0000 (11:40 +0200)]
update TODO

5 years agodoc: mention RestrictNamespaces= merges multiple assignment now
Yu Watanabe [Tue, 29 May 2018 06:11:35 +0000 (15:11 +0900)]
doc: mention RestrictNamespaces= merges multiple assignment now

Follow-up for #8817.

5 years agomeson: use a convenience static library for nspawn core
Zbigniew Jędrzejewski-Szmek [Mon, 28 May 2018 08:37:11 +0000 (10:37 +0200)]
meson: use a convenience static library for nspawn core

This makes it easier to link the nspawn implementation to the tests.
Right now this just means that nspawn-patch-uid.c is not compiled
twice, which is nice, but results in test-patch-uid being slightly bigger,
which is not nice. But in general, we should use convenience libs to
compile everything just once, as far as possible. Otherwise, once we
start compiling a few files here twice, and a few file there thrice, we
soon end up in a state where we are doing hundreds of extra compilations.
So let's do the "right" thing, even if is might not be more efficient.

5 years agomeson: test out headers with more standard versions
Zbigniew Jędrzejewski-Szmek [Mon, 28 May 2018 07:07:36 +0000 (09:07 +0200)]
meson: test out headers with more standard versions

They all pass fine, but let's keep testing regularly.

5 years agobash-completion: add completion for portablectl
Yu Watanabe [Mon, 28 May 2018 06:38:19 +0000 (15:38 +0900)]
bash-completion: add completion for portablectl

5 years agocore: add --dump-bus-properties option to systemd
Yu Watanabe [Mon, 28 May 2018 09:13:19 +0000 (18:13 +0900)]
core: add --dump-bus-properties option to systemd

If systemd is invoked with this option, this dumps all bus properties.
This may be useful for shell completion for `systemctl --property`.

5 years agosd-bus: use _cleanup_ more
Zbigniew Jędrzejewski-Szmek [Sat, 26 May 2018 14:56:01 +0000 (16:56 +0200)]
sd-bus: use _cleanup_ more

5 years agojournalctl: add with-unit mode
Luca Boccassi [Tue, 22 May 2018 11:22:00 +0000 (12:22 +0100)]
journalctl: add with-unit mode

When dealing with a large number of template instances, for example
when launching daemons per VRF, it is hard for operators to correlate
log lines to arguments.
Add a new with-unit mode which, if available, prefixes unit and user
unit names when displaying its log messages instead of the syslog
identifier. It will also use the full timestamp with timezones, like
the short-full mode.

5 years agotree-wide: drop unused variables
Yu Watanabe [Fri, 25 May 2018 09:09:01 +0000 (18:09 +0900)]
tree-wide: drop unused variables

Follow-ups for #8620.

5 years agoupdate TODO
Lennart Poettering [Mon, 16 Apr 2018 10:37:25 +0000 (12:37 +0200)]
update TODO

5 years agoman: add man pages for the portable service stuff
Lennart Poettering [Tue, 17 Apr 2018 15:40:34 +0000 (17:40 +0200)]
man: add man pages for the portable service stuff

5 years agoadd new portable service framework
Lennart Poettering [Mon, 16 Apr 2018 19:41:40 +0000 (21:41 +0200)]
add new portable service framework

This adds a small service "systemd-portabled" and a matching client
"portablectl", which implement the "portable service" concept.

The daemon implements the actual operations, is PolicyKit-enabled and is
activated on demand with exit-on-idle.

Both the daemon and the client are an optional build artifact, enabled
by default rhough.

5 years agomachined: move bus_reply_pair_array() into generic utilities
Lennart Poettering [Mon, 9 Apr 2018 17:44:21 +0000 (19:44 +0200)]
machined: move bus_reply_pair_array() into generic utilities

This way, we can reuse it in portabled.

5 years agoconf-files: beef up conf-files.[ch] a bit
Lennart Poettering [Mon, 16 Apr 2018 19:24:13 +0000 (21:24 +0200)]
conf-files: beef up conf-files.[ch] a bit

This adds fozr new flags:

- If CONF_FILES_DIRECTORY is specified conf_file_list() and friends
  will look for directories only.

- Similar CONF_FILES_REGULAR means we'll look only for regular files.

- If CONF_FILES_BASENAME is specified the resulting list will contain
  only the basenames of all discovered files or directories, not the
  full paths.

- If CONF_FILES_FILTER_MASKED is specified the resulting list will have
  masked entries removed (i.e. those symlinked to /dev/null and
  suchlike)

These four flags are useful for discovering portable service profile
information.

While we are at it, also improve a couple of other things:

- More debug logging

- use path_hash_ops instead of string_hash_ops when putting together the
  path lists

5 years agofileio: make sure read_full_stream() works on memory-backed streams
Lennart Poettering [Tue, 17 Apr 2018 09:07:56 +0000 (11:07 +0200)]
fileio: make sure read_full_stream() works on memory-backed streams

5 years agoos-util: add helpers for finding /etc/os-release
Lennart Poettering [Mon, 26 Mar 2018 14:32:40 +0000 (16:32 +0200)]
os-util: add helpers for finding /etc/os-release

Place this new helpers in a new source file os-util.[ch], and move the
existing and related call path_is_os_tree() to it as well.

5 years agofileio: add parse_env_filev() that is like parse_env_file() but takes a va_list
Lennart Poettering [Mon, 26 Mar 2018 17:20:47 +0000 (19:20 +0200)]
fileio: add parse_env_filev() that is like parse_env_file() but takes a va_list

5 years agofileio: accept FILE* in addition to path in parse_env_file()
Lennart Poettering [Fri, 23 Mar 2018 20:31:14 +0000 (21:31 +0100)]
fileio: accept FILE* in addition to path in parse_env_file()

Most our other parsing functions do this, let's do this here too,
internally we accept that anyway. Also, the closely related
load_env_file() and load_env_file_pairs() also do this, so let's be
systematic.

5 years agoprocess-util: add a new FORK_MOUNTNS_SLAVE flag for safe_fork()
Lennart Poettering [Fri, 23 Mar 2018 19:52:46 +0000 (20:52 +0100)]
process-util: add a new FORK_MOUNTNS_SLAVE flag for safe_fork()

We already have a flag for creating a new mount namespace for the child.
Let's add an extension to that: a new FORK_MOUNTNFS_SLAVE flag. When
used in combination will mark all mounts in the child namespace as
MS_SLAVE so that the child can freely mount or unmount stuff but it
won't leak into the parent.

5 years agofd-util: add new helper call fd_duplicate_data_fd()
Lennart Poettering [Fri, 9 Mar 2018 21:45:08 +0000 (22:45 +0100)]
fd-util: add new helper call fd_duplicate_data_fd()

This call creates an fd from another fd containing the same data.
Specifically, repeated read() on the returned fd should return the same
data as the original fd. This call is useful when we want to copy data
out of disk images and suchlike, and want to be pass fds with the data
around without having to keep the disk image continously mounted.

The implementation tries to be somewhat smart and tries to prefer
memfds/pipes over files in /tmp or /var/tmp based on the size of the
data, but has appropropriate fallbacks in place.

5 years agobasic: fix raw_clone() on 32-bit sparc
Mike Gilbert [Thu, 24 May 2018 14:48:55 +0000 (10:48 -0400)]
basic: fix raw_clone() on 32-bit sparc

The clone syscall uses the same semantics as on 64-bit. The trap number
for syscall entry is different.

Bug: https://bugs.gentoo.org/656368

5 years agoload-fragment: allow to specify RestrictNamespaces= multiple times
Yu Watanabe [Tue, 1 May 2018 01:36:39 +0000 (10:36 +0900)]
load-fragment: allow to specify RestrictNamespaces= multiple times

If multiple RestrictNamespaces= settings are set, then merge the settings.
This also drops supporting "~yes" and "~no".

5 years agonsflsgs: drop namespace_flag_{from,to}_string()
Yu Watanabe [Tue, 1 May 2018 01:48:21 +0000 (10:48 +0900)]
nsflsgs: drop namespace_flag_{from,to}_string()

This also drops namespace_flag_to_string_many_with_check(), and
renames namespace_flag_{from,to}_string_many() to
namespace_flags_{from,to}_string().

5 years agonsflags: drop namespace_flag_to_string_many_with_check()
Yu Watanabe [Tue, 1 May 2018 01:44:19 +0000 (10:44 +0900)]
nsflags: drop namespace_flag_to_string_many_with_check()

We always ignore the unused bits. So, it is not necessary to check
them.

5 years agologind: let's change the type of the runtime directory size to uint64_t
Lennart Poettering [Thu, 17 May 2018 02:33:13 +0000 (22:33 -0400)]
logind: let's change the type of the runtime directory size to uint64_t

Externally it's an uint64_t anyway, and internally we most just
initialize it to physical_memory() which returns uint64_t, hence there's
exactly zero value in using it as size_t internally. Hence, let's fix
that, and use uint64_t everywhere.

5 years agoutil: add debug logging to system_tasks_max()
Lennart Poettering [Thu, 17 May 2018 02:32:15 +0000 (22:32 -0400)]
util: add debug logging to system_tasks_max()

We should always do debug logging when we eat up error conditions. Let's
do so here too.

5 years agoutil: fix physical_memory() to work correctly on cgroupsv2
Lennart Poettering [Thu, 17 May 2018 02:27:58 +0000 (22:27 -0400)]
util: fix physical_memory() to work correctly on cgroupsv2

Let's look into the right cgroupsv2 attribute.

Also, while we are at it, add debug logging for all error conditions we
eat up silently otherwise.

5 years agoupdate TODO
Lennart Poettering [Mon, 7 May 2018 15:50:31 +0000 (17:50 +0200)]
update TODO

5 years agonspawn: make sure our container PID 1 keeps logging to the original stderr as long...
Lennart Poettering [Tue, 22 May 2018 14:52:50 +0000 (16:52 +0200)]
nspawn: make sure our container PID 1 keeps logging to the original stderr as long as possible

If we log to the pty that is configured as stdin/stdout/stderr of the
container too early we risk filling it up in full before we start
processing the pty from the parent process, resulting in deadlocks.
Let's hence keep a copy of the original tty we were started on before
setting up stdin/stdout/stderr, so that we can log to it, and keep using
it as long as we can.

Since the kernel's pty internal buffer is pretty small this actually
triggered deadlocks when we debug logged at lot from nspawn's child
processes, see: https://github.com/systemd/systemd/pull/9024#issuecomment-390403674

With this change we won't use the pty at all, only the actual payload we
start will, and hence we won't deadlock on it, ever.

5 years agodoc: mention in NEWS that AF_INET{,6} are dropped from logind
Yu Watanabe [Thu, 24 May 2018 04:18:28 +0000 (13:18 +0900)]
doc: mention in NEWS that AF_INET{,6} are dropped from logind

Closes #9072.

5 years agotimesync,shared: move logic requesting bus name to shared
Yu Watanabe [Sat, 19 May 2018 16:55:39 +0000 (01:55 +0900)]
timesync,shared: move logic requesting bus name to shared

Preparation for setting DynamicUser= to other services which
request bus names.

5 years agocore: support unit specifiers in IODeviceWeight= and friends
Yu Watanabe [Sat, 19 May 2018 14:59:02 +0000 (23:59 +0900)]
core: support unit specifiers in IODeviceWeight= and friends

5 years agotree-wide: remove some double newlines in headers, too
Lennart Poettering [Tue, 22 May 2018 14:08:26 +0000 (16:08 +0200)]
tree-wide: remove some double newlines in headers, too

5 years agofind-double-newline: look in headers too
Lennart Poettering [Tue, 22 May 2018 14:07:18 +0000 (16:07 +0200)]
find-double-newline: look in headers too

5 years agoconf-parser: make use of free_and_replace() at one more place
Lennart Poettering [Tue, 22 May 2018 11:12:48 +0000 (13:12 +0200)]
conf-parser: make use of free_and_replace() at one more place

5 years agotree-wide: port over all code to the new CONFIG_PARSER_PROTOTYPE() macro
Lennart Poettering [Tue, 22 May 2018 11:10:17 +0000 (13:10 +0200)]
tree-wide: port over all code to the new CONFIG_PARSER_PROTOTYPE() macro

This makes most header files easier to look at. Also Emacs gets really
slow when browsing through large sections of overly long prototypes,
which is much improved by this macro.

We should probably not do something similar with too many other cases,
as macros like this might help readability for some, but make it worse
for others. But I think given the complexity of this specific prototype
and how often we use it, it's worth doing.

5 years agoconfig-parser: introduce new CONFIG_PARSER_PROTOTYPE() macro
Lennart Poettering [Tue, 22 May 2018 11:03:19 +0000 (13:03 +0200)]
config-parser: introduce new CONFIG_PARSER_PROTOTYPE() macro

This builds on the previous GENERIC_PARSER_ARGS macro work. I think in
general it is a better idea to declare macros that generate full C
statements instead of just parts of them, hence, let's introduce
CONFIG_PARSER_PROTOTYPE() which defines a full C function prototype,
instead of the pre-existing way of defining the C function prototype
manually, but then using GENERIC_PARSER_ARGS to define its arguments.

This doesn't drop GENERIC_PARSER_ARGS though, but renames it to
CONFIG_PARSER_ARGUMENTS, and changes the ConfigParserCallback function
type to use it. The new name follows more closely how the other symbols
in the header are named.

5 years agobasic/rm-rf: include the path in error messages
Zbigniew Jędrzejewski-Szmek [Tue, 22 May 2018 09:33:01 +0000 (11:33 +0200)]
basic/rm-rf: include the path in error messages

Attempted to remove disk file system under "/tmp/systemd-temporary-aWPkbQ", and we can't allow that.

5 years agotree-wide: port various bits of the tree over to the new DUMP_STRING_TABLE() macro
Lennart Poettering [Tue, 22 May 2018 10:10:56 +0000 (12:10 +0200)]
tree-wide: port various bits of the tree over to the new DUMP_STRING_TABLE() macro

5 years agostring-table: add new DUMP_STRING_TABLE() macro
Lennart Poettering [Tue, 22 May 2018 10:06:54 +0000 (12:06 +0200)]
string-table: add new DUMP_STRING_TABLE() macro

The macro is inspired by the other string table macros, and takes the
same arguments in the same order and dumps a string table to stdout.
Since it's typesafe it's nice to implement this as macro rather than
regular function.

This new macro is useful for implementing commands such as "systemctl -t
help" and similar, i.e. wherever we want to dump all values of an enum
to stdout.

5 years agotest-sizeof: show that a small 64 field is not enough to force the enum to be 64...
Zbigniew Jędrzejewski-Szmek [Tue, 22 May 2018 07:07:35 +0000 (09:07 +0200)]
test-sizeof: show that a small 64 field is not enough to force the enum to be 64 bits

On both 32 and 64 bits, the result is:
enum Enum → 32 bits, unsigned
enum BigEnum → 32 bits, unsigned
enum BigEnum2 → 64 bits, unsigned
big_enum2_pos → 4
big_enum2_neg → 8

The last two lines show that even if the enum is 64 bit, and the field of an
enum is defined with UINT64_C(), the field can still be smaller.