chiark / gitweb /
elogind.git
6 years agosd-bus: explicitly convert int to bool
Yu Watanabe [Fri, 9 Feb 2018 07:19:11 +0000 (16:19 +0900)]
sd-bus: explicitly convert int to bool

6 years agosd-bus: use free_and_replace()
Yu Watanabe [Fri, 9 Feb 2018 07:21:51 +0000 (16:21 +0900)]
sd-bus: use free_and_replace()

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

6 years agotmpfiles: allow admin/runtime overrides to runtime config
Zbigniew Jędrzejewski-Szmek [Mon, 5 Feb 2018 13:53:11 +0000 (14:53 +0100)]
tmpfiles: allow admin/runtime overrides to runtime config

This is very similar to d16a1c1bb6. For tmpfiles this is much less useful
compared to sysusers, but let's add this anyway for consistency.

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
6 years agocore/execute: make arguments constant if possible
Yu Watanabe [Tue, 6 Feb 2018 03:17:50 +0000 (12:17 +0900)]
core/execute: make arguments constant if possible

Also make functions static if possible.

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>.

6 years agosysusers: allow admin/runtime overrides to command-line config
Zbigniew Jędrzejewski-Szmek [Wed, 31 Jan 2018 14:37:02 +0000 (15:37 +0100)]
sysusers: allow admin/runtime overrides to command-line config

When used in a package installation script, we want to invoke systemd-sysusers
before that package is installed (so it can contain files owned by the newly
created user), so the configuration to use is specified on the command
line. This should be a copy of the configuration that will be installed as
/usr/lib/sysusers.d/package.conf. We still want to obey any overrides in
/etc/sysusers.d or /run/sysusers.d in the usual fashion. Otherwise, we'd get a
different result when systemd-sysusers is run with a copy of the new config on
the command line and when systemd-sysusers is run at boot after package
instalation. In the second case any files in /etc or /run have higher priority,
so the same should happen when the configuration is given on the command line.
More generally, we want the behaviour in this special case to be as close to
the case where the file is finally on disk as possible, so we have to read all
configuration files, since they all might contain overrides and additional
configuration that matters. Even files that have lower priority might specify
additional groups for the user we are creating. Thus, we need to read all
configuration, but insert our new configuration somewhere with the right
priority.

If --target=/path/to/file.conf is given on the command line, we gather the list
of files, and pretend that the command-line config is read from
/path/to/file.conf (doesn't matter if the file on disk actually exists or
not). All package scripts should use this option to obtain consistent and
idempotent behaviour.

The corner case when --target= is specified and there are no positional
arguments is disallowed.

v1:
- version with --config-name=
v2:
- disallow --config-name= and no positional args
v3:
- remove --config-name=
v4:
- add --target= and rework the code completely
v5:
- fix argcounting bug and add example in man page
v6:
- rename --target to --replace

6 years agobasic/strv: add function to insert items at position
Zbigniew Jędrzejewski-Szmek [Thu, 1 Feb 2018 11:50:18 +0000 (12:50 +0100)]
basic/strv: add function to insert items at position

6 years agosysusers: allow the shell to be specified
Zbigniew Jędrzejewski-Szmek [Tue, 30 Jan 2018 13:28:10 +0000 (14:28 +0100)]
sysusers: allow the shell to be specified

This is necessary for some system users where the "login shell" is
set to a specific binary.

6 years agosysusers: emit a bit more info at debug level when locking fails
Zbigniew Jędrzejewski-Szmek [Mon, 29 Jan 2018 13:23:31 +0000 (14:23 +0100)]
sysusers: emit a bit more info at debug level when locking fails

This is the first error message when running unprivileged, and the message is
unspecific, so let's at least add some logging at debug level to make this less
confusing.

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)

6 years agobasic/hashmap: tweak code to avoid pointless gcc warning
Zbigniew Jędrzejewski-Szmek [Fri, 2 Feb 2018 13:34:00 +0000 (14:34 +0100)]
basic/hashmap: tweak code to avoid pointless gcc warning

gcc says:
[196/1142] Compiling C object 'src/basic/basic@sta/hashmap.c.o'.
../src/basic/hashmap.c: In function ‘cachemem_maintain’:
../src/basic/hashmap.c:1913:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
                 mem->active = r = true;
                 ^~~

which conflates two things: the first is transitive assignent a = b = c = d;
the second is assignment of the value of an expression, which happens to be a
an assignment expression here, and boolean. While the second _should_ be
parenthesized, the first should _not_, and it's more natural to understand
our code as the first, and gcc should treat this as an exception and not emit
the warning. But since it's a while until this will be fixed, let's update
our code too.

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

6 years agotest-hashmap: test IteratedCache
Vito Caputo [Sat, 27 Jan 2018 21:10:39 +0000 (13:10 -0800)]
test-hashmap: test IteratedCache

Add some rudimentary testing of the new IteratedCache

6 years agobasic: implement the IteratedCache
Vito Caputo [Sat, 27 Jan 2018 00:38:01 +0000 (16:38 -0800)]
basic: implement the IteratedCache

Adds the basics of the IteratedCache and constructor support for the
Hashmap and OrderedHashmap types.

iterated_cache_get() is responsible for synchronizing the cache with
the associated Hashmap and making it available to the caller at the
supplied result pointers.  Since iterated_cache_get() may need to
allocate memory, it may fail, so callers must check the return value.

On success, pointer arrays containing pointers to the associated
Hashmap's keys and values, in as-iterated order, are returned in
res_keys and res_values, respectively.  Either may be supplied as NULL
to inhibit caching of the keys or values, respectively.

Note that if the cached Hashmap hasn't changed since the previous call
to iterated_cache_get(), and it's not a call activating caching of the
values or keys, the cost is effectively zero as the resulting pointers
will simply refer to the previously returned arrays as-is.

A cleanup function has also been added, iterated_cache_free().

This only frees the IteratedCache container and related arrays.  The
associated Hashmap, its keys, and values are not affected.  Also note
that the associated Hashmap does not automatically free its associated
IteratedCache when freed.

One could, in theory, safely access the arrays returned by a
successful iterated_cache_get() call after its associated Hashmap has
been freed, including the referenced values and keys.  Provided the
iterated_cache_get() was performed prior to the hashmap free, and that
the type of hashmap free performed didn't free keys and/or values as
well.

6 years agobasic: track dirty state in HashmapBase
Vito Caputo [Sun, 8 Oct 2017 23:28:04 +0000 (16:28 -0700)]
basic: track dirty state in HashmapBase

This only adds marking the HashmapBase as dirty, no clearing of
the dirty state happens yet.

No functional changes.

6 years agoupdate TODO
Lennart Poettering [Wed, 31 Jan 2018 18:53:16 +0000 (19:53 +0100)]
update TODO

6 years agostrv: drop strv_join_quoted() (#8057)
Yu Watanabe [Thu, 1 Feb 2018 09:11:02 +0000 (18:11 +0900)]
strv: drop strv_join_quoted() (#8057)

The function `strv_join_quoted()` is now not used, and has a bug
in the buffer size calculation when the strings needs to escaped,
as reported in #8056.
So, let's remove the function.

Closes #8056.

6 years agoSave last mutual commit for migration of the v237-stable branch.
Sven Eden [Wed, 30 May 2018 05:54:20 +0000 (07:54 +0200)]
Save last mutual commit for migration of the v237-stable branch.

6 years agomissing_syscall: when adding syscall replacements, use different names (#8229)
Zbigniew Jędrzejewski-Szmek [Wed, 21 Feb 2018 13:04:50 +0000 (14:04 +0100)]
missing_syscall: when adding syscall replacements, use different names (#8229)

In meson.build we check that functions are available using:
    meson.get_compiler('c').has_function('foo')
which checks the following:
- if __stub_foo or __stub___foo are defined, return false
- if foo is declared (a pointer to the function can be taken), return true
- otherwise check for __builtin_memfd_create

_stub is documented by glibc as
   It defines a symbol '__stub_FUNCTION' for each function
   in the C library which is a stub, meaning it will fail
   every time called, usually setting errno to ENOSYS.

So if __stub is defined, we know we don't want to use the glibc version, but
this doesn't tell us if the name itself is defined or not. If it _is_ defined,
and we define our replacement as an inline static function, we get an error:

In file included from ../src/basic/missing.h:1358:0,
                 from ../src/basic/util.h:47,
                 from ../src/basic/calendarspec.h:29,
                 from ../src/basic/calendarspec.c:34:
../src/basic/missing_syscall.h:65:19: error: static declaration of 'memfd_create' follows non-static declaration
 static inline int memfd_create(const char *name, unsigned int flags) {
                   ^~~~~~~~~~~~
.../usr/include/bits/mman-shared.h:46:5: note: previous declaration of 'memfd_create' was here
 int memfd_create (const char *__name, unsigned int __flags) __THROW;
     ^~~~~~~~~~~~

To avoid this problem, call our inline functions different than glibc,
and use a #define to map the official name to our replacement.

Fixes #8099.

v2:
- use "missing_" as the prefix instead of "_"

v3:
- rebase and update for statx()

  Unfortunately "statx" is also present in "struct statx", so the define
  causes issues. Work around this by using a typedef.

I checked that systemd compiles with current glibc
(glibc-devel-2.26-24.fc27.x86_64) if HAVE_MEMFD_CREATE, HAVE_GETTID,
HAVE_PIVOT_ROOT, HAVE_SETNS, HAVE_RENAMEAT2, HAVE_KCMP, HAVE_KEYCTL,
HAVE_COPY_FILE_RANGE, HAVE_BPF, HAVE_STATX are forced to 0.

Setting HAVE_NAME_TO_HANDLE_AT to 0 causes an issue, but it's not because of
the define, but because of struct file_handle.

(cherry picked from commit 5187dd2c403caf92d09f3491e41f1ceb3f10491f)

6 years agotest-user-util: skip most tests for nobody if synthentization is off
Zbigniew Jędrzejewski-Szmek [Tue, 20 Feb 2018 16:13:41 +0000 (17:13 +0100)]
test-user-util: skip most tests for nobody if synthentization is off

When synthetisation is turned off, there's just too many ways those tests can
go wrong. We are not interested in verifying that the db on disk is correct,
let's just skip all checks.

In the first version of this patch, I recorded if we detected a mismatch during
configuration and only skipped tests in that case, but actually it is possible
to change the host configuration between our configuration phase and running
of the tests. It's just more robust to skip always. (This is particularly true
if tests are installed.)

(cherry picked from commit 7559b2da10b1513849f22312d09a2381569b4f06)

6 years agotest-user-util: print function delimiters
Zbigniew Jędrzejewski-Szmek [Tue, 20 Feb 2018 21:10:45 +0000 (22:10 +0100)]
test-user-util: print function delimiters

This makes it easier to see what is going on. Crashes may happen in a
nested test_{uid,gid}_to_name_one() function, and the default backtrace
doesn't show the actual string being tested.

(cherry picked from commit 52c6e6a8a0221530659c65090f18b16c45a9fc04)

6 years agomeson: apply defaults if /etc/login.defs doesn't exist
Caio Marcelo de Oliveira Filho [Mon, 19 Feb 2018 02:33:16 +0000 (18:33 -0800)]
meson: apply defaults if /etc/login.defs doesn't exist

Apply defaults for system_{uid,gid}_max even if the /etc/login.defs file
doesn't exist (e.g. in Clear Linux with no changes).

awk returns an empty string in case the file doesn't exist, causing meson to
fail in to_int(). So set the default if output is empty. This makes the BEGIN{}
blocks unnecessary, so remove them.

(cherry picked from commit 2f62cf3552d48f518313bd6265bad6763e2b643b)

6 years agomeson: use multiline string syntax (#8214)
Caio Marcelo de Oliveira Filho [Mon, 19 Feb 2018 09:37:19 +0000 (01:37 -0800)]
meson: use multiline string syntax (#8214)

The single quote working with multiple lines is likely to be unintended. With
current versions of meson, it also causes error messages after it to report the
wrong line number. Use the documented syntax instead.

(cherry picked from commit 9e70f2f81821efa4797d89c06d1f04c11e86015e)

6 years agofs-util: add new unlinkat_deallocate() helper
Lennart Poettering [Fri, 9 Feb 2018 08:50:31 +0000 (09:50 +0100)]
fs-util: add new unlinkat_deallocate() helper

This new helper not only removes a file from a directory but also
ensures its space on disk is deallocated, by either punching a hole over
the full file or truncating the file afterwards if the file's link
counter is 0. This is useful in "vacuuming" algorithms to ensure that
client's can't keep the disk space the vacuuming is supposed to recover
pinned simply by keeping an fd open to it.

(cherry picked from commit 43767d9d5e0ce8923828aebf9154da7af83916f7)

6 years agohash-func: add generic hash_ops implementation for hashing paths
Lennart Poettering [Thu, 8 Feb 2018 17:31:15 +0000 (18:31 +0100)]
hash-func: add generic hash_ops implementation for hashing paths

This is similar to string_hash_ops but operates one file system paths
specifically. It will ensure that "/foo//bar" and "///foo/bar" are
considered to be the same path for hashmap purposes.

This makes use of the existing path_compare() API, and adds a matching
hashing function for it.

Note that relative and absolute paths will hash to different values,
however whether the path is suffixed with a slash or not is not
detected. This matches the existing path_compare() behaviour, and
follows the logic that on Linux there can't be two different objects at
path /foo/bar and /foo/bar/ either.

(cherry picked from commit 46e16b347f83d809ed3d34f26286f580dfd086ce)

6 years agohash-funcs: remove redundant definition of devt_hash_ops
Lennart Poettering [Thu, 8 Feb 2018 16:37:56 +0000 (17:37 +0100)]
hash-funcs: remove redundant definition of devt_hash_ops

We should assign a value only in the .c file, not in both the .c and .h
file.

(cherry picked from commit 9bac7d423f1d39737e2b7bc35c484ed0d79de73d)

6 years agojournal: move code that checks for network fs to stat-util.[ch]
Lennart Poettering [Thu, 8 Feb 2018 16:14:37 +0000 (17:14 +0100)]
journal: move code that checks for network fs to stat-util.[ch]

We have similar code in stat-util.[ch] and managing this at a central
place almost definitely is the better choice.

(cherry picked from commit 77f9fa3b8ea46c27e5a5e9270f71bf1b4000c3e0)

6 years agosd-bus: cleanup ssh sessions (Closes: #8076)
Shawn Landden [Sat, 3 Feb 2018 18:16:33 +0000 (10:16 -0800)]
sd-bus: cleanup ssh sessions (Closes: #8076)

we still invoke ssh unnecessarily when there in incompatible or erreneous input
The fallow-up to finish that would make the code a bit more verbose,
as it would require repeating this bit:
```
        r = bus_connect_transport(arg_transport, arg_host, false, &bus);
        if (r < 0) {
                log_error_errno(r, "Failed to create bus connection: %m");
                goto finish;
        }

        sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
```
in every verb, after parsing.

v2: add waitpid() to avoid a zombie process, switch to SIGTERM from SIGKILL
v3: refactor, wait in bus_start_address()
(cherry picked from commit 392cf1d05dbfa1395f6d99102e5ea41debb58fec)

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.