summaryrefslogtreecommitdiffstats
path: root/src/shared/condition.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* shared/condition: accept size suffixes for ConditionMemoryZbigniew Jędrzejewski-Szmek2022-06-101-2/+2
| | | | Fixes #23697.
* shared/condition: reduce scope of variablesZbigniew Jędrzejewski-Szmek2022-06-071-18/+7
|
* stat-util: fix dir_is_empty() with hidden/backup filesLennart Poettering2022-05-041-1/+1
| | | | | | | | | | | | | | | | | | | | 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.
* condition: rework ConditionSecurity=tpm2 check on top of tpm2_support()Lennart Poettering2022-04-201-21/+7
| | | | No change in behaviour. Let's just use our new helper here.
* tree-wide: use 'Architecture' type consistently across the treeLennart Poettering2022-04-041-1/+1
| | | | | | | Some parts of our tree used 'Architecture' for storing architectures, others used ints. Let's unify on the former. Inspired by #22952's rework of the 'Virtualization' enum.
* virt: make virtualization enum a named typeLennart Poettering2022-04-041-2/+3
| | | | | | | | These days we have a mechanism for safely returning errnos in enum types, via definining -ERRNO_MAX as one special enu value. Let's use that for Virtualization. No change in behaviour, just some typesafety improvement.
* Merge pull request #22649 from ↵Zbigniew Jędrzejewski-Szmek2022-03-291-1/+2
|\ | | | | | | | | keszybz/symlink-enablement-yet-again-punish-me-harder Fixups to the unit enablement logic
| * systemctl: fix silent failure when --root is not foundZbigniew Jędrzejewski-Szmek2022-03-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some calls to lookup_path_init() were not followed by any log emission. E.g.: $ SYSTEMD_LOG_LEVEL=debug systemctl --root=/missing enable unit; echo $? 1 Let's add a helper function and use it in various places. $ SYSTEMD_LOG_LEVEL=debug build/systemctl --root=/missing enable unit; echo $? Failed to initialize unit search paths for root directory /missing: No such file or directory 1 $ SYSTEMCTL_SKIP_SYSV=1 build/systemctl --root=/missing enable unit; echo $? Failed to initialize unit search paths for root directory /missing: No such file or directory Failed to enable: No such file or directory. 1 The repeated error in the second case is not very nice, but this is a niche case and I don't think it's worth the trouble to trying to avoid it.
* | efi-loader: split efi-api.[ch] from efi-loader.[ch]Lennart Poettering2022-03-241-1/+1
|/ | | | | | | | | | | | | | Some refactoring: split efi-loader.[ch] in two: isolate the calls that implement out boot loader interface spec, and those which implement access to upstream UEFI firmware features. They are quite different in nature and behaviour, and even semantically it makes to keep these two separate. At the very least because the previous name "efi-loader.[ch]" suggests all was about loader-specific APIs, but much of it is generic uefi stuff... While we are at it, I renamed a bunch of return parameters to follow our usual ret_xyz naming. But besides renaming no real code changes.
* strv: make iterator in STRV_FOREACH() declaread in the loopYu Watanabe2022-03-191-1/+0
| | | | This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
* list: make LIST_FOREACH() and LIST_FOREACH_BACKWARDS() saferYu Watanabe2022-03-191-1/+1
|
* list: declare iterator of LIST_FOREACH() in the loopYu Watanabe2022-03-191-5/+0
|
* util: move on_ac_power() from util.c -> udev-util.cYu Watanabe2022-01-061-1/+1
|
* core: support user manager with Condition[Memory/CPU/IO]PressureLuca Boccassi2021-12-021-3/+24
| | | | | | | | | | Get the cgroup root path from the current PID, so that when ran by the user manager we can get to the right path. Eg: foo.slice:10% will check under: /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/foo.slice/cpu.pressure Follow-up for 81513b382b24a7f3602987f71042d075ca27d1a5
* core: add Condition[Memory/CPU/IO]PressureLuca Boccassi2021-12-011-0/+136
| | | | | | | | | | By default checks PSI on /proc/pressure, and causes a unit to be skipped if the threshold is above the given configuration for the avg300 measurement. Also allow to pass a custom timespan, and a particular slice unit to check under. Fixes #20139
* fix ConditionPathIsReadWrite when path does not exist.jiangchuangang2021-11-301-1/+5
|
* fix ConditionDirectoryNotEmpty when it comes to a Non-directory filejiangchuangang2021-11-301-1/+1
|
* shared: split out UID allocation range stuff from user-record.hLennart Poettering2021-11-131-1/+1
| | | | | | | | user-record.[ch] are about the UserRecord JSON stuff, and the UID allocation range stuff (i.e. login.defs handling) is a very different thing, and complex enough on its own, let's give it its own c/h files. No code changes, just some splitting out of code.
* condition: use /proc/device-tree/Yu Watanabe2021-11-101-6/+3
|
* Drop the text argument from assert_not_reached()Zbigniew Jędrzejewski-Szmek2021-08-031-1/+1
| | | | | | | | | | | | | | | | | In general we almost never hit those asserts in production code, so users see them very rarely, if ever. But either way, we just need something that users can pass to the developers. We have quite a few of those asserts, and some have fairly nice messages, but many are like "WTF?" or "???" or "unexpected something". The error that is printed includes the file location, and function name. In almost all functions there's at most one assert, so the function name alone is enough to identify the failure for a developer. So we don't get much extra from the message, and we might just as well drop them. Dropping them makes our code a tiny bit smaller, and most importantly, improves development experience by making it easy to insert such an assert in the code without thinking how to phrase the argument.
* Merge pull request #19941 from bluca/condition_os_releaseZbigniew Jędrzejewski-Szmek2021-06-251-0/+60
|\ | | | | core: add ConditionOSRelease= directive
| * core: add ConditionOSRelease= directiveLuca Boccassi2021-06-241-0/+60
| |
* | basic,shared: move a bunch of files to src/shared/Zbigniew Jędrzejewski-Szmek2021-06-241-0/+1
|/ | | | | | | | | | | | The goal is to move everything that requires selinux or smack away from src/basic/. This means that src/basic/label.[ch] must move, which implies btrfs-util.[ch], copy.[ch], and a bunch of other files which form a cluster of internal use. This is just moving text around, so there should be no functional difference. test-blockdev-util is new, because path_is_encrypted() is moved to blockdev-util.c, and so far we didn't have any tests for code there.
* core: disable "update" units in the initramfsZbigniew Jędrzejewski-Szmek2021-06-071-0/+5
| | | | | | | | | | | | | | Initially I wanted to add ConditionPathExists=!/etc/initrd-release in various units (ldconfig.service, systemd-sysusers.service, systemd-hwdb-update.service, systemd-journal-catalog-update, systemd-update-done.service), but I think it's better to just disable the mechanism in the initrd altogether. Initrd images are put together in a very particular way, and there is not need to do post-update steps on them. If a unit from some other package winds up in the initrd, we wouldn't want to invoke it either. Also, any modifications are ephemeral, so any update would happen on every use. And finally, initrd images are all about speed, and we shouldn't invoke any unneeded services.
* Add support for conditions on the machines firmwareUwe Kleine-König2021-04-281-0/+79
| | | | | | This allows to limit units to machines that run on a certain firmware type. For device tree defined machines checking against the machine's compatible is also possible.
* shared/condition: add ConditionControlGroupController=v1|v2Zbigniew Jędrzejewski-Szmek2021-02-231-0/+9
| | | | | | | | | | Before, we only allowed conditionalizing on controllers, not the hierarchy. This commit extends this to allow a simple check for v1 (i.e. classic or hybrid), and v2 (full unified). An alternative approach would be to add a separate Condition for this, but I'm not too keen on that, considering that v1 is already being deprecrecated (c.f. 82f3063218).
* condition: add CPUFeatureGiedrius Statkevičius2021-02-171-0/+11
| | | | | | | | | | | | | | | | | | | | | | | Taking a stab at implementing #14479. Add {Condition,Assert}CPUFeature to `systemd-analyze` & friends. Implement it by executing the CPUID instruction. Add tables for common x86/i386 features. Tested via unit tests + checked that commands such as: ```bash systemd-analyze condition 'AssertCPUFeature = rdrand' ``` Succeed as expected and that commands such as ```bash systemd-analyze condition 'AssertCPUFeature = foobar' ``` Fail as expected. Finally, I have amended the `systemd.unit` manual page with the new condition and the list of all currently supported flags.
* condition: if spelunking through /sys/class/tpmrm doesn't work ask EFI if ↵Lennart Poettering2021-02-111-0/+11
| | | | | | | TPM2 exists This makes ConditionSecurity=tpm2 work reliably during early boot: if Linux doesn't know about the TPM2 then maybe the firmware does.
* tree-wide: use -EINVAL for enum invalid valuesZbigniew Jędrzejewski-Szmek2021-02-101-1/+1
| | | | | | | | | As suggested in https://github.com/systemd/systemd/pull/11484#issuecomment-775288617. This does not touch anything exposed in src/systemd. Changing the defines there would be a compatibility break. Note that tests are broken after this commit. They will be fixed in the next one.
* tree-wide: replace strverscmp() and str_verscmp() with strverscmp_improved()Yu Watanabe2021-02-091-1/+1
|
* core: add ConditionSecurity=tpm2 supportLennart Poettering2020-12-031-0/+17
|
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Move {uid,gid}_is_*() from basic to sharedZbigniew Jędrzejewski-Szmek2020-09-251-0/+1
| | | | | Those are functions that express policy, and nothing in basic/ uses (or should use) them.
* core: remove support for ConditionNull=Lennart Poettering2020-08-201-18/+3
| | | | | | | | | | The concept is flawed, and mostly useless. Let's finally remove it. It has been deprecated since 90a2ec10f2d43a8530aae856013518eb567c4039 (6 years ago) and we started to warn since 55dadc5c57ef1379dbc984938d124508a454be55 (1.5 years ago). Let's get rid of it altogether.
* condition: introduce systemd.condition-first-boot= kernel command line switchLennart Poettering2020-05-181-0/+7
| | | | | | | | | Much like systemd.condition-needs-update= this new switch allows overriding of a unit file condition, but this time its ConditionFirstBoot=. Usecase is also primarily debugging, but could be useful for other schemes too.
* condition: debug log if F_OK check on /run/systemd/first-boot fails unexpectedlyLennart Poettering2020-05-181-2/+6
|
* condition: reverse if check to lower indentation levelLennart Poettering2020-05-181-19/+17
| | | | | No change in behaviour. Let's just prefer early exit over deeper indentation.
* condition: allow overriding of ConditionNeedsUpdate= on the kernel command lineLennart Poettering2020-05-181-0/+7
| | | | This should be useful for addressing #15724.
* condition: when reading /etc/ modification timestamp, let's actualy compare ↵Lennart Poettering2020-05-181-1/+1
| | | | | | | it as-is Previously, we'd only compare the nsec component of it, which sounds needlessly fragile. Let's instead compare the timestamp as it is.
* condition: downgrade a few log messages to debugLennart Poettering2020-05-181-3/+3
| | | | | | Condition checks shouldn't log loudly, since they run all the time. Let's make things debuggable, by keeping the messages in LOG_DEBUG in, but don't make more noise than necessary.
* condition: add debug log messages on unexpected errorsLennart Poettering2020-05-181-6/+16
|
* condition: check if path is absolute firstLennart Poettering2020-05-181-6/+5
| | | | | | We should do this check first since it is done on the string itself without any conditioning of system state otherwise. It is a weird to do this test only if /etc is read-only.
* condition: add ConditionEnvironment=Lennart Poettering2020-05-151-30/+63
| | | | | | | Prompted by the discussions in #15180. This is a bit more complex than I hoped, since for PID 1 we need to pass in the synethetic environment block in we generate on demand.
* condition: return (Condition*) NULL from condition_free()Lennart Poettering2020-05-151-2/+2
| | | | Follow our usual coding style.
* condition: introduce generic function type for condition_to_string()-like ↵Lennart Poettering2020-05-151-3/+9
| | | | | | functions Let's add a typedef for a function type we use at multiple places.
* condition: add ConditionPathIsEncrypted=Lennart Poettering2020-05-151-0/+18
| | | | | | | It's easy to add, and should be pretty useful, in particular as in AssertPathIsEncrypted= as it can be used for checking that some path is encrypted before some service is invoked that might want to place secure material there.
* tree-wide: drop stat.h or statfs.h when stat-util.h is includedYu Watanabe2019-11-031-1/+0
|
* tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe2019-11-031-1/+0
|
* util-lib: split shared/efivars into basic/efivars and shared/efi-loaderZbigniew Jędrzejewski-Szmek2019-09-161-1/+1
| | | | | | I want to use efivars.[ch] in proc-cmdline.c, but most of the efivars stuff is not needed in basic/. Move the file from shared/ to basic/, but then move back most of the higher-level functions to the new shared/efi-loader.c file.
* tree-wide: use PROJECT_FILE instead of __FILE__Zbigniew Jędrzejewski-Szmek2019-07-041-2/+2
| | | | This replaces the internal uses of __FILE__ with the new macro.