2009-03-02 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / metadata / process.c
index 25c4ebd72fa63906434af59983f2e640b5f13db2..cfdce2ca9943919055ba80fd28ef14e461c1e0e0 100644 (file)
@@ -4,8 +4,8 @@
  * Author:
  *     Dick Porter (dick@ximian.com)
  *
- * (C) 2002 Ximian, Inc.
- * Copyright (c) 2002-2006 Novell, Inc.
+ * Copyright 2002 Ximian, Inc.
+ * Copyright 2002-2006 Novell, Inc.
  */
 
 #include <config.h>
@@ -21,6 +21,7 @@
 #include <mono/metadata/cil-coff.h>
 #include <mono/metadata/exception.h>
 #include <mono/utils/strenc.h>
+#include <mono/utils/mono-proclib.h>
 #include <mono/io-layer/io-layer.h>
 /* FIXME: fix this code to not depend so much on the inetrnals */
 #include <mono/metadata/class-internals.h>
@@ -494,32 +495,46 @@ quote_path (const gchar *path)
 static gboolean
 complete_path (const gunichar2 *appname, gchar **completed)
 {
-       gchar *utf8app;
+       gchar *utf8app, *utf8appmemory;
        gchar *found;
 
-       utf8app = g_utf16_to_utf8 (appname, -1, NULL, NULL, NULL);
+       utf8appmemory = utf8app = g_utf16_to_utf8 (appname, -1, NULL, NULL, NULL);
+#ifdef PLATFORM_WIN32 // Should this happen on all platforms? 
+       {
+               // remove the quotes around utf8app.
+               size_t len;
+               len = strlen (utf8app);
+               if (len) {
+                       if (utf8app[len-1] == '\"')
+                               utf8app[len-1] = '\0';
+                       if (utf8app[0] == '\"')
+                               utf8app++;
+               }
+       }
+#endif
+
        if (g_path_is_absolute (utf8app)) {
                *completed = quote_path (utf8app);
-               g_free (utf8app);
+               g_free (utf8appmemory);
                return TRUE;
        }
 
        if (g_file_test (utf8app, G_FILE_TEST_IS_EXECUTABLE) && !g_file_test (utf8app, G_FILE_TEST_IS_DIR)) {
                *completed = quote_path (utf8app);
-               g_free (utf8app);
+               g_free (utf8appmemory);
                return TRUE;
        }
        
        found = g_find_program_in_path (utf8app);
        if (found == NULL) {
                *completed = NULL;
-               g_free (utf8app);
+               g_free (utf8appmemory);
                return FALSE;
        }
 
        *completed = quote_path (found);
        g_free (found);
-       g_free (utf8app);
+       g_free (utf8appmemory);
        return TRUE;
 }
 
@@ -793,6 +808,22 @@ MonoBoolean ves_icall_System_Diagnostics_Process_WaitForExit_internal (MonoObjec
        }
 }
 
+MonoBoolean ves_icall_System_Diagnostics_Process_WaitForInputIdle_internal (MonoObject *this, HANDLE process, gint32 ms)
+{
+       guint32 ret;
+       
+       MONO_ARCH_SAVE_REGS;
+
+       if(ms<0) {
+               /* Wait forever */
+               ret=WaitForInputIdle (process, INFINITE);
+       } else {
+               ret=WaitForInputIdle (process, ms);
+       }
+
+       return (ret) ? FALSE : TRUE;
+}
+
 gint64 ves_icall_System_Diagnostics_Process_ExitTime_internal (HANDLE process)
 {
        gboolean ret;
@@ -985,3 +1016,45 @@ ves_icall_System_Diagnostics_Process_SetPriorityClass (HANDLE process, gint32 pr
        *error = ret == 0 ? GetLastError () : 0;
        return ret;
 }
+
+HANDLE
+ves_icall_System_Diagnostics_Process_ProcessHandle_duplicate (HANDLE process)
+{
+       HANDLE ret;
+
+       MONO_ARCH_SAVE_REGS;
+
+#ifdef DEBUG
+       g_message ("%s: Duplicating process handle %p", __func__, process);
+#endif
+       
+       DuplicateHandle (GetCurrentProcess (), process, GetCurrentProcess (),
+                        &ret, THREAD_ALL_ACCESS, TRUE, 0);
+       
+       return ret;
+}
+
+void
+ves_icall_System_Diagnostics_Process_ProcessHandle_close (HANDLE process)
+{
+       MONO_ARCH_SAVE_REGS;
+
+#ifdef DEBUG
+       g_message ("%s: Closing process handle %p", __func__, process);
+#endif
+
+       CloseHandle (process);
+}
+
+gint64
+ves_icall_System_Diagnostics_Process_GetProcessData (int pid, gint32 data_type, gint32 *error)
+{
+       MonoProcessError perror;
+       guint64 res;
+
+       res = mono_process_get_data_with_error (GINT_TO_POINTER (pid), data_type, &perror);
+       if (error)
+               *error = perror;
+       return res;
+}
+