00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef APR_THREAD_PROC_H
00017 #define APR_THREAD_PROC_H
00018
00024 #include "apr.h"
00025 #include "apr_file_io.h"
00026 #include "apr_pools.h"
00027 #include "apr_errno.h"
00028
00029 #if APR_HAVE_STRUCT_RLIMIT
00030 #include <sys/time.h>
00031 #include <sys/resource.h>
00032 #endif
00033
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif
00037
00044 typedef enum {
00045 APR_SHELLCMD,
00046 APR_PROGRAM,
00047 APR_PROGRAM_ENV,
00048 APR_PROGRAM_PATH,
00049 APR_SHELLCMD_ENV
00052 } apr_cmdtype_e;
00053
00054 typedef enum {
00055 APR_WAIT,
00056 APR_NOWAIT
00057 } apr_wait_how_e;
00058
00059
00060
00061
00062
00063
00064 typedef enum {
00065 APR_PROC_EXIT = 1,
00066 APR_PROC_SIGNAL = 2,
00067 APR_PROC_SIGNAL_CORE = 4
00068 } apr_exit_why_e;
00069
00071 #define APR_PROC_CHECK_EXIT(x) (x & APR_PROC_EXIT)
00072
00073 #define APR_PROC_CHECK_SIGNALED(x) (x & APR_PROC_SIGNAL)
00074
00075 #define APR_PROC_CHECK_CORE_DUMP(x) (x & APR_PROC_SIGNAL_CORE)
00076
00078 #define APR_NO_PIPE 0
00079
00081 #define APR_FULL_BLOCK 1
00082
00083 #define APR_FULL_NONBLOCK 2
00084
00085 #define APR_PARENT_BLOCK 3
00086
00087 #define APR_CHILD_BLOCK 4
00088
00090 #define APR_LIMIT_CPU 0
00091
00092 #define APR_LIMIT_MEM 1
00093
00094 #define APR_LIMIT_NPROC 2
00095
00096 #define APR_LIMIT_NOFILE 3
00097
00102 #define APR_OC_REASON_DEATH 0
00104 #define APR_OC_REASON_UNWRITABLE 1
00105 #define APR_OC_REASON_RESTART 2
00109 #define APR_OC_REASON_UNREGISTER 3
00112 #define APR_OC_REASON_LOST 4
00114 #define APR_OC_REASON_RUNNING 5
00121 typedef struct apr_proc_t {
00122
00123 pid_t pid;
00125 apr_file_t *in;
00127 apr_file_t *out;
00129 apr_file_t *err;
00130 #if APR_HAS_PROC_INVOKED || defined(DOXYGEN)
00131
00138 char *invoked;
00139 #endif
00140 #if defined(WIN32) || defined(DOXYGEN)
00141
00147 HANDLE hproc;
00148 #endif
00149 } apr_proc_t;
00150
00161 typedef void (apr_child_errfn_t)(apr_pool_t *proc, apr_status_t err,
00162 const char *description);
00163
00165 typedef struct apr_thread_t apr_thread_t;
00166
00168 typedef struct apr_threadattr_t apr_threadattr_t;
00169
00171 typedef struct apr_procattr_t apr_procattr_t;
00172
00174 typedef struct apr_thread_once_t apr_thread_once_t;
00175
00177 typedef struct apr_threadkey_t apr_threadkey_t;
00178
00180 typedef struct apr_other_child_rec_t apr_other_child_rec_t;
00181
00185 typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_t*, void*);
00186
00187 typedef enum {
00188 APR_KILL_NEVER,
00189 APR_KILL_ALWAYS,
00190 APR_KILL_AFTER_TIMEOUT,
00191 APR_JUST_WAIT,
00192 APR_KILL_ONLY_ONCE
00193 } apr_kill_conditions_e;
00194
00195
00196
00197 #if APR_HAS_THREADS
00198
00204 APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new_attr,
00205 apr_pool_t *cont);
00206
00212 APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr,
00213 apr_int32_t on);
00214
00219 APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr);
00220
00229 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread,
00230 apr_threadattr_t *attr,
00231 apr_thread_start_t func,
00232 void *data, apr_pool_t *cont);
00233
00239 APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
00240 apr_status_t retval);
00241
00247 APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
00248 apr_thread_t *thd);
00249
00253 APR_DECLARE(void) apr_thread_yield(void);
00254
00261 APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
00262 apr_pool_t *p);
00263
00273 APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
00274 void (*func)(void));
00275
00280 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd);
00281
00288 APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
00289 apr_thread_t *thread);
00290
00298 APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
00299 apr_status_t (*cleanup) (void *),
00300 apr_thread_t *thread);
00301
00308 APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
00309 void (*dest)(void *),
00310 apr_pool_t *cont);
00311
00317 APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new_mem,
00318 apr_threadkey_t *key);
00319
00325 APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv,
00326 apr_threadkey_t *key);
00327
00332 APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key);
00333
00340 APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
00341 apr_threadkey_t *threadkey);
00342
00350 APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
00351 apr_status_t (*cleanup) (void *),
00352 apr_threadkey_t *threadkey);
00353
00354 #endif
00355
00361 APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new_attr,
00362 apr_pool_t *cont);
00363
00372 APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
00373 apr_int32_t in, apr_int32_t out,
00374 apr_int32_t err);
00375
00388 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(struct apr_procattr_t *attr,
00389 apr_file_t *child_in,
00390 apr_file_t *parent_in);
00391
00402 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(struct apr_procattr_t *attr,
00403 apr_file_t *child_out,
00404 apr_file_t *parent_out);
00405
00416 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(struct apr_procattr_t *attr,
00417 apr_file_t *child_err,
00418 apr_file_t *parent_err);
00419
00427 APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
00428 const char *dir);
00429
00441 APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
00442 apr_cmdtype_e cmd);
00443
00449 APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
00450 apr_int32_t detach);
00451
00452 #if APR_HAVE_STRUCT_RLIMIT
00453
00465 APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr,
00466 apr_int32_t what,
00467 struct rlimit *limit);
00468 #endif
00469
00481 APR_DECLARE(apr_status_t) apr_procattr_child_errfn_set(apr_procattr_t *attr,
00482 apr_child_errfn_t *errfn);
00483
00496 APR_DECLARE(apr_status_t) apr_procattr_error_check_set(apr_procattr_t *attr,
00497 apr_int32_t chk);
00498
00499 #if APR_HAS_FORK
00500
00506 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont);
00507 #endif
00508
00523 APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new_proc,
00524 const char *progname,
00525 const char * const *args,
00526 const char * const *env,
00527 apr_procattr_t *attr,
00528 apr_pool_t *cont);
00529
00556 APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
00557 int *exitcode, apr_exit_why_e *exitwhy,
00558 apr_wait_how_e waithow);
00559
00586 APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
00587 int *exitcode,
00588 apr_exit_why_e *exitwhy,
00589 apr_wait_how_e waithow,
00590 apr_pool_t *p);
00591
00592 #define APR_PROC_DETACH_FOREGROUND 0
00593 #define APR_PROC_DETACH_DAEMONIZE 1
00601 APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize);
00602
00620 APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc,
00621 void (*maintenance) (int reason,
00622 void *,
00623 int status),
00624 void *data, apr_file_t *write_fd,
00625 apr_pool_t *p);
00626
00636 APR_DECLARE(void) apr_proc_other_child_unregister(void *data);
00637
00658 APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc,
00659 int reason,
00660 int status);
00661
00669 APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
00670 int reason);
00671
00678 APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason);
00679
00686 APR_DECLARE(void) apr_proc_other_child_check(void);
00687
00691 APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *proc, int status);
00692
00693
00699 APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int sig);
00700
00714 APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *proc,
00715 apr_kill_conditions_e how);
00716
00717 #if APR_HAS_THREADS
00718
00719 #if (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2)
00720
00725 APR_DECLARE(apr_status_t) apr_setup_signal_thread(void);
00726
00734 APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum));
00735
00736 #endif
00737
00742 APR_POOL_DECLARE_ACCESSOR(thread);
00743
00744 #endif
00745
00748 #ifdef __cplusplus
00749 }
00750 #endif
00751
00752 #endif
00753