mirror of
https://gitlab.freedesktop.org/wayland/weston
synced 2024-07-21 02:25:36 +00:00
custom-env: Prepare for handling args as well as environment
Rename the bits handling environment variables (currently, all of it), so we have room to handle args as well. No functional changes. Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
parent
3af823b69b
commit
fafe5f0fc2
|
@ -137,7 +137,7 @@ spawn_xserver(void *user_data, const char *display, int abstract_fd, int unix_fd
|
|||
str_printf(&exec_failure_msg,
|
||||
"Error: executing Xwayland as '%s' failed.\n", xserver);
|
||||
custom_env_init_from_environ(&child_env);
|
||||
custom_env_set(&child_env, "WAYLAND_SOCKET", wayland_socket.str1);
|
||||
custom_env_set_env_var(&child_env, "WAYLAND_SOCKET", wayland_socket.str1);
|
||||
envp = custom_env_get_envp(&child_env);
|
||||
|
||||
const char *const argv[] = {
|
||||
|
|
|
@ -76,11 +76,11 @@ custom_env_init_from_environ(struct custom_env *env)
|
|||
char **it;
|
||||
char **ep;
|
||||
|
||||
wl_array_init(&env->p);
|
||||
env->finalized = false;
|
||||
wl_array_init(&env->envp);
|
||||
env->env_finalized = false;
|
||||
|
||||
for (it = environ; *it; it++) {
|
||||
ep = wl_array_add(&env->p, sizeof *ep);
|
||||
ep = wl_array_add(&env->envp, sizeof *ep);
|
||||
assert(ep);
|
||||
*ep = strdup(*it);
|
||||
assert(*ep);
|
||||
|
@ -90,21 +90,21 @@ custom_env_init_from_environ(struct custom_env *env)
|
|||
void
|
||||
custom_env_fini(struct custom_env *env)
|
||||
{
|
||||
char **ep;
|
||||
char **p;
|
||||
|
||||
wl_array_for_each(ep, &env->p)
|
||||
free(*ep);
|
||||
wl_array_for_each(p, &env->envp)
|
||||
free(*p);
|
||||
|
||||
wl_array_release(&env->p);
|
||||
wl_array_release(&env->envp);
|
||||
}
|
||||
|
||||
static char **
|
||||
custom_env_find_element(struct custom_env *env, const char *name)
|
||||
custom_env_get_env_var(struct custom_env *env, const char *name)
|
||||
{
|
||||
char **ep;
|
||||
size_t name_len = strlen(name);
|
||||
|
||||
wl_array_for_each(ep, &env->p) {
|
||||
wl_array_for_each(ep, &env->envp) {
|
||||
char *entry = *ep;
|
||||
|
||||
if (strncmp(entry, name, name_len) == 0 &&
|
||||
|
@ -117,18 +117,18 @@ custom_env_find_element(struct custom_env *env, const char *name)
|
|||
}
|
||||
|
||||
void
|
||||
custom_env_set(struct custom_env *env, const char *name, const char *value)
|
||||
custom_env_set_env_var(struct custom_env *env, const char *name, const char *value)
|
||||
{
|
||||
char **ep;
|
||||
|
||||
assert(strchr(name, '=') == NULL);
|
||||
assert(!env->finalized);
|
||||
assert(!env->env_finalized);
|
||||
|
||||
ep = custom_env_find_element(env, name);
|
||||
ep = custom_env_get_env_var(env, name);
|
||||
if (ep)
|
||||
free(*ep);
|
||||
else
|
||||
ep = wl_array_add(&env->p, sizeof *ep);
|
||||
ep = wl_array_add(&env->envp, sizeof *ep);
|
||||
assert(ep);
|
||||
|
||||
str_printf(ep, "%s=%s", name, value);
|
||||
|
@ -140,14 +140,14 @@ custom_env_get_envp(struct custom_env *env)
|
|||
{
|
||||
char **ep;
|
||||
|
||||
assert(!env->finalized);
|
||||
assert(!env->env_finalized);
|
||||
|
||||
/* add terminating NULL */
|
||||
ep = wl_array_add(&env->p, sizeof *ep);
|
||||
ep = wl_array_add(&env->envp, sizeof *ep);
|
||||
assert(ep);
|
||||
*ep = NULL;
|
||||
|
||||
env->finalized = true;
|
||||
env->env_finalized = true;
|
||||
|
||||
return env->p.data;
|
||||
return env->envp.data;
|
||||
}
|
||||
|
|
|
@ -66,8 +66,8 @@ fdstr_close_all(struct fdstr *s);
|
|||
* between fork() and exec().
|
||||
*/
|
||||
struct custom_env {
|
||||
struct wl_array p;
|
||||
bool finalized;
|
||||
struct wl_array envp;
|
||||
bool env_finalized;
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -77,7 +77,7 @@ void
|
|||
custom_env_fini(struct custom_env *env);
|
||||
|
||||
void
|
||||
custom_env_set(struct custom_env *env, const char *name, const char *value);
|
||||
custom_env_set_env_var(struct custom_env *env, const char *name, const char *value);
|
||||
|
||||
char *const *
|
||||
custom_env_get_envp(struct custom_env *env);
|
||||
|
|
Loading…
Reference in a new issue