1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef APR_THREAD_PROC_H
18 #define APR_THREAD_PROC_H
21 * @file apr_thread_proc.h
22 * @brief APR Thread and Process Library
26 #include "apr_file_io.h"
27 #include "apr_pools.h"
28 #include "apr_errno.h"
30 #if APR_HAVE_STRUCT_RLIMIT
32 #include <sys/resource.h>
37 #endif /* __cplusplus */
40 * @defgroup apr_thread_proc Threads and Process Functions
46 APR_SHELLCMD, /**< use the shell to invoke the program */
47 APR_PROGRAM, /**< invoke the program directly, no copied env */
48 APR_PROGRAM_ENV, /**< invoke the program, replicating our environment */
49 APR_PROGRAM_PATH, /**< find program on PATH, use our environment */
50 APR_SHELLCMD_ENV /**< use the shell to invoke the program,
51 * replicating our environment
56 APR_WAIT, /**< wait for the specified process to finish */
57 APR_NOWAIT /**< do not wait -- just see if it has finished */
60 /* I am specifically calling out the values so that the macros below make
61 * more sense. Yes, I know I don't need to, but I am hoping this makes what
62 * I am doing more clear. If you want to add more reasons to exit, continue
66 APR_PROC_EXIT = 1, /**< process exited normally */
67 APR_PROC_SIGNAL = 2, /**< process exited due to a signal */
68 APR_PROC_SIGNAL_CORE = 4 /**< process exited and dumped a core file */
71 /** did we exit the process */
72 #define APR_PROC_CHECK_EXIT(x) (x & APR_PROC_EXIT)
73 /** did we get a signal */
74 #define APR_PROC_CHECK_SIGNALED(x) (x & APR_PROC_SIGNAL)
75 /** did we get core */
76 #define APR_PROC_CHECK_CORE_DUMP(x) (x & APR_PROC_SIGNAL_CORE)
78 /** @see apr_procattr_io_set */
80 /** @see apr_procattr_io_set and apr_file_pipe_create_ex */
81 #define APR_FULL_BLOCK 1
82 /** @see apr_procattr_io_set and apr_file_pipe_create_ex */
83 #define APR_FULL_NONBLOCK 2
84 /** @see apr_procattr_io_set */
85 #define APR_PARENT_BLOCK 3
86 /** @see apr_procattr_io_set */
87 #define APR_CHILD_BLOCK 4
88 /** @see apr_procattr_io_set */
91 /** @see apr_file_pipe_create_ex */
92 #define APR_READ_BLOCK 3
93 /** @see apr_file_pipe_create_ex */
94 #define APR_WRITE_BLOCK 4
96 /** @see apr_procattr_io_set
97 * @note Win32 only effective with version 1.2.12, portably introduced in 1.3.0
101 /** @see apr_procattr_limit_set */
102 #define APR_LIMIT_CPU 0
103 /** @see apr_procattr_limit_set */
104 #define APR_LIMIT_MEM 1
105 /** @see apr_procattr_limit_set */
106 #define APR_LIMIT_NPROC 2
107 /** @see apr_procattr_limit_set */
108 #define APR_LIMIT_NOFILE 3
111 * @defgroup APR_OC Other Child Flags
114 #define APR_OC_REASON_DEATH 0 /**< child has died, caller must call
115 * unregister still */
116 #define APR_OC_REASON_UNWRITABLE 1 /**< write_fd is unwritable */
117 #define APR_OC_REASON_RESTART 2 /**< a restart is occurring, perform
118 * any necessary cleanup (including
119 * sending a special signal to child)
121 #define APR_OC_REASON_UNREGISTER 3 /**< unregister has been called, do
122 * whatever is necessary (including
124 #define APR_OC_REASON_LOST 4 /**< somehow the child exited without
125 * us knowing ... buggy os? */
126 #define APR_OC_REASON_RUNNING 5 /**< a health check is occurring,
127 * for most maintainence functions
132 /** The APR process type */
133 typedef struct apr_proc_t {
134 /** The process ID */
136 /** Parent's side of pipe to child's stdin */
138 /** Parent's side of pipe to child's stdout */
140 /** Parent's side of pipe to child's stdouterr */
142 #if APR_HAS_PROC_INVOKED || defined(DOXYGEN)
143 /** Diagnositics/debugging string of the command invoked for
144 * this process [only present if APR_HAS_PROC_INVOKED is true]
145 * @remark Only enabled on Win32 by default.
146 * @bug This should either always or never be present in release
147 * builds - since it breaks binary compatibility. We may enable
148 * it always in APR 1.0 yet leave it undefined in most cases.
152 #if defined(WIN32) || defined(DOXYGEN)
153 /** (Win32 only) Creator's handle granting access to the process
154 * @remark This handle is closed and reset to NULL in every case
155 * corresponding to a waitpid() on Unix which returns the exit status.
156 * Therefore Win32 correspond's to Unix's zombie reaping characteristics
157 * and avoids potential handle leaks.
164 * The prototype for APR child errfn functions. (See the description
165 * of apr_procattr_child_errfn_set() for more information.)
166 * It is passed the following parameters:
167 * @param pool Pool associated with the apr_proc_t. If your child
168 * error function needs user data, associate it with this
170 * @param err APR error code describing the error
171 * @param description Text description of type of processing which failed
173 typedef void (apr_child_errfn_t)(apr_pool_t *proc, apr_status_t err,
174 const char *description);
176 /** Opaque Thread structure. */
177 typedef struct apr_thread_t apr_thread_t;
179 /** Opaque Thread attributes structure. */
180 typedef struct apr_threadattr_t apr_threadattr_t;
182 /** Opaque Process attributes structure. */
183 typedef struct apr_procattr_t apr_procattr_t;
185 /** Opaque control variable for one-time atomic variables. */
186 typedef struct apr_thread_once_t apr_thread_once_t;
188 /** Opaque thread private address space. */
189 typedef struct apr_threadkey_t apr_threadkey_t;
191 /** Opaque record of child process. */
192 typedef struct apr_other_child_rec_t apr_other_child_rec_t;
195 * The prototype for any APR thread worker functions.
197 typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_t*, void*);
200 APR_KILL_NEVER, /**< process is never killed (i.e., never sent
201 * any signals), but it will be reaped if it exits
202 * before the pool is cleaned up */
203 APR_KILL_ALWAYS, /**< process is sent SIGKILL on apr_pool_t cleanup */
204 APR_KILL_AFTER_TIMEOUT, /**< SIGTERM, wait 3 seconds, SIGKILL */
205 APR_JUST_WAIT, /**< wait forever for the process to complete */
206 APR_KILL_ONLY_ONCE /**< send SIGTERM and then wait */
207 } apr_kill_conditions_e;
209 /* Thread Function definitions */
214 * Create and initialize a new threadattr variable
215 * @param new_attr The newly created threadattr.
216 * @param cont The pool to use
218 APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new_attr,
222 * Set if newly created threads should be created in detached state.
223 * @param attr The threadattr to affect
224 * @param on Non-zero if detached threads should be created.
226 APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr,
230 * Get the detach state for this threadattr.
231 * @param attr The threadattr to reference
232 * @return APR_DETACH if threads are to be detached, or APR_NOTDETACH
233 * if threads are to be joinable.
235 APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr);
238 * Set the stack size of newly created threads.
239 * @param attr The threadattr to affect
240 * @param stacksize The stack size in bytes
242 APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
243 apr_size_t stacksize);
246 * Set the stack guard area size of newly created threads.
247 * @param attr The threadattr to affect
248 * @param guardsize The stack guard area size in bytes
249 * @note Thread library implementations commonly use a "guard area"
250 * after each thread's stack which is not readable or writable such that
251 * stack overflows cause a segfault; this consumes e.g. 4K of memory
252 * and increases memory management overhead. Setting the guard area
253 * size to zero hence trades off reliable behaviour on stack overflow
254 * for performance. */
255 APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
256 apr_size_t guardsize);
259 * Create a new thread of execution
260 * @param new_thread The newly created thread handle.
261 * @param attr The threadattr to use to determine how to create the thread
262 * @param func The function to start the new thread in
263 * @param data Any data to be passed to the starting function
264 * @param cont The pool to use
266 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread,
267 apr_threadattr_t *attr,
268 apr_thread_start_t func,
269 void *data, apr_pool_t *cont);
272 * stop the current thread
273 * @param thd The thread to stop
274 * @param retval The return value to pass back to any thread that cares
276 APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
277 apr_status_t retval);
280 * block until the desired thread stops executing.
281 * @param retval The return value from the dead thread.
282 * @param thd The thread to join
284 APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
288 * force the current thread to yield the processor
290 APR_DECLARE(void) apr_thread_yield(void);
293 * Initialize the control variable for apr_thread_once. If this isn't
294 * called, apr_initialize won't work.
295 * @param control The control variable to initialize
296 * @param p The pool to allocate data from.
298 APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
302 * Run the specified function one time, regardless of how many threads
304 * @param control The control variable. The same variable should
305 * be passed in each time the function is tried to be
306 * called. This is how the underlying functions determine
307 * if the function has ever been called before.
308 * @param func The function to call.
310 APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
315 * @param thd The thread to detach
317 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd);
320 * Return user data associated with the current thread.
321 * @param data The user data associated with the thread.
322 * @param key The key to associate with the data
323 * @param thread The currently open thread.
325 APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
326 apr_thread_t *thread);
329 * Set user data associated with the current thread.
330 * @param data The user data to associate with the thread.
331 * @param key The key to use for associating the data with the thread
332 * @param cleanup The cleanup routine to use when the thread is destroyed.
333 * @param thread The currently open thread.
335 APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
336 apr_status_t (*cleanup) (void *),
337 apr_thread_t *thread);
340 * Create and initialize a new thread private address space
341 * @param key The thread private handle.
342 * @param dest The destructor to use when freeing the private memory.
343 * @param cont The pool to use
345 APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
346 void (*dest)(void *),
350 * Get a pointer to the thread private memory
351 * @param new_mem The data stored in private memory
352 * @param key The handle for the desired thread private memory
354 APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new_mem,
355 apr_threadkey_t *key);
358 * Set the data to be stored in thread private memory
359 * @param priv The data to be stored in private memory
360 * @param key The handle for the desired thread private memory
362 APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv,
363 apr_threadkey_t *key);
366 * Free the thread private memory
367 * @param key The handle for the desired thread private memory
369 APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key);
372 * Return the pool associated with the current threadkey.
373 * @param data The user data associated with the threadkey.
374 * @param key The key associated with the data
375 * @param threadkey The currently open threadkey.
377 APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
378 apr_threadkey_t *threadkey);
381 * Return the pool associated with the current threadkey.
382 * @param data The data to set.
383 * @param key The key to associate with the data.
384 * @param cleanup The cleanup routine to use when the file is destroyed.
385 * @param threadkey The currently open threadkey.
387 APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
388 apr_status_t (*cleanup) (void *),
389 apr_threadkey_t *threadkey);
394 * Create and initialize a new procattr variable
395 * @param new_attr The newly created procattr.
396 * @param cont The pool to use
398 APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new_attr,
402 * Determine if any of stdin, stdout, or stderr should be linked to pipes
403 * when starting a child process.
404 * @param attr The procattr we care about.
405 * @param in Should stdin be a pipe back to the parent?
406 * @param out Should stdout be a pipe back to the parent?
407 * @param err Should stderr be a pipe back to the parent?
408 * @note If APR_NO_PIPE, there will be no special channel, the child
409 * inherits the parent's corresponding stdio stream. If APR_NO_FILE is
410 * specified, that corresponding stream is closed in the child (and will
411 * be INVALID_HANDLE_VALUE when inspected on Win32). This can have ugly
412 * side effects, as the next file opened in the child on Unix will fall
413 * into the stdio stream fd slot!
415 APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
416 apr_int32_t in, apr_int32_t out,
420 * Set the child_in and/or parent_in values to existing apr_file_t values.
421 * @param attr The procattr we care about.
422 * @param child_in apr_file_t value to use as child_in. Must be a valid file.
423 * @param parent_in apr_file_t value to use as parent_in. Must be a valid file.
424 * @remark This is NOT a required initializer function. This is
425 * useful if you have already opened a pipe (or multiple files)
426 * that you wish to use, perhaps persistently across multiple
427 * process invocations - such as a log file. You can save some
428 * extra function calls by not creating your own pipe since this
429 * creates one in the process space for you.
430 * @bug Note that calling this function with two NULL files on some platforms
431 * creates an APR_FULL_BLOCK pipe, but this behavior is neither portable nor
432 * is it supported. @see apr_procattr_io_set instead for simple pipes.
434 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(struct apr_procattr_t *attr,
435 apr_file_t *child_in,
436 apr_file_t *parent_in);
439 * Set the child_out and parent_out values to existing apr_file_t values.
440 * @param attr The procattr we care about.
441 * @param child_out apr_file_t value to use as child_out. Must be a valid file.
442 * @param parent_out apr_file_t value to use as parent_out. Must be a valid file.
443 * @remark This is NOT a required initializer function. This is
444 * useful if you have already opened a pipe (or multiple files)
445 * that you wish to use, perhaps persistently across multiple
446 * process invocations - such as a log file.
447 * @bug Note that calling this function with two NULL files on some platforms
448 * creates an APR_FULL_BLOCK pipe, but this behavior is neither portable nor
449 * is it supported. @see apr_procattr_io_set instead for simple pipes.
451 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(struct apr_procattr_t *attr,
452 apr_file_t *child_out,
453 apr_file_t *parent_out);
456 * Set the child_err and parent_err values to existing apr_file_t values.
457 * @param attr The procattr we care about.
458 * @param child_err apr_file_t value to use as child_err. Must be a valid file.
459 * @param parent_err apr_file_t value to use as parent_err. Must be a valid file.
460 * @remark This is NOT a required initializer function. This is
461 * useful if you have already opened a pipe (or multiple files)
462 * that you wish to use, perhaps persistently across multiple
463 * process invocations - such as a log file.
464 * @bug Note that calling this function with two NULL files on some platforms
465 * creates an APR_FULL_BLOCK pipe, but this behavior is neither portable nor
466 * is it supported. @see apr_procattr_io_set instead for simple pipes.
468 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(struct apr_procattr_t *attr,
469 apr_file_t *child_err,
470 apr_file_t *parent_err);
473 * Set which directory the child process should start executing in.
474 * @param attr The procattr we care about.
475 * @param dir Which dir to start in. By default, this is the same dir as
476 * the parent currently resides in, when the createprocess call
479 APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
483 * Set what type of command the child process will call.
484 * @param attr The procattr we care about.
485 * @param cmd The type of command. One of:
487 * APR_SHELLCMD -- Anything that the shell can handle
488 * APR_PROGRAM -- Executable program (default)
489 * APR_PROGRAM_ENV -- Executable program, copy environment
490 * APR_PROGRAM_PATH -- Executable program on PATH, copy env
493 APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
497 * Determine if the child should start in detached state.
498 * @param attr The procattr we care about.
499 * @param detach Should the child start in detached state? Default is no.
501 APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
504 #if APR_HAVE_STRUCT_RLIMIT
506 * Set the Resource Utilization limits when starting a new process.
507 * @param attr The procattr we care about.
508 * @param what Which limit to set, one of:
515 * @param limit Value to set the limit to.
517 APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr,
519 struct rlimit *limit);
523 * Specify an error function to be called in the child process if APR
524 * encounters an error in the child prior to running the specified program.
525 * @param attr The procattr describing the child process to be created.
526 * @param errfn The function to call in the child process.
527 * @remark At the present time, it will only be called from apr_proc_create()
528 * on platforms where fork() is used. It will never be called on other
529 * platforms, on those platforms apr_proc_create() will return the error
530 * in the parent process rather than invoke the callback in the now-forked
533 APR_DECLARE(apr_status_t) apr_procattr_child_errfn_set(apr_procattr_t *attr,
534 apr_child_errfn_t *errfn);
537 * Specify that apr_proc_create() should do whatever it can to report
538 * failures to the caller of apr_proc_create(), rather than find out in
540 * @param attr The procattr describing the child process to be created.
541 * @param chk Flag to indicate whether or not extra work should be done
542 * to try to report failures to the caller.
543 * @remark This flag only affects apr_proc_create() on platforms where
544 * fork() is used. This leads to extra overhead in the calling
545 * process, but that may help the application handle such
546 * errors more gracefully.
548 APR_DECLARE(apr_status_t) apr_procattr_error_check_set(apr_procattr_t *attr,
552 * Determine if the child should start in its own address space or using the
553 * current one from its parent
554 * @param attr The procattr we care about.
555 * @param addrspace Should the child start in its own address space? Default
556 * is no on NetWare and yes on other platforms.
558 APR_DECLARE(apr_status_t) apr_procattr_addrspace_set(apr_procattr_t *attr,
559 apr_int32_t addrspace);
562 * Set the username used for running process
563 * @param attr The procattr we care about.
564 * @param username The username used
565 * @param password User password if needed. Password is needed on WIN32
566 * or any other platform having
567 * APR_PROCATTR_USER_SET_REQUIRES_PASSWORD set.
569 APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
570 const char *username,
571 const char *password);
574 * Set the group used for running process
575 * @param attr The procattr we care about.
576 * @param groupname The group name used
578 APR_DECLARE(apr_status_t) apr_procattr_group_set(apr_procattr_t *attr,
579 const char *groupname);
584 * This is currently the only non-portable call in APR. This executes
585 * a standard unix fork.
586 * @param proc The resulting process handle.
587 * @param cont The pool to use.
588 * @remark returns APR_INCHILD for the child, and APR_INPARENT for the parent
591 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont);
595 * Create a new process and execute a new program within that process.
596 * @param new_proc The resulting process handle.
597 * @param progname The program to run
598 * @param args the arguments to pass to the new program. The first
599 * one should be the program name.
600 * @param env The new environment table for the new process. This
601 * should be a list of NULL-terminated strings. This argument
602 * is ignored for APR_PROGRAM_ENV, APR_PROGRAM_PATH, and
603 * APR_SHELLCMD_ENV types of commands.
604 * @param attr the procattr we should use to determine how to create the new
606 * @param pool The pool to use.
607 * @note This function returns without waiting for the new process to terminate;
608 * use apr_proc_wait for that.
610 APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new_proc,
611 const char *progname,
612 const char * const *args,
613 const char * const *env,
614 apr_procattr_t *attr,
618 * Wait for a child process to die
619 * @param proc The process handle that corresponds to the desired child process
620 * @param exitcode The returned exit status of the child, if a child process
621 * dies, or the signal that caused the child to die.
622 * On platforms that don't support obtaining this information,
623 * the status parameter will be returned as APR_ENOTIMPL.
624 * @param exitwhy Why the child died, the bitwise or of:
626 * APR_PROC_EXIT -- process terminated normally
627 * APR_PROC_SIGNAL -- process was killed by a signal
628 * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and
629 * generated a core dump.
631 * @param waithow How should we wait. One of:
633 * APR_WAIT -- block until the child process dies.
634 * APR_NOWAIT -- return immediately regardless of if the
635 * child is dead or not.
637 * @remark The child's status is in the return code to this process. It is one of:
639 * APR_CHILD_DONE -- child is no longer running.
640 * APR_CHILD_NOTDONE -- child is still running.
643 APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
644 int *exitcode, apr_exit_why_e *exitwhy,
645 apr_wait_how_e waithow);
648 * Wait for any current child process to die and return information
650 * @param proc Pointer to NULL on entry, will be filled out with child's
652 * @param exitcode The returned exit status of the child, if a child process
653 * dies, or the signal that caused the child to die.
654 * On platforms that don't support obtaining this information,
655 * the status parameter will be returned as APR_ENOTIMPL.
656 * @param exitwhy Why the child died, the bitwise or of:
658 * APR_PROC_EXIT -- process terminated normally
659 * APR_PROC_SIGNAL -- process was killed by a signal
660 * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and
661 * generated a core dump.
663 * @param waithow How should we wait. One of:
665 * APR_WAIT -- block until the child process dies.
666 * APR_NOWAIT -- return immediately regardless of if the
667 * child is dead or not.
669 * @param p Pool to allocate child information out of.
670 * @bug Passing proc as a *proc rather than **proc was an odd choice
671 * for some platforms... this should be revisited in 1.0
673 APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
675 apr_exit_why_e *exitwhy,
676 apr_wait_how_e waithow,
679 #define APR_PROC_DETACH_FOREGROUND 0 /**< Do not detach */
680 #define APR_PROC_DETACH_DAEMONIZE 1 /**< Detach */
683 * Detach the process from the controlling terminal.
684 * @param daemonize set to non-zero if the process should daemonize
685 * and become a background process, else it will
686 * stay in the foreground.
688 APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize);
691 * Register an other_child -- a child associated to its registered
692 * maintence callback. This callback is invoked when the process
693 * dies, is disconnected or disappears.
694 * @param proc The child process to register.
695 * @param maintenance maintenance is a function that is invoked with a
696 * reason and the data pointer passed here.
697 * @param data Opaque context data passed to the maintenance function.
698 * @param write_fd An fd that is probed for writing. If it is ever unwritable
699 * then the maintenance is invoked with reason
700 * OC_REASON_UNWRITABLE.
701 * @param p The pool to use for allocating memory.
702 * @bug write_fd duplicates the proc->out stream, it's really redundant
703 * and should be replaced in the APR 1.0 API with a bitflag of which
704 * proc->in/out/err handles should be health checked.
705 * @bug no platform currently tests the pipes health.
707 APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc,
708 void (*maintenance) (int reason,
711 void *data, apr_file_t *write_fd,
715 * Stop watching the specified other child.
716 * @param data The data to pass to the maintenance function. This is
717 * used to find the process to unregister.
718 * @warning Since this can be called by a maintenance function while we're
719 * scanning the other_children list, all scanners should protect
720 * themself by loading ocr->next before calling any maintenance
723 APR_DECLARE(void) apr_proc_other_child_unregister(void *data);
726 * Notify the maintenance callback of a registered other child process
727 * that application has detected an event, such as death.
728 * @param proc The process to check
729 * @param reason The reason code to pass to the maintenance function
730 * @param status The status to pass to the maintenance function
731 * @remark An example of code using this behavior;
733 * rv = apr_proc_wait_all_procs(&proc, &exitcode, &status, APR_WAIT, p);
734 * if (APR_STATUS_IS_CHILD_DONE(rv)) {
735 * \#if APR_HAS_OTHER_CHILD
736 * if (apr_proc_other_child_alert(&proc, APR_OC_REASON_DEATH, status)
738 * ; (already handled)
742 * [... handling non-otherchild processes death ...]
745 APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc,
750 * Test one specific other child processes and invoke the maintenance callback
751 * with the appropriate reason code, if still running, or the appropriate reason
752 * code if the process is no longer healthy.
753 * @param ocr The registered other child
754 * @param reason The reason code (e.g. APR_OC_REASON_RESTART) if still running
756 APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
760 * Test all registered other child processes and invoke the maintenance callback
761 * with the appropriate reason code, if still running, or the appropriate reason
762 * code if the process is no longer healthy.
763 * @param reason The reason code (e.g. APR_OC_REASON_RESTART) to running processes
765 APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason);
768 * Terminate a process.
769 * @param proc The process to terminate.
770 * @param sig How to kill the process.
772 APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int sig);
775 * Register a process to be killed when a pool dies.
776 * @param a The pool to use to define the processes lifetime
777 * @param proc The process to register
778 * @param how How to kill the process, one of:
780 * APR_KILL_NEVER -- process is never sent any signals
781 * APR_KILL_ALWAYS -- process is sent SIGKILL on apr_pool_t cleanup
782 * APR_KILL_AFTER_TIMEOUT -- SIGTERM, wait 3 seconds, SIGKILL
783 * APR_JUST_WAIT -- wait forever for the process to complete
784 * APR_KILL_ONLY_ONCE -- send SIGTERM and then wait
787 APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *proc,
788 apr_kill_conditions_e how);
792 #if (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2)
795 * Setup the process for a single thread to be used for all signal handling.
796 * @warning This must be called before any threads are created
798 APR_DECLARE(apr_status_t) apr_setup_signal_thread(void);
801 * Make the current thread listen for signals. This thread will loop
802 * forever, calling a provided function whenever it receives a signal. That
803 * functions should return 1 if the signal has been handled, 0 otherwise.
804 * @param signal_handler The function to call when a signal is received
805 * apr_status_t apr_signal_thread((int)(*signal_handler)(int signum))
807 APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum));
809 #endif /* (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2) */
812 * Get the child-pool used by the thread from the thread info.
813 * @return apr_pool_t the pool
815 APR_POOL_DECLARE_ACCESSOR(thread);
817 #endif /* APR_HAS_THREADS */
825 #endif /* ! APR_THREAD_PROC_H */