#include "config.h"
#include "glib.h"
+#include "glib-private.h"
#include "gprintfint.h"
#include "glibintl.h"
-#include "galias.h"
+#include "gthread.h"
#include <string.h>
#include <stdlib.h>
#include <direct.h>
#include <wchar.h>
+#ifndef GSPAWN_HELPER
#ifdef G_SPAWN_WIN32_DEBUG
static int debug = 1;
#define SETUP_DEBUG() /* empty */
} \
G_STMT_END
#endif
+#endif
enum
{
GetCurrentProcess (), &filehandle,
0, FALSE, DUPLICATE_SAME_ACCESS);
close (fd);
- return _open_osfhandle ((gssize) filehandle, mode | _O_NOINHERIT);
+ return _open_osfhandle ((gintptr) filehandle, mode | _O_NOINHERIT);
}
#ifndef GSPAWN_HELPER
return argc;
}
-GQuark
-g_spawn_error_quark (void)
-{
- return g_quark_from_static_string ("g-exec-error-quark");
-}
+G_DEFINE_QUARK (g-exec-error-quark, g_spawn_error)
+G_DEFINE_QUARK (g-spawn-exit-error-quark, g_spawn_exit_error)
gboolean
g_spawn_async_utf8 (const gchar *working_directory,
{
if (_pipe (p, 4096, _O_BINARY) < 0)
{
+ int errsv = errno;
+
g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
_("Failed to create pipe for communicating with child process (%s)"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
else
*/
static gboolean
read_helper_report (int fd,
- gssize report[2],
+ gintptr report[2],
GError **error)
{
gint bytes = 0;
- while (bytes < sizeof(gssize)*2)
+ while (bytes < sizeof(gintptr)*2)
{
gint chunk;
if (debug)
g_print ("%s:read_helper_report: read %" G_GSIZE_FORMAT "...\n",
__FILE__,
- sizeof(gssize)*2 - bytes);
+ sizeof(gintptr)*2 - bytes);
chunk = read (fd, ((gchar*)report) + bytes,
- sizeof(gssize)*2 - bytes);
+ sizeof(gintptr)*2 - bytes);
if (debug)
g_print ("...got %d bytes\n", chunk);
if (chunk < 0)
{
+ int errsv = errno;
+
/* Some weird shit happened, bail out */
-
g_set_error (error, G_SPAWN_ERROR, G_SPAWN_ERROR_FAILED,
_("Failed to read from child pipe (%s)"),
- g_strerror (errno));
+ g_strerror (errsv));
return FALSE;
}
bytes += chunk;
}
- if (bytes < sizeof(gssize)*2)
+ if (bytes < sizeof(gintptr)*2)
return FALSE;
return TRUE;
}
static void
-set_child_error (gssize report[2],
+set_child_error (gintptr report[2],
const gchar *working_directory,
GError **error)
{
gchar **argv,
char **envp,
char **protected_argv,
- GSpawnChildSetupFunc child_setup,
- gpointer user_data,
GPid *child_handle,
GError **error)
{
const int mode = (exit_status == NULL) ? P_NOWAIT : P_WAIT;
char **new_argv;
- gssize rc = -1;
+ gintptr rc = -1;
int saved_errno;
GError *conv_error = NULL;
gint conv_error_index;
return FALSE;
}
- if (child_setup)
- (* child_setup) (user_data);
-
if (flags & G_SPAWN_SEARCH_PATH)
if (wenvp != NULL)
rc = _wspawnvpe (mode, wargv0, (const wchar_t **) wargv, (const wchar_t **) wenvp);
char **envp,
GSpawnFlags flags,
GSpawnChildSetupFunc child_setup,
- gpointer user_data,
GPid *child_handle,
gint *standard_input,
gint *standard_output,
char args[ARG_COUNT][10];
char **new_argv;
int i;
- gssize rc = -1;
+ gintptr rc = -1;
int saved_errno;
int argc;
int stdin_pipe[2] = { -1, -1 };
int stderr_pipe[2] = { -1, -1 };
int child_err_report_pipe[2] = { -1, -1 };
int helper_sync_pipe[2] = { -1, -1 };
- gssize helper_report[2];
+ gintptr helper_report[2];
static gboolean warned_about_child_setup = FALSE;
GError *conv_error = NULL;
gint conv_error_index;
gchar *helper_process;
CONSOLE_CURSOR_INFO cursor_info;
wchar_t *whelper, **wargv, **wenvp;
- extern gchar *_glib_get_installation_directory (void);
- gchar *glib_top;
+ gchar *glib_dll_directory;
if (child_setup && !warned_about_child_setup)
{
warned_about_child_setup = TRUE;
- g_warning ("passing a child setup function to the g_spawn functions is pointless and dangerous on Win32");
+ g_warning ("passing a child setup function to the g_spawn functions is pointless on Windows and it is ignored");
}
argc = protect_argv (argv, &protected_argv);
gboolean retval =
do_spawn_directly (exit_status, do_return_handle, flags,
argv, envp, protected_argv,
- child_setup, user_data, child_handle,
- error);
+ child_handle, error);
g_strfreev (protected_argv);
return retval;
}
else
helper_process = HELPER_PROCESS ".exe";
- glib_top = _glib_get_installation_directory ();
- if (glib_top != NULL)
+ glib_dll_directory = _glib_get_dll_directory ();
+ if (glib_dll_directory != NULL)
{
- helper_process = g_build_filename (glib_top, "bin", helper_process, NULL);
- g_free (glib_top);
+ helper_process = g_build_filename (glib_dll_directory, helper_process, NULL);
+ g_free (glib_dll_directory);
}
else
helper_process = g_strdup (helper_process);
goto cleanup_and_fail;
}
- if (child_setup)
- (* child_setup) (user_data);
-
whelper = g_utf8_to_utf16 (helper_process, -1, NULL, NULL, NULL);
g_free (helper_process);
envp,
flags,
child_setup,
- user_data,
NULL,
NULL,
standard_output ? &outpipe : NULL,
/* Helper process was involved. Read its report now after the
* grandchild has finished.
*/
- gssize helper_report[2];
+ gintptr helper_report[2];
if (!read_helper_report (reportpipe, helper_report, error))
failed = TRUE;
envp,
flags,
child_setup,
- user_data,
child_handle,
standard_input,
standard_output,
CloseHandle (pid);
}
+gboolean
+g_spawn_check_exit_status (gint exit_status,
+ GError **error)
+{
+ gboolean ret = FALSE;
+
+ if (exit_status != 0)
+ {
+ g_set_error (error, G_SPAWN_EXIT_ERROR, exit_status,
+ _("Child process exited with code %ld"),
+ (long) exit_status);
+ goto out;
+ }
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
#if !defined (_WIN64)
/* Binary compatibility versions that take system codepage pathnames,
#endif /* !_WIN64 */
#endif /* !GSPAWN_HELPER */
-
-#define __G_SPAWN_C__
-#include "galiasdef.c"