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_cmdtype_e;
00050
00051 typedef enum {
00052 APR_WAIT,
00053 APR_NOWAIT
00054 } apr_wait_how_e;
00055
00056
00057
00058
00059
00060
00061 typedef enum {
00062 APR_PROC_EXIT = 1,
00063 APR_PROC_SIGNAL = 2,
00064 APR_PROC_SIGNAL_CORE = 4
00065 } apr_exit_why_e;
00066
00068 #define APR_PROC_CHECK_EXIT(x) (x & APR_PROC_EXIT)
00069
00070 #define APR_PROC_CHECK_SIGNALED(x) (x & APR_PROC_SIGNAL)
00071
00072 #define APR_PROC_CHECK_CORE_DUMP(x) (x & APR_PROC_SIGNAL_CORE)
00073
00075 #define APR_NO_PIPE 0
00076
00078 #define APR_FULL_BLOCK 1
00079
00080 #define APR_FULL_NONBLOCK 2
00081
00082 #define APR_PARENT_BLOCK 3
00083
00084 #define APR_CHILD_BLOCK 4
00085
00087 #define APR_LIMIT_CPU 0
00088
00089 #define APR_LIMIT_MEM 1
00090
00091 #define APR_LIMIT_NPROC 2
00092
00093 #define APR_LIMIT_NOFILE 3
00094
00099 #define APR_OC_REASON_DEATH 0
00101 #define APR_OC_REASON_UNWRITABLE 1
00102 #define APR_OC_REASON_RESTART 2
00106 #define APR_OC_REASON_UNREGISTER 3
00109 #define APR_OC_REASON_LOST 4
00111 #define APR_OC_REASON_RUNNING 5
00118 typedef struct apr_proc_t {
00119
00120 pid_t pid;
00122 apr_file_t *in;
00124 apr_file_t *out;
00126 apr_file_t *err;
00127 #if APR_HAS_PROC_INVOKED || defined(DOXYGEN)
00128
00135 char *invoked;
00136 #endif
00137 #if defined(WIN32) || defined(DOXYGEN)
00138
00144 HANDLE hproc;
00145 #endif
00146 } apr_proc_t;
00147
00158 typedef void (apr_child_errfn_t)(apr_pool_t *proc, apr_status_t err,
00159 const char *description);
00160
00162 typedef struct apr_thread_t apr_thread_t;
00163
00165 typedef struct apr_threadattr_t apr_threadattr_t;
00166
00168 typedef struct apr_procattr_t apr_procattr_t;
00169
00171 typedef struct apr_thread_once_t apr_thread_once_t;
00172
00174 typedef struct apr_threadkey_t apr_threadkey_t;
00175
00177 typedef struct apr_other_child_rec_t apr_other_child_rec_t;
00178
00182 typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_t*, void*);
00183
00184 typedef enum {
00185 APR_KILL_NEVER,
00186 APR_KILL_ALWAYS,
00187 APR_KILL_AFTER_TIMEOUT,
00188 APR_JUST_WAIT,
00189 APR_KILL_ONLY_ONCE
00190 } apr_kill_conditions_e;
00191
00192
00193
00194 #if APR_HAS_THREADS
00195
00201 APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new_attr,
00202 apr_pool_t *cont);
00203
00209 APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr,
00210 apr_int32_t on);
00211
00216 APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr);
00217
00226 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread,
00227 apr_threadattr_t *attr,
00228 apr_thread_start_t func,
00229 void *data, apr_pool_t *cont);
00230
00236 APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd,
00237 apr_status_t retval);
00238
00244 APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval,
00245 apr_thread_t *thd);
00246
00250 APR_DECLARE(void) apr_thread_yield(void);
00251
00258 APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
00259 apr_pool_t *p);
00260
00270 APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
00271 void (*func)(void));
00272
00277 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd);
00278
00285 APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
00286 apr_thread_t *thread);
00287
00295 APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
00296 apr_status_t (*cleanup) (void *),
00297 apr_thread_t *thread);
00298
00305 APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key,
00306 void (*dest)(void *),
00307 apr_pool_t *cont);
00308
00314 APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new_mem,
00315 apr_threadkey_t *key);
00316
00322 APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv,
00323 apr_threadkey_t *key);
00324
00329 APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key);
00330
00337 APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
00338 apr_threadkey_t *threadkey);
00339
00347 APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
00348 apr_status_t (*cleanup) (void *),
00349 apr_threadkey_t *threadkey);
00350
00351 #endif
00352
00358 APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new_attr,
00359 apr_pool_t *cont);
00360
00369 APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
00370 apr_int32_t in, apr_int32_t out,
00371 apr_int32_t err);
00372
00385 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(struct apr_procattr_t *attr,
00386 apr_file_t *child_in,
00387 apr_file_t *parent_in);
00388
00399 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(struct apr_procattr_t *attr,
00400 apr_file_t *child_out,
00401 apr_file_t *parent_out);
00402
00413 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(struct apr_procattr_t *attr,
00414 apr_file_t *child_err,
00415 apr_file_t *parent_err);
00416
00424 APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
00425 const char *dir);
00426
00438 APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
00439 apr_cmdtype_e cmd);
00440
00446 APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr,
00447 apr_int32_t detach);
00448
00449 #if APR_HAVE_STRUCT_RLIMIT
00450
00462 APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr,
00463 apr_int32_t what,
00464 struct rlimit *limit);
00465 #endif
00466
00478 APR_DECLARE(apr_status_t) apr_procattr_child_errfn_set(apr_procattr_t *attr,
00479 apr_child_errfn_t *errfn);
00480
00493 APR_DECLARE(apr_status_t) apr_procattr_error_check_set(apr_procattr_t *attr,
00494 apr_int32_t chk);
00495
00496 #if APR_HAS_FORK
00497
00503 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont);
00504 #endif
00505
00520 APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new_proc,
00521 const char *progname,
00522 const char * const *args,
00523 const char * const *env,
00524 apr_procattr_t *attr,
00525 apr_pool_t *cont);
00526
00553 APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
00554 int *exitcode, apr_exit_why_e *exitwhy,
00555 apr_wait_how_e waithow);
00556
00583 APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
00584 int *exitcode,
00585 apr_exit_why_e *exitwhy,
00586 apr_wait_how_e waithow,
00587 apr_pool_t *p);
00588
00589 #define APR_PROC_DETACH_FOREGROUND 0
00590 #define APR_PROC_DETACH_DAEMONIZE 1
00598 APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize);
00599
00617 APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc,
00618 void (*maintenance) (int reason,
00619 void *,
00620 int status),
00621 void *data, apr_file_t *write_fd,
00622 apr_pool_t *p);
00623
00633 APR_DECLARE(void) apr_proc_other_child_unregister(void *data);
00634
00655 APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc,
00656 int reason,
00657 int status);
00658
00666 APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
00667 int reason);
00668
00675 APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason);
00676
00683 APR_DECLARE(void) apr_proc_other_child_check(void);
00684
00688 APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *proc, int status);
00689
00690
00696 APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int sig);
00697
00711 APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *proc,
00712 apr_kill_conditions_e how);
00713
00714 #if APR_HAS_THREADS
00715
00716 #if (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2)
00717
00722 APR_DECLARE(apr_status_t) apr_setup_signal_thread(void);
00723
00731 APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum));
00732
00733 #endif
00734
00739 APR_POOL_DECLARE_ACCESSOR(thread);
00740
00741 #endif
00742
00745 #ifdef __cplusplus
00746 }
00747 #endif
00748
00749 #endif
00750