diff options
author | t3sserakt <t3ss@posteo.de> | 2021-10-15 21:02:03 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-10-15 21:02:03 +0200 |
commit | 513f23e74650db9408267e82ef8bcb8f770d1015 (patch) | |
tree | 312db7072dc444e9d1e6a13000b79482eb14de82 /src/util | |
parent | d190d23831dae1a77075557f2ff6e0c713d747d5 (diff) | |
parent | d64ac269856744b9bab170964e1d6f36896ecc55 (diff) | |
download | gnunet-513f23e74650db9408267e82ef8bcb8f770d1015.tar.gz gnunet-513f23e74650db9408267e82ef8bcb8f770d1015.zip |
Merge branch 'master' into dev/t3ss/tng
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 6 | ||||
-rw-r--r-- | src/util/child_management.c | 66 | ||||
-rw-r--r-- | src/util/common_allocation.c | 40 |
3 files changed, 37 insertions, 75 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index a3a77073e..c3a0feccc 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -145,10 +145,8 @@ libgnunetutil_la_LDFLAGS = \ | |||
145 | $(GN_LIB_LDFLAGS) \ | 145 | $(GN_LIB_LDFLAGS) \ |
146 | -version-info 14:0:0 | 146 | -version-info 14:0:0 |
147 | 147 | ||
148 | if HAVE_TESTING | 148 | GNUNET_ECC = gnunet-ecc |
149 | GNUNET_ECC = gnunet-ecc | 149 | GNUNET_SCRYPT = gnunet-scrypt |
150 | GNUNET_SCRYPT = gnunet-scrypt | ||
151 | endif | ||
152 | 150 | ||
153 | lib_LTLIBRARIES = libgnunetutil.la | 151 | lib_LTLIBRARIES = libgnunetutil.la |
154 | 152 | ||
diff --git a/src/util/child_management.c b/src/util/child_management.c index 3afd682b9..832e05ece 100644 --- a/src/util/child_management.c +++ b/src/util/child_management.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file testing/child_management.c | 22 | * @file util/child_management.c |
23 | * @brief Handling of child processes in GNUnet. | 23 | * @brief Handling of child processes in GNUnet. |
24 | * @author Christian Grothoff (ANASTASIS) | 24 | * @author Christian Grothoff (ANASTASIS) |
25 | * @author Dominik Meister (ANASTASIS) | 25 | * @author Dominik Meister (ANASTASIS) |
@@ -91,15 +91,10 @@ maint_child_death (void *cls) | |||
91 | 91 | ||
92 | (void) cls; | 92 | (void) cls; |
93 | sig_task = NULL; | 93 | sig_task = NULL; |
94 | |||
95 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
96 | "Received SIGCHLD.\n"); | ||
97 | |||
98 | /* drain pipe */ | 94 | /* drain pipe */ |
99 | pr = GNUNET_DISK_pipe_handle (sigpipe, | 95 | pr = GNUNET_DISK_pipe_handle (sigpipe, |
100 | GNUNET_DISK_PIPE_END_READ); | 96 | GNUNET_DISK_PIPE_END_READ); |
101 | GNUNET_assert (! GNUNET_DISK_handle_invalid (pr)); | 97 | GNUNET_assert (! GNUNET_DISK_handle_invalid (pr)); |
102 | |||
103 | (void) GNUNET_DISK_file_read (pr, | 98 | (void) GNUNET_DISK_file_read (pr, |
104 | buf, | 99 | buf, |
105 | sizeof(buf)); | 100 | sizeof(buf)); |
@@ -158,10 +153,11 @@ sighandler_child_death (void) | |||
158 | errno = old_errno; /* restore errno */ | 153 | errno = old_errno; /* restore errno */ |
159 | } | 154 | } |
160 | 155 | ||
161 | 156 | /** | |
162 | // void __attribute__ ((constructor)) | 157 | * Initializing the signal pipe for child handling. |
158 | */ | ||
163 | static void | 159 | static void |
164 | child_management_start () | 160 | child_management_start (void) |
165 | { | 161 | { |
166 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
167 | "Trying to start child management.\n"); | 163 | "Trying to start child management.\n"); |
@@ -170,19 +166,24 @@ child_management_start () | |||
170 | sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE); | 166 | sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE); |
171 | GNUNET_assert (sigpipe != NULL); | 167 | GNUNET_assert (sigpipe != NULL); |
172 | shc_chld = | 168 | shc_chld = |
173 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 169 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, |
170 | &sighandler_child_death); | ||
174 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 171 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
175 | "Child management started.\n"); | 172 | "Child management started.\n"); |
176 | } | 173 | } |
177 | 174 | ||
175 | |||
178 | /** | 176 | /** |
179 | * Clean up. | 177 | * Clean up. |
180 | */ | 178 | */ |
181 | // void __attribute__ ((destructor)) | ||
182 | static void | 179 | static void |
183 | child_management_done () | 180 | child_management_done (void) |
184 | { | 181 | { |
185 | GNUNET_assert (NULL == sig_task); | 182 | if (NULL != sig_task) |
183 | { | ||
184 | GNUNET_SCHEDULER_cancel (sig_task); | ||
185 | sig_task = NULL; | ||
186 | } | ||
186 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 187 | GNUNET_SIGNAL_handler_uninstall (shc_chld); |
187 | shc_chld = NULL; | 188 | shc_chld = NULL; |
188 | GNUNET_DISK_pipe_close (sigpipe); | 189 | GNUNET_DISK_pipe_close (sigpipe); |
@@ -191,6 +192,15 @@ child_management_done () | |||
191 | "Child management stopped.\n"); | 192 | "Child management stopped.\n"); |
192 | } | 193 | } |
193 | 194 | ||
195 | |||
196 | /** | ||
197 | * Adding a child process to be monitored by the child management. | ||
198 | * | ||
199 | * @param proc The child process to be monitored. | ||
200 | * @param cp The callback to be called, when the child process completed. | ||
201 | * @param cb_cls The closure for the callback. | ||
202 | * @return An handle for the the child being monitored. | ||
203 | */ | ||
194 | struct GNUNET_ChildWaitHandle * | 204 | struct GNUNET_ChildWaitHandle * |
195 | GNUNET_wait_child (struct GNUNET_OS_Process *proc, | 205 | GNUNET_wait_child (struct GNUNET_OS_Process *proc, |
196 | GNUNET_ChildCompletedCallback cb, | 206 | GNUNET_ChildCompletedCallback cb, |
@@ -198,9 +208,6 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc, | |||
198 | { | 208 | { |
199 | struct GNUNET_ChildWaitHandle *cwh; | 209 | struct GNUNET_ChildWaitHandle *cwh; |
200 | 210 | ||
201 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
202 | "Adding child!\n"); | ||
203 | |||
204 | child_management_start (); | 211 | child_management_start (); |
205 | cwh = GNUNET_new (struct GNUNET_ChildWaitHandle); | 212 | cwh = GNUNET_new (struct GNUNET_ChildWaitHandle); |
206 | cwh->proc = proc; | 213 | cwh->proc = proc; |
@@ -221,23 +228,20 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc, | |||
221 | return cwh; | 228 | return cwh; |
222 | } | 229 | } |
223 | 230 | ||
231 | |||
232 | /** | ||
233 | * Removing child handle. | ||
234 | * | ||
235 | * @param cwh The handle to be removed. | ||
236 | */ | ||
224 | void | 237 | void |
225 | GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh) | 238 | GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh) |
226 | { | 239 | { |
227 | if ((NULL != cwh_head)) | 240 | GNUNET_CONTAINER_DLL_remove (cwh_head, |
228 | { | 241 | cwh_tail, |
229 | GNUNET_CONTAINER_DLL_remove (cwh_head, | 242 | cwh); |
230 | cwh_tail, | ||
231 | cwh); | ||
232 | } | ||
233 | if (NULL == cwh_head) | ||
234 | { | ||
235 | child_management_done (); | ||
236 | } | ||
237 | if (NULL != sig_task) | ||
238 | { | ||
239 | GNUNET_SCHEDULER_cancel (sig_task); | ||
240 | sig_task = NULL; | ||
241 | } | ||
242 | GNUNET_free (cwh); | 243 | GNUNET_free (cwh); |
244 | if (NULL != cwh_head) | ||
245 | return; | ||
246 | child_management_done (); | ||
243 | } | 247 | } |
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c index 308488131..f48f87167 100644 --- a/src/util/common_allocation.c +++ b/src/util/common_allocation.c | |||
@@ -42,13 +42,6 @@ | |||
42 | #define INT_MAX 0x7FFFFFFF | 42 | #define INT_MAX 0x7FFFFFFF |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #if 0 | ||
46 | #define W32_MEM_LIMIT 200000000 | ||
47 | #endif | ||
48 | |||
49 | #ifdef W32_MEM_LIMIT | ||
50 | static LONG mem_used = 0; | ||
51 | #endif | ||
52 | 45 | ||
53 | /** | 46 | /** |
54 | * Allocate memory. Checks the return value, aborts if no more | 47 | * Allocate memory. Checks the return value, aborts if no more |
@@ -184,11 +177,6 @@ GNUNET_xmemdup_ (const void *buf, | |||
184 | /* As a security precaution, we generally do not allow very large | 177 | /* As a security precaution, we generally do not allow very large |
185 | * allocations here */ | 178 | * allocations here */ |
186 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); | 179 | GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); |
187 | #ifdef W32_MEM_LIMIT | ||
188 | size += sizeof(size_t); | ||
189 | if (mem_used + size > W32_MEM_LIMIT) | ||
190 | return NULL; | ||
191 | #endif | ||
192 | GNUNET_assert_at (size < INT_MAX, filename, linenumber); | 180 | GNUNET_assert_at (size < INT_MAX, filename, linenumber); |
193 | ret = malloc (size); | 181 | ret = malloc (size); |
194 | if (ret == NULL) | 182 | if (ret == NULL) |
@@ -196,11 +184,6 @@ GNUNET_xmemdup_ (const void *buf, | |||
196 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); | 184 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
197 | GNUNET_assert (0); | 185 | GNUNET_assert (0); |
198 | } | 186 | } |
199 | #ifdef W32_MEM_LIMIT | ||
200 | *((size_t *) ret) = size; | ||
201 | ret = &((size_t *) ret)[1]; | ||
202 | mem_used += size; | ||
203 | #endif | ||
204 | GNUNET_memcpy (ret, buf, size); | 187 | GNUNET_memcpy (ret, buf, size); |
205 | return ret; | 188 | return ret; |
206 | } | 189 | } |
@@ -222,23 +205,12 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) | |||
222 | 205 | ||
223 | (void) filename; | 206 | (void) filename; |
224 | (void) linenumber; | 207 | (void) linenumber; |
225 | #ifdef W32_MEM_LIMIT | ||
226 | size += sizeof(size_t); | ||
227 | if (mem_used + size > W32_MEM_LIMIT) | ||
228 | return NULL; | ||
229 | #endif | ||
230 | 208 | ||
231 | result = malloc (size); | 209 | result = malloc (size); |
232 | if (NULL == result) | 210 | if (NULL == result) |
233 | return NULL; | 211 | return NULL; |
234 | memset (result, 0, size); | 212 | memset (result, 0, size); |
235 | 213 | ||
236 | #ifdef W32_MEM_LIMIT | ||
237 | *((size_t *) result) = size; | ||
238 | result = &((size_t *) result)[1]; | ||
239 | mem_used += size; | ||
240 | #endif | ||
241 | |||
242 | return result; | 214 | return result; |
243 | } | 215 | } |
244 | 216 | ||
@@ -260,11 +232,6 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) | |||
260 | (void) filename; | 232 | (void) filename; |
261 | (void) linenumber; | 233 | (void) linenumber; |
262 | 234 | ||
263 | #ifdef W32_MEM_LIMIT | ||
264 | n += sizeof(size_t); | ||
265 | ptr = &((size_t *) ptr)[-1]; | ||
266 | mem_used = mem_used - *((size_t *) ptr) + n; | ||
267 | #endif | ||
268 | #if defined(M_SIZE) | 235 | #if defined(M_SIZE) |
269 | #if ENABLE_POISONING | 236 | #if ENABLE_POISONING |
270 | { | 237 | { |
@@ -295,9 +262,6 @@ GNUNET_xrealloc_ (void *ptr, size_t n, const char *filename, int linenumber) | |||
295 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); | 262 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc"); |
296 | GNUNET_assert (0); | 263 | GNUNET_assert (0); |
297 | } | 264 | } |
298 | #ifdef W32_MEM_LIMIT | ||
299 | ptr = &((size_t *) ptr)[1]; | ||
300 | #endif | ||
301 | return ptr; | 265 | return ptr; |
302 | } | 266 | } |
303 | 267 | ||
@@ -333,10 +297,6 @@ GNUNET_xfree_ (void *ptr, | |||
333 | { | 297 | { |
334 | if (NULL == ptr) | 298 | if (NULL == ptr) |
335 | return; | 299 | return; |
336 | #ifdef W32_MEM_LIMIT | ||
337 | ptr = &((size_t *) ptr)[-1]; | ||
338 | mem_used -= *((size_t *) ptr); | ||
339 | #endif | ||
340 | #if defined(M_SIZE) | 300 | #if defined(M_SIZE) |
341 | #if ENABLE_POISONING | 301 | #if ENABLE_POISONING |
342 | { | 302 | { |