diff --git a/gio/gcontenttype.c b/gio/gcontenttype.c index 3e5b841ab..3c9522bc6 100644 --- a/gio/gcontenttype.c +++ b/gio/gcontenttype.c @@ -780,7 +780,7 @@ g_content_type_guess (const gchar *filename, if (filename) { i = strlen (filename); - if (filename[i - 1] == '/') + if (i > 0 && filename[i - 1] == '/') { name_mimetypes[0] = "inode/directory"; name_mimetypes[1] = NULL; diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c index 30812dba6..fc2a96c94 100644 --- a/glib/gspawn-win32.c +++ b/glib/gspawn-win32.c @@ -637,6 +637,13 @@ fork_exec (gint *exit_status, argc = protect_argv (argv, &protected_argv); + /* + * FIXME: Workaround broken spawnvpe functions that SEGV when "=X:=" + * environment variables are missing. Calling chdir() will set the magic + * environment variable again. + */ + _chdir ("."); + if (stdin_fd == -1 && stdout_fd == -1 && stderr_fd == -1 && (flags & G_SPAWN_CHILD_INHERITS_STDIN) && !(flags & G_SPAWN_STDOUT_TO_DEV_NULL) && diff --git a/glib/tests/meson.build b/glib/tests/meson.build index 11563bcfe..9b4e713fc 100644 --- a/glib/tests/meson.build +++ b/glib/tests/meson.build @@ -278,6 +278,16 @@ executable('test-spawn-echo', 'test-spawn-echo.c', install: installed_tests_enabled, ) +if host_machine.system() == 'windows' + # test-spawn-sleep helper binary required by the spawn tests above + executable('test-spawn-sleep', 'test-spawn-sleep.c', + c_args : test_cargs, + dependencies : test_deps, + install_dir: installed_tests_execdir, + install: installed_tests_enabled, + ) +endif + executable('testing-helper', 'testing-helper.c', c_args : test_cargs, dependencies : test_deps, diff --git a/glib/tests/option-argv0.c b/glib/tests/option-argv0.c index 37ac44a9f..a18e68676 100644 --- a/glib/tests/option-argv0.c +++ b/glib/tests/option-argv0.c @@ -39,7 +39,6 @@ test_platform_argv0 (void) const gchar * const expected_prgnames[] = { "option-argv0", - "lt-option-argv0", #ifdef G_OS_WIN32 "option-argv0.exe", #endif diff --git a/glib/tests/spawn-multithreaded.c b/glib/tests/spawn-multithreaded.c index 614e503ca..c73a23433 100644 --- a/glib/tests/spawn-multithreaded.c +++ b/glib/tests/spawn-multithreaded.c @@ -31,6 +31,7 @@ #include static char *echo_prog_path; +static char *sleep_prog_path; #ifdef G_OS_UNIX #include @@ -43,10 +44,6 @@ static char *echo_prog_path; static GMainLoop *global_main_loop; static guint alive; -#ifdef G_OS_WIN32 -static char *argv0; -#endif - static GPid get_a_child (gint ttl) { @@ -61,9 +58,9 @@ get_a_child (gint ttl) si.cb = sizeof (&si); memset (&pi, 0, sizeof (pi)); - cmdline = g_strdup_printf ("child-test -c%d", ttl); + cmdline = g_strdup_printf ("%s %d", sleep_prog_path, ttl); - if (!CreateProcess (argv0, cmdline, NULL, NULL, + if (!CreateProcess (NULL, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) g_error ("CreateProcess failed: %s", g_win32_error_message (GetLastError ())); @@ -145,7 +142,7 @@ test_spawn_childs (void) global_main_loop = g_main_loop_new (NULL, FALSE); #ifdef G_OS_WIN32 - system ("ipconfig /all"); + system ("cd ."); #else system ("true"); #endif @@ -172,7 +169,7 @@ test_spawn_childs_threads (void) global_main_loop = g_main_loop_new (NULL, FALSE); #ifdef G_OS_WIN32 - system ("ipconfig /all"); + system ("cd ."); #else system ("true"); #endif @@ -384,14 +381,13 @@ main (int argc, dirname = g_path_get_dirname (argv[0]); echo_prog_path = g_build_filename (dirname, "test-spawn-echo" EXEEXT, NULL); - if (!g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)) - { - g_free (echo_prog_path); - echo_prog_path = g_build_filename (dirname, "lt-test-spawn-echo" EXEEXT, NULL); - } + sleep_prog_path = g_build_filename (dirname, "test-spawn-sleep" EXEEXT, NULL); g_free (dirname); g_assert (g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)); +#ifdef G_OS_WIN32 + g_assert (g_file_test (sleep_prog_path, G_FILE_TEST_EXISTS)); +#endif g_test_add_func ("/gthread/spawn-childs", test_spawn_childs); g_test_add_func ("/gthread/spawn-childs-threads", test_spawn_childs_threads); @@ -401,6 +397,7 @@ main (int argc, ret = g_test_run(); g_free (echo_prog_path); + g_free (sleep_prog_path); return ret; } diff --git a/glib/tests/spawn-path-search.c b/glib/tests/spawn-path-search.c index 2a8911139..5008fc960 100644 --- a/glib/tests/spawn-path-search.c +++ b/glib/tests/spawn-path-search.c @@ -23,6 +23,17 @@ #include #endif +static gboolean +skip_win32 (void) +{ +#ifdef G_OS_WIN32 + g_test_skip ("The test manipulate PATH, and breaks DLL lookups."); + return TRUE; +#else + return FALSE; +#endif +} + static void test_do_not_search (void) { @@ -38,6 +49,9 @@ test_do_not_search (void) g_test_summary ("Without G_SPAWN_SEARCH_PATH, spawn-test-helper " "means ./spawn-test-helper."); + if (skip_win32 ()) + return; + envp = g_environ_setenv (envp, "PATH", subdir, TRUE); g_ptr_array_add (argv, @@ -90,6 +104,9 @@ test_search_path (void) g_test_summary ("With G_SPAWN_SEARCH_PATH, spawn-test-helper " "means $PATH/spawn-test-helper."); + if (skip_win32 ()) + return; + envp = g_environ_setenv (envp, "PATH", subdir, TRUE); g_ptr_array_add (argv, @@ -143,6 +160,9 @@ test_search_path_from_envp (void) g_test_summary ("With G_SPAWN_SEARCH_PATH_FROM_ENVP, spawn-test-helper " "means $PATH/spawn-test-helper with $PATH from envp."); + if (skip_win32 ()) + return; + envp = g_environ_setenv (envp, "PATH", here, TRUE); g_ptr_array_add (argv, @@ -198,6 +218,9 @@ test_search_path_ambiguous (void) g_test_summary ("With G_SPAWN_SEARCH_PATH and G_SPAWN_SEARCH_PATH_FROM_ENVP, " "the latter wins."); + if (skip_win32 ()) + return; + envp = g_environ_setenv (envp, "PATH", here, TRUE); g_ptr_array_add (argv, @@ -252,6 +275,10 @@ test_search_path_fallback_in_environ (void) int wait_status = -1; g_test_summary ("With G_SPAWN_SEARCH_PATH but no PATH, a fallback is used."); + + if (skip_win32 ()) + return; + /* We can't make a meaningful assertion about what the fallback *is*, * but we can assert that it *includes* the current working directory. */ @@ -319,6 +346,9 @@ test_search_path_fallback_in_envp (void) /* We can't make a meaningful assertion about what the fallback *is*, * but we can assert that it *includes* the current working directory. */ + if (skip_win32 ()) + return; + if (g_file_test ("/usr/bin/spawn-test-helper", G_FILE_TEST_IS_EXECUTABLE) || g_file_test ("/bin/spawn-test-helper", G_FILE_TEST_IS_EXECUTABLE)) { @@ -384,6 +414,9 @@ test_search_path_heap_allocation (void) int wait_status = -1; gsize i; + if (skip_win32 ()) + return; + memset (placeholder, '_', sizeof (placeholder)); /* Force search_path_buffer to be heap-allocated */ long_dir = g_test_build_filename (G_TEST_BUILT, "path-test-subdir", placeholder, NULL); diff --git a/glib/tests/spawn-singlethread.c b/glib/tests/spawn-singlethread.c index 7711ba8fe..b17b47237 100644 --- a/glib/tests/spawn-singlethread.c +++ b/glib/tests/spawn-singlethread.c @@ -505,11 +505,6 @@ main (int argc, dirname = g_path_get_dirname (argv[0]); echo_prog_path = g_build_filename (dirname, "test-spawn-echo" EXEEXT, NULL); - if (!g_file_test (echo_prog_path, G_FILE_TEST_EXISTS)) - { - g_free (echo_prog_path); - echo_prog_path = g_build_filename (dirname, "lt-test-spawn-echo" EXEEXT, NULL); - } echo_script_path = g_build_filename (dirname, "echo-script" SCRIPT_EXT, NULL); if (!g_file_test (echo_script_path, G_FILE_TEST_EXISTS)) { diff --git a/glib/tests/test-spawn-sleep.c b/glib/tests/test-spawn-sleep.c new file mode 100644 index 000000000..34dfd5bd9 --- /dev/null +++ b/glib/tests/test-spawn-sleep.c @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 Red Hat, Inc. + * + * This work is provided "as is"; redistribution and modification + * in whole or in part, in any medium, physical or electronic is + * permitted without restriction. + * + * This work is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * In no event shall the authors or contributors be liable for any + * direct, indirect, incidental, special, exemplary, or consequential + * damages (including, but not limited to, procurement of substitute + * goods or services; loss of use, data, or profits; or business + * interruption) however caused and on any theory of liability, whether + * in contract, strict liability, or tort (including negligence or + * otherwise) arising in any way out of the use of this software, even + * if advised of the possibility of such damage. + */ +#include "config.h" + +#include +#include "glib.h" + +int +main (int argc, + char *argv[]) +{ + g_usleep (atoi (argv[1]) * G_USEC_PER_SEC); + return 0; +}