diff options
Diffstat (limited to 'src/test/test-unit-file.c')
-rw-r--r-- | src/test/test-unit-file.c | 65 |
1 files changed, 60 insertions, 5 deletions
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index e517f571d6..a8025c825b 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -20,7 +20,6 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <assert.h> #include <stdio.h> #include <stddef.h> #include <string.h> @@ -37,6 +36,7 @@ #include "strv.h" #include "fileio.h" #include "test-helper.h" +#include "hostname-util.h" static int test_unit_file_get_set(void) { int r; @@ -92,6 +92,7 @@ static void check_execcommand(ExecCommand *c, static void test_config_parse_exec(void) { /* int config_parse_exec( + const char *unit, const char *filename, unsigned line, const char *section, @@ -224,6 +225,15 @@ static void test_config_parse_exec(void) { check_execcommand(c1, "/sbin/find", NULL, ";", "x", false); + log_info("/* encoded semicolon */"); + r = config_parse_exec(NULL, "fake", 5, "section", 1, + "LValue", 0, + "/bin/find \\073", + &c, NULL); + assert_se(r >= 0); + c1 = c1->command_next; + check_execcommand(c1, "/bin/find", NULL, ";", NULL, false); + log_info("/* spaces in the filename */"); r = config_parse_exec(NULL, "fake", 5, "section", 1, "LValue", 0, @@ -295,6 +305,16 @@ static void test_config_parse_exec(void) { c1 = c1->command_next; check_execcommand(c1, "/path ", NULL, NULL, NULL, false); + log_info("/* quoted backslashes */"); + r = config_parse_exec(NULL, "fake", 5, "section", 1, + "LValue", 0, + "/bin/grep '\\w+\\K'", + &c, NULL); + assert_se(r >= 0); + c1 = c1->command_next; + check_execcommand(c1, "/bin/grep", NULL, "\\w+\\K", NULL, false); + + log_info("/* trailing backslash: \\ */"); /* backslash is invalid */ r = config_parse_exec(NULL, "fake", 4, "section", 1, @@ -303,6 +323,41 @@ static void test_config_parse_exec(void) { assert_se(r == 0); assert_se(c1->command_next == NULL); + log_info("/* missing ending ' */"); + r = config_parse_exec(NULL, "fake", 4, "section", 1, + "LValue", 0, "/path 'foo", + &c, NULL); + assert_se(r == 0); + assert_se(c1->command_next == NULL); + + log_info("/* missing ending ' with trailing backslash */"); + r = config_parse_exec(NULL, "fake", 4, "section", 1, + "LValue", 0, "/path 'foo\\", + &c, NULL); + assert_se(r == 0); + assert_se(c1->command_next == NULL); + + log_info("/* invalid space between modifiers */"); + r = config_parse_exec(NULL, "fake", 4, "section", 1, + "LValue", 0, "- /path", + &c, NULL); + assert_se(r == 0); + assert_se(c1->command_next == NULL); + + log_info("/* only modifiers, no path */"); + r = config_parse_exec(NULL, "fake", 4, "section", 1, + "LValue", 0, "-", + &c, NULL); + assert_se(r == 0); + assert_se(c1->command_next == NULL); + + log_info("/* empty argument, reset */"); + r = config_parse_exec(NULL, "fake", 4, "section", 1, + "LValue", 0, "", + &c, NULL); + assert_se(r == 0); + assert_se(c == NULL); + exec_command_free_list(c); } @@ -439,12 +494,12 @@ static void test_install_printf(void) { char name[] = "name.service", path[] = "/run/systemd/system/name.service", user[] = "xxxx-no-such-user"; - InstallInfo i = {name, path, user}; - InstallInfo i2 = {name, path, NULL}; + UnitFileInstallInfo i = {name, path, user}; + UnitFileInstallInfo i2 = {name, path, NULL}; char name3[] = "name@inst.service", path3[] = "/run/systemd/system/name.service"; - InstallInfo i3 = {name3, path3, user}; - InstallInfo i4 = {name3, path3, NULL}; + UnitFileInstallInfo i3 = {name3, path3, user}; + UnitFileInstallInfo i4 = {name3, path3, NULL}; _cleanup_free_ char *mid, *bid, *host; |