"Fossies" - the Fresh Open Source Software archive

Member "gpg4win-2.1.0/patches/glib-2.12.12/02-gspawn-w32.patch" of archive gpg4win-2.1.0.tar.gz:


#! /bin/sh
patch -p1 -f $* < $0
exit $?

Fix calling of the spawn helper for W32.

2006-01-12  Werner Koch  <wk@g10code.com>

	* glib/gspawn-win32.c (do_spawn_with_pipes): First try to load the
	helper from the module's directory.


diff -upr glib-2.9.2-wk1/glib/gspawn-win32.c glib/glib/gspawn-win32.c
--- glib-2.9.2-wk1/glib/gspawn-win32.c	2005-09-07 12:10:49.000000000 +0200
+++ glib/glib/gspawn-win32.c	2006-01-13 09:14:48.000000000 +0100
@@ -632,6 +632,7 @@ do_spawn_with_pipes (gint               
   GError *conv_error = NULL;
   gint conv_error_index;
   gchar *helper_process;
+  gchar *helper_process_buf = NULL;
   CONSOLE_CURSOR_INFO cursor_info;
   
   SETUP_DEBUG();
@@ -678,6 +679,23 @@ do_spawn_with_pipes (gint               
     helper_process = HELPER_PROCESS "-console.exe";
   else
     helper_process = HELPER_PROCESS ".exe";
+
+  /* We better check whether the helper process is available in the
+     same directory as this library.  Only if this is not the case we
+     try it without a path and hope that it can be found n PATH. */
+  helper_process_buf = g_malloc (MAX_PATH + 50 + strlen (helper_process));
+  if ( GetModuleFileNameA (0, helper_process_buf, MAX_PATH + 50) )
+    {
+      char *p = strrchr (helper_process_buf, '\\');
+      if (!p)
+        p = helper_process_buf;
+      else
+        p++;
+      strcpy (p, helper_process);
+      if (!g_access (helper_process_buf, X_OK))
+        helper_process = helper_process_buf; /* Yes, use that one. */
+    }
+
   new_argv[0] = helper_process;
   _g_sprintf (args[ARG_CHILD_ERR_REPORT], "%d", child_err_report_pipe[1]);
   new_argv[ARG_CHILD_ERR_REPORT] = args[ARG_CHILD_ERR_REPORT];
@@ -944,6 +962,7 @@ do_spawn_with_pipes (gint               
   if (rc != -1)
     CloseHandle ((HANDLE) rc);
   
+  g_free (helper_process_buf);
   return TRUE;
 
  cleanup_and_fail:
@@ -965,6 +984,7 @@ do_spawn_with_pipes (gint               
     close (stderr_pipe[0]);
   if (stderr_pipe[1] != -1)
     close (stderr_pipe[1]);
+  g_free (helper_process_buf);
 
   return FALSE;
 }