summaryrefslogtreecommitdiff
path: root/glib/tests/spawn-path-search-helper.c
diff options
context:
space:
mode:
authorSimon McVittie <smcv@collabora.com>2021-01-31 14:01:06 +0000
committerSimon McVittie <smcv@collabora.com>2021-01-31 14:15:37 +0000
commita85c126602a8927a11a437a1dde71d253d3d38b6 (patch)
tree4248f7987a58b82555ecd3255b43fc0645baf75d /glib/tests/spawn-path-search-helper.c
parente864c6577ad45ecf614c63850ef059edf3313670 (diff)
downloadglib-wip/avoid-searching-path.tar.gz
Expand test coverage for G_SPAWN_SEARCH_PATHwip/avoid-searching-path
Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'glib/tests/spawn-path-search-helper.c')
-rw-r--r--glib/tests/spawn-path-search-helper.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/glib/tests/spawn-path-search-helper.c b/glib/tests/spawn-path-search-helper.c
index b417c7896..378c203c7 100644
--- a/glib/tests/spawn-path-search-helper.c
+++ b/glib/tests/spawn-path-search-helper.c
@@ -55,6 +55,7 @@ main (int argc,
gboolean search_path = FALSE;
gboolean search_path_from_envp = FALSE;
gboolean slow_path = FALSE;
+ gboolean unset_path_in_envp = FALSE;
gchar *chdir_child = NULL;
gchar *set_path_in_envp = NULL;
gchar **envp = NULL;
@@ -72,6 +73,9 @@ main (int argc,
{ "set-path-in-envp", '\0',
G_OPTION_FLAG_NONE, G_OPTION_ARG_FILENAME, &set_path_in_envp,
"Set PATH in specified environment to this value", "PATH", },
+ { "unset-path-in-envp", '\0',
+ G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &unset_path_in_envp,
+ "Unset PATH in specified environment", NULL },
{ "slow-path", '\0',
G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &slow_path,
"Use a child-setup function to avoid the posix_spawn fast path", NULL },
@@ -102,9 +106,20 @@ main (int argc,
envp = g_get_environ ();
+ if (set_path_in_envp != NULL && unset_path_in_envp)
+ {
+ g_set_error (&error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
+ "Cannot both set PATH and unset it");
+ ret = 2;
+ goto out;
+ }
+
if (set_path_in_envp != NULL)
envp = g_environ_setenv (envp, "PATH", set_path_in_envp, TRUE);
+ if (unset_path_in_envp)
+ envp = g_environ_unsetenv (envp, "PATH");
+
if (search_path)
spawn_flags |= G_SPAWN_SEARCH_PATH;