mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-10-07 09:28:22 +00:00
Compare commits
21
Commits
0.9.7-beta1
...
0.9.7-rc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02d6006b2f | ||
|
|
e8e5f11c66 | ||
|
|
e53a6fa4c0 | ||
|
|
c478b0a0c8 | ||
|
|
5f207e6978 | ||
|
|
a2b74d0afd | ||
|
|
b867b11de3 | ||
|
|
806765d1d3 | ||
|
|
62d2b97e17 | ||
|
|
c04e339034 | ||
|
|
927b495646 | ||
|
|
57b5392590 | ||
|
|
463030108f | ||
|
|
46dd754264 | ||
|
|
12d9641b66 | ||
|
|
6cb1203d26 | ||
|
|
23d0ec333e | ||
|
|
da579fd308 | ||
|
|
14152bc999 | ||
|
|
6c32e5f2e2 | ||
|
|
62f74f2b60 |
@@ -9,3 +9,4 @@ b8f67c6cd0d62f864db9b2b265b4e260ad7d873c 0.9.6-rc2
|
||||
35918dd4b3771158b2b57410613ef029e08bbd60 0.9.6
|
||||
5f25d1f97f9dde3e391a668c1c610a52a5db8244 0.9.6.1
|
||||
ef31fc61ac48018c464f28ebfdf865b96bf83f18 0.9.6.2
|
||||
9e100c1f085034396cec586f0c76ad3f9800d1a5 0.9.7-beta1
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* 0.9.7-beta1 [20110301]
|
||||
|
||||
- fully modular re-design
|
||||
- advanced build system with presets
|
||||
- threading support
|
||||
- emperor mode for massive auto-hosting
|
||||
- caching subsystem
|
||||
|
||||
@@ -121,6 +121,9 @@ void emperor_add(char *name, time_t born) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
||||
unsetenv("UWSGI_RELOADS");
|
||||
|
||||
uef = uwsgi_num2str(n_ui->pipe[1]);
|
||||
if (setenv("UWSGI_EMPEROR_FD", uef, 1)) {
|
||||
uwsgi_error("setenv()");
|
||||
|
||||
@@ -55,6 +55,11 @@ struct uwsgi_gateway *register_gateway(char *name, void (*loop)(void)) {
|
||||
|
||||
if (!uwsgi.master_process) {
|
||||
if (gw_pid > 0) {
|
||||
#ifdef __linux__
|
||||
if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0,0,0)) {
|
||||
uwsgi_error("prctl()");
|
||||
}
|
||||
#endif
|
||||
loop();
|
||||
// never here !!! (i hope)
|
||||
exit(1);
|
||||
@@ -101,6 +106,11 @@ void gateway_respawn(int id) {
|
||||
|
||||
if (gw_pid == 0) {
|
||||
if (uwsgi.master_as_root) uwsgi_as_root();
|
||||
#ifdef __linux__
|
||||
if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0,0,0)) {
|
||||
uwsgi_error("prctl()");
|
||||
}
|
||||
#endif
|
||||
ug->loop();
|
||||
// never here !!! (i hope)
|
||||
exit(1);
|
||||
|
||||
@@ -141,6 +141,12 @@ void uwsgi_ini_config(char *file, char *magic_table[]) {
|
||||
val = NULL;
|
||||
}
|
||||
}
|
||||
if (aopt->has_arg == no_argument) {
|
||||
if (!strcmp("false", val) || val[0] == '0') {
|
||||
lopt++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
manage_opt(aopt->val, val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,14 +134,36 @@ void uwsgi_rwunlock(void *lock) { uwsgi_unlock(lock); }
|
||||
#define UWSGI_LOCK_SIZE 8
|
||||
#define UWSGI_RWLOCK_SIZE 8
|
||||
|
||||
void uwsgi_lock_init(void *lock) {}
|
||||
static int lock_counter = 0;
|
||||
|
||||
void uwsgi_lock_init(void *lock) {
|
||||
|
||||
char filename[17];
|
||||
|
||||
if (snprintf(filename, 17, ".uwsgiflock%d", lock_counter) < 0) {
|
||||
uwsgi_log("unable to create lock %d\n", lock_counter);
|
||||
}
|
||||
|
||||
int fd = open(filename, O_CREAT|O_RDWR|O_TRUNC);
|
||||
if (fd < 0) {
|
||||
uwsgi_error("open()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
memcpy(lock, &fd, sizeof(int));
|
||||
}
|
||||
|
||||
void uwsgi_lock(void *lock) {
|
||||
//if (flock((int) *lock, LOCK_EX)) { uwsgi_error("flock()"); }
|
||||
|
||||
int fd;
|
||||
memcpy(&fd, lock, sizeof(int));
|
||||
if (flock(fd, LOCK_EX)) { uwsgi_error("flock()"); }
|
||||
}
|
||||
|
||||
void uwsgi_unlock(void *lock) {
|
||||
//if (flock((int) *lock, LOCK_UN)) { uwsgi_error("flock()"); }
|
||||
int fd;
|
||||
memcpy(&fd, lock, sizeof(int));
|
||||
if (flock(fd, LOCK_UN)) { uwsgi_error("flock()"); }
|
||||
}
|
||||
|
||||
void uwsgi_rwlock_init(void *lock) { uwsgi_lock_init(lock) ;}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#define _NO_UWSGI_RB
|
||||
#include "uwsgi.h"
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
|
||||
|
||||
@@ -177,7 +177,7 @@ void master_loop(char **argv, char **environ) {
|
||||
//UWSGI_RELEASE_GIL
|
||||
|
||||
/* route signals to workers... */
|
||||
signal(SIGHUP, (void *) &grace_them_all);
|
||||
uwsgi_unix_signal(SIGHUP, grace_them_all);
|
||||
signal(SIGTERM, (void *) &reap_them_all);
|
||||
signal(SIGINT, (void *) &kill_them_all);
|
||||
signal(SIGQUIT, (void *) &kill_them_all);
|
||||
@@ -245,6 +245,10 @@ void master_loop(char **argv, char **environ) {
|
||||
uh->modifier1 = 99;
|
||||
uh->pktsize = cluster_opt_size - 4;
|
||||
uh->modifier2 = 1;
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uh->pktsize = uwsgi_swap16(uh->pktsize);
|
||||
#endif
|
||||
|
||||
cptrbuf = cluster_opt_buf+4;
|
||||
|
||||
@@ -361,6 +365,11 @@ void master_loop(char **argv, char **environ) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// call a series of waitpid to ensure all processes (gateways and daemons) are dead
|
||||
for(i=0;i<(uwsgi.gateways_cnt+ushared->daemons_cnt);i++) {
|
||||
diedpid = waitpid(WAIT_ANY, &waitpid_status, WNOHANG);
|
||||
}
|
||||
|
||||
uwsgi_log( "binary reloading uWSGI...\n");
|
||||
if (chdir(uwsgi.cwd)) {
|
||||
uwsgi_error("chdir()");
|
||||
@@ -407,12 +416,6 @@ void master_loop(char **argv, char **environ) {
|
||||
master_has_children = 1;
|
||||
}
|
||||
#endif
|
||||
#ifdef UWSGI_PROXY
|
||||
if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) {
|
||||
master_has_children = 1;
|
||||
}
|
||||
// TODO if gateways > 0 master_has_children == 1
|
||||
#endif
|
||||
|
||||
if (!master_has_children) {
|
||||
diedpid = 0;
|
||||
@@ -525,7 +528,7 @@ void master_loop(char **argv, char **environ) {
|
||||
}
|
||||
// reload me
|
||||
else if (byte == 1) {
|
||||
grace_them_all();
|
||||
grace_them_all(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -593,12 +596,19 @@ void master_loop(char **argv, char **environ) {
|
||||
switch(uwsgi.wsgi_requests[0]->uh.modifier1) {
|
||||
case 95:
|
||||
memset(&nucn, 0, sizeof(struct uwsgi_cluster_node));
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uwsgi.wsgi_requests[0]->uh.pktsize = uwsgi_swap16(uwsgi.wsgi_requests[0]->uh.pktsize);
|
||||
#endif
|
||||
uwsgi_hooked_parse(uwsgi.wsgi_requests[0]->buffer, uwsgi.wsgi_requests[0]->uh.pktsize, manage_cluster_announce, &nucn);
|
||||
if (nucn.name[0] != 0) {
|
||||
uwsgi_cluster_add_node(&nucn, CLUSTER_NODE_DYNAMIC);
|
||||
}
|
||||
break;
|
||||
case 96:
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uwsgi.wsgi_requests[0]->uh.pktsize = uwsgi_swap16(uwsgi.wsgi_requests[0]->uh.pktsize);
|
||||
#endif
|
||||
uwsgi_log_verbose("%.*s\n", uwsgi.wsgi_requests[0]->uh.pktsize, uwsgi.wsgi_requests[0]->buffer);
|
||||
break;
|
||||
case 98:
|
||||
@@ -614,6 +624,9 @@ void master_loop(char **argv, char **environ) {
|
||||
}
|
||||
break;
|
||||
case 73:
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uwsgi.wsgi_requests[0]->uh.pktsize = uwsgi_swap16(uwsgi.wsgi_requests[0]->uh.pktsize);
|
||||
#endif
|
||||
uwsgi_log_verbose("[uWSGI cluster %s] new node available: %.*s\n", uwsgi.cluster, uwsgi.wsgi_requests[0]->uh.pktsize, uwsgi.wsgi_requests[0]->buffer);
|
||||
break;
|
||||
}
|
||||
@@ -679,6 +692,7 @@ void master_loop(char **argv, char **environ) {
|
||||
// checking logsize
|
||||
if (uwsgi.logfile) {
|
||||
uwsgi.shared->logsize = lseek(2, 0, SEEK_CUR);
|
||||
/*
|
||||
if (uwsgi.shared->logsize > 8192) {
|
||||
//uwsgi_log("logsize: %d\n", uwsgi.shared->logsize);
|
||||
char *new_logfile = uwsgi_malloc(strlen(uwsgi.logfile) + 14 + 1);
|
||||
@@ -688,6 +702,7 @@ void master_loop(char **argv, char **environ) {
|
||||
}
|
||||
free(new_logfile);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@@ -716,7 +731,7 @@ void master_loop(char **argv, char **environ) {
|
||||
uwsgi.workers[0].requests = tmp_counter;
|
||||
}
|
||||
|
||||
// remove expired cache items
|
||||
// remove expired cache items TODO use rb_tree timeouts
|
||||
if (uwsgi.cache_max_items > 0) {
|
||||
for(i=0;i< (int)uwsgi.cache_max_items;i++) {
|
||||
uwsgi_wlock(uwsgi.cache_lock);
|
||||
|
||||
+20
-1
@@ -247,6 +247,7 @@ void erlang_loop() {
|
||||
int fd;
|
||||
|
||||
int eversion;
|
||||
int i;
|
||||
|
||||
ei_x_buff x, xr;
|
||||
|
||||
@@ -291,13 +292,31 @@ void erlang_loop() {
|
||||
|
||||
x.index = 0;
|
||||
ei_decode_version(x.buff, &x.index, &eversion);
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("eversion: %d\n", eversion);
|
||||
#endif
|
||||
|
||||
if (!strcmp(em.toname, "rex")) {
|
||||
uwsgi_erlang_rpc(fd, &em.from, &x);
|
||||
}
|
||||
else {
|
||||
dump_eterm(&x);
|
||||
int uep = -1;
|
||||
for(i=0;i<uerl.uep_cnt;i++) {
|
||||
if (!strcmp(uerl.uep[i].name, em.toname)) {
|
||||
uep = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (uep > -1) {
|
||||
if (uerl.uep[uep].plugin) {
|
||||
uerl.uep[uep].plugin( uerl.uep[uep].func, &x );
|
||||
}
|
||||
}
|
||||
else {
|
||||
uwsgi_log("!!! unregistered erlang process requested, dumping it !!!\n");
|
||||
dump_eterm(&x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-1
@@ -1,9 +1,19 @@
|
||||
#include <ei.h>
|
||||
|
||||
#define MAX_UWSGI_ERLANG_PROCESSES 64
|
||||
|
||||
#define LONG_ARGS_ERLANG 17012
|
||||
#define LONG_ARGS_ERLANG_COOKIE 17013
|
||||
|
||||
|
||||
|
||||
struct uwsgi_erlang_process {
|
||||
|
||||
char name[0xff];
|
||||
void (*plugin)(void *, ei_x_buff *);
|
||||
void *func;
|
||||
};
|
||||
|
||||
struct uwsgi_erlang {
|
||||
|
||||
ei_cnode cnode;
|
||||
@@ -13,6 +23,8 @@ struct uwsgi_erlang {
|
||||
int fd;
|
||||
|
||||
void *lock;
|
||||
|
||||
struct uwsgi_erlang_process uep[MAX_UWSGI_ERLANG_PROCESSES];
|
||||
int uep_cnt;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+8
-3
@@ -209,7 +209,7 @@ uint16_t http_add_uwsgi_header(struct http_session *h_session, struct iovec *iov
|
||||
|
||||
for(i=0;i<hhlen;i++) {
|
||||
if (!status) {
|
||||
hh[i] = toupper(hh[i]);
|
||||
hh[i] = toupper((int)hh[i]);
|
||||
if (hh[i] == '-') hh[i] = '_';
|
||||
if (hh[i] == ':') {
|
||||
status = 1;
|
||||
@@ -548,9 +548,10 @@ void http_loop() {
|
||||
continue;
|
||||
}
|
||||
|
||||
uhttp_session->timeout = reset_timeout(uhttp_session);
|
||||
|
||||
switch(uhttp_session->status) {
|
||||
|
||||
uhttp_session->timeout = reset_timeout(uhttp_session);
|
||||
|
||||
case HTTP_STATUS_RECV:
|
||||
len = recv(uhttp_session->fd, uhttp_session->buffer + uhttp_session->h_pos, UMAX16-uhttp_session->h_pos, 0);
|
||||
@@ -681,6 +682,10 @@ void http_loop() {
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uhttp_session->uh.pktsize = uwsgi_swap16(uhttp_session->uh.pktsize);
|
||||
#endif
|
||||
|
||||
uhttp_session->iov[0].iov_base = &uhttp_session->uh;
|
||||
uhttp_session->iov[0].iov_len = 4;
|
||||
|
||||
@@ -691,7 +696,7 @@ void http_loop() {
|
||||
}
|
||||
|
||||
// fd passing: PERFORMANCE EXTREME BOOST !!!
|
||||
if (uhttp_session->pass_fd) {
|
||||
if (uhttp_session->pass_fd && !uhttp_session->remains) {
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
msg.msg_iov = uhttp_session->iov;
|
||||
|
||||
+44
-1
@@ -72,6 +72,7 @@ PyObject *erl_to_py(ei_x_buff* x) {
|
||||
ei_decode_string(x->buff, &x->index, atom);
|
||||
pobj = PyString_FromString(atom);
|
||||
free(atom);
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_ATOM_EXT:
|
||||
atom = uwsgi_malloc(esize+1);
|
||||
@@ -84,6 +85,7 @@ PyObject *erl_to_py(ei_x_buff* x) {
|
||||
pobj = PyUnicode_FromString(atom);
|
||||
#endif
|
||||
free(atom);
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_SMALL_TUPLE_EXT:
|
||||
case ERL_LARGE_TUPLE_EXT:
|
||||
@@ -94,6 +96,7 @@ PyObject *erl_to_py(ei_x_buff* x) {
|
||||
PyTuple_SetItem(pobj, i, zero);
|
||||
Py_DECREF(zero);
|
||||
}
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_LIST_EXT:
|
||||
case ERL_NIL_EXT:
|
||||
@@ -108,12 +111,14 @@ PyObject *erl_to_py(ei_x_buff* x) {
|
||||
PyList_Append(pobj, zero);
|
||||
Py_DECREF(zero);
|
||||
}
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_BINARY_EXT:
|
||||
binary = uwsgi_malloc(esize);
|
||||
ei_decode_binary(x->buff, &x->index, binary, &bin_size);
|
||||
pobj = PyString_FromStringAndSize(binary, bin_size);
|
||||
free(binary);
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_PID_EXT:
|
||||
ei_decode_pid(x->buff, &x->index, &epid);
|
||||
@@ -121,6 +126,7 @@ PyObject *erl_to_py(ei_x_buff* x) {
|
||||
PyTuple_SetItem(pobj, 0, PyInt_FromLong(epid.num));
|
||||
PyTuple_SetItem(pobj, 1, PyInt_FromLong(epid.serial));
|
||||
PyTuple_SetItem(pobj, 2, PyInt_FromLong(epid.creation));
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
default:
|
||||
ei_skip_term(x->buff, &x->index);
|
||||
@@ -292,6 +298,42 @@ recv:
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
void pyerl_call_registered(void *func, ei_x_buff *x) {
|
||||
|
||||
PyObject *pyargs = PyTuple_New(1);
|
||||
PyObject *ret;
|
||||
|
||||
PyTuple_SetItem(pyargs, 0, erl_to_py(x));
|
||||
|
||||
ret = python_call((PyObject *) func, pyargs, 0);
|
||||
}
|
||||
|
||||
PyObject *pyerl_register_process(PyObject * self, PyObject * args) {
|
||||
|
||||
char *name;
|
||||
PyObject *callable;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "sO:erlang_register_process", &name, &callable)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (uerl.uep_cnt >= MAX_UWSGI_ERLANG_PROCESSES)
|
||||
return PyErr_Format(PyExc_ValueError, "You can define max %d erlang registered processes", MAX_UWSGI_ERLANG_PROCESSES);
|
||||
|
||||
if (strlen(name) > 0xff-1)
|
||||
return PyErr_Format(PyExc_ValueError, "Invalid erlang process name");
|
||||
|
||||
strcpy(uerl.uep[uerl.uep_cnt].name, name);
|
||||
uerl.uep[uerl.uep_cnt].plugin = pyerl_call_registered;
|
||||
uerl.uep[uerl.uep_cnt].func = callable;
|
||||
|
||||
uerl.uep_cnt++;
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
||||
}
|
||||
|
||||
PyObject *pyerl_recv(PyObject * self, PyObject * args) {
|
||||
|
||||
ei_x_buff x;
|
||||
@@ -401,6 +443,7 @@ static PyMethodDef uwsgi_pyerl_methods[] = {
|
||||
{"erlang_rpc", pyerl_rpc, METH_VARARGS, ""},
|
||||
{"erlang_lock", pyerl_lock, METH_VARARGS, ""},
|
||||
{"erlang_unlock", pyerl_unlock, METH_VARARGS, ""},
|
||||
{"erlang_register_process", pyerl_register_process, METH_VARARGS, ""},
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -426,7 +469,7 @@ int py_to_erl(PyObject *pobj, ei_x_buff *x) {
|
||||
ei_x_encode_empty_list(x);
|
||||
}
|
||||
else if (PyString_Check(pobj)) {
|
||||
ei_x_encode_string(x, PyString_AsString(pobj));
|
||||
ei_x_encode_binary(x, PyString_AsString(pobj), PyString_Size(pobj));
|
||||
}
|
||||
else if (PyUnicode_Check(pobj)) {
|
||||
ei_x_encode_atom(x, PyString_AsString(pobj));
|
||||
|
||||
+10
-1
@@ -4,13 +4,22 @@ extern struct uwsgi_server uwsgi;
|
||||
extern struct uwsgi_python up;
|
||||
|
||||
void gil_real_get() {
|
||||
#ifndef PYTHREE
|
||||
PyEval_AcquireLock();
|
||||
PyThreadState_Swap((PyThreadState *) pthread_getspecific(up.upt_gil_key));
|
||||
#else
|
||||
PyEval_RestoreThread((PyThreadState *) pthread_getspecific(up.upt_gil_key));
|
||||
#endif
|
||||
}
|
||||
|
||||
void gil_real_release() {
|
||||
#ifndef PYTHREE
|
||||
pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Swap(NULL));
|
||||
PyEval_ReleaseLock();
|
||||
PyEval_ReleaseLock();
|
||||
#else
|
||||
pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Get());
|
||||
PyEval_SaveThread();
|
||||
#endif
|
||||
}
|
||||
|
||||
void gil_fake_get() {}
|
||||
|
||||
@@ -13,6 +13,9 @@ struct option uwsgi_python_options[] = {
|
||||
{"callable", required_argument, 0, LONG_ARGS_CALLABLE},
|
||||
{"test", required_argument, 0, 'j'},
|
||||
{"home", required_argument, 0, 'H'},
|
||||
{"virtualenv", required_argument, 0, 'H'},
|
||||
{"venv", required_argument, 0, 'H'},
|
||||
{"pyhome", required_argument, 0, 'H'},
|
||||
{"pythonpath", required_argument, 0, LONG_ARGS_PYTHONPATH},
|
||||
{"python-path", required_argument, 0, LONG_ARGS_PYTHONPATH},
|
||||
{"pymodule-alias", required_argument, 0, LONG_ARGS_PYMODULE_ALIAS},
|
||||
@@ -829,6 +832,9 @@ int uwsgi_python_signal_handler(uint8_t sig, void *handler) {
|
||||
if (!args)
|
||||
return -1;
|
||||
|
||||
if (!handler) return -1;
|
||||
|
||||
|
||||
PyTuple_SetItem(args, 0, PyInt_FromLong(sig));
|
||||
|
||||
ret = python_call(handler, args, 0);
|
||||
|
||||
@@ -428,15 +428,26 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
|
||||
|
||||
if (uwsgi.post_buffering > 0) {
|
||||
UWSGI_RELEASE_GIL
|
||||
// read to disk
|
||||
if (wsgi_req->post_cl <= (size_t) uwsgi.post_buffering) {
|
||||
if (!uwsgi_read_whole_body(wsgi_req, wsgi_req->post_buffering_buf, uwsgi.post_buffering_bufsize)) {
|
||||
goto clear;
|
||||
// read to disk if post_cl > post_buffering
|
||||
if (!up.pep3333_input) {
|
||||
if (wsgi_req->post_cl >= (size_t) uwsgi.post_buffering) {
|
||||
if (!uwsgi_read_whole_body(wsgi_req, wsgi_req->post_buffering_buf, uwsgi.post_buffering_bufsize)) {
|
||||
goto clear;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!uwsgi_read_whole_body_in_mem(wsgi_req, wsgi_req->post_buffering_buf)) {
|
||||
goto clear;
|
||||
// read to disk if post_cl > post_buffering
|
||||
if (wsgi_req->post_cl >= (size_t) uwsgi.post_buffering) {
|
||||
if (!uwsgi_read_whole_body(wsgi_req, wsgi_req->post_buffering_buf, uwsgi.post_buffering_bufsize)) {
|
||||
goto clear;
|
||||
}
|
||||
}
|
||||
// on tiny post use memory
|
||||
else {
|
||||
if (!uwsgi_read_whole_body_in_mem(wsgi_req, wsgi_req->post_buffering_buf)) {
|
||||
goto clear;
|
||||
}
|
||||
}
|
||||
}
|
||||
UWSGI_GET_GIL
|
||||
|
||||
@@ -893,6 +893,9 @@ int uwsgi_string_sendto(int fd, uint8_t modifier1, uint8_t modifier2, struct soc
|
||||
|
||||
uh->modifier1 = modifier1;
|
||||
uh->pktsize = len;
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uh->pktsize = uwsgi_swap16(uh->pktsize);
|
||||
#endif
|
||||
uh->modifier2 = modifier2;
|
||||
|
||||
memcpy(upkt+4, message, len);
|
||||
|
||||
@@ -10,20 +10,20 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
|
||||
// leave 1 byte for abstract namespace (108 linux -> 104 bsd/mac)
|
||||
if (strlen(socket_name) > 102) {
|
||||
uwsgi_log( "invalid socket name\n");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
uws_addr = malloc(sizeof(struct sockaddr_un));
|
||||
if (uws_addr == NULL) {
|
||||
uwsgi_error("malloc()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
memset(uws_addr, 0, sizeof(struct sockaddr_un));
|
||||
serverfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (serverfd < 0) {
|
||||
uwsgi_error("socket()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
if (abstract_socket == 0) {
|
||||
if (unlink(socket_name) != 0 && errno != ENOENT) {
|
||||
@@ -44,13 +44,13 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
|
||||
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);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
|
||||
if (listen(serverfd, listen_queue) != 0) {
|
||||
uwsgi_error("listen()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
// chmod unix socket for lazy users
|
||||
@@ -104,7 +104,7 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
|
||||
serverfd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
|
||||
if (serverfd < 0) {
|
||||
uwsgi_error("socket()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
uwsgi_log( "binding on %d SCTP interfaces on port: %d\n", num_ip, ntohs(uws_addr[0].sin_port));
|
||||
@@ -112,7 +112,7 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
|
||||
|
||||
if (sctp_bindx(serverfd, (struct sockaddr *) uws_addr, num_ip, SCTP_BINDX_ADD_ADDR) != 0) {
|
||||
uwsgi_error("sctp_bindx()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
sctp_im.sinit_max_instreams = 0xFFFF;
|
||||
@@ -124,7 +124,7 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
|
||||
|
||||
if (listen(serverfd, listen_queue) != 0) {
|
||||
uwsgi_error("listen()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
return serverfd;
|
||||
@@ -328,7 +328,7 @@ char *generate_socket_name(char *socket_name) {
|
||||
struct ifaddrs *ifap = NULL, *ifa, *ifaf;
|
||||
if (getifaddrs(&ifap)) {
|
||||
uwsgi_error("getifaddrs()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
// here socket_name will be truncated
|
||||
@@ -359,7 +359,7 @@ char *generate_socket_name(char *socket_name) {
|
||||
}
|
||||
|
||||
uwsgi_log("unable to find avalid socket address\n");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
return socket_name ;
|
||||
}
|
||||
@@ -381,7 +381,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) {
|
||||
serverfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (serverfd < 0) {
|
||||
uwsgi_error("socket()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
if (socket_name[0] == 0) {
|
||||
@@ -394,7 +394,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) {
|
||||
|
||||
if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEADDR, (const void *) &reuse, sizeof(int)) < 0) {
|
||||
uwsgi_error("setsockopt()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
if (!uwsgi.no_defer_accept) {
|
||||
@@ -421,12 +421,12 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) {
|
||||
uwsgi_log("probably another instance of uWSGI is running on the same address.\n");
|
||||
}
|
||||
uwsgi_error("bind()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
if (listen(serverfd, listen_queue) != 0) {
|
||||
uwsgi_error("listen()");
|
||||
exit(1);
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1634,8 +1634,23 @@ int is_a_number(char *what) {
|
||||
int i;
|
||||
|
||||
for(i=0;i<(int)strlen(what);i++) {
|
||||
if (!isdigit(what[i])) return 0;
|
||||
if (!isdigit((int)what[i])) return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void uwsgi_unix_signal(int signum, void (*func)(int)) {
|
||||
|
||||
struct sigaction sa;
|
||||
|
||||
memset(&sa, 0, sizeof(struct sigaction));
|
||||
|
||||
sa.sa_handler = func;
|
||||
|
||||
sigemptyset(&sa.sa_mask);
|
||||
|
||||
if (sigaction(signum, &sa, NULL) < 0) {
|
||||
uwsgi_error("sigaction()");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ void warn_pipe()
|
||||
}
|
||||
}
|
||||
|
||||
void gracefully_kill()
|
||||
void gracefully_kill(int signum)
|
||||
{
|
||||
uwsgi_log("Gracefully killing worker %d (pid: %d)...\n", uwsgi.mywid, uwsgi.mypid);
|
||||
if (UWSGI_IS_IN_REQUEST) {
|
||||
@@ -224,16 +224,18 @@ void kill_them_all()
|
||||
kill(uwsgi.workers[i].pid, SIGINT);
|
||||
}
|
||||
|
||||
for (i = 0; i <= uwsgi.gateways_cnt; i++) {
|
||||
kill(uwsgi.gateways[i].pid, SIGKILL);
|
||||
for (i = 0; i < uwsgi.shared->daemons_cnt; i++) {
|
||||
if (uwsgi.shared->daemons[i].pid > 0)
|
||||
kill(uwsgi.shared->daemons[i].pid, SIGKILL);
|
||||
}
|
||||
|
||||
for (i = 0; i <= uwsgi.shared->daemons_cnt; i++) {
|
||||
kill(uwsgi.shared->daemons[i].pid, SIGKILL);
|
||||
for (i = 0; i < uwsgi.gateways_cnt; i++) {
|
||||
if (uwsgi.gateways[i].pid > 0)
|
||||
kill(uwsgi.gateways[i].pid, SIGKILL);
|
||||
}
|
||||
}
|
||||
|
||||
void grace_them_all()
|
||||
void grace_them_all(int signum)
|
||||
{
|
||||
int i;
|
||||
uwsgi.to_heaven = 1;
|
||||
@@ -243,9 +245,16 @@ void grace_them_all()
|
||||
}
|
||||
|
||||
for (i = 0; i < uwsgi.shared->daemons_cnt; i++) {
|
||||
if (uwsgi.shared->daemons[i].pid > 0)
|
||||
kill(uwsgi.shared->daemons[i].pid, SIGKILL);
|
||||
}
|
||||
|
||||
for (i = 0; i < uwsgi.gateways_cnt; i++) {
|
||||
if (uwsgi.gateways[i].pid > 0)
|
||||
kill(uwsgi.gateways[i].pid, SIGKILL);
|
||||
}
|
||||
|
||||
|
||||
uwsgi_log("...gracefully killing workers...\n");
|
||||
for (i = 1; i <= uwsgi.numproc; i++) {
|
||||
if (uwsgi.workers[i].pid > 0)
|
||||
@@ -254,15 +263,37 @@ void grace_them_all()
|
||||
|
||||
}
|
||||
|
||||
void uwsgi_nuclear_blast() {
|
||||
|
||||
if (!uwsgi.workers) {
|
||||
reap_them_all();
|
||||
}
|
||||
else if (uwsgi.master_process) {
|
||||
if (getpid() == uwsgi.workers[0].pid) {
|
||||
reap_them_all();
|
||||
}
|
||||
}
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void reap_them_all()
|
||||
{
|
||||
int i;
|
||||
uwsgi.to_heaven = 1;
|
||||
|
||||
for (i = 0; i < uwsgi.shared->daemons_cnt; i++) {
|
||||
if (uwsgi.shared->daemons[i].pid > 0)
|
||||
kill(uwsgi.shared->daemons[i].pid, SIGKILL);
|
||||
}
|
||||
|
||||
for (i = 0; i < uwsgi.gateways_cnt; i++) {
|
||||
if (uwsgi.gateways[i].pid > 0)
|
||||
kill(uwsgi.gateways[i].pid, SIGKILL);
|
||||
}
|
||||
|
||||
if (!uwsgi.workers) return;
|
||||
|
||||
uwsgi_log("...brutally killing workers...\n");
|
||||
for (i = 1; i <= uwsgi.numproc; i++) {
|
||||
if (uwsgi.workers[i].pid > 0)
|
||||
@@ -366,6 +397,18 @@ static void vacuum(void)
|
||||
if (chdir(uwsgi.cwd)) {
|
||||
uwsgi_error("chdir()");
|
||||
}
|
||||
if (uwsgi.pidfile && !uwsgi.uid) {
|
||||
if (unlink(uwsgi.pidfile)) {
|
||||
uwsgi_error("unlink()");
|
||||
} else {
|
||||
uwsgi_log("VACUUM: pidfile removed.\n");
|
||||
}
|
||||
}
|
||||
if (uwsgi.chdir) {
|
||||
if (chdir(uwsgi.chdir)) {
|
||||
uwsgi_error("chdir()");
|
||||
}
|
||||
}
|
||||
for (i = 0; i < uwsgi.sockets_cnt; i++) {
|
||||
if (uwsgi.sockets[i].family == AF_UNIX) {
|
||||
if (unlink(uwsgi.sockets[i].name)) {
|
||||
@@ -375,13 +418,6 @@ static void vacuum(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uwsgi.pidfile && !uwsgi.uid) {
|
||||
if (unlink(uwsgi.pidfile)) {
|
||||
uwsgi_error("unlink()");
|
||||
} else {
|
||||
uwsgi_log("VACUUM: pidfile removed.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -614,6 +650,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
#ifdef UWSGI_XML
|
||||
if (uwsgi.xml_config != NULL) {
|
||||
magic_table['o'] = uwsgi.xml_config;
|
||||
magic_table['v'] = uwsgi.emperor_dir;
|
||||
if (uwsgi.xml_config[0] == '/') {
|
||||
magic_table['p'] = uwsgi.xml_config;
|
||||
}
|
||||
@@ -630,6 +667,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
#ifdef UWSGI_INI
|
||||
if (uwsgi.ini != NULL) {
|
||||
magic_table['o'] = uwsgi.ini;
|
||||
magic_table['v'] = uwsgi.emperor_dir;
|
||||
if (uwsgi.ini[0] == '/') {
|
||||
magic_table['p'] = uwsgi.ini;
|
||||
}
|
||||
@@ -647,6 +685,7 @@ int main(int argc, char *argv[], char *envp[])
|
||||
#ifdef UWSGI_YAML
|
||||
if (uwsgi.yaml != NULL) {
|
||||
magic_table['o'] = uwsgi.yaml;
|
||||
magic_table['v'] = uwsgi.emperor_dir;
|
||||
if (uwsgi.yaml[0] == '/') {
|
||||
magic_table['p'] = uwsgi.yaml;
|
||||
}
|
||||
@@ -736,7 +775,7 @@ options_parsed:
|
||||
uwsgi_log("***\n*** You are running a DEBUG version of uWSGI, plese disable DEBUG in uwsgiconfig.py and recompile it ***\n***\n");
|
||||
#endif
|
||||
|
||||
uwsgi_log("compiled with version: %s\n", __VERSION__);
|
||||
uwsgi_log("compiled with version: %s on %s\n", __VERSION__, UWSGI_BUILD_DATE);
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uwsgi_log("*** big endian arch detected ***\n");
|
||||
@@ -771,14 +810,15 @@ options_parsed:
|
||||
#define CLONE_NEWIPC 0x08000000
|
||||
#endif
|
||||
if (uwsgi.ns) {
|
||||
void *linux_clone_stack = alloca(uwsgi.page_size);
|
||||
for(;;) {
|
||||
pid_t pid = clone(uwsgi_start, linux_clone_stack+uwsgi.page_size, SIGCHLD|CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS, (void *)argv);
|
||||
char stack[PTHREAD_STACK_MIN];
|
||||
uwsgi_log("*** jailing uWSGI in %s ***\n", uwsgi.ns);
|
||||
pid_t pid = clone(uwsgi_start, stack+PTHREAD_STACK_MIN, SIGCHLD|CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS, (void *)argv);
|
||||
if (pid == -1) {
|
||||
uwsgi_error("clone()");
|
||||
exit(1);
|
||||
}
|
||||
uwsgi_log("waiting for jailed master dead...\n");
|
||||
uwsgi_log("waiting for jailed master (pid: %d) death...\n", (int) pid);
|
||||
pid = waitpid(pid, NULL, 0);
|
||||
if (pid < 0) {
|
||||
uwsgi_error("waitpid()");
|
||||
@@ -820,7 +860,7 @@ int uwsgi_start(void *v_argv) {
|
||||
|
||||
#ifdef __linux__
|
||||
if (uwsgi.ns) {
|
||||
|
||||
|
||||
if (getpid() != 1) {
|
||||
uwsgi_log("your kernel does not support linux pid namespace\n");
|
||||
exit(1);
|
||||
@@ -973,6 +1013,11 @@ int uwsgi_start(void *v_argv) {
|
||||
// never here
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// do not go on if no socket or gateway is defined
|
||||
if (!uwsgi.sockets_cnt && !uwsgi.gateways_cnt) {
|
||||
exit(0);
|
||||
}
|
||||
close(emperor_pipe[0]);
|
||||
uwsgi.has_emperor = 1;
|
||||
uwsgi.emperor_fd = emperor_pipe[1];
|
||||
@@ -1212,6 +1257,10 @@ int uwsgi_start(void *v_argv) {
|
||||
socket_type_len = sizeof(struct sockaddr_un);
|
||||
gsa.sa = &usa.sa;
|
||||
if (!getsockname(j, gsa.sa, &socket_type_len)) {
|
||||
if (socket_type_len <= 2) {
|
||||
// unbound socket
|
||||
continue;
|
||||
}
|
||||
if (gsa.sa->sa_family == AF_UNIX) {
|
||||
if (!strcmp(usa.sa_un.sun_path, uwsgi.sockets[i].name)) {
|
||||
uwsgi.sockets[i].fd = j;
|
||||
@@ -1715,7 +1764,7 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && !uwsgi.master_process) {
|
||||
signal(SIGALRM, (void *) &harakiri);
|
||||
}
|
||||
signal(SIGHUP, (void *) &gracefully_kill);
|
||||
uwsgi_unix_signal(SIGHUP, gracefully_kill);
|
||||
signal(SIGINT, (void *) &end_me);
|
||||
signal(SIGTERM, (void *) &reload_me);
|
||||
|
||||
@@ -1954,10 +2003,12 @@ end:
|
||||
return 1;
|
||||
case LONG_ARGS_CLUSTER:
|
||||
uwsgi.cluster = optarg;
|
||||
uwsgi.master_process = 1;
|
||||
return 1;
|
||||
case LONG_ARGS_CLUSTER_NODES:
|
||||
uwsgi.cluster = optarg;
|
||||
uwsgi.cluster_nodes = 1;
|
||||
uwsgi.master_process = 1;
|
||||
return 1;
|
||||
#endif
|
||||
case LONG_ARGS_CHROOT:
|
||||
@@ -2151,7 +2202,11 @@ end:
|
||||
uwsgi.numproc = rl.rlim_max;
|
||||
}
|
||||
else {
|
||||
#ifdef _SC_NPROCESSORS_ONLN
|
||||
uwsgi.numproc = (sysconf(_SC_NPROCESSORS_ONLN))*2;
|
||||
#else
|
||||
uwsgi.numproc = 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -2641,6 +2696,11 @@ int uwsgi_cluster_add_me() {
|
||||
uint16_t ustrlen;
|
||||
char numproc[6];
|
||||
|
||||
if (!uwsgi.sockets[0].name) {
|
||||
uwsgi_log("you need to specify at least a socket to start a uWSGI cluster\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
snprintf(numproc, 6, "%d", uwsgi.numproc);
|
||||
|
||||
size_t len = 2 + strlen(key1) + 2 + strlen(uwsgi.hostname) + 2 + strlen(key2) + 2 + strlen(uwsgi.sockets[0].name) + 2 + strlen(key3) + 2 + strlen(numproc) + 2 + strlen(key4) + 2 + 1;
|
||||
|
||||
@@ -1163,10 +1163,10 @@ 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 gracefully_kill(int);
|
||||
void reap_them_all(void);
|
||||
void kill_them_all(void);
|
||||
void grace_them_all(void);
|
||||
void grace_them_all(int);
|
||||
void reload_me(void);
|
||||
void end_me(void);
|
||||
int bind_to_unix(char *, int, int, int);
|
||||
@@ -1566,6 +1566,7 @@ int uwsgi_dict_set(struct uwsgi_dict *, char *, uint16_t, char *, uint64_t);
|
||||
|
||||
struct uwsgi_subscriber_name *uwsgi_get_subscriber(struct uwsgi_dict *, char *, uint16_t);
|
||||
|
||||
#ifndef _NO_UWSGI_RB
|
||||
#include "lib/rbtree.h"
|
||||
|
||||
struct uwsgi_rb_timer {
|
||||
@@ -1579,3 +1580,9 @@ struct uwsgi_rb_timer {
|
||||
struct rb_root *uwsgi_init_rb_timer(void);
|
||||
struct uwsgi_rb_timer *uwsgi_add_rb_timer(struct rb_root *, time_t, void *);
|
||||
struct uwsgi_rb_timer *uwsgi_min_rb_timer(struct rb_root *);
|
||||
|
||||
#endif
|
||||
|
||||
void uwsgi_nuclear_blast();
|
||||
|
||||
void uwsgi_unix_signal(int, void (*)(int));
|
||||
|
||||
+4
-1
@@ -2,6 +2,7 @@
|
||||
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
uwsgi_os = os.uname()[0]
|
||||
uwsgi_os_k = re.split('[-+]', os.uname()[2])[0]
|
||||
uwsgi_os_v = os.uname()[3]
|
||||
@@ -208,6 +209,8 @@ class uConf(object):
|
||||
sys.exit(1)
|
||||
|
||||
def get_gcll(self):
|
||||
|
||||
self.cflags.append('-DUWSGI_BUILD_DATE="\\"%s\\""' % time.strftime("%d %B %Y %H:%M:%S"))
|
||||
kvm_list = ['FreeBSD', 'OpenBSD', 'NetBSD', 'DragonFly']
|
||||
|
||||
if uwsgi_os == 'SunOS':
|
||||
@@ -256,7 +259,7 @@ class uConf(object):
|
||||
if int(sun_major) >= 5:
|
||||
if int(sun_minor) >= 10:
|
||||
event_mode = 'port'
|
||||
elif uwsgi_os in ('Darwin', 'FreeBSD', 'OpenBSD'):
|
||||
elif uwsgi_os in ('Darwin', 'FreeBSD', 'OpenBSD', 'NetBSD'):
|
||||
event_mode = 'kqueue'
|
||||
|
||||
if event_mode == 'epoll':
|
||||
|
||||
Reference in New Issue
Block a user