summaryrefslogtreecommitdiffstats
path: root/src/test/test-core-unit.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* ASSERT_STREQ for simple casesIvan Kruglov2024-04-151-7/+7
|
* ASSERT_NULL/ASSERT_NOT_NULLIvan Kruglov2024-04-101-1/+1
|
* tree-wide: Fix -Wmaybe-uninitialized compilation warningsDaan De Meyer2023-08-041-4/+4
|
* core/unit: add UNIT_ESCAPE_EXEC_SYNTAXZbigniew Jędrzejewski-Szmek2023-04-241-18/+38
| | | | | | | | | | Unfortunately we can't escape $ when ':' is used to prohibit variable expansion: ExecStart=:echo $$ is not the same as ExecStart=:echo $ This just adds the functionality and the unittests, without using it anywhere for real yet.
* core/unit: rename UNIT_ESCAPE_EXEC_SYNTAX → *_ENVZbigniew Jędrzejewski-Szmek2023-04-241-2/+2
| | | | In preparation for future changes.
* core/unit: fix shell-escaping of stringsZbigniew Jędrzejewski-Szmek2023-04-241-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Our escaping of '$' is '$$', not '\$'. We would write unit files that were not valid: $ systemd-run --user bash -c 'echo $$; sleep 1000' Running as unit: run-r1c7c45b5b69f487c86ae205e12100808.service $ systemctl cat --user run-r1c7c45b5b69f487c86ae205e12100808 # /run/user/1000/systemd/transient/run-r1c7c45b5b69f487c86ae205e12100808.service ... ExecStart="/usr/bin/bash" "-c" "echo \$\$\; sleep 1000" $ systemd-analyze verify /run/user/1000/systemd/transient/run-r1c7c45b5b69f487c86ae205e12100808.service /run/user/1000/systemd/transient/run-r1c7c45b5b69f487c86ae205e12100808.service:7: Ignoring unknown escape sequences: "echo \$\$\; sleep 1000" Similarly, ';' cannot be escaped as '\;'. Only a handful of characters listed in "Supported escapes" is allowed. Escaping of "'" can be done, but it's not useful because we use double quotes around the string anyway whenever we do escaping. unit_write_setting() is called all over the place. In a great majority of places we write either fixed strings or something that we generate ourselves, so no escaping or quoting is needed. (And it's not allowed, e.g. 'Type="oneshot"' would not work.) But if we forgot to add escaping or quoting for a free-style string, it would probably allow writing a unit file that would be read completely wrong. I looked over various places where unit_write_setting() is called, and I couldn't find any place where quoting/escaping was forgotten. But trying to figure out the full ramifications of this change is not easy.
* test-core-unit: add new test file for unit_escape_setting() and friendsZbigniew Jędrzejewski-Szmek2023-04-041-0/+100
None of the existing test files fit very well. test-unit-serialize is pretty close, but it does special cgroup setup, which we don't need in this case. I hope we can add more tests in the future for this basic functionality, so I'm adding a brand new file names after the source file it's testing.