diff options
author | Anita Zhang <the.anitazha@gmail.com> | 2019-02-20 14:53:58 -0800 |
---|---|---|
committer | Anita Zhang <the.anitazha@gmail.com> | 2019-05-30 20:41:42 -0700 |
commit | b3d593673c5b8b0b7d781fd26ab2062ca6e7dbdb (patch) | |
tree | b8c32bff31ac2b3336ceaeee6bc8588b4a09e4dd /src/test | |
parent | 9e90465539345b25628edaa39f55489a9cfb7479 (diff) | |
download | systemd-b3d593673c5b8b0b7d781fd26ab2062ca6e7dbdb.tar.gz systemd-b3d593673c5b8b0b7d781fd26ab2062ca6e7dbdb.tar.bz2 systemd-b3d593673c5b8b0b7d781fd26ab2062ca6e7dbdb.zip |
core: add ExecStartXYZEx= with dbus support for executable prefixes
Closes #11654
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-exec-util.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/test-exec-util.c b/src/test/test-exec-util.c index f6f2e6317e..ec51891634 100644 --- a/src/test/test-exec-util.c +++ b/src/test/test-exec-util.c @@ -402,6 +402,50 @@ static void test_error_catching(void) { assert_se(r == 42); } +static void test_exec_command_flags_from_strv(void) { + ExecCommandFlags flags = 0; + char **valid_strv = STRV_MAKE("no-env-expand", "no-setuid", "ignore-failure"); + char **invalid_strv = STRV_MAKE("no-env-expand", "no-setuid", "nonexistent-option", "ignore-failure"); + int r; + + r = exec_command_flags_from_strv(valid_strv, &flags); + + assert_se(r == 0); + assert_se(FLAGS_SET(flags, EXEC_COMMAND_NO_ENV_EXPAND)); + assert_se(FLAGS_SET(flags, EXEC_COMMAND_NO_SETUID)); + assert_se(FLAGS_SET(flags, EXEC_COMMAND_IGNORE_FAILURE)); + assert_se(!FLAGS_SET(flags, EXEC_COMMAND_AMBIENT_MAGIC)); + assert_se(!FLAGS_SET(flags, EXEC_COMMAND_FULLY_PRIVILEGED)); + + r = exec_command_flags_from_strv(invalid_strv, &flags); + + assert_se(r == -EINVAL); +} + +static void test_exec_command_flags_to_strv(void) { + _cleanup_strv_free_ char **opts = NULL, **empty_opts = NULL, **invalid_opts = NULL; + ExecCommandFlags flags = 0; + int r; + + flags |= (EXEC_COMMAND_AMBIENT_MAGIC|EXEC_COMMAND_NO_ENV_EXPAND|EXEC_COMMAND_IGNORE_FAILURE); + + r = exec_command_flags_to_strv(flags, &opts); + + assert_se(r == 0); + assert_se(strv_equal(opts, STRV_MAKE("ignore-failure", "ambient", "no-env-expand"))); + + r = exec_command_flags_to_strv(0, &empty_opts); + + assert_se(r == 0); + assert_se(strv_equal(empty_opts, STRV_MAKE_EMPTY)); + + flags = _EXEC_COMMAND_FLAGS_INVALID; + + r = exec_command_flags_to_strv(flags, &invalid_opts); + + assert_se(r == -EINVAL); +} + int main(int argc, char *argv[]) { test_setup_logging(LOG_DEBUG); @@ -411,6 +455,8 @@ int main(int argc, char *argv[]) { test_stdout_gathering(); test_environment_gathering(); test_error_catching(); + test_exec_command_flags_from_strv(); + test_exec_command_flags_to_strv(); return 0; } |