summaryrefslogtreecommitdiffstats
path: root/src/shared/specifier.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: host_name → hostnameZbigniew Jędrzejewski-Szmek2022-04-111-25/+25
| | | | | We use "hostname" exclusively in docs, and also in a big majority of the code. Let's use the same spelling in remaining places.
* specifier: use %q for pretty hostnameLennart Poettering2022-04-081-1/+2
| | | | | | | %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
* shared/specifier: fix %u/%U/%g/%G when called as unprivileged userZbigniew Jędrzejewski-Szmek2022-03-291-5/+5
| | | | | | | | | | | | | | | | 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.
* core: introduce %R specifier for pretty hostnameFrantisek Sumsal2022-03-101-0/+2
| | | | Resolves: #20054
* core: add %y/%Y specifiers for the fragment path of the unitZbigniew Jędrzejewski-Szmek2022-01-211-0/+2
| | | | | | | | | | | | | | | | | | 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.
* tree-wide: make specifier expansion --root= awareLennart Poettering2021-06-241-23/+23
| | | | | | | | | | | | | | | | | | | | | | 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
* sysusers: add a generic specifier table for common casesLennart Poettering2021-05-261-1/+3
| | | | | | | This moves the definition of the specifier table consisting only of system and /tmp specifiers into generic code so that we can share it. This patch only adds one user of it for now. Follow-up patches will add more.
* tree-wide: refuse too long strings earlier in specifier_printf()Yu Watanabe2021-05-121-1/+1
| | | | | | | | | | | | 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.
* shared: add new IMAGE_VERSION=/IMAGE_ID= field to /etc/os-releaseLennart Poettering2021-03-311-0/+7
| | | | | | | | | | | | | | | | | | | | | | This specifes two new optional fields for /etc/os-release: IMAGE_VERSION= and IMAGE_ID= that are supposed to identify the image of the current booted system by name and version. This is inspired by the versioning stuff in https://github.com/systemd/mkosi/pull/683. In environments where pre-built images are installed and updated as a whole the existing os-release version/distro identifier are not sufficient to describe the system's version, as they describe only the distro an image is built from, but not the image itself, even if that image is deployed many times on many systems, and even if that image contains more resources than just the RPMs/DEBs. In particular, "mkosi" is a tool for building disk images based on distro RPMs with additional resources dropped in. The combination of all of these together with their versions should also carry an identifier and version, and that's what IMAGE_VERSION= and IMAGE_ID= is supposed to be.
* tree-wide: sort specifiers and move common comments to specifier.hYu Watanabe2020-11-251-7/+31
|
* specifiers: introduce common macros for generating specifier tablesLennart Poettering2020-11-251-0/+24
| | | | | | | | | | | | | 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
|
* Add %l as specifier for the hostname without any domain componentZbigniew Jędrzejewski-Szmek2020-05-071-0/+1
| | | | | | | | | 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.
* tree-wide: support a bunch of additional specifiersLennart Poettering2020-04-281-0/+5
|
* Mark *data and *userdata params to specifier_printf() as constZbigniew Jędrzejewski-Szmek2018-12-121-16/+16
| | | | | | | It would be very wrong if any of the specfier printf calls modified any of the objects or data being printed. Let's mark all arguments as const (primarily to make it easier for the reader to see where modifications cannot occur).
* shared: add %g, %G specifiers for group / gid (#10368)Davide Cavalca2018-10-131-0/+2
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-06-141-4/+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.
* core: introduce specifiers for /tmp and /var/tmpLennart Poettering2018-05-291-0/+3
| | | | | | | | | | | This corresponds nicely with the specifiers we already pass for /var/lib, /var/cache, /run and so on. This is particular useful to update the test-path service files to operate without guessable files, thus allowing multiple parallel test-path invocations to pass without issues (the idea is to set $TMPDIR early on in the test to some private directory, and then only use the new %T or %V specifier to refer to it).
* 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: unify specifier implementations for user-related specifiersLennart Poettering2017-11-291-0/+5
| | | | | | The code in install-printf.c and unit-printf.c for these is pretty much the same and very generic. Let's move this all over to the generic specifier.c, and share the implementations.
* specifier: add helper for escaping '%' characters to avoid making them ↵Lennart Poettering2017-11-291-0/+8
| | | | | | | subject for expansion This is ultimately just a wrapper around strreplace(), but it makes things a bit more self-descriptive.
* Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek2017-11-191-0/+1
| | | | | This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
* tree-wide: remove Emacs lines from all filesDaniel Mack2016-02-101-2/+0
| | | | | This should be handled fine now by .dir-locals.el, so need to carry that stuff in every file.
* specifier: rework specifier calls to return proper error messageLennart Poettering2013-09-171-7/+7
| | | | | | Previously the specifier calls could only indicate OOM by returning NULL. With this change they will return negative errno-style error codes like everything else.
* core: add %v specifierZbigniew Jędrzejewski-Szmek2013-07-191-0/+1
|
* Move generic specifier functions to sharedZbigniew Jędrzejewski-Szmek2013-01-301-1/+5
| | | | No functional change. This makes it possible to use them in install.c.
* use #pragma once instead of foo*foo #define guardsShawn Landden2012-07-191-4/+1
| | | | | | | | | | | | | | | | | #pragma once has been "un-deprecated" in gcc since 3.3, and is widely supported in other compilers. I've been using and maintaining (rebasing) this patch for a while now, as it annoyed me to see #ifndef fooblahfoo, etc all over the place, almost arrogant about the annoyance of having to define all these names to perform a commen but neccicary functionality, when a completely superior alternative exists. I havn't sent it till now, cause its kindof a style change, and it is bad voodoo to mess with style that has been established by more established editors. So feel free to lambast me as a crazy bafoon. v2 - preserve externally used headers
* move more common files to shared/ and add them to shared.laKay Sievers2012-04-121-0/+37