mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-10-04 16:08:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e260873338 | ||
|
|
a7822742c0 | ||
|
|
f1316ef4bb | ||
|
|
4106931175 | ||
|
|
fb5ba40f0c | ||
|
|
854e51f0ad | ||
|
|
676b43f17d | ||
|
|
48b68e6a92 | ||
|
|
61f33721e1 | ||
|
|
5c3c46598f | ||
|
|
4358036f9e | ||
|
|
54d75d92ef | ||
|
|
b1ae57c932 | ||
|
|
2636baa33f | ||
|
|
926c739517 |
@@ -2,3 +2,4 @@ d3850b52334a91d005b0fe45e1e38ba0997a1fb8 no_server mode
|
||||
2d8a617299153ed2efa6ecee7920e9d36c29e0f5 0.9.5beta1
|
||||
04722a2d0121080d14a64df097c278860db5ce8a 0.9.5rc1
|
||||
820cc64ab296dc4589ef72a33a6b804c22a0430c 0.9.5rc2
|
||||
b0db39cfad5ac6d4f00bbb3f9c57cf73206e2afb 0.9.5
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
*** may 2010 ***
|
||||
|
||||
* 0.9.5.1 [20100519] *
|
||||
|
||||
- fixed paste support
|
||||
- added a new modifier (22)
|
||||
- full support for configuration via environment variables
|
||||
- nginx_string option in nginx module
|
||||
- fix for harakiri without master
|
||||
- backported unladen swallow support for 0.9.6-dev
|
||||
- fixed address space limit detection via getrlimit()
|
||||
- http body buffering implementation
|
||||
- added --prio option (to set priority)
|
||||
- added --post-limit to limit the size of uploads
|
||||
- added --logto option to allow udp logging without daemonizing
|
||||
- applied Gentoo's packagers fixes for build system
|
||||
|
||||
* 0.9.5 [20100501] *
|
||||
|
||||
- hook based request/modifier management
|
||||
|
||||
@@ -490,7 +490,7 @@ static int uwsgi_create_env(server *srv, handler_ctx *hctx) {
|
||||
if (hctx->path_info_offset > 1) {
|
||||
uwsgi_add_var(b, "SCRIPT_NAME", 11, con->uri.path->ptr, hctx->path_info_offset);
|
||||
if (strlen(con->uri.path->ptr + hctx->path_info_offset) > 0) {
|
||||
uwsgi_add_var(b, "PATH_INFO", 9, con->request.orig_uri->ptr + hctx->path_info_offset, strlen(con->request.orig_uri->ptr + hctx->path_info_offset));
|
||||
uwsgi_add_var(b, "PATH_INFO", 9, con->uri.path->ptr + hctx->path_info_offset, strlen(con->uri.path->ptr + hctx->path_info_offset));
|
||||
}
|
||||
else {
|
||||
uwsgi_add_var(b, "PATH_INFO", 9, "/", 1);
|
||||
@@ -498,7 +498,7 @@ static int uwsgi_create_env(server *srv, handler_ctx *hctx) {
|
||||
}
|
||||
else {
|
||||
uwsgi_add_var(b, "SCRIPT_NAME", 11, "", 0) ;
|
||||
uwsgi_add_var(b, "PATH_INFO", 9, con->request.orig_uri->ptr, con->request.orig_uri->used-1) ;
|
||||
uwsgi_add_var(b, "PATH_INFO", 9, con->uri.path->ptr, strlen(con->uri.path->ptr)) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ typedef struct {
|
||||
ngx_array_t *uwsgi_lengths;
|
||||
ngx_array_t *uwsgi_values;
|
||||
|
||||
ngx_str_t uwsgi_string ;
|
||||
|
||||
u_char modifier1;
|
||||
u_char modifier2;
|
||||
|
||||
@@ -271,6 +273,14 @@ static ngx_command_t ngx_http_uwsgi_commands[] = {
|
||||
offsetof (ngx_http_uwsgi_loc_conf_t, params_source),
|
||||
NULL},
|
||||
|
||||
{ ngx_string("uwsgi_string"),
|
||||
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF |
|
||||
NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_slot,
|
||||
NGX_HTTP_LOC_CONF_OFFSET,
|
||||
offsetof(ngx_http_uwsgi_loc_conf_t, uwsgi_string),
|
||||
NULL },
|
||||
|
||||
{ngx_string ("uwsgi_pass_header"),
|
||||
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF |
|
||||
NGX_CONF_FLAG,
|
||||
@@ -538,13 +548,18 @@ ngx_http_uwsgi_create_request (ngx_http_request_t * r)
|
||||
}
|
||||
}
|
||||
|
||||
if (uwcf->uwsgi_string.data && uwcf->uwsgi_string.len) {
|
||||
uwsgi_pkt_size += uwcf->uwsgi_string.len ;
|
||||
}
|
||||
|
||||
// check here
|
||||
|
||||
/* allow custom uwsgi packet
|
||||
if (uwsgi_pkt_size > 0 && uwsgi_pkt_size < 2) {
|
||||
ngx_log_error (NGX_LOG_ALERT, r->connection->log, 0,
|
||||
"uwsgi request is too little: %uz", uwsgi_pkt_size);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
*/
|
||||
|
||||
b = ngx_create_temp_buf (r->pool, uwsgi_pkt_size + 4);
|
||||
if (b == NULL) {
|
||||
@@ -676,6 +691,11 @@ ngx_http_uwsgi_create_request (ngx_http_request_t * r)
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (uwcf->uwsgi_string.data && uwcf->uwsgi_string.len) {
|
||||
b->last = ngx_copy(b->last, uwcf->uwsgi_string.data, uwcf->uwsgi_string.len);
|
||||
}
|
||||
|
||||
if (uwcf->upstream.pass_request_body) {
|
||||
body = r->upstream->request_bufs;
|
||||
r->upstream->request_bufs = cl;
|
||||
@@ -1381,6 +1401,8 @@ ngx_http_uwsgi_merge_loc_conf (ngx_conf_t * cf, void *parent, void *child)
|
||||
ngx_conf_merge_value (conf->upstream.intercept_errors,
|
||||
prev->upstream.intercept_errors, 0);
|
||||
|
||||
ngx_conf_merge_str_value(conf->uwsgi_string, prev->uwsgi_string, "");
|
||||
|
||||
hash.max_size = 512;
|
||||
hash.bucket_size = ngx_align (64, ngx_cacheline_size);
|
||||
hash.name = "uwsgi_hide_headers_hash";
|
||||
|
||||
+17
@@ -2,6 +2,20 @@
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
static size_t get_content_length(char *buf, uint16_t size) {
|
||||
int i;
|
||||
size_t val = 0 ;
|
||||
for(i=0;i<size;i++) {
|
||||
if (buf[i] >= '0' && buf[i] <= '9') {
|
||||
val = (val*10) + (buf[i] - '0') ;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
#ifdef UWSGI_UDP
|
||||
ssize_t send_udp_message(uint8_t modifier1, char *host, char *message, uint16_t message_size) {
|
||||
|
||||
@@ -382,6 +396,9 @@ int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req)
|
||||
wsgi_req->unbit_flags = *(unsigned long long *) ptrbuf;
|
||||
}
|
||||
#endif
|
||||
else if (!strncmp("CONTENT_LENGTH", 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);
|
||||
}
|
||||
if (wsgi_req->var_cnt < uwsgi->vec_size - (4 + 1)) {
|
||||
wsgi_req->var_cnt++;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,9 @@ clear:
|
||||
}
|
||||
if (wsgi_req->async_post && !wsgi_req->fd_closed) {
|
||||
fclose(wsgi_req->async_post);
|
||||
wsgi_req->fd_closed = 1 ;
|
||||
if (!uwsgi->post_buffering || wsgi_req->post_cl <= uwsgi->post_buffering) {
|
||||
wsgi_req->fd_closed = 1 ;
|
||||
}
|
||||
}
|
||||
Py_XDECREF((PyObject *)wsgi_req->async_placeholder);
|
||||
clear2:
|
||||
|
||||
@@ -34,7 +34,7 @@ class uWSGIDistribution(Distribution):
|
||||
|
||||
|
||||
setup(name='uWSGI',
|
||||
version='0.9.5',
|
||||
version='0.9.5.1',
|
||||
description='The uWSGI server',
|
||||
author='Unbit',
|
||||
author_email='info@unbit.it',
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
def application(env, start_response):
|
||||
#print env
|
||||
print env
|
||||
start_response('200 Ok', [('Content-type', 'text/plain')])
|
||||
yield "hello world"
|
||||
yield "hello world2"
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import uwsgi
|
||||
|
||||
def ciao():
|
||||
uwsgi.start_response('200 OK', [ ('Content-type', 'text/plain') ])
|
||||
uwsgi.send(str(22+30))
|
||||
|
||||
def application(env, start_response):
|
||||
|
||||
start_response('200 Ok', [('Content-type', 'text/html')])
|
||||
|
||||
if env['REQUEST_METHOD'] == 'POST':
|
||||
print "getting file..."
|
||||
remains = int(env['CONTENT_LENGTH'])
|
||||
print remains
|
||||
buf = ''
|
||||
while remains > 0:
|
||||
if remains < 8192:
|
||||
buf = env['wsgi.input'].read(remains)
|
||||
else:
|
||||
buf = env['wsgi.input'].read(8192)
|
||||
#print len(buf)
|
||||
remains = remains - len(buf)
|
||||
#print "remains",remains
|
||||
print "upload ready"
|
||||
yield env['CONTENT_LENGTH']
|
||||
else:
|
||||
yield """
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<input type="file" name="file" />
|
||||
<input type="submit" value="invia" />
|
||||
</form>
|
||||
"""
|
||||
|
||||
@@ -27,6 +27,15 @@ uint64_t uwsgi_swap64(uint64_t x) {
|
||||
|
||||
#endif
|
||||
|
||||
void inc_harakiri(int sec) {
|
||||
if (uwsgi.master_process) {
|
||||
uwsgi.workers[uwsgi.mywid].harakiri += sec;
|
||||
}
|
||||
else {
|
||||
alarm(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] + sec);
|
||||
}
|
||||
}
|
||||
|
||||
void set_harakiri(int sec) {
|
||||
if (uwsgi.master_process) {
|
||||
if (sec == 0) {
|
||||
@@ -45,12 +54,8 @@ void set_harakiri(int sec) {
|
||||
|
||||
void daemonize(char *logfile) {
|
||||
pid_t pid;
|
||||
int fd, fdin;
|
||||
int fdin;
|
||||
|
||||
#ifdef UWSGI_UDP
|
||||
char *udp_port;
|
||||
struct sockaddr_in udp_addr;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -94,8 +99,25 @@ void daemonize(char *logfile) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* stdin */
|
||||
if (dup2(fdin, 0) < 0) {
|
||||
uwsgi_error("dup2()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
logto(logfile);
|
||||
|
||||
}
|
||||
|
||||
void logto(char *logfile) {
|
||||
|
||||
int fd ;
|
||||
|
||||
#ifdef UWSGI_UDP
|
||||
char *udp_port;
|
||||
struct sockaddr_in udp_addr;
|
||||
|
||||
udp_port = strchr(logfile, ':');
|
||||
if (udp_port) {
|
||||
udp_port[0] = 0 ;
|
||||
@@ -132,12 +154,6 @@ void daemonize(char *logfile) {
|
||||
}
|
||||
#endif
|
||||
|
||||
/* stdin */
|
||||
if (dup2(fdin, 0) < 0) {
|
||||
uwsgi_error("dup2()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
/* stdout */
|
||||
if (dup2(fd, 1) < 0) {
|
||||
@@ -152,8 +168,6 @@ void daemonize(char *logfile) {
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +295,7 @@ void uwsgi_close_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_r
|
||||
(*uwsgi->shared->after_hooks[wsgi_req->uh.modifier1]) (uwsgi, wsgi_req);
|
||||
|
||||
// leave harakiri mode
|
||||
if (uwsgi->workers[uwsgi->mywid].harakiri > 0) {
|
||||
if (uwsgi->shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(0);
|
||||
}
|
||||
|
||||
@@ -314,6 +328,10 @@ void wsgi_req_setup(struct wsgi_request *wsgi_req, int async_id) {
|
||||
wsgi_req->hvec = &uwsgi.async_hvec[wsgi_req->async_id];
|
||||
wsgi_req->buffer = uwsgi.async_buf[wsgi_req->async_id];
|
||||
|
||||
if (uwsgi.post_buffering > 0) {
|
||||
wsgi_req->post_buffering_buf = uwsgi.async_post_buf[wsgi_req->async_id];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int wsgi_req_recv(struct wsgi_request *wsgi_req) {
|
||||
@@ -382,15 +400,28 @@ void sanitize_args(struct uwsgi_server *uwsgi) {
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (uwsgi->wsgi_config) {
|
||||
uwsgi->single_interpreter = 1 ;
|
||||
}
|
||||
}
|
||||
|
||||
void env_to_arg(char *src, char *dst) {
|
||||
int i;
|
||||
int val = 0 ;
|
||||
|
||||
for(i=0;i<strlen(src);i++) {
|
||||
dst[i] = tolower(src[i]);
|
||||
if (dst[i] == '_') {
|
||||
dst[i] = '-';
|
||||
if (src[i] == '=') {
|
||||
val = 1 ;
|
||||
}
|
||||
if (val) {
|
||||
dst[i] = src[i];
|
||||
}
|
||||
else {
|
||||
dst[i] = tolower(src[i]);
|
||||
if (dst[i] == '_') {
|
||||
dst[i] = '-';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -330,11 +330,16 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
{"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},
|
||||
{"pyargv", required_argument, 0, LONG_ARGS_PYARGV},
|
||||
{"paste", required_argument, 0, LONG_ARGS_PASTE},
|
||||
{"no-server", no_argument, &no_server, 1},
|
||||
{"no-defer-accept", no_argument, &uwsgi.no_defer_accept, 1},
|
||||
{"limit-as", required_argument, 0, LONG_ARGS_LIMIT_AS},
|
||||
{"limit-post", required_argument, 0, LONG_ARGS_LIMIT_POST},
|
||||
{"prio", required_argument, 0, LONG_ARGS_PRIO},
|
||||
{"post-buffering", required_argument, 0, LONG_ARGS_POST_BUFFERING},
|
||||
{"post-buffering-bufsize", required_argument, 0, LONG_ARGS_POST_BUFFERING_SIZE},
|
||||
#ifdef UWSGI_UDP
|
||||
{"udp", required_argument, 0, LONG_ARGS_UDP},
|
||||
#endif
|
||||
@@ -372,6 +377,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
{"ugreen", no_argument, &uwsgi.ugreen, 1},
|
||||
{"ugreen-stacksize", required_argument, 0, LONG_ARGS_UGREEN_PAGES},
|
||||
#endif
|
||||
{"logto", required_argument, 0, LONG_ARGS_LOGTO},
|
||||
{"version", no_argument, 0, LONG_ARGS_VERSION},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
@@ -447,44 +453,6 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
//parse environ
|
||||
|
||||
parse_sys_envs(environ, long_options);
|
||||
char **uenvs = environ;
|
||||
while(*uenvs) {
|
||||
if (!strncmp(*uenvs, "UWSGI_", 6)) {
|
||||
char *earg = malloc(strlen(*uenvs+6)+1);
|
||||
if (!earg) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
env_to_arg(*uenvs+6, earg);
|
||||
char *eq_pos = strchr(earg, '=');
|
||||
if (!eq_pos) {
|
||||
break;
|
||||
}
|
||||
eq_pos[0] = 0 ;
|
||||
struct option *lopt = long_options, *aopt;
|
||||
while ((aopt = lopt)) {
|
||||
if (!aopt->name)
|
||||
break;
|
||||
if (!strcmp(earg, aopt->name)) {
|
||||
if (aopt->flag) {
|
||||
*aopt->flag = aopt->val;
|
||||
}
|
||||
else {
|
||||
if (eq_pos[1] != 0) {
|
||||
manage_opt(aopt->val, eq_pos+1);
|
||||
}
|
||||
else {
|
||||
manage_opt(aopt->val, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
lopt++;
|
||||
}
|
||||
|
||||
}
|
||||
uenvs++;
|
||||
}
|
||||
|
||||
|
||||
if (uwsgi.binary_path == argv[0]) {
|
||||
cwd = uwsgi_get_cwd();
|
||||
@@ -509,6 +477,8 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
}
|
||||
#endif
|
||||
|
||||
uwsgi_log("compiled with version: %s\n", __VERSION__);
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uwsgi_log("*** big endian arch detected ***\n");
|
||||
#endif
|
||||
@@ -537,10 +507,20 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (uwsgi.prio != 0) {
|
||||
if (setpriority(PRIO_PROCESS, 0, uwsgi.prio)) {
|
||||
uwsgi_error("setpriority()");
|
||||
}
|
||||
else {
|
||||
uwsgi_log("scheduler priority set to %d\n", uwsgi.prio);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!getrlimit(RLIMIT_AS, &uwsgi.rl)) {
|
||||
#ifndef UNBIT
|
||||
// check for overflow
|
||||
if ((sizeof(void *) == 4 && (uint32_t) uwsgi.rl.rlim_max < UINT32_MAX) || (sizeof(void *) == 8 && (uint64_t) uwsgi.rl.rlim_max < UINT64_MAX)) {
|
||||
if (uwsgi.rl.rlim_max != RLIM_INFINITY) {
|
||||
#endif
|
||||
uwsgi_log("your process address space limit is %lld bytes (%lld MB)\n", (long long) uwsgi.rl.rlim_max, (long long) uwsgi.rl.rlim_max / 1024 / 1024);
|
||||
#ifndef UNBIT
|
||||
@@ -597,12 +577,31 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (uwsgi.post_buffering > 0) {
|
||||
uwsgi.async_post_buf = malloc( sizeof(char *) * uwsgi.async);
|
||||
if (!uwsgi.async_post_buf) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!uwsgi.post_buffering_bufsize) {
|
||||
uwsgi.post_buffering_bufsize = 8192 ;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<uwsgi.async;i++) {
|
||||
uwsgi.async_buf[i] = malloc(uwsgi.buffer_size);
|
||||
if (!uwsgi.async_buf[i]) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
if (uwsgi.post_buffering > 0) {
|
||||
uwsgi.async_post_buf[i] = malloc(uwsgi.post_buffering_bufsize);
|
||||
if (!uwsgi.async_post_buf[i]) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -893,6 +892,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
#ifdef UWSGI_SPOOLER
|
||||
uwsgi.shared->hooks[UWSGI_MODIFIER_SPOOL_REQUEST] = uwsgi_request_spooler; //17
|
||||
#endif
|
||||
uwsgi.shared->hooks[UWSGI_MODIFIER_EVAL] = uwsgi_request_eval; //22
|
||||
uwsgi.shared->hooks[UWSGI_MODIFIER_FASTFUNC] = uwsgi_request_fastfunc; //26
|
||||
|
||||
uwsgi.shared->hooks[UWSGI_MODIFIER_MANAGE_PATH_INFO] = uwsgi_request_wsgi; // 30
|
||||
@@ -2468,9 +2468,14 @@ pid_t spooler_start(int serverfd, PyObject * uwsgi_module_dict) {
|
||||
void manage_opt(int i, char *optarg) {
|
||||
|
||||
switch (i) {
|
||||
#ifdef UWSGI_ASYNC
|
||||
case LONG_ARGS_ASYNC:
|
||||
uwsgi.async = atoi(optarg);
|
||||
break;
|
||||
#endif
|
||||
case LONG_ARGS_LOGTO:
|
||||
logto(optarg);
|
||||
break;
|
||||
#ifdef UWSGI_UGREEN
|
||||
case LONG_ARGS_UGREEN_PAGES:
|
||||
uwsgi.ugreen_stackpages = atoi(optarg);
|
||||
@@ -2551,6 +2556,18 @@ void manage_opt(int i, char *optarg) {
|
||||
uwsgi.rl.rlim_cur = (atoi(optarg)) * 1024 * 1024;
|
||||
uwsgi.rl.rlim_max = uwsgi.rl.rlim_cur;
|
||||
break;
|
||||
case LONG_ARGS_LIMIT_POST:
|
||||
uwsgi.limit_post = (int) strtol(optarg, NULL, 10);
|
||||
break;
|
||||
case LONG_ARGS_PRIO:
|
||||
uwsgi.prio = (int) strtol(optarg, NULL, 10);
|
||||
break;
|
||||
case LONG_ARGS_POST_BUFFERING:
|
||||
uwsgi.post_buffering = atoi(optarg);
|
||||
break;
|
||||
case LONG_ARGS_POST_BUFFERING_SIZE:
|
||||
uwsgi.post_buffering_bufsize = atoi(optarg);
|
||||
break;
|
||||
case LONG_ARGS_PASTE:
|
||||
uwsgi.paste = optarg;
|
||||
break;
|
||||
@@ -2729,6 +2746,10 @@ void manage_opt(int i, char *optarg) {
|
||||
\t--pythonpath <dir>\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--udp <ip:port>\t\t\tbind master process to udp socket on ip:port\n\
|
||||
\t--snmp\t\t\t\tenable SNMP support in the UDP server\n\
|
||||
\t--erlang <name@ip>\t\tenable the Erlang server with node name <node@ip>\n\
|
||||
@@ -2740,9 +2761,10 @@ void manage_opt(int i, char *optarg) {
|
||||
\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--async <n>\t\t\tenable async mode with n core\n\
|
||||
\t--logto <logfile|addr>\t\tlog to file/udp\n\
|
||||
\t--stackless\t\t\tenable usage of tasklet (only on Stackless Python)\n\
|
||||
\t--version\t\t\tprint server version\n\
|
||||
\t-d|--daemonize <logfile>\tdaemonize and log into <logfile>\n", uwsgi.binary_path);
|
||||
\t-d|--daemonize <logfile|addr>\tdaemonize and log into <logfile> or udp <addr>\n", uwsgi.binary_path);
|
||||
exit(1);
|
||||
case 0:
|
||||
break;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/* indent -i8 -br -brs -brf -l0 -npsl -nip -npcs */
|
||||
|
||||
#define UWSGI_VERSION "0.9.5-dev"
|
||||
#define UWSGI_VERSION "0.9.5.1"
|
||||
|
||||
#define uwsgi_error(x) uwsgi_log("%s: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__);
|
||||
|
||||
@@ -139,6 +139,11 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
|
||||
#define LONG_ARGS_UGREEN_PAGES 17022
|
||||
#define LONG_ARGS_FILE_CONFIG 17023
|
||||
#define LONG_ARGS_MULTICAST 17024
|
||||
#define LONG_ARGS_LOGTO 17025
|
||||
#define LONG_ARGS_PRIO 17026
|
||||
#define LONG_ARGS_POST_BUFFERING 17027
|
||||
#define LONG_ARGS_POST_BUFFERING_SIZE 17028
|
||||
#define LONG_ARGS_LIMIT_POST 17029
|
||||
|
||||
#define UWSGI_OK 0
|
||||
#define UWSGI_AGAIN 1
|
||||
@@ -198,6 +203,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
|
||||
|
||||
#define UWSGI_MODIFIER_ADMIN_REQUEST 10
|
||||
#define UWSGI_MODIFIER_SPOOL_REQUEST 17
|
||||
#define UWSGI_MODIFIER_EVAL 22
|
||||
#define UWSGI_MODIFIER_FASTFUNC 26
|
||||
#define UWSGI_MODIFIER_MANAGE_PATH_INFO 30
|
||||
#define UWSGI_MODIFIER_MESSAGE 31
|
||||
@@ -347,6 +353,10 @@ struct wsgi_request {
|
||||
|
||||
int async_plagued;
|
||||
|
||||
size_t post_cl;
|
||||
char *post_buffering_buf;
|
||||
uint64_t post_buffering_read;
|
||||
|
||||
#ifdef UWSGI_STACKLESS
|
||||
PyTaskletObject* tasklet;
|
||||
#endif
|
||||
@@ -383,8 +393,11 @@ struct uwsgi_server {
|
||||
|
||||
struct iovec *async_hvec;
|
||||
char **async_buf;
|
||||
char **async_post_buf;
|
||||
|
||||
struct rlimit rl;
|
||||
size_t limit_post;
|
||||
int prio;
|
||||
|
||||
char *binary_path;
|
||||
|
||||
@@ -424,6 +437,10 @@ struct uwsgi_server {
|
||||
|
||||
int buffer_size;
|
||||
|
||||
int post_buffering;
|
||||
int post_buffering_harakiri;
|
||||
int post_buffering_bufsize;
|
||||
|
||||
int master_process;
|
||||
|
||||
int no_defer_accept;
|
||||
@@ -626,6 +643,7 @@ int bind_to_sctp(char *, int, char *);
|
||||
#endif
|
||||
#ifndef UNBIT
|
||||
void daemonize(char *);
|
||||
void logto(char *);
|
||||
#endif
|
||||
void log_request(struct wsgi_request *);
|
||||
void get_memusage(void);
|
||||
@@ -664,6 +682,7 @@ pid_t spooler_start(int, PyObject *);
|
||||
#endif
|
||||
|
||||
void set_harakiri(int);
|
||||
void inc_harakiri(int);
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uint16_t uwsgi_swap16(uint16_t);
|
||||
@@ -692,6 +711,7 @@ int uwsgi_request_admin(struct uwsgi_server *, struct wsgi_request *);
|
||||
#ifdef UWSGI_SPOOLER
|
||||
int uwsgi_request_spooler(struct uwsgi_server *, struct wsgi_request *);
|
||||
#endif
|
||||
int uwsgi_request_eval(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_fastfunc(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_marshal(struct uwsgi_server *, struct wsgi_request *);
|
||||
int uwsgi_request_ping(struct uwsgi_server *, struct wsgi_request *);
|
||||
@@ -730,7 +750,12 @@ struct wsgi_request *find_first_available_wsgi_req(struct uwsgi_server *);
|
||||
struct wsgi_request *find_wsgi_req_by_fd(struct uwsgi_server *, int, int);
|
||||
struct wsgi_request *find_wsgi_req_by_id(struct uwsgi_server *, int);
|
||||
|
||||
#ifdef __clang__
|
||||
struct wsgi_request *next_wsgi_req(struct uwsgi_server *, struct wsgi_request *);
|
||||
#else
|
||||
inline struct wsgi_request *next_wsgi_req(struct uwsgi_server *, struct wsgi_request *);
|
||||
#endif
|
||||
|
||||
|
||||
int async_add(int, int , int) ;
|
||||
int async_mod(int, int , int) ;
|
||||
@@ -819,7 +844,11 @@ void u_green_init(struct uwsgi_server *);
|
||||
void u_green_loop(struct uwsgi_server *);
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
struct wsgi_request *current_wsgi_req(struct uwsgi_server *);
|
||||
#else
|
||||
inline struct wsgi_request *current_wsgi_req(struct uwsgi_server *);
|
||||
#endif
|
||||
|
||||
void sanitize_args(struct uwsgi_server *);
|
||||
|
||||
|
||||
@@ -55,6 +55,34 @@ int uwsgi_request_admin(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_re
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
int uwsgi_request_eval(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
|
||||
PyObject *code, *py_dict;
|
||||
|
||||
PyObject *m = PyImport_AddModule("__main__");
|
||||
if (m == NULL) {
|
||||
PyErr_Print();
|
||||
return -1;
|
||||
}
|
||||
|
||||
py_dict = PyModule_GetDict(m);
|
||||
// make it a valid c string
|
||||
wsgi_req->buffer[wsgi_req->uh.pktsize] = 0 ;
|
||||
// need to find a way to cache compilations...
|
||||
code = Py_CompileString(wsgi_req->buffer, "uWSGI", Py_file_input);
|
||||
if (code == NULL) {
|
||||
PyErr_Print();
|
||||
return -1;
|
||||
}
|
||||
PyEval_EvalCode((PyCodeObject *)code, py_dict, py_dict );
|
||||
Py_DECREF(code);
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
return -1;
|
||||
}
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
/* uwsgi FASTFUNC|26 */
|
||||
int uwsgi_request_fastfunc(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
|
||||
|
||||
|
||||
@@ -19,6 +19,25 @@ extern struct uwsgi_server uwsgi;
|
||||
|
||||
#define UWSGI_LOGBASE "[- uWSGI -"
|
||||
|
||||
PyObject *py_uwsgi_send(PyObject * self, PyObject * args) {
|
||||
|
||||
char *data;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:send", &data)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (write(uwsgi.wsgi_req->poll.fd, data, strlen(data)) < 0) {
|
||||
uwsgi_error("write()");
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_True);
|
||||
return Py_True;
|
||||
|
||||
}
|
||||
|
||||
#ifdef UWSGI_ASYNC
|
||||
|
||||
|
||||
@@ -868,6 +887,7 @@ static PyMethodDef uwsgi_advanced_methods[] = {
|
||||
{"load_plugin", py_uwsgi_load_plugin, METH_VARARGS, ""},
|
||||
{"lock", py_uwsgi_lock, METH_VARARGS, ""},
|
||||
{"unlock", py_uwsgi_unlock, METH_VARARGS, ""},
|
||||
{"send", py_uwsgi_send, METH_VARARGS, ""},
|
||||
{"set_warning_message", py_uwsgi_warning, METH_VARARGS, ""},
|
||||
#ifdef UWSGI_MULTICAST
|
||||
{"send_multicast_message", py_uwsgi_multicast, METH_VARARGS, ""},
|
||||
|
||||
+36
-20
@@ -13,14 +13,15 @@ SENDFILE=True
|
||||
PROFILER=True
|
||||
NAGIOS=True
|
||||
PROXY=True
|
||||
PASTE=True
|
||||
MINTERPRETERS=True
|
||||
ASYNC=True
|
||||
UGREEN=True
|
||||
STACKLESS=False
|
||||
PLUGINS = []
|
||||
USWALLOW=False
|
||||
UNBIT=False
|
||||
UWSGI_BIN_NAME = 'uwsgi'
|
||||
GCC='gcc'
|
||||
|
||||
# specific compilation flags
|
||||
# libxml2 or expat
|
||||
@@ -46,17 +47,27 @@ import subprocess
|
||||
|
||||
from distutils import sysconfig
|
||||
|
||||
GCC = os.environ.get('CC', sysconfig.get_config_var('CC'))
|
||||
if not GCC:
|
||||
GCC = 'gcc'
|
||||
|
||||
gcc_list = ['utils', 'pyutils', 'protocol', 'socket', 'logging', 'wsgi_handlers', 'wsgi_headers', 'uwsgi_handlers', 'uwsgi']
|
||||
|
||||
# large file support
|
||||
try:
|
||||
cflags = ['-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + sysconfig.get_config_var('CFLAGS').split()
|
||||
cflags = ['-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 = cflags + ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True) ]
|
||||
ldflags = ['-lpthread', '-rdynamic'] + sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split()
|
||||
ldflags = os.environ.get("LDFLAGS", "").split()
|
||||
libs = ['-lpthread', '-rdynamic'] + sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split()
|
||||
|
||||
if USWALLOW:
|
||||
cflags = cflags + sysconfig.get_config_var('LLVM_CXXFLAGS').split()
|
||||
ldflags = ldflags + sysconfig.get_config_var('LLVM_LDFLAGS').split() + sysconfig.get_config_var('LINKFORSHARED').split()
|
||||
GCC = 'clang'
|
||||
|
||||
def depends_on(what, dep):
|
||||
for d in dep:
|
||||
@@ -68,9 +79,9 @@ def spcall(cmd):
|
||||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
|
||||
|
||||
if p.wait() == 0:
|
||||
return p.stdout.read().rstrip().decode()
|
||||
return p.stdout.read().rstrip().decode()
|
||||
else:
|
||||
return None
|
||||
return None
|
||||
|
||||
def add_o(x):
|
||||
if x == 'uwsgi':
|
||||
@@ -97,7 +108,7 @@ def build_uwsgi(bin_name):
|
||||
print(plugin)
|
||||
|
||||
print("*** uWSGI linking ***")
|
||||
ldline = "%s -o %s %s %s" % (GCC, bin_name, ' '.join(map(add_o, gcc_list)), ' '.join(ldflags))
|
||||
ldline = "%s -o %s %s %s %s" % (GCC, bin_name, ' '.join(ldflags), ' '.join(map(add_o, gcc_list)), ' '.join(libs))
|
||||
print(ldline)
|
||||
ret = os.system(ldline)
|
||||
if ret != 0:
|
||||
@@ -141,19 +152,19 @@ def parse_vars():
|
||||
version = sys.version_info
|
||||
uver = "%d.%d" % (version[0], version[1])
|
||||
|
||||
ldflags.append('-lpython' + uver)
|
||||
libs.append('-lpython' + uver)
|
||||
|
||||
if str(PYLIB_PATH) != '':
|
||||
ldflags.insert(0,'-L' + PYLIB_PATH)
|
||||
libs.insert(0,'-L' + PYLIB_PATH)
|
||||
|
||||
kvm_list = ['FreeBSD', 'OpenBSD', 'NetBSD', 'DragonFly']
|
||||
|
||||
if uwsgi_os == 'SunOS':
|
||||
ldflags.append('-lsendfile')
|
||||
ldflags.remove('-rdynamic')
|
||||
libs.append('-lsendfile')
|
||||
libs.remove('-rdynamic')
|
||||
|
||||
if uwsgi_os in kvm_list:
|
||||
ldflags.append('-lkvm')
|
||||
libs.append('-lkvm')
|
||||
|
||||
if uwsgi_os == 'OpenBSD':
|
||||
UGREEN = False
|
||||
@@ -210,6 +221,9 @@ def parse_vars():
|
||||
if PROFILER:
|
||||
cflags.append("-DUWSGI_PROFILER")
|
||||
|
||||
if PASTE:
|
||||
cflags.append('-DUWSGI_PASTE')
|
||||
|
||||
if SENDFILE:
|
||||
cflags.append("-DUWSGI_SENDFILE")
|
||||
gcc_list.append('sendfile')
|
||||
@@ -221,7 +235,7 @@ def parse_vars():
|
||||
print("*** libxml2 headers unavailable. uWSGI build is interrupted. You have to install libxml2 development package or use libexpat or disable XML")
|
||||
sys.exit(1)
|
||||
else:
|
||||
ldflags.append(xmlconf)
|
||||
libs.append(xmlconf)
|
||||
xmlconf = spcall("xml2-config --cflags")
|
||||
if xmlconf is None:
|
||||
print("*** libxml2 headers unavailable. uWSGI build is interrupted. You have to install libxml2 development package or use libexpat or disable XML")
|
||||
@@ -232,21 +246,21 @@ def parse_vars():
|
||||
gcc_list.append('xmlconf')
|
||||
elif XML_IMPLEMENTATION == 'expat':
|
||||
cflags.append("-DUWSGI_XML -DUWSGI_XML_EXPAT")
|
||||
ldflags.append('-lexpat')
|
||||
libs.append('-lexpat')
|
||||
gcc_list.append('xmlconf')
|
||||
|
||||
|
||||
if ERLANG:
|
||||
depends_on("ERLANG", ['EMBEDDED'])
|
||||
cflags.append("-DUWSGI_ERLANG")
|
||||
ldflags.append(ERLANG_LDFLAGS)
|
||||
libs.append(ERLANG_LDFLAGS)
|
||||
if str(ERLANG_CFLAGS) != '':
|
||||
cflags.append(ERLANG_CFLAGS)
|
||||
gcc_list.append('erlang')
|
||||
|
||||
if SCTP:
|
||||
ldflags.append("-lsctp")
|
||||
cflags.append("-DUWSGI_SCTP")
|
||||
libs.append("-lsctp")
|
||||
cflags.append("-DUWSGI_SCTP")
|
||||
|
||||
if SPOOLER:
|
||||
depends_on("SPOOLER", ['EMBEDDED'])
|
||||
@@ -263,13 +277,13 @@ def build_plugin(path):
|
||||
import uwsgiplugin as up
|
||||
|
||||
cflags.append(up.CFLAGS)
|
||||
ldflags.append(up.LDFLAGS)
|
||||
libs.append(up.LDFLAGS)
|
||||
|
||||
cflags.insert(0, '-I.')
|
||||
|
||||
plugin_base = path + '/' + up.NAME + '_plugin'
|
||||
|
||||
gccline = "%s -fPIC -shared -o %s.so %s %s.c %s" % (GCC, plugin_base, ' '.join(cflags), plugin_base, ' '.join(ldflags))
|
||||
gccline = "%s -fPIC -shared -o %s.so %s %s %s.c %s" % (GCC, plugin_base, ' '.join(cflags), ' '.join(ldflags), plugin_base, ' '.join(libs))
|
||||
print(gccline)
|
||||
|
||||
ret = os.system(gccline)
|
||||
@@ -294,9 +308,11 @@ if __name__ == "__main__":
|
||||
sys.exit(1)
|
||||
|
||||
if cmd == '--cflags':
|
||||
print(' '.join(cflags))
|
||||
print(' '.join(cflags))
|
||||
if cmd == '--ldflags':
|
||||
print(' '.join(ldflags))
|
||||
print(' '.join(ldflags))
|
||||
if cmd == '--libs':
|
||||
print(' '.join(libs))
|
||||
elif cmd == '--build':
|
||||
parse_vars()
|
||||
build_uwsgi(UWSGI_BIN_NAME)
|
||||
|
||||
+42
-1
@@ -107,6 +107,13 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uwsgi->limit_post) {
|
||||
if (wsgi_req->post_cl > uwsgi->limit_post) {
|
||||
uwsgi_log("Invalid (too big) CONTENT_LENGTH. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef UWSGI_THREADING
|
||||
if (uwsgi->has_threads && !uwsgi->workers[uwsgi->mywid].i_have_gil) {
|
||||
@@ -212,7 +219,41 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
|
||||
|
||||
// set wsgi vars
|
||||
|
||||
wsgi_req->async_post = fdopen(wsgi_req->poll.fd, "r");
|
||||
|
||||
if (uwsgi->post_buffering > 0 && wsgi_req->post_cl > 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) {
|
||||
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, uwsgi->post_buffering_bufsize);
|
||||
}
|
||||
else {
|
||||
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, post_remains);
|
||||
}
|
||||
if (post_chunk < 0) {
|
||||
uwsgi_error("read()");
|
||||
goto clear;
|
||||
}
|
||||
if (fwrite(wsgi_req->post_buffering_buf, post_chunk, 1, wsgi_req->async_post) <0) {
|
||||
uwsgi_error("fwrite()");
|
||||
goto clear;
|
||||
}
|
||||
post_remains -= post_chunk;
|
||||
}
|
||||
rewind(wsgi_req->async_post);
|
||||
}
|
||||
else {
|
||||
wsgi_req->async_post = fdopen(wsgi_req->poll.fd, "r");
|
||||
}
|
||||
|
||||
wsgi_socket = PyFile_FromFile(wsgi_req->async_post, "wsgi_input", "r", NULL);
|
||||
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.input", wsgi_socket);
|
||||
|
||||
Reference in New Issue
Block a user