summaryrefslogtreecommitdiffstats
path: root/src/basic (follow)
Commit message (Collapse)AuthorAgeFilesLines
* basic/in-addr-util: add IN_ADDR_PREFIX_TO_STRINGZbigniew Jędrzejewski-Szmek2022-06-062-24/+45
|
* basic/in-addr-util: drop check for prefix length in formatting functionZbigniew Jędrzejewski-Szmek2022-06-061-5/+2
| | | | | | | | | | | | | | The general rule should be to be strict when parsing data, but lenient when printing it. Or in other words, we should verify data in verification functions, but not when printing things. It doesn't make sense to refuse to print a value that we are using internally. We were tripping ourselves in some of the print functions: we want to report than an address was configured with too-long prefix, but the log line would use "n/a" if the prefix was too long. This is not useful. Most of the time, the removal of the check doesn't make any difference, because we verified the prefix length on input.
* basic/in-addr-util: add IN_ADDR_TO_STRINGZbigniew Jędrzejewski-Szmek2022-06-062-1/+22
| | | | | | | | | | | | | | | Since we don't need the error value, and the buffer is allocated with a fixed size, the whole logic provided by in_addr_to_string() becomes unnecessary, so it's enough to wrap inet_ntop() directly. inet_ntop() can only fail with ENOSPC. But we specify a buffer that is supposed to be large enough, so this should never fail. A bunch of tests of this are added. This allows all the wrappers like strna(), strnull(), strempty() to be dropped. The guard of 'if (DEBUG_LOGGING)' can be dropped from around log_debug(), because log_debug() implements the check outside of the function call. But log_link_debug() does not, so it we need it to avoid unnecessary evaluation of the formatting.
* Move basic/recovery-key.* to shared/Zbigniew Jędrzejewski-Szmek2022-06-023-127/+0
| | | | | No particular reason to have it in basic/. We should let homectl and other users share the single copy through libsystemd-shared.
* macro: make ALIGN4() and ALIGN8() also return SIZE_MAX on overflowYu Watanabe2022-05-311-19/+0
| | | | This also drops unused ALIGN4_PTR(), ALIGN8_PTR(), and ALIGN_TO_PTR().
* tree-wide: use ALIGN_PTR()Yu Watanabe2022-05-311-2/+2
|
* Simplify random number selectionJason A. Donenfeld2022-05-313-165/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We currently have a convoluted and complex selection of which random numbers to use. We can simplify this down to two functions that cover all of our use cases: 1) Randomness for crypto: this one needs to wait until the RNG is initialized. So it uses getrandom(0). If that's not available, it polls on /dev/random, and then reads from /dev/urandom. This function returns whether or not it was successful, as before. 2) Randomness for other things: this one uses getrandom(GRND_INSECURE). If it's not available it uses getrandom(GRND_NONBLOCK). And if that would block, then it falls back to /dev/urandom. And if /dev/urandom isn't available, it uses the fallback code. It never fails and doesn't return a value. These two cases match all the uses of randomness inside of systemd. I would prefer to make both of these return void, and get rid of the fallback code, and simply assert in the incredibly unlikely case that /dev/urandom doesn't exist. But Luca disagrees, so this commit attempts to instead keep case (1) returning a return value, which all the callers already check, and fix the fallback code in (2) to be less bad than before. For the less bad fallback code for (2), we now use auxval and some timestamps, together with various counters representing the invocation, hash it all together and provide the output. Provided that AT_RANDOM is secure, this construction is probably okay too, though notably it doesn't have any forward secrecy. Fortunately, it's only used by random_bytes() and not by crypto_random_bytes().
* cgroup-util: Properly handle conditions where cgroup.threads is empty after ↵msizanoen12022-05-301-3/+12
| | | | | | | | | | | | | SIGKILL but processes still remain After sending a SIGKILL to a process, the process might disappear from `cgroup.threads` but still show up in `cgroup.procs` and still remains in the cgroup and cause migrating new processes to `Delegate=yes` cgroups to fail with `-EBUSY`. This is especially likely for heavyweight processes that consume more kernel CPU time to clean up. Fix this by only returning 0 when both `cgroup.threads` and `cgroup.procs` are empty.
* macro: Move attribute defintions to macro-fundamentalJan Janssen2022-05-281-18/+0
| | | | This also sorts them.
* fundamental: Move some helpers into string-util-fundamentalJan Janssen2022-05-212-17/+0
|
* Merge pull request #23339 from poettering/sockaddr-size-limitLuca Boccassi2022-05-214-43/+64
|\ | | | | tree-wide: add support for connecting to AF_UNIX sockets in the file system beyond the 108ch limit
| * tree-wide: port various users over to connect_unix_path()Lennart Poettering2022-05-131-22/+8
| | | | | | | | Let's make use of our new helper, and thus allow longer paths.
| * fileio: port read_file_full() to use connect_unix_path()Lennart Poettering2022-05-131-21/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | This way we can connect correctly to any AF_UNIX socket in the file system, and even save some code. Yay! This also adds some test code for this, that ensures read_file_full() works correctly for AF_UNIX sockets that violate the 108 char limit. Supporting sockets like this kinda matters I think, for the simple reason that apps want to build socket paths via XDG_RUNTIME_DIR and suchlike, and we should be able to connect to them, even via non-normalized paths.
| * socket-util: add new connect_unix_path() helperLennart Poettering2022-05-132-0/+50
| | | | | | | | | | | | | | | | | | This is a short helper for connecting to AF_UNIX sockets in the file system. It works around the 108ch limit of sockaddr_un, and supports "at" style fds. This doesn't come with a test of its own, but the next patch will add that.
* | basic/strv: add optimizable version of strv_push/consume/extendZbigniew Jędrzejewski-Szmek2022-05-202-15/+39
|/ | | | | | | | | | This will be helpful in cases where we are repeatedly adding entries to a long strv and want to skip the iteration over old entries leading to quadratic behaviour. Note that we don't want to calculate the length if not necessary, so the calculation is delayed until after we've checked that value is not NULL.
* fileio: fix error propagationLennart Poettering2022-05-131-1/+1
|
* fileio: propagate original error if we notice AF_UNIX connect() is not going ↵Lennart Poettering2022-05-131-1/+1
| | | | | | | | | to work let's not make up new errors in these checks that validate if connect() work at all. After all, we don't really know if the ENXIO we saw earlier actually is really caused by the inode being an AF_UNIX socket, we just have the suspicion...
* socket-util: change sockaddr_un_set_path() to return recognizable error on ↵Lennart Poettering2022-05-131-1/+4
| | | | | | | | | 108ch limit This way we can implement nice fallbacks later on. While we are at it, provide a test for this (one that is a bit over the top, but then again, we can never have enough tests).
* Merge pull request #23361 from keszybz/resolved-helpersYu Watanabe2022-05-121-1/+8
|\ | | | | Add some ref-unref helpers for resolved
| * Add saturate_add() that generalizes size_add()Zbigniew Jędrzejewski-Szmek2022-05-121-1/+8
| |
* | Merge pull request #23289 from yuwata/resolve-answer-add-rrsigZbigniew Jędrzejewski-Szmek2022-05-121-0/+4
|\| | | | | resolve: place RRSIG after the corresponding entries
| * ordered-set: introduce ordered_set_reserve()Yu Watanabe2022-05-071-0/+4
| |
* | Merge pull request #23351 from keszybz/logind-messageYu Watanabe2022-05-113-3/+15
|\ \ | | | | | | logind: fix crash in logind on bad message string
| * | meson: turn on log-message-verification by default in developer buildsZbigniew Jędrzejewski-Szmek2022-05-112-3/+8
| | | | | | | | | | | | | | | I'm not _quite_ convinced that this a good idea… I'm at least keeping it separate to make it easy to revert ;)
| * | Do LOG_MESSAGE_VERIFICATION in coverity runsZbigniew Jędrzejewski-Szmek2022-05-111-1/+1
| | | | | | | | | | | | | | | This should be enough to get reports if we screw up anywhere, coverity does analysis of printf format strings.
| * | Optionally call printf on LOG_MESSAGE() argumentsZbigniew Jędrzejewski-Szmek2022-05-111-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | With an intentional mistake: ../src/login/logind-dbus.c: In function ‘bus_manager_log_shutdown’: ../src/login/logind-dbus.c:1542:39: error: format ‘%s’ expects a matching ‘char *’ argument [-Werror=format=] 1542 | LOG_MESSAGE("%s %s", message), | ^~~~~~~
| * | tree-wide: use LOG_MESSAGE() where possibleZbigniew Jędrzejewski-Szmek2022-05-112-2/+3
| |/ | | | | | | | | | | | | Also break some long lines for more uniform formatting. No functional change. I went over all log_struct, log_struct_errno, log_unit_struct, log_unit_struct_errno calls, and they seem fine.
* | Merge pull request #23335 from keszybz/fuzz-json-more-coverageYu Watanabe2022-05-101-2/+2
|\ \ | | | | | | More coverage in fuzz-json
| * | basic/alloc-util: remove unnecessary parensZbigniew Jędrzejewski-Szmek2022-05-101-2/+2
| | | | | | | | | | | | Those symbols are not macros anymore, so we can drop parens.
* | | shared/calendarspec: wrap long comments and reduce scope of one varZbigniew Jędrzejewski-Szmek2022-05-101-18/+21
|/ /
* | socket-util: don't reference field by macro parameter nameLennart Poettering2022-05-091-2/+2
| | | | | | | | | | Let's avoid ambigituies here. (Interesting that the current users compiled at all, in fact)
* | basic/virt: use STRV_FOREACH instead of iteration with ELEMENTSOFZbigniew Jędrzejewski-Szmek2022-05-081-8/+9
|/ | | | I think it's a bit simpler, we don't have two indexes.
* basic/strv: fix splitting of strings with escape charactersZbigniew Jędrzejewski-Szmek2022-05-061-1/+1
| | | | | | | | | Plain strv_split() should not care if the strings contains backslashes or quote characters. But extract_first_word() interprets backslashes unless EXTRACT_RETAIN_ESCAPE is given. I wonder how it's possible that nobody noticed this before. I think this code was introduced in 0645b83a40d1c782f173c4d8440ab2fc82a75006.
* shared/terminal-util: don't use $COLORTERM to force colorsZbigniew Jędrzejewski-Szmek2022-05-061-9/+18
| | | | | | Fixup for a5efbf468c96190c9562bc8121eda32310dfd112: if $COLORTERM was set, we'd unconditionally turn on colors, which is unexpected and wrong. It even breaks our own tests when executed in gnome-terminal.
* core: handle lookup paths being symlinksAndreas Rammhold2022-05-051-1/+40
| | | | | | | | | | | With a recent change paths leaving the statically known lookup paths would be treated differently then those that remained within those. That was done (AFAIK) to consistently handle alias names. Unfortunately that means that on some distributions, especially those where /etc/ consists mostly of symlinks, would trigger that new detection for every single unit in /etc/systemd/system. The reason for that is that the units directory itself is already a symlink. Rebased-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
* terminal-util: get_color_mode checks COLORTERMSonali Srivastava2022-05-052-4/+12
|
* basic: Add some missing headers to compress.hDaan De Meyer2022-05-041-0/+2
|
* stat-util: drop dir_is_populated() which is apparently not usedLennart Poettering2022-05-041-8/+0
|
* stat-util: fix dir_is_empty() with hidden/backup filesLennart Poettering2022-05-042-18/+30
| | | | | | | | | | | | | | | | | | | | This is a follow-up for f470cb6d13558fc06131dc677d54a089a0b07359 which in turn is a follow-up for a068aceafbffcba85398cce636c25d659265087a. The latter started to honour hidden files when deciding whether a directory is empty. The former reverted to the old behaviour to fix issue #23220. It introduced a bug though: when a directory contains a larger number of hidden entries the getdents64() buffer will not suffice to read them, since we just allocate three entries for it (which is definitely enough if we just ignore the . + .. entries, but not ig we ignore more). I think it's a bit confusing that dir_is_empty() can return true even if rmdir() on the dir would return ENOTEMPTY. Hence, let's rework the function to make it optional whether hidden files are ignored or not. After all, I looking at the users of this function I am pretty sure in more cases we want to honour hidden files.
* stat-util: ignore hidden_or_backup_file when checking if dir is emptyLuca Boccassi2022-05-011-1/+1
| | | | | | | | | | Commit https://github.com/systemd/systemd/commit/a068aceafbf changed dir_is_emtpy_at to use FOREACH_DIRENT_IN_BUFFER instead of FOREACH_DIRENT, but used dot_or_dotdot which just checks if the name is literally '.' or '..' which is not enough, previous behaviour was to ignore all hidden files, so restore that and add a test case. Fixes https://github.com/systemd/systemd/issues/23220
* Merge pull request #23119 from yuwata/test-sd-device-exclude-bdiZbigniew Jędrzejewski-Szmek2022-04-272-0/+27
|\ | | | | test: exclude "bdi" subsystem
| * set: introduce set_fnmatch()Yu Watanabe2022-04-272-0/+27
| |
* | compress: make Compression a regular non-sparse enumLennart Poettering2022-04-262-8/+5
| | | | | | | | | | | | | | Given we have two different types for the journal object flags and the Compression enum, let's make the latter a regular non-sparse enum, and thus remove some surprises. We have to convert anyway between the two, and already do via COMPRESSION_FROM_OBJECT().
* | basic: move compress.[ch] → src/basic/Lennart Poettering2022-04-263-0/+1210
|/ | | | | | | | | | | | The compression helpers are used both in journal code and in coredump code, and there's a good chance we'll use them later for other stuff. Let's hence move them into src/basic/, to make them a proper internal API we can use from everywhere where that's desirable. (pstore might be a candidate, for example) No real code changes, just some moving around, build system rearrangements, and stripping of journal-def.h inclusion.
* tree-wide: Simplify variable declarations behind #ifdefJan Janssen2022-04-231-4/+2
|
* macro: upgrade ref counting overflow check assert() → assert_se()Lennart Poettering2022-04-211-1/+1
| | | | | | | | | | The overflow check for ref counting should not be subject to NDEBUG, hence upgrade assert() → assert_se(). (The check for zero is an immediate bug in our code, and should be impossible to trigger, hence it's fine if the check is optimized away if people are crazy enough to set NDEBUG, so that can stay assert()) https://github.com/systemd/systemd/pull/23099#discussion_r854341850
* Merge pull request #23099 from yuwata/sd-bus-track-fixletsLennart Poettering2022-04-201-2/+6
|\ | | | | sd-bus: fix counter
| * macro: check over flow in reference counterYu Watanabe2022-04-191-2/+6
| |
* | Merge pull request #23124 from yuwata/fixes-for-post-merge-reviewDaan De Meyer2022-04-203-2/+40
|\ \ | | | | | | Fixes for post merge review
| * | string-util: introduce strspn_from_end()Yu Watanabe2022-04-192-0/+17
| | |