webroar 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +48 -1
- data/README +11 -14
- data/Rakefile +1 -1
- data/conf/mime_type.yml +172 -166
- data/conf/server_internal_config.yml +30 -8
- data/doc/user-guide.html +294 -153
- data/doc/user-guide.txt +9 -13
- data/lib/command_runner.rb +1 -0
- data/lib/dependencies.rb +18 -15
- data/lib/installer.rb +115 -50
- data/src/admin_panel/app/controllers/admin_controller.rb +1 -15
- data/src/admin_panel/app/controllers/application_controller.rb +2 -2
- data/src/admin_panel/app/controllers/application_specification_controller.rb +2 -1
- data/src/admin_panel/app/controllers/headers_controller.rb +73 -0
- data/src/admin_panel/app/controllers/mail_specification_controller.rb +10 -0
- data/src/admin_panel/app/controllers/server_specification_controller.rb +14 -0
- data/src/admin_panel/app/helpers/admin_helper.rb +0 -85
- data/src/admin_panel/app/models/app.rb +1 -1
- data/src/admin_panel/app/models/application_specification.rb +33 -25
- data/src/admin_panel/app/models/headers.rb +116 -0
- data/src/admin_panel/app/models/mail_specification.rb +20 -5
- data/src/admin_panel/app/models/server_specification.rb +2 -7
- data/src/admin_panel/app/views/admin/configuration.html.erb +10 -5
- data/src/admin_panel/app/views/exceptions/_exception_list_partial.html.erb +4 -4
- data/src/admin_panel/app/views/graph/_graph_page.html.erb +3 -0
- data/src/admin_panel/app/views/headers/_add_expires_text_box.html.erb +35 -0
- data/src/admin_panel/app/views/headers/_expires_by_type_form.html.erb +65 -0
- data/src/admin_panel/app/views/headers/_headers_table.html.erb +113 -0
- data/src/admin_panel/app/views/mail_specification/_current_spec.html.erb +168 -0
- data/src/admin_panel/app/views/{admin → server_specification}/_add_div.html.erb +1 -1
- data/src/admin_panel/config/initializers/application_constants.rb +6 -0
- data/src/admin_panel/lib/control.rb +6 -3
- data/src/admin_panel/lib/scgi.rb +74 -21
- data/src/admin_panel/lib/yaml_writer.rb +51 -17
- data/src/admin_panel/public/javascripts/application.js +20 -1
- data/src/head/wr_access_log.c +2 -2
- data/src/head/wr_application.c +294 -236
- data/src/head/wr_application.h +8 -8
- data/src/head/wr_configurator.c +451 -517
- data/src/head/wr_configurator.h +10 -115
- data/src/head/wr_connection.c +26 -25
- data/src/head/wr_connection.h +2 -3
- data/src/head/wr_controller.c +110 -93
- data/src/head/wr_controller.h +6 -6
- data/src/head/wr_main.c +31 -24
- data/src/head/wr_request.c +70 -93
- data/src/head/wr_request.h +0 -4
- data/src/head/wr_resolver.c +21 -15
- data/src/head/wr_resolver.h +2 -2
- data/src/head/wr_server.c +36 -26
- data/src/head/wr_server.h +5 -5
- data/src/head/wr_worker.c +551 -512
- data/src/head/wr_worker.h +33 -20
- data/src/helper/wr_config.c +316 -0
- data/src/helper/wr_config.h +235 -0
- data/src/helper/wr_helper.h +1 -5
- data/src/helper/wr_logger.c +4 -4
- data/src/helper/wr_scgi.c +3 -4
- data/src/helper/wr_scgi.h +2 -0
- data/src/helper/wr_string.h +2 -2
- data/src/helper/wr_util.c +3 -1
- data/src/helper/wr_util.h +0 -0
- data/src/helper/wr_yaml_parser.c +30 -0
- data/src/helper/wr_yaml_parser.h +1 -0
- data/src/ruby_lib/exception_tracker/instrumentation/action_controller.rb +2 -1
- data/src/ruby_lib/mailer/smtpmail.rb +7 -4
- data/src/ruby_lib/profiler/instrumentation/action_controller.rb +2 -1
- data/src/ruby_lib/profiler/instrumentation/active_record.rb +3 -0
- data/src/ruby_lib/rack/adapter/rails.rb +14 -7
- data/src/ruby_lib/ruby_interface/client.rb +1 -1
- data/src/ruby_lib/ruby_interface/version.rb +2 -2
- data/src/ruby_lib/webroar_app_loader.rb +4 -2
- data/src/worker/wkr_controller.c +200 -140
- data/src/worker/wkr_http.c +14 -28
- data/src/worker/wkr_http.h +4 -4
- data/src/worker/wkr_http_request.c +12 -11
- data/src/worker/wkr_http_request.h +7 -8
- data/src/worker/wkr_http_response.c +10 -14
- data/src/worker/wkr_http_response.h +0 -1
- data/src/worker/wkr_main.c +74 -140
- data/src/worker/wkr_static.c +295 -108
- data/src/worker/wkr_static.h +20 -7
- data/src/worker/worker.c +245 -70
- data/src/worker/worker.h +46 -34
- data/tasks/compile.rake +128 -175
- data/tasks/test.rake +345 -469
- data/test/spec/webroar_command_spec.rb +23 -0
- metadata +173 -43
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/README +0 -34
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/Rakefile +0 -13
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/init.rb +0 -5
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/lib/action_mailer_tls.rb +0 -16
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/lib/smtp_tls.rb +0 -123
- data/src/admin_panel/vendor/plugins/action_mailer_optional_tls/test/tls_test.rb +0 -42
- data/src/head/wr_config.h +0 -165
- data/src/ruby_lib/mailer/action_mailer_tls.rb +0 -16
- data/src/ruby_lib/mailer/smtp_tls.rb +0 -123
data/src/worker/wkr_static.h
CHANGED
|
@@ -19,7 +19,13 @@
|
|
|
19
19
|
#ifndef WKR_STATIC_H_
|
|
20
20
|
#define WKR_STATIC_H_
|
|
21
21
|
|
|
22
|
-
#include <
|
|
22
|
+
#include <wkr_http_response.h>
|
|
23
|
+
#if defined(W_ZLIB) && defined(W_REGEX)
|
|
24
|
+
#include <regex.h>
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
#define MAP_SIZE 36
|
|
28
|
+
#define DEFAULT_CONTENT_TYPE "javascript|css|xml|text"
|
|
23
29
|
|
|
24
30
|
typedef struct static_file_s{
|
|
25
31
|
char ext[10];
|
|
@@ -28,13 +34,20 @@ typedef struct static_file_s{
|
|
|
28
34
|
struct static_file_s *next;
|
|
29
35
|
}static_file_t;
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
typedef struct static_server_s{
|
|
38
|
+
struct stat buf;
|
|
39
|
+
const char *path, *encoding, *user_agent, *modify;
|
|
40
|
+
wr_buffer_t *buffer; // Buffer to
|
|
41
|
+
static_file_t *map[MAP_SIZE + 1];
|
|
42
|
+
#if defined(W_ZLIB) && defined(W_REGEX)
|
|
43
|
+
regex_t *r_user_agent, *r_content_type;
|
|
44
|
+
#endif
|
|
45
|
+
}static_server_t;
|
|
33
46
|
|
|
34
|
-
|
|
35
|
-
void
|
|
47
|
+
static_server_t * static_server_new(void *worker);
|
|
48
|
+
void static_server_free(static_server_t *stat);
|
|
36
49
|
|
|
37
50
|
/* Serve the static file content */
|
|
38
|
-
void static_file_process(
|
|
51
|
+
void static_file_process(void *http);
|
|
39
52
|
|
|
40
|
-
#endif /*WKR_STATIC_H_*/
|
|
53
|
+
#endif /*WKR_STATIC_H_*/
|
data/src/worker/worker.c
CHANGED
|
@@ -33,6 +33,15 @@
|
|
|
33
33
|
#include <netinet/in.h>
|
|
34
34
|
#include <sys/un.h>
|
|
35
35
|
#include <ev.c>
|
|
36
|
+
#include <pwd.h>
|
|
37
|
+
|
|
38
|
+
#ifdef __linux__
|
|
39
|
+
#include <sys/prctl.h>
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
extern config_t *Config;
|
|
43
|
+
|
|
44
|
+
void load_application(wkr_t* w);
|
|
36
45
|
|
|
37
46
|
wkr_tmp_t* wkr_tmp_new() {
|
|
38
47
|
LOG_FUNCTION
|
|
@@ -46,23 +55,23 @@ wkr_tmp_t* wkr_tmp_new() {
|
|
|
46
55
|
wr_string_null(tmp->type);
|
|
47
56
|
wr_string_null(tmp->name);
|
|
48
57
|
wr_string_null(tmp->resolver);
|
|
49
|
-
wr_string_null(tmp->ruby_path);
|
|
50
|
-
wr_string_null(tmp->script_path);
|
|
51
58
|
wr_string_null(tmp->root_path);
|
|
52
59
|
wr_string_null(tmp->ctl_path);
|
|
53
60
|
wr_string_null(tmp->log_file);
|
|
54
61
|
|
|
55
|
-
// tmp->path = tmp->env = tmp->type = tmp->name =
|
|
56
|
-
// tmp->resolver = tmp->ruby_path = tmp->script_path =
|
|
57
|
-
// tmp->root_path = tmp->ctl_path = tmp->log_file = NULL;
|
|
58
|
-
|
|
59
62
|
tmp->profiler = 'n';
|
|
60
63
|
tmp->gid = tmp->uid = 0;
|
|
61
64
|
// HTTP1.1 assumes persistent connection by default
|
|
62
65
|
tmp->keep_alive = TRUE;
|
|
63
66
|
tmp->is_uds = FALSE;
|
|
64
67
|
tmp->is_static = 0;
|
|
65
|
-
|
|
68
|
+
#ifdef W_ZLIB
|
|
69
|
+
tmp->lower_limit = tmp->upper_limit = 0;
|
|
70
|
+
#ifdef W_REGEX
|
|
71
|
+
wr_string_null(tmp->r_user_agent);
|
|
72
|
+
wr_string_null(tmp->r_content_type);
|
|
73
|
+
#endif
|
|
74
|
+
#endif
|
|
66
75
|
return tmp;
|
|
67
76
|
}
|
|
68
77
|
|
|
@@ -75,23 +84,13 @@ void wkr_tmp_free(wkr_tmp_t** t) {
|
|
|
75
84
|
wr_string_free(tmp->type);
|
|
76
85
|
wr_string_free(tmp->name);
|
|
77
86
|
wr_string_free(tmp->resolver);
|
|
78
|
-
wr_string_free(tmp->ruby_path);
|
|
79
|
-
wr_string_free(tmp->script_path);
|
|
80
87
|
wr_string_free(tmp->root_path);
|
|
81
88
|
wr_string_free(tmp->ctl_path);
|
|
82
89
|
wr_string_free(tmp->log_file);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// if(tmp->name) free(tmp->name);
|
|
88
|
-
// if(tmp->resolver) free(tmp->resolver);
|
|
89
|
-
// if(tmp->ruby_path) free(tmp->ruby_path);
|
|
90
|
-
// if(tmp->script_path) free(tmp->script_path);
|
|
91
|
-
// if(tmp->root_path) free(tmp->root_path);
|
|
92
|
-
// if(tmp->ctl_path) free(tmp->ctl_path);
|
|
93
|
-
// if(tmp->log_file) free(tmp->log_file);
|
|
94
|
-
|
|
90
|
+
#if defined(W_ZLIB) && defined(W_REGEX)
|
|
91
|
+
wr_string_free(tmp->r_content_type);
|
|
92
|
+
wr_string_free(tmp->r_user_agent);
|
|
93
|
+
#endif
|
|
95
94
|
free(tmp);
|
|
96
95
|
}
|
|
97
96
|
*t = NULL;
|
|
@@ -114,38 +113,25 @@ wkr_t* worker_new(struct ev_loop *loop, wkr_tmp_t *tmp) {
|
|
|
114
113
|
w->tmp = tmp;
|
|
115
114
|
assert(w->tmp!=NULL);
|
|
116
115
|
|
|
117
|
-
w->
|
|
116
|
+
w->env_var = NULL;
|
|
117
|
+
|
|
118
|
+
w->ctl = wkr_ctl_new(w);
|
|
118
119
|
assert(w->ctl!=NULL);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
setsocketoption(w->ctl->fd);
|
|
131
|
-
|
|
132
|
-
memset(&addr, 0, sizeof(addr));
|
|
133
|
-
addr.sun_family = AF_UNIX;
|
|
134
|
-
strcpy(addr.sun_path, tmp->ctl_path.str);
|
|
135
|
-
|
|
136
|
-
int len = sizeof(addr.sun_family)+strlen(addr.sun_path);
|
|
137
|
-
#ifdef __APPLE__
|
|
138
|
-
len ++;
|
|
139
|
-
#endif
|
|
140
|
-
|
|
141
|
-
LOG_DEBUG(DEBUG,"send_ack_on_unix_socket() connecting with socket %s",addr.sun_path);
|
|
142
|
-
if(connect(w->ctl->fd, (struct sockaddr *)&addr, len) < 0) {
|
|
143
|
-
LOG_ERROR(SEVERE,"Connect with controller fd failed: %s",strerror(errno));
|
|
144
|
-
worker_free(&w);
|
|
145
|
-
return NULL;
|
|
146
|
-
}
|
|
120
|
+
if(connect_to_head(w) == FALSE){
|
|
121
|
+
worker_free(&w);
|
|
122
|
+
return NULL;
|
|
123
|
+
}
|
|
124
|
+
start_ctl_watcher(w);
|
|
125
|
+
/* if(w->tmp->is_static){
|
|
126
|
+
w->ctl->scgi = scgi_new();
|
|
127
|
+
load_application(w);
|
|
128
|
+
} else */ if(send_config_req_msg(w) < 0){
|
|
129
|
+
worker_free(&w);
|
|
130
|
+
return NULL;
|
|
147
131
|
}
|
|
148
132
|
|
|
133
|
+
// Connect to head controller UDS socket before user previliges get lowered.
|
|
134
|
+
|
|
149
135
|
return w;
|
|
150
136
|
}
|
|
151
137
|
|
|
@@ -157,7 +143,6 @@ void worker_free(wkr_t **wrk) {
|
|
|
157
143
|
close(w->req_fd);
|
|
158
144
|
if(w->listen_fd > 0)
|
|
159
145
|
close(w->listen_fd);
|
|
160
|
-
// if(w->sock_path){
|
|
161
146
|
if(w->sock_path.str) {
|
|
162
147
|
// Set root privilege to remove socket file.
|
|
163
148
|
// if(setegid(0)!=0){
|
|
@@ -168,8 +153,6 @@ void worker_free(wkr_t **wrk) {
|
|
|
168
153
|
// }
|
|
169
154
|
unlink(w->sock_path.str);
|
|
170
155
|
wr_string_free(w->sock_path);
|
|
171
|
-
// unlink(w->sock_path);
|
|
172
|
-
// free(w->sock_path);
|
|
173
156
|
}
|
|
174
157
|
ev_io_stop(w->loop, &(w->w_accept));
|
|
175
158
|
ev_io_stop(w->loop, &(w->ctl->w_read));
|
|
@@ -180,13 +163,14 @@ void worker_free(wkr_t **wrk) {
|
|
|
180
163
|
if(w->ctl)
|
|
181
164
|
wkr_ctl_free(&w->ctl);
|
|
182
165
|
|
|
166
|
+
wr_string_list_free(w->env_var);
|
|
183
167
|
free(w);
|
|
184
168
|
}
|
|
185
169
|
*wrk=NULL;
|
|
186
170
|
}
|
|
187
171
|
|
|
188
172
|
/** Conenct worker on internet socket */
|
|
189
|
-
|
|
173
|
+
int listen_internet_socket(wkr_t* w) {
|
|
190
174
|
LOG_FUNCTION
|
|
191
175
|
struct sockaddr_in addr;
|
|
192
176
|
if ((w->listen_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
|
|
@@ -223,8 +207,7 @@ static inline int connect_internet_socket(wkr_t* w) {
|
|
|
223
207
|
return 0;
|
|
224
208
|
}
|
|
225
209
|
|
|
226
|
-
|
|
227
|
-
static inline int connect_unix_socket(wkr_t* w) {
|
|
210
|
+
int listen_unix_socket(wkr_t* w) {
|
|
228
211
|
LOG_FUNCTION
|
|
229
212
|
struct sockaddr_un addr;
|
|
230
213
|
|
|
@@ -241,19 +224,14 @@ static inline int connect_unix_socket(wkr_t* w) {
|
|
|
241
224
|
memset(&addr, 0, sizeof(addr));
|
|
242
225
|
/* Preparing socket path unique to this worker*/
|
|
243
226
|
w->sock_path.str = (char*) malloc(sizeof(char)*50);
|
|
244
|
-
w->sock_path.len = sprintf(w->sock_path.str, "%s_%d",
|
|
227
|
+
w->sock_path.len = sprintf(w->sock_path.str, "%s_%d", Config->Worker.sock_path.str, getpid());
|
|
245
228
|
|
|
246
|
-
// w->sock_path = wr_malloc_CHAR(50);
|
|
247
|
-
// sprintf(w->sock_path, "%s_%d",WR_WKR_SOCK_PATH,getpid());
|
|
248
|
-
|
|
249
|
-
// LOG_DEBUG(DEBUG,"connect_unix_socket() socket name is %s",w->sock_path);
|
|
250
229
|
LOG_DEBUG(DEBUG,"connect_unix_socket() socket name is %s",w->sock_path.str);
|
|
251
230
|
|
|
252
231
|
addr.sun_family = AF_UNIX;
|
|
253
232
|
//strcpy(addr.sun_path,w->sock_path);
|
|
254
233
|
strcpy(addr.sun_path,w->sock_path.str);
|
|
255
234
|
unlink(addr.sun_path);
|
|
256
|
-
// LOG_DEBUG(DEBUG,"connect_unix_socket() Binding worker at socket path %s",w->sock_path);
|
|
257
235
|
LOG_DEBUG(DEBUG,"connect_unix_socket() Binding worker at socket path %s",w->sock_path.str);
|
|
258
236
|
|
|
259
237
|
int len = sizeof(addr.sun_family) + strlen(addr.sun_path);
|
|
@@ -277,20 +255,20 @@ static inline int connect_unix_socket(wkr_t* w) {
|
|
|
277
255
|
|
|
278
256
|
|
|
279
257
|
/** Connect worket to Head */
|
|
280
|
-
int
|
|
258
|
+
int worker_listen(wkr_t* w) {
|
|
281
259
|
LOG_FUNCTION
|
|
260
|
+
int retval;
|
|
282
261
|
if(w->is_uds == 1) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if(connect_internet_socket(w) >=0)
|
|
287
|
-
return send_ack_on_internet_socket(w);
|
|
262
|
+
return listen_unix_socket(w);
|
|
263
|
+
}else{
|
|
264
|
+
return listen_internet_socket(w);
|
|
288
265
|
}
|
|
289
|
-
|
|
266
|
+
|
|
267
|
+
// if(retval >= 0 ) return send_ack_ctl_msg(w);
|
|
290
268
|
}
|
|
291
269
|
|
|
292
270
|
/** This function accept connection from Head. */
|
|
293
|
-
|
|
271
|
+
void request_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) {
|
|
294
272
|
LOG_FUNCTION
|
|
295
273
|
wkr_t *w = (wkr_t*) watcher->data;
|
|
296
274
|
|
|
@@ -332,5 +310,202 @@ void worker_accept_requests(wkr_t* w) {
|
|
|
332
310
|
w->w_accept.data = w;
|
|
333
311
|
ev_io_init(&(w->w_accept), request_accept_cb, w->listen_fd, EV_READ);
|
|
334
312
|
ev_io_start(w->loop,&(w->w_accept));
|
|
313
|
+
//wkr_tmp_free(&w->tmp);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
int drop_privileges(wkr_t *w, scgi_t *scgi) {
|
|
317
|
+
char *str;
|
|
318
|
+
|
|
319
|
+
str = (char*) scgi_header_value_get(scgi, "USER");
|
|
320
|
+
|
|
321
|
+
if(str && strlen(str) > 0) {
|
|
322
|
+
struct passwd *user_info=NULL;
|
|
323
|
+
user_info = getpwnam(str);
|
|
324
|
+
// Check for user existence
|
|
325
|
+
if(user_info) {
|
|
326
|
+
w->tmp->uid = user_info->pw_uid;
|
|
327
|
+
w->tmp->gid = user_info->pw_gid;
|
|
328
|
+
} else {
|
|
329
|
+
scgi_body_add(w->ctl->scgi, "Application run_as_user is invalid. Application not started.", strlen("Application run_as_user is invalid. Application not started."));
|
|
330
|
+
LOG_ERROR(SEVERE,"Application run_as_user is invalid. Application not started.");
|
|
331
|
+
return FALSE;
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
scgi_body_add(w->ctl->scgi, "Application run_as_user is missing. Application not started.", strlen("Application run_as_user is missing. Application not started."));
|
|
335
|
+
LOG_ERROR(SEVERE,"Application run_as_user is missing. Application not started.");
|
|
336
|
+
return FALSE;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
change_log_file_owner(w->tmp->uid, w->tmp->gid);
|
|
340
|
+
//setting read, effective, saved group and user id
|
|
341
|
+
if(setgid(w->tmp->gid)!=0) {
|
|
342
|
+
scgi_body_add(w->ctl->scgi, "setegid() failed", strlen("setegid() failed"));
|
|
343
|
+
LOG_ERROR(SEVERE,"setegid() failed");
|
|
344
|
+
return FALSE;
|
|
345
|
+
}
|
|
346
|
+
if(setuid(w->tmp->uid)!=0) {
|
|
347
|
+
scgi_body_add(w->ctl->scgi, "seteuid() failed", strlen("seteuid() failed"));
|
|
348
|
+
LOG_ERROR(SEVERE,"seteuid() failed");
|
|
349
|
+
return FALSE;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
LOG_DEBUG(DEBUG,"Passed userid=%d and groupid=%d",
|
|
353
|
+
w->tmp->uid, w->tmp->gid);
|
|
354
|
+
LOG_DEBUG(DEBUG,"effective userid=%d and groupid=%d",geteuid(),getegid());
|
|
355
|
+
#ifdef __linux__
|
|
356
|
+
int rv = prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
|
|
357
|
+
LOG_DEBUG(DEBUG,"prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) = %d", rv);
|
|
358
|
+
if (rv < 0) {
|
|
359
|
+
LOG_ERROR(SEVERE,"error setting prctl(PR_SET_DUMPABLE, 1, 0, 0, 0), errno = %d, desc = %s", errno, strerror(errno));
|
|
360
|
+
}
|
|
361
|
+
#endif
|
|
362
|
+
return TRUE;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
void manipulate_environment_variable(wkr_t* w, scgi_t *scgi) {
|
|
366
|
+
LOG_FUNCTION
|
|
367
|
+
char *var, *str;
|
|
368
|
+
int rv = 0;
|
|
369
|
+
|
|
370
|
+
str = (char*) scgi_header_value_get(scgi, "ENV_VAR");
|
|
371
|
+
w->env_var = wr_string_list_new();
|
|
372
|
+
if(str){
|
|
373
|
+
var = strtok(str,"#");
|
|
374
|
+
while(var){
|
|
375
|
+
LOG_DEBUG(DEBUG,"Environment variable string = %s", var);
|
|
376
|
+
wr_string_list_add(w->env_var, var, strlen(var));
|
|
377
|
+
// TODO: see the security concerns
|
|
378
|
+
rv = putenv(w->env_var->rear->str.str);
|
|
379
|
+
if (rv != 0) {
|
|
380
|
+
LOG_ERROR(WARN, "putenv() failed, errno = %d, description = %s", errno, strerror(errno));
|
|
381
|
+
}
|
|
382
|
+
var = strtok(NULL,"#");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
void load_application(wkr_t* w){
|
|
388
|
+
LOG_FUNCTION
|
|
389
|
+
|
|
390
|
+
w->ctl->scgi = scgi_new();
|
|
391
|
+
if(w->ctl->scgi == NULL) {
|
|
392
|
+
LOG_ERROR(SEVERE,"Cannot create SCGI Request");
|
|
393
|
+
sigproc();
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
w->http = http_new(w);
|
|
398
|
+
if(w->http == NULL) {
|
|
399
|
+
scgi_body_add(w->ctl->scgi, "unable to load application.", strlen("unable to load application."));
|
|
400
|
+
LOG_ERROR(SEVERE,"unable to load application.");
|
|
401
|
+
}else if(worker_listen(w) < 0) {
|
|
402
|
+
scgi_body_add(w->ctl->scgi, "Error Initializing Workers.", strlen("Error Initializing Workers."));
|
|
403
|
+
LOG_ERROR(WARN,"Error Initializing Workers.");
|
|
404
|
+
}else{
|
|
405
|
+
worker_accept_requests(w);
|
|
406
|
+
LOG_INFO("Worker ready for serving requests.");
|
|
407
|
+
init_idle_watcher(w);
|
|
408
|
+
|
|
409
|
+
LOG_INFO("Successfully loaded rack application=%s with environment=%s",
|
|
410
|
+
w->tmp->path.str, w->tmp->env.str);
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
//loading adapter according to application type
|
|
414
|
+
LOG_DEBUG(DEBUG,"webroar_root = %s", w->tmp->root_path.str);
|
|
415
|
+
LOG_DEBUG(DEBUG,"path = %s, name = %s, type = %s, environment = %s, baseuri = %s, analytics = %c",
|
|
416
|
+
w->tmp->path.str, w->tmp->name.str, w->tmp->type.str,
|
|
417
|
+
w->tmp->env.str, w->tmp->resolver.str, w->tmp->profiler);
|
|
418
|
+
|
|
419
|
+
// Send error or ok acknowledgement message
|
|
420
|
+
if(w->ctl->scgi->body_length > 0){
|
|
421
|
+
// Send error response
|
|
422
|
+
w->ctl->error = TRUE;
|
|
423
|
+
get_worker_add_ctl_scgi(w, TRUE);
|
|
424
|
+
ev_io_start(w->loop,&(w->ctl->w_write));
|
|
425
|
+
ev_timer_again(w->loop, &w->ctl->t_ack);
|
|
426
|
+
}else{
|
|
427
|
+
// Send acknowledgement message
|
|
428
|
+
get_worker_add_ctl_scgi(w, FALSE);
|
|
429
|
+
ev_io_start(w->loop,&(w->ctl->w_write));
|
|
430
|
+
}
|
|
335
431
|
wkr_tmp_free(&w->tmp);
|
|
336
432
|
}
|
|
433
|
+
|
|
434
|
+
void application_config_read_cb(wkr_t* w, scgi_t *scgi){
|
|
435
|
+
LOG_FUNCTION
|
|
436
|
+
char *str;
|
|
437
|
+
/*w->ctl->scgi = scgi_new();
|
|
438
|
+
|
|
439
|
+
if(w->ctl->scgi == NULL) {
|
|
440
|
+
LOG_ERROR(SEVERE,"Cannot create SCGI Request");
|
|
441
|
+
sigproc();
|
|
442
|
+
return;
|
|
443
|
+
} */
|
|
444
|
+
|
|
445
|
+
if(w->tmp->is_static){
|
|
446
|
+
|
|
447
|
+
#ifdef W_ZLIB
|
|
448
|
+
str = (char*) scgi_header_value_get(scgi, "LOWER_LIMIT");
|
|
449
|
+
if(str){
|
|
450
|
+
w->tmp->lower_limit = atol(str);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
str = (char*) scgi_header_value_get(scgi, "UPPER_LIMIT");
|
|
454
|
+
if(str){
|
|
455
|
+
w->tmp->upper_limit = atol(str);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
#ifdef W_REGEX
|
|
459
|
+
str = (char*) scgi_header_value_get(scgi, "CONTENT_TYPE");
|
|
460
|
+
if(str){
|
|
461
|
+
wr_string_new(w->tmp->r_content_type, str, strlen(str));
|
|
462
|
+
}else {
|
|
463
|
+
wr_string_new(w->tmp->r_content_type, DEFAULT_CONTENT_TYPE, strlen(DEFAULT_CONTENT_TYPE));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
str = (char*) scgi_header_value_get(scgi, "USER_AGENT");
|
|
468
|
+
if(str){
|
|
469
|
+
wr_string_new(w->tmp->r_user_agent, str, strlen(str));
|
|
470
|
+
}
|
|
471
|
+
#endif
|
|
472
|
+
|
|
473
|
+
#endif
|
|
474
|
+
}else{
|
|
475
|
+
if(drop_privileges(w, scgi) == FALSE) {
|
|
476
|
+
wkr_tmp_free(&w->tmp);
|
|
477
|
+
sigproc();
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
manipulate_environment_variable(w, scgi);
|
|
482
|
+
str = (char*) scgi_header_value_get(scgi, "PATH");
|
|
483
|
+
if(str){
|
|
484
|
+
wr_string_new(w->tmp->path, str, strlen(str));
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
str = (char*) scgi_header_value_get(scgi, "ENV");
|
|
488
|
+
if(str){
|
|
489
|
+
wr_string_new(w->tmp->env, str, strlen(str));
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
str = (char*) scgi_header_value_get(scgi, "TYPE");
|
|
493
|
+
if(str){
|
|
494
|
+
wr_string_new(w->tmp->type, str, strlen(str));
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
str = (char*) scgi_header_value_get(scgi, "BASE_URI");
|
|
498
|
+
if(str){
|
|
499
|
+
wr_string_new(w->tmp->resolver, str, strlen(str));
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
str = (char*) scgi_header_value_get(scgi, "ANALYTICS");
|
|
503
|
+
if(str && strcmp(str,"enabled")==0){
|
|
504
|
+
w->tmp->profiler = 'y';
|
|
505
|
+
}else{
|
|
506
|
+
w->tmp->profiler = 'n';
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
load_application(w);
|
|
511
|
+
}
|
data/src/worker/worker.h
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
#ifndef WORKER_H_
|
|
24
24
|
#define WORKER_H_
|
|
25
25
|
|
|
26
|
-
#include <
|
|
26
|
+
#include <wkr_http.h>
|
|
27
27
|
|
|
28
28
|
typedef struct wkr_s wkr_t;
|
|
29
29
|
typedef struct wkr_tmp_s wkr_tmp_t;
|
|
@@ -31,22 +31,28 @@ typedef struct wkr_ctl_s wkr_ctl_t;
|
|
|
31
31
|
|
|
32
32
|
/****** Worket temporary structure ****/
|
|
33
33
|
struct wkr_tmp_s {
|
|
34
|
-
wr_str_t
|
|
35
|
-
wr_str_t
|
|
36
|
-
wr_str_t
|
|
37
|
-
wr_str_t
|
|
38
|
-
wr_str_t
|
|
39
|
-
wr_str_t
|
|
40
|
-
|
|
41
|
-
wr_str_t
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
short
|
|
46
|
-
short
|
|
47
|
-
short
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
wr_str_t path; /**< Application path */
|
|
35
|
+
wr_str_t env; /**< Application environment */
|
|
36
|
+
wr_str_t type; /**< Application type */
|
|
37
|
+
wr_str_t name; /**< Application name */
|
|
38
|
+
wr_str_t resolver; /**< Application baseuri */
|
|
39
|
+
wr_str_t root_path; /**< WebROaR root path */
|
|
40
|
+
char profiler; /**< Analytics flag */
|
|
41
|
+
wr_str_t ctl_path; /**< Server control path/port */
|
|
42
|
+
wr_str_t log_file; /**< Log file name */
|
|
43
|
+
short gid; /**< Process group id */
|
|
44
|
+
short uid; /**< Process user id */
|
|
45
|
+
short keep_alive; /**< HTTP connection keep alive flag */
|
|
46
|
+
short is_uds;
|
|
47
|
+
short is_static; /**< Worker to serve static files only */
|
|
48
|
+
#ifdef W_ZLIB
|
|
49
|
+
wr_u_long lower_limit; /**< Content-Length lower than the value would not be encoded */
|
|
50
|
+
wr_u_long upper_limit; /**< Content-Length larger than the value would not be encoded */
|
|
51
|
+
#ifdef W_REGEX
|
|
52
|
+
wr_str_t r_user_agent; /**< Regex value to validate User-Agent */
|
|
53
|
+
wr_str_t r_content_type; /**< Regex value to validate Content-Type */
|
|
54
|
+
#endif
|
|
55
|
+
#endif
|
|
50
56
|
};
|
|
51
57
|
|
|
52
58
|
wkr_tmp_t* wkr_tmp_new();
|
|
@@ -56,44 +62,50 @@ void wkr_tmp_free(wkr_tmp_t**);
|
|
|
56
62
|
struct wkr_ctl_s {
|
|
57
63
|
int fd;
|
|
58
64
|
ev_io w_read;
|
|
59
|
-
char msg[
|
|
65
|
+
char msg[STR_SIZE1KB];
|
|
60
66
|
size_t msg_size;
|
|
61
67
|
size_t bytes_read;
|
|
62
68
|
ev_io w_write;
|
|
69
|
+
ev_timer t_ack;
|
|
63
70
|
//size_t bytes_write;
|
|
64
71
|
scgi_t* scgi;
|
|
72
|
+
int error;
|
|
65
73
|
};
|
|
66
74
|
|
|
67
|
-
wkr_ctl_t* wkr_ctl_new();
|
|
75
|
+
wkr_ctl_t* wkr_ctl_new(wkr_t *w);
|
|
68
76
|
void wkr_ctl_free(wkr_ctl_t**);
|
|
69
|
-
int
|
|
70
|
-
|
|
77
|
+
int connect_to_head(wkr_t *w);
|
|
78
|
+
void start_ctl_watcher(wkr_t *w);
|
|
79
|
+
// Flag to create error response.
|
|
80
|
+
void get_worker_add_ctl_scgi(wkr_t* w, const int flag);
|
|
81
|
+
int send_config_req_msg(wkr_t* w);
|
|
82
|
+
void application_config_read_cb(wkr_t* w, scgi_t *scgi);
|
|
71
83
|
|
|
72
84
|
/********** Worker structure *********/
|
|
73
85
|
struct wkr_s {
|
|
74
86
|
/** Listen request from Head */
|
|
75
|
-
int
|
|
76
|
-
int
|
|
77
|
-
wr_str_t
|
|
78
|
-
ev_io
|
|
87
|
+
int listen_fd;
|
|
88
|
+
int listen_port;
|
|
89
|
+
wr_str_t sock_path;
|
|
90
|
+
ev_io w_accept;
|
|
79
91
|
struct ev_loop *loop;
|
|
80
92
|
|
|
81
93
|
/** Request */
|
|
82
|
-
int
|
|
83
|
-
ev_io
|
|
84
|
-
short
|
|
94
|
+
int req_fd; /**< Socket fd */
|
|
95
|
+
ev_io w_req; /**< watcher */
|
|
96
|
+
short is_uds;
|
|
85
97
|
|
|
86
|
-
wkr_ctl_t
|
|
87
|
-
wkr_tmp_t
|
|
88
|
-
http_t
|
|
98
|
+
wkr_ctl_t *ctl;
|
|
99
|
+
wkr_tmp_t *tmp;
|
|
100
|
+
http_t *http;
|
|
101
|
+
|
|
102
|
+
wr_str_list_t *env_var; /**< Environment variable array */
|
|
89
103
|
};
|
|
90
104
|
|
|
91
105
|
wkr_t* worker_new(struct ev_loop *, wkr_tmp_t*);
|
|
92
106
|
void worker_free(wkr_t**);
|
|
93
|
-
void
|
|
94
|
-
int worker_connect(wkr_t*);
|
|
107
|
+
void init_idle_watcher(wkr_t *w);
|
|
95
108
|
void start_idle_watcher();
|
|
96
|
-
void stop_idle_watcher();
|
|
97
109
|
void sigproc();
|
|
98
110
|
|
|
99
111
|
#endif /*WORKER_H_*/
|