From: Tor Lillqvist Date: Tue, 28 Nov 2000 20:04:08 +0000 (+0000) Subject: Patches by Hans Breuer: X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=55c7329d515ae763674d8ac6e9e30fc6fedad9cf;p=dana%2Fcg-glib.git Patches by Hans Breuer: 2000-11-28 Tor Lillqvist Patches by Hans Breuer: * gspawn-win32.c: Move the code for gspawn-win32-helper to its own file. * makefile.{mingw,msc}.in: Change accordingly. * gspawn-win32-helper.c: New file. * Makefile.am (EXTRA_DIST): Add it. * gmarkup.c (find_current_text_end): Fix assertion not to check an uninitialised variable. * gboxed.c: Include for memset (). --- diff --git a/ChangeLog b/ChangeLog index 265d42d2..5582acd2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2000-11-28 Tor Lillqvist + + Patches by Hans Breuer: + + * gspawn-win32.c: Move the code for gspawn-win32-helper to its own + file. + + * makefile.{mingw,msc}.in: Change accordingly. + + * gspawn-win32-helper.c: New file. + + * Makefile.am (EXTRA_DIST): Add it. + + * gmarkup.c (find_current_text_end): Fix assertion not to check an + uninitialised variable. + 2000-11-28 Sebastian Wilhelmi * gthread.c: Set the thread data before locking the mutex, because diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 265d42d2..5582acd2 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,19 @@ +2000-11-28 Tor Lillqvist + + Patches by Hans Breuer: + + * gspawn-win32.c: Move the code for gspawn-win32-helper to its own + file. + + * makefile.{mingw,msc}.in: Change accordingly. + + * gspawn-win32-helper.c: New file. + + * Makefile.am (EXTRA_DIST): Add it. + + * gmarkup.c (find_current_text_end): Fix assertion not to check an + uninitialised variable. + 2000-11-28 Sebastian Wilhelmi * gthread.c: Set the thread data before locking the mutex, because diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 265d42d2..5582acd2 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,19 @@ +2000-11-28 Tor Lillqvist + + Patches by Hans Breuer: + + * gspawn-win32.c: Move the code for gspawn-win32-helper to its own + file. + + * makefile.{mingw,msc}.in: Change accordingly. + + * gspawn-win32-helper.c: New file. + + * Makefile.am (EXTRA_DIST): Add it. + + * gmarkup.c (find_current_text_end): Fix assertion not to check an + uninitialised variable. + 2000-11-28 Sebastian Wilhelmi * gthread.c: Set the thread data before locking the mutex, because diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 265d42d2..5582acd2 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,19 @@ +2000-11-28 Tor Lillqvist + + Patches by Hans Breuer: + + * gspawn-win32.c: Move the code for gspawn-win32-helper to its own + file. + + * makefile.{mingw,msc}.in: Change accordingly. + + * gspawn-win32-helper.c: New file. + + * Makefile.am (EXTRA_DIST): Add it. + + * gmarkup.c (find_current_text_end): Fix assertion not to check an + uninitialised variable. + 2000-11-28 Sebastian Wilhelmi * gthread.c: Set the thread data before locking the mutex, because diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 265d42d2..5582acd2 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,19 @@ +2000-11-28 Tor Lillqvist + + Patches by Hans Breuer: + + * gspawn-win32.c: Move the code for gspawn-win32-helper to its own + file. + + * makefile.{mingw,msc}.in: Change accordingly. + + * gspawn-win32-helper.c: New file. + + * Makefile.am (EXTRA_DIST): Add it. + + * gmarkup.c (find_current_text_end): Fix assertion not to check an + uninitialised variable. + 2000-11-28 Sebastian Wilhelmi * gthread.c: Set the thread data before locking the mutex, because diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 265d42d2..5582acd2 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,19 @@ +2000-11-28 Tor Lillqvist + + Patches by Hans Breuer: + + * gspawn-win32.c: Move the code for gspawn-win32-helper to its own + file. + + * makefile.{mingw,msc}.in: Change accordingly. + + * gspawn-win32-helper.c: New file. + + * Makefile.am (EXTRA_DIST): Add it. + + * gmarkup.c (find_current_text_end): Fix assertion not to check an + uninitialised variable. + 2000-11-28 Sebastian Wilhelmi * gthread.c: Set the thread data before locking the mutex, because diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 265d42d2..5582acd2 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,19 @@ +2000-11-28 Tor Lillqvist + + Patches by Hans Breuer: + + * gspawn-win32.c: Move the code for gspawn-win32-helper to its own + file. + + * makefile.{mingw,msc}.in: Change accordingly. + + * gspawn-win32-helper.c: New file. + + * Makefile.am (EXTRA_DIST): Add it. + + * gmarkup.c (find_current_text_end): Fix assertion not to check an + uninitialised variable. + 2000-11-28 Sebastian Wilhelmi * gthread.c: Set the thread data before locking the mutex, because diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 265d42d2..5582acd2 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,19 @@ +2000-11-28 Tor Lillqvist + + Patches by Hans Breuer: + + * gspawn-win32.c: Move the code for gspawn-win32-helper to its own + file. + + * makefile.{mingw,msc}.in: Change accordingly. + + * gspawn-win32-helper.c: New file. + + * Makefile.am (EXTRA_DIST): Add it. + + * gmarkup.c (find_current_text_end): Fix assertion not to check an + uninitialised variable. + 2000-11-28 Sebastian Wilhelmi * gthread.c: Set the thread data before locking the mutex, because diff --git a/Makefile.am b/Makefile.am index 172b4489..d54cbc48 100644 --- a/Makefile.am +++ b/Makefile.am @@ -25,6 +25,7 @@ EXTRA_DIST = \ glibconfig.h.win32.in \ gwin32.c \ gspawn-win32.c \ + gspawn-win32-helper.c \ config.h.win32.in \ build-dll \ glib.rc.in \ diff --git a/glib/Makefile.am b/glib/Makefile.am index 172b4489..d54cbc48 100644 --- a/glib/Makefile.am +++ b/glib/Makefile.am @@ -25,6 +25,7 @@ EXTRA_DIST = \ glibconfig.h.win32.in \ gwin32.c \ gspawn-win32.c \ + gspawn-win32-helper.c \ config.h.win32.in \ build-dll \ glib.rc.in \ diff --git a/glib/gmarkup.c b/glib/gmarkup.c index 3df39b9f..46064910 100644 --- a/glib/gmarkup.c +++ b/glib/gmarkup.c @@ -778,7 +778,7 @@ find_current_text_end (GMarkupParseContext *context) const gchar *p; const gchar *next; - g_assert (p != end); + g_assert (context->current_text_len > 0); p = context->current_text; next = g_utf8_find_next_char (p, end); diff --git a/glib/gspawn-win32-helper.c b/glib/gspawn-win32-helper.c new file mode 100644 index 00000000..08aeb448 --- /dev/null +++ b/glib/gspawn-win32-helper.c @@ -0,0 +1,226 @@ +/* gspawn-win32-helper.c - Helper program for process launching on Win32. + * + * Copyright 2000 Red Hat, Inc. + * Copyright 2000 Tor Lillqvist + * + * GLib is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * GLib 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. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GLib; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#define GSPAWN_HELPER +#include "gspawn-win32.c" /* For shared definitions */ + +static void +write_err_and_exit (gint fd, + gint msg) +{ + gint en = errno; + + write (fd, &msg, sizeof(msg)); + write (fd, &en, sizeof(en)); + + _exit (1); +} + +static void +write_no_error (gint fd) +{ + gint msg = CHILD_NO_ERROR; + gint en = 0; + + write (fd, &msg, sizeof(msg)); + write (fd, &en, sizeof(en)); +} + +#ifdef __GNUC__ +# ifndef _stdcall +# define _stdcall __attribute__((stdcall)) +# endif +#endif + +/* We build gspawn-win32-helper.exe as a Windows GUI application + * to avoid any temporarily flashing console windows in case + * the gspawn function is invoked by a GUI program. Thus, no main() + * but a WinMain(). We do, however, still use argc and argv tucked + * away in the global __argc and __argv by the C runtime startup code. + */ + +int _stdcall +WinMain (struct HINSTANCE__ *hInstance, + struct HINSTANCE__ *hPrevInstance, + char *lpszCmdLine, + int nCmdShow) +{ + int child_err_report_fd; + int i; + int fd; + int mode; + GString *debugstring; + + SETUP_DEBUG(); + + if (debug) + { + debugstring = g_string_new (""); + + g_string_append (debugstring, + g_strdup_printf ("g-spawn-win32-helper: " + "argc = %d, argv: ", + __argc)); + for (i = 0; i < __argc; i++) + { + if (i > 0) + g_string_append (debugstring, " "); + g_string_append (debugstring, __argv[i]); + } + + MessageBox (NULL, debugstring->str, "gspawn-win32-helper", 0); + } + + g_assert (__argc >= ARG_COUNT); + + /* argv[ARG_CHILD_ERR_REPORT] is the file descriptor onto which + * write error messages. + */ + child_err_report_fd = atoi (__argv[ARG_CHILD_ERR_REPORT]); + + /* 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 + * the bit bucket NUL:. + */ + if (__argv[ARG_STDIN][0] == '-') + ; /* Nothing */ + else if (__argv[ARG_STDIN][0] == 'z') + { + fd = open ("NUL:", O_RDONLY); + if (fd != 0) + { + dup2 (fd, 0); + close (fd); + } + } + else + { + fd = atoi (__argv[ARG_STDIN]); + if (fd != 0) + { + dup2 (fd, 0); + close (fd); + } + } + + if (__argv[ARG_STDOUT][0] == '-') + ; /* Nothing */ + else if (__argv[ARG_STDOUT][0] == 'z') + { + fd = open ("NUL:", O_WRONLY); + if (fd != 1) + { + dup2 (fd, 1); + close (fd); + } + } + else + { + fd = atoi (__argv[ARG_STDOUT]); + if (fd != 1) + { + dup2 (fd, 1); + close (fd); + } + } + + if (__argv[ARG_STDERR][0] == '-') + ; /* Nothing */ + else if (__argv[ARG_STDERR][0] == 'z') + { + fd = open ("NUL:", O_WRONLY); + if (fd != 2) + { + dup2 (fd, 2); + close (fd); + } + } + else + { + fd = atoi (__argv[ARG_STDERR]); + if (fd != 2) + { + dup2 (fd, 2); + close (fd); + } + } + + /* __argv[ARG_WORKING_DIRECTORY] is the directory in which to run the + * process. If "-", don't change directory. + */ + if (__argv[ARG_WORKING_DIRECTORY][0] == '-' && + __argv[ARG_WORKING_DIRECTORY][1] == 0) + ; /* Nothing */ + else if (chdir (__argv[ARG_WORKING_DIRECTORY]) < 0) + write_err_and_exit (child_err_report_fd, + CHILD_CHDIR_FAILED); + + /* __argv[ARG_CLOSE_DESCRIPTORS] is "y" if file descriptors from 3 + * upwards should be closed + */ + + if (__argv[ARG_CLOSE_DESCRIPTORS][0] == 'y') + for (i = 3; i < 1000; i++) /* FIXME real limit? */ + if (i != child_err_report_fd) + close (i); + + /* __argv[ARG_WAIT] is "w" to wait for the program to exit */ + + if (__argv[ARG_WAIT][0] == 'w') + mode = P_WAIT; + else + mode = P_NOWAIT; + + /* __argv[ARG_USE_PATH] is "y" to use PATH, otherwise not */ + + /* __argv[ARG_PROGRAM] is program file to run, + * __argv[ARG_PROGRAM+1]... is its __argv. + */ + + if (debug) + { + debugstring = g_string_new (""); + g_string_append (debugstring, + g_strdup_printf ("calling %s on program %s, __argv: ", + (__argv[ARG_USE_PATH][0] == 'y' ? + "spawnvp" : "spawnv"), + __argv[ARG_PROGRAM])); + i = ARG_PROGRAM+1; + while (__argv[i]) + g_string_append (debugstring, __argv[i++]); + MessageBox (NULL, debugstring->str, "gspawn-win32-helper", 0); + } + + if (__argv[ARG_USE_PATH][0] == 'y') + { + if (spawnvp (mode, __argv[ARG_PROGRAM], __argv+ARG_PROGRAM) < 0) + write_err_and_exit (child_err_report_fd, CHILD_SPAWN_FAILED); + } + else + { + if (spawnv (mode, __argv[ARG_PROGRAM], __argv+ARG_PROGRAM) < 0) + write_err_and_exit (child_err_report_fd, CHILD_SPAWN_FAILED); + } + + return 0; +} + diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c index c1bb2222..3033285d 100644 --- a/glib/gspawn-win32.c +++ b/glib/gspawn-win32.c @@ -1,4 +1,4 @@ -/* gspawn.c - Process launching +/* gspawn-win32.c - Process launching on Win32 * * Copyright 2000 Red Hat, Inc. * @@ -986,208 +986,4 @@ make_pipe (gint p[2], return TRUE; } -#else /* GSPAWN_HELPER */ - -static void -write_err_and_exit (gint fd, - gint msg) -{ - gint en = errno; - - write (fd, &msg, sizeof(msg)); - write (fd, &en, sizeof(en)); - - _exit (1); -} - -static void -write_no_error (gint fd) -{ - gint msg = CHILD_NO_ERROR; - gint en = 0; - - write (fd, &msg, sizeof(msg)); - write (fd, &en, sizeof(en)); -} - -#ifdef __GNUC__ -# ifndef _stdcall -# define _stdcall __attribute__((stdcall)) -# endif -#endif - -/* We build gspawn-win32-helper.exe as a Windows GUI application - * to avoid any temporarily flashing console windows in case - * the gspawn function is invoked by a GUI program. Thus, no main() - * but a WinMain(). We do, however, still use argc and argv tucked - * away in the global __argc and __argv by the C runtime startup code. - */ - -int _stdcall -WinMain (struct HINSTANCE__ *hInstance, - struct HINSTANCE__ *hPrevInstance, - char *lpszCmdLine, - int nCmdShow) -{ - int child_err_report_fd; - int i; - int fd; - int mode; - GString *debugstring; - - SETUP_DEBUG(); - - if (debug) - { - debugstring = g_string_new (""); - - g_string_append (debugstring, - g_strdup_printf ("g-spawn-win32-helper: " - "argc = %d, argv: ", - __argc)); - for (i = 0; i < __argc; i++) - { - if (i > 0) - g_string_append (debugstring, " "); - g_string_append (debugstring, __argv[i]); - } - - MessageBox (NULL, debugstring->str, "gspawn-win32-helper", 0); - } - - g_assert (__argc >= ARG_COUNT); - - /* argv[ARG_CHILD_ERR_REPORT] is the file descriptor onto which - * write error messages. - */ - child_err_report_fd = atoi (__argv[ARG_CHILD_ERR_REPORT]); - - /* 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 - * the bit bucket NUL:. - */ - if (__argv[ARG_STDIN][0] == '-') - ; /* Nothing */ - else if (__argv[ARG_STDIN][0] == 'z') - { - fd = open ("NUL:", O_RDONLY); - if (fd != 0) - { - dup2 (fd, 0); - close (fd); - } - } - else - { - fd = atoi (__argv[ARG_STDIN]); - if (fd != 0) - { - dup2 (fd, 0); - close (fd); - } - } - - if (__argv[ARG_STDOUT][0] == '-') - ; /* Nothing */ - else if (__argv[ARG_STDOUT][0] == 'z') - { - fd = open ("NUL:", O_WRONLY); - if (fd != 1) - { - dup2 (fd, 1); - close (fd); - } - } - else - { - fd = atoi (__argv[ARG_STDOUT]); - if (fd != 1) - { - dup2 (fd, 1); - close (fd); - } - } - - if (__argv[ARG_STDERR][0] == '-') - ; /* Nothing */ - else if (__argv[ARG_STDERR][0] == 'z') - { - fd = open ("NUL:", O_WRONLY); - if (fd != 2) - { - dup2 (fd, 2); - close (fd); - } - } - else - { - fd = atoi (__argv[ARG_STDERR]); - if (fd != 2) - { - dup2 (fd, 2); - close (fd); - } - } - - /* __argv[ARG_WORKING_DIRECTORY] is the directory in which to run the - * process. If "-", don't change directory. - */ - if (__argv[ARG_WORKING_DIRECTORY][0] == '-' && - __argv[ARG_WORKING_DIRECTORY][1] == 0) - ; /* Nothing */ - else if (chdir (__argv[ARG_WORKING_DIRECTORY]) < 0) - write_err_and_exit (child_err_report_fd, - CHILD_CHDIR_FAILED); - - /* __argv[ARG_CLOSE_DESCRIPTORS] is "y" if file descriptors from 3 - * upwards should be closed - */ - - if (__argv[ARG_CLOSE_DESCRIPTORS][0] == 'y') - for (i = 3; i < 1000; i++) /* FIXME real limit? */ - if (i != child_err_report_fd) - close (i); - - /* __argv[ARG_WAIT] is "w" to wait for the program to exit */ - - if (__argv[ARG_WAIT][0] == 'w') - mode = P_WAIT; - else - mode = P_NOWAIT; - - /* __argv[ARG_USE_PATH] is "y" to use PATH, otherwise not */ - - /* __argv[ARG_PROGRAM] is program file to run, - * __argv[ARG_PROGRAM+1]... is its __argv. - */ - - if (debug) - { - debugstring = g_string_new (""); - g_string_append (debugstring, - g_strdup_printf ("calling %s on program %s, __argv: ", - (__argv[ARG_USE_PATH][0] == 'y' ? - "spawnvp" : "spawnv"), - __argv[ARG_PROGRAM])); - i = ARG_PROGRAM+1; - while (__argv[i]) - g_string_append (debugstring, __argv[i++]); - MessageBox (NULL, debugstring->str, "gspawn-win32-helper", 0); - } - - if (__argv[ARG_USE_PATH][0] == 'y') - { - if (spawnvp (mode, __argv[ARG_PROGRAM], __argv+ARG_PROGRAM) < 0) - write_err_and_exit (child_err_report_fd, CHILD_SPAWN_FAILED); - } - else - { - if (spawnv (mode, __argv[ARG_PROGRAM], __argv+ARG_PROGRAM) < 0) - write_err_and_exit (child_err_report_fd, CHILD_SPAWN_FAILED); - } - - return 0; -} - -#endif /* GSPAWN_HELPER */ +#endif /* !GSPAWN_HELPER */ diff --git a/glib/makefile.mingw.in b/glib/makefile.mingw.in index e0188b93..d6912283 100644 --- a/glib/makefile.mingw.in +++ b/glib/makefile.mingw.in @@ -97,7 +97,7 @@ makefile.mingw: makefile.mingw.in glib-$(GLIB_VER).dll : $(glib_OBJECTS) glib.def ./build-dll glib $(GLIB_VER) glib.def $(glib_OBJECTS) $(LIBICONV_LIBS) -luser32 -lwsock32 -gspawn-win32-helper.exe : gspawn-win32.c +gspawn-win32-helper.exe : gspawn-win32-helper.c $(CC) $(CFLAGS) -mwindows -DGSPAWN_HELPER -DG_LOG_DOMAIN=\"gspawn-win32-helper\" -o $@ $< -L . -lglib-$(GLIB_VER) ################ subdirectories diff --git a/glib/makefile.msc.in b/glib/makefile.msc.in index f03ccd07..f67422e2 100644 --- a/glib/makefile.msc.in +++ b/glib/makefile.msc.in @@ -95,9 +95,8 @@ makefile.msc: makefile.msc.in glib-$(GLIB_VER).dll : $(glib_OBJECTS) glib.def $(CC) $(CFLAGS) -LD -Feglib-$(GLIB_VER).dll $(glib_OBJECTS) $(LIBICONV_LIBS) user32.lib advapi32.lib wsock32.lib $(LDFLAGS) /def:glib.def -gspawn-win32-helper.exe : gspawn-win32.c glib-$(GLIB_VER).dll - $(CC) $(CFLAGS) -Fe$@ -DGSPAWN_HELPER -DG_LOG_DOMAIN=\"gspawn-win32-helper\" gspawn-win32.c glib-$(GLIB_VER).lib $(LDFLAGS) /subsystem:windows user32.lib - @erase gspawn-win32.obj +gspawn-win32-helper.exe : gspawn-win32-helper.c glib-$(GLIB_VER).dll + $(CC) $(CFLAGS) -Fe$@ -DGSPAWN_HELPER -DG_LOG_DOMAIN=\"gspawn-win32-helper\" gspawn-win32-helper.c glib-$(GLIB_VER).lib $(LDFLAGS) /subsystem:windows user32.lib ################ subdirectories diff --git a/gmarkup.c b/gmarkup.c index 3df39b9f..46064910 100644 --- a/gmarkup.c +++ b/gmarkup.c @@ -778,7 +778,7 @@ find_current_text_end (GMarkupParseContext *context) const gchar *p; const gchar *next; - g_assert (p != end); + g_assert (context->current_text_len > 0); p = context->current_text; next = g_utf8_find_next_char (p, end); diff --git a/gobject/ChangeLog b/gobject/ChangeLog index ae777277..973493e0 100644 --- a/gobject/ChangeLog +++ b/gobject/ChangeLog @@ -1,3 +1,7 @@ +2000-11-28 Tor Lillqvist + + * gboxed.c: Include for memset (). + 2000-11-22 Tor Lillqvist * gobject.def: Update. diff --git a/gobject/gboxed.c b/gobject/gboxed.c index 024440d2..d9d00aff 100644 --- a/gobject/gboxed.c +++ b/gobject/gboxed.c @@ -22,7 +22,7 @@ #include "gvalue.h" #include "gvaluecollector.h" - +#include /* --- typedefs & structures --- */ typedef struct diff --git a/gspawn-win32-helper.c b/gspawn-win32-helper.c new file mode 100644 index 00000000..08aeb448 --- /dev/null +++ b/gspawn-win32-helper.c @@ -0,0 +1,226 @@ +/* gspawn-win32-helper.c - Helper program for process launching on Win32. + * + * Copyright 2000 Red Hat, Inc. + * Copyright 2000 Tor Lillqvist + * + * GLib is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * GLib 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. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GLib; see the file COPYING.LIB. If not, write + * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#define GSPAWN_HELPER +#include "gspawn-win32.c" /* For shared definitions */ + +static void +write_err_and_exit (gint fd, + gint msg) +{ + gint en = errno; + + write (fd, &msg, sizeof(msg)); + write (fd, &en, sizeof(en)); + + _exit (1); +} + +static void +write_no_error (gint fd) +{ + gint msg = CHILD_NO_ERROR; + gint en = 0; + + write (fd, &msg, sizeof(msg)); + write (fd, &en, sizeof(en)); +} + +#ifdef __GNUC__ +# ifndef _stdcall +# define _stdcall __attribute__((stdcall)) +# endif +#endif + +/* We build gspawn-win32-helper.exe as a Windows GUI application + * to avoid any temporarily flashing console windows in case + * the gspawn function is invoked by a GUI program. Thus, no main() + * but a WinMain(). We do, however, still use argc and argv tucked + * away in the global __argc and __argv by the C runtime startup code. + */ + +int _stdcall +WinMain (struct HINSTANCE__ *hInstance, + struct HINSTANCE__ *hPrevInstance, + char *lpszCmdLine, + int nCmdShow) +{ + int child_err_report_fd; + int i; + int fd; + int mode; + GString *debugstring; + + SETUP_DEBUG(); + + if (debug) + { + debugstring = g_string_new (""); + + g_string_append (debugstring, + g_strdup_printf ("g-spawn-win32-helper: " + "argc = %d, argv: ", + __argc)); + for (i = 0; i < __argc; i++) + { + if (i > 0) + g_string_append (debugstring, " "); + g_string_append (debugstring, __argv[i]); + } + + MessageBox (NULL, debugstring->str, "gspawn-win32-helper", 0); + } + + g_assert (__argc >= ARG_COUNT); + + /* argv[ARG_CHILD_ERR_REPORT] is the file descriptor onto which + * write error messages. + */ + child_err_report_fd = atoi (__argv[ARG_CHILD_ERR_REPORT]); + + /* 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 + * the bit bucket NUL:. + */ + if (__argv[ARG_STDIN][0] == '-') + ; /* Nothing */ + else if (__argv[ARG_STDIN][0] == 'z') + { + fd = open ("NUL:", O_RDONLY); + if (fd != 0) + { + dup2 (fd, 0); + close (fd); + } + } + else + { + fd = atoi (__argv[ARG_STDIN]); + if (fd != 0) + { + dup2 (fd, 0); + close (fd); + } + } + + if (__argv[ARG_STDOUT][0] == '-') + ; /* Nothing */ + else if (__argv[ARG_STDOUT][0] == 'z') + { + fd = open ("NUL:", O_WRONLY); + if (fd != 1) + { + dup2 (fd, 1); + close (fd); + } + } + else + { + fd = atoi (__argv[ARG_STDOUT]); + if (fd != 1) + { + dup2 (fd, 1); + close (fd); + } + } + + if (__argv[ARG_STDERR][0] == '-') + ; /* Nothing */ + else if (__argv[ARG_STDERR][0] == 'z') + { + fd = open ("NUL:", O_WRONLY); + if (fd != 2) + { + dup2 (fd, 2); + close (fd); + } + } + else + { + fd = atoi (__argv[ARG_STDERR]); + if (fd != 2) + { + dup2 (fd, 2); + close (fd); + } + } + + /* __argv[ARG_WORKING_DIRECTORY] is the directory in which to run the + * process. If "-", don't change directory. + */ + if (__argv[ARG_WORKING_DIRECTORY][0] == '-' && + __argv[ARG_WORKING_DIRECTORY][1] == 0) + ; /* Nothing */ + else if (chdir (__argv[ARG_WORKING_DIRECTORY]) < 0) + write_err_and_exit (child_err_report_fd, + CHILD_CHDIR_FAILED); + + /* __argv[ARG_CLOSE_DESCRIPTORS] is "y" if file descriptors from 3 + * upwards should be closed + */ + + if (__argv[ARG_CLOSE_DESCRIPTORS][0] == 'y') + for (i = 3; i < 1000; i++) /* FIXME real limit? */ + if (i != child_err_report_fd) + close (i); + + /* __argv[ARG_WAIT] is "w" to wait for the program to exit */ + + if (__argv[ARG_WAIT][0] == 'w') + mode = P_WAIT; + else + mode = P_NOWAIT; + + /* __argv[ARG_USE_PATH] is "y" to use PATH, otherwise not */ + + /* __argv[ARG_PROGRAM] is program file to run, + * __argv[ARG_PROGRAM+1]... is its __argv. + */ + + if (debug) + { + debugstring = g_string_new (""); + g_string_append (debugstring, + g_strdup_printf ("calling %s on program %s, __argv: ", + (__argv[ARG_USE_PATH][0] == 'y' ? + "spawnvp" : "spawnv"), + __argv[ARG_PROGRAM])); + i = ARG_PROGRAM+1; + while (__argv[i]) + g_string_append (debugstring, __argv[i++]); + MessageBox (NULL, debugstring->str, "gspawn-win32-helper", 0); + } + + if (__argv[ARG_USE_PATH][0] == 'y') + { + if (spawnvp (mode, __argv[ARG_PROGRAM], __argv+ARG_PROGRAM) < 0) + write_err_and_exit (child_err_report_fd, CHILD_SPAWN_FAILED); + } + else + { + if (spawnv (mode, __argv[ARG_PROGRAM], __argv+ARG_PROGRAM) < 0) + write_err_and_exit (child_err_report_fd, CHILD_SPAWN_FAILED); + } + + return 0; +} + diff --git a/gspawn-win32.c b/gspawn-win32.c index c1bb2222..3033285d 100644 --- a/gspawn-win32.c +++ b/gspawn-win32.c @@ -1,4 +1,4 @@ -/* gspawn.c - Process launching +/* gspawn-win32.c - Process launching on Win32 * * Copyright 2000 Red Hat, Inc. * @@ -986,208 +986,4 @@ make_pipe (gint p[2], return TRUE; } -#else /* GSPAWN_HELPER */ - -static void -write_err_and_exit (gint fd, - gint msg) -{ - gint en = errno; - - write (fd, &msg, sizeof(msg)); - write (fd, &en, sizeof(en)); - - _exit (1); -} - -static void -write_no_error (gint fd) -{ - gint msg = CHILD_NO_ERROR; - gint en = 0; - - write (fd, &msg, sizeof(msg)); - write (fd, &en, sizeof(en)); -} - -#ifdef __GNUC__ -# ifndef _stdcall -# define _stdcall __attribute__((stdcall)) -# endif -#endif - -/* We build gspawn-win32-helper.exe as a Windows GUI application - * to avoid any temporarily flashing console windows in case - * the gspawn function is invoked by a GUI program. Thus, no main() - * but a WinMain(). We do, however, still use argc and argv tucked - * away in the global __argc and __argv by the C runtime startup code. - */ - -int _stdcall -WinMain (struct HINSTANCE__ *hInstance, - struct HINSTANCE__ *hPrevInstance, - char *lpszCmdLine, - int nCmdShow) -{ - int child_err_report_fd; - int i; - int fd; - int mode; - GString *debugstring; - - SETUP_DEBUG(); - - if (debug) - { - debugstring = g_string_new (""); - - g_string_append (debugstring, - g_strdup_printf ("g-spawn-win32-helper: " - "argc = %d, argv: ", - __argc)); - for (i = 0; i < __argc; i++) - { - if (i > 0) - g_string_append (debugstring, " "); - g_string_append (debugstring, __argv[i]); - } - - MessageBox (NULL, debugstring->str, "gspawn-win32-helper", 0); - } - - g_assert (__argc >= ARG_COUNT); - - /* argv[ARG_CHILD_ERR_REPORT] is the file descriptor onto which - * write error messages. - */ - child_err_report_fd = atoi (__argv[ARG_CHILD_ERR_REPORT]); - - /* 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 - * the bit bucket NUL:. - */ - if (__argv[ARG_STDIN][0] == '-') - ; /* Nothing */ - else if (__argv[ARG_STDIN][0] == 'z') - { - fd = open ("NUL:", O_RDONLY); - if (fd != 0) - { - dup2 (fd, 0); - close (fd); - } - } - else - { - fd = atoi (__argv[ARG_STDIN]); - if (fd != 0) - { - dup2 (fd, 0); - close (fd); - } - } - - if (__argv[ARG_STDOUT][0] == '-') - ; /* Nothing */ - else if (__argv[ARG_STDOUT][0] == 'z') - { - fd = open ("NUL:", O_WRONLY); - if (fd != 1) - { - dup2 (fd, 1); - close (fd); - } - } - else - { - fd = atoi (__argv[ARG_STDOUT]); - if (fd != 1) - { - dup2 (fd, 1); - close (fd); - } - } - - if (__argv[ARG_STDERR][0] == '-') - ; /* Nothing */ - else if (__argv[ARG_STDERR][0] == 'z') - { - fd = open ("NUL:", O_WRONLY); - if (fd != 2) - { - dup2 (fd, 2); - close (fd); - } - } - else - { - fd = atoi (__argv[ARG_STDERR]); - if (fd != 2) - { - dup2 (fd, 2); - close (fd); - } - } - - /* __argv[ARG_WORKING_DIRECTORY] is the directory in which to run the - * process. If "-", don't change directory. - */ - if (__argv[ARG_WORKING_DIRECTORY][0] == '-' && - __argv[ARG_WORKING_DIRECTORY][1] == 0) - ; /* Nothing */ - else if (chdir (__argv[ARG_WORKING_DIRECTORY]) < 0) - write_err_and_exit (child_err_report_fd, - CHILD_CHDIR_FAILED); - - /* __argv[ARG_CLOSE_DESCRIPTORS] is "y" if file descriptors from 3 - * upwards should be closed - */ - - if (__argv[ARG_CLOSE_DESCRIPTORS][0] == 'y') - for (i = 3; i < 1000; i++) /* FIXME real limit? */ - if (i != child_err_report_fd) - close (i); - - /* __argv[ARG_WAIT] is "w" to wait for the program to exit */ - - if (__argv[ARG_WAIT][0] == 'w') - mode = P_WAIT; - else - mode = P_NOWAIT; - - /* __argv[ARG_USE_PATH] is "y" to use PATH, otherwise not */ - - /* __argv[ARG_PROGRAM] is program file to run, - * __argv[ARG_PROGRAM+1]... is its __argv. - */ - - if (debug) - { - debugstring = g_string_new (""); - g_string_append (debugstring, - g_strdup_printf ("calling %s on program %s, __argv: ", - (__argv[ARG_USE_PATH][0] == 'y' ? - "spawnvp" : "spawnv"), - __argv[ARG_PROGRAM])); - i = ARG_PROGRAM+1; - while (__argv[i]) - g_string_append (debugstring, __argv[i++]); - MessageBox (NULL, debugstring->str, "gspawn-win32-helper", 0); - } - - if (__argv[ARG_USE_PATH][0] == 'y') - { - if (spawnvp (mode, __argv[ARG_PROGRAM], __argv+ARG_PROGRAM) < 0) - write_err_and_exit (child_err_report_fd, CHILD_SPAWN_FAILED); - } - else - { - if (spawnv (mode, __argv[ARG_PROGRAM], __argv+ARG_PROGRAM) < 0) - write_err_and_exit (child_err_report_fd, CHILD_SPAWN_FAILED); - } - - return 0; -} - -#endif /* GSPAWN_HELPER */ +#endif /* !GSPAWN_HELPER */ diff --git a/makefile.mingw.in b/makefile.mingw.in index e0188b93..d6912283 100644 --- a/makefile.mingw.in +++ b/makefile.mingw.in @@ -97,7 +97,7 @@ makefile.mingw: makefile.mingw.in glib-$(GLIB_VER).dll : $(glib_OBJECTS) glib.def ./build-dll glib $(GLIB_VER) glib.def $(glib_OBJECTS) $(LIBICONV_LIBS) -luser32 -lwsock32 -gspawn-win32-helper.exe : gspawn-win32.c +gspawn-win32-helper.exe : gspawn-win32-helper.c $(CC) $(CFLAGS) -mwindows -DGSPAWN_HELPER -DG_LOG_DOMAIN=\"gspawn-win32-helper\" -o $@ $< -L . -lglib-$(GLIB_VER) ################ subdirectories diff --git a/makefile.msc.in b/makefile.msc.in index f03ccd07..f67422e2 100644 --- a/makefile.msc.in +++ b/makefile.msc.in @@ -95,9 +95,8 @@ makefile.msc: makefile.msc.in glib-$(GLIB_VER).dll : $(glib_OBJECTS) glib.def $(CC) $(CFLAGS) -LD -Feglib-$(GLIB_VER).dll $(glib_OBJECTS) $(LIBICONV_LIBS) user32.lib advapi32.lib wsock32.lib $(LDFLAGS) /def:glib.def -gspawn-win32-helper.exe : gspawn-win32.c glib-$(GLIB_VER).dll - $(CC) $(CFLAGS) -Fe$@ -DGSPAWN_HELPER -DG_LOG_DOMAIN=\"gspawn-win32-helper\" gspawn-win32.c glib-$(GLIB_VER).lib $(LDFLAGS) /subsystem:windows user32.lib - @erase gspawn-win32.obj +gspawn-win32-helper.exe : gspawn-win32-helper.c glib-$(GLIB_VER).dll + $(CC) $(CFLAGS) -Fe$@ -DGSPAWN_HELPER -DG_LOG_DOMAIN=\"gspawn-win32-helper\" gspawn-win32-helper.c glib-$(GLIB_VER).lib $(LDFLAGS) /subsystem:windows user32.lib ################ subdirectories