Compare commits

..
62 Commits
Author SHA1 Message Date
roberto@sirius 89158b0509 better virtual host mode 2010-09-14 17:54:33 +02:00
roberto@sirius 86b90b8b16 fix a regression in PYTHONPATH management under INI/PASTE 2010-09-14 15:14:08 +02:00
roberto@sirius fe4c88c1c5 uWSGI 0.9.6.1 2010-09-12 09:26:54 +02:00
roberto@sirius f0f08728ab more verbose callable loading error 2010-09-12 08:57:43 +02:00
roberto@mrspurr 5259c803e8 dynamic app optimizations 2010-09-12 08:38:43 +02:00
roberto@haiku c6e5e533fa memory_report for Haiku 2010-09-12 07:41:52 +00:00
roberto@sirius 21e4cc19c8 export x-wsgiorg.uwsgi.version in WSGI env 2010-09-11 17:40:52 +02:00
roberto@haiku 045001fd6c fix Haiku usage of AF_UNIX 2010-09-11 16:17:11 +00:00
roberto@sirius eadaf3407a build system fixes 2010-09-11 14:51:51 +02:00
roberto@haiku 7434d3113c Haiku OS and gcc 2.95 support 2010-09-11 14:49:02 +00:00
roberto@sirius ab9fade14d fix no-strict-aliasing 2010-09-10 20:46:19 +02:00
roberto@sirius 5be63b02e8 fixed a typo 2010-09-10 17:25:34 +02:00
roberto@sirius 7694c38021 less verbose on SNMP management 2010-09-10 17:21:14 +02:00
roberto@sirius d13f7a45b9 ready for 0.9.6.1 2010-09-10 17:04:34 +02:00
roberto@sirius 44e8f01671 log request on SIGPIPE and HARAKIRI 2010-09-10 15:47:58 +02:00
roberto@sirius 09a8104256 protocol parsing optimization 2010-09-10 13:31:24 +02:00
roberto@fiorenzo 09d8ac2656 encoding fixes in uwsgiconfig.py 2010-09-10 11:48:11 +02:00
roberto@mrspurr c5877df60c fix --logto usage in cherokee 2010-09-10 08:35:34 +02:00
roberto@sirius 0f2fff31ee new --eval config option 2010-09-09 14:06:51 +02:00
roberto@sirius ebcdd294aa allow --pp as --pythonpath 2010-09-09 11:59:15 +02:00
roberto@sirius d663e10584 add -fno-strict-aliasing only for python 2.x or gcc < 4.3 2010-09-08 18:20:31 +02:00
roberto@sirius 048299e1d3 new spooler optimizations 2010-09-08 17:18:52 +02:00
roberto@sirius 96aaa9fa3f spooler fixes and uwsgi.spooler_jobs() 2010-09-08 17:00:32 +02:00
roberto@netbsd 015f17192c fix another strict check 2010-09-08 12:24:44 +02:00
roberto@silente f0ac801ecd support gcc < 4 2010-06-23 23:15:47 +02:00
roberto@fiorenzo f3b207c024 get return value of write() in http.c 2010-09-08 09:47:57 +02:00
roberto@freebsd64 0379e200b6 -O2 is now officially supported 2010-09-08 09:43:53 +02:00
roberto@voldemort abe6168bc3 uwsgi.is_a_reload 2010-09-07 12:27:38 +02:00
roberto@voldemort a6aa2c31c6 fixed PASTE=False compilation 2010-09-07 10:01:34 +02:00
roberto@voldemort f35ad319cf other 'c strict' fixes 2010-09-06 09:03:42 +02:00
riccardo@montag 527ad44463 fix osx compilation 2010-09-05 14:00:55 +02:00
riccardo@montag b245307f55 stricter compiler flags 2010-09-05 13:58:24 +02:00
roberto 9285b403d9 SNMP test 2010-09-05 12:47:21 +02:00
roberto@voldemort 58b72a4c80 another subprocess fix 2010-09-05 11:51:50 +02:00
roberto@sirius 73f706723e better handling of subprocesses 2010-09-03 15:46:33 +02:00
roberto@sirius 4d22f7171f fix a little comment 2010-09-03 12:20:11 +02:00
roberto@sirius b60e22b4e5 default fallback for unknown SCRIPT_NAME 2010-09-03 12:19:27 +02:00
roberto@sirius 7310b73289 fixed stupid bug in INI parsing 2010-09-03 08:14:17 +02:00
roberto@sirius 4fa61c225a uWSGI 0.9.6 2010-08-29 06:51:52 +02:00
roberto@sirius 63b41856e5 Changelog for 0.9.6 2010-08-28 19:58:55 +02:00
roberto@sirius ed1e668240 NetBSD latest fixes. Ready for 0.9.6 release 2010-08-28 19:36:55 +02:00
roberto@freebsd64 e3a7e70180 fix pidfile on HTTP mode 2010-08-28 13:51:38 +02:00
roberto@freebsd64 9f0b20c8d2 use getsockname() in vacuum() 2010-08-28 13:16:22 +02:00
roberto@freebsd64 68aff372ce HTTP final fixes, better reloading system, better cwd detection, powered up vacuum 2010-08-28 13:00:21 +02:00
roberto@sirius 38cfa72318 close ini file 2010-08-27 11:07:35 +02:00
roberto@sirius 31047e1e10 fixes for --file and shebang support 2010-08-27 07:32:44 +02:00
roberto@sirius bbb90296bb applied Leonid Borisenko patch to allow -O2 and -fno-strict-aliasing CFLAGS 2010-08-27 06:21:43 +02:00
roberto@sirius 00c6aa2f65 0.9.6-rc2 2010-08-26 17:08:15 +02:00
roberto@sirius 720da09631 xmlconf fixes 2010-08-26 15:33:25 +02:00
roberto@fiorenzo 47f7c09b97 add empty QUERY_STRING in http server 2010-08-26 14:55:39 +02:00
roberto@sirius cb5704da10 --callable 2010-08-26 14:09:15 +02:00
roberto@fiorenzo c64356b231 uwsgi packet watermark in HTTP server 2010-08-26 11:38:48 +02:00
roberto@sirius 2acd2f5224 another solaris hack 2010-08-26 11:01:57 +02:00
roberto@sirius ba251f8e3d another solaris fix 2010-08-26 10:09:40 +02:00
roberto@sirius 48019f9044 first round of http fixes 2010-08-26 10:06:17 +02:00
roberto@sunsparc d9a1f2448c solaris fixes 2010-08-26 09:33:23 +02:00
roberto@ubuntu64 553a947c2d fix routing 2010-08-26 08:43:28 +02:00
roberto@sirius 736aedfa89 add --ini-paste commodity and removal of strlc* functions 2010-08-26 08:36:44 +02:00
roberto@sirius 6184acc727 updated --help 2010-08-25 20:00:10 +02:00
roberto@sirius f0d96b03fa added --ping and --ping-timeout 2010-08-25 19:21:31 +02:00
roberto@sirius 14bf840eef fix urack.rb upload 2010-08-24 16:44:32 +02:00
roberto@sirius 7ea08093c7 uWSGI 0.9.6-rc1 2010-08-24 08:41:25 +02:00
28 changed files with 1147 additions and 217 deletions
+4
View File
@@ -4,3 +4,7 @@ d3850b52334a91d005b0fe45e1e38ba0997a1fb8 no_server mode
820cc64ab296dc4589ef72a33a6b804c22a0430c 0.9.5rc2
b0db39cfad5ac6d4f00bbb3f9c57cf73206e2afb 0.9.5
9f8b98ad1dfa51b86b13fa624c65f73523075fc4 0.9.5.1
a83e7a482e65befcfbb0e24af8cd5d15190acdd7 0.9.6-rc1
b8f67c6cd0d62f864db9b2b265b4e260ad7d873c 0.9.6-rc2
35918dd4b3771158b2b57410613ef029e08bbd60 0.9.6
5f25d1f97f9dde3e391a668c1c610a52a5db8244 0.9.6.1
+49
View File
@@ -1,3 +1,52 @@
*** september 2010 ***
* 0.9.6.1 [20100912]
- print the request uri during SIGPIPE or HARAKIRI
- added SIGUSR2 support (it will print the current running request, if available)
- protocol parsing optimization
- fixed --logto support
- new --eval option allows inline definition of WSGI script
- support for defining WSGI script in xml using CDATA
- allow --pp as --pythonpath shortcut
- various spooler optimizations and fixes
- added -O2 optimization by default
- added uwsgi.is_a_reload commodity function
- .ini file support fix
- SNMP agent fix
- support for subprocesses generated by master
- fix a regression in SCRIPT_NAME handling
- Haiku official support
- gcc 2.95 support
- dynamic app management optimizations
- export x-wsgiorg.uwsgi.version in WSGI env
*** august 2010 ***
* 0.9.6 [20100829]
- better handling of SCRIPT_NAME
- vacuum option for deleting unix sockets and pidfiles after usage
- advanced XML configuration
- new configuration systems: INI files and LDAP
- embedded HTTP server for development/testing
- better signal handling
- PSGI plugin improved
- usability fixes and new commodities options for root startup
- grunt processes (detached workers)
- preliminary integrated virtualhosting mode
- new option catch-exceptions can redirect python exceptions to your browser
- logging improvements (--logto and --logdate options)
- Full PEP 333 compliant usage of wsgi.file_wrapper
- re-initialize random seed after every fork() [security fix]
- fix Spooler's usage of stdin
- export WSGI environment in uwsgi.env (for doing evil things)
- logsize tracking (uwsgi.logsize) for future embedded log rotation
*** july 2010 ***
* 0.9.5.4 [20100706]
*** june 2010 ***
* 0.9.5.3 [20100628]
+4
View File
@@ -191,6 +191,10 @@ module Rack
buf, sender = client.recvfrom(remains)
end
if buf.length == 0
break
end
rack_input.write( buf )
remains -= buf.length
end
+7
View File
@@ -5,6 +5,13 @@
void evdis_loop(struct uwsgi_server *uwsgi) {
// populate event list
int kfd = kqueue();
if (kfd < 0) {
uwsgi_error("kqueue()");
exit(1);
}
}
+105 -32
View File
@@ -30,12 +30,23 @@ void http_end() {
exit(0);
}
static char *add_uwsgi_var(char *up, char *key, uint16_t keylen, char *val, uint16_t vallen, int header)
void http_wait_end() {
pid_t wp_p;
int wp_c;
wp_p = waitpid(-1, &wp_c, 0);
uwsgi_log("closing uWSGI embedded HTTP server.\n");
exit(0);
}
static char *add_uwsgi_var(char *up, char *key, uint16_t keylen, char *val, uint16_t vallen, int header, char *watermark)
{
int i;
if (!header) {
if ( (up + 2 + keylen + 2 + vallen) > watermark ) return up ;
*up++ = (unsigned char) (keylen & 0xff);
*up++ = (unsigned char) ((keylen >> 8) & 0xff);
@@ -48,16 +59,18 @@ static char *add_uwsgi_var(char *up, char *key, uint16_t keylen, char *val, uint
if (key[i] == '-') {
key[i] = '_';
} else {
key[i] = toupper(key[i]);
key[i] = toupper( (int) key[i]);
}
}
if (strncmp("CONTENT_TYPE", key, keylen) && strncmp("CONTENT_LENGTH", key, keylen)) {
if ( (up + 2 + keylen + 5 + 2 + vallen) > watermark ) return up ;
*up++ = (unsigned char) (((uint16_t) keylen + 5) & 0xff);
*up++ = (unsigned char) ((((uint16_t) keylen + 5) >> 8) & 0xff);
memcpy(up, "HTTP_", 5);
up += 5;
} else {
if ( (up + 2 + keylen + 2 + vallen) > watermark ) return up ;
*up++ = (unsigned char) (keylen & 0xff);
*up++ = (unsigned char) ((keylen >> 8) & 0xff);
}
@@ -98,10 +111,29 @@ void http_loop(struct uwsgi_server * uwsgi)
exit(1);
}
// ignore broken pipes;
signal(SIGPIPE, SIG_IGN);
if (!uwsgi->http_only) {
signal(SIGCHLD, &http_end);
signal(SIGINT, &http_wait_end);
}
else {
signal(SIGINT, &http_end);
}
uwsgi->http_server_name = malloc(256);
if (!uwsgi->http_server_name) {
uwsgi_error("malloc()");
exit(1);
}
memset(uwsgi->http_server_name, 0, 256);
if (gethostname(uwsgi->http_server_name, 255)) {
uwsgi_error("gethostname()");
memcpy(uwsgi->http_server_name, "localhost", 9);
}
uwsgi_log("starting HTTP loop on %s (pid: %d)\n", uwsgi->http_server_name, (int) getpid());
for(;;) {
if (!uwsgi->http_only) {
@@ -128,6 +160,7 @@ void http_loop(struct uwsgi_server * uwsgi)
if (ret) {
uwsgi_log("pthread_create() = %d\n", ret);
free(ur);
// sleep a bit to allow some resource gaining
sleep(1);
continue;
}
@@ -141,15 +174,13 @@ static void *http_request(void *u_h_r)
char buf[4096];
char tmp_buf[4096];
char *ptr;
char uwsgipkt[4096];
char *up;
struct uwsgi_http_req *ur = (struct uwsgi_http_req *) u_h_r ;
int clientfd = ur->fd;
int uwsgi_fd;
int uwsgi_fd = -1;
int need_to_read = 1;
int state = uwsgi_http_method;
@@ -158,17 +189,23 @@ static void *http_request(void *u_h_r)
size_t len;
int i,
j;
int i, j;
char HTTP_header_key[1024];
uint16_t ulen;
ptr = tmp_buf;
char *ptr = tmp_buf;
up = uwsgipkt;
int qs = 0;
char *up = uwsgipkt;
char *watermark = up + 4096 ;
char *watermark2 = tmp_buf + 4096 ;
int path_info_len;
char *ip;
up[0] = 0;
up[3] = 0;
@@ -180,37 +217,43 @@ static void *http_request(void *u_h_r)
uwsgi_error("read()");
break;
}
for (i = 0; i < len; i++) {
for (i = 0; i < (int) len; i++) {
if (buf[i] == ' ') {
if (state == uwsgi_http_method) {
up = add_uwsgi_var(up, "REQUEST_METHOD", 14, tmp_buf, ptr - tmp_buf, 0);
up = add_uwsgi_var(up, "REQUEST_METHOD", 14, tmp_buf, ptr - tmp_buf, 0, watermark);
ptr = tmp_buf;
state = uwsgi_http_uri;
} else if (state == uwsgi_http_uri) {
up = add_uwsgi_var(up, "REQUEST_URI", 11, tmp_buf, ptr - tmp_buf, 0);
up = add_uwsgi_var(up, "REQUEST_URI", 11, tmp_buf, ptr - tmp_buf, 0, watermark);
int path_info_len = ptr - tmp_buf;
path_info_len = ptr - tmp_buf;
for (j = 0; j < ptr - tmp_buf; j++) {
if (tmp_buf[j] == '?') {
path_info_len = j;
if (j + 1 < (ptr - tmp_buf)) {
up = add_uwsgi_var(up, "QUERY_STRING", 12, tmp_buf + j + 1, (ptr - tmp_buf) - (j + 1), 0);
up = add_uwsgi_var(up, "QUERY_STRING", 12, tmp_buf + j + 1, (ptr - tmp_buf) - (j + 1), 0, watermark);
qs = 1 ;
}
break;
}
}
up = add_uwsgi_var(up, "PATH_INFO", 9, tmp_buf, path_info_len, 0);
if (!qs) {
up = add_uwsgi_var(up, "QUERY_STRING", 12, NULL, 0, 0, watermark);
}
up = add_uwsgi_var(up, "PATH_INFO", 9, tmp_buf, path_info_len, 0, watermark);
ptr = tmp_buf;
state = uwsgi_http_protocol;
} else if (state == uwsgi_http_header_key_colon) {
if (ptr+1 > watermark2) { close(uwsgi_fd); goto clear;}
*ptr++ = 0;
memset(HTTP_header_key, 0, sizeof(HTTP_header_key));
@@ -219,6 +262,7 @@ static void *http_request(void *u_h_r)
state = uwsgi_http_header_val;
} else {
//check for overflow
if (ptr+1 > watermark2) { close(uwsgi_fd); goto clear;}
*ptr++ = buf[i];
}
@@ -236,8 +280,9 @@ static void *http_request(void *u_h_r)
if (state == uwsgi_http_header_val_r) {
up = add_uwsgi_var(up, HTTP_header_key, strlen(HTTP_header_key), tmp_buf, ptr - tmp_buf, 1);
up = add_uwsgi_var(up, HTTP_header_key, strlen(HTTP_header_key), tmp_buf, ptr - tmp_buf, 1, watermark);
if (!strcmp("CONTENT_LENGTH", HTTP_header_key)) {
if (ptr+1 > watermark2) { close(uwsgi_fd); goto clear;}
*ptr++ = 0;
http_body_len = atoi(tmp_buf);
}
@@ -245,41 +290,56 @@ static void *http_request(void *u_h_r)
state = uwsgi_http_header_key;
} else if (state == uwsgi_http_protocol_r) {
up = add_uwsgi_var(up, "SERVER_PROTOCOL", 15, tmp_buf, ptr - tmp_buf, 0);
up = add_uwsgi_var(up, "SERVER_PROTOCOL", 15, tmp_buf, ptr - tmp_buf, 0, watermark);
ptr = tmp_buf;
state = uwsgi_http_header_key;
} else if (state == uwsgi_http_end) {
need_to_read = 0;
if (uwsgi.http_server_name) {
up = add_uwsgi_var(up, "SERVER_NAME", 11, uwsgi.http_server_name, strlen(uwsgi.http_server_name), 0);
} else {
up = add_uwsgi_var(up, "SERVER_NAME", 11, "localhost", 9, 0);
}
up = add_uwsgi_var(up, "SERVER_NAME", 11, uwsgi.http_server_name, strlen(uwsgi.http_server_name), 0, watermark);
up = add_uwsgi_var(up, "SERVER_PORT", 11, uwsgi.http_server_port, strlen(uwsgi.http_server_port), 0, watermark);
up = add_uwsgi_var(up, "SERVER_PORT", 11, uwsgi.http_server_port, strlen(uwsgi.http_server_port), 0);
up = add_uwsgi_var(up, "SCRIPT_NAME", 11, "", 0, 0);
up = add_uwsgi_var(up, "SCRIPT_NAME", 11, "", 0, 0, watermark);
char *ip = inet_ntoa(ur->c_addr.sin_addr);
up = add_uwsgi_var(up, "REMOTE_ADDR", 11, ip, strlen(ip), 0);
ip = inet_ntoa(ur->c_addr.sin_addr);
up = add_uwsgi_var(up, "REMOTE_ADDR", 11, ip, strlen(ip), 0, watermark);
//up = add_uwsgi_var(up, "REMOTE_ADDR", 11, "127.0.0.1", 9, 0, watermark);
//up = add_uwsgi_var(up, "REMOTE_USER", 11, "unknown", 7, 0);
for(j=0;j<uwsgi.http_vars_cnt;j++) {
char *separator;
separator = strchr(uwsgi.http_vars[j], '=');
if (separator) {
up = add_uwsgi_var(up, uwsgi.http_vars[j], separator - uwsgi.http_vars[j], separator + 1, strlen(separator + 1), 0, watermark);
}
else {
up = add_uwsgi_var(up, uwsgi.http_vars[j], strlen(uwsgi.http_vars[j]), NULL, 0, 0, watermark);
}
}
uwsgi_fd = uwsgi_connect(uwsgi.socket_name, 10);
if (uwsgi_fd >= 0) {
ulen = (up - uwsgipkt) - 4;
uwsgipkt[1] = (unsigned char) (ulen & 0xff);
uwsgipkt[2] = (unsigned char) ((ulen >> 8) & 0xff);
write(uwsgi_fd, uwsgipkt, ulen + 4);
if (write(uwsgi_fd, uwsgipkt, ulen + 4) < 0) {
uwsgi_error("write()");
}
if (http_body_len > 0) {
if (http_body_len >= len - (i + 1)) {
write(uwsgi_fd, buf + i + 1, len - (i + 1));
if (http_body_len >= (int) len - (i + 1)) {
if (write(uwsgi_fd, buf + i + 1, len - (i + 1)) < 0) {
uwsgi_error("write()");
}
http_body_len -= len - (i + 1);
} else {
write(uwsgi_fd, buf + i, http_body_len);
if (write(uwsgi_fd, buf + i, http_body_len) < 0) {
uwsgi_error("write()");
}
http_body_len = 0;
}
@@ -289,15 +349,23 @@ static void *http_request(void *u_h_r)
to_read = http_body_len;
}
len = read(clientfd, uwsgipkt, to_read);
write(uwsgi_fd, uwsgipkt, len);
if (write(uwsgi_fd, uwsgipkt, len) < 0) {
uwsgi_error("write()");
}
http_body_len -= len;
}
}
while ((len = read(uwsgi_fd, uwsgipkt, 4096)) > 0) {
write(clientfd, uwsgipkt, len);
if (write(clientfd, uwsgipkt, len) < 0) {
uwsgi_error("write()");
}
}
close(uwsgi_fd);
}
else {
close(uwsgi_fd);
goto clear;
}
}
} else if (buf[i] == ':') {
@@ -305,11 +373,13 @@ static void *http_request(void *u_h_r)
state = uwsgi_http_header_key_colon;
} else {
//check for overflow
if (ptr+1 > watermark2) { close(uwsgi_fd); goto clear;}
*ptr++ = buf[i];
}
} else {
//check for overflow
if (ptr+1 > watermark2) { close(uwsgi_fd); goto clear;}
*ptr++ = buf[i];
}
@@ -317,8 +387,11 @@ static void *http_request(void *u_h_r)
}
clear:
close(clientfd);
free(ur);
pthread_exit(NULL);
return NULL;
}
+10 -6
View File
@@ -30,7 +30,7 @@ char *ini_lstrip(char *line) {
off_t i ;
char *ptr = line;
for(i=0;i<strlen(line);i++) {
for(i=0;i< (int) strlen(line);i++) {
if (line[i] == ' ' || line[i] == '\t') {
ptr++;
continue;
@@ -46,7 +46,7 @@ char *ini_get_key(char *key) {
off_t i;
char *ptr = key ;
for(i=0;i<strlen(key);i++) {
for(i=0;i< (int) strlen(key);i++) {
ptr++ ;
if (key[i] == '=') {
key[i] = 0;
@@ -83,7 +83,7 @@ void uwsgi_ini_config(char *file, struct option *long_options) {
char *ini_line;
char *section;
char *section = "";
char *key;
char *val;
@@ -96,7 +96,9 @@ void uwsgi_ini_config(char *file, struct option *long_options) {
colon = strchr(file, ':');
if (colon) {
colon[0] = 0;
section_asked = colon+1 ;
if (colon[1] != 0) {
section_asked = colon+1 ;
}
}
fd = open(file, O_RDONLY);
@@ -144,7 +146,7 @@ void uwsgi_ini_config(char *file, struct option *long_options) {
// this is a comment
}
else {
// val is always valid, but (obviously can be ignored)
// val is always valid, but (obviously) can be ignored
val = ini_get_key(key);
if (!strcmp(section, section_asked)) {
@@ -170,10 +172,12 @@ void uwsgi_ini_config(char *file, struct option *long_options) {
}
ini += (ini_line - ini);
sb.st_size -= (ini_line - ini);
ini += (ini_line - ini);
}
close(fd);
}
+13 -13
View File
@@ -10,10 +10,10 @@ void ldap2uwsgi(char *ldapname, char *uwsginame) {
int i;
for(i=0;i<strlen(ldapname);i++) {
if (isupper(ldapname[i])) {
for(i=0;i< (int) strlen(ldapname);i++) {
if (isupper( (int)ldapname[i])) {
*ptr++= '-';
*ptr++= tolower(ldapname[i]);
*ptr++= tolower( (int) ldapname[i]);
}
else {
*ptr++= ldapname[i] ;
@@ -28,8 +28,8 @@ int calc_ldap_name(char *name) {
int i;
int counter = 0;
for(i=0;i<strlen(name);i++) {
if (isupper(name[i])) {
for(i=0;i< (int)strlen(name);i++) {
if (isupper( (int) name[i])) {
counter++;
}
}
@@ -70,10 +70,10 @@ void uwsgi_ldap_schema_dump_ldif(struct option *lo) {
else {
uwsgi_log("olcAttributeTypes: ( 1.3.6.1.4.1.35156.17.4.%d NAME 'uWSGI", aopt->val) ;
}
for(i=0;i<strlen(aopt->name);i++) {
for(i=0;i< (int)strlen(aopt->name);i++) {
if (aopt->name[i] == '-') {
i++;
uwsgi_log("%c", toupper(aopt->name[i]));
uwsgi_log("%c", toupper( (int) aopt->name[i]));
}
else {
uwsgi_log("%c", aopt->name[i]);
@@ -110,10 +110,10 @@ next:
uwsgi_log("uWSGI");
for(i=0;i<strlen(aopt->name);i++) {
for(i=0;i< (int)strlen(aopt->name);i++) {
if (aopt->name[i] == '-') {
i++;
uwsgi_log("%c", toupper(aopt->name[i]));
uwsgi_log("%c", toupper( (int) aopt->name[i]));
}
else {
uwsgi_log("%c", aopt->name[i]);
@@ -160,10 +160,10 @@ void uwsgi_ldap_schema_dump(struct option *lo) {
else {
uwsgi_log("attributetype ( 1.3.6.1.4.1.35156.17.4.%d NAME 'uWSGI", aopt->val) ;
}
for(i=0;i<strlen(aopt->name);i++) {
for(i=0;i< (int)strlen(aopt->name);i++) {
if (aopt->name[i] == '-') {
i++;
uwsgi_log("%c", toupper(aopt->name[i]));
uwsgi_log("%c", toupper( (int) aopt->name[i]));
}
else {
uwsgi_log("%c", aopt->name[i]);
@@ -200,10 +200,10 @@ next:
uwsgi_log("uWSGI");
for(i=0;i<strlen(aopt->name);i++) {
for(i=0;i< (int)strlen(aopt->name);i++) {
if (aopt->name[i] == '-') {
i++;
uwsgi_log("%c", toupper(aopt->name[i]));
uwsgi_log("%c", toupper( (int) aopt->name[i]));
}
else {
uwsgi_log("%c", aopt->name[i]);
+13 -2
View File
@@ -84,7 +84,7 @@ void log_request(struct wsgi_request *wsgi_req) {
}
rlen = snprintf(logpkt, 4096, "[pid: %d|app: %d|req: %d/%llu] %.*s (%.*s) {%d vars in %d bytes} [%.*s] %.*s %.*s => generated %llu bytes in %ld msecs%s(%.*s %d) %d headers in %d bytes (%d async switches on async core %d)\n",
uwsgi.mypid,
(int) uwsgi.mypid,
wsgi_req->app_id,
app_req,
(unsigned long long ) uwsgi.workers[0].requests,
@@ -180,6 +180,17 @@ void get_memusage() {
kvm_close(kv);
}
#elif defined(__HAIKU__)
area_info ai;
int32 cookie;
uwsgi.workers[uwsgi.mywid].vsz_size = 0 ;
uwsgi.workers[uwsgi.mywid].rss_size = 0 ;
while(get_next_area_info(0, &cookie, &ai) == B_OK) {
uwsgi.workers[uwsgi.mywid].vsz_size += ai.ram_size;
if ( (ai.protection & B_WRITE_AREA) != 0) {
uwsgi.workers[uwsgi.mywid].rss_size += ai.ram_size;
}
}
#endif
}
+2 -1
View File
@@ -2,13 +2,14 @@
void nagios(struct uwsgi_server *uwsgi) {
char *tcp_port;
struct pollfd nagios_poll;
// connect and send
if (uwsgi->socket_name == NULL) {
fprintf(stdout, "UWSGI UNKNOWN: you have specified an invalid socket\n");
exit(3);
}
char *tcp_port = strchr(uwsgi->socket_name, ':');
tcp_port = strchr(uwsgi->socket_name, ':');
if (tcp_port == NULL) {
fprintf(stdout, "UWSGI UNKNOWN: you have specified an invalid socket\n");
exit(3);
+4 -4
View File
@@ -30,7 +30,7 @@ int uwsgi_load_plugin(struct uwsgi_server *uwsgi, int modifier, char *plugin, ch
if (absolute) {
plugin_name = malloc(strlen(plugin) + 1);
strlcpy(plugin_name, plugin, strlen(plugin));
memcpy(plugin_name, plugin, strlen(plugin) + 1);
}
else {
plugin_name = malloc(strlen(UWSGI_PLUGIN_DIR) + 1 + strlen(plugin) + 1);
@@ -38,9 +38,9 @@ int uwsgi_load_plugin(struct uwsgi_server *uwsgi, int modifier, char *plugin, ch
uwsgi_error("malloc()");
return -1 ;
}
strlcpy(plugin_name, UWSGI_PLUGIN_DIR, strlen(UWSGI_PLUGIN_DIR));
strlcat(plugin_name, "/", 1);
strlcat(plugin_name, plugin, strlen(plugin));
memcpy(plugin_name, UWSGI_PLUGIN_DIR, strlen(UWSGI_PLUGIN_DIR));
memcpy(plugin_name + strlen(UWSGI_PLUGIN_DIR) , "/", 1);
memcpy(plugin_name + strlen(UWSGI_PLUGIN_DIR) + 1, plugin, strlen(plugin) + 1);
}
plugin_handle = dlopen(plugin_name, RTLD_NOW | RTLD_GLOBAL);
free(plugin_name);
+23 -16
View File
@@ -349,73 +349,80 @@ int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req)
ptrbuf += 2;
if (ptrbuf + strsize <= bufferend) {
//uwsgi_log("uwsgi %.*s = %.*s\n", wsgi_req->hvec[wsgi_req->var_cnt].iov_len, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, strsize, ptrbuf);
if (!strncmp("SCRIPT_NAME", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
if (!uwsgi_strncmp("SCRIPT_NAME", 11, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->script_name = ptrbuf;
wsgi_req->script_name_len = strsize;
#ifdef UWSGI_DEBUG
uwsgi_debug("SCRIPT_NAME=%.*s\n", wsgi_req->script_name_len, wsgi_req->script_name);
#endif
}
else if (!strncmp("PATH_INFO", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("PATH_INFO", 9, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->path_info = ptrbuf;
wsgi_req->path_info_len = strsize;
#ifdef UWSGI_DEBUG
uwsgi_debug("PATH_INFO=%.*s\n", wsgi_req->path_info_len, wsgi_req->path_info);
#endif
}
else if (!strncmp("SERVER_PROTOCOL", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("SERVER_PROTOCOL", 15, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->protocol = ptrbuf;
wsgi_req->protocol_len = strsize;
}
else if (!strncmp("REQUEST_URI", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("REQUEST_URI", 11, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->uri = ptrbuf;
wsgi_req->uri_len = strsize;
}
else if (!strncmp("QUERY_STRING", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("QUERY_STRING", 12, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->query_string = ptrbuf;
wsgi_req->query_string_len = strsize;
}
else if (!strncmp("REQUEST_METHOD", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("REQUEST_METHOD", 14, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->method = ptrbuf;
wsgi_req->method_len = strsize;
}
else if (!strncmp("REMOTE_ADDR", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("REMOTE_ADDR", 11, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->remote_addr = ptrbuf;
wsgi_req->remote_addr_len = strsize;
}
else if (!strncmp("REMOTE_USER", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("REMOTE_USER", 11, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->remote_user = ptrbuf;
wsgi_req->remote_user_len = strsize;
}
else if (!strncmp("UWSGI_SCHEME", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("UWSGI_SCHEME", 12, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->scheme = ptrbuf;
wsgi_req->scheme_len = strsize;
}
else if (!strncmp("UWSGI_SCRIPT",wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len )) {
else if (!uwsgi_strncmp("UWSGI_SCRIPT", 12, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len )) {
wsgi_req->wsgi_script = ptrbuf;
wsgi_req->wsgi_script_len = strsize;
}
else if (!strncmp("UWSGI_MODULE", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("UWSGI_MODULE", 12, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->wsgi_module = ptrbuf;
wsgi_req->wsgi_module_len = strsize;
}
else if (!strncmp("UWSGI_CALLABLE", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("UWSGI_CALLABLE", 14, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->wsgi_callable = ptrbuf;
wsgi_req->wsgi_callable_len = strsize;
}
else if (!strncmp("UWSGI_PYHOME", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("UWSGI_PYHOME", 12, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->pyhome = ptrbuf;
wsgi_req->pyhome_len = strsize;
}
else if (!strncmp("SERVER_NAME", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("UWSGI_CHDIR", 11, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->chdir = ptrbuf;
wsgi_req->chdir_len = strsize;
}
else if (!uwsgi_strncmp("SERVER_NAME", 11, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->host = ptrbuf;
wsgi_req->host_len = strsize;
#ifdef UWSGI_DEBUG
uwsgi_debug("SERVER_NAME=%.*s\n", wsgi_req->host_len, wsgi_req->host);
#endif
}
else if (!strncmp("HTTPS", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("HTTPS", 5, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->https = ptrbuf;
wsgi_req->https_len = strsize;
}
else if (!strncmp("CONTENT_LENGTH", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
else if (!uwsgi_strncmp("CONTENT_LENGTH", 14, wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->post_cl = get_content_length(ptrbuf, strsize);
}
+2 -2
View File
@@ -189,12 +189,12 @@ void uwsgi_proxy(int proxyfd) {
for (i = 0; i < nevents; i++) {
if (eevents[i].ASYNC_FD == proxyfd) {
if ( (int)eevents[i].ASYNC_FD == proxyfd) {
if (eevents[i].ASYNC_IS_IN) {
// new connection, accept it
ev.ASYNC_FD = accept(proxyfd, (struct sockaddr *) &upc_addr, &upc_len);
if (ev.ASYNC_FD < 0) {
if ( (int) ev.ASYNC_FD < 0) {
uwsgi_error("accept()");
continue;
}
+4 -2
View File
@@ -136,7 +136,7 @@ clear:
}
if (wsgi_req->async_post && !wsgi_req->fd_closed) {
fclose(wsgi_req->async_post);
if (!uwsgi->post_buffering || wsgi_req->post_cl <= uwsgi->post_buffering) {
if (!uwsgi->post_buffering || wsgi_req->post_cl <= (size_t) uwsgi->post_buffering) {
wsgi_req->fd_closed = 1 ;
}
@@ -210,6 +210,8 @@ int uwsgi_python_call(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req,
}
void init_pyargv(struct uwsgi_server *uwsgi) {
char *ap;
#ifdef PYTHREE
wchar_t pname[6];
@@ -229,7 +231,7 @@ void init_pyargv(struct uwsgi_server *uwsgi) {
}
memset(wcargv, 0, sizeof( wchar_t ) * (strlen(uwsgi->pyargv)+1));
#endif
char *ap;
#ifdef __sun__
// FIX THIS !!!
ap = strtok(uwsgi->pyargv, " ");
+5 -2
View File
@@ -1,3 +1,4 @@
#ifdef UWSGI_ROUTING
#include "uwsgi.h"
void routing_setup(struct uwsgi_server *uwsgi) {
@@ -62,7 +63,7 @@ void check_route(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
void uwsgi_route_action_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, struct uwsgi_route *ur) {
int i;
PyObject *route_py_callbase, *route_py_dict;
PyObject *route_py_callbase, *route_py_dict = NULL;
uwsgi_log("managing WSGI route...\n");
if (ur->callable == NULL) {
@@ -105,7 +106,7 @@ void uwsgi_route_action_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *ws
void uwsgi_route_action_uwsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, struct uwsgi_route *ur) {
PyObject *route_py_callbase, *route_py_dict;
PyObject *route_py_callbase, *route_py_dict = NULL ;
int i;
uwsgi_log("managing uwsgi route...\n");
@@ -152,3 +153,5 @@ void uwsgi_route_action_uwsgi(struct uwsgi_server *uwsgi, struct wsgi_request *w
}
}
#endif
+1 -1
View File
@@ -149,7 +149,7 @@ ssize_t uwsgi_do_sendfile(int sockfd, int filefd, size_t filesize, size_t chunk,
return jlen ;
}
while (i < filesize) {
while (i < (int) filesize) {
jlen = read(filefd, nosf_buf, chunk);
if (jlen <= 0) {
uwsgi_error("read()");
+1 -1
View File
@@ -34,7 +34,7 @@ class uWSGIDistribution(Distribution):
setup(name='uWSGI',
version='0.9.6-dev',
version='0.9.6.1',
description='The uWSGI server',
author='Unbit',
author_email='info@unbit.it',
+1 -1
View File
@@ -1,6 +1,6 @@
import uwsgi
print "uWSGI version:", uwsgi.version
print "!!! uWSGI version:", uwsgi.version
def ciao():
print "modifica su /tmp"
+40 -5
View File
@@ -39,9 +39,9 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_
uint8_t community_len;
uint64_t snmp_int;
uint64_t request_id;
uint64_t version;
uint64_t snmp_int = 0;
uint64_t request_id = 0;
uint64_t version = 0;
// KISS for memory management
@@ -55,6 +55,9 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_
return;
ptr++;
#ifdef UWSGI_DEBUG
uwsgi_debug("SNMP packet size: %d\n", size);
#endif
@@ -68,6 +71,9 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_
return;
ptr += ptrdelta;
#ifdef UWSGI_DEBUG
uwsgi_debug("SNMP version: %d\n", version);
#endif
@@ -90,11 +96,16 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_
if (memcmp(ptr, uwsgi.shared->snmp_community, community_len))
return;
#ifdef UWSGI_DEBUG
uwsgi_debug("SNMP community: %.*s\n", community_len, ptr);
#endif
ptr += community_len;
// check for get request
if (*ptr != SNMP_GET)
return;
*ptr = SNMP_RES;
ptr++;
seq1 = ptr;
@@ -110,34 +121,45 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_
if (*ptr != SNMP_INTEGER)
return;
ptr++;
ptrdelta = get_snmp_integer(ptr, &request_id);
if (ptrdelta <= 0)
return;
#ifdef UWSGI_DEBUG
uwsgi_debug("SNMP request id: %d %p\n", request_id, ptr);
#endif
// check here
if (ptr + ptrdelta >= buffer + size)
return;
ptr += ptrdelta;
// get error
if (*ptr != SNMP_INTEGER)
return;
ptr++;
snmp_int = 0;
ptrdelta = get_snmp_integer(ptr, &snmp_int);
if (ptrdelta <= 0)
return;
if (ptr + ptrdelta >= buffer + size)
return;
if (snmp_int != 0)
return;
ptr += ptrdelta;
// get index
if (*ptr != SNMP_INTEGER)
return;
ptr++;
snmp_int = 0;
ptrdelta = get_snmp_integer(ptr, &snmp_int);
if (ptrdelta <= 0)
return;
@@ -148,6 +170,10 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_
return;
ptr += ptrdelta;
#ifdef UWSGI_DEBUG
uwsgi_debug("SNMP int [1]: %d\n", snmp_int);
#endif
// check for sequence
if (*ptr != SNMP_SEQUENCE)
return;
@@ -173,6 +199,10 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_
seq3 = ptr;
ptr++;
#ifdef UWSGI_DEBUG
uwsgi_debug("SNMP ASN len: %d\n", asnlen);
#endif
// is it an OID ?
if (*ptr != SNMP_OID)
return;
@@ -248,11 +278,16 @@ static int get_snmp_integer(uint8_t * ptr, uint64_t * val) {
uint16_t tlen;
int i, j;
uint8_t *cval = (uint8_t *) val;
tlen = *ptr;
if (tlen > 4)
return -1;
#ifdef UWSGI_DEBUG
uwsgi_debug("SNMP get integer TLEN %d %p\n", tlen, ptr);
#endif
j = 0;
#ifdef __BIG_ENDIAN__
@@ -260,7 +295,7 @@ static int get_snmp_integer(uint8_t * ptr, uint64_t * val) {
#else
for (i = tlen - 1; i >= 0; i--) {
#endif
val[j] = ptr[1 + i];
cval[j] = ptr[1 + i];
j++;
}
@@ -419,7 +454,7 @@ PyObject *py_snmp_community(PyObject * self, PyObject * args) {
memcpy(uwsgi.shared->snmp_community, snmp_community, 72);
}
else {
strlcpy(uwsgi.shared->snmp_community, snmp_community, 73);
memcpy(uwsgi.shared->snmp_community, snmp_community, strlen(snmp_community) + 1);
}
Py_INCREF(Py_True);
+8 -3
View File
@@ -38,12 +38,17 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
}
uws_addr->sun_family = AF_UNIX;
strlcpy(uws_addr->sun_path + abstract_socket, socket_name, 102+1);
memcpy(uws_addr->sun_path + abstract_socket, socket_name, 102);
#ifdef __HAIKU__
if (bind(serverfd, (struct sockaddr *) uws_addr, sizeof(struct sockaddr_un))) {
#else
if (bind(serverfd, (struct sockaddr *) uws_addr, strlen(socket_name) + abstract_socket + ((void *) uws_addr->sun_path - (void *) uws_addr)) != 0) {
#endif
uwsgi_error("bind()");
exit(1);
}
if (listen(serverfd, listen_queue) != 0) {
uwsgi_error("listen()");
@@ -220,7 +225,7 @@ int connect_to_unix(char *socket_name, int timeout) {
memset(&uws_addr, 0, sizeof(struct sockaddr_un));
uws_addr.sun_family = AF_UNIX;
strlcpy(uws_addr.sun_path, socket_name, 102+1);
memcpy(uws_addr.sun_path, socket_name, 102);
uwsgi_poll.fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (uwsgi_poll.fd < 0) {
+9 -6
View File
@@ -18,7 +18,7 @@ int spool_request(struct uwsgi_server *uwsgi, char *filename, int rn, char *buff
hostname[256] = 0;
if (snprintf(filename, 1024, "%s/uwsgi_spoolfile_on_%s_%d_%d_%llu_%llu", uwsgi->spool_dir, hostname, getpid(), rn, (unsigned long long) tv.tv_sec, (unsigned long long) tv.tv_usec) <= 0) {
if (snprintf(filename, 1024, "%s/uwsgi_spoolfile_on_%s_%d_%d_%llu_%llu", uwsgi->spool_dir, hostname, (int) getpid(), rn, (unsigned long long) tv.tv_sec, (unsigned long long) tv.tv_usec) <= 0) {
return 0;
}
@@ -56,7 +56,7 @@ int spool_request(struct uwsgi_server *uwsgi, char *filename, int rn, char *buff
close(fd);
uwsgi_log( "written %d bytes to spool file %s.\n", size + 4, filename);
uwsgi_log( "written %d bytes to spool file %s\n", size + 4, filename);
return 1;
@@ -86,9 +86,6 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
char *key;
char *val;
// spool every 30 seconds by default
uwsgi->shared->spooler_frequency = 30 ;
spool_tuple = PyTuple_New(1);
if (!spool_tuple) {
@@ -114,8 +111,14 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
}
// asked by Marco Beri
#ifdef __HAIKU__
uwsgi_log( "lowering spooler priority to %d\n", B_LOW_PRIORITY);
set_thread_priority(find_thread(NULL), B_LOW_PRIORITY);
#else
uwsgi_log( "lowering spooler priority to %d\n", PRIO_MAX);
setpriority(PRIO_PROCESS, getpid(), PRIO_MAX);
#endif
nullfd = open("/dev/null", O_RDONLY);
if (nullfd < 0) {
@@ -144,7 +147,7 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
continue;
}
if (!access(dp->d_name, R_OK | W_OK)) {
uwsgi_log( "managing spool request %s...\n", dp->d_name);
uwsgi_log( "managing spool request %s ...\n", dp->d_name);
spooler_callable = PyDict_GetItemString(uwsgi_module_dict, "spooler");
if (!spooler_callable) {
+1 -1
View File
@@ -414,7 +414,7 @@ void u_green_loop(struct uwsgi_server *uwsgi) {
for(i=0; i<uwsgi->async_nevents;i++) {
if (uwsgi->async_events[i].ASYNC_FD == uwsgi->serverfd) {
if ( (int) uwsgi->async_events[i].ASYNC_FD == uwsgi->serverfd) {
wsgi_req = find_first_accepting_wsgi_req(uwsgi);
if (!wsgi_req) goto cycle;
u_green_schedule_to_req(uwsgi, wsgi_req);
+36 -8
View File
@@ -155,18 +155,20 @@ void logto(char *logfile) {
/* stdout */
if (dup2(fd, 1) < 0) {
uwsgi_error("dup2()");
exit(1);
if (fd != 1) {
if (dup2(fd, 1) < 0) {
uwsgi_error("dup2()");
exit(1);
}
close(fd);
}
/* stderr */
if (dup2(fd, 2) < 0) {
if (dup2(1, 2) < 0) {
uwsgi_error("dup2()");
exit(1);
}
close(fd);
}
@@ -297,7 +299,7 @@ void uwsgi_close_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_r
// defunct process reaper
if (uwsgi->shared->options[UWSGI_OPTION_REAPER] == 1 || uwsgi->grunt) {
while( waitpid(-1, &waitpid_status, WNOHANG) > 0) ;
while( waitpid(WAIT_ANY, &waitpid_status, WNOHANG) > 0) ;
}
// reset request
memset(wsgi_req, 0, sizeof(struct wsgi_request));
@@ -405,18 +407,36 @@ void sanitize_args(struct uwsgi_server *uwsgi) {
uwsgi->single_interpreter = 1 ;
}
#ifdef UWSGI_INI
if (uwsgi->ini) {
uwsgi->single_interpreter = 1 ;
}
#endif
#ifdef UWSGI_PASTE
if (uwsgi->paste) {
uwsgi->single_interpreter = 1 ;
}
#endif
if (uwsgi->shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
if (!uwsgi->post_buffering) {
uwsgi_log(" *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers *** \n");
}
}
#ifdef UWSGI_HTTP
if (uwsgi->http && !uwsgi->http_only) {
uwsgi->vacuum = 1;
}
#endif
}
void env_to_arg(char *src, char *dst) {
int i;
int val = 0 ;
for(i=0;i<strlen(src);i++) {
for(i=0;i< (int) strlen(src);i++) {
if (src[i] == '=') {
val = 1 ;
}
@@ -424,7 +444,7 @@ void env_to_arg(char *src, char *dst) {
dst[i] = src[i];
}
else {
dst[i] = tolower(src[i]);
dst[i] = tolower( (int) src[i]);
if (dst[i] == '_') {
dst[i] = '-';
}
@@ -507,3 +527,11 @@ void uwsgi_log(const char *fmt, ...) {
// do not check for errors
rlen = write(2, logpkt, rlen);
}
inline int uwsgi_strncmp(char *src, int slen, char *dst, int dlen) {
if (slen != dlen) return 1;
return memcmp(src, dst, dlen);
}
+460 -68
View File
@@ -75,15 +75,19 @@ static struct option long_options[] = {
#endif
{"disable-logging", no_argument, 0, 'L'},
{"callable", required_argument, 0, LONG_ARGS_CALLABLE},
{"pidfile", required_argument, 0, LONG_ARGS_PIDFILE},
{"chroot", required_argument, 0, LONG_ARGS_CHROOT},
{"gid", required_argument, 0, LONG_ARGS_GID},
{"uid", required_argument, 0, LONG_ARGS_UID},
{"pythonpath", required_argument, 0, LONG_ARGS_PYTHONPATH},
{"python-path", required_argument, 0, LONG_ARGS_PYTHONPATH},
{"pp", required_argument, 0, LONG_ARGS_PYTHONPATH},
{"pyargv", required_argument, 0, LONG_ARGS_PYARGV},
#ifdef UWSGI_INI
{"ini", required_argument, 0, LONG_ARGS_INI},
{"ini-paste", required_argument, 0, LONG_ARGS_INI_PASTE},
#endif
#ifdef UWSGI_PASTE
{"paste", required_argument, 0, LONG_ARGS_PASTE},
@@ -102,6 +106,7 @@ static struct option long_options[] = {
{"post-buffering", required_argument, 0, LONG_ARGS_POST_BUFFERING},
{"post-buffering-bufsize", required_argument, 0, LONG_ARGS_POST_BUFFERING_SIZE},
{"ignore-script-name", no_argument, &uwsgi.ignore_script_name, 1},
{"no-default-app", no_argument, &uwsgi.no_default_app, 1},
#ifdef UWSGI_UDP
{"udp", required_argument, 0, LONG_ARGS_UDP},
#endif
@@ -129,6 +134,7 @@ static struct option long_options[] = {
#endif
{"wsgi-file", required_argument, 0, LONG_ARGS_WSGI_FILE},
{"file", required_argument, 0, LONG_ARGS_FILE_CONFIG},
{"eval", required_argument, 0, LONG_ARGS_EVAL_CONFIG},
#ifdef UWSGI_ASYNC
{"async", required_argument, 0, LONG_ARGS_ASYNC},
#endif
@@ -156,15 +162,54 @@ static struct option long_options[] = {
#ifdef UWSGI_HTTP
{"http", required_argument, 0, LONG_ARGS_HTTP},
{"http-only", no_argument, &uwsgi.http_only, 1},
{"http-var", required_argument, 0, LONG_ARGS_HTTP_VAR},
#endif
{"catch-exceptions", no_argument, &uwsgi.catch_exceptions, 1},
{"mode", required_argument, 0, LONG_ARGS_MODE},
{"env", required_argument, 0, LONG_ARGS_ENV},
{"vacuum", no_argument, &uwsgi.vacuum, 1},
{"ping", required_argument, 0, LONG_ARGS_PING},
{"ping-timeout", required_argument, 0, LONG_ARGS_PING_TIMEOUT},
{"version", no_argument, 0, LONG_ARGS_VERSION},
{0, 0, 0, 0}
};
void ping(struct uwsgi_server *uwsgi) {
struct uwsgi_header uh;
struct pollfd uwsgi_poll;
// use a 3 secs timeout by default
if (!uwsgi->ping_timeout) uwsgi->ping_timeout = 3 ;
uwsgi_poll.fd = uwsgi_connect(uwsgi->ping, uwsgi->ping_timeout);
if (uwsgi_poll.fd < 0) {
exit(1);
}
uh.modifier1 = UWSGI_MODIFIER_PING;
uh.pktsize = 0;
uh.modifier2 = 0;
if (write(uwsgi_poll.fd, &uh, 4) != 4) {
uwsgi_error("write()");
exit(2);
}
uwsgi_poll.events = POLLIN;
if (!uwsgi_parse_response(&uwsgi_poll, uwsgi->ping_timeout, &uh, NULL)) {
exit(1);
}
else {
if (uh.pktsize > 0) {
exit(2);
}
else {
exit(0);
}
}
}
int find_worker_id(pid_t pid) {
int i;
for (i = 1; i <= uwsgi.numproc; i++) {
@@ -178,13 +223,20 @@ int find_worker_id(pid_t pid) {
PyMethodDef null_methods[] = {
{NULL, NULL},
{ NULL, NULL},
};
struct uwsgi_app *wi;
void warn_pipe() {
uwsgi_log("SIGPIPE: writing to a closed pipe/socket/fd !!!\n");
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
if (uwsgi.async < 2 && wsgi_req->uri_len > 0) {
uwsgi_log("SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request %.*s !!!\n", wsgi_req->uri_len, wsgi_req->uri );
}
else {
uwsgi_log("SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) !!!\n");
}
}
void gracefully_kill() {
@@ -230,6 +282,7 @@ void grace_them_all() {
void reap_them_all() {
int i;
uwsgi.to_heaven = 1;
uwsgi_log("...brutally killing workers...\n");
for (i = 1; i <= uwsgi.numproc; i++) {
kill(uwsgi.workers[i].pid, SIGTERM);
@@ -280,6 +333,22 @@ void stats() {
uwsgi_log("\n");
}
void what_i_am_doing() {
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
if (uwsgi.async < 2 && wsgi_req->uri_len > 0) {
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < time(NULL)) {
uwsgi_log("HARAKIRI: --- uWSGI worker %d (pid: %d) WAS managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime((const time_t *) &wsgi_req->start_of_request.tv_sec) );
}
else {
uwsgi_log("SIGUSR2: --- uWSGI worker %d (pid: %d) is managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime((const time_t *) &wsgi_req->start_of_request.tv_sec) );
}
}
}
PyObject *wsgi_spitout;
PyMethodDef uwsgi_spit_method[] = { {"uwsgi_spit", py_uwsgi_spit, METH_VARARGS, ""} };
@@ -310,14 +379,23 @@ static void unconfigured_after_hook(struct uwsgi_server *uwsgi, struct wsgi_requ
static void vacuum(void) {
struct sockaddr_un sa;
socklen_t sa_len = sizeof(struct sockaddr_un);
if (uwsgi.vacuum) {
if (getpid() == masterpid) {
if (uwsgi.socket_name && uwsgi.bind_to_unix) {
if (unlink(uwsgi.socket_name)) {
uwsgi_error("unlink()");
}
else {
uwsgi_log("VACUUM: unix socket removed.\n");
if (chdir(uwsgi.cwd)) {
uwsgi_error("chdir()");
}
memset(&sa, 0, sa_len);
if (!getsockname(uwsgi.serverfd, (struct sockaddr*)&sa, &sa_len)) {
if (sa.sun_family == AF_UNIX) {
if (unlink(sa.sun_path)) {
uwsgi_error("unlink()");
}
else {
uwsgi_log("VACUUM: unix socket removed.\n");
}
}
}
if (uwsgi.pidfile && !uwsgi.uid) {
@@ -362,7 +440,6 @@ int main(int argc, char *argv[], char *envp[]) {
int working_workers = 0;
int blocking_workers = 0;
char *cwd = NULL;
int ready_to_reload = 0;
int ready_to_die = 0;
@@ -370,6 +447,18 @@ int main(int argc, char *argv[], char *envp[]) {
unsigned int reloads = 0;
char env_reload_buf[11];
int option_index = 0;
#ifdef UWSGI_UDP
PyObject *udp_callable;
PyObject *udp_callable_args = NULL;
PyObject *udp_response;
#endif
#ifdef UWSGI_HTTP
pid_t http_pid;
#endif
#ifdef UNBIT
//struct uidsec_struct us;
@@ -377,19 +466,33 @@ int main(int argc, char *argv[], char *envp[]) {
int socket_type = 0;
socklen_t socket_type_len;
PyObject *random_module, *random_dict, *random_seed;
int master_has_children = 0;
#ifdef UWSGI_DEBUG
struct utsname uuts;
int so_bufsize ;
socklen_t so_bufsize_len;
#endif
/* anti signal bombing */
signal(SIGHUP, SIG_IGN);
signal(SIGTERM, SIG_IGN);
atexit(vacuum);
// initialize masterpid with a default value
masterpid = getpid();
memset(&uwsgi, 0, sizeof(struct uwsgi_server));
uwsgi.cwd = uwsgi_get_cwd();
atexit(vacuum);
#ifdef UWSGI_DEBUG
/* get system information */
struct utsname uuts;
if (uname(&uuts)) {
uwsgi_error("uname()");
}
@@ -412,6 +515,11 @@ int main(int argc, char *argv[], char *envp[]) {
}
memset(uwsgi.shared, 0, sizeof(struct uwsgi_shared));
#ifdef UWSGI_SPOOLER
// set the spooler frequency to 30 seconds by default
uwsgi.shared->spooler_frequency = 30;
#endif
for (i = 0; i <= 0xFF; i++) {
uwsgi.shared->hooks[i] = unconfigured_hook;
uwsgi.shared->after_hooks[i] = unconfigured_after_hook;
@@ -432,7 +540,7 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] = 4;
uwsgi.shared->options[UWSGI_OPTION_LOGGING] = 1;
int option_index = 0;
gettimeofday(&uwsgi.start_tv, NULL);
@@ -485,6 +593,11 @@ int main(int argc, char *argv[], char *envp[]) {
if (optind < argc) {
char *lazy = argv[optind];
char *qc = strchr(lazy, ':');
if (qc) {
qc[0] = 0 ;
uwsgi.callable = qc + 1;
}
if (!strcmp(lazy+strlen(lazy)-3, ".py")) {
uwsgi.file_config = lazy;
}
@@ -510,14 +623,17 @@ int main(int argc, char *argv[], char *envp[]) {
parse_sys_envs(environ, long_options);
if (uwsgi.ping) {
ping(&uwsgi);
}
if (uwsgi.binary_path == argv[0]) {
cwd = uwsgi_get_cwd();
uwsgi.binary_path = malloc(strlen(argv[0]) + 1);
if (uwsgi.binary_path == NULL) {
uwsgi_error("malloc()");
exit(1);
}
strlcpy(uwsgi.binary_path, argv[0], strlen(argv[0]) + 1);
memcpy(uwsgi.binary_path, argv[0], strlen(argv[0]) + 1);
}
if (uwsgi.shared->options[UWSGI_OPTION_CGI_MODE] == 0) {
@@ -552,7 +668,7 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi_error("fopen");
exit(1);
}
if (fprintf(pidfile, "%d\n", getpid()) < 0) {
if (fprintf(pidfile, "%d\n", (int) getpid()) < 0) {
uwsgi_log( "could not write pidfile.\n");
}
fclose(pidfile);
@@ -575,8 +691,14 @@ int main(int argc, char *argv[], char *envp[]) {
}
if (uwsgi.prio != 0) {
#ifdef __HAIKU__
if (set_thread_priority(find_thread(NULL),uwsgi.prio) == B_BAD_THREAD_ID) {
uwsgi_error("set_thread_priority()");
#else
if (setpriority(PRIO_PROCESS, 0, uwsgi.prio)) {
uwsgi_error("setpriority()");
#endif
}
else {
uwsgi_log("scheduler priority set to %d\n", uwsgi.prio);
@@ -603,7 +725,7 @@ int main(int argc, char *argv[], char *envp[]) {
sanitize_args(&uwsgi);
#ifdef UWSGI_HTTP
if (uwsgi.http) {
if (uwsgi.http && !uwsgi.is_a_reload) {
char *tcp_port = strchr(uwsgi.http, ':');
if (tcp_port) {
uwsgi.http_server_port = tcp_port+1;
@@ -623,29 +745,33 @@ int main(int argc, char *argv[], char *envp[]) {
}
if (!uwsgi.socket_name) {
uwsgi.socket_name = malloc(64);
if (!uwsgi.socket_name) {
uwsgi_error("malloc()");
exit(1);
}
snprintf(uwsgi.socket_name, 64, "%d_%d.sock", (int) time(NULL), (int) getpid());
uwsgi_log("using %s as uwsgi protocol socket\n", uwsgi.socket_name);
snprintf(uwsgi.socket_name, 64, "%d_%d.sock", (int) time(NULL), (int) getpid());
uwsgi_log("using %s as uwsgi protocol socket\n", uwsgi.socket_name);
}
if (uwsgi.http_only) {
signal(SIGINT, (void *) &end_me);
http_loop(&uwsgi);
// never here
exit(1);
}
pid_t http_pid = fork();
http_pid = fork();
if (http_pid > 0) {
signal(SIGINT, (void *) &end_me);
masterpid = http_pid;
http_loop(&uwsgi);
// never here
exit(1);
@@ -654,6 +780,20 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi_error("fork()");
exit(1);
}
if (uwsgi.pidfile && !uwsgi.is_a_reload) {
uwsgi_log( "updating pidfile with pid %d\n", (int) getpid());
pidfile = fopen(uwsgi.pidfile, "w");
if (!pidfile) {
uwsgi_error("fopen");
exit(1);
}
if (fprintf(pidfile, "%d\n", (int) getpid()) < 0) {
uwsgi_log( "could not update pidfile.\n");
}
fclose(pidfile);
}
close(uwsgi.http_fd);
}
#endif
@@ -661,9 +801,9 @@ int main(int argc, char *argv[], char *envp[]) {
if (uwsgi.async > 1) {
if (!getrlimit(RLIMIT_NOFILE, &uwsgi.rl)) {
if (uwsgi.rl.rlim_cur < uwsgi.async) {
if ( (unsigned long) uwsgi.rl.rlim_cur < (unsigned long) uwsgi.async) {
uwsgi_log("- your current max open files limit is %lu, this is lower than requested async cores !!! -\n", (unsigned long) uwsgi.rl.rlim_cur);
if (uwsgi.rl.rlim_cur < uwsgi.rl.rlim_max && uwsgi.rl.rlim_max > uwsgi.async) {
if (uwsgi.rl.rlim_cur < uwsgi.rl.rlim_max && (unsigned long) uwsgi.rl.rlim_max > (unsigned long) uwsgi.async) {
unsigned long tmp_nofile = (unsigned long) uwsgi.rl.rlim_cur ;
uwsgi.rl.rlim_cur = uwsgi.async;
if (!setrlimit(RLIMIT_NOFILE, &uwsgi.rl)) {
@@ -857,7 +997,6 @@ int main(int argc, char *argv[], char *envp[]) {
char *tcp_port = strchr(uwsgi.socket_name, ':');
if (tcp_port == NULL) {
uwsgi.serverfd = bind_to_unix(uwsgi.socket_name, uwsgi.listen_queue, uwsgi.chmod_socket, uwsgi.abstract_socket);
uwsgi.bind_to_unix = 1;
}
else {
uwsgi.serverfd = bind_to_tcp(uwsgi.socket_name, uwsgi.listen_queue, tcp_port);
@@ -901,8 +1040,7 @@ int main(int argc, char *argv[], char *envp[]) {
#ifdef UWSGI_DEBUG
int so_bufsize ;
socklen_t so_bufsize_len = sizeof(int) ;
so_bufsize_len = sizeof(int) ;
if (getsockopt(uwsgi.serverfd, SOL_SOCKET, SO_RCVBUF, &so_bufsize, &so_bufsize_len)) {
uwsgi_error("getsockopt()");
}
@@ -1019,10 +1157,13 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi_paste_config();
}
#endif
else if (uwsgi.eval != NULL) {
uwsgi_eval_config(uwsgi.eval);
}
// parse xml anyway
#ifdef UWSGI_XML
if (uwsgi.xml_config != NULL) {
if (uwsgi.xml_round2 && uwsgi.xml_config != NULL) {
uwsgi_xml_config(uwsgi.wsgi_req, NULL);
}
#endif
@@ -1160,7 +1301,7 @@ int main(int argc, char *argv[], char *envp[]) {
memcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, 72);
}
else {
strlcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, 73);
memcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, strlen(uwsgi.snmp_community) + 1);
}
}
uwsgi_log( "filling SNMP table...");
@@ -1174,8 +1315,7 @@ int main(int argc, char *argv[], char *envp[]) {
#endif
#ifdef UWSGI_UDP
PyObject *udp_callable = PyDict_GetItemString(uwsgi.embedded_dict, "udp_callable");
PyObject *udp_callable_args = NULL;
udp_callable = PyDict_GetItemString(uwsgi.embedded_dict, "udp_callable");
if (udp_callable) {
udp_callable_args = PyTuple_New(3);
}
@@ -1218,11 +1358,9 @@ int main(int argc, char *argv[], char *envp[]) {
}
#endif
uwsgi_log( "binary reloading uWSGI...\n");
if (cwd) {
if (chdir(cwd)) {
uwsgi_error("chdir()");
exit(1);
}
if (chdir(uwsgi.cwd)) {
uwsgi_error("chdir()");
exit(1);
}
/* check fd table (a module can obviosly open some fd on initialization...) */
uwsgi_log( "closing all fds > 2 (_SC_OPEN_MAX = %ld)...\n", sysconf(_SC_OPEN_MAX));
@@ -1247,7 +1385,7 @@ int main(int argc, char *argv[], char *envp[]) {
exit(1);
}
int master_has_children = 0;
if (uwsgi.numproc > 0 ) {
master_has_children = 1;
@@ -1319,7 +1457,7 @@ int main(int argc, char *argv[], char *envp[]) {
PyTuple_SetItem(udp_callable_args, 0, PyString_FromString(udp_client_addr));
PyTuple_SetItem(udp_callable_args, 1, PyInt_FromLong(ntohs(udp_client.sin_port)));
PyTuple_SetItem(udp_callable_args, 2, PyString_FromStringAndSize(uwsgi.wsgi_req->buffer, rlen));
PyObject *udp_response = python_call(udp_callable, udp_callable_args, 0);
udp_response = python_call(udp_callable, udp_callable_args, 0);
if (udp_response) {
Py_DECREF(udp_response);
}
@@ -1370,6 +1508,9 @@ int main(int argc, char *argv[], char *envp[]) {
/* TODO */
/* then brutally kill the worker */
uwsgi_log("*** HARAKIRI ON WORKER %d (pid: %d) ***\n", i, uwsgi.workers[i].pid);
kill(uwsgi.workers[i].pid, SIGUSR2);
// allow SIGUSR2 to be delivered
sleep(1);
kill(uwsgi.workers[i].pid, SIGKILL);
// to avoid races
uwsgi.workers[i].harakiri = 0;
@@ -1430,6 +1571,21 @@ int main(int argc, char *argv[], char *envp[]) {
}
}
}
#endif
// TODO rewrite without using exit code (targeted at 0.9.7)
#ifdef __sun__
/* horrible hack... what the FU*K is doing Solaris ??? */
if (WIFSIGNALED(waitpid_status)) {
if (uwsgi.to_heaven) {
ready_to_reload++;
continue;
}
else if (uwsgi.to_hell) {
ready_to_die++;
continue;
}
}
#endif
/* check for reloading */
if (WIFEXITED(waitpid_status)) {
@@ -1443,6 +1599,21 @@ int main(int argc, char *argv[], char *envp[]) {
}
}
uwsgi.mywid = find_worker_id(diedpid);
if (uwsgi.mywid <= 0) {
if (WIFEXITED(waitpid_status)) {
uwsgi_log("subprocess %d exited with code %d\n", (int) diedpid, WEXITSTATUS(waitpid_status));
}
else if (WIFSIGNALED(waitpid_status)) {
uwsgi_log("subprocess %d exited by signal %d\n", (int) diedpid, WTERMSIG(waitpid_status));
}
else if (WIFSTOPPED(waitpid_status)) {
uwsgi_log("subprocess %d stopped\n", (int) diedpid);
}
continue;
}
uwsgi_log( "DAMN ! process %d died :( trying respawn ...\n", diedpid);
gettimeofday(&last_respawn, NULL);
if (last_respawn.tv_sec == respawn_delta) {
@@ -1452,7 +1623,6 @@ int main(int argc, char *argv[], char *envp[]) {
}
gettimeofday(&last_respawn, NULL);
respawn_delta = last_respawn.tv_sec;
uwsgi.mywid = find_worker_id(diedpid);
pid = fork();
if (pid == 0) {
uwsgi.mypid = getpid();
@@ -1490,11 +1660,11 @@ int main(int argc, char *argv[], char *envp[]) {
}
// reinitialize the random seed (thanks Jonas Borgström)
PyObject *random_module = PyImport_ImportModule("random");
random_module = PyImport_ImportModule("random");
if (random_module) {
PyObject *random_dict = PyModule_GetDict(random_module);
random_dict = PyModule_GetDict(random_module);
if (random_dict) {
PyObject *random_seed = PyDict_GetItemString(random_dict, "seed");
random_seed = PyDict_GetItemString(random_dict, "seed");
if (random_seed) {
PyObject *random_args = PyTuple_New(1);
// pass no args
@@ -1540,6 +1710,8 @@ int main(int argc, char *argv[], char *envp[]) {
signal(SIGUSR1, (void *) &stats);
signal(SIGUSR2, (void *) &what_i_am_doing);
signal(SIGPIPE, (void *) &warn_pipe);
@@ -1604,6 +1776,9 @@ int main(int argc, char *argv[], char *envp[]) {
}
#endif
// re-initialize wsgi_req (can be full of init_uwsgi_app data)
memset(uwsgi.wsgi_requests, 0, sizeof(struct wsgi_request) * uwsgi.async);
while (uwsgi.workers[uwsgi.mywid].manage_next_request) {
@@ -1634,7 +1809,7 @@ int main(int argc, char *argv[], char *envp[]) {
for(i=0; i<uwsgi.async_nevents;i++) {
if (uwsgi.async_events[i].ASYNC_FD == uwsgi.serverfd) {
if ( (int) uwsgi.async_events[i].ASYNC_FD == uwsgi.serverfd) {
uwsgi.wsgi_req = find_first_available_wsgi_req(&uwsgi);
if (uwsgi.wsgi_req == NULL) {
@@ -1861,6 +2036,23 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
memset(wi, 0, sizeof(struct uwsgi_app));
// dynamic chdir ?
if (uwsgi.wsgi_req->chdir_len > 0) {
wi->chdir = malloc(uwsgi.wsgi_req->chdir_len + 1);
if (wi->chdir == NULL) {
uwsgi_error("malloc()");
}
memcpy(wi->chdir, uwsgi.wsgi_req->chdir, uwsgi.wsgi_req->chdir_len);
wi->chdir[uwsgi.wsgi_req->chdir_len] = 0;
#ifdef UWSGI_DEBUG
uwsgi_debug("chdir to %s\n", wi->chdir);
#endif
if (chdir(wi->chdir)) {
uwsgi_error("chdir()");
}
}
if (uwsgi.single_interpreter == 0) {
wi->interpreter = Py_NewInterpreter();
if (!wi->interpreter) {
@@ -1878,15 +2070,17 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
uwsgi_log( "interpreter for app %d initialized.\n", id);
}
if (uwsgi.eval) {
wi->wsgi_callable = my_callable;
Py_INCREF(my_callable);
}
#ifdef UWSGI_PASTE
if (uwsgi.paste) {
else if (uwsgi.paste) {
wi->wsgi_callable = my_callable;
Py_INCREF(my_callable);
}
else if (uwsgi.wsgi_file) {
#else
if (uwsgi.wsgi_file) {
#endif
else if (uwsgi.wsgi_file) {
wi->wsgi_callable = my_callable;
Py_INCREF(my_callable);
}
@@ -1894,6 +2088,17 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
if (uwsgi.wsgi_config == NULL) {
if (uwsgi.wsgi_req->wsgi_script_len > 0) {
uwsgi.wsgi_req->wsgi_callable = strchr(uwsgi.wsgi_req->wsgi_script, ':');
if (uwsgi.wsgi_req->wsgi_callable) {
uwsgi.wsgi_req->wsgi_callable[0] = 0;
uwsgi.wsgi_req->wsgi_callable++;
uwsgi.wsgi_req->wsgi_callable_len = uwsgi.wsgi_req->wsgi_script_len - strlen(uwsgi.wsgi_req->wsgi_script) - 1;
uwsgi.wsgi_req->wsgi_script_len = strlen(uwsgi.wsgi_req->wsgi_script);
}
else {
uwsgi.wsgi_req->wsgi_callable = "application";
uwsgi.wsgi_req->wsgi_callable_len = 11;
}
memcpy(tmpstring, uwsgi.wsgi_req->wsgi_script, uwsgi.wsgi_req->wsgi_script_len);
wsgi_module = PyImport_ImportModule(tmpstring);
if (!wsgi_module) {
@@ -1904,8 +2109,6 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
}
return -1;
}
uwsgi.wsgi_req->wsgi_callable = "application";
uwsgi.wsgi_req->wsgi_callable_len = 11;
}
else {
memcpy(tmpstring, uwsgi.wsgi_req->wsgi_module, uwsgi.wsgi_req->wsgi_module_len);
@@ -1955,6 +2158,7 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
if (!wi->wsgi_callable) {
PyErr_Print();
uwsgi_log("unable to find \"%s\" callable\n", tmpstring);
if (uwsgi.single_interpreter == 0) {
Py_EndInterpreter(wi->interpreter);
PyThreadState_Swap(uwsgi.main_thread);
@@ -2207,6 +2411,72 @@ void uwsgi_paste_config() {
#endif
void uwsgi_eval_config(char *code) {
int ret;
PyObject *wsgi_eval_dict, *wsgi_eval_module, *wsgi_eval_callable;
struct _node *wsgi_eval_node = NULL;
PyObject *wsgi_compiled_node ;
uwsgi.single_interpreter = 1;
wsgi_eval_node = PyParser_SimpleParseString(code, Py_file_input);
if (!wsgi_eval_node) {
PyErr_Print();
uwsgi_log( "failed to parse <eval> code\n");
exit(1);
}
wsgi_compiled_node = (PyObject *) PyNode_Compile(wsgi_eval_node, "uwsgi_eval_config");
if (!wsgi_compiled_node) {
PyErr_Print();
uwsgi_log( "failed to compile eval code\n");
exit(1);
}
wsgi_eval_module = PyImport_ExecCodeModule("uwsgi_eval_config", wsgi_compiled_node);
if (!wsgi_eval_module) {
PyErr_Print();
exit(1);
}
Py_DECREF(wsgi_compiled_node);
wsgi_eval_dict = PyModule_GetDict(wsgi_eval_module);
if (!wsgi_eval_dict) {
PyErr_Print();
exit(1);
}
if (uwsgi.callable) {
wsgi_eval_callable = PyDict_GetItemString(wsgi_eval_dict, uwsgi.callable);
}
else {
wsgi_eval_callable = PyDict_GetItemString(wsgi_eval_dict, "application");
}
if (!wsgi_eval_callable) {
PyErr_Print();
uwsgi_log( "unable to find wsgi callable in your code\n");
exit(1);
}
if (!PyFunction_Check(wsgi_eval_callable) && !PyCallable_Check(wsgi_eval_callable)) {
uwsgi_log( "you must define a callable object in your code\n");
exit(1);
}
ret = init_uwsgi_app(NULL, wsgi_eval_callable);
}
/* trying to emulate Graham's mod_wsgi, this will allows easy and fast migrations */
void uwsgi_wsgi_file_config() {
@@ -2284,21 +2554,30 @@ void uwsgi_wsgi_config(char *filename) {
PyObject *app_list;
int ret;
Py_ssize_t i;
PyObject *app_mnt, *app_app;
PyObject *app_mnt, *app_app = NULL;
FILE *uwsgifile;
char *quick_callable = NULL;
PyObject *uwsgi_compiled_node;
struct _node *uwsgi_file_node;
PyObject *tmp_callable;
uwsgi.single_interpreter = 1;
if (filename) {
if (uwsgi.callable) {
quick_callable = uwsgi.callable ;
}
uwsgifile = fopen(filename, "r");
if (!uwsgifile) {
uwsgi_error("fopen()");
exit(1);
}
struct _node *uwsgi_file_node = PyParser_SimpleParseFile(uwsgifile, filename, Py_file_input);
uwsgi_file_node = PyParser_SimpleParseFile(uwsgifile, filename, Py_file_input);
if (!uwsgi_file_node) {
PyErr_Print();
uwsgi_log( "failed to parse wsgi file %s\n", filename);
@@ -2307,7 +2586,7 @@ void uwsgi_wsgi_config(char *filename) {
fclose(uwsgifile);
PyObject *uwsgi_compiled_node = (PyObject *) PyNode_Compile(uwsgi_file_node, filename);
uwsgi_compiled_node = (PyObject *) PyNode_Compile(uwsgi_file_node, filename);
if (!uwsgi_compiled_node) {
PyErr_Print();
@@ -2326,10 +2605,15 @@ void uwsgi_wsgi_config(char *filename) {
}
else {
quick_callable = strchr(uwsgi.wsgi_config, ':');
if (quick_callable) {
quick_callable[0] = 0 ;
quick_callable++;
if (uwsgi.callable) {
quick_callable = uwsgi.callable ;
}
else {
quick_callable = strchr(uwsgi.wsgi_config, ':');
if (quick_callable) {
quick_callable[0] = 0 ;
quick_callable++;
}
}
wsgi_module = PyImport_ImportModule(uwsgi.wsgi_config);
@@ -2339,6 +2623,7 @@ void uwsgi_wsgi_config(char *filename) {
}
}
wsgi_dict = PyModule_GetDict(wsgi_module);
if (!wsgi_dict) {
PyErr_Print();
@@ -2395,8 +2680,19 @@ void uwsgi_wsgi_config(char *filename) {
}
else {
// quick callable -> thanks gunicorn for the idea
app_app = PyDict_GetItemString(wsgi_dict, quick_callable);
if (app_app) {
// we have extended the concept a bit...
if (quick_callable[strlen(quick_callable) -2 ] == '(' && quick_callable[strlen(quick_callable) -1] ==')') {
quick_callable[strlen(quick_callable) -2 ] = 0 ;
tmp_callable = PyDict_GetItemString(wsgi_dict, quick_callable);
if (tmp_callable) {
app_app = python_call(tmp_callable, PyTuple_New(0), 0);
}
}
else {
app_app = PyDict_GetItemString(wsgi_dict, quick_callable);
}
if (app_app) {
applications = PyDict_New();
if (!applications) {
uwsgi_log( "could not initialize applications dictionary\n");
@@ -2407,11 +2703,11 @@ void uwsgi_wsgi_config(char *filename) {
uwsgi_log( "unable to set default application\n");
exit(1);
}
}
else {
}
else {
uwsgi_log( "\"%s\" callable not found.\n", quick_callable);
exit(1);
}
}
}
if (!PyDict_Check(applications)) {
@@ -2485,7 +2781,6 @@ void init_uwsgi_embedded_module() {
PyObject *new_uwsgi_module, *zero;
int i;
/* initialize for stats */
uwsgi.workers_tuple = PyTuple_New(uwsgi.numproc);
for (i = 0; i < uwsgi.numproc; i++) {
@@ -2583,6 +2878,19 @@ void init_uwsgi_embedded_module() {
exit(1);
}
if (uwsgi.is_a_reload) {
if (PyDict_SetItemString(uwsgi.embedded_dict, "is_a_reload", Py_True)) {
PyErr_Print();
exit(1);
}
}
else {
if (PyDict_SetItemString(uwsgi.embedded_dict, "is_a_reload", Py_False)) {
PyErr_Print();
exit(1);
}
}
uwsgi.embedded_args = PyTuple_New(2);
if (!uwsgi.embedded_args) {
PyErr_Print();
@@ -2616,7 +2924,7 @@ void init_uwsgi_embedded_module() {
#endif
#ifdef UWSGI_PROXY
pid_t proxy_start(has_master) {
pid_t proxy_start(int has_master) {
pid_t pid;
@@ -2694,6 +3002,15 @@ void manage_opt(int i, char *optarg) {
case LONG_ARGS_CHDIR2:
uwsgi.chdir2 = optarg;
break;
case LONG_ARGS_PING:
uwsgi.ping = optarg;
break;
case LONG_ARGS_PING_TIMEOUT:
uwsgi.ping_timeout = atoi(optarg);
break;
case LONG_ARGS_CALLABLE:
uwsgi.callable = optarg;
break;
#ifdef UWSGI_HTTP
case LONG_ARGS_HTTP:
uwsgi.http = optarg;
@@ -2811,6 +3128,17 @@ void manage_opt(int i, char *optarg) {
case LONG_ARGS_ERLANG_COOKIE:
uwsgi.erlang_cookie = optarg;
break;
#endif
#ifdef UWSGI_HTTP
case LONG_ARGS_HTTP_VAR:
if (uwsgi.http_vars_cnt < 63) {
uwsgi.http_vars[uwsgi.http_vars_cnt] = optarg;
uwsgi.http_vars_cnt++;
}
else {
uwsgi_log( "you can specify at most 64 --http-var options\n");
}
break;
#endif
case LONG_ARGS_PYTHONPATH:
if (uwsgi.python_path_cnt < 63) {
@@ -2841,6 +3169,36 @@ void manage_opt(int i, char *optarg) {
case LONG_ARGS_INI:
uwsgi.ini = optarg;
break;
case LONG_ARGS_EVAL_CONFIG:
uwsgi.eval = optarg;
break;
#ifdef UWSGI_PASTE
case LONG_ARGS_INI_PASTE:
uwsgi.ini = optarg;
if (uwsgi.ini[0] != '/') {
uwsgi.paste = malloc( 7 + strlen(uwsgi.cwd) + 1 + strlen(uwsgi.ini) + 1);
if (uwsgi.paste == NULL) {
uwsgi_error("malloc()");
exit(1);
}
memset(uwsgi.paste, 0, 7 + strlen(uwsgi.cwd) + strlen(uwsgi.ini) + 1);
memcpy(uwsgi.paste, "config:", 7);
memcpy(uwsgi.paste + 7, uwsgi.cwd, strlen(uwsgi.cwd));
uwsgi.paste[7 + strlen(uwsgi.cwd)] = '/';
memcpy(uwsgi.paste + 7 + strlen(uwsgi.cwd) + 1, uwsgi.ini, strlen(uwsgi.ini));
}
else {
uwsgi.paste = malloc( 7 + strlen(uwsgi.ini) + 1);
if (uwsgi.paste == NULL) {
uwsgi_error("malloc()");
exit(1);
}
memset(uwsgi.paste, 0, 7 + strlen(uwsgi.ini) + 1);
memcpy(uwsgi.paste, "config:", 7);
memcpy(uwsgi.paste + 7, uwsgi.ini, strlen(uwsgi.ini));
}
break;
#endif
#endif
#ifdef UWSGI_PASTE
case LONG_ARGS_PASTE:
@@ -2989,7 +3347,7 @@ void manage_opt(int i, char *optarg) {
\t-v|--max-vars <n>\t\tset maximum number of vars/headers to <n>\n\
\t-A|--sharedarea <n>\t\tcreate a shared memory area of <n> pages\n\
\t-c|--cgi-mode\t\t\tset cgi mode\n\
\t-C|--chmod-socket\t\tchmod socket to 666\n\
\t-C|--chmod-socket[=NNN]\t\tchmod socket to 666 or NNN\n\
\t-P|--profiler\t\t\tenable profiler\n\
\t-m|--memory-report\t\tenable memory usage report\n\
\t-i|--single-interpreter\t\tsingle interpreter mode\n\
@@ -3002,34 +3360,67 @@ void manage_opt(int i, char *optarg) {
\t-R|--max-requests\t\tmaximum number of requests for each worker\n\
\t-j|--test\t\t\ttest if uWSGI can import a module\n\
\t-Q|--spooler <dir>\t\trun the spooler on directory <dir>\n\
\t--callable <callable>\t\tset the callable (default 'application')\n\
\t--pidfile <file>\t\twrite the masterpid to <file>\n\
\t--chroot <dir>\t\t\tchroot to directory <dir> (only root)\n\
\t--gid <id>\t\t\tsetgid to <id> (only root)\n\
\t--uid <id>\t\t\tsetuid to <id> (only root)\n\
\t--gid <id/groupname>\t\tsetgid to <id/groupname> (only root)\n\
\t--uid <id/username>\t\tsetuid to <id/username> (only root)\n\
\t--chdir <dir>\t\t\tchdir to <dir> before app loading\n\
\t--chdir2 <dir>\t\t\tchdir to <dir> after module loading\n\
\t--no-server\t\t\tinitialize the uWSGI server then exit. Useful for testing and using uwsgi embedded module\n\
\t--no-defer-accept\t\tdisable the no-standard way to defer the accept() call (TCP_DEFER_ACCEPT, SO_ACCEPTFILTER...)\n\
\t--paste <config:/egg:>\t\tload applications using paste.deploy.loadapp()\n\
\t--check-interval <sec>\t\tset the check interval (in seconds) of the master process\n\
\t--pythonpath <dir>\t\tadd <dir> to PYTHONPATH\n\
\t--python-path <dir>\t\tadd <dir> to PYTHONPATH\n\
\t--pp <dir>\t\t\tadd <dir> to PYTHONPATH\n\
\t--pyargv <args>\t\t\tassign args to python sys.argv\n\
\t--limit-as <MB>\t\t\tlimit the address space of processes to MB megabytes\n\
\t--limit-post <bytes>\t\tlimit HTTP content_length size to <bytes>\n\
\t--post-buffering <bytes>\tbuffer HTTP POST request higher than <bytes> to disk\n\
\t--post-buffering-bufsize <b>\tset the buffer size to <b> bytes for post-buffering\n\
\t--prio <N>\t\t\tset process priority/nice to N\n\
\t--no-orphans\t\t\tautomatically kill workers on master's dead\n\
\t--udp <ip:port>\t\t\tbind master process to udp socket on ip:port\n\
\t--multicast <group>\t\tset multicast group\n\
\t--snmp\t\t\t\tenable SNMP support in the UDP server\n\
\t--snmp-community <value>\tset SNMP community code to <value>\n\
\t--erlang <name@ip>\t\tenable the Erlang server with node name <node@ip>\n\
\t--erlang-cookie <cookie>\ttset the erlang cookie to <cookie>\n\
\t--erlang-cookie <cookie>\tset the erlang cookie to <cookie>\n\
\t--nagios\t\t\tdo a nagios check\n\
\t--binary-path <bin-path>\ttset the path for the next reload of uWSGI (needed for chroot environments)\n\
\t--binary-path <bin-path>\tset the path for the next reload of uWSGI (needed for chroot environments)\n\
\t--proxy <socket>\t\trun the uwsgi proxy on socket <socket>\n\
\t--proxy-node <socket>\t\tadd the node <socket> to the proxy\n\
\t--proxy-max-connections <n>\tset the max number of concurrent connections mnaged by the proxy\n\
\t--wsgi-file <file>\t\tload the <file> wsgi file\n\
\t--file <file>\t\t\tuse python file instead of python module for configuration\n\
\t--eval <code>\t\t\tevaluate code for app configuration\n\
\t--async <n>\t\t\tenable async mode with n core\n\
\t--logto <logfile|addr>\t\tlog to file/udp\n\
\t--logdate\t\t\tadd timestamp to loglines\n\
\t--ignore-script-name\t\tdisable uWSGI management of SCRIPT_NAME\n\
\t--no-default-app\t\tdo not fallback unknown SCRIPT_NAME requests\n\
\t--ini <inifile>\t\t\tpath of ini config file\n\
\t--ini-paste <inifile>\t\tpath of ini config file that contains paste configuration\n\
\t--ldap <url>\t\t\turl of LDAP uWSGIConfig resource\n\
\t--ldap-schema\t\t\tdump uWSGIConfig LDAP schema\n\
\t--ldap-schema-ldif\t\tdump uWSGIConfig LDAP schema in LDIF format\n\
\t--grunt\t\t\t\tenable grunt workers\n\
\t--ugreen\t\t\tenable uGreen support\n\
\t--ugreen-stacksize <n>\t\tset uGreen stacksize to <n>\n\
\t--stackless\t\t\tenable usage of tasklet (only on Stackless Python)\n\
\t--no-site\t\t\tdo not import site.py on startup\n\
\t--vhost\t\t\t\tenable virtual hosting\n\
\t--routing\t\t\tenable uWSGI advanced routing\n\
\t--http <addr>\t\t\tstart embedded HTTP server on <addr>\n\
\t--http-only\t\t\tstart only the embedded HTTP server\n\
\t--http-var KEY[=VALUE]\t\tadd var KEY to uwsgi requests made by the embedded HTTP server\n\
\t--catch-exceptions\t\tprint exceptions in the browser\n\
\t--mode\t\t\t\tset configuration mode\n\
\t--env KEY=VALUE\t\t\tset environment variable\n\
\t--vacuum\t\t\tclear the environment on exit (remove UNIX sockets and pidfiles)\n\
\t--ping <addr>\t\t\tping a uWSGI server (returns 1 on failure 0 on success)\n\
\t--ping-timeout <n>\t\tset ping timeout to <n>\n\
\t--version\t\t\tprint server version\n\
\t-d|--daemonize <logfile|addr>\tdaemonize and log into <logfile> or udp <addr>\n", uwsgi.binary_path);
exit(1);
@@ -3065,7 +3456,7 @@ void uwsgi_cluster_add_node(char *nodename, int workers) {
ucn = &uwsgi.shared->nodes[i];
if (ucn->name[0] == 0) {
strlcpy(ucn->name, nodename, 101);
memcpy(ucn->name, nodename, strlen(nodename) + 1);
ucn->workers = workers;
ucn->ucn_addr.sin_family = AF_INET;
ucn->ucn_addr.sin_port = htons(atoi(tcp_port + 1));
@@ -3086,3 +3477,4 @@ void uwsgi_cluster_add_node(char *nodename, int workers) {
uwsgi_log( "unable to add node %s\n", nodename);
}
+61 -6
View File
@@ -2,7 +2,7 @@
/* indent -i8 -br -brs -brf -l0 -npsl -nip -npcs -npsl -di1 */
#define UWSGI_VERSION "0.9.6-dev"
#define UWSGI_VERSION "0.9.6.1"
#define uwsgi_error(x) uwsgi_log("%s: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__);
#define uwsgi_debug(x, ...) uwsgi_log("[uWSGI DEBUG] " x, __VA_ARGS__);
@@ -25,10 +25,7 @@
#include <sys/utsname.h>
// linux has not strlcpy
#ifdef __linux
#define strlcpy(x, y, z) strcpy(x, y)
#define strlcat(x, y, z) strcat(x, y)
#include <sys/prctl.h>
#endif
@@ -93,6 +90,10 @@
#define PRIO_MAX 20
#endif
#ifdef __HAIKU__
#define WAIT_ANY (-1)
#endif
#define MAX_PYARGV 10
#include <sys/ioctl.h>
@@ -101,11 +102,17 @@
#include <sys/sendfile.h>
#include <sys/epoll.h>
#elif defined(__sun__)
#include <sys/sendfile.h>
#include <sys/devpoll.h>
#elif defined(__HAIKU__)
#else
#include <sys/event.h>
#endif
#ifdef __HAIKU__
#include <kernel/OS.h>
#endif
#undef _XOPEN_SOURCE
#include <Python.h>
@@ -174,6 +181,13 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#define LONG_ARGS_LDAP_SCHEMA 17036
#define LONG_ARGS_LDAP 17037
#define LONG_ARGS_LDAP_SCHEMA_LDIF 17038
#define LONG_ARGS_PING 17039
#define LONG_ARGS_PING_TIMEOUT 17040
#define LONG_ARGS_INI_PASTE 17041
#define LONG_ARGS_CALLABLE 17042
#define LONG_ARGS_HTTP_VAR 17043
#define LONG_ARGS_NO_DEFAULT_APP 17044
#define LONG_ARGS_EVAL_CONFIG 17045
@@ -213,6 +227,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#endif
#elif __APPLE__
#include <libkern/OSByteOrder.h>
#elif defined(__HAIKU__)
#else
#include <machine/endian.h>
#endif
@@ -292,6 +307,7 @@ struct uwsgi_app {
#endif
int requests;
char *chdir;
};
@@ -379,6 +395,9 @@ struct wsgi_request {
char *pyhome;
uint16_t pyhome_len;
char *chdir;
uint16_t chdir_len;
int fd_closed;
int sendfile_fd;
@@ -448,13 +467,19 @@ struct uwsgi_server {
uid_t uid;
char *mode;
#ifdef UWSGI_HTTP
char *http;
char *http_server_name;
char *http_server_port;
int http_only;
int http_fd;
char *http_vars[64];
int http_vars_cnt;
#endif
int ignore_script_name;
int no_default_app;
int logdate;
int serverfd;
@@ -656,6 +681,7 @@ struct uwsgi_server {
#ifdef UWSGI_EMBED_PLUGIN_RACK
char *plugin_arg_rack;
char *plugin_arg_rails;
#endif
#endif
@@ -664,12 +690,27 @@ struct uwsgi_server {
int catch_exceptions;
int vacuum;
int bind_to_unix;
int no_server;
#ifdef UWSGI_LDAP
char *ldap;
#endif
char *ping;
int ping_timeout;
char *callable;
int xml_round2;
char *cwd;
char *eval;
int log_slow_requests;
int log_zero_headers;
int log_empty_body;
int log_high_memory;
};
struct uwsgi_cluster_node {
@@ -760,6 +801,7 @@ struct uwsgi_worker {
char *uwsgi_get_cwd(void);
void warn_pipe(void);
void what_i_am_doing(void);
void goodbye_cruel_world(void);
void gracefully_kill(void);
void reap_them_all(void);
@@ -795,8 +837,11 @@ void uwsgi_xml_config(struct wsgi_request *, struct option *);
#endif
void uwsgi_wsgi_config(char *);
#ifdef UWSGI_PASTE
void uwsgi_paste_config(void);
#endif
void uwsgi_wsgi_file_config(void);
void uwsgi_eval_config(char *);
void internal_server_error(int, char *);
@@ -1043,11 +1088,15 @@ void embed_plugins(struct uwsgi_server *);
#ifdef UWSGI_EMBED_PLUGIN_RACK
#undef UWSGI_PLUGIN_LONGOPT_RACK
#define UWSGI_PLUGIN_LONGOPT_RACK {"rack", required_argument, 0, 30007},
#define UWSGI_PLUGIN_LONGOPT_RACK {"rack", required_argument, 0, 30007},\
{"rails", required_argument, 0, 30008},
#undef LONG_ARGS_PLUGIN_EMBED_RACK
#define LONG_ARGS_PLUGIN_EMBED_RACK case 30007:\
uwsgi.plugin_arg_rack = optarg;\
break;\
case 30008:\
uwsgi.plugin_arg_rails = optarg;\
break;
#endif
@@ -1077,3 +1126,9 @@ void uwsgi_ldap_schema_dump(struct option*);
void uwsgi_ldap_schema_dump_ldif(struct option*);
void uwsgi_ldap_config(struct uwsgi_server *, struct option*);
#endif
#ifdef __clang__
int uwsgi_strncmp(char *, int , char *, int );
#else
inline int uwsgi_strncmp(char *, int , char *, int );
#endif
+165 -4
View File
@@ -258,7 +258,7 @@ PyObject *py_uwsgi_sharedarea_write(PyObject * self, PyObject * args) {
return NULL;
}
if (pos + strlen(value) >= uwsgi.page_size * uwsgi.sharedareasize) {
if (pos + (int) strlen(value) >= uwsgi.page_size * uwsgi.sharedareasize) {
Py_INCREF(Py_None);
return Py_None;
}
@@ -373,6 +373,58 @@ PyObject *py_uwsgi_spooler_freq(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_spooler_jobs(PyObject * self, PyObject * args) {
DIR *sdir;
struct dirent *dp;
char *abs_path;
struct stat sf_lstat;
PyObject *jobslist = PyList_New(0);
sdir = opendir(uwsgi.spool_dir);
if (sdir) {
while ((dp = readdir(sdir)) != NULL) {
if (!strncmp("uwsgi_spoolfile_on_", dp->d_name, 19)) {
abs_path = malloc(strlen(uwsgi.spool_dir) + 1 + strlen(dp->d_name) + 1);
if (!abs_path) {
uwsgi_error("malloc()");
closedir(sdir);
goto clear;
}
memset(abs_path, 0 , strlen(uwsgi.spool_dir) + 1 + strlen(dp->d_name) + 1);
memcpy(abs_path, uwsgi.spool_dir, strlen(uwsgi.spool_dir));
memcpy(abs_path + strlen(uwsgi.spool_dir) , "/", 1);
memcpy(abs_path + strlen(uwsgi.spool_dir) + 1, dp->d_name, strlen(dp->d_name) );
if (lstat(abs_path, &sf_lstat)) {
free(abs_path);
continue;
}
if (!S_ISREG(sf_lstat.st_mode)) {
free(abs_path);
continue;
}
if (!access(abs_path, R_OK | W_OK)) {
if (PyList_Append(jobslist, PyString_FromString(abs_path))) {
PyErr_Print();
}
}
free(abs_path);
}
}
closedir(sdir);
}
clear:
return jobslist;
}
PyObject *py_uwsgi_send_spool(PyObject * self, PyObject * args) {
PyObject *spool_dict, *spool_vars;
@@ -479,6 +531,8 @@ PyObject *py_uwsgi_send_multi_message(PyObject * self, PyObject * args) {
char *buffer;
struct uwsgi_header uh;
PyObject *arg_cluster;
PyObject *cluster_node;
PyObject *arg_host, *arg_port, *arg_message;
@@ -536,7 +590,7 @@ PyObject *py_uwsgi_send_multi_message(PyObject * self, PyObject * args) {
for (i = 0; i < clen; i++) {
multipoll[i].events = POLLIN;
PyObject *cluster_node = PyTuple_GetItem(arg_cluster, i);
cluster_node = PyTuple_GetItem(arg_cluster, i);
arg_host = PyTuple_GetItem(cluster_node, 0);
if (!PyString_Check(arg_host)) {
goto clear;
@@ -917,9 +971,10 @@ PyObject *py_uwsgi_mem(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_disconnect(PyObject * self, PyObject * args) {
uwsgi_log( "disconnecting worker %d (pid :%d) from session...\n", uwsgi.mywid, uwsgi.mypid);
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
uwsgi_log( "disconnecting worker %d (pid :%d) from session...\n", uwsgi.mywid, uwsgi.mypid);
fclose(wsgi_req->async_post);
wsgi_req->fd_closed = 1 ;
@@ -928,6 +983,110 @@ PyObject *py_uwsgi_disconnect(PyObject * self, PyObject * args) {
return Py_True;
}
PyObject *py_uwsgi_parse_file(PyObject * self, PyObject * args) {
char *filename;
int fd;
ssize_t len;
char *buffer, *ptrbuf, *bufferend, *keybuf;
uint16_t strsize = 0, keysize = 0;
struct uwsgi_header uh;
PyObject *zero;
if (!PyArg_ParseTuple(args, "s:parsefile", &filename)) {
return NULL;
}
fd = open(filename, O_RDONLY);
if (fd < 0) {
uwsgi_error("open()");
goto clear;
}
len = read(fd, &uh, 4);
if (len != 4) {
uwsgi_error("read()");
goto clear2;
}
buffer = malloc(uh.pktsize);
if (!buffer) {
uwsgi_error("malloc()");
goto clear2;
}
len = read(fd, buffer, uh.pktsize);
if (len != uh.pktsize) {
uwsgi_error("read()");
free(buffer);
goto clear2;
}
ptrbuf = buffer ;
bufferend = ptrbuf + uh.pktsize ;
if (!uh.modifier1 || uh.modifier1 == UWSGI_MODIFIER_SPOOL_REQUEST) {
zero = PyDict_New();
while (ptrbuf < bufferend) {
if (ptrbuf + 2 < bufferend) {
memcpy(&strsize, ptrbuf, 2);
#ifdef __BIG_ENDIAN__
strsize = uwsgi_swap16(strsize);
#endif
/* key cannot be null */
if (!strsize) {
uwsgi_log( "uwsgi key cannot be null.\n");
goto clear3;
}
ptrbuf += 2;
if (ptrbuf + strsize < bufferend) {
// var key
keybuf = ptrbuf;
keysize = strsize;
ptrbuf += strsize;
// value can be null (even at the end) so use <=
if (ptrbuf + 2 <= bufferend) {
memcpy(&strsize, ptrbuf, 2);
#ifdef __BIG_ENDIAN__
strsize = uwsgi_swap16(strsize);
#endif
ptrbuf += 2;
if (ptrbuf + strsize <= bufferend) {
PyDict_SetItem(zero, PyString_FromStringAndSize( keybuf, keysize ), PyString_FromStringAndSize( ptrbuf, strsize ));
ptrbuf += strsize;
}
else {
goto clear3;
}
}
else {
goto clear3;
}
}
}
else {
goto clear3;
}
}
return zero;
}
goto clear;
clear3:
Py_DECREF(zero);
clear2:
close(fd);
clear:
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_uwsgi_grunt(PyObject * self, PyObject * args) {
pid_t grunt_pid ;
@@ -978,6 +1137,7 @@ clear:
static PyMethodDef uwsgi_spooler_methods[] = {
{"send_to_spooler", py_uwsgi_send_spool, METH_VARARGS, ""},
{"set_spooler_frequency", py_uwsgi_spooler_freq, METH_VARARGS, ""},
{"spooler_jobs", py_uwsgi_spooler_jobs, METH_VARARGS, ""},
{NULL, NULL},
};
#endif
@@ -1016,6 +1176,7 @@ static PyMethodDef uwsgi_advanced_methods[] = {
#ifdef UWSGI_ASYNC
{"async_sleep", py_uwsgi_async_sleep, METH_VARARGS, ""},
#endif
{"parsefile", py_uwsgi_parse_file, METH_VARARGS, ""},
//{"call_hook", py_uwsgi_call_hook, METH_VARARGS, ""},
{NULL, NULL},
};
+46 -16
View File
@@ -28,7 +28,7 @@ STACKLESS=False
PLUGINS = []
USWALLOW=False
UNBIT=False
DEBUG=True
DEBUG=False
EMBED_PLUGINS=True
UWSGI_BIN_NAME = 'uwsgi'
UWSGI_PLUGIN_DIR = '.'
@@ -63,16 +63,46 @@ GCC = os.environ.get('CC', sysconfig.get_config_var('CC'))
if not GCC:
GCC = 'gcc'
def spcall(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
if p.wait() == 0:
if sys.version_info[0] > 2:
return p.stdout.read().rstrip().decode()
return p.stdout.read().rstrip()
else:
return None
def spcall2(cmd):
p = subprocess.Popen(cmd, shell=True, stderr=subprocess.PIPE)
if p.wait() == 0:
if sys.version_info[0] > 2:
return p.stderr.read().rstrip().decode()
return p.stderr.read().rstrip()
else:
return None
gcc_version = str(spcall2("%s -v" % GCC)).split('\n')[-1].split()[2]
gcc_major = int(gcc_version.split('.')[0])
gcc_minor = int(gcc_version.split('.')[1])
gcc_list = ['utils', 'pyutils', 'protocol', 'socket', 'logging', 'wsgi_handlers', 'wsgi_headers', 'uwsgi_handlers', 'plugins', 'uwsgi']
# large file support
try:
cflags = ['-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split()
except:
print("You need python headers to build uWSGI.")
sys.exit(1)
cflags = ['-O2', '-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split()
# add -fno-strict-aliasing only on python2 and gcc < 4.3
if (sys.version_info[0] == 2) or (gcc_major < 4) or (gcc_major == 4 and gcc_minor < 3):
cflags = cflags + ['-fno-strict-aliasing']
if gcc_major >= 4:
cflags = cflags + [ '-Wextra', '-Wno-unused-parameter', '-Wno-missing-field-initializers' ]
cflags = cflags + ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True) ]
ldflags = os.environ.get("LDFLAGS", "").split()
libs = ['-lpthread', '-rdynamic'] + sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split()
if not sysconfig.get_config_var('Py_ENABLE_SHARED'):
@@ -90,13 +120,6 @@ def depends_on(what, dep):
print("%s needs %s support." % (what, d))
sys.exit(1)
def spcall(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
if p.wait() == 0:
return p.stdout.read().rstrip().decode()
else:
return None
def add_o(x):
if x == 'uwsgi':
@@ -236,7 +259,7 @@ def unbit_setup():
def parse_vars():
global UGREEN
global UGREEN, ASYNC, PROXY
version = sys.version_info
uver = "%d.%d" % (version[0], version[1])
@@ -256,9 +279,16 @@ def parse_vars():
if uwsgi_os in kvm_list:
libs.append('-lkvm')
if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm':
if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm' or uwsgi_os == 'Haiku':
UGREEN = False
if uwsgi_os == 'Haiku':
ASYNC = False
PROXY = False
libs.remove('-rdynamic')
libs.remove('-lpthread')
libs.append('-lroot')
if EMBEDDED:
cflags.append('-DUWSGI_EMBEDDED')
gcc_list.append('uwsgi_pymodule')
+38 -14
View File
@@ -73,14 +73,24 @@ PyObject *py_eventfd_write(PyObject * self, PyObject * args) {
int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
int i;
size_t post_remains = wsgi_req->post_cl;
ssize_t post_chunk;
PyObject *zero, *wsgi_socket;
PyObject *pydictkey, *pydictvalue;
static PyObject *uwsgi_version = NULL;
char *path_info;
struct uwsgi_app *wi ;
int tmp_stderr;
if (uwsgi_version == NULL) {
uwsgi_version = PyString_FromString(UWSGI_VERSION);
}
#ifdef UWSGI_ASYNC
if (wsgi_req->async_status == UWSGI_AGAIN) {
@@ -135,6 +145,9 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
#else
PyString_Concat(&zero, PyString_FromString("|"));
PyString_Concat(&zero, PyString_FromStringAndSize(wsgi_req->script_name, wsgi_req->script_name_len));
#ifdef UWSGI_DEBUG
uwsgi_debug("VirtualHost SCRIPT_NAME=%s\n", PyString_AsString(zero));
#endif
#endif
}
else {
@@ -145,15 +158,11 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
if (PyDict_Contains(uwsgi->py_apps, zero)) {
wsgi_req->app_id = PyInt_AsLong(PyDict_GetItem(uwsgi->py_apps, zero));
}
else {
else if (wsgi_req->script_name_len > 1 || uwsgi->default_app < 0 || uwsgi->vhost) {
/* unavailable app for this SCRIPT_NAME */
wsgi_req->app_id = -1;
if (wsgi_req->wsgi_script_len > 0 || (wsgi_req->wsgi_callable_len > 0 && wsgi_req->wsgi_module_len > 0)) {
if ((wsgi_req->app_id = init_uwsgi_app(NULL, NULL)) == -1) {
internal_server_error(wsgi_req->poll.fd, "wsgi application not found");
Py_DECREF(zero);
goto clear2;
}
wsgi_req->app_id = init_uwsgi_app(NULL, NULL);
}
}
@@ -165,8 +174,14 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
if (wsgi_req->app_id == -1) {
internal_server_error(wsgi_req->poll.fd, "wsgi application not found");
goto clear2;
// use default app ?
if (!uwsgi->no_default_app && uwsgi->default_app >= 0) {
wsgi_req->app_id = uwsgi->default_app ;
}
else {
internal_server_error(wsgi_req->poll.fd, "wsgi application not found");
goto clear2;
}
}
@@ -180,6 +195,14 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
// set the interpreter
PyThreadState_Swap(wi->interpreter);
if (wi->chdir) {
#ifdef UWSGI_DEBUG
uwsgi_debug("chdir to %s\n", wi->chdir);
#endif
if (chdir(wi->chdir)) {
uwsgi_error("chdir()");
}
}
}
wi->requests++;
@@ -245,20 +268,19 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
// set wsgi vars
if (uwsgi->post_buffering > 0 && wsgi_req->post_cl > uwsgi->post_buffering) {
if (uwsgi->post_buffering > 0 && wsgi_req->post_cl > (size_t) uwsgi->post_buffering) {
wsgi_req->async_post = tmpfile();
if (!wsgi_req->async_post) {
uwsgi_error("tmpfile()");
goto clear;
}
size_t post_remains = wsgi_req->post_cl;
ssize_t post_chunk;
while(post_remains > 0) {
if (uwsgi->shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
inc_harakiri(uwsgi->shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
}
if (post_remains > uwsgi->post_buffering_bufsize) {
if (post_remains > (size_t) uwsgi->post_buffering_bufsize) {
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, uwsgi->post_buffering_bufsize);
}
else {
@@ -268,7 +290,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
uwsgi_error("read()");
goto clear;
}
if (fwrite(wsgi_req->post_buffering_buf, post_chunk, 1, wsgi_req->async_post) <0) {
if (!fwrite(wsgi_req->post_buffering_buf, post_chunk, 1, wsgi_req->async_post)) {
uwsgi_error("fwrite()");
goto clear;
}
@@ -338,6 +360,8 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
PyDict_SetItemString(uwsgi->embedded_dict, "env", wsgi_req->async_environ);
PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.uwsgi.version", uwsgi_version);
#ifdef UWSGI_ROUTING
uwsgi_log("routing %d routes %d\n", uwsgi->routing, uwsgi->nroutes);
@@ -395,7 +419,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
sorry that is a hack to avoid the rewrite of PyErr_Print
temporarily map (using dup2) stderr to wsgi_req->poll.fd
*/
int tmp_stderr = dup(2);
tmp_stderr = dup(2);
if (tmp_stderr < 0) {
uwsgi_error("dup()");
goto clear;
+35 -3
View File
@@ -23,6 +23,8 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
char *colon ;
char *xml_id ;
colon = strchr(uwsgi.xml_config, ':');
if (colon) {
colon[0] = 0 ;
@@ -54,8 +56,10 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
element = NULL ;
if (node->type == XML_ELEMENT_NODE) {
if (!strcmp((char *) node->name, "uwsgi")) {
if (colon) {
if (strcmp(colon, (char *) xmlGetProp(node, (const xmlChar *) "id")) ) {
xml_id = (char *) xmlGetProp(node, (const xmlChar *) "id");
if (colon && xml_id) {
if ( strcmp(colon, xml_id) ) {
continue;
}
}
@@ -75,7 +79,28 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
if (long_options) {
// first check for options
for (node = element->children; node; node = node->next) {
if (node->type == XML_ELEMENT_NODE) {
if (node->type == XML_CDATA_SECTION_NODE) {
if (node->content) {
manage_opt(LONG_ARGS_EVAL_CONFIG, (char *) node->content);
}
}
else if (node->type == XML_ELEMENT_NODE) {
if (!strcmp((char *) node->name, "app")) {
uwsgi.xml_round2 = 1 ;
continue;
}
#ifdef UWSGI_ROUTING
if (!strcmp((char *) node->name, "route")) {
uwsgi.xml_round2 = 1 ;
continue;
}
if (!strcmp((char *) node->name, "routing")) {
uwsgi.xml_round2 = 1 ;
continue;
}
#endif
lopt = long_options;
while ((aopt = lopt)) {
if (!aopt->name)
@@ -100,6 +125,13 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
}
}
xml_id = (char *) xmlGetProp(node, (const xmlChar *) "id") ;
if (colon && xml_id) {
if (strcmp(colon, xml_id)) {
goto next;
}
}
if (aopt->flag) {
*aopt->flag = aopt->val;
}