Commit Graph
4938 Commits
Author SHA1 Message Date
Yu Watanabe 57e7af551e Merge pull request #25786 from keszybz/ebadf
Use -EBADF for fd initialization
2022-12-20 10:02:10 +09:00
Yu Watanabe 8d8d4b092a Merge pull request #25787 from msekletar/rename-process-cap
units: allow systemd-userdbd to change process name
2022-12-20 09:58:47 +09:00
Michal Sekletar 03ee26168f argv-util: do proper permission check while when changing process name
Process renaming happens very seldomly so we are able to afford proper
permission check, i.e. actually check for CAP_SYS_RESOURCE capability
instead of euid.
2022-12-19 17:29:40 +01:00
Zbigniew Jędrzejewski-Szmek e8d2cb0f34 basic/hashmap: add comment
Coverity complains that the check is suspicious. Add a comment to help
the reader.
2022-12-19 15:16:41 +01:00
Zbigniew Jędrzejewski-Szmek 351293b3bb basic/fd-util: rearrange variable declarations
Having two blocks of normal variable declarations was unnecessary.
Also 'i' can be narrower in scope.
2022-12-19 15:00:59 +01:00
Zbigniew Jędrzejewski-Szmek 3401477982 tree-wide: use -EBADF also in pipe initializers
In some places, initialization is dropped when unnecesary.
2022-12-19 15:00:59 +01:00
Zbigniew Jędrzejewski-Szmek a5937dcf39 tree-wide: change initialization to use EBADF instead of EBADFD
Those fds never were, so it's not fair to say that they are in "bad state".
Let's use the shorter and more direct errno.
2022-12-19 15:00:59 +01:00
Zbigniew Jędrzejewski-Szmek 254d1313ae tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.

Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state

Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.

In some places, initialization is dropped if unnecessary.
2022-12-19 15:00:57 +01:00
Yu Watanabe 6f3473ca03 Merge pull request #25718 from yuwata/locale-cleanups
locale: avoid TOCTOU in reading config files
2022-12-16 00:51:13 +09:00
Yu Watanabe b3f1afc089 Merge pull request #24058 from qdeslandes/journald_regex_filtering
Allow for journald logs filtering on a per-unit basis
2022-12-15 22:03:33 +09:00
Quentin Deslandes 96c648fecd set: add set_make_nulstr
Add function set_make_nulstr() to create a nulstr out of a set. Behave
the same way as strv_make_nulstr().
2022-12-15 09:57:39 +00:00
Yu Watanabe edac5c4636 mountpoint-util: introduce mount_propagation_flag_is_valid() 2022-12-15 14:15:59 +09:00
Yu Watanabe b205e59ad4 mountpoint-util: rename mount_propagation_flags_to_string() and friends as singular 2022-12-15 14:15:55 +09:00
Zbigniew Jędrzejewski-Szmek 7a14db9cfd basic: do not output emojis if not on a proper terminal
$TERM would generally be set if we're connected to a proper graphical terminal
emulator. In all other cases, in particular if $TERM is not set, we almost
certainly are not connected to something that can output emojis. In particular
the text console is unlikely to ever do it correctly.

So let's invert the check, and only write emojis if $TERM is set.

Fixes #25521.
2022-12-15 12:56:03 +09:00
Yu Watanabe a6e16d949c Merge pull request #25723 from keszybz/generators-tmp
Run generators with / ro and /tmp mounted
2022-12-15 12:53:49 +09:00
Zbigniew Jędrzejewski-Szmek 61ef30515b shared: add new safe_fork flag FORK_PRIVATE_TMP
If the flag is set, we mount /tmp/ in a way that is suitable for generators and
other quick jobs.

Unfortunately I had to move some code from shared/mount-util.c to
basic/mountpoint-util.c. The functions that are moved are very thin wrappers
around mount(2), so this doesn't actually change much in the code split between
libbasic and libshared.

Implications for the host would be weird if a private mount namespace is not
used, so assert on FORK_NEW_MOUNTNS when the flag is used.
2022-12-14 22:12:44 +01:00
Yu Watanabe dc1752ea72 stat-util: introduce fd_is_read_only_fs()
Then, reimplement path_is_read_only_fs() by the function to avoid race.
2022-12-15 03:25:09 +09:00
Siddhesh Poyarekar 7929e180aa Use dummy allocator to make accesses defined as per standard
systemd uses malloc_usable_size() everywhere to use memory blocks
obtained through malloc, but that is abuse since the
malloc_usable_size() interface isn't meant for this kind of use, it is
for diagnostics only.  This is also why systemd behaviour is flaky when
built with _FORTIFY_SOURCE.

One way to make this more standard (and hence safer) is to, at every
malloc_usable_size() call, also 'reallocate' the block so that the
compiler can see the larger size.  This is done through a dummy
reallocator whose only purpose is to tell the compiler about the larger
usable size, it doesn't do any actual reallocation.

Florian Weimer pointed out that this doesn't solve the problem of an
allocator potentially growing usable size at will, which will break the
implicit assumption in systemd use that the value returned remains
constant as long as the object is valid.  The safest way to fix that is
for systemd to step away from using malloc_usable_size() like this.

Resolves #22801.
2022-12-14 17:49:47 +01:00
Yu Watanabe 649512b934 env-file: introduce parse_env_file_fd() 2022-12-14 20:18:58 +09:00
Yu Watanabe dd57a22e6a env-file: several cleanups
- add missing assertions,
- rename function arguments for storing results,
- add typedef for callback.
2022-12-14 20:18:58 +09:00
Yu Watanabe 0ec8777e18 Merge pull request #25726 from dtardon/cleanups
Several small cleanups
2022-12-14 20:17:56 +09:00
David Tardon 1dca43db12 ratelimit: drop use of goto 2022-12-13 16:03:37 +01:00
David Tardon 229b008635 mountpoint-util: reduce variable scope 2022-12-13 15:47:52 +01:00
Zbigniew Jędrzejewski-Szmek 2053593fcc treewide: drop "RUN_" from "RUN_WITH_UMASK"
RUN_WITH_UMASK was initially conceived for spawning externals progs with the
umask set. But nowadays we use it various syscalls and stuff that doesn't "run"
anything, so the "RUN_" prefix has outlived its usefulness.
2022-12-13 14:39:30 +01:00
Yu Watanabe 4596c83658 in-addr-util: introduce in_addr_data_hash_ops_free and expose its compare and hash functions
Preparation for later commits.
2022-12-13 20:32:44 +09:00
Zbigniew Jędrzejewski-Szmek 7aebbdcfa9 Merge pull request #25636 from thom311/th/wcast-align-fixes
all: avoid various "-Wcast-align=strict" warnings
2022-12-09 15:03:45 +01:00
Thomas Haller 6759b62720 all: avoid various "-Wcast-align=strict" warnings 2022-12-09 08:58:07 +01:00
Yu Watanabe 7d34567444 hexdecoct: fix NULL pointer dereferences in hexmem()
Fixes oss-fuzz#54090 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54090).

Fixes #25655.
2022-12-09 04:55:47 +09:00
Yu Watanabe 45655e776f hexdecoct: add missing NULL check
Fixes oss-fuzz#54065 (https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54065).

Fixes #25650.
2022-12-09 04:54:43 +09:00
Yu Watanabe c21b316964 hexdecoct: several cleanups for base64_append()
- add missing assertions,
- use size_t for buffser size or memory index,
- handle empty input more gracefully,
- return the length or the result string,
- fix off-by-one issue when the prefix is already long enough.
2022-12-09 04:53:50 +09:00
Lennart Poettering b6256af75e socket-util: add CMSG_TYPED_DATA() as type-safe wrapper around CMSG_DATA() 2022-12-08 17:48:34 +01:00
Lennart Poettering 93c1baa0c8 Merge pull request #25667 from poettering/sha256-align-fix
sha256 alignment fixes/rework
2022-12-08 17:24:17 +01:00
Yu Watanabe 340bc268c8 fs-util: make chmod_and_chown_at() work with empty path and AT_FDCWD
Follow-up for 7d000133c2.

Fixes CID#1500608.
2022-12-08 15:57:33 +01:00
Lennart Poettering d8007e7aac fundamental: split out unaligned_{read|write}_ne{16,32,64}() helpers into unaligned-fundamental.h
Let's allow using this in code shared between userspace and EFI mode.

Also, don't implement these functions via endianness conversions given
we don't actually want to convert endianess here.
2022-12-08 15:18:47 +01:00
Zbigniew Jędrzejewski-Szmek cc420ae52a Merge pull request #25616 from poettering/chase-symlinks-opendir
chase-symlinks/systemctl: let's handle cases without /proc/ better
2022-12-06 17:10:54 +01:00
Yu Watanabe 76519cecc7 escape: fix wrong octescape of bad character
Fixes a bug introduced by 95052df376.

This also makes octescape() support NULL or zero length string.

Fixes [oss-fuzz#54059](https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54059).

Fixes #25643.
2022-12-06 12:18:10 +09:00
Daan De Meyer 2877b14720 chase-symlinks: Fix regression from 5bc244aaa9
Previously, chase_symlinks() always returned an absolute path, which
changed after 5bc244aaa9. This commit
fixes chase_symlinks() so it returns absolute paths all the time again.
2022-12-05 09:27:58 +01:00
Zbigniew Jędrzejewski-Szmek 27c8ca439f manager: write net/unix/max_dgram_qlen sysctl as fixed string 2022-12-03 11:59:03 +01:00
Lennart Poettering 2075b6dd39 chase-symlink: when converting directory O_PATH fd to real fd, don't bother with /proc/
Replaces: #25581
2022-12-02 23:55:44 +01:00
Lennart Poettering 03c16b9784 glyph-util: add warning sign special glyph 2022-12-02 23:54:50 +01:00
Lennart Poettering 1fe6e5c112 Revert "basic: add fallback in chase_symlinks_and_opendir() for cases when /proc is not mounted"
This reverts commit 3e22dfc235.
2022-12-02 17:57:10 +01:00
Michal Sekletar 3e22dfc235 basic: add fallback in chase_symlinks_and_opendir() for cases when /proc is not mounted
https://bugzilla.redhat.com/show_bug.cgi?id=2136916
2022-12-02 17:45:33 +01:00
Neil Moore d833ed781f virt: Support detection of LMHS SRE guests 2022-12-02 10:29:14 +09:00
Ray Strode 9fe26523a1 terminal-util: Set OPOST when setting ONLCR
reset_terminal_fd sets certain minimum required terminal attributes
that systemd relies on.

One of those attributes is `ONLCR` which ensures that when a new line
is sent to the terminal, that the cursor not only moves to the next
line, but also moves to the very beginning of that line.

In order for `ONLCR` to work, the terminal needs to perform output
post-processing. That requires an additional attribute, `OPOST`,
which reset_terminal_fd currently fails to ensure is set.

In most cases `OPOST` (and `ONLCR` actually) are both set anyway, so
it's not an issue, but it could be a problem if, e.g., the terminal was
put in raw mode by a program and the program unexpectedly died before
restoring settings.

This commit ensures when `ONLCR` is set `OPOST` is set too, which is
the only thing that really makes sense to do.
2022-12-01 11:29:21 +01:00
Lennart Poettering 5f5865f0ad fd-util: add new helper fd_reopen_conditional()
This is a wrapper around fd_reopen() that will reopen an fd if the
F_GETFL flags indicate this is necessary, and otherwise not.

This is useful for various utility calls that shall be able to operate
on O_PATH and without it, and might need to convert between the two
depending on what's passed in.
2022-11-29 15:32:47 +01:00
Lennart Poettering 17f244e8f9 resolved: introduce the _localdnsstub and _localdnsproxy special hostnames for 127.0.0.54 + 127.0.0.53
Let's give these special IP addresses names. After all name resolution
is our job here.

Fixes: #23623
2022-11-25 17:37:30 +01:00
Daan De Meyer 03288a3f28 Merge pull request #25500 from DaanDeMeyer/mcopy-skip-symlinks
mkfs-util: Skip symlinks when calling mcopy
2022-11-24 16:28:01 +01:00
Daan De Meyer a0a4c57818 recurse-dir: Handle RECURSE_DIR_ENSURE_TYPE in readdir_all() 2022-11-24 14:02:19 +01:00
Daan De Meyer 06da125ea1 dirent-util: Expose dirent_ensure_type() 2022-11-24 13:18:00 +01:00
Yu Watanabe 00a60eaf5f Merge pull request #25483 from poettering/ppoll-usec-eintr
ppoll() + EINTR fixes
2022-11-24 09:42:48 +09:00