1 #ifndef WSGI_DAEMON_H 2 #define WSGI_DAEMON_H 3 4 /* ------------------------------------------------------------------------- */ 5 6 /* 7 * Copyright 2007-2019 GRAHAM DUMPLETON 8 * 9 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * you may not use this file except in compliance with the License. 11 * You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 /* ------------------------------------------------------------------------- */ 23 24 #include "wsgi_python.h" 25 #include "wsgi_apache.h" 26 27 /* ------------------------------------------------------------------------- */ 28 29 #ifndef WIN32 30 #if APR_HAS_OTHER_CHILD && APR_HAS_THREADS && APR_HAS_FORK 31 #define MOD_WSGI_WITH_DAEMONS 1 32 #endif 33 #endif 34 35 /* 36 * Apache 2.X and UNIX specific definitions related to 37 * distinct daemon processes. 38 */ 39 40 #if defined(MOD_WSGI_WITH_DAEMONS) 41 42 #include "unixd.h" 43 #include "scoreboard.h" 44 #include "mpm_common.h" 45 #include "apr_proc_mutex.h" 46 #include "apr_thread_cond.h" 47 #include "apr_atomic.h" 48 #include "http_connection.h" 49 #include "apr_poll.h" 50 #include "apr_signal.h" 51 #include "http_vhost.h" 52 53 #if APR_MAJOR_VERSION < 2 54 #include "apr_support.h" 55 #endif 56 57 #if APR_MAJOR_VERSION < 1 58 #define apr_atomic_cas32 apr_atomic_cas 59 #endif 60 61 #if APR_HAVE_SYS_SOCKET_H 62 #include <sys/socket.h> 63 #endif 64 #if APR_HAVE_UNISTD_H 65 #include <unistd.h> 66 #endif 67 #if APR_HAVE_SYS_TYPES_H 68 #include <sys/types.h> 69 #endif 70 #ifdef HAVE_SYS_SEM_H 71 #include <sys/sem.h> 72 #endif 73 74 #include <locale.h> 75 #include <sys/un.h> 76 77 #ifndef WSGI_LISTEN_BACKLOG 78 #define WSGI_LISTEN_BACKLOG 100 79 #endif 80 81 #define WSGI_STACK_HEAD 0xffff 82 #define WSGI_STACK_LAST 0xffff 83 #define WSGI_STACK_TERMINATED 0x10000 84 #define WSGI_STACK_NO_LISTENER 0x20000 85 86 typedef struct { 87 server_rec *server; 88 long random; 89 int id; 90 const char *name; 91 const char *user; 92 uid_t uid; 93 const char *group; 94 gid_t gid; 95 const char *groups_list; 96 int groups_count; 97 gid_t *groups; 98 int processes; 99 int multiprocess; 100 int threads; 101 long umask; 102 const char *root; 103 const char *home; 104 const char *lang; 105 const char *locale; 106 const char *python_home; 107 const char *python_path; 108 const char *python_eggs; 109 int stack_size; 110 int maximum_requests; 111 int shutdown_timeout; 112 apr_time_t startup_timeout; 113 apr_time_t deadlock_timeout; 114 apr_time_t inactivity_timeout; 115 apr_time_t request_timeout; 116 apr_time_t graceful_timeout; 117 apr_time_t eviction_timeout; 118 apr_time_t restart_interval; 119 apr_time_t connect_timeout; 120 apr_time_t socket_timeout; 121 apr_time_t queue_timeout; 122 const char *socket_user; 123 int listen_backlog; 124 const char *display_name; 125 int send_buffer_size; 126 int recv_buffer_size; 127 int header_buffer_size; 128 int response_buffer_size; 129 apr_time_t response_socket_timeout; 130 const char *script_user; 131 const char *script_group; 132 int cpu_time_limit; 133 int cpu_priority; 134 rlim_t memory_limit; 135 rlim_t virtual_memory_limit; 136 const char *socket_path; 137 int socket_rotation; 138 int listener_fd; 139 const char* mutex_path; 140 apr_proc_mutex_t* mutex; 141 int server_metrics; 142 const char *newrelic_config_file; 143 const char *newrelic_environment; 144 } WSGIProcessGroup; 145 146 typedef struct { 147 WSGIProcessGroup *group; 148 int instance; 149 apr_proc_t process; 150 apr_socket_t *listener; 151 } WSGIDaemonProcess; 152 153 typedef struct { 154 int id; 155 WSGIDaemonProcess *process; 156 apr_thread_t *thread; 157 int running; 158 int next; 159 int wakeup; 160 apr_thread_cond_t *condition; 161 apr_thread_mutex_t *mutex; 162 apr_time_t request; 163 } WSGIDaemonThread; 164 165 typedef struct { 166 apr_uint32_t state; 167 } WSGIThreadStack; 168 169 typedef struct { 170 const char *name; 171 const char *socket_path; 172 apr_time_t connect_timeout; 173 apr_time_t socket_timeout; 174 apr_socket_t *socket; 175 } WSGIDaemonSocket; 176 177 extern int wsgi_daemon_count; 178 extern apr_hash_t *wsgi_daemon_index; 179 extern apr_hash_t *wsgi_daemon_listeners; 180 181 extern WSGIDaemonProcess *wsgi_daemon_process; 182 183 extern int volatile wsgi_request_count; 184 185 extern WSGIDaemonThread *wsgi_worker_threads; 186 187 extern WSGIThreadStack *wsgi_worker_stack; 188 189 extern int volatile wsgi_daemon_shutdown; 190 191 #endif 192 193 /* ------------------------------------------------------------------------- */ 194 195 #endif 196 197 /* vi: set sw=4 expandtab : */ 198