Compare commits

...
39 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
26 changed files with 732 additions and 138 deletions
+2
View File
@@ -6,3 +6,5 @@ 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
+23
View File
@@ -1,3 +1,26 @@
*** 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]
+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);
}
}
+27 -14
View File
@@ -174,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;
@@ -197,14 +195,17 @@ static void *http_request(void *u_h_r)
uint16_t ulen;
ptr = tmp_buf;
char *ptr = tmp_buf;
int qs = 0;
up = uwsgipkt;
char *up = uwsgipkt;
char *watermark = up + 4096 ;
char *watermark2 = tmp_buf + 4096 ;
int path_info_len;
char *ip;
up[0] = 0;
up[3] = 0;
@@ -216,7 +217,7 @@ 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] == ' ') {
@@ -230,7 +231,7 @@ static void *http_request(void *u_h_r)
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;
@@ -301,7 +302,7 @@ static void *http_request(void *u_h_r)
up = add_uwsgi_var(up, "SCRIPT_NAME", 11, "", 0, 0, watermark);
char *ip = inet_ntoa(ur->c_addr.sin_addr);
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);
@@ -325,14 +326,20 @@ static void *http_request(void *u_h_r)
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;
}
@@ -342,12 +349,16 @@ 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);
}
@@ -381,4 +392,6 @@ clear:
free(ur);
pthread_exit(NULL);
return NULL;
}
+4 -4
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;
@@ -146,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)) {
@@ -172,8 +172,8 @@ void uwsgi_ini_config(char *file, struct option *long_options) {
}
ini += (ini_line - ini);
sb.st_size -= (ini_line - ini);
ini += (ini_line - ini);
}
+6 -6
View File
@@ -10,7 +10,7 @@ void ldap2uwsgi(char *ldapname, char *uwsginame) {
int i;
for(i=0;i<strlen(ldapname);i++) {
for(i=0;i< (int) strlen(ldapname);i++) {
if (isupper( (int)ldapname[i])) {
*ptr++= '-';
*ptr++= tolower( (int) ldapname[i]);
@@ -28,7 +28,7 @@ int calc_ldap_name(char *name) {
int i;
int counter = 0;
for(i=0;i<strlen(name);i++) {
for(i=0;i< (int)strlen(name);i++) {
if (isupper( (int) name[i])) {
counter++;
}
@@ -70,7 +70,7 @@ 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( (int) aopt->name[i]));
@@ -110,7 +110,7 @@ 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( (int) aopt->name[i]));
@@ -160,7 +160,7 @@ 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( (int) aopt->name[i]));
@@ -200,7 +200,7 @@ 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( (int) aopt->name[i]));
+12 -1
View File
@@ -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);
+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, " ");
+2 -2
View File
@@ -63,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) {
@@ -106,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");
+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',
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"
+39 -4
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++;
}
+6 -1
View File
@@ -39,11 +39,16 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
uws_addr->sun_family = AF_UNIX;
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()");
+8 -5
View File
@@ -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);
+29 -7
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,6 +407,18 @@ 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");
@@ -422,7 +436,7 @@ 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 ;
}
@@ -513,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);
}
+243 -34
View File
@@ -83,6 +83,7 @@ static struct option long_options[] = {
{"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},
@@ -105,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
@@ -132,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
@@ -220,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() {
@@ -323,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, ""} };
@@ -421,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;
@@ -428,6 +466,16 @@ 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);
@@ -444,7 +492,7 @@ int main(int argc, char *argv[], char *envp[]) {
#ifdef UWSGI_DEBUG
/* get system information */
struct utsname uuts;
if (uname(&uuts)) {
uwsgi_error("uname()");
}
@@ -467,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;
@@ -487,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);
@@ -638,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);
@@ -686,15 +745,20 @@ 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);
}
@@ -704,10 +768,10 @@ int main(int argc, char *argv[], char *envp[]) {
exit(1);
}
pid_t http_pid = fork();
http_pid = fork();
if (http_pid > 0) {
masterpid = http_pid;
masterpid = http_pid;
http_loop(&uwsgi);
// never here
exit(1);
@@ -737,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)) {
@@ -976,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()");
}
@@ -1094,6 +1157,9 @@ 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
@@ -1249,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);
}
@@ -1320,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;
@@ -1392,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);
}
@@ -1443,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;
@@ -1531,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) {
@@ -1540,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();
@@ -1578,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
@@ -1628,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);
@@ -1692,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) {
@@ -1722,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) {
@@ -1949,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) {
@@ -1966,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);
}
@@ -1982,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) {
@@ -1992,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);
@@ -2043,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);
@@ -2295,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() {
@@ -2377,6 +2559,10 @@ void uwsgi_wsgi_config(char *filename) {
char *quick_callable = NULL;
PyObject *uwsgi_compiled_node;
struct _node *uwsgi_file_node;
PyObject *tmp_callable;
uwsgi.single_interpreter = 1;
if (filename) {
@@ -2391,7 +2577,7 @@ void uwsgi_wsgi_config(char *filename) {
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);
@@ -2400,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();
@@ -2437,6 +2623,7 @@ void uwsgi_wsgi_config(char *filename) {
}
}
wsgi_dict = PyModule_GetDict(wsgi_module);
if (!wsgi_dict) {
PyErr_Print();
@@ -2496,12 +2683,13 @@ void uwsgi_wsgi_config(char *filename) {
// 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 ;
PyObject *tmp_callable = PyDict_GetItemString(wsgi_dict, quick_callable);
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) {
@@ -2593,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++) {
@@ -2691,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();
@@ -2724,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;
@@ -2969,6 +3169,10 @@ 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] != '/') {
@@ -2995,6 +3199,7 @@ void manage_opt(int i, char *optarg) {
}
break;
#endif
#endif
#ifdef UWSGI_PASTE
case LONG_ARGS_PASTE:
uwsgi.paste = optarg;
@@ -3167,6 +3372,8 @@ void manage_opt(int i, char *optarg) {
\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\
@@ -3179,18 +3386,20 @@ void manage_opt(int i, char *optarg) {
\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\
+35 -1
View File
@@ -2,7 +2,7 @@
/* indent -i8 -br -brs -brf -l0 -npsl -nip -npcs -npsl -di1 */
#define UWSGI_VERSION "0.9.6"
#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__);
@@ -90,6 +90,10 @@
#define PRIO_MAX 20
#endif
#ifdef __HAIKU__
#define WAIT_ANY (-1)
#endif
#define MAX_PYARGV 10
#include <sys/ioctl.h>
@@ -100,10 +104,15 @@
#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>
@@ -177,6 +186,8 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#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
@@ -216,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
@@ -295,6 +307,7 @@ struct uwsgi_app {
#endif
int requests;
char *chdir;
};
@@ -382,6 +395,9 @@ struct wsgi_request {
char *pyhome;
uint16_t pyhome_len;
char *chdir;
uint16_t chdir_len;
int fd_closed;
int sendfile_fd;
@@ -463,6 +479,7 @@ struct uwsgi_server {
#endif
int ignore_script_name;
int no_default_app;
int logdate;
int serverfd;
@@ -687,6 +704,13 @@ struct uwsgi_server {
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 {
@@ -777,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);
@@ -812,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 *);
@@ -1098,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},
};
+45 -15
View File
@@ -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;
+6 -1
View File
@@ -79,7 +79,12 @@ 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 ;