Make nested type loading lazier.
[mono.git] / mono / metadata / attach.c
index 88f72ac36826644028c1c9b42189d551e566530a..b14709aeabc85b89e7e42f4e39c9b2c6a0d01a89 100644 (file)
@@ -4,9 +4,17 @@
  * Author:
  *   Zoltan Varga (vargaz@gmail.com)
  *
- * (C) 2007-2008 Novell, Inc.
+ * Copyright 2007-2009 Novell, Inc (http://www.novell.com)
  */
 
+#include <config.h>
+#include <glib.h>
+
+#ifdef HOST_WIN32
+#define DISABLE_ATTACH
+#endif
+#ifndef DISABLE_ATTACH
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -22,7 +30,7 @@
 #include <errno.h>
 #include <netdb.h>
 #include <unistd.h>
-#include <glib.h>
+
 
 #include <mono/metadata/assembly.h>
 #include <mono/metadata/metadata.h>
 #include <mono/metadata/gc-internal.h>
 #include "attach.h"
 
-#ifndef DISABLE_ATTACH
-
-#ifndef PLATFORM_WIN32
-
 /*
  * This module enables other processes to attach to a running mono process and
  * load agent assemblies. 
  * Communication is done through a UNIX Domain Socket located at
  * /tmp/mono-<USER>/.mono-<PID>.
- * We a simplified version of the .net remoting protocol.
+ * We use a simplified version of the .net remoting protocol.
  * To increase security, and to avoid spinning up a listener thread on startup,
  * we follow the java implementation, and only start up the attach mechanism
- * when we receive a QUIT signal and there is a file named '.attach_pid<PID>' in
- * /tmp.
+ * when we receive a QUIT signal and there is a file named 
+ * '.mono_attach_pid<PID>' in /tmp.
  *
  * SECURITY:
  * - This module allows loading of arbitrary code into a running mono runtime, so
@@ -104,8 +108,6 @@ static guint32 WINAPI receiver_thread (void *arg);
 
 static void transport_start_receive (void);
 
-static void maybe_start (gpointer user_data);
-
 /*
  * Functions to decode protocol data
  */
@@ -181,8 +183,6 @@ decode_string_value (guint8 *buf, guint8 **endbuf, guint8 *limit)
 void
 mono_attach_parse_options (char *options)
 {
-       config.enabled = TRUE;
-
        if (!options)
                return;
        if (!strcmp (options, "disable"))
@@ -194,7 +194,7 @@ mono_attach_init (void)
 {
        InitializeCriticalSection (&agent_mutex);
 
-       mono_gc_add_finalizer_thread_callback (maybe_start, NULL);
+       config.enabled = TRUE;
 }
 
 /**
@@ -238,15 +238,14 @@ mono_attach_start (void)
         * do the actual startup.
         */
        needs_to_start = TRUE;
-       // FIXME: This is not actually signal-safe
        mono_gc_finalize_notify ();
 
        return TRUE;
 }
 
 /* Called by the finalizer thread when it is woken up */
-static void
-maybe_start (gpointer user_data)
+void
+mono_attach_maybe_start (void)
 {
        if (!needs_to_start)
                return;
@@ -367,7 +366,12 @@ ipc_connect (void)
         */
        /* FIXME: Use TMP ? */
        pw = NULL;
+#ifdef HAVE_GETPWUID_R
        res = getpwuid_r (getuid (), &pwbuf, buf, sizeof (buf), &pw);
+#else
+       pw = getpwuid(getuid ());
+       res = pw != NULL ? 0 : 1;
+#endif
        if (res != 0) {
                fprintf (stderr, "attach: getpwuid_r () failed.\n");
                return;
@@ -405,7 +409,7 @@ ipc_connect (void)
        unlink (filename);
 
        /* Bind a name to the socket.   */
-       name.sun_family = AF_FILE;
+       name.sun_family = AF_UNIX;
        strcpy (name.sun_path, filename);
 
        size = (offsetof (struct sockaddr_un, sun_path)
@@ -476,7 +480,7 @@ transport_start_receive (void)
        if (!listen_fd)
                return;
 
-       receiver_thread_handle = CreateThread (NULL, 0, receiver_thread, NULL, 0, &tid);
+       receiver_thread_handle = mono_create_thread (NULL, 0, receiver_thread, NULL, 0, &tid);
        g_assert (receiver_thread_handle);
 }
 
@@ -502,7 +506,7 @@ receiver_thread (void *arg)
                /* Ask the runtime to not abort this thread */
                //mono_thread_current ()->flags |= MONO_THREAD_FLAG_DONT_MANAGE;
                /* Ask the runtime to not wait for this thread */
-               mono_thread_current ()->state |= ThreadState_Background;
+               mono_thread_internal_current ()->state |= ThreadState_Background;
 
                while (TRUE) {
                        char *cmd, *agent_name, *agent_args;
@@ -570,7 +574,7 @@ receiver_thread (void *arg)
        return 0;
 }
 
-#else /* PLATFORM_WIN32 */
+#else /* DISABLE_ATTACH */
 
 void
 mono_attach_parse_options (char *options)
@@ -589,30 +593,10 @@ mono_attach_start (void)
 }
 
 void
-mono_attach_cleanup (void)
-{
-}
-
-#endif /* PLATFORM_WIN32 */
-
-#else /* DISABLE_ATTACH */
-
-void
-mono_attach_parse_options (char *options)
+mono_attach_maybe_start (void)
 {
 }
 
-void
-mono_attach_init (void)
-{
-}
-
-gboolean
-mono_attach_start (void)
-{
-       return FALSE;
-}
-
 void
 mono_attach_cleanup (void)
 {