chiark / gitweb /
elogind.git
6 years agotime-util: add overflow checking to monotonic timestamp specifications
Lennart Poettering [Thu, 2 Feb 2017 17:35:00 +0000 (18:35 +0100)]
time-util: add overflow checking to monotonic timestamp specifications

6 years agotime-util: when formatting usec_t as raw integers use PRIu64
Lennart Poettering [Thu, 2 Feb 2017 17:34:26 +0000 (18:34 +0100)]
time-util: when formatting usec_t as raw integers use PRIu64

After all, usec_t is defined as uint64_t, and not as unsigned long long.

6 years agotime-util: when converting to time_t do something useful in 2038
Lennart Poettering [Thu, 2 Feb 2017 17:33:36 +0000 (18:33 +0100)]
time-util: when converting to time_t do something useful in 2038

On systems where time_t is 32bit we should invalidate the
timeval/timespec instead of proceeding with a potentially overflown
value.

6 years agotime-util: refuse formatting/parsing times that we can't store
Lennart Poettering [Thu, 2 Feb 2017 17:30:29 +0000 (18:30 +0100)]
time-util: refuse formatting/parsing times that we can't store

usec_t is always 64bit, which means it can cover quite a number of
years. However, 4 digit year display and glibc limitations around time_t
limit what we can actually parse and format. Let's make this explicit,
so that we never end up formatting dates we can#t parse and vice versa.

Note that this is really just about formatting/parsing. Internal
calculations with times outside of the formattable range are not
affected.

6 years agotime: time_t is signed, and mktime() is happy to return negative time
Lennart Poettering [Thu, 2 Feb 2017 17:25:33 +0000 (18:25 +0100)]
time: time_t is signed, and mktime() is happy to return negative time

Passing a year such as 1960 to mktime() will result in a negative return
value. This is quite confusing, as the man page claims that on failure
the call will return -1...

Given that our own usec_t type is unsigned, and we can't express times
before 1970 hence, let's consider all negative times returned by
mktime() as invalid, regardless if just -1, or anything else negative.

6 years agoConsistently use ERFKILL for masked units
Zbigniew Jędrzejewski-Szmek [Wed, 1 Feb 2017 23:36:09 +0000 (18:36 -0500)]
Consistently use ERFKILL for masked units

76ec966f0e33685f833 changed the code from ESHUTDOWN to ERFKILL, but missed one
spot in bus-common-errors.c. Fix that.

The code in transaction.c was checking for ERFKILL, but I'm not sure if this
mismatch had any effect, i.e. if there were any code paths in which the wrong
code actually made difference.

Also add comments when ESHUTDOWN is used in the journal code, so it's easy to
distinguish those cases when grepping. Standarize on the same capitalization.

(There's also a bunch of uses in sd-bus.c, but that's clearly different.)

6 years agohexdecoct: use typesafe new() instead of malloc()
Lennart Poettering [Wed, 1 Feb 2017 23:10:44 +0000 (00:10 +0100)]
hexdecoct: use typesafe new() instead of malloc()

6 years agofs-util: unify code we use to check if dirent's d_name is "." or ".."
Lennart Poettering [Wed, 1 Feb 2017 23:06:18 +0000 (00:06 +0100)]
fs-util: unify code we use to check if dirent's d_name is "." or ".."

We use different idioms at different places. Let's replace this is the
one true new idiom, that is even a bit faster...

6 years agoshared/cgroup-show: extract funtion to query unit cgroup path
Zbigniew Jędrzejewski-Szmek [Wed, 1 Feb 2017 19:30:57 +0000 (14:30 -0500)]
shared/cgroup-show: extract funtion to query unit cgroup path

…and use it where possible.

6 years agoutil-lib: Fix chase_symlinks() with absolute symlinks (#5185)
3chas3 [Tue, 31 Jan 2017 13:21:15 +0000 (08:21 -0500)]
util-lib: Fix chase_symlinks() with absolute symlinks (#5185)

If chase_symlinks() encouters an absolute symlink, it resets the todo
buffer to just the newly discovered symlink and discards any of the
remaining previous symlink path.  Regardless of whether or not the
symlink is absolute or relative, we need to preserve the remainder of
the path that has not yet been resolved.

6 years agologind: trivial simplification
Zbigniew Jędrzejewski-Szmek [Sat, 28 Jan 2017 02:50:06 +0000 (21:50 -0500)]
logind: trivial simplification

free_and_strdup() handles NULL arg, so make use of that.

6 years agotree-wide: adjust fall through comments so that gcc is happy
Zbigniew Jędrzejewski-Szmek [Fri, 27 Jan 2017 05:50:10 +0000 (00:50 -0500)]
tree-wide: adjust fall through comments so that gcc is happy

gcc 7 adds -Wimplicit-fallthrough=3 to -Wextra. There are a few ways
we could deal with that. After we take into account the need to stay compatible
with older versions of the compiler (and other compilers), I don't think adding
__attribute__((fallthrough)), even as a macro, is worth the trouble. It sticks
out too much, a comment is just as good. But gcc has some very specific
requiremnts how the comment should look. Adjust it the specific form that it
likes. I don't think the extra stuff we had in those comments was adding much
value.

(Note: the documentation seems to be wrong, and seems to describe a different
pattern from the one that is actually used. I guess either the docs or the code
will have to change before gcc 7 is finalized.)

6 years agotree-wide: remove consecutive duplicate words in comments (#5148)
Stefan Schweter [Wed, 25 Jan 2017 02:45:30 +0000 (03:45 +0100)]
tree-wide: remove consecutive duplicate words in comments (#5148)

6 years agovirt: update url to hypervisor top-level functional specification (#5149)
Stefan Schweter [Wed, 25 Jan 2017 02:44:59 +0000 (03:44 +0100)]
virt: update url to hypervisor top-level functional specification (#5149)

6 years agosocket-utils: revert f1811313f42dc7ddaed3c47edc834c2bfd1309b2
Susant Sahani [Tue, 24 Jan 2017 18:24:34 +0000 (23:54 +0530)]
socket-utils: revert f1811313f42dc7ddaed3c47edc834c2bfd1309b2

':' in not a a valid interface name.

6 years agonetwork: accept colons in network interface names, normally used for alias interfaces...
peoronoob [Tue, 24 Jan 2017 03:26:41 +0000 (04:26 +0100)]
network: accept colons in network interface names, normally used for alias interfaces (#5117)

6 years agobasic/def: indentation
Zbigniew Jędrzejewski-Szmek [Sun, 22 Jan 2017 21:38:01 +0000 (16:38 -0500)]
basic/def: indentation

6 years agobasic/strv: allow NULLs to be inserted into strv
Zbigniew Jędrzejewski-Szmek [Sun, 22 Jan 2017 21:23:24 +0000 (16:23 -0500)]
basic/strv: allow NULLs to be inserted into strv

All callers of this function insert non-empty strings, so there's no functional
change.

6 years agobasic/exec-util: add support for synchronous (ordered) execution
Zbigniew Jędrzejewski-Szmek [Sun, 22 Jan 2017 20:22:37 +0000 (15:22 -0500)]
basic/exec-util: add support for synchronous (ordered) execution

The output of processes can be gathered, and passed back to the callee.
(This commit just implements the basic functionality and tests.)

After the preparation in previous commits, the change in functionality is
relatively simple. For coding convenience, alarm is prepared *before* any
children are executed, and not before. This shouldn't matter usually, since
just forking of the children should be pretty quick. One could also argue that
this is more correct, because we will also catch the case when (for whatever
reason), forking itself is slow.

Three callback functions and three levels of serialization are used:
- from individual generator processes to the generator forker
- from the forker back to the main process
- deserialization in the main process

v2:
- replace an structure with an indexed array of callbacks

6 years agobasic/conf-files: extend conf_files_list() to list unsuffixed files
Zbigniew Jędrzejewski-Szmek [Sun, 22 Jan 2017 19:16:19 +0000 (14:16 -0500)]
basic/conf-files: extend conf_files_list() to list unsuffixed files

5dd11ab5f36ce71138005 did a similar change for conf_files_list_strv().
Here we do the same for conf_files_list() and conf_files_list_nulstr().

No change for existing users. Tests are added.

6 years agobasic/util: move execute_directory() to separate file
Zbigniew Jędrzejewski-Szmek [Sun, 22 Jan 2017 17:35:08 +0000 (12:35 -0500)]
basic/util: move execute_directory() to separate file

It's a fairly specialized function. Let's make new files for it and the tests.

6 years agoprocess-util: rename char *r to ans and add comment
Zbigniew Jędrzejewski-Szmek [Sun, 15 Jan 2017 17:41:34 +0000 (12:41 -0500)]
process-util: rename char *r to ans and add comment

Add a comment about the return value and rename r to ans. r is
nowadays reserved for the integer return value, and char *r is confusing.

6 years agosocket-util: drop _pure_ from a function with an output parameter
Zbigniew Jędrzejewski-Szmek [Wed, 11 Jan 2017 19:09:47 +0000 (14:09 -0500)]
socket-util: drop _pure_ from a function with an output parameter

If it writes to memory, it's not pure, by definition.
Fixup for 882ac6e769c5c.

6 years agosparse: avoid clash with __bitwise and __force from 4.10 linux/types.h (#5061)
Lubomir Rintel [Wed, 11 Jan 2017 09:50:25 +0000 (10:50 +0100)]
sparse: avoid clash with __bitwise and __force from 4.10 linux/types.h (#5061)

It also used __bitwise and __force. It seems easier to rename
our versions since they are local to this one single header.

Also, undefine them afteerwards, so that we don't pollute the
preprocessor macro namespace.

6 years agomissing.h: add AF_VSOCK bits
Stefan Hajnoczi [Tue, 10 Jan 2017 13:35:18 +0000 (13:35 +0000)]
missing.h: add AF_VSOCK bits

Ubuntu 14.04 (Trusty) kernel header packages ship without
<linux/vm_sockets.h>.  Only struct sockaddr_vm and VMADDR_CID_ANY will
be needed by elogind and they are simple enough to go in missing.h.

CentOS 7 <sys/socket.h> does not define AF_VSOCK.  Define it so the code
can compile although actual socket(2) calls may fail at runtime if the
address family isn't available.

6 years agobuild-sys: add check for gperf lookup function signature (#5055)
Mike Gilbert [Tue, 10 Jan 2017 07:39:05 +0000 (02:39 -0500)]
build-sys: add check for gperf lookup function signature (#5055)

gperf-3.1 generates lookup functions that take a size_t length
parameter instead of unsigned int. Test for this at configure time.

Fixes: https://github.com/elogind/elogind/issues/5039
6 years agoutil-lib: add a comment explaining the user name rules we enforce
Lennart Poettering [Tue, 27 Dec 2016 16:59:21 +0000 (17:59 +0100)]
util-lib: add a comment explaining the user name rules we enforce

6 years agosd-event: when an event source fails, don't assume the type of it is still set
Lennart Poettering [Fri, 23 Dec 2016 22:26:15 +0000 (23:26 +0100)]
sd-event: when an event source fails, don't assume the type of it is still set

If a callback of an event source returns an error, then the event source
might already be half-destroyed, if the callback dropped all refs.
Hence, don't assume that the type is still valid, and save it before we
issue the callback.

6 years agoutil-lib: rework path_check_fstype() and path_is_temporary_fs() to use O_PATH
Lennart Poettering [Tue, 20 Dec 2016 18:09:27 +0000 (19:09 +0100)]
util-lib: rework path_check_fstype() and path_is_temporary_fs() to use O_PATH

Also, add tests to make sure this actually works as intended.

6 years agosocket-util: add AF_VSOCK address family
Stefan Hajnoczi [Tue, 20 Dec 2016 14:24:27 +0000 (14:24 +0000)]
socket-util: add AF_VSOCK address family

The AF_VSOCK address family facilitates guest<->host communication on
VMware and KVM (virtio-vsock).  Adding support to elogind allows guest
agents to be launched through .socket unit files.  Today guest agents
are stand-alone daemons running inside guests that do not take advantage
of elogind socket activation.

6 years agosocket-util: introduce port argument in sockaddr_port()
Stefan Hajnoczi [Tue, 20 Dec 2016 14:10:54 +0000 (14:10 +0000)]
socket-util: introduce port argument in sockaddr_port()

sockaddr_port() either returns a >= 0 port number or a negative errno.
This works for AF_INET and AF_INET6 because port ranges are only 16-bit.

In AF_VSOCK ports are 32-bit so an int cannot represent all port number
and negative errnos.  Separate the port and the return code.

6 years agobasic/log: use IN_SET
Zbigniew Jędrzejewski-Szmek [Sun, 18 Dec 2016 00:55:43 +0000 (19:55 -0500)]
basic/log: use IN_SET

6 years agoutil-lib: be stricter when decoding hex strings
Lennart Poettering [Fri, 16 Dec 2016 12:08:29 +0000 (13:08 +0100)]
util-lib: be stricter when decoding hex strings

If a hex string has an uneven length, generate an error instead of
silently assuming a trailing '0' was in place.

6 years agoAdd sd_is_socket_sockaddr (#4885)
Zbigniew Jędrzejewski-Szmek [Wed, 14 Dec 2016 10:51:26 +0000 (05:51 -0500)]
Add sd_is_socket_sockaddr (#4885)

Fixes #1188.

6 years agosd-id128: id128_write overwrites target file
Evgeny Vereshchagin [Tue, 13 Dec 2016 11:45:01 +0000 (11:45 +0000)]
sd-id128: id128_write overwrites target file

6 years agomachine-id-setup: `--print --commit` respects the --root option
Evgeny Vereshchagin [Tue, 13 Dec 2016 11:34:09 +0000 (11:34 +0000)]
machine-id-setup: `--print --commit` respects the --root option

6 years agoutil-lib: various improvements to kernel command line parsing
Lennart Poettering [Mon, 12 Dec 2016 17:29:15 +0000 (18:29 +0100)]
util-lib: various improvements to kernel command line parsing

This improves kernel command line parsing in a number of ways:

a) An kernel option "foo_bar=xyz" is now considered equivalent to
   "foo-bar-xyz", i.e. when comparing kernel command line option names "-" and
   "_" are now considered equivalent (this only applies to the option names
   though, not the option values!). Most of our kernel options used "-" as word
   separator in kernel command line options so far, but some used "_". With
   this change, which was a source of confusion for users (well, at least of
   one user: myself, I just couldn't remember that it's elogind.debug-shell,
   not elogind.debug_shell). Considering both as equivalent is inspired how
   modern kernel module loading normalizes all kernel module names to use
   underscores now too.

b) All options previously using a dash for separating words in kernel command
   line options now use an underscore instead, in all documentation and in
   code. Since a) has been implemented this should not create any compatibility
   problems, but normalizes our documentation and our code.

c) All kernel command line options which take booleans (or are boolean-like)
   have been reworked so that "foobar" (without argument) is now equivalent to
   "foobar=1" (but not "foobar=0"), thus normalizing the handling of our
   boolean arguments. Specifically this means elogind.debug-shell and
   elogind_debug_shell=1 are now entirely equivalent.

d) All kernel command line options which take an argument, and where no
   argument is specified will now result in a log message. e.g. passing just
   "elogind.unit" will no result in a complain that it needs an argument. This
   is implemented in the proc_cmdline_missing_value() function.

e) There's now a call proc_cmdline_get_bool() similar to proc_cmdline_get_key()
   that parses booleans (following the logic explained in c).

f) The proc_cmdline_parse() call's boolean argument has been replaced by a new
   flags argument that takes a common set of bits with proc_cmdline_get_key().

g) All kernel command line APIs now begin with the same "proc_cmdline_" prefix.

h) There are now tests for much of this. Yay!

6 years agoutil-lib: read $SYSTEMD_PROC_CMDLINE if set when looking for the kernel cmdline
Lennart Poettering [Mon, 12 Dec 2016 12:42:06 +0000 (13:42 +0100)]
util-lib: read $SYSTEMD_PROC_CMDLINE if set when looking for the kernel cmdline

if we want to parse the kernel command line, let's check the
$SYSTEMD_PROC_CMDLINE environment variable first. This is useful for debugging
purposes.

6 years agoman: use unicode ellipsis in more places
Zbigniew Jędrzejewski-Szmek [Sun, 11 Dec 2016 22:01:07 +0000 (17:01 -0500)]
man: use unicode ellipsis in more places

As requested in
https://github.com/elogind/elogind/pull/4864#pullrequestreview-12372557.

docbook will substitute triple dots for the ellipsis in man output, so this has
no effect on the troff output, only on HTML, making it infinitesimally nicer.

In some places we show output from programs, which use dots, and those places
should not be changed. In some tables, the alignment would change if dots were
changed to the ellipsis which is only one character. Since docbook replaces the
ellipsis automatically, we should leave those be. This patch changes all other
places.

6 years agobasic/log: CODE_FUNCTION → CODE_FUNC
Zbigniew Jędrzejewski-Szmek [Sun, 11 Dec 2016 20:40:55 +0000 (15:40 -0500)]
basic/log: CODE_FUNCTION → CODE_FUNC

elogind.journal-fields(7) documents CODE_FUNC=. Internally, we were
inconsistent: sd_journal_print uses CODE_FUNC=, log.h has CODE_FUNCTION=,
python-elogind and bootchart also used CODE_FUNC=, when they were internal.
Most external projects use sd_journal_* functions, so CODE_FUNC=,
python-elogind still uses CODE_FUNC=, as does elogind-bootchart, and
independent reimplementations in golang-github-coreos-go-elogind, qtbase,
network manager, glib, pulseaudio. Hence, I don't think there's much
choice.

6 years agoshare/log: change log_syntax from "[a:b] " to "a:b: "
Zbigniew Jędrzejewski-Szmek [Sun, 11 Dec 2016 19:37:12 +0000 (14:37 -0500)]
share/log: change log_syntax from "[a:b] " to "a:b: "

Those square brackets don't fit how our other messages look like; we use colons
everywhere else. The "[a:b]" format was originally added in
ed5bcfbe3c3b68e59242c03649eea03a9707d318, and remained unchanged for 7 years,
but in the meantime other conventions evolved.

The new version is also one character shorter.

[/etc/elogind/system/elogind-networkd.service.d/override.conf:2] Failed to parse sec value, ignoring: ...
  ↓
/etc/elogind/system/elogind-networkd.service.d/override.conf:2: Failed to parse sec value, ignoring: ...

6 years agobasic/log: merge two big log_struct_internal invocations into one
Zbigniew Jędrzejewski-Szmek [Sun, 11 Dec 2016 19:34:45 +0000 (14:34 -0500)]
basic/log: merge two big log_struct_internal invocations into one

We can take advantage of the fact a NULL argument terminates the list.

6 years agobasic/extract-word,man: clarify "correction" of invalid escapes
Zbigniew Jędrzejewski-Szmek [Sun, 11 Dec 2016 04:20:42 +0000 (23:20 -0500)]
basic/extract-word,man: clarify "correction" of invalid escapes

Our warning message was misleading, because we wouldn't "correct" anything,
we'd just ignore unkown escapes. Update the message.

Also, print just the extracted word (which contains the offending sequences) in
the message, instead of the whole line.

Fixes #4697.

6 years agoutil-lib: make verbose_mount() grok MS_MOVE
Lennart Poettering [Fri, 9 Dec 2016 16:35:48 +0000 (17:35 +0100)]
util-lib: make verbose_mount() grok MS_MOVE

Let's print a proper message if we see MS_MOVE.

6 years agotree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853)
Reverend Homer [Fri, 9 Dec 2016 09:04:30 +0000 (12:04 +0300)]
tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853)

6 years agoutil-lib: add new path_is_temporary_fs() API
Lennart Poettering [Thu, 8 Dec 2016 18:39:50 +0000 (19:39 +0100)]
util-lib: add new path_is_temporary_fs() API

As simple wrapper around fd_is_temporary_fs().

6 years agoutil-lib: make sure fd_check_fstype() opens files with O_CLOEXEC
Lennart Poettering [Thu, 8 Dec 2016 18:35:05 +0000 (19:35 +0100)]
util-lib: make sure fd_check_fstype() opens files with O_CLOEXEC

Also, O_NOCTTY is a safer bet, let's add that too.

6 years agoutil-lib: beef path_is_os_tree() up a bit
Lennart Poettering [Thu, 8 Dec 2016 16:19:27 +0000 (17:19 +0100)]
util-lib: beef path_is_os_tree() up a bit

Let's use chase_symlinks() when looking for /etc/os-release and
/usr/lib/os-release as these files might be symlinks (and actually are IRL on
some distros).

6 years agoutil-lib: accept invoking chase_symlinks() with a NULL return parameter
Lennart Poettering [Thu, 8 Dec 2016 16:15:06 +0000 (17:15 +0100)]
util-lib: accept invoking chase_symlinks() with a NULL return parameter

Let's permit invoking chase_symlinks() with a NULL return parameter. If so, the
resolved name is not returned, and call is useful for checking for existance of
a file, without actually returning its ultimate path.

6 years agocore: add comment why we don't bother with MS_SHARED remounting of / in containers
Lennart Poettering [Thu, 8 Dec 2016 09:51:32 +0000 (10:51 +0100)]
core: add comment why we don't bother with MS_SHARED remounting of / in containers

6 years agopam: include pam_keyinit.so in our PAM fragments
Lennart Poettering [Wed, 7 Dec 2016 19:14:43 +0000 (20:14 +0100)]
pam: include pam_keyinit.so in our PAM fragments

We want that elogind --user gets its own keyring as usual, even if the
barebones PAM snippet we ship upstream is used. If we don't do this we get the
basic keyring elogind --system sets up for us.

6 years agoutil-lib: rework rename_process() to be able to make use of PR_SET_MM_ARG_START
Lennart Poettering [Tue, 6 Dec 2016 19:29:07 +0000 (20:29 +0100)]
util-lib: rework rename_process() to be able to make use of PR_SET_MM_ARG_START

PR_SET_MM_ARG_START allows us to relatively cleanly implement process renaming.
However, it's only available with privileges. Hence, let's try to make use of
it, and if we can't fall back to the traditional way of overriding argv[0].

This removes size restrictions on the process name shown in argv[] at least for
privileged processes.

6 years agoutil-lib: improve container detection logic
Lennart Poettering [Tue, 6 Dec 2016 14:51:26 +0000 (15:51 +0100)]
util-lib: improve container detection logic

Previously, elogind-detect-virt was unable to detect "elogind-nspawn -a"
container environments, i.e. where PID 1 is a stub process running in host
context, as in that case /proc/1/environ was inherited from the host. Let's
improve that, and add an additional check for container environments where
/proc/1/environ is not cleaned up and does not contain the $container
environment variable:

The /proc/1/sched file shows the host PID in the first line. if this is not
1, we know we are running in a PID namespace (but not which implementation).

With these changes we should be able to detect container environments that
don't set $container at all.

6 years agocore: introduce parse_ip_port (#4825)
Susant Sahani [Tue, 6 Dec 2016 11:21:45 +0000 (16:51 +0530)]
core: introduce parse_ip_port (#4825)

1. Listed in TODO.
2. Tree wide replace safe_atou16 with parse_ip_port incase
   it's used for ports.

6 years agotime-util: accept "µs" as time unit, in addition to "us" (#4836)
Lennart Poettering [Tue, 6 Dec 2016 09:51:26 +0000 (10:51 +0100)]
time-util: accept "µs" as time unit, in addition to "us" (#4836)

Let's accept "µs" as alternative time unit for microseconds. We already accept
"us" and "usec" for them, lets extend on this and accept the proper scientific
unit specification too.

We will never output this as time unit, but it's fine to accept it, after all
we are pretty permissive with time units already.

6 years agoman: Document return value of event source prepare callback (#4834)
Martin Ejdestig [Mon, 5 Dec 2016 22:42:41 +0000 (23:42 +0100)]
man: Document return value of event source prepare callback (#4834)

6 years agoModify mount_propagation_flags_from_string to return a normal int code
Zbigniew Jędrzejewski-Szmek [Sat, 3 Dec 2016 18:57:42 +0000 (13:57 -0500)]
Modify mount_propagation_flags_from_string to return a normal int code

This means that callers can distiguish an error from flags==0,
and don't have to special-case the empty string.

6 years agoutil-lib: drop unnecessary NULL check
Lennart Poettering [Fri, 2 Dec 2016 16:01:19 +0000 (17:01 +0100)]
util-lib: drop unnecessary NULL check

DEFINE_TRIVIAL_CLEANUP_FUNC() already does that check, no need to duplicate it.

6 years agocgroup: properly check for ignore-notfound paths (#4803)
Dave Reisner [Fri, 2 Dec 2016 14:23:23 +0000 (09:23 -0500)]
cgroup: properly check for ignore-notfound paths (#4803)

Follow-up to #4687 and e7330dfe14b1965f.

6 years agocore: store the invocation ID in the per-service keyring
Lennart Poettering [Fri, 2 Dec 2016 14:05:55 +0000 (15:05 +0100)]
core: store the invocation ID in the per-service keyring

Let's store the invocation ID in the per-service keyring as a root-owned key,
with strict access rights. This has the advantage over the environment-based ID
passing that it also works from SUID binaries (as they key cannot be overidden
by unprivileged code starting them), in contrast to the secure_getenv() based
mode.

The invocation ID is now passed in three different ways to a service:

- As environment variable $INVOCATION_ID. This is easy to use, but may be
  overriden by unprivileged code (which might be a bad or a good thing), which
  means it's incompatible with SUID code (see above).

- As extended attribute on the service cgroup. This cannot be overriden by
  unprivileged code, and may be queried safely from "outside" of a service.
  However, it is incompatible with containers right now, as unprivileged
  containers generally cannot set xattrs on cgroupfs.

- As "invocation_id" key in the kernel keyring. This has the benefit that the
  key cannot be changed by unprivileged service code, and thus is safe to
  access from SUID code (see above). But do note that service code can replace
  the session keyring with a fresh one that lacks the key. However in that case
  the key will not be owned by root, which is easily detectable. The keyring is
  also incompatible with containers right now, as it is not properly namespace
  aware (but this is being worked on), and thus most container managers mask
  the keyring-related system calls.

Ideally we'd only have one way to pass the invocation ID, but the different
ways all have limitations. The invocation ID hookup in journald is currently
only available on the host but not in containers, due to the mentioned
limitations.

How to verify the new invocation ID in the keyring:

 # elogind-run -t /bin/sh
 Running as unit: run-rd917366c04f847b480d486017f7239d6.service
 Press ^] three times within 1s to disconnect TTY.
 # keyctl show
 Session Keyring
  680208392 --alswrv      0     0  keyring: _ses
  250926536 ----s-rv      0     0   \_ user: invocation_id
 # keyctl request user invocation_id
 250926536
 # keyctl read 250926536
 16 bytes of data in key:
 9c96317c ac64495a a42b9cd7 4f3ff96b
 # echo $INVOCATION_ID
 9c96317cac64495aa42b9cd74f3ff96b
 # ^D

This creates a new transient service runnint a shell. Then verifies the
contents of the keyring, requests the invocation ID key, and reads its payload.
For comparison the invocation ID as passed via the environment variable is also
displayed.

6 years agocore: run each system service with a fresh session keyring
Lennart Poettering [Fri, 2 Dec 2016 00:54:41 +0000 (01:54 +0100)]
core: run each system service with a fresh session keyring

This patch ensures that each system service gets its own session kernel keyring
automatically, and implicitly. Without this a keyring is allocated for it
on-demand, but is then linked with the user's kernel keyring, which is OK
behaviour for logged in users, but not so much for system services.

With this change each service gets a session keyring that is specific to the
service and ceases to exist when the service is shut down. The session keyring
is not linked up with the user keyring and keys hence only search within the
session boundaries by default.

(This is useful in a later commit to store per-service material in the keyring,
for example the invocation ID)

(With input from David Howells)

6 years agoutil-lib: add easy helpers for temporary directories that rmdir()ed via _cleanup_
Lennart Poettering [Thu, 1 Dec 2016 22:19:31 +0000 (23:19 +0100)]
util-lib: add easy helpers for temporary directories that rmdir()ed via _cleanup_

This adds mkdtemp_malloc() that is a combination of mkdtemp() plus strdup(). It
initializes its return paremeter only if the temporary directory could be
created successfully, so that the parameter is exactly non-NULL when the
directory exists.

rmdir_and_free() and rmdir_and_freep() are also added, and the latter may be
used inside of _cleanup_ for such a directory string variable, to automatically
rmdir() the directory if it is non-NULL when the scope exits.

rmdir_and_free() is similar to the existing rm_rf_and_free() however, is only
removes a single directory and does not operate recursively.

6 years agoutil-lib: rename CHASE_NON_EXISTING → CHASE_NONEXISTENT
Lennart Poettering [Thu, 1 Dec 2016 11:49:23 +0000 (12:49 +0100)]
util-lib: rename CHASE_NON_EXISTING → CHASE_NONEXISTENT

As suggested by @keszybz

6 years agocore: rework logic to determine when we decide to add automatic deps for mounts
Lennart Poettering [Tue, 29 Nov 2016 21:50:21 +0000 (22:50 +0100)]
core: rework logic to determine when we decide to add automatic deps for mounts

This adds a concept of "extrinsic" mounts. If mounts are extrinsic we consider
them managed by something else and do not add automatic ordering against
umount.target, local-fs.target, remote-fs.target.

Extrinsic mounts are considered:

- All mounts if we are running in --user mode

- API mounts such as everything below /proc, /sys, /dev, which exist from
  earliest boot to latest shutdown.

- All mounts marked as initrd mounts, if we run on the host

- The initrd's private directory /run/initrams that should survive until last
  reboot.

This primarily merges a couple of different exclusion lists into a single
concept.

6 years agoTwo small cleanups
Zbigniew Jędrzejewski-Szmek [Tue, 29 Nov 2016 19:42:57 +0000 (14:42 -0500)]
Two small cleanups

6 years agocgroup: support prefix "-" in cgroups whitelisting entries (#4687)
Dongsu Park [Tue, 29 Nov 2016 19:16:55 +0000 (20:16 +0100)]
cgroup: support prefix "-" in cgroups whitelisting entries (#4687)

So far elogind-nspawn container has been creating files under
/run/elogind/inaccessible, no matter whether it's running in user
namespace or not. That's fine for regular files, dirs, socks, fifos.
However, it's not for block and character devices, because kernel
doesn't allow them to be created under user namespace. It results
in warnings at booting like that:

====
  Couldn't stat device /run/elogind/inaccessible/chr
  Couldn't stat device /run/elogind/inaccessible/blk
====

Thus we need to have the cgroups whitelisting handler to silently ignore
a file, when the device path is prefixed with "-". That's exactly the
same convention used in directives like ReadOnlyPaths=. Also insert the
prefix "-" to inaccessible entries.

6 years agofs-util: add new CHASE_NON_EXISTING flag to chase_symlinks()
Lennart Poettering [Tue, 29 Nov 2016 17:02:45 +0000 (18:02 +0100)]
fs-util: add new CHASE_NON_EXISTING flag to chase_symlinks()

This new flag controls whether to consider a problem if the referenced path
doesn't actually exist. If specified it's OK if the final file doesn't exist.

Note that this permits one or more final components of the path not to exist,
but these must not contain "../" for safety reasons (or, to be extra safe,
neither "./" and a couple of others, i.e. what path_is_safe() permits).

This new flag is useful when resolving paths before issuing an mkdir() or
open(O_CREAT) on a path, as it permits that the file or directory is created
later.

The return code of chase_symlinks() is changed to return 1 if the file exists,
and 0 if it doesn't. The latter is only returned in case CHASE_NON_EXISTING is
set.

6 years agofs-util: add flags parameter to chase_symlinks()
Lennart Poettering [Tue, 29 Nov 2016 15:49:30 +0000 (16:49 +0100)]
fs-util: add flags parameter to chase_symlinks()

Let's remove chase_symlinks_prefix() and instead introduce a flags parameter to
chase_symlinks(), with a flag CHASE_PREFIX_ROOT that exposes the behaviour of
chase_symlinks_prefix().

6 years agofs-util: change chase_symlinks() behaviour in regards to escaping the root dir
Lennart Poettering [Tue, 29 Nov 2016 14:54:42 +0000 (15:54 +0100)]
fs-util: change chase_symlinks() behaviour in regards to escaping the root dir

Previously, we'd generate an EINVAL error if it is attempted to escape a root
directory with relative ".." symlinks. With this commit this is changed so that
".." from the root directory is a NOP, following the kernel's own behaviour
where /.. is equivalent to /.

As suggested by @keszybz.

6 years agofs-util: add chase_symlinks_prefix() and extend comments
Lennart Poettering [Fri, 25 Nov 2016 17:59:39 +0000 (18:59 +0100)]
fs-util: add chase_symlinks_prefix() and extend comments

chase_symlinks() currently expects a fully qualified, absolute path, relative
to the host's root as first argument. Which is useful in many ways, and similar
to the paths unlink(), rename(), open(), … expect. Sometimes it's however
useful to first prefix the specified path with the specified root directory.
Add a new call chase_symlinks_prefix() for this, that is a simple wrapper.

6 years agoutil: Fine tune running_in_chroot() a bit
Lennart Poettering [Thu, 24 Nov 2016 16:42:19 +0000 (17:42 +0100)]
util: Fine tune running_in_chroot() a bit

Let's be a bit more careful when detecting chroot() environments, so that we
can discern them from namespaced environments.

Previously this would simply check if the root directory of PID 1 matches our
own root directory. With this commit, we also check whether the namespaces of
PID 1 and ourselves are the same. If not we assume we are running inside of a
namespaced environment instead of a chroot() environment.

This has the benefit that systemctl (which uses running_in_chroot()) will work
as usual when invoked in a namespaced service.

6 years agocore: keep supporting cgroup hybrid layout from v232 for live upgrades
Tejun Heo [Wed, 23 Nov 2016 17:27:32 +0000 (12:27 -0500)]
core: keep supporting cgroup hybrid layout from v232 for live upgrades

v232's cgroup hybrid mode mounted v2 on /sys/fs/cgroup/elogind, which
unfortunately broke other tools which expect v1 there.  From v233 on, hybrid
mode instead mounts and uses v2 on /sys/fs/cgroup/unified and keeps
/sys/fs/cgroup/elogind on v1 for compatibility with external tools.  However,
to keep elogind live upgrades working, v233+ should be able to recognize v232
layout and keep using it.

This patch adds v232 hybrid mode support.  If v232 layout is detected,
cg_unified(SYSTEMD_CGRouP_CONTROLLER) keeps returning %true but
cg_hybrid_unified() returns %false.  This keeps process management on cgroup v2
but turns off the parallel layout.

6 years agocore: hook up MountFlags= to the transient unit logic
Lennart Poettering [Tue, 22 Nov 2016 19:19:08 +0000 (20:19 +0100)]
core: hook up MountFlags= to the transient unit logic

This makes "elogind-run -p MountFlags=shared -t /bin/sh" work, by making
MountFlags= to the list of properties that may be accessed transiently.

6 years agosd-event: fix sd_event_source_get_priority() (#4712)
Martin Ejdestig [Tue, 22 Nov 2016 00:21:00 +0000 (01:21 +0100)]
sd-event: fix sd_event_source_get_priority() (#4712)

To properly store priority in passed in pointer and return 0 for success.
Also add a test for verifying that it works correctly.

6 years agocore: make SYSTEMD_CGROUP_CONTROLLER a special string
Tejun Heo [Mon, 21 Nov 2016 19:45:53 +0000 (14:45 -0500)]
core: make SYSTEMD_CGROUP_CONTROLLER a special string

SYSTEMD_CGROUP_CONTROLLER is currently defined as "name=elogind" which cgroup
utility functions interpret as a named cgroup hierarchy with the specified
named.  With the planned cgroup hybrid mode changes, SYSTEMD_CGROUP_CONTROLLER
would map to different hierarchy names.

This patch makes SYSTEMD_CGROUP_CONTROLLER a special string "_elogind" which is
substituted to "name=elogind" by the cgroup utility functions.  This allows the
callers to address the elogind hierarchy without actually specifying the
hierarchy name allowing the cgroup utility functions to map it to whatever is
appropriate.

Note that SYSTEMD_CGROUP_CONTROLLER was already special on full unified cgroup
hierarchy even before this patch.

6 years agocore: simplify cg_[all_]unified()
Tejun Heo [Mon, 21 Nov 2016 19:45:53 +0000 (14:45 -0500)]
core: simplify cg_[all_]unified()

cg_[all_]unified() test whether a specific controller or all controllers are on
the unified hierarchy.  While what's being asked is a simple binary question,
the callers must assume that the functions may fail any time, which
unnecessarily complicates their usages.  This complication is unnecessary.
Internally, the test result is cached anyway and there are only a few places
where the test actually needs to be performed.

This patch simplifies cg_[all_]unified().

* cg_[all_]unified() are updated to return bool.  If the result can't be
  decided, assertion failure is triggered.  Error handlings from their callers
  are dropped.

* cg_unified_flush() is updated to calculate the new result synchrnously and
  return whether it succeeded or not.  Places which need to flush the test
  result are updated to test for failure.  This ensures that all the following
  cg_[all_]unified() tests succeed.

* Places which expected possible cg_[all_]unified() failures are updated to
  call and test cg_unified_flush() before calling cg_[all_]unified().  This
  includes functions used while setting up mounts during boot and
  manager_setup_cgroup().

6 years agocore: make hybrid cgroup unified mode keep compat /sys/fs/cgroup/elogind hierarchy
Tejun Heo [Mon, 21 Nov 2016 19:45:53 +0000 (14:45 -0500)]
core: make hybrid cgroup unified mode keep compat /sys/fs/cgroup/elogind hierarchy

Currently the hybrid mode mounts cgroup v2 on /sys/fs/cgroup instead of the v1
name=elogind hierarchy.  While this works fine for elogind itself, it breaks
tools which expect cgroup v1 hierarchy on /sys/fs/cgroup/elogind.

This patch updates the hybrid mode so that it mounts v2 hierarchy on
/sys/fs/cgroup/unified and keeps v1 "name=elogind" hierarchy on
/sys/fs/cgroup/elogind for compatibility.  elogind itself doesn't depend on the
"name=elogind" hierarchy at all.  All operations take place on the v2 hierarchy
as before but the v1 hierarchy is kept in sync so that any tools which expect
it to be there can keep doing so.  This allows elogind to take advantage of
cgroup v2 process management without requiring other tools to be aware of the
hybrid mode.

The hybrid mode is implemented by mapping the special elogind controller to
/sys/fs/cgroup/unified and making the basic cgroup utility operations -
cg_attach(), cg_create(), cg_rmdir() and cg_trim() - also operate on the
/sys/fs/cgroup/elogind hierarchy whenever the cgroup2 hierarchy is updated.

While a bit messy, this will allow dropping complications from using cgroup v1
for process management a lot sooner than otherwise possible which should make
it a net gain in terms of maintainability.

v2: Fixed !cgns breakage reported by @evverx and renamed the unified mount
    point to /sys/fs/cgroup/unified as suggested by @brauner.

v3: chown the compat hierarchy too on delegation.  Suggested by @evverx.

v4: [zj]
- drop the change to default, full "legacy" is still the default.

6 years agotree-wide: stop using canonicalize_file_name(), use chase_symlinks() instead
Lennart Poettering [Fri, 18 Nov 2016 20:35:21 +0000 (21:35 +0100)]
tree-wide: stop using canonicalize_file_name(), use chase_symlinks() instead

Let's use chase_symlinks() everywhere, and stop using GNU
canonicalize_file_name() everywhere. For most cases this should not change
behaviour, however increase exposure of our function to get better tested. Most
importantly in a few cases (most notably nspawn) it can take the correct root
directory into account when chasing symlinks.

6 years agonspawn: support ephemeral boots from images
Lennart Poettering [Fri, 18 Nov 2016 17:38:06 +0000 (18:38 +0100)]
nspawn: support ephemeral boots from images

Previously --ephemeral was only supported with container trees in btrfs
subvolumes (i.e. in combination with --directory=). This adds support for
--ephemeral in conjunction with disk images (i.e. --image=) too.

As side effect this fixes that --ephemeral was accepted but ignored when using
-M on a container that turned out to be an image.

Fixes: #4664
6 years agobasic/process-util: we need to take the shorter of two strings
Zbigniew Jędrzejewski-Szmek [Fri, 18 Nov 2016 01:57:22 +0000 (20:57 -0500)]
basic/process-util: we need to take the shorter of two strings

==30496== Conditional jump or move depends on uninitialised value(s)
==30496==    at 0x489F654: memcmp (vg_replace_strmem.c:1091)
==30496==    by 0x49BF203: getenv_for_pid (process-util.c:678)
==30496==    by 0x4993ACB: detect_container (virt.c:442)
==30496==    by 0x182DFF: test_get_process_comm (test-process-util.c:98)
==30496==    by 0x185847: main (test-process-util.c:368)
==30496==

6 years agosd-id128: add new sd_id128_get_machine_app_specific() API
Lennart Poettering [Thu, 17 Nov 2016 16:07:46 +0000 (17:07 +0100)]
sd-id128: add new sd_id128_get_machine_app_specific() API

This adds an API for retrieving an app-specific machine ID to sd-id128.
Internally it calculates HMAC-SHA256 with an 128bit app-specific ID as payload
and the machine ID as key.

(An alternative would have been to use siphash for this, which is also
cryptographically strong. However, as it only generates 64bit hashes it's not
an obvious choice for generating 128bit IDs.)

Fixes: #4667
6 years agocore: add "khash" API to src/basic/ (as wrapper around kernel AF_ALG)
Lennart Poettering [Thu, 17 Nov 2016 16:03:21 +0000 (17:03 +0100)]
core: add "khash" API to src/basic/ (as wrapper around kernel AF_ALG)

Let's take inspiration from bluez's ELL library, and let's move our
cryptographic primitives away from libgcrypt and towards the kernel's AF_ALG
cryptographic userspace API.

In the long run we should try to remove the dependency on libgcrypt, in favour
of using only the kernel's own primitives, however this is unlikely to happen
anytime soon, as the kernel does not provide Elliptic Curve APIs to userspace
at this time, and we need them for the DNSSEC cryptographic.

This commit only covers hashing for now, symmetric encryption/decryption or
even asymetric encryption/decryption is not available for now.

"khash" is little more than a lightweight wrapper around the kernel's AF_ALG
socket API.

6 years agoshared: split out code for adding multiple names to sd_bus_track object
Lennart Poettering [Tue, 15 Nov 2016 18:18:36 +0000 (19:18 +0100)]
shared: split out code for adding multiple names to sd_bus_track object

Let's introduce a new call bus_track_add_name_many() that adds a string list to
a tracking object.

6 years agobus-util: print RestrictNamespaces= as a string
Djalal Harouni [Tue, 15 Nov 2016 14:15:37 +0000 (15:15 +0100)]
bus-util: print RestrictNamespaces= as a string

Allow all callers that want to print RestrictNamespaces= returned from D-Bus
as a string instead of a u64 value.

6 years agotree-wide: make invocations of extract_first_word more uniform (#4627)
Zbigniew Jędrzejewski-Szmek [Fri, 11 Nov 2016 17:58:41 +0000 (12:58 -0500)]
tree-wide: make invocations of extract_first_word more uniform (#4627)

extract_first_words deals fine with the string being NULL, so drop the upfront
check for that.

6 years agobasic/virt: fix userns check on CONFIG_USER_NS=n kernel (#4651)
Zbigniew Jędrzejewski-Szmek [Fri, 11 Nov 2016 15:54:54 +0000 (10:54 -0500)]
basic/virt: fix userns check on CONFIG_USER_NS=n kernel (#4651)

ENOENT should be treated as "false", but because of the broken errno check it
was treated as an error. So ConditionVirtualization=user-namespaces probably
returned the correct answer, but only by accident.

Fixes #4608.

6 years agocore: don't use the unified hierarchy for the elogind cgroup yet (#4628)
Martin Pitt [Thu, 10 Nov 2016 04:33:13 +0000 (05:33 +0100)]
core: don't use the unified hierarchy for the elogind cgroup yet (#4628)

Too many things don't get along with the unified hierarchy yet:

 * https://github.com/opencontainers/runc/issues/1175
 * https://github.com/docker/docker/issues/28109
 * https://github.com/lxc/lxc/issues/1280

So revert the default to the legacy hierarchy for now. Developers of the above
software can opt into the unified hierarchy with
"elogind.legacy_elogind_cgroup_controller=0".

6 years agoman/sd_watchdog_enabled: correct minor typos (#4632)
Jonathan Boulle [Wed, 9 Nov 2016 16:30:10 +0000 (17:30 +0100)]
man/sd_watchdog_enabled: correct minor typos (#4632)

6 years agoAdjust pkgconfig files to point at rootlibdir (#4584)
Mike Gilbert [Tue, 8 Nov 2016 08:36:41 +0000 (03:36 -0500)]
Adjust pkgconfig files to point at rootlibdir (#4584)

The .so symlinks got moved to rootlibdir in 082210c7.

6 years agotree-wide: drop (llu) casts for kernel's __u64
Zbigniew Jędrzejewski-Szmek [Mon, 7 Nov 2016 16:49:51 +0000 (11:49 -0500)]
tree-wide: drop (llu) casts for kernel's __u64

According to comments in <asm/types.h>, __u64 is always defined as unsigned
long long. Those casts should be superfluous.

6 years agotree-wide: add PRI_[NU]SEC, and use time format strings more
Zbigniew Jędrzejewski-Szmek [Mon, 7 Nov 2016 16:49:25 +0000 (11:49 -0500)]
tree-wide: add PRI_[NU]SEC, and use time format strings more

6 years agocore: reprint the question every 2 sec in ask_char()
Franck Bui [Mon, 7 Nov 2016 16:14:59 +0000 (17:14 +0100)]
core: reprint the question every 2 sec in ask_char()

ask_char() now reprints the question every 2sec automatically.

It prefixes its output with '\r' to to bring the cursor to the
beginning of the terminal line, and then print the message, redoing it
every 2sec.

As long as nothing interferes with out output this logic will have no
visible effect as we constantly overprint the visible text with the
exact same text.

However, if something is dumped in the middle, then our question won't
get lost, as we'll ask soon again.

This is useful if the question is asked to a terminal that is also
used to dump some other status messages/logs. For example when
confirmation messages are enabled during the boot
(elogind.confirm_spawn=1), the question can easily be lost if the
kernel logs are also enabled and both use the same console.

Idea suggested by Lennart Poettering.

6 years agoRename formats-util.h to format-util.h
Zbigniew Jędrzejewski-Szmek [Mon, 7 Nov 2016 15:14:59 +0000 (10:14 -0500)]
Rename formats-util.h to format-util.h

We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.

6 years agotree-wide: add SD_ID128_MAKE_STR, remove LOG_MESSAGE_ID
Zbigniew Jędrzejewski-Szmek [Sun, 6 Nov 2016 17:48:23 +0000 (12:48 -0500)]
tree-wide: add SD_ID128_MAKE_STR, remove LOG_MESSAGE_ID

Embedding sd_id128_t's in constant strings was rather cumbersome. We had
SD_ID128_CONST_STR which returned a const char[], but it had two problems:
- it wasn't possible to statically concatanate this array with a normal string
- gcc wasn't really able to optimize this, and generated code to perform the
  "conversion" at runtime.
Because of this, even our own code in coredumpctl wasn't using
SD_ID128_CONST_STR.

Add a new macro to generate a constant string: SD_ID128_MAKE_STR.
It is not as elegant as SD_ID128_CONST_STR, because it requires a repetition
of the numbers, but in practice it is more convenient to use, and allows gcc
to generate smarter code:

$ size .libs/elogind{,-logind,-journald}{.old,}
   text    data     bss     dec     hex filename
1265204  149564    4808 1419576  15a938 .libs/elogind.old
1260268  149564    4808 1414640  1595f0 .libs/elogind
 246805   13852     209  260866   3fb02 .libs/elogind-logind.old
 240973   13852     209  255034   3e43a .libs/elogind-logind
 146839    4984      34  151857   25131 .libs/elogind-journald.old
 146391    4984      34  151409   24f71 .libs/elogind-journald

It is also much easier to check if a certain binary uses a certain MESSAGE_ID:

$ strings .libs/elogind.old|grep MESSAGE_ID
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x

$ strings .libs/elogind|grep MESSAGE_ID
MESSAGE_ID=c7a787079b354eaaa9e77b371893cd27
MESSAGE_ID=b07a249cd024414a82dd00cd181378ff
MESSAGE_ID=641257651c1b4ec9a8624d7a40a9e1e7
MESSAGE_ID=de5b426a63be47a7b6ac3eaac82e2f6f
MESSAGE_ID=d34d037fff1847e6ae669a370e694725
MESSAGE_ID=7d4958e842da4a758f6c1cdc7b36dcc5
MESSAGE_ID=1dee0369c7fc4736b7099b38ecb46ee7
MESSAGE_ID=39f53479d3a045ac8e11786248231fbf
MESSAGE_ID=be02cf6855d2428ba40df7e9d022f03d
MESSAGE_ID=7b05ebc668384222baa8881179cfda54
MESSAGE_ID=9d1aaa27d60140bd96365438aad20286

6 years agoLink: port to new ethtool ETHTOOL_xLINKSETTINGS
Susant Sahani [Fri, 4 Nov 2016 09:55:07 +0000 (15:25 +0530)]
Link: port to new ethtool ETHTOOL_xLINKSETTINGS

Link: port to new ethtool ETHTOOL_xLINKSETTINGS
This patch defines a new ETHTOOL_GLINKSETTINGS/SLINKSETTINGS API,
handled by the new get_link_ksettings/set_link_ksettings .

This is a WIP version based on this [kernel
patch](https://patchwork.kernel.org/patch/8411401/).

commit 0527f1c

http://github.com/torvalds/linux/commit/3f1ac7a700d039c61d8d8b99f28d605d489a60cfommit
35afb33

6 years agoacl-util: fix memleak
Evgeny Vereshchagin [Thu, 3 Nov 2016 22:04:40 +0000 (22:04 +0000)]
acl-util: fix memleak

Fixes:
$ ./libtool --mode execute valgrind --leak-check=full ./journalctl >/dev/null
==22309== Memcheck, a memory error detector
==22309== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==22309== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==22309== Command: /home/vagrant/elogind/.libs/lt-journalctl
==22309==
Hint: You are currently not seeing messages from other users and the system.
      Users in groups 'adm', 'elogind-journal', 'wheel' can see all messages.
      Pass -q to turn off this notice.
==22309==
==22309== HEAP SUMMARY:
==22309==     in use at exit: 8,680 bytes in 4 blocks
==22309==   total heap usage: 5,543 allocs, 5,539 frees, 9,045,618 bytes allocated
==22309==
==22309== 488 (56 direct, 432 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 4
==22309==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
==22309==    by 0x6F37A0A: __new_var_obj_p (__libobj.c:36)
==22309==    by 0x6F362F7: __acl_init_obj (acl_init.c:28)
==22309==    by 0x6F37731: __acl_from_xattr (__acl_from_xattr.c:54)
==22309==    by 0x6F36087: acl_get_file (acl_get_file.c:69)
==22309==    by 0x4F15752: acl_search_groups (acl-util.c:172)
==22309==    by 0x113A1E: access_check_var_log_journal (journalctl.c:1836)
==22309==    by 0x113D8D: access_check (journalctl.c:1889)
==22309==    by 0x115681: main (journalctl.c:2236)
==22309==
==22309== LEAK SUMMARY:
==22309==    definitely lost: 56 bytes in 1 blocks
==22309==    indirectly lost: 432 bytes in 1 blocks
==22309==      possibly lost: 0 bytes in 0 blocks
==22309==    still reachable: 8,192 bytes in 2 blocks
==22309==         suppressed: 0 bytes in 0 blocks

6 years agoRevert "sd-bus: use PRIu64 instead of casting" (#4556)
Zbigniew Jędrzejewski-Szmek [Thu, 3 Nov 2016 17:16:42 +0000 (13:16 -0400)]
Revert "sd-bus: use PRIu64 instead of casting" (#4556)

This reverts commit 75ead2b753cb9586f3f208326446081baab70da1.

Follow up for #4546:
> @@ -848,8 +848,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         if (k->src_id == KDBUS_SRC_ID_KERNEL)
                 bus_message_set_sender_driver(bus, m);
         else {
-                xsprintf(m->sender_buffer, ":1.%llu",
-                         (unsigned long long)k->src_id);
+                xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);

This produces:

src/libelogind/sd-bus/bus-kernel.c: In function ‘bus_kernel_make_message’:
src/libelogind/sd-bus/bus-kernel.c:851:44: warning: format ‘%lu’ expects argument of type ‘long
unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=]
                 xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
                                            ^

6 years agocore: monitor the inotify file descriptor not the console one in acquire_terminal()
Franck Bui [Wed, 2 Nov 2016 15:24:57 +0000 (16:24 +0100)]
core: monitor the inotify file descriptor not the console one in acquire_terminal()

When waiting for the terminal to be release in acquire_terminal(), we
were monitoring the terminal fd instead of the inotify descriptor.

Therefore any write accesses would wake up the waiting process instead
of being wake up when the tty is closed only.

6 years agoDrop FOREACH_WORD_QUOTED
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2016 02:44:50 +0000 (22:44 -0400)]
Drop FOREACH_WORD_QUOTED

6 years agotree-wide: drop unneded WHITESPACE param to extract_first_word
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2016 00:06:44 +0000 (20:06 -0400)]
tree-wide: drop unneded WHITESPACE param to extract_first_word

It's the default, and NULL is shorter.