mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
Ignore the G_SPAWN_DO_NOT_REAP_CHILD flag, can't be meaninfully
2002-11-17 Tor Lillqvist <tml@iki.fi> * glib/gspawn-win32.c (g_spawn_async_with_pipes): Ignore the G_SPAWN_DO_NOT_REAP_CHILD flag, can't be meaninfully implemented on Windows, at least not now. Always pass dont_wait as TRUE to do_spawn_with_pipes(). The semantics of the dont_wait parameter is very different from the semantics of the intermediate_child parameter to fork_exec_with_pipes() in the Unix version. This fixes a serious bug, g_spawn_async() in fact behaved synchronously. (do_spawn_with_pipes, do_spawn): Rename from fork_exec_with_pipes() and do_exec(), those names were from the Unix bersion, and misleading. (close_and_invalidate): Don't try to close invalid fds. * glib/gspawn.c (g_spawn_async_with_pipes): Add warning about Windows behaviour. There is no fork(), so the child_setup() function is in fact called in the parent. * glib/gspawn-win32-helper.c (WinMain): Insert spaces in argv debugging output. * tests/spawn-test-win32-gui.c: New file. Test program to be linked as a GUI application. Behaves differently depending on how invoked (by spawn-test). * tests/spawn-test.c (run_tests): On Win32, run the spawn-test-win32-gui program, too, in several ways, synchronously and asynchronously. * tests/Makefile.am: Corresponding change.
This commit is contained in:
committed by
Tor Lillqvist
parent
78000c3b54
commit
1f04f2cce2
@@ -32,12 +32,21 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
run_tests (void)
|
||||
{
|
||||
GError *err;
|
||||
gchar *output = NULL;
|
||||
#ifdef G_OS_WIN32
|
||||
gchar *erroutput = NULL;
|
||||
int pipedown[2], pipeup[2];
|
||||
gchar **argv = 0;
|
||||
#endif
|
||||
|
||||
printf ("The following errors are supposed to occur:\n");
|
||||
|
||||
@@ -86,8 +95,10 @@ run_tests (void)
|
||||
}
|
||||
#else
|
||||
#ifdef G_OS_WIN32
|
||||
printf ("Running ipconfig synchronously, collecting its output\n");
|
||||
|
||||
if (!g_spawn_command_line_sync ("ipconfig /all",
|
||||
&output, NULL, NULL,
|
||||
&output, &erroutput, NULL,
|
||||
&err))
|
||||
{
|
||||
fprintf (stderr, "Error: %s\n", err->message);
|
||||
@@ -97,6 +108,7 @@ run_tests (void)
|
||||
else
|
||||
{
|
||||
g_assert (output != NULL);
|
||||
g_assert (erroutput != NULL);
|
||||
|
||||
if (strstr (output, "IP Configuration") == 0)
|
||||
{
|
||||
@@ -105,10 +117,145 @@ run_tests (void)
|
||||
|
||||
exit (1);
|
||||
}
|
||||
if (erroutput[0] != '\0')
|
||||
{
|
||||
printf ("error output was '%s', should have been empty\n",
|
||||
erroutput);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_free (output);
|
||||
output = NULL;
|
||||
g_free (erroutput);
|
||||
erroutput = NULL;
|
||||
}
|
||||
|
||||
printf ("Starting spawn-test-win32-gui asynchronously (without wait).\n"
|
||||
"Click on the OK buttons.\n");
|
||||
|
||||
if (!g_spawn_command_line_async ("'.\\spawn-test-win32-gui.exe' 1", &err))
|
||||
{
|
||||
fprintf (stderr, "Error: %s\n", err->message);
|
||||
g_error_free (err);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
printf ("Running spawn-test-win32-gui synchronously,\n"
|
||||
"collecting its output. Click on the OK buttons.\n");
|
||||
if (!g_spawn_command_line_sync ("'.\\spawn-test-win32-gui.exe' 2",
|
||||
&output, &erroutput, NULL,
|
||||
&err))
|
||||
{
|
||||
fprintf (stderr, "Error: %s\n", err->message);
|
||||
g_error_free (err);
|
||||
exit (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert (output != NULL);
|
||||
g_assert (erroutput != NULL);
|
||||
|
||||
if (strcmp (output, "This is stdout\r\n") != 0)
|
||||
{
|
||||
printf ("output was '%s', should have been 'This is stdout'\n",
|
||||
g_strescape (output, NULL));
|
||||
|
||||
exit (1);
|
||||
}
|
||||
if (strcmp (erroutput, "This is stderr\r\n") != 0)
|
||||
{
|
||||
printf ("error output was '%s', should have been 'This is stderr'\n",
|
||||
g_strescape (erroutput, NULL));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_free (output);
|
||||
g_free (erroutput);
|
||||
}
|
||||
|
||||
printf ("Running spawn-test-win32-gui asynchronously again.\n"
|
||||
"This time talking to it through pipes. Click on the OK buttons.\n");
|
||||
|
||||
if (pipe (pipedown) < 0 ||
|
||||
pipe (pipeup) < 0)
|
||||
{
|
||||
fprintf (stderr, "Could not create pipes\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!g_shell_parse_argv (g_strdup_printf ("'.\\spawn-test-win32-gui.exe' pipes %d %d",
|
||||
pipedown[0], pipeup[1]),
|
||||
NULL, &argv,
|
||||
&err))
|
||||
{
|
||||
fprintf (stderr, "Error parsing command line? %s\n", err->message);
|
||||
g_error_free (err);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!g_spawn_async (NULL, argv, NULL,
|
||||
G_SPAWN_LEAVE_DESCRIPTORS_OPEN |
|
||||
G_SPAWN_DO_NOT_REAP_CHILD,
|
||||
NULL, NULL, NULL,
|
||||
&err))
|
||||
{
|
||||
fprintf (stderr, "Error: %s\n", err->message);
|
||||
g_error_free (err);
|
||||
exit (1);
|
||||
}
|
||||
else
|
||||
{
|
||||
int k, n;
|
||||
char buf[100];
|
||||
|
||||
if ((k = read (pipeup[0], &n, sizeof (n))) != sizeof (n))
|
||||
{
|
||||
if (k == -1)
|
||||
fprintf (stderr, "Read error: %s\n", g_strerror (errno));
|
||||
else
|
||||
fprintf (stderr, "Wanted to read %d bytes, got %d\n",
|
||||
sizeof (n), k);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if ((k = read (pipeup[0], buf, n)) != n)
|
||||
{
|
||||
if (k == -1)
|
||||
fprintf (stderr, "Read error: %s\n", g_strerror (errno));
|
||||
else
|
||||
fprintf (stderr, "Wanted to read %d bytes, got %d\n",
|
||||
n, k);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
n = strlen ("Bye then");
|
||||
if (write (pipedown[1], &n, sizeof (n)) == -1 ||
|
||||
write (pipedown[1], "Bye then", n) == -1)
|
||||
{
|
||||
fprintf (stderr, "Write error: %s\n", g_strerror (errno));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if ((k = read (pipeup[0], &n, sizeof (n))) != sizeof (n))
|
||||
{
|
||||
if (k == -1)
|
||||
fprintf (stderr, "Read error: %s\n", g_strerror (errno));
|
||||
else
|
||||
fprintf (stderr, "Wanted to read %d bytes, got %d\n",
|
||||
sizeof (n), k);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if ((k = read (pipeup[0], buf, n)) != n)
|
||||
{
|
||||
if (k == -1)
|
||||
fprintf (stderr, "Read error: %s\n", g_strerror (errno));
|
||||
else
|
||||
fprintf (stderr, "Wanted to read %d bytes, got %d\n",
|
||||
n, k);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user