* 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>
#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
static void transport_start_receive (void);
-static void maybe_start (gpointer user_data);
-
/*
* Functions to decode protocol data
*/
void
mono_attach_parse_options (char *options)
{
- config.enabled = TRUE;
-
if (!options)
return;
if (!strcmp (options, "disable"))
{
InitializeCriticalSection (&agent_mutex);
- mono_gc_add_finalizer_thread_callback (maybe_start, NULL);
+ config.enabled = TRUE;
}
/**
* 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;
*/
/* 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;
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)
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);
}
/* 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;
return 0;
}
-#else /* PLATFORM_WIN32 */
+#else /* DISABLE_ATTACH */
void
mono_attach_parse_options (char *options)
}
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)
{