From f4cb22c78d573d53dba62b7f6743cbe0a1d1e135 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 10 Mar 2004 22:59:14 +0000 Subject: [PATCH] glib/gspawn-win32.c Implement G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce 2004-03-10 Tor Lillqvist * glib/gspawn-win32.c * glib/gspawn-win32-helper.c: Implement G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler) * tests/spawn-test.c * tests/spawn-test-win32-gui.c: Test it. --- ChangeLog | 9 +++++++++ ChangeLog.pre-2-10 | 9 +++++++++ ChangeLog.pre-2-12 | 9 +++++++++ ChangeLog.pre-2-4 | 9 +++++++++ ChangeLog.pre-2-6 | 9 +++++++++ ChangeLog.pre-2-8 | 9 +++++++++ glib/gspawn-win32-helper.c | 11 ++++++++--- glib/gspawn-win32.c | 14 ++++++++++---- tests/spawn-test-win32-gui.c | 13 ++++++++----- tests/spawn-test.c | 30 ++++++++++++++++++++++++------ 10 files changed, 104 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d8f58a05..9c3e305f8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-03-10 Tor Lillqvist + + * glib/gspawn-win32.c + * glib/gspawn-win32-helper.c: Implement + G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler) + + * tests/spawn-test.c + * tests/spawn-test-win32-gui.c: Test it. + Tue Mar 9 09:16:11 2004 Owen Taylor * === Released 2.3.6 === diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 9d8f58a05..9c3e305f8 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +2004-03-10 Tor Lillqvist + + * glib/gspawn-win32.c + * glib/gspawn-win32-helper.c: Implement + G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler) + + * tests/spawn-test.c + * tests/spawn-test-win32-gui.c: Test it. + Tue Mar 9 09:16:11 2004 Owen Taylor * === Released 2.3.6 === diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 9d8f58a05..9c3e305f8 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,12 @@ +2004-03-10 Tor Lillqvist + + * glib/gspawn-win32.c + * glib/gspawn-win32-helper.c: Implement + G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler) + + * tests/spawn-test.c + * tests/spawn-test-win32-gui.c: Test it. + Tue Mar 9 09:16:11 2004 Owen Taylor * === Released 2.3.6 === diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 9d8f58a05..9c3e305f8 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,12 @@ +2004-03-10 Tor Lillqvist + + * glib/gspawn-win32.c + * glib/gspawn-win32-helper.c: Implement + G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler) + + * tests/spawn-test.c + * tests/spawn-test-win32-gui.c: Test it. + Tue Mar 9 09:16:11 2004 Owen Taylor * === Released 2.3.6 === diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 9d8f58a05..9c3e305f8 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,12 @@ +2004-03-10 Tor Lillqvist + + * glib/gspawn-win32.c + * glib/gspawn-win32-helper.c: Implement + G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler) + + * tests/spawn-test.c + * tests/spawn-test-win32-gui.c: Test it. + Tue Mar 9 09:16:11 2004 Owen Taylor * === Released 2.3.6 === diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 9d8f58a05..9c3e305f8 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +2004-03-10 Tor Lillqvist + + * glib/gspawn-win32.c + * glib/gspawn-win32-helper.c: Implement + G_SPAWN_FILE_AND_ARGV_ZERO. (#136792, Bruce Hochstetler) + + * tests/spawn-test.c + * tests/spawn-test-win32-gui.c: Test it. + Tue Mar 9 09:16:11 2004 Owen Taylor * === Released 2.3.6 === diff --git a/glib/gspawn-win32-helper.c b/glib/gspawn-win32-helper.c index 0679031d6..5a2c9106b 100644 --- a/glib/gspawn-win32-helper.c +++ b/glib/gspawn-win32-helper.c @@ -76,6 +76,7 @@ WinMain (struct HINSTANCE__ *hInstance, int handle; int no_error = CHILD_NO_ERROR; int zero = 0; + gint file_and_argv_zero = 0; gchar **new_argv; SETUP_DEBUG(); @@ -105,6 +106,10 @@ WinMain (struct HINSTANCE__ *hInstance, */ child_err_report_fd = atoi (__argv[ARG_CHILD_ERR_REPORT]); + /* Hack to implement G_SPAWN_FILE_AND_ARGV_ZERO */ + if (__argv[ARG_CHILD_ERR_REPORT][strlen (__argv[ARG_CHILD_ERR_REPORT]) - 1] == '#') + file_and_argv_zero = 1; + /* argv[ARG_STDIN..ARG_STDERR] are the file descriptors that should * be dup2'd to stdin, stdout and stderr, '-' if the corresponding * std* should be let alone, and 'z' if it should be connected to @@ -220,7 +225,7 @@ WinMain (struct HINSTANCE__ *hInstance, __argv[ARG_PROGRAM], (mode == P_WAIT ? "P_WAIT" : "P_NOWAIT"))); - i = ARG_PROGRAM+1; + i = ARG_PROGRAM + 1 + file_and_argv_zero; while (new_argv[i]) { g_string_append (debugstring, new_argv[i++]); @@ -231,9 +236,9 @@ WinMain (struct HINSTANCE__ *hInstance, } if (new_argv[ARG_USE_PATH][0] == 'y') - handle = spawnvp (mode, __argv[ARG_PROGRAM], new_argv+ARG_PROGRAM); + handle = spawnvp (mode, __argv[ARG_PROGRAM], new_argv + ARG_PROGRAM + file_and_argv_zero); else - handle = spawnv (mode, __argv[ARG_PROGRAM], new_argv+ARG_PROGRAM); + handle = spawnv (mode, __argv[ARG_PROGRAM], new_argv + ARG_PROGRAM + file_and_argv_zero); if (debug) { diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c index 5ca783aef..3c2a944c4 100644 --- a/glib/gspawn-win32.c +++ b/glib/gspawn-win32.c @@ -39,8 +39,6 @@ * The structure of the source code in this file is a mess, I know. */ -/* FIXME: Actually implement G_SPAWN_FILE_AND_ARGV_ZERO */ - /* Define this to get some logging all the time */ /* #define G_SPAWN_WIN32_DEBUG */ @@ -670,9 +668,9 @@ do_spawn (gboolean dont_wait, g_print ("doing without gspawn-win32-helper\n"); if (search_path) - rc = spawnvp (mode, argv[0], protected_argv); + rc = spawnvp (mode, argv[0], file_and_argv_zero ? protected_argv + 1 : protected_argv); else - rc = spawnv (mode, argv[0], protected_argv); + rc = spawnv (mode, argv[0], file_and_argv_zero ? protected_argv + 1 : protected_argv); for (i = 0; i < argc; i++) g_free (protected_argv[i]); @@ -695,6 +693,14 @@ do_spawn (gboolean dont_wait, _g_sprintf (args[ARG_CHILD_ERR_REPORT], "%d", child_err_report_fd); new_argv[ARG_CHILD_ERR_REPORT] = args[ARG_CHILD_ERR_REPORT]; + if (file_and_argv_zero) + { + /* Overload ARG_CHILD_ERR_REPORT to also encode the + * G_SPAWN_FILE_AND_ARGV_ZERO functionality. + */ + strcat (args[ARG_CHILD_ERR_REPORT], "#"); + } + if (stdin_fd >= 0) { _g_sprintf (args[ARG_STDIN], "%d", stdin_fd); diff --git a/tests/spawn-test-win32-gui.c b/tests/spawn-test-win32-gui.c index 8622d4411..aade3e73a 100644 --- a/tests/spawn-test-win32-gui.c +++ b/tests/spawn-test-win32-gui.c @@ -10,7 +10,14 @@ WinMain (struct HINSTANCE__ *hInstance, char *lpszCmdLine, int nCmdShow) { - if (__argc <= 2) + 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) { MessageBox (NULL, "spawn-test-win32-gui: Will write to stdout", lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL); @@ -29,7 +36,6 @@ WinMain (struct HINSTANCE__ *hInstance, int infd = atoi (__argv[2]); int outfd = atoi (__argv[3]); int k, n; - char buf[100]; if (infd < 0 || outfd < 0) { @@ -87,9 +93,6 @@ WinMain (struct HINSTANCE__ *hInstance, } } - MessageBox (NULL, "spawn-test-win32-gui: Sleeping a bit.", - lpszCmdLine, MB_ICONINFORMATION|MB_SYSTEMMODAL); - Sleep (2000); MessageBox (NULL, "spawn-test-win32-gui: Done, exiting.", diff --git a/tests/spawn-test.c b/tests/spawn-test.c index cfd4e0e05..efe9afea6 100644 --- a/tests/spawn-test.c +++ b/tests/spawn-test.c @@ -131,8 +131,9 @@ run_tests (void) erroutput = NULL; } - printf ("Starting spawn-test-win32-gui asynchronously (without wait).\n" - "Click on the OK buttons.\n"); + printf ("Running spawn-test-win32-gui in various ways. Click on the OK buttons.\n"); + + printf ("First asynchronously (without wait).\n"); if (!g_spawn_command_line_async ("'.\\spawn-test-win32-gui.exe' 1", &err)) { @@ -141,8 +142,7 @@ run_tests (void) exit (1); } - printf ("Running spawn-test-win32-gui synchronously,\n" - "collecting its output. Click on the OK buttons.\n"); + printf ("Now synchronously, collecting its output.\n"); if (!g_spawn_command_line_sync ("'.\\spawn-test-win32-gui.exe' 2", &output, &erroutput, NULL, &err)) @@ -174,8 +174,26 @@ run_tests (void) 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"); + printf ("Now with G_SPAWN_FILE_AND_ARGV_ZERO.\n"); + + if (!g_shell_parse_argv ("'.\\spawn-test-win32-gui.exe' this-should-be-argv-zero nop", 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_FILE_AND_ARGV_ZERO, + NULL, NULL, NULL, + &err)) + { + fprintf (stderr, "Error: %s\n", err->message); + g_error_free (err); + exit (1); + } + + printf ("Now talking to it through pipes.\n"); if (pipe (pipedown) < 0 || pipe (pipeup) < 0)