Commit Graph

3184 Commits

Author SHA1 Message Date
Frantisek Sumsal 15dd451535 tree-wide: codespell fixes
Another batch of codespell fixes as reported by Fossies.org
2020-05-25 10:29:28 +02:00
Lennart Poettering 5b3f4a20ea fileio: sync directory after rename, too 2020-05-21 23:28:48 +02:00
Zbigniew Jędrzejewski-Szmek 7c15a55f8b
Merge pull request #15870 from poettering/proc-cmdline-efi-fix
udev /proc/cmdline handling fixes
2020-05-21 09:07:27 +02:00
Anita Zhang b10ceb4783
Merge pull request #15557 from poettering/journal-zero-fix
journal: deal better with reading from zeroed out journal mmaps
2020-05-20 18:14:51 -07:00
Lennart Poettering 09835de3cc proc-cmdline: make checking of EFI options variable optional
And do not use it in the IMPORT{cmdline} udev code. Wherever we expose
direct interfaces to check the kernel cmdline, let's not consult our
systemd-specific EFI variable, but strictly use the actual kernel
variable, because that's what we claim we do. i.e. it's fine to use the
EFI variable for our own settings, but for the generic APIs to the
kernel cmdline we should not use it.

Specifically, this applies to IMPORT{cmdline} and
ConditionKernelCommandLine=. In the latter case we weren#t checking the
EFI variable anyway, hence let's do the same for the udev case, too.

Fixes: #15739
2020-05-20 19:22:09 +02:00
Lennart Poettering 05a7827e87 proc-cmdline: add checking of EFI options variable in proc_cmdline_get_key_many() too 2020-05-20 19:18:45 +02:00
Lennart Poettering 4b5ee5901c proc-cmdline: fix return value clobbering in proc_cmdline_get_key()
Let's make sure proc_cmdline_get_key() follows our coding style: never
clobber return values on failure, and always initialize on success.
2020-05-20 19:17:44 +02:00
Zbigniew Jędrzejewski-Szmek 6b8664cb5b tree-wide: fix bad errno checks 2020-05-20 18:10:58 +02:00
Zbigniew Jędrzejewski-Szmek a0fa268337 basic/efivars: fix errno propagation
Fixup for 484f4e5b2d. Should fix #15730.
2020-05-20 18:08:05 +02:00
Lennart Poettering 053e0626db fs-util: teach unlinkat_deallocate() a simple scheme for overwriting for erasing
With that it becomes useful for deleting password files and such.
2020-05-19 17:27:13 +02:00
Lennart Poettering 1d06deba0f
Merge pull request #15845 from poettering/btrfs-encrypted-fix
make path_is_encrypted() test pass on btrfs inside container
2020-05-19 17:15:22 +02:00
Lennart Poettering 544e146b0e journalctl,elsewhere: make sure --file=foo fails with sane error msg if foo is not readable
It annoyed me for quite a while that running "journalctl --file=…" on a
file that is not readable failed with a "File not found" error instead
of a permission error. Let's fix that.

We make this work by using the GLOB_NOCHECK flag for glob() which means
that files are not accessible will be returned in the array as they are
instead of being filtered away. This then means that our later attemps
to open the files will fail cleanly with a good error message.
2020-05-19 15:26:51 +02:00
Zbigniew Jędrzejewski-Szmek 7f6b827f36
Merge pull request #15836 from poettering/makefs-lock
lock whole block device file running makefs
2020-05-19 15:23:23 +02:00
Lennart Poettering 3468e5ac51 btrfs-util: tweak error code a bit 2020-05-19 12:12:00 +02:00
Lennart Poettering 3931056767 proc-cmdline: add some explanatory comments 2020-05-18 20:17:57 +02:00
Lennart Poettering ac83e5aeca blockdev: add helper for locking whole block device 2020-05-18 18:41:56 +02:00
Lennart Poettering 6cba41ab0d blockdev: propagate one more unexpected error 2020-05-18 18:41:56 +02:00
Zbigniew Jędrzejewski-Szmek b3d15d90c0
Merge pull request #15804 from poettering/hostnamed-instant-part1
four likely safe commits split out of #15624
2020-05-18 15:26:24 +02:00
Lennart Poettering 7cd9e4f8a0 limit-util: quieten a very common debug message that is misleading 2020-05-15 15:50:09 +02:00
Lennart Poettering 3250501865
Merge pull request #15660 from benjarobin/perf_barrier_fd
Faster manager_process_barrier_fd and drop message if BARRIER=1 found
2020-05-14 09:07:41 +02:00
Lennart Poettering fee5c52ac2 stat-util: add stat_inode_unmodified() helper that checks if an inode was modified 2020-05-13 16:57:44 +02:00
Benjamin Robin 147d8fc1a7 basic: Allow to call STRV_FOREACH_BACKWARDS() with a char * const * strv 2020-05-10 18:57:56 +02:00
Lennart Poettering 0497c4c28a random-util: make use of GRND_INSECURE when it is defined
kernel 5.6 added support for a new flag for getrandom(): GRND_INSECURE.
If we set it we can get some random data out of the kernel random pool,
even if it is not yet initializated. This is great for us to initialize
hash table seeds and such, where it is OK if they are crap initially. We
used RDRAND for these cases so far, but RDRAND is only available on
newer CPUs and some archs. Let's now use GRND_INSECURE for these cases
as well, which means we won't needlessly delay boot anymore even on
archs/CPUs that do not have RDRAND.

Of course we never set this flag when generating crypto keys or uuids.
Which makes it different from RDRAND for us (and is the reason I think
we should keep explicit RDRAND support in): RDRAND we don't trust enough
for crypto keys. But we do trust it enough for UUIDs.
2020-05-10 11:15:16 +02:00
Lennart Poettering e2b5546452 random-util: use ERRNO_IS_NOT_SUPPORTED() macro
Some container mgr or sandbox solution might block it with an unexpected
error code, hence let's be tolerant here.
2020-05-10 11:14:17 +02:00
Lennart Poettering 57ee010ff2 random-util: actually encode our expectations on RAND_MAX 2020-05-10 11:13:49 +02:00
Lennart Poettering 622e1cdb31 fs-util: beef up path_is_encrypted() to deal with LVM block devices
Let's iterate through the slaves/ directory to find backing devices of
the block devices we care about.
2020-05-10 09:23:30 +02:00
Zbigniew Jędrzejewski-Szmek f2a8372e37
Merge pull request #15703 from poettering/homed-tweak-default-storage
homed: avoid double encryption
2020-05-08 16:57:14 +02:00
Zbigniew Jędrzejewski-Szmek 0328d672f3
Merge pull request #15651 from poettering/newlocale-check
check if locales are installed before using them
2020-05-08 11:31:34 +02:00
Zbigniew Jędrzejewski-Szmek 8acb7780df
Merge pull request #15623 from poettering/cmsg-cleanup
various CMSG_xyz clean-ups, split out of #15571
2020-05-08 11:05:06 +02:00
Lennart Poettering ed9c0851e5 fs-util: add helper path_is_encrypted() that checks if a file system is encrypted 2020-05-07 23:31:36 +02:00
Lennart Poettering c60bc8d4fb
Merge pull request #15745 from keszybz/one-more-specifier
Add %l as specifier for short hostname
2020-05-07 22:18:59 +02:00
Zbigniew Jędrzejewski-Szmek e97708fa3e Add %l as specifier for the hostname without any domain component
As described in #15603, it is a fairly common setup to use a fqdn as the
configured hostname. But it is often convenient to use just the actual
hostname, i.e. until the first dot. This adds support in tmpfiles, sysusers,
and unit files for %l which expands to that.

Fixes #15603.
2020-05-07 17:36:44 +02:00
Lennart Poettering 23fa786ca6 locale-util: add new helper locale_is_installed()
This new helper checks whether the specified locale is installed. It's
distinct from locale_is_valid() which just superficially checks if a
string looks like something that could be a valid locale.

Heavily inspired by @jsynacek's #13964.

Replaces: #13964
2020-05-07 17:23:23 +02:00
Zbigniew Jędrzejewski-Szmek 5cea17a177
Merge pull request #15635 from keszybz/set-put-strdup
Let set_put_strdup() allocate the set and related changes
2020-05-07 17:01:59 +02:00
Lennart Poettering fb29cdbef2 tree-wide: make sure our control buffers are properly aligned
We always need to make them unions with a "struct cmsghdr" in them, so
that things properly aligned. Otherwise we might end up at an unaligned
address and the counting goes all wrong, possibly making the kernel
refuse our buffers.

Also, let's make sure we initialize the control buffers to zero when
sending, but leave them uninitialized when reading.

Both the alignment and the initialization thing is mentioned in the
cmsg(3) man page.
2020-05-07 14:39:44 +02:00
Lennart Poettering 0d9d333672 tree-wide: remove redundant assignments
We already initialize the fields a few lines up to the very same values,
hence remove this.
2020-05-07 14:39:44 +02:00
Zbigniew Jędrzejewski-Szmek 25b3e2a835 basic/hashmap: allow NULL values in strdup hashmaps and add test 2020-05-06 16:56:42 +02:00
Zbigniew Jędrzejewski-Szmek be32732168 basic/set: let set_put_strdup() create the set with string hash ops
If we're using a set with _put_strdup(), most of the time we want to use
string hash ops on the set, and free the strings when done. This defines
the appropriate a new string_hash_ops_free structure to automatically free
the keys when removing the set, and makes set_put_strdup() and set_put_strdupv()
instantiate the set with those hash ops.

hashmap_put_strdup() was already doing something similar.

(It is OK to instantiate the set earlier, possibly with a different hash ops
structure. set_put_strdup() will then use the existing set. It is also OK
to call set_free_free() instead of set_free() on a set with
string_hash_ops_free, the effect is the same, we're just overriding the
override of the cleanup function.)

No functional change intended.
2020-05-06 16:54:06 +02:00
Lennart Poettering 45d82c3f1c systemctl: ensure underline for "list-unit-files" empty cells 2020-05-06 15:40:15 +02:00
Evgeny Vereshchagin 80cf50120c
Merge pull request #15422 from nolange/add_zstd_coredump
coredump: add zstandard support for coredumps
2020-05-04 14:57:39 +03:00
Norbert Lange ef5924aa31 coredump: add zstandard support for coredumps
this will hook libzstd into coredump,
using this format as default.
2020-05-04 10:59:43 +02:00
Lennart Poettering ddd6a22a0f basic: add STRCASE_IN_SET() which is to STR_IN_SET() what strcaseeq() is to streq() 2020-05-04 10:11:19 +02:00
Zbigniew Jędrzejewski-Szmek b76ef59756
Merge pull request #13512 from msekletar/freezer
core: introduce support for cgroup freezer
2020-05-01 07:52:29 +02:00
Michal Sekletár d9e45bc3ab core: introduce support for cgroup freezer
With cgroup v2 the cgroup freezer is implemented as a cgroup
attribute called cgroup.freeze. cgroup can be frozen by writing "1"
to the file and kernel will send us a notification through
"cgroup.events" after the operation is finished and processes in the
cgroup entered quiescent state, i.e. they are not scheduled to
run. Writing "0" to the attribute file does the inverse and process
execution is resumed.

This commit exposes above low-level functionality through systemd's DBus
API. Each unit type must provide specialized implementation for these
methods, otherwise, we return an error. So far only service, scope, and
slice unit types provide the support. It is possible to check if a
given unit has the support using CanFreeze() DBus property.

Note that DBus API has a synchronous behavior and we dispatch the reply
to freeze/thaw requests only after the kernel has notified us that
requested operation was completed.
2020-04-30 19:02:51 +02:00
Lennart Poettering 484f4e5b2d efi: honour SYSTEMD_EFI_OPTIONS even if we wouldn't honour SystemdOptions EFI var due to SecureBoot
Fixes: #14864
2020-04-30 12:12:14 +02:00
Lennart Poettering f46ba93944 efi: cache test results of boolean EFI state functions
EFI variable access is nowadays subject to rate limiting by the kernel.
Thus, let's cache the results of checking them, in order to minimize how
often we access them.

Fixes: #14828
2020-04-30 08:10:31 +02:00
Michal Sekletár 25a1f04c68 basic/cgroup-util: introduce cg_get_keyed_attribute_full()
Callers of cg_get_keyed_attribute_full() can now specify via the flag whether the
missing keyes in cgroup attribute file are OK or not. Also the wrappers for both
strict and graceful version are provided.
2020-04-29 18:41:19 +02:00
Luca Boccassi 4096043f05 Revert "detect-virt: also detect "microsoft" as WSL"
WSL2 will soon (TM) include the "WSL2" string in /proc/sys/kernel/osrelease
so the workaround will no longer be necessary.
We have several different cloud images which do include the "microsoft"
string already, which would break this detection. They are for internal
usage at the moment, but the userspace side can come from all over the
place so it would be quite hard to track and downstream-patch to avoid
breakages.

This reverts commit a2f838d590.
2020-04-28 13:13:12 +02:00
Zbigniew Jędrzejewski-Szmek 7229ec02ab efivars: retry open and read operations
On my laptop (Lenovo X1carbo 4th) I very occasionally see test-boot-timestamps
fail with this tb:

262/494 test-boot-timestamps                    FAIL    0.7348453998565674 s (killed by signal 6 SIGABRT)

08:12:48 SYSTEMD_LANGUAGE_FALLBACK_MAP='/home/zbyszek/src/systemd/src/locale/language-fallback-map' SYSTEMD_KBD_MODEL_MAP='/home/zbyszek/src/systemd/src/locale/kbd-model-map' PATH='/home/zbyszek/src/systemd/build:/home/zbyszek/.local/bin:/usr/lib64/qt-3.3/bin:/usr/share/Modules/bin:/usr/condabin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/zbyszek/bin:/var/lib/snapd/snap/bin' /home/zbyszek/src/systemd/build/test-boot-timestamps
--- stderr ---
Failed to read $container of PID 1, ignoring: Permission denied
Found container virtualization none.
Failed to get SystemdOptions EFI variable, ignoring: Interrupted system call
Failed to read ACPI FPDT: Permission denied
Failed to read LoaderTimeInitUSec: Interrupted system call
Failed to read EFI loader data: Interrupted system call
Assertion 'q >= 0' failed at src/test/test-boot-timestamps.c:84, function main(). Aborting.

Normally it takes ~0.02s, but here there's a slowdown to 0.73 and things fail with EINTR.
This happens only occasionally, and I haven't been able to capture a strace.

It would be to ignore that case in test-boot-timestamps or always translate
EINTR to -ENODATA. Nevertheless, I think it's better to retry, since this gives
as more resilient behaviour and avoids a transient failure.

See
https://github.com/torvalds/linux/blob/master/fs/efivarfs/file.c#L75
and
bef3efbeb8.
2020-04-28 09:00:25 +02:00
Dan Streetman 0bc5f001db cgroup-util: check for SYSFS_MAGIC when detecting cgroup format
When nothing at all is mounted at /sys/fs/cgroup, the fs.f_type is
SYSFS_MAGIC (0x62656572) which results in the confusing debug log:

"Unknown filesystem type 62656572 mounted on /sys/fs/cgroup."

Instead, if the f_type is SYSFS_MAGIC, a more accurate message is:

"No filesystem is currently mounted on /sys/fs/cgroup."
2020-04-25 10:00:43 +02:00