chiark / gitweb /
elogind.git
6 years agobasic/fileio: use IN_SET
Zbigniew Jędrzejewski-Szmek [Tue, 21 Feb 2017 16:15:27 +0000 (11:15 -0500)]
basic/fileio: use IN_SET

6 years agobasic/fileio: fix memleak when discarding an invalid variable
Zbigniew Jędrzejewski-Szmek [Tue, 21 Feb 2017 16:15:19 +0000 (11:15 -0500)]
basic/fileio: fix memleak when discarding an invalid variable

Fixes #5405.

6 years agocopy: a plain unlink() works here too
Lennart Poettering [Tue, 21 Feb 2017 16:13:28 +0000 (17:13 +0100)]
copy: a plain unlink() works here too

6 years agoSyntax for defines that is also unterstood by the GNU C/C++ compilers. (#5397)
pyBlob [Mon, 20 Feb 2017 21:24:45 +0000 (22:24 +0100)]
Syntax for defines that is also unterstood by the GNU C/C++ compilers. (#5397)

6 years agocgroup-util: fix the reversed return value of cg_is_unified_elogind_contoller_wanted
Zbigniew Jędrzejewski-Szmek [Mon, 20 Feb 2017 17:26:53 +0000 (12:26 -0500)]
cgroup-util: fix the reversed return value of cg_is_unified_elogind_contoller_wanted

1d84ad944520fc3e062ef518c4db4e1 reversed the meaning of the option.
The kernel command line option has the opposite meaning to the function,
i.e. specifying "legacy=yes" means "unifed elogind controller=no".

6 years agocore/mount-setup: if unified hierarchy is not supported, fall back to legacy
Zbigniew Jędrzejewski-Szmek [Sun, 19 Feb 2017 20:59:21 +0000 (15:59 -0500)]
core/mount-setup: if unified hierarchy is not supported, fall back to legacy

We need this to gracefully support older or strangely configured kernels.

v2:
- do not install a callback handler, just embed the right conditions into
  cg_is_*_wanted()

v3:
- fix bug in cg_is_legacy_wanted()

6 years agoRename cg_is_unified_elogind_controller_wanted to cg_is_hybrid_wanted
Zbigniew Jędrzejewski-Szmek [Sun, 19 Feb 2017 20:36:56 +0000 (15:36 -0500)]
Rename cg_is_unified_elogind_controller_wanted to cg_is_hybrid_wanted

Less typing and doesn't make the table so incredibly wide.

6 years agoshared/pager: abort if we cannot set environment variables
Zbigniew Jędrzejewski-Szmek [Sun, 19 Feb 2017 18:52:18 +0000 (13:52 -0500)]
shared/pager: abort if we cannot set environment variables

This most likely means oom, it's better to exit than to run less with
incomplete settings.

CID #714383.

6 years agologind: check return value from lseek
Zbigniew Jędrzejewski-Szmek [Sun, 19 Feb 2017 18:43:22 +0000 (13:43 -0500)]
logind: check return value from lseek

In practice this doesn't matter much because the read that follows will
likely fail, but we'll get a better error message.

CID #1368233.

6 years agobuild.h: include default cgroup hierarchy setting in --version output
Zbigniew Jędrzejewski-Szmek [Sun, 19 Feb 2017 04:28:01 +0000 (23:28 -0500)]
build.h: include default cgroup hierarchy setting in --version output

This is pretty important, and we print this string during startup, so putting
the default hierarchy information might help with diagnosis if things go awry.

$ ./systemctl --version
elogind 232
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN default-hierarchy=legacy

v2: make the message nicer by including the ./configure option argument
directly in output

6 years agopid1: add ./configure switch to select default cgroup hierarchy
Zbigniew Jędrzejewski-Szmek [Sun, 19 Feb 2017 04:13:15 +0000 (23:13 -0500)]
pid1: add ./configure switch to select default cgroup hierarchy

The default default is set to "legacy", with "hybrid" and "unified"
being the other two alternatives.

There invert the behaviour for elogind.legacy_elogind_cgroup_controller:
if it is not specified on the kernel command line, "hybrid" is used if
selected as the default. If this option is specified, "hybrid" is used if false,
and full "legacy" if true.

Also make all fields in the configure summary lowercase (unless they are
capitalized names) for consistency.

v2:
- update for the fixed interpreation of elogind.legacy_elogind_cgroup_controller

6 years agoTighten checking for variable validity
Zbigniew Jędrzejewski-Szmek [Sat, 18 Feb 2017 03:56:28 +0000 (22:56 -0500)]
Tighten checking for variable validity

In the future we might want to allow additional syntax (for example
"unset VAR". But let's check that the data we're getting does not contain
anything unexpected.

6 years agomissing: add renameat2() definition for 64bit arm (#5378)
Lennart Poettering [Fri, 17 Feb 2017 18:10:09 +0000 (19:10 +0100)]
missing: add renameat2() definition for 64bit arm (#5378)

Following a similar commit in casync:

https://github.com/elogind/casync/pull/10

6 years agovirt: Update cache if the detected vm is virtualbox (#5364)
Benjamin Robin [Fri, 17 Feb 2017 07:45:30 +0000 (08:45 +0100)]
virt: Update cache if the detected vm is virtualbox (#5364)

6 years agohostname-util: default to the compile time default hostname in gethostname_malloc()
Lennart Poettering [Thu, 16 Feb 2017 11:02:17 +0000 (12:02 +0100)]
hostname-util: default to the compile time default hostname in gethostname_malloc()

Currently, if the hostname is not set gethostname_malloc() defaults to
the "sysname", which is "linux" on Linux. Let's change that to also
honour the compile-time fallback hostname as specified on the configure
command line.

6 years agovirt: swap order of cpuid and dmi again, but properly detect oracle (#5355)
Christian Hesse [Wed, 15 Feb 2017 22:51:31 +0000 (23:51 +0100)]
virt: swap order of cpuid and dmi again, but properly detect oracle (#5355)

This breaks again, this time for setups where Qemu is not reported via DMI for whatever
reason. So swap order of cpuid and dmi again, but properly detect oracle.

See issue #5318.

6 years agovirt: detect qemu/kvm as 'kvm'
Christian Hesse [Tue, 14 Feb 2017 13:51:12 +0000 (14:51 +0100)]
virt: detect qemu/kvm as 'kvm'

In commit 050e65a we swapped order of detect_vm_{cpuid,dmi}(). That
fixed Virtualbox but broke qemu with kvm, which is expected to return
'kvm'. So check for qemu/kvm first, then DMI, CPUID last.

This fixes #5318.

Signed-off-by: Christian Hesse <mail@eworm.de>
6 years agomachined: when copying files from/to userns containers chown to root
Lennart Poettering [Mon, 13 Feb 2017 18:24:01 +0000 (19:24 +0100)]
machined: when copying files from/to userns containers chown to root

This changes the file copy logic of machined to set the UID/GID of all
copied files to 0 if the host and container do not share the same user
namespace.

Fixes: #4078
6 years agocopy: change the various copy_xyz() calls to take a unified flags parameter
Lennart Poettering [Mon, 13 Feb 2017 18:00:22 +0000 (19:00 +0100)]
copy: change the various copy_xyz() calls to take a unified flags parameter

This adds a unified "copy_flags" parameter to all copy_xyz() function
calls, replacing the various boolean flags so far used. This should make
many invocations more readable as it is clear what behaviour is
precisely requested. This also prepares ground for adding support for
more modes later on.

6 years agocore/manager: split out creation of serialization fd out to a helper
Zbigniew Jędrzejewski-Szmek [Sat, 11 Feb 2017 23:33:16 +0000 (18:33 -0500)]
core/manager: split out creation of serialization fd out to a helper

There is a slight change in behaviour: the user manager for root will create a
temporary file in /run/elogind, not /tmp. I don't think this matters, but
simplifies implementation.

6 years agoAllow braceless variables to be expanded
Zbigniew Jędrzejewski-Szmek [Sat, 11 Feb 2017 19:05:10 +0000 (14:05 -0500)]
Allow braceless variables to be expanded

(Only in environment.d files.)

We have only basic compatibility with shell syntax, but specifying variables
without using braces is probably more common, and I think a lot of people would
be surprised if this didn't work.

6 years agoenv-util,fileio: immediately replace variables in load_env_file_push()
Zbigniew Jędrzejewski-Szmek [Sat, 11 Feb 2017 04:08:53 +0000 (23:08 -0500)]
env-util,fileio: immediately replace variables in load_env_file_push()

strv_env_replace was calling env_match(), which in effect allowed multiple
values for the same key to be inserted into the environment block. That's
pointless, because APIs to access variables only return a single value (the
latest entry), so it's better to keep the block clean, i.e. with just a single
entry for each key.

Add a new helper function that simply tests if the part before '=' is equal in
two strings and use that in strv_env_replace.

In load_env_file_push, use strv_env_replace to immediately replace the previous
assignment with a matching name.

Afaict, none of the callers are materially affected by this change, but it
seems like some pointless work was being done, if the same value was set
multiple times. We'd go through parsing and assigning the value for each
entry. With this change, we handle just the last one.

6 years agobasic/fileio: add helper function for a set of two common checks
Zbigniew Jędrzejewski-Szmek [Sat, 11 Feb 2017 03:14:03 +0000 (22:14 -0500)]
basic/fileio: add helper function for a set of two common checks

6 years agoman: update pam_elogind and elogind-logind man pages a bit
Lennart Poettering [Thu, 9 Feb 2017 17:40:42 +0000 (18:40 +0100)]
man: update pam_elogind and elogind-logind man pages a bit

This builds on @utezduyar's #4640, but extends on it.

Fixes: #4550
Replaces: #4640

6 years agosd-event: "when exiting no signal event are pending" is a wrong assertion (#5271)
Franck Bui [Wed, 8 Feb 2017 19:56:22 +0000 (20:56 +0100)]
sd-event: "when exiting no signal event are pending" is a wrong assertion (#5271)

The code make the following assertion: when freeing a event loop object
(usually it's done after exiting from the main event loop), no signal events
are still queued and are pending.

This assertion can be found in event_unmask_signal_data() with
"assert(!d->current);" assertion.

It appears that this assertion can be wrong at least in a specific case
described below.

Consider the following example which is inspired from udev: a process defines 3
source events: 2 are created by sd_event_add_signal() and 1 is created by
sd_event_add_post().

 1. the process receives the 2 signals consecutively so that signal 'A' source
     event is queued and pending. Consequently the post source event is also
     queued and pending. This is done by sd_event_wait().

 2. The callback for signal 'A' is called by sd_event_dispatch().

 3. The next call to sd_event_wait() will queue signal 'B' source event.

 4. The callback for the post source event is called and calls sd_event_exit().

 5. the event loop is exited.

 6. freeing the event loop object will lead to the assertion failure in
     event_unmask_signal_data().

This patch simply removes this assertion as it doesn't seem to be a
bug if the signal data still reference a signal source at this point.

6 years agotree-wide: make bus_map_all_properties return a proper sd_bus_error
Lennart Poettering [Wed, 8 Feb 2017 16:59:58 +0000 (17:59 +0100)]
tree-wide: make bus_map_all_properties return a proper sd_bus_error

And then show it, to make things a bit friendlier to the user if we fail
acquiring some props.

In fact, this fixes a number of actual bugs, where we used an error
structure for output that we actually never got an error in.

6 years agobasic/dirent-util: allow suffix to be omitted for dirent_is_file_with_suffix
Zbigniew Jędrzejewski-Szmek [Wed, 8 Feb 2017 02:06:38 +0000 (21:06 -0500)]
basic/dirent-util: allow suffix to be omitted for dirent_is_file_with_suffix

6 years agol10n: fix file permissions of Indonesian translation
AsciiWolf [Tue, 7 Feb 2017 18:02:01 +0000 (19:02 +0100)]
l10n: fix file permissions of Indonesian translation

6 years agoman: document that sd_notify() is racy in some cases
Lennart Poettering [Mon, 6 Feb 2017 12:49:44 +0000 (13:49 +0100)]
man: document that sd_notify() is racy in some cases

6 years agotreewide: replace homegrown memory_erase with explicit_bzero
Zbigniew Jędrzejewski-Szmek [Mon, 6 Feb 2017 01:05:27 +0000 (20:05 -0500)]
treewide: replace homegrown memory_erase with explicit_bzero

explicit_bzero was added in glibc 2.25. Make use of it.

explicit_bzero is hardcoded to zero the memory, so string erase now
truncates the string, instead of overwriting it with 'x'. This causes
a visible difference only in the journalctl case.

6 years agotime-util: Fix overflow check introduce in commit f977849 (#5216)
Benjamin Robin [Fri, 3 Feb 2017 15:13:55 +0000 (16:13 +0100)]
time-util: Fix overflow check introduce in commit f977849 (#5216)

6 years agomanager: refuse reloading/reexecing when /run is overly full
Lennart Poettering [Fri, 3 Feb 2017 11:12:54 +0000 (12:12 +0100)]
manager: refuse reloading/reexecing when /run is overly full

Let's add an extra safety check: before entering a reload/reexec, let's
verify that there's enough room in /run for it.

Fixes: #5016
6 years agologind: Don't try to emit a change signal for the 'Sessions' property (#5211)
afrantzis [Fri, 3 Feb 2017 01:39:26 +0000 (03:39 +0200)]
logind: Don't try to emit a change signal for the 'Sessions' property (#5211)

The 'Sessions' property for both org.freedesktop.login1.User and
org.freedesktop.login1.Seat is marked as EmitsChangedSignal(false).
Trying to emit a change signal that includes the 'Sessions' property
leads to the signal not being sent at all.

Fixes #5210.

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.