chiark / gitweb /
elogind.git
5 years agologind-user.c: As we need special.h elsewhere now, use it here, too.
Sven Eden [Fri, 8 Jun 2018 06:35:24 +0000 (08:35 +0200)]
logind-user.c: As we need special.h elsewhere now, use it here, too.

(cherry picked from commit a96cb75c17b008312fca8f81bc2a126f8a87850c)

5 years agopam_elogind.c: Remove renames by mask, check_tree.pl can handle this now.
Sven Eden [Fri, 8 Jun 2018 06:30:56 +0000 (08:30 +0200)]
pam_elogind.c: Remove renames by mask, check_tree.pl can handle this now.

(cherry picked from commit 6964ec46218d41d699690ed590026249969b2257)

5 years agomeson.build: remove unnecessary `ln --relative` check
Kylie McClain [Thu, 7 Jun 2018 04:23:07 +0000 (00:23 -0400)]
meson.build: remove unnecessary `ln --relative` check

`ln --relative` is used by tools/meson-make-symlink.sh, which is never once
ran during the build process for elogind. additionally, it incurrs a
dependency on GNU coreutils (or any other `ln` that has the non-standard
`--relative` extension), so there's no real need to check for it.

5 years agoAdd https://github.com/Yamakuzure/pwx-elogind-migration-tools.git as submodule 'pwx'
Sven Eden [Wed, 6 Jun 2018 06:04:06 +0000 (08:04 +0200)]
Add https://github.com/Yamakuzure/pwx-elogind-migration-tools.git as submodule 'pwx'

5 years agoRename pwx to pwx_local as a backup.
Sven Eden [Wed, 6 Jun 2018 06:03:09 +0000 (08:03 +0200)]
Rename pwx to pwx_local as a backup.

5 years agopwx/last_mutual_commits.csv: Add last mutual before branching out v238-stable
Sven Eden [Tue, 5 Jun 2018 17:15:47 +0000 (19:15 +0200)]
pwx/last_mutual_commits.csv: Add last mutual before branching out v238-stable

5 years agoPrep v238: Uncomment now needed headers and unmask now needed functions in src/test...
Sven Eden [Tue, 5 Jun 2018 17:08:31 +0000 (19:08 +0200)]
Prep v238: Uncomment now needed headers and unmask now needed functions in src/test (6/6)

5 years agoPrep v238: Uncomment now needed headers and unmask now needed functions in src/shared...
Sven Eden [Tue, 5 Jun 2018 17:08:31 +0000 (19:08 +0200)]
Prep v238: Uncomment now needed headers and unmask now needed functions in src/shared (5/6)

5 years agoPrep v238: Uncomment now needed headers and unmask now needed functions in src/login...
Sven Eden [Tue, 5 Jun 2018 17:08:31 +0000 (19:08 +0200)]
Prep v238: Uncomment now needed headers and unmask now needed functions in src/login (4/6)

5 years agoPrep v238: Uncomment now needed headers and unmask now needed functions in src/libelo...
Sven Eden [Tue, 5 Jun 2018 17:08:31 +0000 (19:08 +0200)]
Prep v238: Uncomment now needed headers and unmask now needed functions in src/libelogind (3/6)

5 years agoPrep v238: Uncomment now needed headers and unmask now needed functions in src/core...
Sven Eden [Tue, 5 Jun 2018 17:08:31 +0000 (19:08 +0200)]
Prep v238: Uncomment now needed headers and unmask now needed functions in src/core (2/6)

5 years agoPrep v238: Uncomment now needed headers and unmask now needed functions in src/basic...
Sven Eden [Tue, 5 Jun 2018 17:08:31 +0000 (19:08 +0200)]
Prep v238: Uncomment now needed headers and unmask now needed functions in src/basic (1/6)

5 years agoPrep v238: Apply some upstream fixes to the sections elogind pendants.
Sven Eden [Tue, 5 Jun 2018 17:06:28 +0000 (19:06 +0200)]
Prep v238: Apply some upstream fixes to the sections elogind pendants.

5 years agoPrep v238: Remove obsolete sources and add missing new ones.
Sven Eden [Tue, 5 Jun 2018 17:03:51 +0000 (19:03 +0200)]
Prep v238: Remove obsolete sources and add missing new ones.

5 years agoPrep v238: removed superfluous files that slithered in during upstream commit migration.
Sven Eden [Fri, 1 Jun 2018 18:23:08 +0000 (20:23 +0200)]
Prep v238: removed superfluous files that slithered in during upstream commit migration.

5 years agoPrep v238: Fixed meson.build files in src/shared and src/test
Sven Eden [Fri, 1 Jun 2018 18:22:28 +0000 (20:22 +0200)]
Prep v238: Fixed meson.build files in src/shared and src/test

5 years agoPrep v238: Applied some upstream updates to src/libelogind (5/5)
Sven Eden [Fri, 1 Jun 2018 18:21:49 +0000 (20:21 +0200)]
Prep v238: Applied some upstream updates to src/libelogind (5/5)

5 years agoPrep v238: Applied some upstream updates to src/core (4/5)
Sven Eden [Fri, 1 Jun 2018 18:21:35 +0000 (20:21 +0200)]
Prep v238: Applied some upstream updates to src/core (4/5)

5 years agoPrep v238: Applied some upstream updates to src/basic (3/5)
Sven Eden [Fri, 1 Jun 2018 18:21:25 +0000 (20:21 +0200)]
Prep v238: Applied some upstream updates to src/basic (3/5)

5 years agoPrep v238: Updated root build files (2/5)
Sven Eden [Fri, 1 Jun 2018 18:21:05 +0000 (20:21 +0200)]
Prep v238: Updated root build files (2/5)

5 years agoPrep v238: Applied some upstream updates to man (1/5)
Sven Eden [Fri, 1 Jun 2018 18:20:09 +0000 (20:20 +0200)]
Prep v238: Applied some upstream updates to man (1/5)

6 years agoPrep v238: Move CODING_STYLE to doc/ mirroring upstream
Sven Eden [Fri, 1 Jun 2018 18:07:42 +0000 (20:07 +0200)]
Prep v238: Move CODING_STYLE to doc/ mirroring upstream

6 years agocheck_tree.pl: A few minor cleanups.
Sven Eden [Wed, 30 May 2018 15:46:30 +0000 (17:46 +0200)]
check_tree.pl: A few minor cleanups.

6 years agoSave last mutual commit for migration to v238 tag.
Sven Eden [Wed, 30 May 2018 05:59:31 +0000 (07:59 +0200)]
Save last mutual commit for migration to v238 tag.

6 years agoNEWS: bump version and add contributors
Zbigniew Jędrzejewski-Szmek [Mon, 5 Mar 2018 16:13:38 +0000 (17:13 +0100)]
NEWS: bump version and add contributors

6 years agomeson: bump so revision and systemd version in preparation for v238
Zbigniew Jędrzejewski-Szmek [Mon, 5 Mar 2018 16:12:48 +0000 (17:12 +0100)]
meson: bump so revision and systemd version in preparation for v238

6 years agomailmap: one more person
Zbigniew Jędrzejewski-Szmek [Mon, 5 Mar 2018 16:08:01 +0000 (17:08 +0100)]
mailmap: one more person

6 years agologin: remember that fds received from PID1 need to be removed eventually
Alan Jenkins [Sat, 3 Mar 2018 18:44:39 +0000 (18:44 +0000)]
login: remember that fds received from PID1 need to be removed eventually

Remember to set sd->pushed_fd when we receive an fd from PID1 on startup,
the same as we set it when we send an fd to PID1.

6 years agologin: fix FDNAME in call to sd_pid_notify_with_fds()
Alan Jenkins [Sat, 3 Mar 2018 18:37:50 +0000 (18:37 +0000)]
login: fix FDNAME in call to sd_pid_notify_with_fds()

$ git grep FDNAME
logind-session-device.c: ... "FDNAME=session-", sd->session->id);
logind-session-device.c: ... "FDNAME=session", sd->session->id);

Oops.

Fixes #8343.  Or at least a more minimal reproducer.  Xorg still
dies when logind is restarted, but the Xorg message says this
is entirely deliberate.

(This could also be the reason I hit #8035, instead of the race
condition I originally suggested).

6 years agoNEWS: update for v238
Zbigniew Jędrzejewski-Szmek [Mon, 5 Mar 2018 09:25:17 +0000 (10:25 +0100)]
NEWS: update for v238

6 years agoman: just use unicode for an mdash
Zbigniew Jędrzejewski-Szmek [Mon, 5 Mar 2018 08:31:17 +0000 (09:31 +0100)]
man: just use unicode for an mdash

6 years agoupdate TODO
Lennart Poettering [Fri, 2 Mar 2018 15:25:27 +0000 (16:25 +0100)]
update TODO

6 years agofd-util: drop stdio_unset_cloexec(), it's not used anymore
Lennart Poettering [Wed, 28 Feb 2018 22:24:50 +0000 (23:24 +0100)]
fd-util: drop stdio_unset_cloexec(), it's not used anymore

6 years agosd-bus: let's better not invade stdio territory when duplicating fds
Lennart Poettering [Wed, 28 Feb 2018 22:36:33 +0000 (23:36 +0100)]
sd-bus: let's better not invade stdio territory when duplicating fds

6 years agotree-wide: port various places over to use new rearrange_stdio()
Lennart Poettering [Wed, 28 Feb 2018 22:32:49 +0000 (23:32 +0100)]
tree-wide: port various places over to use new rearrange_stdio()

6 years agoterminal-util: port some generic code over to rearrange_stdio()
Lennart Poettering [Wed, 28 Feb 2018 20:21:33 +0000 (21:21 +0100)]
terminal-util: port some generic code over to rearrange_stdio()

6 years agofd-util: add new call rearrange_stdio()
Lennart Poettering [Wed, 28 Feb 2018 09:00:26 +0000 (10:00 +0100)]
fd-util: add new call rearrange_stdio()

Quite often we need to set up a number of fds as stdin/stdout/stderr of
a process we are about to start. Add a generic implementation for a
routine doing that that takes care to do so properly:

1. Can handle the case where stdin/stdout/stderr where previously
   closed, and the fds to set as stdin/stdout/stderr hence likely in the
   0..2 range.  handling this properly is nasty, since we need to first
   move the fds out of this range in order to later move them back in, to
   make things fully robust.

2. Can optionally open /dev/null in case for one or more of the fds, in
   a smart way, sharing the open file if possible between multiple of
   the fds.

3. Guarantees that O_CLOEXEC is not set on the three fds, even if the fds
   already were in the 0..2 range and hence possibly weren't moved.

6 years agoupdate TODO
Lennart Poettering [Wed, 28 Feb 2018 19:21:57 +0000 (20:21 +0100)]
update TODO

6 years agococcinelle: add reallocarray() coccinelle script
Lennart Poettering [Tue, 27 Feb 2018 18:09:22 +0000 (19:09 +0100)]
coccinelle: add reallocarray() coccinelle script

Let's systematically make use of reallocarray() whereever we invoke
realloc() with a product of two values.

6 years agomeson: use dashes in colour names
Zbigniew Jędrzejewski-Szmek [Fri, 2 Mar 2018 08:09:29 +0000 (09:09 +0100)]
meson: use dashes in colour names

6 years agoAdd build-time option to change the color of the "OK" status text
Alexander F Rødseth [Thu, 1 Mar 2018 12:12:02 +0000 (13:12 +0100)]
Add build-time option to change the color of the "OK" status text

6 years agoOrganize the ANSI codes and add missing colors
Alexander F Rødseth [Thu, 1 Mar 2018 17:23:05 +0000 (18:23 +0100)]
Organize the ANSI codes and add missing colors

For consistency.

6 years agologind: fix typo in comment
Lennart Poettering [Fri, 2 Mar 2018 10:56:15 +0000 (11:56 +0100)]
logind: fix typo in comment

6 years agologind: open device if needed
Lennart Poettering [Fri, 2 Mar 2018 10:55:51 +0000 (11:55 +0100)]
logind: open device if needed

Fixes: #8291
6 years agologind: cast away return value we don't care about
Lennart Poettering [Fri, 2 Mar 2018 10:55:33 +0000 (11:55 +0100)]
logind: cast away return value we don't care about

6 years agologind: voidify a function we never check the return value of
Lennart Poettering [Fri, 2 Mar 2018 10:55:16 +0000 (11:55 +0100)]
logind: voidify a function we never check the return value of

6 years agomount-setup: change bpf mount mode to 0700 (#8334)
Lennart Poettering [Fri, 2 Mar 2018 11:55:24 +0000 (12:55 +0100)]
mount-setup: change bpf mount mode to 0700 (#8334)

After discussing with the kernel folks, we agreed to default to 0700 for
this. Better safe than sorry.

6 years agoRemove /sbin from paths if split-bin is false (#8324)
Zbigniew Jędrzejewski-Szmek [Thu, 1 Mar 2018 20:48:36 +0000 (21:48 +0100)]
Remove /sbin from paths if split-bin is false (#8324)

Follow-up for 157baa87e4.

6 years agomeson: support both separate and merged sbin-bin directories
Zbigniew Jędrzejewski-Szmek [Thu, 1 Mar 2018 09:28:29 +0000 (10:28 +0100)]
meson: support both separate and merged sbin-bin directories

Follow-up for ba7f4ae6178309dc937e10cf7dce0eca9dafb8de.

By default, we detect if the real root has a separate /usr/sbin directory, but
this can be overrides with -Dsplit-bin=true|false. The check assumes that
/usr/sbin is split if it is not a symlink, so it'll return a false negative
with some more complicated setups. But that's OK, in those cases this should be
configured explicitly.

This will copy the structure of the directories in the root file system to
$DESTDIR. If a directory is a directory in $DESTDIR but a symlink in the root
file system, this script will fail. This means that it's not possible to reuse
a $DESTDIR from between ba7f4ae61 and this patch.

6 years agomeson: autodetect split-usr
Zbigniew Jędrzejewski-Szmek [Thu, 1 Mar 2018 10:49:42 +0000 (11:49 +0100)]
meson: autodetect split-usr

Also move the status from "features" to the paths section. This is more of an
anti-feature.

6 years agoprocfs-util: drop unnecessary zero initializations (#8321)
Lennart Poettering [Thu, 1 Mar 2018 10:27:06 +0000 (11:27 +0100)]
procfs-util: drop unnecessary zero initializations (#8321)

Follow-up for #8149.

6 years agobasic/cgroup-util: simplify cg_get_keyed_attribute(), add test
Zbigniew Jędrzejewski-Szmek [Thu, 1 Mar 2018 08:30:55 +0000 (09:30 +0100)]
basic/cgroup-util: simplify cg_get_keyed_attribute(), add test

I didn't like the nested loop where we'd count what we have acquired already,
since we should always know that.

6 years agoupdate TODO
Lennart Poettering [Fri, 9 Feb 2018 18:43:35 +0000 (19:43 +0100)]
update TODO

6 years agocore: turn on memory/cpu/tasks accounting by default for the root slice
Lennart Poettering [Fri, 9 Feb 2018 18:07:01 +0000 (19:07 +0100)]
core: turn on memory/cpu/tasks accounting by default for the root slice

The kernel exposes the necessary data in /proc anyway, let's expose it
hence by default.

With this in place "systemctl status -- -.slice" will show accounting
data out-of-the-box now.

6 years agocore: hook up /proc queries for the root slice, too
Lennart Poettering [Fri, 9 Feb 2018 18:05:59 +0000 (19:05 +0100)]
core: hook up /proc queries for the root slice, too

Do what we already prepped in cgtop for the root slice in PID 1 too:
consult /proc for the data we need.

6 years agocgroup-util: rework cg_get_keyed_attribute() a bit
Lennart Poettering [Fri, 9 Feb 2018 17:35:52 +0000 (18:35 +0100)]
cgroup-util: rework cg_get_keyed_attribute() a bit

Let's make sure we don't clobber the return parameter on failure, to
follow our coding style. Also, break the loop early if we have all
attributes we need.

This also changes the keys parameter to a simple char**, so that we can
use STRV_MAKE() for passing the list of attributes to read.

This also makes it possible to distuingish the case when the whole
attribute file doesn't exist from one key in it missing. In the former
case we return -ENOENT, in the latter we now return -ENXIO.

6 years agoprocfs-util: add APIs to get consumed CPU time and used memory from /proc
Lennart Poettering [Fri, 9 Feb 2018 16:32:26 +0000 (17:32 +0100)]
procfs-util: add APIs to get consumed CPU time and used memory from /proc

This is preparation for emulating the "usage_usec" keyed attribute of
the "cpu.stat" property of the root cgroup from data in /proc. Similar,
for emulating the "memory.current" attribute.

6 years agocore: don't process dbus unit and job queue when there are already too many messages...
Lennart Poettering [Tue, 13 Feb 2018 17:30:34 +0000 (18:30 +0100)]
core: don't process dbus unit and job queue when there are already too many messages pending

We maintain a queue of units and jobs that we are supposed to generate
change/new notifications for because they were either just created or
some of their property has changed. Let's throttle processing of this
queue a bit: as soon as > 1K of bus messages are queued for writing
let's skip processing the queue, and then recheck on the next
iteration again.

Moreover, never process more than 100 units in one go, return to the
event loop after that. Both limits together should put effective limits
on both space and time usage of the function, delaying further
operations until a later moment, when the queue is empty or the the
event loop is sufficiently idle again.

This should keep the number of generated messages much lower than
before on busy systems or where some client is hanging.

Note that this also means a bad client can slow down message dispatching
substantially for up to 90s if it likes to, for all clients. But that
should be acceptable as we only allow trusted bus clients, anyway.

Fixes: #8166
6 years agosd-bus: add APIs to query the current read and write queue size
Lennart Poettering [Tue, 13 Feb 2018 17:27:05 +0000 (18:27 +0100)]
sd-bus: add APIs to query the current read and write queue size

6 years agoprocess-util: don't install atfork() handler more than once
Lennart Poettering [Mon, 26 Feb 2018 19:50:57 +0000 (20:50 +0100)]
process-util: don't install atfork() handler more than once

6 years agoutil: add new safe_close_above_stdio() wrapper
Lennart Poettering [Mon, 26 Feb 2018 14:41:38 +0000 (15:41 +0100)]
util: add new safe_close_above_stdio() wrapper

At various places we only want to close fds if they are not
stdin/stdout/stderr, i.e. fds 0, 1, 2. Let's add a unified helper call
for that, and port everything over.

6 years agomeson: install compat symlinks for systemctl and systemd (#8300)
Zbigniew Jędrzejewski-Szmek [Wed, 28 Feb 2018 09:20:48 +0000 (10:20 +0100)]
meson: install compat symlinks for systemctl and systemd (#8300)

v2:
- init is a symlink to systemd, not systemctl!

6 years agodoc: add a new doc/ directory, and move two markdown docs into them
Lennart Poettering [Mon, 26 Feb 2018 10:48:46 +0000 (11:48 +0100)]
doc: add a new doc/ directory, and move two markdown docs into them

I figure sooneror later we'll have more of these docs, hence let's give
them a clean place to be.

This leaves NEWS and README/README.md as well as the LICENSE texts in
the root directory of the project since that appears to be customary for
Free Software projects.

6 years agorules: add a missing comma in 70-uaccess.rules since it improves readability
Franck Bui [Fri, 23 Feb 2018 15:49:17 +0000 (16:49 +0100)]
rules: add a missing comma in 70-uaccess.rules since it improves readability

rule-syntax-check.py failed with the following error:

$ ./test/rule-syntax-check.py ./src/login/70-uaccess.rules
Invalid line ./src/login/70-uaccess.rules:31: SUBSYSTEM=="sound", TAG+="uaccess"   OPTIONS+="static_node=snd/timer", OPTIONS+="static_node=snd/seq"
  clause: TAG+="uaccess"   OPTIONS+="static_node=snd/timer"

The comma is actually optional but the script makes it mandatory which seems a
good thing since it improves readability.

6 years agomissing_syscall: add pkey_mprotect for ppc (#8292)
Zbigniew Jędrzejewski-Szmek [Tue, 27 Feb 2018 12:33:00 +0000 (13:33 +0100)]
missing_syscall: add pkey_mprotect for ppc (#8292)

Accurate for both ppc and ppc64 according to https://fedora.juszkiewicz.com.pl/syscalls.html.

6 years agokhash: try to detect broken AF_ALG support in centos kernels
Lennart Poettering [Mon, 26 Feb 2018 12:46:58 +0000 (13:46 +0100)]
khash: try to detect broken AF_ALG support in centos kernels

Fixes: #8278
6 years agosd-login: make use of _cleanup_close_ where possible
Lennart Poettering [Mon, 26 Feb 2018 17:45:45 +0000 (18:45 +0100)]
sd-login: make use of _cleanup_close_ where possible

6 years agologind: make sure we don't trip up on half-initialized session devices
Lennart Poettering [Mon, 26 Feb 2018 17:34:49 +0000 (18:34 +0100)]
logind: make sure we don't trip up on half-initialized session devices

Fixes: #8035
6 years agologind: check file is device node before using .st_rdev
Lennart Poettering [Mon, 26 Feb 2018 17:34:43 +0000 (18:34 +0100)]
logind: check file is device node before using .st_rdev

6 years agologind: let's pack a few struct fields we can pack
Lennart Poettering [Mon, 26 Feb 2018 17:34:13 +0000 (18:34 +0100)]
logind: let's pack a few struct fields we can pack

6 years agologind: fd 0 is a valid fd
Lennart Poettering [Mon, 26 Feb 2018 17:33:51 +0000 (18:33 +0100)]
logind: fd 0 is a valid fd

6 years agologind: let's reduce one level of indentation
Lennart Poettering [Mon, 26 Feb 2018 17:33:20 +0000 (18:33 +0100)]
logind: let's reduce one level of indentation

6 years agologind: propagate the right error, don't make up ENOMEM
Lennart Poettering [Mon, 26 Feb 2018 17:33:05 +0000 (18:33 +0100)]
logind: propagate the right error, don't make up ENOMEM

6 years agologind: rework sd_eviocrevoke()
Lennart Poettering [Mon, 26 Feb 2018 17:32:07 +0000 (18:32 +0100)]
logind: rework sd_eviocrevoke()

Let's initialize static variables properly and get rid of redundant
variables.

6 years agologind: trivial improvements
Lennart Poettering [Mon, 26 Feb 2018 17:31:06 +0000 (18:31 +0100)]
logind: trivial improvements

Just some addition whitespace, some additional assert()s, and removal of
redundant variables.

6 years agobasic/xattr-util: do not cast ssize_t to int
Zbigniew Jędrzejewski-Szmek [Sun, 25 Feb 2018 20:25:33 +0000 (21:25 +0100)]
basic/xattr-util: do not cast ssize_t to int

gcc warns about unitialized memory access because it notices that ssize_t which
is < 0 could be cast to positive int value. We know that this can't really
happen because only -1 can be returned, but OTOH, in principle a large
*positive* value cannot be cast properly. This is unlikely too, since xattrs
cannot be too large, but it seems cleaner to just use a size_t to return the
value and avoid the cast altoghter. This makes the code simpler and gcc is
happy too.

The following warning goes away:
[113/1502] Compiling C object 'src/basic/basic@sta/xattr-util.c.o'.
In file included from ../src/basic/alloc-util.h:28:0,
                 from ../src/basic/xattr-util.c:30:
../src/basic/xattr-util.c: In function ‘fd_getcrtime_at’:
../src/basic/macro.h:207:60: warning: ‘b’ may be used uninitialized in this function [-Wmaybe-uninitialized]
                 UNIQ_T(A,aq) < UNIQ_T(B,bq) ? UNIQ_T(A,aq) : UNIQ_T(B,bq); \
                                                            ^
../src/basic/xattr-util.c:155:19: note: ‘b’ was declared here
         usec_t a, b;
                   ^

6 years agobasic/exec-util: use _exit() to return from child
Zbigniew Jędrzejewski-Szmek [Sun, 25 Feb 2018 20:07:18 +0000 (21:07 +0100)]
basic/exec-util: use _exit() to return from child

6 years agobasic: shorten the code a bit in two places
Zbigniew Jędrzejewski-Szmek [Sun, 25 Feb 2018 16:26:22 +0000 (17:26 +0100)]
basic: shorten the code a bit in two places

gcc complains that len might be used unitialized, but afaict, this is not true.

6 years agotree-wide: use reallocarray instead of our home-grown realloc_multiply (#8279)
Zbigniew Jędrzejewski-Szmek [Mon, 26 Feb 2018 20:20:00 +0000 (21:20 +0100)]
tree-wide: use reallocarray instead of our home-grown realloc_multiply (#8279)

There isn't much difference, but in general we prefer to use the standard
functions. glibc provides reallocarray since version 2.26.

I moved explicit_bzero is configure test to the bottom, so that the two stdlib
functions are at the bottom.

6 years agobasic/virt: provide a nicer message is /proc/cpuinfo is not available
Zbigniew Jędrzejewski-Szmek [Fri, 23 Feb 2018 11:49:15 +0000 (12:49 +0100)]
basic/virt: provide a nicer message is /proc/cpuinfo is not available

$ sudo systemd-run -p RootDirectory=/usr -E LD_LIBRARY_PATH=/lib/systemd/ -E SYSTEMD_LOG_LEVEL=debug /bin/systemd-detect-virt

Before
systemd-detect-virt[18498]: No virtualization found in DMI
systemd-detect-virt[18498]: No virtualization found in CPUID
systemd-detect-virt[18498]: Virtualization XEN not found, /proc/xen does not exist
systemd-detect-virt[18498]: This platform does not support /proc/device-tree
systemd-detect-virt[18498]: Failed to check for virtualization: No such file or directory

The first four lines are at debug level, so the user would only see that last
one usually, which is not very enlightening.

This now becomes:
systemd-detect-virt[21172]: No virtualization found in DMI
systemd-detect-virt[21172]: No virtualization found in CPUID
systemd-detect-virt[21172]: Virtualization XEN not found, /proc/xen does not exist
systemd-detect-virt[21172]: This platform does not support /proc/device-tree
systemd-detect-virt[21172]: /proc/cpuinfo not found, assuming no UML virtualization.
systemd-detect-virt[21172]: This platform does not support /proc/sysinfo
systemd-detect-virt[21172]: Found VM virtualization none
systemd-detect-virt[21172]: none

We do more checks, which is good too.

6 years agobasic/log: add an assert that does not recurse into logging functions
Zbigniew Jędrzejewski-Szmek [Fri, 23 Feb 2018 12:29:03 +0000 (13:29 +0100)]
basic/log: add an assert that does not recurse into logging functions

Then it can be used in the asserts in logging functions without causing
infinite recursion. The error is just printed to stderr, it should be
good enough for the common case.

6 years agoudev/net-id: check all snprintf return values
Zbigniew Jędrzejewski-Szmek [Fri, 23 Feb 2018 10:12:19 +0000 (11:12 +0100)]
udev/net-id: check all snprintf return values

gcc-8 throws an error if it knows snprintf might truncate output and the
return value is ignored:
../src/udev/udev-builtin-net_id.c: In function 'dev_pci_slot':
../src/udev/udev-builtin-net_id.c:297:47: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=]
                 snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
                                               ^~
../src/udev/udev-builtin-net_id.c:297:17: note: 'snprintf' output between 10 and 4360 bytes into a destination of size 4096
                 snprintf(str, sizeof str, "%s/%s/address", slots, dent->d_name);
                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

Let's check all return values. This actually makes the code better, because there's
no point in trying to open a file when the name has been truncated, etc.

6 years agobasic/log: make sure header is printed correctly, add test
Zbigniew Jędrzejewski-Szmek [Thu, 22 Feb 2018 22:55:14 +0000 (23:55 +0100)]
basic/log: make sure header is printed correctly, add test

If log_do_header() was called with overly long parameters, it'd generate
improper output. Essentially, it'd be truncated at random point, in particular
missing a newline at the end, so it'd run with the next field, usually MESSAGE=.

log_do_header is called with parameters from compiled code (file name, lien
nubmer, etc), so in practice this was unlikely to ever be a problem, but it is
possible. In particular, if systemd was compiled from sources in some deeply
nested directory (which happens for example in mock and other build roots), the
filename could be very long.

As a safety measure, let's truncate all parameters to 256 bytes. So we have
5 fields which are 256 bytes (plus the field name prefix), and a few other
fields with fixed width. This must always fit in the 2048 byte buffer.
I don't think there's much gain in calculating the required length precisely,
since it's a lot of fields and a few bytes allocated on the stack don't matter.

6 years agobasic/log: fix confusion with parameters to log_dispatch_internal
Zbigniew Jędrzejewski-Szmek [Thu, 22 Feb 2018 22:45:27 +0000 (23:45 +0100)]
basic/log: fix confusion with parameters to log_dispatch_internal

log_dispatch_internal has only one caller where the extra_field/extra
params are not null: log_unit_full. When log_unit_full() was called,
when we got to log_dispatch_internal, our header would look like this:
PRIORITY=7
SYSLOG_FACILITY=3
CODE_FILE=../src/core/manager.c
CODE_LINE=2145
CODE_FUNC=manager_invoke_sigchld_event
USER_UNIT=gnome-terminal-server.service
65dffa7a3b984a6d9a46f0b8fb57710bUSER_INVOCATION_ID=
SYSLOG_IDENTIFIER=systemd

It took me a while to understand why I'm not seeing mangled messages in the
journal (after all, "" is a valid rvalue for log messages). The answer is that
journald rejects any field name which starts with a digit, and the MESSAGE_ID
that was used here starts with a digit. Hence, those lines would be silently
filtered out.

6 years agobasic/log: make log_object_internalv static
Zbigniew Jędrzejewski-Szmek [Thu, 22 Feb 2018 22:07:58 +0000 (23:07 +0100)]
basic/log: make log_object_internalv static

It makes the code easier to read, because it's obvious that the function
cannot be called from elsewhere.

6 years agobasic/log: voidify snprintf statements
Zbigniew Jędrzejewski-Szmek [Thu, 22 Feb 2018 21:09:16 +0000 (22:09 +0100)]
basic/log: voidify snprintf statements

The buffers are fixed size, so the message may not fit, but we don't
particularly care.

6 years agoRevert "Replace use of snprintf with xsprintf"
Zbigniew Jędrzejewski-Szmek [Thu, 22 Feb 2018 21:03:15 +0000 (22:03 +0100)]
Revert "Replace use of snprintf with xsprintf"

This reverts commit a7419dbc59da5c8cc9e90b3d96bc947cad91ae16.

_All_ changes in that commit were wrong.

Fixes #8211.

6 years agologin: fix user@.service case, so we don't allow nested sessions (#8051)
Alan Jenkins [Thu, 22 Feb 2018 20:38:44 +0000 (20:38 +0000)]
login: fix user@.service case, so we don't allow nested sessions (#8051)

> logind sessions are mostly bound to the audit session concept, and audit
> sessions remain unaffected by "su", in fact they are defined to be
> "sealed off", i.e. in a way that if a process entered a session once, it
> will always stay with it, and so will its children, i.e. the only way to
> get a new session is by forking off something off PID 1 (or something
> similar) that never has been part of a session.

The code had a gap.  user@.service is a special case PAM session which does
not create a logind session.  Let's remember to check for it.

Fixes #8021

6 years agoFix format-truncation compile failure by typecasting USB IDs (#8250)
Patrick Uiterwijk [Thu, 22 Feb 2018 18:41:30 +0000 (19:41 +0100)]
Fix format-truncation compile failure by typecasting USB IDs (#8250)

This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit int, and
uses that for parsing USB device and vendor IDs.

This fixes a compile error with gcc-8 because while we know that USB IDs are 2 bytes,
the compiler does not know that.

../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output may be
truncated writing between 4 and 8 bytes into a region of size between 2 and 6
[-Werror=format-truncation=]

Signed-off-by: Adam Williamson <awilliam@redhat.com>
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
6 years agovirt: detect QNX hypervisor Detect QNX hypervisor based on the CPUID.
Shuang Liu [Thu, 22 Feb 2018 13:35:47 +0000 (14:35 +0100)]
virt: detect QNX hypervisor Detect QNX hypervisor based on the CPUID.

Fixes: #7239
6 years agomount-setup: always use the same source as fstype for the API VFS we mount
Lennart Poettering [Fri, 16 Feb 2018 14:49:32 +0000 (15:49 +0100)]
mount-setup: always use the same source as fstype for the API VFS we mount

So far, for all our API VFS mounts we used the fstype also as mount
source, let's do that for the cgroupsv2 mounts too. The kernel doesn't
really care about the source for API VFS, but it's visible to the user,
hence let's clean this up and follow the rule we otherwise follow.

6 years agobpf: use BPF_F_ALLOW_MULTI flag if it is available
Lennart Poettering [Fri, 16 Feb 2018 14:35:49 +0000 (15:35 +0100)]
bpf: use BPF_F_ALLOW_MULTI flag if it is available

This new kernel 4.15 flag permits that multiple BPF programs can be
executed for each packet processed: multiple per cgroup plus all
programs defined up the tree on all parent cgroups.

We can use this for two features:

1. Finally provide per-slice IP accounting (which was previously
   unavailable)

2. Permit delegation of BPF programs to services (i.e. leaf nodes).

This patch beefs up PID1's handling of BPF to enable both.

Note two special items to keep in mind:

a. Our inner-node BPF programs (i.e. the ones we attach to slices) do
   not enforce IP access lists, that's done exclsuively in the leaf-node
   BPF programs. That's a good thing, since that way rules in leaf nodes
   can cancel out rules further up (i.e. for example to implement a
   logic of "disallow everything except httpd.service"). Inner node BPF
   programs to accounting however if that's requested. This is
   beneficial for performance reasons: it means in order to provide
   per-slice IP accounting we don't have to add up all child unit's
   data.

b. When this code is run on pre-4.15 kernel (i.e. where
   BPF_F_ALLOW_MULTI is not available) we'll make IP acocunting on slice
   units unavailable (i.e. revert to behaviour from before this commit).
   For leaf nodes we'll fallback to non-ALLOW_MULTI mode however, which
   means that BPF delegation is not available there at all, if IP
   fw/acct is turned on for the unit. This is a change from earlier
   behaviour, where we use the BPF_F_ALLOW_OVERRIDE flag, so that our
   fw/acct would lose its effect as soon as delegation was turned on and
   some client made use of that. I think the new behaviour is the safer
   choice in this case, as silent bypassing of our fw rules is not
   possible anymore. And if people want proper delegation then the way
   out is a more modern kernel or turning off IP firewalling/acct for
   the unit algother.

6 years agobpf: mount bpffs by default on boot
Lennart Poettering [Fri, 16 Feb 2018 13:59:26 +0000 (14:59 +0100)]
bpf: mount bpffs by default on boot

We make heavy use of BPF functionality these days, hence expose the BPF
file system too by default now. (Note however, that we don't actually
make use bpf file systems object yet, but we might later on too.)

6 years agonologin: extend the /run/nologin descriptions a bit (#8244)
Lennart Poettering [Thu, 22 Feb 2018 13:21:30 +0000 (14:21 +0100)]
nologin: extend the /run/nologin descriptions a bit (#8244)

This is an attempt to improve #8228 a bit, by extending the /run/nologin
a bit, but still keeping it somewhat brief.

On purpose I used the vague wording "unprivileged user" rather than
"non-root user" so that pam_nologin can be updated to disable its
behaviour for members of the "wheel" group one day, and our messages
would still make sense.

See #8228.

6 years agobasic: split out update_reboot_parameter_and_warn() into its own .c/.h files
Lennart Poettering [Wed, 21 Feb 2018 16:54:35 +0000 (17:54 +0100)]
basic: split out update_reboot_parameter_and_warn() into its own .c/.h files

This is primarily preparation for a follow-up commit that adds a common
implementation of the other side of the reboot parameter file, i.e. the
code that reads the file and issues reboot() for it.

6 years agobasic: add a common syscall wrapper around reboot()
Lennart Poettering [Wed, 21 Feb 2018 16:42:59 +0000 (17:42 +0100)]
basic: add a common syscall wrapper around reboot()

This mimics the raw_clone() call we have in place already and
establishes a new syscall wrapper raw_reboot() that wraps the kernel's
reboot() system call in a bit more low-level fashion that glibc's
reboot() wrapper. The main difference is that the extra "arg" argument
is supported.

Ultimately this just replaces the syscall wrapper implementation we
currently have at three places in our codebase by a single one.

With this change this means that all our syscall() invocations are
neatly separated out in static inline system call wrappers in our header
functions.

6 years agomissing: always use __NR_ as prefix for syscall numbers
Lennart Poettering [Wed, 21 Feb 2018 16:27:34 +0000 (17:27 +0100)]
missing: always use __NR_ as prefix for syscall numbers

Apparently, both __NR_ and SYS_ are useful, but we mostly use __NR_
hence use it for these two cases too, so that we settle on __NR_
exclusively.

6 years agomissing: Fix statx syscall ifdeffery
Lennart Poettering [Wed, 21 Feb 2018 16:25:01 +0000 (17:25 +0100)]
missing: Fix statx syscall ifdeffery

Fix a copy/paste mistake.

Fixes: #8238
6 years agotree-wide: reopen log when we need to log in FORK_CLOSE_ALL_FDS children
Lennart Poettering [Wed, 21 Feb 2018 23:35:00 +0000 (00:35 +0100)]
tree-wide: reopen log when we need to log in FORK_CLOSE_ALL_FDS children

In a number of occasions we use FORK_CLOSE_ALL_FDS when forking off a
child, since we don't want to pass fds to the processes spawned (either
because we later want to execve() some other process there, or because
our child might hang around for longer than expected, in which case it
shouldn't keep our fd pinned). This also closes any logging fds, and
thus means logging is turned off in the child. If we want to do proper
logging, explicitly reopen the logs hence in the child at the right
time.

This is particularly crucial in the umount/remount children we fork off
the shutdown binary, as otherwise the children can't log, which is
why #8155 is harder to debug than necessary: the log messages we
generate about failing mount() system calls aren't actually visible on
screen, as they done in the child processes where the log fds are
closed.

6 years agolog: only open kmsg on fallback if we actually want to use it
Lennart Poettering [Wed, 21 Feb 2018 23:31:36 +0000 (00:31 +0100)]
log: only open kmsg on fallback if we actually want to use it

Previously, we'd try to open kmsg on failure of the journal/syslog even
if no automatic fallback to kmsg was requested — and we wouldn't even
use the open connection afterwards...