custom-env: Add support for argument array

execve() takes the same form for arguments as environment: an array of
constant pointers to mutable strings, terminated by a NULL.

To make it easier for users who want to build up their own argument
strings to pass to execve, add support for argument arrays to custom_env.

Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
Daniel Stone
2022-07-12 14:46:56 +01:00
committed by Pekka Paalanen
parent 2a9cae17d8
commit e568a025e1
3 changed files with 67 additions and 4 deletions
+19
View File
@@ -73,6 +73,8 @@ setup_env(struct weston_test_harness *harness)
DECLARE_FIXTURE_SETUP(setup_env);
#define DEFAULT_ENVP (char * const []) { "ENV1=one", "ENV2=two", "ENV3=three", NULL }
TEST(basic_env)
{
struct custom_env env;
@@ -85,3 +87,20 @@ TEST(basic_env)
assert(env.env_finalized);
custom_env_fini(&env);
}
TEST(basic_env_arg)
{
struct custom_env env;
char *const argp[] = { "arg1", "arg2", "arg3", NULL };
custom_env_init_from_environ(&env);
custom_env_add_arg(&env, "arg1");
custom_env_add_arg(&env, "arg2");
custom_env_add_arg(&env, "arg3");
ASSERT_STR_ARRAY_MATCH("envp", custom_env_get_envp(&env), DEFAULT_ENVP);
assert(env.env_finalized);
ASSERT_STR_ARRAY_MATCH("argp", custom_env_get_argp(&env), argp);
assert(env.arg_finalized);
custom_env_fini(&env);
}