diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-02-27 11:00:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-02-27 11:00:10 +0000 |
commit | 0238db34853380280ccf164918ebbb28260f4629 (patch) | |
tree | 2c47ddbbfa27e7a0479d5c12e78d77342780a4bd /src/include/gnunet_os_lib.h | |
parent | dc3ae8f36ec69ca2a96a93feda501682ff168320 (diff) | |
download | gnunet-0238db34853380280ccf164918ebbb28260f4629.tar.gz gnunet-0238db34853380280ccf164918ebbb28260f4629.zip |
enabling use of pipes for signal communication also on UNIX to enable future integration with Java services
Diffstat (limited to 'src/include/gnunet_os_lib.h')
-rw-r--r-- | src/include/gnunet_os_lib.h | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index c56947431..e9e484f78 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h | |||
@@ -27,6 +27,16 @@ | |||
27 | * @author Ioana Patrascu | 27 | * @author Ioana Patrascu |
28 | * @author Tzvetan Horozov | 28 | * @author Tzvetan Horozov |
29 | * @author Milan | 29 | * @author Milan |
30 | * | ||
31 | * This code manages child processes. We can communicate with child | ||
32 | * processes using signals. Because signals are not supported on W32 | ||
33 | * and Java (at least not nicely), we can alternatively use a pipe | ||
34 | * to send signals to the child processes (if the child process is | ||
35 | * a full-blown GNUnet process that supports reading signals from | ||
36 | * a pipe, of course). Naturally, this also only works for 'normal' | ||
37 | * termination via signals, and not as a replacement for SIGKILL. | ||
38 | * Thus using pipes to communicate signals should only be enabled if | ||
39 | * the child is a Java process OR if we are on Windoze. | ||
30 | */ | 40 | */ |
31 | 41 | ||
32 | #ifndef GNUNET_OS_LIB_H | 42 | #ifndef GNUNET_OS_LIB_H |
@@ -201,7 +211,7 @@ GNUNET_OS_process_current (void); | |||
201 | 211 | ||
202 | 212 | ||
203 | /** | 213 | /** |
204 | * Sends sig to the process | 214 | * Sends a signal to the process |
205 | * | 215 | * |
206 | * @param proc pointer to process structure | 216 | * @param proc pointer to process structure |
207 | * @param sig signal | 217 | * @param sig signal |
@@ -219,6 +229,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig); | |||
219 | void | 229 | void |
220 | GNUNET_OS_process_close (struct GNUNET_OS_Process *proc); | 230 | GNUNET_OS_process_close (struct GNUNET_OS_Process *proc); |
221 | 231 | ||
232 | |||
222 | /** | 233 | /** |
223 | * Get the pid of the process in question | 234 | * Get the pid of the process in question |
224 | * | 235 | * |
@@ -229,6 +240,7 @@ GNUNET_OS_process_close (struct GNUNET_OS_Process *proc); | |||
229 | pid_t | 240 | pid_t |
230 | GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc); | 241 | GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc); |
231 | 242 | ||
243 | |||
232 | /** | 244 | /** |
233 | * Set process priority | 245 | * Set process priority |
234 | * | 246 | * |
@@ -241,10 +253,10 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, | |||
241 | enum GNUNET_SCHEDULER_Priority prio); | 253 | enum GNUNET_SCHEDULER_Priority prio); |
242 | 254 | ||
243 | 255 | ||
244 | |||
245 | /** | 256 | /** |
246 | * Start a process. | 257 | * Start a process. |
247 | * | 258 | * |
259 | * @param pipe_control should a pipe be used to send signals to the child? | ||
248 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | 260 | * @param pipe_stdin pipe to use to send input to child process (or NULL) |
249 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | 261 | * @param pipe_stdout pipe to use to get output from child process (or NULL) |
250 | * @param filename name of the binary | 262 | * @param filename name of the binary |
@@ -252,7 +264,8 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, | |||
252 | * @return pointer to process structure of the new process, NULL on error | 264 | * @return pointer to process structure of the new process, NULL on error |
253 | */ | 265 | */ |
254 | struct GNUNET_OS_Process * | 266 | struct GNUNET_OS_Process * |
255 | GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, | 267 | GNUNET_OS_start_process_vap (int pipe_control, |
268 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | ||
256 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 269 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
257 | const char *filename, | 270 | const char *filename, |
258 | char *const argv[]); | 271 | char *const argv[]); |
@@ -261,6 +274,7 @@ GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
261 | /** | 274 | /** |
262 | * Start a process. | 275 | * Start a process. |
263 | * | 276 | * |
277 | * @param pipe_control should a pipe be used to send signals to the child? | ||
264 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | 278 | * @param pipe_stdin pipe to use to send input to child process (or NULL) |
265 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | 279 | * @param pipe_stdout pipe to use to get output from child process (or NULL) |
266 | * @param filename name of the binary | 280 | * @param filename name of the binary |
@@ -268,7 +282,8 @@ GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
268 | * @return pointer to process structure of the new process, NULL on error | 282 | * @return pointer to process structure of the new process, NULL on error |
269 | */ | 283 | */ |
270 | struct GNUNET_OS_Process * | 284 | struct GNUNET_OS_Process * |
271 | GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, | 285 | GNUNET_OS_start_process (int pipe_control, |
286 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | ||
272 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 287 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
273 | const char *filename, ...); | 288 | const char *filename, ...); |
274 | 289 | ||
@@ -276,6 +291,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
276 | /** | 291 | /** |
277 | * Start a process. | 292 | * Start a process. |
278 | * | 293 | * |
294 | * @param pipe_control should a pipe be used to send signals to the child? | ||
279 | * @param pipe_stdin pipe to use to send input to child process (or NULL) | 295 | * @param pipe_stdin pipe to use to send input to child process (or NULL) |
280 | * @param pipe_stdout pipe to use to get output from child process (or NULL) | 296 | * @param pipe_stdout pipe to use to get output from child process (or NULL) |
281 | * @param filename name of the binary | 297 | * @param filename name of the binary |
@@ -283,13 +299,15 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
283 | * @return pointer to process structure of the new process, NULL on error | 299 | * @return pointer to process structure of the new process, NULL on error |
284 | */ | 300 | */ |
285 | struct GNUNET_OS_Process * | 301 | struct GNUNET_OS_Process * |
286 | GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | 302 | GNUNET_OS_start_process_va (int pipe_control, |
303 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | ||
287 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 304 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
288 | const char *filename, va_list va); | 305 | const char *filename, va_list va); |
289 | 306 | ||
290 | /** | 307 | /** |
291 | * Start a process. | 308 | * Start a process. |
292 | * | 309 | * |
310 | * @param pipe_control should a pipe be used to send signals to the child? | ||
293 | * @param lsocks array of listen sockets to dup systemd-style (or NULL); | 311 | * @param lsocks array of listen sockets to dup systemd-style (or NULL); |
294 | * must be NULL on platforms where dup is not supported | 312 | * must be NULL on platforms where dup is not supported |
295 | * @param filename name of the binary | 313 | * @param filename name of the binary |
@@ -298,7 +316,9 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, | |||
298 | * @return pointer to process structure of the new process, NULL on error | 316 | * @return pointer to process structure of the new process, NULL on error |
299 | */ | 317 | */ |
300 | struct GNUNET_OS_Process * | 318 | struct GNUNET_OS_Process * |
301 | GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, const char *filename, | 319 | GNUNET_OS_start_process_v (int pipe_control, |
320 | const SOCKTYPE *lsocks, | ||
321 | const char *filename, | ||
302 | char *const argv[]); | 322 | char *const argv[]); |
303 | 323 | ||
304 | 324 | ||
@@ -307,6 +327,7 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, const char *filename, | |||
307 | */ | 327 | */ |
308 | struct GNUNET_OS_CommandHandle; | 328 | struct GNUNET_OS_CommandHandle; |
309 | 329 | ||
330 | |||
310 | /** | 331 | /** |
311 | * Type of a function to process a line of output. | 332 | * Type of a function to process a line of output. |
312 | * | 333 | * |
@@ -315,6 +336,7 @@ struct GNUNET_OS_CommandHandle; | |||
315 | */ | 336 | */ |
316 | typedef void (*GNUNET_OS_LineProcessor) (void *cls, const char *line); | 337 | typedef void (*GNUNET_OS_LineProcessor) (void *cls, const char *line); |
317 | 338 | ||
339 | |||
318 | /** | 340 | /** |
319 | * Stop/kill a command. | 341 | * Stop/kill a command. |
320 | * | 342 | * |
@@ -370,7 +392,13 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc); | |||
370 | 392 | ||
371 | 393 | ||
372 | /** | 394 | /** |
373 | * Connects this process to its parent via pipe | 395 | * Connects this process to its parent via pipe; |
396 | * essentially, the parent control handler will read signal numbers | ||
397 | * from the 'GNUNET_OS_CONTROL_PIPE' (as given in an environment | ||
398 | * variable) and raise those signals. | ||
399 | * | ||
400 | * @param cls closure (unused) | ||
401 | * @param tc scheduler context (unused) | ||
374 | */ | 402 | */ |
375 | void | 403 | void |
376 | GNUNET_OS_install_parent_control_handler (void *cls, | 404 | GNUNET_OS_install_parent_control_handler (void *cls, |