GME  13
apr_thread_proc.h
Go to the documentation of this file.
00001 /* Licensed to the Apache Software Foundation (ASF) under one or more
00002  * contributor license agreements.  See the NOTICE file distributed with
00003  * this work for additional information regarding copyright ownership.
00004  * The ASF licenses this file to You under the Apache License, Version 2.0
00005  * (the "License"); you may not use this file except in compliance with
00006  * the License.  You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
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 /* __cplusplus */
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 /* I am specifically calling out the values so that the macros below make
00061  * more sense.  Yes, I know I don't need to, but I am hoping this makes what
00062  * I am doing more clear.  If you want to add more reasons to exit, continue
00063  * to use bitmasks.
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 
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 
00089 #define APR_NO_FILE          8
00090 
00092 #define APR_READ_BLOCK       3
00093 
00094 #define APR_WRITE_BLOCK      4
00095 
00099 #define APR_NO_FILE          8
00100 
00102 #define APR_LIMIT_CPU        0
00103 
00104 #define APR_LIMIT_MEM        1
00105 
00106 #define APR_LIMIT_NPROC      2
00107 
00108 #define APR_LIMIT_NOFILE     3
00109 
00114 #define APR_OC_REASON_DEATH         0     
00116 #define APR_OC_REASON_UNWRITABLE    1     
00117 #define APR_OC_REASON_RESTART       2     
00121 #define APR_OC_REASON_UNREGISTER    3     
00124 #define APR_OC_REASON_LOST          4     
00126 #define APR_OC_REASON_RUNNING       5     
00133 typedef struct apr_proc_t {
00134 
00135     pid_t pid;
00137     apr_file_t *in;
00139     apr_file_t *out;
00141     apr_file_t *err;
00142 #if APR_HAS_PROC_INVOKED || defined(DOXYGEN)
00143 
00150     char *invoked;
00151 #endif
00152 #if defined(WIN32) || defined(DOXYGEN)
00153 
00159     HANDLE hproc;
00160 #endif
00161 } apr_proc_t;
00162 
00173 typedef void (apr_child_errfn_t)(apr_pool_t *proc, apr_status_t err,
00174                                  const char *description);
00175 
00177 typedef struct apr_thread_t           apr_thread_t;
00178 
00180 typedef struct apr_threadattr_t       apr_threadattr_t;
00181 
00183 typedef struct apr_procattr_t         apr_procattr_t;
00184 
00186 typedef struct apr_thread_once_t      apr_thread_once_t;
00187 
00189 typedef struct apr_threadkey_t        apr_threadkey_t;
00190 
00192 typedef struct apr_other_child_rec_t  apr_other_child_rec_t;
00193 
00197 typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_t*, void*);
00198 
00199 typedef enum {
00200     APR_KILL_NEVER,             
00201     APR_KILL_ALWAYS,            
00202     APR_KILL_AFTER_TIMEOUT,     
00203     APR_JUST_WAIT,              
00204     APR_KILL_ONLY_ONCE          
00205 } apr_kill_conditions_e;
00206 
00207 /* Thread Function definitions */
00208 
00209 #if APR_HAS_THREADS
00210 
00216 APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new_attr, 
00217                                                 apr_pool_t *cont);
00218 
00224 APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr, 
00225                                                     apr_int32_t on);
00226 
00233 APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr);
00234 
00240 APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
00241                                                        apr_size_t stacksize);
00242 
00253 APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
00254                                                        apr_size_t guardsize);
00255 
00264 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread, 
00265                                             apr_threadattr_t *attr, 
00266                                             apr_thread_start_t func, 
00267                                             void *data, apr_pool_t *cont);
00268 
00274 APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, 
00275                                           apr_status_t retval);
00276 
00282 APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, 
00283                                           apr_thread_t *thd); 
00284 
00288 APR_DECLARE(void) apr_thread_yield(void);
00289 
00296 APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
00297                                                apr_pool_t *p);
00298 
00308 APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
00309                                           void (*func)(void));
00310 
00315 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd);
00316 
00323 APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
00324                                              apr_thread_t *thread);
00325 
00333 APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
00334                                              apr_status_t (*cleanup) (void *),
00335                                              apr_thread_t *thread);
00336 
00343 APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key, 
00344                                                     void (*dest)(void *),
00345                                                     apr_pool_t *cont);
00346 
00352 APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new_mem, 
00353                                                  apr_threadkey_t *key);
00354 
00360 APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv, 
00361                                                  apr_threadkey_t *key);
00362 
00367 APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key);
00368 
00375 APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
00376                                                 apr_threadkey_t *threadkey);
00377 
00385 APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
00386                                                 apr_status_t (*cleanup) (void *),
00387                                                 apr_threadkey_t *threadkey);
00388 
00389 #endif
00390 
00396 APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new_attr,
00397                                                   apr_pool_t *cont);
00398 
00413 APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, 
00414                                              apr_int32_t in, apr_int32_t out,
00415                                              apr_int32_t err);
00416 
00432 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(struct apr_procattr_t *attr,
00433                                                   apr_file_t *child_in,
00434                                                   apr_file_t *parent_in);
00435 
00449 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(struct apr_procattr_t *attr,
00450                                                    apr_file_t *child_out,
00451                                                    apr_file_t *parent_out);
00452 
00466 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(struct apr_procattr_t *attr,
00467                                                    apr_file_t *child_err,
00468                                                    apr_file_t *parent_err);
00469 
00477 APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr, 
00478                                               const char *dir);
00479 
00491 APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
00492                                                   apr_cmdtype_e cmd);
00493 
00499 APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, 
00500                                                  apr_int32_t detach);
00501 
00502 #if APR_HAVE_STRUCT_RLIMIT
00503 
00515 APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, 
00516                                                 apr_int32_t what,
00517                                                 struct rlimit *limit);
00518 #endif
00519 
00531 APR_DECLARE(apr_status_t) apr_procattr_child_errfn_set(apr_procattr_t *attr,
00532                                                        apr_child_errfn_t *errfn);
00533 
00546 APR_DECLARE(apr_status_t) apr_procattr_error_check_set(apr_procattr_t *attr,
00547                                                        apr_int32_t chk);
00548 
00556 APR_DECLARE(apr_status_t) apr_procattr_addrspace_set(apr_procattr_t *attr,
00557                                                        apr_int32_t addrspace);
00558 
00567 APR_DECLARE(apr_status_t) apr_procattr_user_set(apr_procattr_t *attr,
00568                                                 const char *username,
00569                                                 const char *password);
00570 
00576 APR_DECLARE(apr_status_t) apr_procattr_group_set(apr_procattr_t *attr,
00577                                                  const char *groupname);
00578 
00579 
00580 #if APR_HAS_FORK
00581 
00589 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont);
00590 #endif
00591 
00608 APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new_proc,
00609                                           const char *progname,
00610                                           const char * const *args,
00611                                           const char * const *env, 
00612                                           apr_procattr_t *attr, 
00613                                           apr_pool_t *pool);
00614 
00641 APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
00642                                         int *exitcode, apr_exit_why_e *exitwhy,
00643                                         apr_wait_how_e waithow);
00644 
00671 APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
00672                                                   int *exitcode,
00673                                                   apr_exit_why_e *exitwhy,
00674                                                   apr_wait_how_e waithow,
00675                                                   apr_pool_t *p);
00676 
00677 #define APR_PROC_DETACH_FOREGROUND 0    
00678 #define APR_PROC_DETACH_DAEMONIZE 1     
00686 APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize);
00687 
00705 APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc, 
00706                                            void (*maintenance) (int reason, 
00707                                                                 void *, 
00708                                                                 int status),
00709                                            void *data, apr_file_t *write_fd,
00710                                            apr_pool_t *p);
00711 
00721 APR_DECLARE(void) apr_proc_other_child_unregister(void *data);
00722 
00743 APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc, 
00744                                                      int reason,
00745                                                      int status);
00746 
00754 APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
00755                                                int reason);
00756 
00763 APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason);
00764 
00770 APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int sig);
00771 
00785 APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *proc,
00786                                            apr_kill_conditions_e how);
00787 
00788 #if APR_HAS_THREADS 
00789 
00790 #if (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2)
00791 
00796 APR_DECLARE(apr_status_t) apr_setup_signal_thread(void);
00797 
00805 APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum));
00806 
00807 #endif /* (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2) */
00808 
00813 APR_POOL_DECLARE_ACCESSOR(thread);
00814 
00815 #endif /* APR_HAS_THREADS */
00816 
00819 #ifdef __cplusplus
00820 }
00821 #endif
00822 
00823 #endif  /* ! APR_THREAD_PROC_H */
00824