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.
2002-11-17 04:52:55 +01:00
|
|
|
#include <windows.h>
|
2004-03-31 04:13:52 +02:00
|
|
|
#include <errno.h>
|
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.
2002-11-17 04:52:55 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2004-03-31 04:13:52 +02:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
/* For read() and write() */
|
|
|
|
#include <unistd.h>
|
|
|
|
/* Cygwin does not prototype __argc and __argv in stdlib.h */
|
|
|
|
extern int __argc;
|
|
|
|
extern char** __argv;
|
|
|
|
#endif
|
|
|
|
|
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.
2002-11-17 04:52:55 +01:00
|
|
|
int _stdcall
|
|
|
|
WinMain (struct HINSTANCE__ *hInstance,
|
|
|
|
struct HINSTANCE__ *hPrevInstance,
|
|
|
|
char *lpszCmdLine,
|
|
|
|
int nCmdShow)
|
|
|
|
{
|
2004-03-10 23:59:14 +01:00
|
|
|
char buf[100];
|
|
|
|
|
|
|
|
if (__argc >= 2 && strcmp (__argv[1], "nop") == 0)
|
|
|
|
{
|
|
|
|
sprintf (buf, "spawn-test-win32-gui: argv[0]=\"%s\"", __argv[0]);
|
|
|
|
MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
|
|
}
|
|
|
|
else if (__argc <= 2)
|
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.
2002-11-17 04:52:55 +01:00
|
|
|
{
|
|
|
|
MessageBox (NULL, "spawn-test-win32-gui: Will write to stdout",
|
|
|
|
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
|
|
|
|
|
|
printf ("This is stdout\n");
|
|
|
|
fflush (stdout);
|
|
|
|
|
|
|
|
MessageBox (NULL, "spawn-test-win32-gui: Will write to stderr",
|
|
|
|
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
|
|
|
|
|
|
fprintf (stderr, "This is stderr\n");
|
|
|
|
fflush (stderr);
|
|
|
|
}
|
|
|
|
else if (__argc == 4 && strcmp (__argv[1], "pipes") == 0)
|
|
|
|
{
|
|
|
|
int infd = atoi (__argv[2]);
|
|
|
|
int outfd = atoi (__argv[3]);
|
|
|
|
int k, n;
|
|
|
|
|
|
|
|
if (infd < 0 || outfd < 0)
|
|
|
|
{
|
|
|
|
MessageBox (NULL, "spawn-test-win32-gui: illegal fds on command line",
|
|
|
|
lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageBox (NULL, "spawn-test-win32-gui: Will write to parent",
|
|
|
|
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
|
|
|
|
|
|
n = strlen ("Hello there");
|
|
|
|
if (write (outfd, &n, sizeof (n)) == -1 ||
|
|
|
|
write (outfd, "Hello there", n) == -1)
|
|
|
|
{
|
|
|
|
sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errno));
|
|
|
|
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageBox (NULL, "spawn-test-win32-gui: Will read from parent",
|
|
|
|
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
|
|
|
|
|
|
if ((k = read (infd, &n, sizeof (n))) != sizeof (n))
|
|
|
|
{
|
|
|
|
sprintf (buf, "spawn-test-win32-gui: Got only %d bytes, wanted %d",
|
|
|
|
k, sizeof (n));
|
|
|
|
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sprintf (buf, "spawn-test-win32-gui: Parent says %d bytes to read", n);
|
|
|
|
MessageBox (NULL, buf, lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
|
|
|
|
|
|
if ((k = read (infd, buf, n)) != n)
|
|
|
|
{
|
|
|
|
if (k == -1)
|
|
|
|
sprintf (buf, "spawn-test-win32-gui: Read: %s", strerror (errno));
|
|
|
|
else
|
|
|
|
sprintf (buf, "spawn-test-win32-gui: Got only %d bytes", k);
|
|
|
|
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageBox (NULL, "spawn-test-win32-gui: Will write more to parent",
|
|
|
|
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
|
|
|
|
|
|
n = strlen ("See ya");
|
|
|
|
if (write (outfd, &n, sizeof (n)) == -1 ||
|
|
|
|
write (outfd, "See ya", n) == -1)
|
|
|
|
{
|
|
|
|
sprintf (buf, "spawn-test-win32-gui: Write: %s", strerror (errno));
|
|
|
|
MessageBox (NULL, buf, lpszCmdLine, MB_ICONERROR|MB_SYSTEMMODAL);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Sleep (2000);
|
|
|
|
|
|
|
|
MessageBox (NULL, "spawn-test-win32-gui: Done, exiting.",
|
|
|
|
lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|