00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef APR_THREAD_PROC_H
00018 #define APR_THREAD_PROC_H
00019
00025 #include "apr.h"
00026 #include "apr_file_io.h"
00027 #include "apr_pools.h"
00028 #include "apr_errno.h"
00029
00030 #if APR_HAVE_STRUCT_RLIMIT
00031 #include <sys/time.h>
00032 #include <sys/resource.h>
00033 #endif
00034
00035 #ifdef __cplusplus
00036 extern "C" {
00037 #endif
00038
00045 typedef enum {
00046 APR_SHELLCMD,
00047 APR_PROGRAM,
00048 APR_PROGRAM_ENV,
00049 APR_PROGRAM_PATH,
00050 APR_SHELLCMD_ENV
00053 } apr_cmdtype_e;
00054
00055 typedef enum {
00056 APR_WAIT,
00057 APR_NOWAIT
00058 } apr_wait_how_e;
00059
00060
00061
00062
00063
00064
00065 typedef enum {
00066 APR_PROC_EXIT = 1,
00067 APR_PROC_SIGNAL = 2,
00068 APR_PROC_SIGNAL_CORE = 4
00069 } apr_exit_why_e;
00070
00072 #define APR_PROC_CHECK_EXIT(x) (x & APR_PROC_EXIT)
00073
00074 #define APR_PROC_CHECK_SIGNALED(x) (x & APR_PROC_SIGNAL)
00075
00076 #define APR_PROC_CHECK_CORE_DUMP(x) (x & APR_PROC_SIGNAL_CORE)
00077
00079 #define APR_NO_PIPE 0
00080
00082 #define APR_FULL_BLOCK 1
00083
00084 #define APR_FULL_NONBLOCK 2
00085
00086 #define APR_PARENT_BLOCK 3
00087
00088 #define APR_CHILD_BLOCK 4
00089
00091 #define APR_LIMIT_CPU 0
00092
00093 #define APR_LIMIT_MEM 1
00094
00095 #define APR_LIMIT_NPROC 2
00096
00097 #define APR_LIMIT_NOFILE 3
00098
00103 #define APR_OC_REASON_DEATH 0
00105 #define APR_OC_REASON_UNWRITABLE 1
00106 #define APR_OC_REASON_RESTART 2
00110 #define APR_OC_REASON_UNREGISTER 3
00113 #define APR_OC_REASON_LOST 4
00115 #define APR_OC_REASON_RUNNING 5
00122 typedef struct apr_proc_t {
00123
00124 pid_t pid;
00126 apr_file_t *in;
00128 apr_file_t *out;
00130 apr_file_t *err;
00131 #if APR_HAS_PROC_INVOKED || defined(DOXYGEN)
00132
00139 char *invoked;
00140 #endif
00141 #if defined(WIN32) || defined(DOXYGEN)
00142
00148 HANDLE hproc;
00149 #endif
00150 } apr_proc_t;
00151
00162 typedef void (apr_child_errfn_t)(apr_pool_t *proc, apr_status_t err,
00163 const char *description);
00164
00166 typedef struct apr_thread_t apr_thread_t;
00167
00169 typedef struct apr_threadattr_t apr_threadattr_t;
00170
00172 typedef struct apr_procattr_t apr_procattr_t;
00173
00175 typedef struct apr_thread_once_t apr_thread_once_t;
00176
00178 typedef struct apr_threadkey_t apr_threadkey_t;
00179
00181 typedef struct apr_other_child_rec_t apr_other_child_rec_t;
00182
00186 typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_t*, void*);
00187
00188 typedef enum {
00189 APR_KILL_NEVER,
00190 APR_KILL_ALWAYS,
00191 APR_KILL_AFTER_TIMEOUT,
00192 APR_JUST_WAIT,
00193 APR_KILL_ONLY_ONCE
00194 } apr_kill_conditions_e;
00195
00196
00197
00198 #if APR_HAS_THREADS
00199
00205 APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new_attr,
00206 apr_pool_t *cont);
00207
00213 APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr,
00214 apr_int32_t on);
00215
00220 APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr);
00221
00227 APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
00228 apr_size_t stacksize);
00239 APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
00240 apr_size_t guardsize);
00249 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread,
00250 apr_threadattr_t *attr,
00251 apr_thread_start_t func,
00252 void *data, apr_pool_t *cont);
00253
00259 APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
00260 apr_status_t retval);
00261
00267 APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
00268 apr_thread_t *thd);
00269
00273 APR_DECLARE(void) apr_thread_yield(void);
00274
00281 APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
00282 apr_pool_t *p);
00283
00293 APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
00294 void (*func)(void));
00295
00300 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd);
00301
00308 APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
00309 apr_thread_t *thread);
00310
00318 APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
00319 apr_status_t (*cleanup) (void *),
00320 apr_thread_t *thread);
00321
00328 APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
00329 void (*dest)(void *),
00330 apr_pool_t *cont);
00331
00337 APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new_mem,
00338 apr_threadkey_t *key);
00339
00345 APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv,
00346 apr_threadkey_t *key);
00347
00352 APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key);
00353
00360 APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
00361 apr_threadkey_t *threadkey);
00362
00370 APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
00371 apr_status_t (*cleanup) (void *),
00372 apr_threadkey_t *threadkey);
00373
00374 #endif
00375
00381 APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new_attr,
00382 apr_pool_t *cont);
00383
00392 APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
00393 apr_int32_t in, apr_int32_t out,
00394 apr_int32_t err);
00395
00408 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(struct apr_procattr_t *attr,
00409 apr_file_t *child_in,
00410 apr_file_t *parent_in);
00411
00422 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(struct apr_procattr_t *attr,
00423 apr_file_t *child_out,
00424 apr_file_t *parent_out);
00425
00436 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(struct apr_procattr_t *attr,
00437 apr_file_t *child_err,
00438 apr_file_t *parent_err);
00439
00447 APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
00448 const char *dir);
00449
00461 APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
00462 apr_cmdtype_e cmd);
00463
00469 APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
00470 apr_int32_t detach);
00471
00472 #if APR_HAVE_STRUCT_RLIMIT
00485 APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr,
00486 apr_int32_t what,
00487 struct rlimit *limit);
00488 #endif
00489
00501 APR_DECLARE(apr_status_t) apr_procattr_child_errfn_set(apr_procattr_t *attr,
00502 apr_child_errfn_t *errfn);
00503
00516 APR_DECLARE(apr_status_t) apr_procattr_error_check_set(apr_procattr_t *attr,
00517 apr_int32_t chk);
00518
00519 #if APR_HAS_FORK
00526 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont);
00527 #endif
00528
00543 APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new_proc,
00544 const char *progname,
00545 const char * const *args,
00546 const char * const *env,
00547 apr_procattr_t *attr,
00548 apr_pool_t *cont);
00549
00576 APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
00577 int *exitcode, apr_exit_why_e *exitwhy,
00578 apr_wait_how_e waithow);
00579
00606 APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
00607 int *exitcode,
00608 apr_exit_why_e *exitwhy,
00609 apr_wait_how_e waithow,
00610 apr_pool_t *p);
00611
00612 #define APR_PROC_DETACH_FOREGROUND 0
00613 #define APR_PROC_DETACH_DAEMONIZE 1
00621 APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize);
00622
00640 APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc,
00641 void (*maintenance) (int reason,
00642 void *,
00643 int status),
00644 void *data, apr_file_t *write_fd,
00645 apr_pool_t *p);
00646
00656 APR_DECLARE(void) apr_proc_other_child_unregister(void *data);
00657
00678 APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc,
00679 int reason,
00680 int status);
00681
00689 APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
00690 int reason);
00691
00698 APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason);
00699
00706 APR_DECLARE(void) apr_proc_other_child_check(void);
00707
00711 APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *proc, int status);
00712
00713
00719 APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int sig);
00720
00734 APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *proc,
00735 apr_kill_conditions_e how);
00736
00737 #if APR_HAS_THREADS
00738
00739 #if (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2)
00740
00745 APR_DECLARE(apr_status_t) apr_setup_signal_thread(void);
00746
00754 APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum));
00755
00756 #endif
00757
00762 APR_POOL_DECLARE_ACCESSOR(thread);
00763
00764 #endif
00765
00768 #ifdef __cplusplus
00769 }
00770 #endif
00771
00772 #endif
00773