projects
/
mono.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[sgen] Fix race conditions in worker thread start/stop.
[mono.git]
/
mono
/
metadata
/
attach.c
diff --git
a/mono/metadata/attach.c
b/mono/metadata/attach.c
index 69489fc8ecba2c6e0e4f9d4bfea6b62eba5d79f1..b14709aeabc85b89e7e42f4e39c9b2c6a0d01a89 100644
(file)
--- a/
mono/metadata/attach.c
+++ b/
mono/metadata/attach.c
@@
-4,9
+4,17
@@
* Author:
* Zoltan Varga (vargaz@gmail.com)
*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
@@
-22,7
+30,7
@@
#include <errno.h>
#include <netdb.h>
#include <unistd.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/assembly.h>
#include <mono/metadata/metadata.h>
@@
-32,20
+40,16
@@
#include <mono/metadata/gc-internal.h>
#include "attach.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>.
/*
* 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
* 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
*
* 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 transport_start_receive (void);
-static void maybe_start (gpointer user_data);
-
/*
* Functions to decode protocol 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)
{
void
mono_attach_parse_options (char *options)
{
- config.enabled = TRUE;
-
if (!options)
return;
if (!strcmp (options, "disable"))
if (!options)
return;
if (!strcmp (options, "disable"))
@@
-194,15
+194,15
@@
mono_attach_init (void)
{
InitializeCriticalSection (&agent_mutex);
{
InitializeCriticalSection (&agent_mutex);
-
mono_gc_add_finalizer_thread_callback (maybe_start, NULL)
;
+
config.enabled = TRUE
;
}
}
-/*
+/*
*
* mono_attach_start:
*
* mono_attach_start:
*
- * Start the attach mechanism if needed.
+ * Start the attach mechanism if needed. This is called from a signal handler so it must be signal safe.
+ *
* Returns: whenever it was started.
* Returns: whenever it was started.
- * This is called from a signal handler so it must be signal safe.
*/
gboolean
mono_attach_start (void)
*/
gboolean
mono_attach_start (void)
@@
-238,15
+238,14
@@
mono_attach_start (void)
* do the actual startup.
*/
needs_to_start = 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 */
mono_gc_finalize_notify ();
return TRUE;
}
/* Called by the finalizer thread when it is woken up */
-
static
void
-m
aybe_start (gpointer user_data
)
+void
+m
ono_attach_maybe_start (void
)
{
if (!needs_to_start)
return;
{
if (!needs_to_start)
return;
@@
-367,7
+366,12
@@
ipc_connect (void)
*/
/* FIXME: Use TMP ? */
pw = NULL;
*/
/* FIXME: Use TMP ? */
pw = NULL;
+#ifdef HAVE_GETPWUID_R
res = getpwuid_r (getuid (), &pwbuf, buf, sizeof (buf), &pw);
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;
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. */
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)
strcpy (name.sun_path, filename);
size = (offsetof (struct sockaddr_un, sun_path)
@@
-476,7
+480,7
@@
transport_start_receive (void)
if (!listen_fd)
return;
if (!listen_fd)
return;
- receiver_thread_handle =
CreateT
hread (NULL, 0, receiver_thread, NULL, 0, &tid);
+ receiver_thread_handle =
mono_create_t
hread (NULL, 0, receiver_thread, NULL, 0, &tid);
g_assert (receiver_thread_handle);
}
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 */
/* 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;
while (TRUE) {
char *cmd, *agent_name, *agent_args;
@@
-570,7
+574,7
@@
receiver_thread (void *arg)
return 0;
}
return 0;
}
-#else /*
PLATFORM_WIN32
*/
+#else /*
DISABLE_ATTACH
*/
void
mono_attach_parse_options (char *options)
void
mono_attach_parse_options (char *options)
@@
-589,28
+593,8
@@
mono_attach_start (void)
}
void
}
void
-mono_attach_cleanup (void)
-{
-}
-
-#endif /* PLATFORM_WIN32 */
-
-#else /* DISABLE_ATTACH */
-
-void
-mono_attach_parse_options (char *options)
-{
-}
-
-void
-mono_attach_init (void)
-{
-}
-
-gboolean
-mono_attach_start (void)
+mono_attach_maybe_start (void)
{
{
- return FALSE;
}
void
}
void