summaryrefslogtreecommitdiff
path: root/src/test/test-specifier.c
Commit message (Collapse)AuthorAgeFilesLines
* test-specifier: Ignore -ENOPKG from specifier_printf()Daan De Meyer2023-05-081-1/+1
| | | | | If /etc/machine-id contains "uninitialized", specifier_printf() with %m will fail with ENOPKG, so ignore that error as well.
* test: add tests for uuid/uint64 specifiersFrantisek Sumsal2023-04-161-0/+27
| | | | | They're used in repart, but are not part of the "common" specifier lists, so cover them explicitly.
* specifier: always convert missing machine-id file to EUNATCHYu Watanabe2023-04-051-1/+1
| | | | Then, use id128_get_machine().
* basic: add RuntimeScope enumLennart Poettering2023-03-101-1/+1
| | | | | | | | | | | | In various tools and services we have a per-system and per-user concept. So far we sometimes used a boolean indicating whether we are in system mode, or a reversed boolean indicating whether we are in user mode, or the LookupScope enum used by the lookup path logic. Let's address that, in introduce a common enum for this, we can use all across the board. This is mostly just search/replace, no actual code changes.
* test-specifier: do not fail if machine-id is missingLuca Boccassi2022-10-251-2/+7
| | | | When building in a chroot there might not be any machine-id
* specifier: use %q for pretty hostnameLennart Poettering2022-04-081-1/+1
| | | | | | | %R is already used in service manager specifier expansion (cgroup root), hence use a different char, that was so far not used. Follow-up for: 6ceb0a4094908dd213a78b9f6d0c59a684831ab0
* Rename UnitFileScope to LookupScopeZbigniew Jędrzejewski-Szmek2022-03-291-1/+1
| | | | | | | | | As suggested in https://github.com/systemd/systemd/pull/22649/commits/8b3ad3983f5440eef812b34e5ed862ca59fdf7f7#r837345892 The define is generalized and moved to path-lookup.h, where it seems to fit better. This allows a recursive include to be removed and in general makes things simpler.
* shared/specifier: fix %u/%U/%g/%G when called as unprivileged userZbigniew Jędrzejewski-Szmek2022-03-291-1/+2
| | | | | | | | | | | | | | | | We would resolve those specifiers to the calling user/group. This is mostly OK when done in the manager, because the manager generally operates as root in system mode, and a non-root in user mode. It would still be wrong if called with --test though. But in systemctl, this would be generally wrong, since we can call 'systemctl --system' as a normal user, either for testing or even for actual operation with '--root=…'. When operating in --global mode, %u/%U/%g/%G should return an error. The information whether we're operating in system mode, user mode, or global mode is passed as the data pointer to specifier_group_name(), specifier_user_name(), specifier_group_id(), specifier_user_id(). We can't use userdata, because it's already used for other things.
* shared/specifier: provide proper error messages when specifiers fail to read ↵Zbigniew Jędrzejewski-Szmek2022-03-291-1/+1
| | | | | | | | | | | | | | | files ENOENT is easily confused with the file that we're working on not being present, e.g. when the file contains %o or something else that requires os-release to be present. Let's use -EUNATCH instead to reduce that chances of confusion if the context of the error is lost. And once we have pinpointed the reason, let's provide a proper error message: + build/systemctl --root=/tmp/systemctl-test.TO7Mcb enable some-some-link6@.socket /tmp/systemctl-test.TO7Mcb/etc/systemd/system/some-some-link6@.socket: Failed to resolve alias "target@A:%A.socket": Protocol driver not attached Failed to enable unit, cannot resolve specifiers in "target@A:%A.socket".
* shared/specifier: clarify and add test for missing dataZbigniew Jędrzejewski-Szmek2022-03-291-0/+14
| | | | | | In systemd.unit we document that unset fields resolve to "". But we didn't directly test this, so let's do that. Also, we return -ENOENT if the file is missing, which we didn't document or test.
* core: introduce %R specifier for pretty hostnameFrantisek Sumsal2022-03-101-1/+1
| | | | Resolves: #20054
* core: add %y/%Y specifiers for the fragment path of the unitZbigniew Jędrzejewski-Szmek2022-01-211-0/+42
| | | | | | | | | | | | | | | | | | Fixes #6308: people want to be able to link a unit file via 'systemctl enable' from a git checkout or such and refer to other files in the same repo. The new specifiers make that easy. %y/%Y is used because other more obvious choices like %d/%D or %p/%P are not available because at least on of the two letters is already used. The new specifiers are only available in units. Technically it would be trivial to add then in [Install] too, but I don't see how they could be useful, so I didn't do that. I added both %y and %Y because both were requested in the issue, and because I think both could be useful, depending on the case. %Y to refer to other files in the same repo, and %y in the case where a single repo has multiple unit files, and e.g. each unit has some corresponding asset named after the unit file.
* shared/specifier: treat NULL the same as ""Zbigniew Jędrzejewski-Szmek2022-01-201-4/+5
| | | | | | We would busily allocate an empty string to concatenate all of it's zero characters to the output. Let's make things a bit simpler by letting the specifier functions return NULL to mean "nothing to append".
* test: Use TEST macroJan Janssen2021-11-251-22/+5
| | | | | | | | | This converts to TEST macro where it is trivial. Some additional notable changes: - simplify HAVE_LIBIDN #ifdef in test-dns-domain.c - use saved_argc/saved_argv in test-copy.c, test-path-util.c, test-tmpfiles.c and test-unit-file.c
* tree-wide: make specifier expansion --root= awareLennart Poettering2021-06-241-4/+4
| | | | | | | | | | | | | | | | | | | | | | This fixes repart's, systemctl's, sysusers' and tmpfiles' specifier expansion to honour the root dir specified with --root=. This is relevant for specifiers such as %m, %o, … which are directly sourced from files on disk. This doesn't try to be overly smart: specifiers referring to runtime concepts (i.e. boot ID, architecture, hostname) rather than files on the medium are left as is. There's certainly a point to be made that they should fail in case --root= is specified, but I am not entirely convinced about that, and it's certainly something we can look into later if there's reason to. I wondered for a while how to hook this up best, but given that quite a large number of specifiers resolve to data from files on disks, and most of our tools needs this, I ultimately decided to make the root dir a first class parameter to specifier_printf(). Replaces: #16187 Fixes: #16183
* tree-wide: refuse too long strings earlier in specifier_printf()Yu Watanabe2021-05-121-4/+4
| | | | | | | | | | | | We usually call specifier_printf() and then check the validity of the result. In many cases, validity checkers, e.g. path_is_valid(), refuse too long strings. This makes specifier_printf() refuse such long results earlier. Moreover, unit_full_string() and description field in sysuser now refuse results longer than LONG_LINE_MAX. config_parse() already refuses the line longer than LONG_LINE_MAX. Hence, it should be ok to set the same value as the maximum length of the resolved string.
* test: move test_specifier_printf() to test-specifier.cYu Watanabe2021-05-121-0/+33
|
* specifiers: introduce common macros for generating specifier tablesLennart Poettering2020-11-251-17/+4
| | | | | | | | | | | | | In many cases the tables are largely the same, hence define a common set of macros to generate the common parts. This adds in a couple of missing specifiers here and there, so is more thant just refactoring: it actually fixes accidental omissions. Note that some entries that look like they could be unified under these macros can't really be unified, since they are slightly different. For example in the DNSSD service logic we want to use the DNSSD hostname for %H rather than the unmodified kernel one.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* test-specifier: add a simple test which prints "global" specifiersZbigniew Jędrzejewski-Szmek2020-05-071-1/+47
| | | | ...i.e. those which can be resolved without a context parameter.
* tests: use a helper function to parse environment and open loggingZbigniew Jędrzejewski-Szmek2018-09-141-1/+2
| | | | | The advantages are that we save a few lines, and that we can override logging using environment variables in more test executables.
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-3/+0
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-06-141-2/+0
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-04-061-13/+0
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* specifier: add helper for escaping '%' characters to avoid making them ↵Lennart Poettering2017-11-291-0/+66
subject for expansion This is ultimately just a wrapper around strreplace(), but it makes things a bit more self-descriptive.