glib/glib/gspawn-win32-helper.c
Bruno Haible 34462896a0 When the sublangid is SUBLANG_DEFAULT, return the locale of the language's
2001-09-24  Bruno Haible  <haible@clisp.cons.org>

	* glib/gwin32.c (g_win32_getlocale): When the sublangid is
	SUBLANG_DEFAULT, return the locale of the language's main country,
	not a country-neutral locale. E.g. "en_US" instead of "en". Add
	handling of LANG_SORBIAN. Fix typo for SUBLANG_CHINESE_SIMPLIFIED
	(China == CN, CH == Switzerland). Ignore empty environment
	variable values.

2001-09-28  Tor Lillqvist  <tml@iki.fi>

	* glib/makefile.{mingw,msc}.in: Add localcharset.o. Just copy the
	source file from libcharset and compile in this directory.

	* glib/giochannel.c: Mark rest of g_set_error strings for
	translation, too.

	* glib/giowin32.c: Add some debugging output functions, call them
	when debugging.
	(create_events, g_io_win32_msg_write): Free message fetched with
	g_win32_error_message ().
	(g_io_win32_check): Indentation fixes.
	(g_io_win32_fd_read,g_io_win32_sock_read): Don't always return
	G_IO_STATUS_NORMAL. Do return G_IO_STATUS_EOF if we got 0 bytes,
	like on Unix. This helps making the test programs run
	successfully.

	* glib/gmain.c (g_poll): Return the code ifdeffed out with
	TEST_WITHOUT_THIS. Can't remember why it was ifdeffed out. Things
	seem to work as previously with the code in place. Especially
	spawn-test didn't work with the code ifdeffed out (Bug#61067).

	* glib/grand.c (g_rand_new): Don't try to use /dev/urandom unless
	on Unix.

	* glib/gspawn-win32-helper.c (WinMain): Remove Sleep(10000)
	accidentally left in.

gthread:

2001-09-28  Tor Lillqvist  <tml@iki.fi>

	* gthread-win32.c: Use an extra level of indirection for GMutex.
	It is now a pointer either to a pointer to a CRITICAL_SECTION
	struct, or to a mutex HANDLE. This is needed in case the user
	defines G_ERRORCHECK_MUTEXES. G_MUTEX_SIZE must correctly reflect
	the size of *GMutex, but this used to vary depending on whether we
	at run-time chose to use CRITICAL_SECTIONs or mutexes.
	(g_mutex_free_win32_cs_impl, g_cond_free_win32_impl): Call
	DeleteCriticalSection() when done with it.

	* gthread-impl.c (g_thread_init_with_errorcheck_mutexes): Call
	g_thread_impl_init() before accessing
	g_thread_functions_for_glib_use_default, as the
	g_thread_impl_init() function might modify it.

po:

2001-09-28  Tor Lillqvist  <tml@iki.fi>

	* POTFILES.in: Add iochannel.c and giowin32.c.

	* sv.po: Remove a bogus fuzziness indicator.
2001-09-27 22:07:00 +00:00

231 lines
5.6 KiB
C

/* 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.
*/
#undef G_LOG_DOMAIN
#include "glib.h"
#define GSPAWN_HELPER
#include "gspawn-win32.c" /* For shared definitions */
static GString *debugstring;
static void
write_err_and_exit (gint fd,
gint msg)
{
gint en = errno;
if (debug)
{
debugstring = g_string_new ("");
g_string_append (debugstring,
g_strdup_printf ("writing error code %d and errno %d",
msg, en));
MessageBox (NULL, debugstring->str, "gspawn-win32-helper", 0);
}
write (fd, &msg, sizeof(msg));
write (fd, &en, sizeof(en));
_exit (1);
}
#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;
gint zero = 0;
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);
}
write (child_err_report_fd, &zero, sizeof (zero));
write (child_err_report_fd, &zero, sizeof (zero));
return 0;
}