summaryrefslogtreecommitdiff
path: root/src/shared/specifier.c
Commit message (Collapse)AuthorAgeFilesLines
* headers: remove unneeded includes from util.hZbigniew Jędrzejewski-Szmek2019-03-271-0/+1
| | | | | This means we need to include many more headers in various files that simply included util.h before, but it seems cleaner to do it this way.
* Mark *data and *userdata params to specifier_printf() as constZbigniew Jędrzejewski-Szmek2018-12-121-14/+14
| | | | | | | 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/+18
|
* tree-wide: drop empty lines in commentsYu Watanabe2018-07-231-1/+0
|
* 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.
* core: introduce specifiers for /tmp and /var/tmpLennart Poettering2018-05-291-0/+35
| | | | | | | | | | | 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.
* shared/specifier: use realloc to free some memory after specifier expansionZbigniew Jędrzejewski-Szmek2018-03-281-2/+9
| | | | | | | | | | | This is a separate commit only because it actually *increases* memory allocations: ==3256== total heap usage: 100,120 allocs, 100,120 frees, 13,097,140 bytes allocated to ==4690== total heap usage: 100,121 allocs, 100,121 frees, 14,198,329 bytes allocated Essentially, we do a little more work to reduce the memory footprint a bit. For a test where we just allocate the memory and drop it soon afterwards, this is not beneficial, but it should still be useful for a long running program.
* shared/specifier: be less extravagant with memory allocationsZbigniew Jędrzejewski-Szmek2018-03-281-15/+5
| | | | | | | | | | | | | | | | | | | | ubsan times out because we do too many allocations: $ valgrind build/fuzz-unit-file test/fuzz-regressions/fuzz-unit-file/oss-fuzz-6977-full ... test/fuzz-regressions/fuzz-unit-file/oss-fuzz-6977-full... ok ==1757== ==1757== HEAP SUMMARY: ==1757== in use at exit: 0 bytes in 0 blocks ==1757== total heap usage: 199,997 allocs, 199,997 frees, 90,045,318,585 bytes allocated ... ==3256== total heap usage: 100,120 allocs, 100,120 frees, 13,097,140 bytes allocated https://oss-fuzz.com/v2/issue/4651449704251392/6977 should now be really fixed. e3c3d6761b3e7d was the first attempt, but even with this change, e3c3d6761b3e7d still makes sense.
* macro: introduce TAKE_PTR() macroLennart Poettering2018-03-221-2/+1
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* shared: use _cleanup_ in specifier_printf (#7586)Zbigniew Jędrzejewski-Szmek2017-12-081-15/+10
| | | Follow-up for e62d316561.
* shared: fix a memory leakEvgeny Vereshchagin2017-12-061-2/+3
| | | | | | | | | | | | | | | | | | | ``` $ ./src/test/test-systemd-tmpfiles.py valgrind --leak-check=full --error-exitcode=1 ./build/systemd-tmpfiles ... Running valgrind --leak-check=full --error-exitcode=1 ./build/systemd-tmpfiles on 'w /unresolved/argument - - - - "%Y"' ... [<stdin>:1] Failed to substitute specifiers in argument: Invalid slot ... ==22602== 5 bytes in 1 blocks are definitely lost in loss record 1 of 2 ==22602== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==22602== by 0x4ECA7D4: malloc_multiply (alloc-util.h:74) ==22602== by 0x4ECA909: specifier_printf (specifier.c:59) ==22602== by 0x113490: specifier_expansion_from_arg (tmpfiles.c:1923) ==22602== by 0x1144E7: parse_line (tmpfiles.c:2159) ==22602== by 0x11551C: read_config_file (tmpfiles.c:2425) ==22602== by 0x115AB0: main (tmpfiles.c:2529) ```
* Fix typoZbigniew Jędrzejewski-Szmek2017-12-061-1/+1
|
* Fail on unknown (alphanumerical) specifiersZbigniew Jędrzejewski-Szmek2017-12-061-1/+8
| | | | | | | | | | | | | | | | | | | | | | | The code intentionally ignored unknown specifiers, treating them as text. This needs to change because otherwise we can never add a new specifier in a backwards compatible way. So just treat an unknown (potential) specifier as an error. In principle this is a break of backwards compatibility, but the previous behaviour was pretty much useless, since the expanded value could change every time we add new specifiers, which we do all the time. As a compromise for backwards compatibility, only fail on alphanumerical characters. This should cover the most cases where an unescaped percent character is used, like size=5% and such, which behave the same as before with this patch. OTOH, this means that we will not be able to use non-alphanumerical specifiers without breaking backwards compatibility again. I think that's an acceptable compromise. v2: - add NEWS entry v3: - only fail on alphanumerical
* specifier: unify specifier implementations for user-related specifiersLennart Poettering2017-11-291-0/+43
| | | | | | 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/+30
| | | | | | | 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.
* shared: end string with % if one was found at the end of a expandible string ↵Felipe Sateler2017-09-141-0/+4
| | | | | | | | | (#6828) Current behavior is that %X where X is an unidentified specifier, then the result is the same %X string. This was not the case when the string ended with a stray %, where the character would have not been output. Lets add that missing character. Fixes: #6374
* 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.
* shared: include what we useThomas Hindoe Paaboel Andersen2015-12-061-1/+6
| | | | | The next step of a general cleanup of our includes. This one mostly adds missing includes but there are a few removals as well.
* util-lib: split out allocation calls into alloc-util.[ch]Lennart Poettering2015-10-271-1/+2
|
* util-lib: split our string related calls from util.[ch] into its own file ↵Lennart Poettering2015-10-241-1/+2
| | | | | | | | | | | | | | string-util.[ch] There are more than enough calls doing string manipulations to deserve its own files, hence do something about it. This patch also sorts the #include blocks of all files that needed to be updated, according to the sorting suggestions from CODING_STYLE. Since pretty much every file needs our string manipulation functions this effectively means that most files have sorted #include blocks now. Also touches a few unrelated include files.
* util: split all hostname related calls into hostname-util.cLennart Poettering2015-05-181-0/+1
|
* specifier: rework specifier calls to return proper error messageLennart Poettering2013-09-171-41/+64
| | | | | | 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/+12
|
* Move generic specifier functions to sharedZbigniew Jędrzejewski-Szmek2013-01-291-0/+36
| | | | No functional change. This makes it possible to use them in install.c.
* specifier: minor modernizationsLennart Poettering2012-11-141-3/+6
|
* move more common files to shared/ and add them to shared.laKay Sievers2012-04-121-0/+108