aboutsummaryrefslogtreecommitdiff
path: root/src/util/child_management.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-07-03 20:12:30 +0200
committerChristian Grothoff <christian@grothoff.org>2023-07-03 20:12:32 +0200
commitc9f09bed813f3629809e28446db3268b552edfd1 (patch)
tree7c38a84af07ef7d82751790429aa7fdb73ecf1bd /src/util/child_management.c
parente22ae6be5bf25c743a6c7db34bb0ef163704824f (diff)
downloadgnunet-c9f09bed813f3629809e28446db3268b552edfd1.tar.gz
gnunet-c9f09bed813f3629809e28446db3268b552edfd1.zip
handle race between child termination and us installing the SIGCHLD handler
Diffstat (limited to 'src/util/child_management.c')
-rw-r--r--src/util/child_management.c21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/util/child_management.c b/src/util/child_management.c
index 680dbcabe..e78ebac9f 100644
--- a/src/util/child_management.c
+++ b/src/util/child_management.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021-2023 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -153,6 +153,7 @@ sighandler_child_death (void)
153 errno = old_errno; /* restore errno */ 153 errno = old_errno; /* restore errno */
154} 154}
155 155
156
156/** 157/**
157 * Initializing the signal pipe for child handling. 158 * Initializing the signal pipe for child handling.
158 */ 159 */
@@ -193,20 +194,13 @@ child_management_done (void)
193} 194}
194 195
195 196
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 cb 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 */
204struct GNUNET_ChildWaitHandle * 197struct GNUNET_ChildWaitHandle *
205GNUNET_wait_child (struct GNUNET_OS_Process *proc, 198GNUNET_wait_child (struct GNUNET_OS_Process *proc,
206 GNUNET_ChildCompletedCallback cb, 199 GNUNET_ChildCompletedCallback cb,
207 void *cb_cls) 200 void *cb_cls)
208{ 201{
209 struct GNUNET_ChildWaitHandle *cwh; 202 struct GNUNET_ChildWaitHandle *cwh;
203 bool may_race = (NULL == sigpipe);
210 204
211 child_management_start (); 205 child_management_start ();
212 cwh = GNUNET_new (struct GNUNET_ChildWaitHandle); 206 cwh = GNUNET_new (struct GNUNET_ChildWaitHandle);
@@ -225,15 +219,14 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc,
225 &maint_child_death, 219 &maint_child_death,
226 NULL); 220 NULL);
227 } 221 }
222 /* Handle race-condition case where the child terminated just before we
223 installed the signal handler and thus we missed the signal. */
224 if (may_race)
225 sighandler_child_death ();
228 return cwh; 226 return cwh;
229} 227}
230 228
231 229
232/**
233 * Removing child handle.
234 *
235 * @param cwh The handle to be removed.
236 */
237void 230void
238GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh) 231GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh)
239{ 232{