1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
From fd665684cce67fe27c205c63a0dc1a9f4a67cad2 Mon Sep 17 00:00:00 2001
From: Justus Winter <4winter@informatik.uni-hamburg.de>
Date: Thu, 24 Sep 2015 18:23:28 +0200
Subject: [PATCH hurd 09/12] fixup_libports
---
libports/introspection.c | 35 ++++++++++++++++++++---------------
libports/manage-multithread.c | 6 ++++--
libports/manage-one-thread.c | 6 ++++--
libports/ports.h | 1 +
4 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/libports/introspection.c b/libports/introspection.c
index 912c768..07f8624 100644
--- a/libports/introspection.c
+++ b/libports/introspection.c
@@ -71,24 +71,29 @@ service_introspection_requests (void *arg)
return NULL;
}
-/* Start the introspection server before main is called. */
-static void __attribute__ ((constructor))
-init (void)
+/* Start the introspection server if it is not already running. */
+void
+_ports_start_introspection_server (void)
{
+ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+ static int initialized = 0;
error_t err;
-
pthread_t thread;
- pthread_attr_t attr;
-#define STACK_SIZE (64 * 1024)
- pthread_attr_init (&attr);
- pthread_attr_setstacksize (&attr, STACK_SIZE);
-#undef STACK_SIZE
-
- err = pthread_create (&thread, &attr,
- service_introspection_requests, NULL);
- if (err)
- error (1, err, "pthread_create");
- pthread_detach (thread);
+
+ pthread_mutex_lock (&lock);
+ if (! initialized)
+ {
+ err = pthread_create (&thread, NULL,
+ service_introspection_requests, NULL);
+ if (err)
+ error (0, err, "Error starting introspection server");
+ else
+ {
+ pthread_detach (thread);
+ initialized = 1;
+ }
+ }
+ pthread_mutex_unlock (&lock);
}
/* Return the number of hard and weak references of the object
diff --git a/libports/manage-multithread.c b/libports/manage-multithread.c
index 8707d98..d2e7dbe 100644
--- a/libports/manage-multithread.c
+++ b/libports/manage-multithread.c
@@ -214,8 +214,7 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket,
}
ports_port_deref (pi);
- if (__builtin_expect (MACH_PORT_VALID (trace_port), 0)
- && outp->RetCode != MIG_NO_REPLY)
+ if (__builtin_expect (MACH_PORT_VALID (trace_port), 0))
introspection_trace_message (trace_port, outp, trace_id);
}
else
@@ -291,5 +290,8 @@ ports_manage_port_operations_multithread (struct port_bucket *bucket,
master thread from going away. */
global_timeout = 0;
+ /* Make sure the introspection server is running. */
+ _ports_start_introspection_server ();
+
thread_function ((void *) 1);
}
diff --git a/libports/manage-one-thread.c b/libports/manage-one-thread.c
index 55aa378..86d575e 100644
--- a/libports/manage-one-thread.c
+++ b/libports/manage-one-thread.c
@@ -104,8 +104,7 @@ ports_manage_port_operations_one_thread (struct port_bucket *bucket,
}
ports_port_deref (pi);
- if (__builtin_expect (MACH_PORT_VALID (trace_port), 0)
- && outp->RetCode != MIG_NO_REPLY)
+ if (__builtin_expect (MACH_PORT_VALID (trace_port), 0))
introspection_trace_message (trace_port, outp, trace_id);
}
else
@@ -125,6 +124,9 @@ ports_manage_port_operations_one_thread (struct port_bucket *bucket,
zero. */
timeout = 0;
+ /* Make sure the introspection server is running. */
+ _ports_start_introspection_server ();
+
_ports_thread_online (&bucket->threadpool, &thread);
do
err = mach_msg_server_timeout (internal_demuxer, 0, bucket->portset,
diff --git a/libports/ports.h b/libports/ports.h
index a31b894..e61b38c 100644
--- a/libports/ports.h
+++ b/libports/ports.h
@@ -496,5 +496,6 @@ void _ports_complete_deallocate (struct port_info *);
error_t _ports_create_port_internal (struct port_class *, struct port_bucket *,
size_t, void *, int);
error_t _ports_trace_message (mach_port_t, const mach_msg_header_t *);
+void _ports_start_introspection_server (void);
#endif
--
2.1.4
|