mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-10-04 16:08:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d4172a271 | ||
|
|
e842a181aa | ||
|
|
1ba0935579 | ||
|
|
920d1e5cfe | ||
|
|
473b4f1e57 | ||
|
|
b5c19bc1f8 | ||
|
|
79222adfe7 | ||
|
|
8b90efc567 | ||
|
|
4667eedc2b | ||
|
|
752252c9e4 | ||
|
|
6d91b7317d | ||
|
|
cddd1148fd | ||
|
|
c2096e8373 | ||
|
|
4f57ef33af | ||
|
|
aa34beade1 | ||
|
|
1149e60125 | ||
|
|
7def85636e | ||
|
|
d44692b268 | ||
|
|
46322b84b4 | ||
|
|
5785c61a13 | ||
|
|
594880fb46 | ||
|
|
4373306f78 | ||
|
|
f3e164b397 | ||
|
|
a60bb56b18 | ||
|
|
d08d08f39b | ||
|
|
4c4c2bb0fe | ||
|
|
cf79ce40e4 | ||
|
|
c153c26c18 | ||
|
|
82f5d1f988 | ||
|
|
5de83201ea | ||
|
|
6d69c01651 | ||
|
|
61f3d162a4 | ||
|
|
0a025ef93a | ||
|
|
f0951d3f41 | ||
|
|
f2e4eabf42 | ||
|
|
4fc99b3a3e | ||
|
|
1efb3f4096 | ||
|
|
9c29d6899f | ||
|
|
9a7524b55d | ||
|
|
04dfc3ae19 | ||
|
|
fc10411adb | ||
|
|
2378db4520 | ||
|
|
bdbd484db5 | ||
|
|
a2f6dd4ee2 | ||
|
|
ac001beb41 | ||
|
|
05895c40f7 | ||
|
|
fbf9a5b27c | ||
|
|
9c84e9f6cc | ||
|
|
486796bdf9 | ||
|
|
e795cd8912 | ||
|
|
643fc3019b | ||
|
|
f409e8b501 | ||
|
|
361ec8bcd4 | ||
|
|
ba3ac9ad09 | ||
|
|
419f1801cd | ||
|
|
d3c5ccc061 | ||
|
|
be6f61aa1b | ||
|
|
eb6c35aa95 | ||
|
|
797b14b23e | ||
|
|
44e7be13e2 | ||
|
|
18f6660603 | ||
|
|
c3f64af2df | ||
|
|
2278f98318 | ||
|
|
b4ee27b524 | ||
|
|
85ee422dcb | ||
|
|
15f70b2444 | ||
|
|
b7b126e89f | ||
|
|
56e284e18a | ||
|
|
0d4f4a2411 | ||
|
|
68049a5177 | ||
|
|
fc2355e5be | ||
|
|
49925e95d4 | ||
|
|
bee171e5da | ||
|
|
df809c8e34 | ||
|
|
3b64838324 | ||
|
|
f1f51948eb | ||
|
|
906da5cb9a | ||
|
|
dacad8d9b9 | ||
|
|
39fbea6d48 | ||
|
|
4796f85277 | ||
|
|
01ee66d1f6 | ||
|
|
6c61ac9c7e | ||
|
|
77c279b3a9 | ||
|
|
34430ceac4 | ||
|
|
fd1f79d154 | ||
|
|
56f7d09b2b | ||
|
|
479df7c2cc | ||
|
|
69c41026a4 | ||
|
|
7a305704f1 | ||
|
|
8d44dff97e | ||
|
|
c9324c06ca | ||
|
|
3446c2d322 | ||
|
|
6704d1a95a | ||
|
|
0e539f25cd | ||
|
|
00eb37f724 | ||
|
|
30c6ac8cb8 | ||
|
|
faa13228a5 | ||
|
|
e1941a49b8 | ||
|
|
d32f7b997d | ||
|
|
972333941d | ||
|
|
1691263744 | ||
|
|
debfe5b2b9 | ||
|
|
d2ce28f441 | ||
|
|
b9170b2c85 | ||
|
|
33a6195e44 | ||
|
|
933ef85cf2 | ||
|
|
0b27d41712 | ||
|
|
2124b930fd | ||
|
|
b5a2a89630 | ||
|
|
22bf9b33b0 | ||
|
|
b44c2208d9 | ||
|
|
44136aa572 | ||
|
|
5dd62ef909 | ||
|
|
5ea95c9e89 | ||
|
|
8095a9108c | ||
|
|
1cbc423afc | ||
|
|
4e260fa8a1 | ||
|
|
bb4be12fda | ||
|
|
672fb0eaa6 | ||
|
|
def274f28c | ||
|
|
be9f1578cc | ||
|
|
8d8f3bdc51 | ||
|
|
4d9720e4b5 | ||
|
|
6e2adf9cf3 | ||
|
|
7f004c5d6d | ||
|
|
13e7b53c54 | ||
|
|
1c89522519 | ||
|
|
3b4581a581 | ||
|
|
dfaa1d9313 | ||
|
|
795721b91e | ||
|
|
6bd0095513 | ||
|
|
38682590e9 | ||
|
|
aa2a212be8 | ||
|
|
51714203a7 | ||
|
|
fbac57a903 | ||
|
|
768d1c4099 | ||
|
|
82fa510030 | ||
|
|
a6e6bff082 | ||
|
|
304f847dc6 | ||
|
|
5bb7f02921 | ||
|
|
02ee60c6ef | ||
|
|
4d3526a377 | ||
|
|
ca9d1830bb | ||
|
|
4ff485d565 | ||
|
|
63d5c6afc9 | ||
|
|
3a36551d1f | ||
|
|
26877e1da9 | ||
|
|
d81330c514 | ||
|
|
441013b71b | ||
|
|
a6b9e653a4 | ||
|
|
c7161139e7 | ||
|
|
ce07c1a454 | ||
|
|
4eb3b76c35 | ||
|
|
3519fcbcc6 | ||
|
|
70dd9fca32 | ||
|
|
a573602171 | ||
|
|
29418654d7 | ||
|
|
31c31c4ce2 | ||
|
|
0217766dd1 | ||
|
|
3d15660407 | ||
|
|
57ce416ae1 | ||
|
|
248a22b064 | ||
|
|
49c5206d86 | ||
|
|
5b17363b40 | ||
|
|
e6c3c04e64 | ||
|
|
9a36b2b891 | ||
|
|
bfd699dac5 | ||
|
|
cc3e43eb3d | ||
|
|
b934ac9588 | ||
|
|
92b6c62cac | ||
|
|
46cceb0465 | ||
|
|
f1b3522c2a | ||
|
|
c99f5d0875 | ||
|
|
b972c2d6bb | ||
|
|
d226f65890 | ||
|
|
60b54c4d7c | ||
|
|
ace79b1179 | ||
|
|
9993e3710c | ||
|
|
98541dbc65 | ||
|
|
cabb6d72d9 | ||
|
|
217f2f99ff | ||
|
|
890e0004b6 | ||
|
|
d17d947cd1 | ||
|
|
a69c775cd5 | ||
|
|
4c051d90ed | ||
|
|
f55c52eaff | ||
|
|
88b5f968a4 | ||
|
|
6fdeecce0f | ||
|
|
f6923728d8 | ||
|
|
cf96783dce | ||
|
|
e4d3d209c8 | ||
|
|
5182eaf485 | ||
|
|
082d47e156 | ||
|
|
0715031b00 | ||
|
|
27c3532617 | ||
|
|
cb1370b148 | ||
|
|
9cc58a3c13 | ||
|
|
150f0c631e | ||
|
|
0574a120bc | ||
|
|
c6550ece68 | ||
|
|
e76a40530b | ||
|
|
31c73ce298 | ||
|
|
b304766718 | ||
|
|
0ab1cfacc9 | ||
|
|
b1f06bce32 | ||
|
|
347ef1a5bf | ||
|
|
b4d9eb4f73 | ||
|
|
f44a36900a | ||
|
|
b6c969254d | ||
|
|
c5003561dd | ||
|
|
18dead4cd2 | ||
|
|
62aee259fa | ||
|
|
69c49f713e | ||
|
|
08525a91ee | ||
|
|
40fee74a5f | ||
|
|
6d8f179863 | ||
|
|
d0b3c442c1 | ||
|
|
de82b58952 | ||
|
|
eb33fa7b19 | ||
|
|
9dde5f9d82 | ||
|
|
036df0e5ff | ||
|
|
1154aa8ddc | ||
|
|
3371dd2f94 | ||
|
|
06791376af | ||
|
|
30e0af3826 | ||
|
|
e4903ee0bf | ||
|
|
859c386b40 | ||
|
|
b83fecf4d3 | ||
|
|
25dc608fa3 | ||
|
|
c01cf1f6be | ||
|
|
9825f95ed5 | ||
|
|
36143381e1 | ||
|
|
8c25bafc73 | ||
|
|
826f49c010 | ||
|
|
8b006c0874 | ||
|
|
5806c333f5 | ||
|
|
e606d1e5d1 | ||
|
|
2ccdd0fb67 |
@@ -1,3 +1,5 @@
|
||||
surprise i am empty !
|
||||
The uWSGI project
|
||||
|
||||
Look in the online documentation on https://uwsgi-docs.readthedocs.org/en/latest/
|
||||
For official documentation check: https://uwsgi-docs.readthedocs.org/en/latest/
|
||||
|
||||
For commercial support check: http://unbit.com/
|
||||
|
||||
@@ -1,441 +0,0 @@
|
||||
#include "../../uwsgi.h"
|
||||
#include "erlang.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
struct uwsgi_erlang uerl;
|
||||
|
||||
struct uwsgi_option erlang_options[] = {
|
||||
{"erlang", required_argument, 0, "spawn an erlang c-node", uwsgi_opt_set_str, &uerl.name, UWSGI_OPT_MASTER},
|
||||
{"erlang-cookie", required_argument, 0, "set erlang cookie", uwsgi_opt_set_str, &uerl.cookie, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
|
||||
void dump_eterm(ei_x_buff *x) {
|
||||
|
||||
int etype, esize, arity;
|
||||
long long num;
|
||||
char *atom;
|
||||
int i;
|
||||
char *binary;
|
||||
long bin_size;
|
||||
double fnum;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
uwsgi_log("etype: %d/%c esize: %d\n", etype, etype, esize);
|
||||
|
||||
switch(etype) {
|
||||
case ERL_SMALL_INTEGER_EXT:
|
||||
case ERL_INTEGER_EXT:
|
||||
case ERL_SMALL_BIG_EXT:
|
||||
case ERL_LARGE_BIG_EXT:
|
||||
ei_decode_longlong(x->buff, &x->index, &num);
|
||||
uwsgi_log("num: %lu\n", num);
|
||||
break;
|
||||
case ERL_FLOAT_EXT:
|
||||
ei_decode_double(x->buff, &x->index, &fnum);
|
||||
uwsgi_log("float: %f\n", fnum);
|
||||
break;
|
||||
case ERL_STRING_EXT:
|
||||
atom = uwsgi_malloc(esize+1);
|
||||
ei_decode_string(x->buff, &x->index, atom);
|
||||
uwsgi_log("string: %s\n", atom);
|
||||
free(atom);
|
||||
break;
|
||||
case ERL_ATOM_EXT:
|
||||
atom = uwsgi_malloc(esize+1);
|
||||
ei_decode_atom(x->buff, &x->index, atom);
|
||||
uwsgi_log("atom: %s\n", atom);
|
||||
free(atom);
|
||||
break;
|
||||
case ERL_SMALL_TUPLE_EXT:
|
||||
case ERL_LARGE_TUPLE_EXT:
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
for(i=0;i<arity;i++) {
|
||||
dump_eterm(x);
|
||||
}
|
||||
break;
|
||||
case ERL_LIST_EXT:
|
||||
case ERL_NIL_EXT:
|
||||
ei_decode_list_header(x->buff, &x->index, &arity);
|
||||
if (arity == 0) {
|
||||
uwsgi_log("nil value\n");
|
||||
break;
|
||||
}
|
||||
for(i=0;i<arity+1;i++) {
|
||||
dump_eterm(x);
|
||||
}
|
||||
break;
|
||||
case ERL_BINARY_EXT:
|
||||
binary = uwsgi_malloc(esize);
|
||||
ei_decode_binary(x->buff, &x->index, binary, &bin_size);
|
||||
uwsgi_log("binary data of %d bytes\n", bin_size);
|
||||
free(binary);
|
||||
break;
|
||||
default:
|
||||
uwsgi_log("ignored...\n");
|
||||
ei_skip_term(x->buff, &x->index);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void uwsgi_erlang_rpc(int fd, erlang_pid *from, ei_x_buff *x) {
|
||||
|
||||
int etype, esize;
|
||||
int arity;
|
||||
|
||||
char *gen_call;
|
||||
char *module;
|
||||
char *call;
|
||||
char buffer[0xffff];
|
||||
|
||||
char *argv[256] ;
|
||||
uint16_t argvs[256] ;
|
||||
int argc = 0;
|
||||
uint16_t ret;
|
||||
ei_x_buff xr;
|
||||
|
||||
erlang_ref eref;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("%d %c %c %c\n", etype, etype, ERL_SMALL_TUPLE_EXT, ERL_LARGE_TUPLE_EXT);
|
||||
#endif
|
||||
if (etype != ERL_SMALL_TUPLE_EXT && etype != ERL_LARGE_TUPLE_EXT) return;
|
||||
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("rpc arity %d\n", arity);
|
||||
#endif
|
||||
if (arity != 3) return ;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_ATOM_EXT && etype != ERL_STRING_EXT) return ;
|
||||
|
||||
gen_call = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, gen_call);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, gen_call);
|
||||
}
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("gen call = %s\n", gen_call);
|
||||
#endif
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_SMALL_TUPLE_EXT) return ;
|
||||
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
if (arity != 2) return ;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
ei_skip_term(x->buff, &x->index);
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
ei_decode_ref(x->buff, &x->index, &eref);
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
module = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, module);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, module);
|
||||
}
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_SMALL_TUPLE_EXT) return ;
|
||||
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("arity: %d\n", arity);
|
||||
#endif
|
||||
if (arity != 5) return ;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
char *method = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, method);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, method);
|
||||
}
|
||||
|
||||
if (strcmp(method, "call")) return;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_ATOM_EXT && etype != ERL_STRING_EXT) return ;
|
||||
|
||||
module = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, module);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, module);
|
||||
}
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype != ERL_ATOM_EXT && etype != ERL_STRING_EXT) return ;
|
||||
|
||||
call = uwsgi_malloc(esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
ei_decode_atom(x->buff, &x->index, call);
|
||||
}
|
||||
else {
|
||||
ei_decode_string(x->buff, &x->index, call);
|
||||
}
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("RPC %s %s\n", module, call);
|
||||
#endif
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
if (etype == ERL_ATOM_EXT) {
|
||||
argc = 1;
|
||||
argv[0] = uwsgi_malloc(esize+1);
|
||||
ei_decode_atom(x->buff, &x->index, argv[0]);
|
||||
argvs[1] = esize;
|
||||
}
|
||||
else if (etype == ERL_STRING_EXT) {
|
||||
argc = 1;
|
||||
argv[0] = uwsgi_malloc(esize+1);
|
||||
ei_decode_string(x->buff, &x->index, argv[0]);
|
||||
argvs[1] = esize;
|
||||
}
|
||||
|
||||
ret = uwsgi_rpc(call, argc, argv, argvs, buffer);
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("buffer: %.*s\n", ret, buffer);
|
||||
#endif
|
||||
|
||||
ei_x_new_with_version(&xr);
|
||||
|
||||
ei_x_encode_tuple_header(&xr, 2);
|
||||
//ei_x_encode_atom(&xr, "rex");
|
||||
ei_x_encode_ref(&xr, &eref);
|
||||
ei_x_encode_string_len(&xr, buffer, ret);
|
||||
|
||||
uwsgi_log("ei_send to %d %s %d %d %d: %d %d\n", fd, from->node, from->num , from->serial, from->creation, xr.index, ei_send(fd, from, xr.buff, xr.index));
|
||||
//uwsgi_log("ei_send to %d %s %d %d %d: %d %d\n", fd, from->node, from->num , from->serial, from->creation, xr.index, ei_reg_send(&uerl.cnode, fd, "rex", xr.buff, xr.index));
|
||||
|
||||
|
||||
}
|
||||
|
||||
void erlang_loop(int id, void *data) {
|
||||
|
||||
ErlConnect econn;
|
||||
//ErlMessage em;
|
||||
erlang_msg em;
|
||||
int fd;
|
||||
|
||||
int eversion;
|
||||
|
||||
ei_x_buff x, xr;
|
||||
|
||||
ei_x_new(&x);
|
||||
ei_x_new(&xr);
|
||||
|
||||
|
||||
/*
|
||||
int fd0 = ei_connect(&uerl.cnode, "anothernode@maverick64");
|
||||
uwsgi_log("fd0: %d\n", fd0);
|
||||
|
||||
ei_x_encode_list_header(&x, 0);
|
||||
|
||||
ei_rpc_to(&uerl.cnode, fd0, "erlang", "node", x.buff, x.index);
|
||||
|
||||
ei_rpc_from(&uerl.cnode, fd0, 10000, &em, &xr);
|
||||
|
||||
uwsgi_log("From: %s To: %s RegName: %s\n", em.from.node, em.to.node, em.toname);
|
||||
|
||||
xr.index = 0;
|
||||
ei_decode_version(xr.buff, &xr.index, &eversion);
|
||||
uwsgi_log("eversion: %d\n", eversion);
|
||||
|
||||
dump_eterm(&xr);
|
||||
*/
|
||||
|
||||
for(;;) {
|
||||
|
||||
fd = ei_accept(&uerl.cnode, uerl.fd, &econn);
|
||||
|
||||
if (fd >= 0) {
|
||||
|
||||
for (;;) {
|
||||
if (ei_xreceive_msg(fd, &em, &x) == ERL_MSG) {
|
||||
|
||||
if (em.msgtype == ERL_TICK)
|
||||
continue;
|
||||
|
||||
uwsgi_log("[erlang] message From: %s To (process): %s\n", em.from.node, em.toname);
|
||||
|
||||
|
||||
|
||||
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 {
|
||||
struct uwsgi_erlang_process *uep = uerl.uep;
|
||||
while(uep) {
|
||||
if (!strcmp(uep->name, em.toname)) {
|
||||
if (uep->plugin) {
|
||||
uep->plugin(uep->func, &x);
|
||||
}
|
||||
break;
|
||||
}
|
||||
uep = uep->next;
|
||||
}
|
||||
|
||||
if (!uep) {
|
||||
uwsgi_log("!!! unregistered erlang process requested, dumping it !!!\n");
|
||||
dump_eterm(&x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
if (em.msgtype) {
|
||||
dump_erl_obj(em.msg);
|
||||
erl_free_compound(em.msg);
|
||||
}
|
||||
if (em.to) {
|
||||
uwsgi_log("*** TO ***\n");
|
||||
dump_erl_obj(em.to);
|
||||
erl_free_compound(em.to);
|
||||
}
|
||||
|
||||
if (em.from) {
|
||||
uwsgi_log("*** FROM ***\n");
|
||||
dump_erl_obj(em.from);
|
||||
erl_free_compound(em.from);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int erlang_init() {
|
||||
|
||||
char *host;
|
||||
struct sockaddr_in sin;
|
||||
socklen_t slen = sizeof(struct sockaddr_in);
|
||||
char *ip = NULL;
|
||||
char *nodename;
|
||||
struct in_addr addr;
|
||||
|
||||
uerl.lock = uwsgi_lock_init("erlang");
|
||||
|
||||
if (uerl.name) {
|
||||
|
||||
|
||||
host = strchr(uerl.name, '@');
|
||||
|
||||
if (!host) {
|
||||
if (ei_connect_init(&uerl.cnode, uerl.name, uerl.cookie, 0) < 0) {
|
||||
uwsgi_log("unable to initialize erlang connection\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
nodename = uwsgi_concat2n(uerl.name, host-uerl.name, "",0);
|
||||
ip = uwsgi_resolve_ip(host+1);
|
||||
if (ip) {
|
||||
#ifdef UWSGI_DEBUG
|
||||
uwsgi_log("ip: %s\n", ip);
|
||||
#endif
|
||||
addr.s_addr = inet_addr(ip);
|
||||
if (ei_connect_xinit(&uerl.cnode, host+1, nodename, uerl.name, &addr, uerl.cookie, 0) < 0) {
|
||||
uwsgi_log("unable to initialize erlang connection\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (ei_connect_init(&uerl.cnode, nodename, uerl.cookie, 0) < 0) {
|
||||
uwsgi_log("unable to initialize erlang connection\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
free(nodename);
|
||||
}
|
||||
|
||||
if (ip) {
|
||||
uerl.fd = bind_to_tcp(ip, uwsgi.listen_queue, NULL);
|
||||
}
|
||||
else {
|
||||
uerl.fd = bind_to_tcp("", uwsgi.listen_queue, NULL);
|
||||
}
|
||||
|
||||
if (uerl.fd < 0) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (getsockname(uerl.fd, (struct sockaddr *) &sin, &slen)) {
|
||||
uwsgi_error("getsockname()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (ei_publish(&uerl.cnode, ntohs(sin.sin_port)) < 0) {
|
||||
uwsgi_log( "*** unable to subscribe with EPMD ***\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uwsgi_log("Erlang C-Node %s registered on port %d\n", ei_thisnodename(&uerl.cnode), ntohs(sin.sin_port));
|
||||
|
||||
|
||||
if (register_gateway("uWSGI erlang c-node", erlang_loop, NULL) == NULL) {
|
||||
uwsgi_log("unable to register the erlang gateway\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct uwsgi_plugin erlang_plugin = {
|
||||
|
||||
.name = "erlang",
|
||||
.options = erlang_options,
|
||||
.init = erlang_init,
|
||||
};
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#include <ei.h>
|
||||
|
||||
struct uwsgi_erlang_process {
|
||||
|
||||
char name[0xff];
|
||||
void (*plugin)(void *, ei_x_buff *);
|
||||
void *func;
|
||||
|
||||
struct uwsgi_erlang_process *next;
|
||||
};
|
||||
|
||||
struct uwsgi_erlang {
|
||||
|
||||
ei_cnode cnode;
|
||||
char *name;
|
||||
char *cookie;
|
||||
|
||||
int fd;
|
||||
|
||||
void *lock;
|
||||
|
||||
struct uwsgi_erlang_process *uep;
|
||||
};
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import os
|
||||
|
||||
NAME='erlang'
|
||||
|
||||
ERLANGPATH = os.environ.get('UWSGICONFIG_ERLANGPATH', 'erl')
|
||||
|
||||
includedir = os.popen(ERLANGPATH + " -noshell -noinput -eval \"io:format('~s~n', [code:lib_dir(erl_interface, include)])\" -s erlang halt").read().rstrip()
|
||||
libpath = os.popen(ERLANGPATH + " -noshell -noinput -eval \"io:format('~s~n', [code:lib_dir(erl_interface, lib)])\" -s erlang halt").read().rstrip()
|
||||
|
||||
CFLAGS = [ '-I' + includedir ]
|
||||
LDFLAGS = [ '-L' + libpath ]
|
||||
|
||||
LIBS = ['-lei']
|
||||
|
||||
GCC_LIST = ['erlang']
|
||||
@@ -1,116 +0,0 @@
|
||||
#include <uwsgi.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
void (*uwsgi_go_helper_post_fork_c)();
|
||||
void (*uwsgi_go_helper_post_init_c)();
|
||||
void * (*uwsgi_go_helper_env_new_c)(struct wsgi_request *);
|
||||
void (*uwsgi_go_helper_env_add_c)(void *, char *, int, char *, int);
|
||||
void (*uwsgi_go_helper_request_c)(void *, struct wsgi_request *);
|
||||
int (*uwsgi_go_helper_signal_handler_c)(int, void *);
|
||||
void (*uwsgi_go_helper_run_core_c)(int);
|
||||
char *(*uwsgi_go_helper_version_c)();
|
||||
|
||||
void uwsgi_go_post_fork() {
|
||||
uwsgi_go_helper_post_fork_c();
|
||||
}
|
||||
|
||||
void uwsgi_opt_setup_goroutines(char *opt, char *value, void *foobar) {
|
||||
// set async mode
|
||||
uwsgi_opt_set_int(opt, value, &uwsgi.async);
|
||||
// set loop engine
|
||||
uwsgi.loop = "goroutines";
|
||||
}
|
||||
|
||||
struct uwsgi_option uwsgi_go_options[] = {
|
||||
{"goroutines", required_argument, 0, "a shortcut setting optimal options for goroutine-based apps, takes the number of goroutines to spawn as argument", uwsgi_opt_setup_goroutines, NULL, UWSGI_OPT_THREADS},
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
|
||||
};
|
||||
|
||||
#define uwsgi_go_get_symbol(x) x ## _c = dlsym(RTLD_DEFAULT, #x);\
|
||||
if (!x ## _c) {\
|
||||
uwsgi_log("[uwsgi-go] unable to load " #x " function\n"); exit(1);\
|
||||
}
|
||||
|
||||
static int uwsgi_go_init() {
|
||||
|
||||
// build the functions table
|
||||
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_post_fork)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_post_init)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_env_new)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_env_add)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_request)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_signal_handler)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_run_core)
|
||||
uwsgi_go_get_symbol(uwsgi_go_helper_version)
|
||||
|
||||
uwsgi_log("Go version \"%s\" initialized\n", uwsgi_go_helper_version_c());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_go_request(struct wsgi_request *wsgi_req) {
|
||||
/* Standard GO request */
|
||||
if (!wsgi_req->uh->pktsize) {
|
||||
uwsgi_log("Empty GO request. skip.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uwsgi_parse_vars(wsgi_req)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
wsgi_req->async_environ = uwsgi_go_helper_env_new_c(wsgi_req);
|
||||
int i;
|
||||
for(i=0;i<wsgi_req->var_cnt;i++) {
|
||||
uwsgi_go_helper_env_add_c(wsgi_req->async_environ, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len,
|
||||
wsgi_req->hvec[i+1].iov_base, wsgi_req->hvec[i+1].iov_len);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
uwsgi_go_helper_request_c(wsgi_req->async_environ, wsgi_req);
|
||||
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
static void uwsgi_go_after_request(struct wsgi_request *wsgi_req) {
|
||||
log_request(wsgi_req);
|
||||
}
|
||||
|
||||
static int uwsgi_go_signal_handler(uint8_t signum, void *handler) {
|
||||
return uwsgi_go_helper_signal_handler_c((int)signum, handler);
|
||||
}
|
||||
|
||||
static void goroutines_loop() {
|
||||
int i;
|
||||
for (i = 1; i < uwsgi.async; i++) {
|
||||
uwsgi_go_helper_run_core_c(i);
|
||||
}
|
||||
simple_loop_run_int(0);
|
||||
}
|
||||
|
||||
static void uwsgi_go_on_load() {
|
||||
uwsgi_register_loop("goroutines", goroutines_loop);
|
||||
}
|
||||
|
||||
static void uwsgi_go_call_init_hook() {
|
||||
if (uwsgi_go_helper_post_init_c) {
|
||||
uwsgi_go_helper_post_init_c();
|
||||
}
|
||||
}
|
||||
|
||||
struct uwsgi_plugin go_plugin = {
|
||||
.name = "go",
|
||||
.modifier1 = 11,
|
||||
.request = uwsgi_go_request,
|
||||
.after_request = uwsgi_go_after_request,
|
||||
.preinit_apps = uwsgi_go_call_init_hook,
|
||||
.post_fork = uwsgi_go_post_fork,
|
||||
.init = uwsgi_go_init,
|
||||
.signal_handler = uwsgi_go_signal_handler,
|
||||
.on_load = uwsgi_go_on_load,
|
||||
.options = uwsgi_go_options,
|
||||
};
|
||||
@@ -1,420 +0,0 @@
|
||||
/*
|
||||
uWSGI go integration package
|
||||
*/
|
||||
|
||||
package uwsgi
|
||||
|
||||
/*
|
||||
#include <uwsgi.h>
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
// commodity functions to simulate argc/argv
|
||||
|
||||
static char ** uwsgi_go_helper_create_argv(int len) {
|
||||
return uwsgi_calloc(sizeof(char *) * len);
|
||||
}
|
||||
|
||||
static void uwsgi_go_helper_set_argv(char **argv, int pos, char *item) {
|
||||
argv[pos] = item;
|
||||
}
|
||||
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"net/http"
|
||||
"net/http/cgi"
|
||||
"unsafe"
|
||||
"strings"
|
||||
"strconv"
|
||||
"io"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// this stores the modifier used by the go plugin (default 11)
|
||||
var uwsgi_modifier1 int = -1;
|
||||
// the following to objects are used to implement a sort of GC to avoid request environ and
|
||||
// signal handlers to be garbage collected
|
||||
var uwsgi_env_gc = make(map[*C.struct_wsgi_request](*map[string]string))
|
||||
var uwsgi_signals_gc = make([]*func(int), 256)
|
||||
|
||||
var uwsgi_default_request_handler func(http.ResponseWriter, *http.Request) = nil
|
||||
var uwsgi_default_handler http.Handler = nil
|
||||
var uwsgi_post_fork_hook func() = nil
|
||||
var uwsgi_post_init_hook func() = nil
|
||||
|
||||
|
||||
/*
|
||||
|
||||
uWSGI api functions
|
||||
|
||||
*/
|
||||
|
||||
// raise a uWSGI signal
|
||||
func Signal(signum int) {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return
|
||||
}
|
||||
C.uwsgi_signal_send(C.uwsgi.signal_socket, C.uint8_t(signum))
|
||||
}
|
||||
|
||||
// set a user lock
|
||||
func Lock(num int) {
|
||||
C.uwsgi_user_lock(C.int(num));
|
||||
}
|
||||
|
||||
// unset a user lock
|
||||
func Unlock(num int) {
|
||||
C.uwsgi_user_unlock(C.int(num));
|
||||
}
|
||||
|
||||
// add a timer
|
||||
func AddTimer(signum int, seconds int) bool {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return false
|
||||
}
|
||||
if int(C.uwsgi_add_timer(C.uint8_t(signum), C.int(seconds))) == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// add a red black timer
|
||||
func AddRbTimer(signum int, seconds int) bool {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return false
|
||||
}
|
||||
if int(C.uwsgi_signal_add_rb_timer(C.uint8_t(signum), C.int(seconds), C.int(0))) == 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// check if a signal is registered
|
||||
func SignalRegistered(signum int) bool {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return false
|
||||
}
|
||||
if int(C.uwsgi_signal_registered(C.uint8_t(signum))) == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// register a signal
|
||||
func RegisterSignal(signum int, who string, handler func(int)) bool {
|
||||
if C.uwsgi.master_process == 0 {
|
||||
return false
|
||||
}
|
||||
if uwsgi_modifier1 == -1 {
|
||||
c_go := C.CString("go")
|
||||
defer C.free(unsafe.Pointer(c_go))
|
||||
uwsgi_modifier1 = int(C.uwsgi_plugin_modifier1(c_go))
|
||||
if uwsgi_modifier1 == -1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
c_who := C.CString(who)
|
||||
defer C.free(unsafe.Pointer(c_who))
|
||||
if int(C.uwsgi_register_signal(C.uint8_t(signum), c_who, unsafe.Pointer(&handler), C.uint8_t(uwsgi_modifier1))) == 0 {
|
||||
uwsgi_signals_gc[signum] = &handler
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func Alarm(alarm string, msg string) {
|
||||
a := C.CString(alarm)
|
||||
defer C.free(unsafe.Pointer(a))
|
||||
m := C.CString(msg)
|
||||
defer C.free(unsafe.Pointer(m))
|
||||
ml := len(msg)
|
||||
C.uwsgi_alarm_trigger(a, m, C.size_t(ml))
|
||||
}
|
||||
|
||||
// get an item from the cache
|
||||
func CacheGet(key string, cache string) []byte {
|
||||
|
||||
k := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(k))
|
||||
kl := len(key)
|
||||
var vl C.uint64_t = C.uint64_t(0)
|
||||
|
||||
|
||||
c := (*C.char)(nil)
|
||||
if len(cache) > 0 {
|
||||
c = C.CString(cache)
|
||||
defer C.free(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
var p []byte
|
||||
|
||||
c_value := C.uwsgi_cache_magic_get(k, C.uint16_t(kl), &vl, (*C.uint64_t)(nil), c)
|
||||
|
||||
if c_value != nil {
|
||||
p = C.GoBytes((unsafe.Pointer)(c_value), C.int(vl))
|
||||
} else {
|
||||
p = nil
|
||||
}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// remove an intem from the cache
|
||||
func CacheDel(key string, cache string) bool {
|
||||
|
||||
k := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(k))
|
||||
kl := len(key)
|
||||
|
||||
c := (*C.char)(nil)
|
||||
if len(cache) > 0 {
|
||||
c = C.CString(cache)
|
||||
defer C.free(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
if int(C.uwsgi_cache_magic_del(k, C.uint16_t(kl), c)) < 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// check if an item exists in the cache
|
||||
func CacheExists(key string, cache string) bool {
|
||||
k := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(k))
|
||||
kl := len(key)
|
||||
|
||||
c := (*C.char)(nil)
|
||||
if len(cache) > 0 {
|
||||
c = C.CString(cache)
|
||||
defer C.free(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
if int(C.uwsgi_cache_magic_exists(k, C.uint16_t(kl), c)) == 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// put an item in the cache
|
||||
func CacheSetFlags(key string, p []byte, expires uint64, flags int, cache string) bool {
|
||||
|
||||
k := C.CString(key)
|
||||
defer C.free(unsafe.Pointer(k))
|
||||
kl := len(key)
|
||||
v := unsafe.Pointer(&p[0])
|
||||
vl := len(p)
|
||||
|
||||
c := (*C.char)(nil)
|
||||
if len(cache) > 0 {
|
||||
c = C.CString(cache)
|
||||
defer C.free(unsafe.Pointer(c))
|
||||
}
|
||||
|
||||
if int(C.uwsgi_cache_magic_set(k, C.uint16_t(kl), (*C.char)(v), C.uint64_t(vl), C.uint64_t(expires), C.uint64_t(flags), c)) < 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func CacheSet(key string, p []byte, expires uint64, cache string) bool {
|
||||
return CacheSetFlags(key, p, expires, 0, cache);
|
||||
}
|
||||
|
||||
func CacheUpdate(key string, p []byte, expires uint64, cache string) bool {
|
||||
return CacheSetFlags(key, p, expires, 2, cache);
|
||||
}
|
||||
|
||||
// get the current worker id
|
||||
func WorkerId() int {
|
||||
return int(C.uwsgi.mywid)
|
||||
}
|
||||
|
||||
// get the current mule id
|
||||
func MuleId() int {
|
||||
return int(C.uwsgi.muleid)
|
||||
}
|
||||
|
||||
// get the current logsize (if available)
|
||||
func LogSize() int64 {
|
||||
return int64(C.uwsgi.shared.logsize)
|
||||
}
|
||||
|
||||
func PostFork(hook func()) {
|
||||
uwsgi_post_fork_hook = hook
|
||||
}
|
||||
|
||||
func PostInit(hook func()) {
|
||||
uwsgi_post_init_hook = hook
|
||||
}
|
||||
|
||||
func RequestHandler(hook func(http.ResponseWriter, *http.Request)) {
|
||||
uwsgi_default_request_handler = hook
|
||||
}
|
||||
|
||||
func Handler(handler http.Handler) {
|
||||
uwsgi_default_handler = handler
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
C -> go and go -> C bridges
|
||||
|
||||
*/
|
||||
|
||||
//export uwsgi_go_helper_post_fork
|
||||
func uwsgi_go_helper_post_fork() {
|
||||
if uwsgi_post_fork_hook != nil {
|
||||
uwsgi_post_fork_hook()
|
||||
}
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_post_init
|
||||
func uwsgi_go_helper_post_init() {
|
||||
if uwsgi_post_init_hook != nil {
|
||||
uwsgi_post_init_hook()
|
||||
}
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_env_new
|
||||
func uwsgi_go_helper_env_new(wsgi_req *C.struct_wsgi_request) *map[string]string {
|
||||
var env map[string]string
|
||||
env = make(map[string]string)
|
||||
// track env to avoid it being garbage collected...
|
||||
uwsgi_env_gc[wsgi_req] = &env
|
||||
return &env
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_env_add
|
||||
func uwsgi_go_helper_env_add(env *map[string]string, k *C.char, kl C.int, v *C.char, vl C.int) {
|
||||
var mk string = C.GoStringN(k, kl)
|
||||
var mv string = C.GoStringN(v, vl)
|
||||
(*env)[mk] = mv
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
http.* implementations
|
||||
|
||||
*/
|
||||
|
||||
type ResponseWriter struct {
|
||||
r *http.Request
|
||||
wsgi_req *C.struct_wsgi_request
|
||||
headers http.Header
|
||||
wroteHeader bool
|
||||
}
|
||||
|
||||
func (w *ResponseWriter) Write(p []byte) (n int, err error) {
|
||||
if !w.wroteHeader {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
m := len(p)
|
||||
C.uwsgi_response_write_body_do(w.wsgi_req, (*C.char)(unsafe.Pointer(&p[0])), C.size_t(m))
|
||||
return m+n, err
|
||||
}
|
||||
|
||||
// TODO fix it !!!
|
||||
func (w *ResponseWriter) WriteHeader(status int) {
|
||||
codestring := http.StatusText(status)
|
||||
var tmp_buf string = strconv.Itoa(status) + " " + codestring
|
||||
c_status := C.CString(tmp_buf)
|
||||
defer C.free(unsafe.Pointer(c_status))
|
||||
C.uwsgi_response_prepare_headers(w.wsgi_req, c_status, C.uint16_t(len(tmp_buf)) )
|
||||
if w.headers.Get("Content-Type") == "" {
|
||||
w.headers.Set("Content-Type", "text/html; charset=utf-8")
|
||||
}
|
||||
for k := range w.headers {
|
||||
hk_c := C.CString(k)
|
||||
defer C.free(unsafe.Pointer(hk_c))
|
||||
for _, v := range w.headers[k] {
|
||||
v = strings.NewReplacer("\n", " ", "\r", " ").Replace(v)
|
||||
v = strings.TrimSpace(v)
|
||||
hv_c := C.CString(v)
|
||||
defer C.free(unsafe.Pointer(hv_c))
|
||||
C.uwsgi_response_add_header(w.wsgi_req, hk_c, C.uint16_t(len(k)), hv_c, C.uint16_t(len(v)))
|
||||
}
|
||||
}
|
||||
w.wroteHeader = true
|
||||
}
|
||||
|
||||
func (w *ResponseWriter) Header() http.Header {
|
||||
return w.headers
|
||||
}
|
||||
|
||||
|
||||
type BodyReader struct {
|
||||
wsgi_req *C.struct_wsgi_request
|
||||
}
|
||||
|
||||
// there is no close in request body
|
||||
func (br *BodyReader) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (br *BodyReader) Read(p []byte) (n int, err error) {
|
||||
m := len(p)
|
||||
var rlen C.ssize_t = C.ssize_t(0)
|
||||
c_body := C.uwsgi_request_body_read(br.wsgi_req, C.ssize_t(m), &rlen)
|
||||
if (c_body == C.uwsgi.empty) {
|
||||
err = io.EOF;
|
||||
return 0, err
|
||||
} else if (c_body != nil) {
|
||||
C.memcpy(unsafe.Pointer(&p[0]), unsafe.Pointer(c_body), C.size_t(rlen))
|
||||
return int(rlen), err
|
||||
}
|
||||
err = io.ErrUnexpectedEOF
|
||||
rlen = 0
|
||||
return int(rlen), err
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_request
|
||||
func uwsgi_go_helper_request(env *map[string]string, wsgi_req *C.struct_wsgi_request) {
|
||||
httpReq, err := cgi.RequestFromMap(*env)
|
||||
if err != nil {
|
||||
} else {
|
||||
httpReq.Body = &BodyReader{wsgi_req}
|
||||
w := ResponseWriter{httpReq, wsgi_req,http.Header{},false}
|
||||
if uwsgi_default_request_handler != nil {
|
||||
uwsgi_default_request_handler(&w, httpReq)
|
||||
} else if uwsgi_default_handler != nil {
|
||||
uwsgi_default_handler.ServeHTTP(&w, httpReq)
|
||||
} else {
|
||||
http.DefaultServeMux.ServeHTTP(&w, httpReq)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_version
|
||||
func uwsgi_go_helper_version() *C.char {
|
||||
return C.CString(runtime.Version())
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_signal_handler
|
||||
func uwsgi_go_helper_signal_handler(signum int, handler *func(int)) int {
|
||||
(*handler)(signum)
|
||||
return 0;
|
||||
}
|
||||
|
||||
//export uwsgi_go_helper_run_core
|
||||
func uwsgi_go_helper_run_core(core_id int) {
|
||||
go C.simple_loop_run_int(C.int(core_id))
|
||||
}
|
||||
|
||||
/*
|
||||
the main function, running the uWSGI server via libuwsgi.so
|
||||
*/
|
||||
func Run() {
|
||||
argc := len(os.Args) + 1
|
||||
argv := C.uwsgi_go_helper_create_argv(C.int(argc))
|
||||
for i, s := range os.Args {
|
||||
C.uwsgi_go_helper_set_argv(argv, C.int(i), C.CString(s))
|
||||
}
|
||||
C.uwsgi_init(C.int(argc-1), argv, nil)
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import os
|
||||
NAME='go'
|
||||
|
||||
CFLAGS = []
|
||||
LDFLAGS = []
|
||||
LIBS = []
|
||||
GCC_LIST = ['go_plugin']
|
||||
|
||||
def post_build(config):
|
||||
os.environ['GOPATH'] = 'plugins/go'
|
||||
cflags = ['-I'+os.getcwd()]
|
||||
for c in config.cflags:
|
||||
if not c.startswith('-DUWSGI_BUILD_DATE') and not c.startswith('-DUWSGI_CFLAGS'):
|
||||
cflags.append(c)
|
||||
|
||||
cflags.append('-Wno-implicit-function-declaration')
|
||||
cflags.append('-Wno-implicit-int')
|
||||
cflags.append('-Wno-unused-function')
|
||||
cflags.append('-Wno-unused-variable')
|
||||
|
||||
os.environ['CGO_CFLAGS'] = ' '.join(cflags).replace('\\"', '')
|
||||
base = os.path.dirname(config.get('bin_name'))
|
||||
if not base:
|
||||
base = "."
|
||||
os.environ['CGO_LDFLAGS'] = '-L' + base + ' -L'+os.getcwd() + ' -luwsgi'
|
||||
if os.system("go install uwsgi") != 0:
|
||||
os._exit(1)
|
||||
print("*** uwsgi go module available in $GOPATH %s/plugins/go ***" % os.getcwd())
|
||||
@@ -1,543 +0,0 @@
|
||||
#include "../erlang/erlang.h"
|
||||
#include "../python/uwsgi_python.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
extern struct uwsgi_erlang uerl;
|
||||
extern struct uwsgi_python up;
|
||||
|
||||
ei_cnode *pyerl_cnode;
|
||||
|
||||
PyObject *pyerl_close(PyObject * self, PyObject * args) {
|
||||
|
||||
int fd;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:erlang_close", &fd)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *pyerl_connect(PyObject * self, PyObject * args) {
|
||||
|
||||
char *node = NULL;
|
||||
int fd;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s:erlang_connect", &node)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fd = ei_connect(pyerl_cnode, node);
|
||||
|
||||
if (fd < 0) {
|
||||
return PyErr_Format(PyExc_ValueError, "Unable to connect to erlang node");
|
||||
}
|
||||
|
||||
return PyInt_FromLong(fd);
|
||||
|
||||
}
|
||||
|
||||
int py_to_erl(PyObject *, ei_x_buff*);
|
||||
|
||||
PyObject *erl_to_py(ei_x_buff* x) {
|
||||
|
||||
int etype, esize, arity;
|
||||
long long num;
|
||||
double fnum;
|
||||
char *atom, *binary;
|
||||
long bin_size;
|
||||
PyObject *pobj;
|
||||
PyObject *zero;
|
||||
erlang_pid epid;
|
||||
int i;
|
||||
|
||||
ei_get_type(x->buff, &x->index, &etype, &esize);
|
||||
|
||||
switch(etype) {
|
||||
case ERL_SMALL_INTEGER_EXT:
|
||||
case ERL_INTEGER_EXT:
|
||||
case ERL_SMALL_BIG_EXT:
|
||||
case ERL_LARGE_BIG_EXT:
|
||||
ei_decode_longlong(x->buff, &x->index, &num);
|
||||
return PyLong_FromLong(num);
|
||||
case ERL_FLOAT_EXT:
|
||||
ei_decode_double(x->buff, &x->index, &fnum);
|
||||
return PyFloat_FromDouble(fnum);
|
||||
case ERL_STRING_EXT:
|
||||
atom = uwsgi_malloc(esize+1);
|
||||
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);
|
||||
ei_decode_atom(x->buff, &x->index, atom);
|
||||
#ifndef PyUnicode_FromString
|
||||
zero = PyString_FromString(atom);
|
||||
pobj = PyUnicode_FromObject(zero);
|
||||
Py_DECREF(zero);
|
||||
#else
|
||||
pobj = PyUnicode_FromString(atom);
|
||||
#endif
|
||||
free(atom);
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_SMALL_TUPLE_EXT:
|
||||
case ERL_LARGE_TUPLE_EXT:
|
||||
ei_decode_tuple_header(x->buff, &x->index, &arity);
|
||||
pobj = PyTuple_New(arity);
|
||||
for(i=0;i<arity;i++) {
|
||||
zero = erl_to_py(x);
|
||||
PyTuple_SetItem(pobj, i, zero);
|
||||
Py_DECREF(zero);
|
||||
}
|
||||
Py_INCREF(pobj);
|
||||
return pobj;
|
||||
case ERL_LIST_EXT:
|
||||
case ERL_NIL_EXT:
|
||||
ei_decode_list_header(x->buff, &x->index, &arity);
|
||||
if (!arity) {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
pobj = PyList_New(0);
|
||||
for(i=0;i<arity+1;i++) {
|
||||
zero = erl_to_py(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);
|
||||
pobj = PyTuple_New(3);
|
||||
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);
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
||||
}
|
||||
|
||||
PyObject *pyerl_lock(PyObject * self, PyObject * args) {
|
||||
|
||||
uwsgi_lock(uerl.lock);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *pyerl_unlock(PyObject * self, PyObject * args) {
|
||||
|
||||
uwsgi_unlock(uerl.lock);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *pyerl_send(PyObject * self, PyObject * args) {
|
||||
PyObject *node;
|
||||
PyObject *reg;
|
||||
char *cnode;
|
||||
PyObject *pobj;
|
||||
ei_x_buff x;
|
||||
int fd;
|
||||
int close_fd = 0;
|
||||
erlang_pid epid;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOO:erlang_send", &node, ®, &pobj)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyString_Check(node)) {
|
||||
cnode = PyString_AsString(node);
|
||||
fd = ei_connect(pyerl_cnode, cnode);
|
||||
close_fd = 1;
|
||||
}
|
||||
else if (PyInt_Check(node)) {
|
||||
fd = PyInt_AsLong(node);
|
||||
}
|
||||
else {
|
||||
return PyErr_Format(PyExc_ValueError, "invalid erlang node/descriptor");
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
return PyErr_Format(PyExc_ValueError, "Unable to connect to erlang node");
|
||||
}
|
||||
|
||||
|
||||
ei_x_new_with_version(&x);
|
||||
|
||||
if (py_to_erl(pobj, &x) < 0) {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Unsupported object in Python->Erlang translation");
|
||||
}
|
||||
|
||||
|
||||
if (PyTuple_Check(reg) && PyTuple_Size(reg) == 3) {
|
||||
epid.num = PyInt_AsLong( PyTuple_GetItem(reg, 0) );
|
||||
epid.serial = PyInt_AsLong( PyTuple_GetItem(reg, 1) );
|
||||
epid.creation = PyInt_AsLong( PyTuple_GetItem(reg, 2) );
|
||||
ei_send(fd, &epid, x.buff, x.index);
|
||||
}
|
||||
else if (PyString_Check(reg)) {
|
||||
ei_reg_send(pyerl_cnode, fd, PyString_AsString(reg), x.buff, x.index);
|
||||
}
|
||||
else {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Invalid Erlang process");
|
||||
}
|
||||
|
||||
return PyInt_FromLong(fd);
|
||||
}
|
||||
|
||||
PyObject *pyerl_sr(PyObject * self, PyObject * args) {
|
||||
|
||||
PyObject *node;
|
||||
PyObject *reg;
|
||||
char *cnode;
|
||||
PyObject *pobj;
|
||||
ei_x_buff x;
|
||||
int fd;
|
||||
int close_fd = 0;
|
||||
erlang_msg em;
|
||||
erlang_pid epid;
|
||||
int eversion;
|
||||
PyObject *res;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOO:erlang_sr", &node, ®, &pobj)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyString_Check(node)) {
|
||||
cnode = PyString_AsString(node);
|
||||
fd = ei_connect(pyerl_cnode, cnode);
|
||||
close_fd = 1;
|
||||
}
|
||||
else if (PyInt_Check(node)) {
|
||||
fd = PyInt_AsLong(node);
|
||||
}
|
||||
else {
|
||||
return PyErr_Format(PyExc_ValueError, "invalid erlang node/descriptor");
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
return PyErr_Format(PyExc_ValueError, "Unable to connect to erlang node");
|
||||
}
|
||||
|
||||
|
||||
|
||||
ei_x_new_with_version(&x);
|
||||
|
||||
if (py_to_erl(pobj, &x) < 0) {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Unsupported object in Python->Erlang translation");
|
||||
}
|
||||
|
||||
|
||||
if (PyTuple_Check(reg) && PyTuple_Size(reg) == 3) {
|
||||
epid.num = PyInt_AsLong( PyTuple_GetItem(reg, 0) );
|
||||
epid.serial = PyInt_AsLong( PyTuple_GetItem(reg, 1) );
|
||||
epid.creation = PyInt_AsLong( PyTuple_GetItem(reg, 2) );
|
||||
ei_send(fd, &epid, x.buff, x.index);
|
||||
}
|
||||
else if (PyString_Check(reg)) {
|
||||
ei_reg_send(pyerl_cnode, fd, PyString_AsString(reg), x.buff, x.index);
|
||||
}
|
||||
else {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Invalid Erlang process");
|
||||
}
|
||||
|
||||
recv:
|
||||
ei_x_free(&x);
|
||||
|
||||
ei_x_new(&x);
|
||||
|
||||
if (ei_xreceive_msg(fd, &em, &x) == ERL_MSG) {
|
||||
|
||||
if (em.msgtype == ERL_TICK) {
|
||||
goto recv;
|
||||
}
|
||||
x.index = 0;
|
||||
ei_decode_version(x.buff, &x.index, &eversion);
|
||||
res = erl_to_py(&x);
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return res;
|
||||
}
|
||||
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
void pyerl_call_registered(void *func, ei_x_buff *x) {
|
||||
|
||||
PyObject *pyargs = PyTuple_New(1);
|
||||
|
||||
PyTuple_SetItem(pyargs, 0, erl_to_py(x));
|
||||
|
||||
python_call((PyObject *) func, pyargs, 0, NULL);
|
||||
}
|
||||
|
||||
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 (strlen(name) > 0xff-1)
|
||||
return PyErr_Format(PyExc_ValueError, "Invalid erlang process name");
|
||||
|
||||
struct uwsgi_erlang_process *uep = uerl.uep, *old_uep;
|
||||
|
||||
if (!uep) {
|
||||
uerl.uep = uwsgi_malloc(sizeof(struct uwsgi_erlang_process));
|
||||
uep = uerl.uep;
|
||||
}
|
||||
else {
|
||||
while(uep) {
|
||||
old_uep = uep;
|
||||
uep = uep->next;
|
||||
}
|
||||
|
||||
uep = uwsgi_malloc(sizeof(struct uwsgi_erlang_process));
|
||||
old_uep->next = uep;
|
||||
}
|
||||
|
||||
strcpy(uep->name, name);
|
||||
uep->plugin = pyerl_call_registered;
|
||||
uep->func = callable;
|
||||
uep->next = NULL;
|
||||
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
|
||||
}
|
||||
|
||||
PyObject *pyerl_recv(PyObject * self, PyObject * args) {
|
||||
|
||||
ei_x_buff x;
|
||||
erlang_msg em;
|
||||
PyObject *res;
|
||||
int eversion;
|
||||
int fd;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i:erlang_recv", &fd)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
recv:
|
||||
ei_x_new(&x);
|
||||
|
||||
if (ei_xreceive_msg(fd, &em, &x) == ERL_MSG) {
|
||||
|
||||
if (em.msgtype == ERL_TICK) {
|
||||
ei_x_free(&x);
|
||||
goto recv;
|
||||
}
|
||||
x.index = 0;
|
||||
ei_decode_version(x.buff, &x.index, &eversion);
|
||||
res = erl_to_py(&x);
|
||||
ei_x_free(&x);
|
||||
return res;
|
||||
}
|
||||
|
||||
ei_x_free(&x);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
PyObject *pyerl_rpc(PyObject * self, PyObject * args) {
|
||||
|
||||
PyObject *node;
|
||||
char *mod, *fun;
|
||||
char *cnode;
|
||||
PyObject *pobj;
|
||||
ei_x_buff x;
|
||||
ei_x_buff xr;
|
||||
int fd;
|
||||
int close_fd = 0;
|
||||
int eversion;
|
||||
PyObject *res;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OssO:erlang_rpc", &node, &mod, &fun, &pobj)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyString_Check(node)) {
|
||||
cnode = PyString_AsString(node);
|
||||
fd = ei_connect(pyerl_cnode, cnode);
|
||||
close_fd = 1;
|
||||
}
|
||||
else if (PyInt_Check(node)) {
|
||||
fd = PyInt_AsLong(node);
|
||||
}
|
||||
else {
|
||||
return PyErr_Format(PyExc_ValueError, "Invalid erlang node/descriptor");
|
||||
}
|
||||
|
||||
if (fd < 0) {
|
||||
return PyErr_Format(PyExc_ValueError, "Unable to connect to erlang node");
|
||||
}
|
||||
|
||||
ei_x_new(&x);
|
||||
|
||||
if (py_to_erl(pobj, &x) < 0) {
|
||||
ei_x_free(&x);
|
||||
if (close_fd) close(fd);
|
||||
return PyErr_Format(PyExc_ValueError, "Unsupported object in Python->Erlang translation");
|
||||
}
|
||||
|
||||
|
||||
ei_x_new(&xr);
|
||||
if (ei_rpc(pyerl_cnode, fd, mod, fun, x.buff, x.index, &xr) < 0) {
|
||||
if (close_fd) close(fd);
|
||||
ei_x_free(&x);
|
||||
ei_x_free(&xr);
|
||||
return PyErr_Format(PyExc_ValueError, "Error in Erlang rpc");
|
||||
}
|
||||
|
||||
xr.index = 0;
|
||||
ei_decode_version(xr.buff, &xr.index, &eversion);
|
||||
|
||||
res = erl_to_py(&xr);
|
||||
|
||||
if (close_fd) close(fd);
|
||||
ei_x_free(&x);
|
||||
ei_x_free(&xr);
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyMethodDef uwsgi_pyerl_methods[] = {
|
||||
{"erlang_connect", pyerl_connect, METH_VARARGS, ""},
|
||||
{"erlang_close", pyerl_close, METH_VARARGS, ""},
|
||||
{"erlang_send_message", pyerl_send, METH_VARARGS, ""},
|
||||
{"erlang_send", pyerl_send, METH_VARARGS, ""},
|
||||
{"erlang_recv_message", pyerl_recv, METH_VARARGS, ""},
|
||||
{"erlang_recv", pyerl_recv, METH_VARARGS, ""},
|
||||
{"erlang_sr", pyerl_sr, METH_VARARGS, ""},
|
||||
{"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},
|
||||
};
|
||||
|
||||
void py_erl_init_functions() {
|
||||
|
||||
PyMethodDef *uwsgi_function;
|
||||
|
||||
PyDict_SetItemString(up.embedded_dict, "erlang_node", PyString_FromString(ei_thisnodename(pyerl_cnode)));
|
||||
|
||||
for (uwsgi_function = uwsgi_pyerl_methods; uwsgi_function->ml_name != NULL; uwsgi_function++) {
|
||||
PyObject *func = PyCFunction_New(uwsgi_function, NULL);
|
||||
PyDict_SetItemString(up.embedded_dict, uwsgi_function->ml_name, func);
|
||||
Py_DECREF(func);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int py_to_erl(PyObject *pobj, ei_x_buff *x) {
|
||||
int i;
|
||||
PyObject *pobj2;
|
||||
|
||||
if (pobj == NULL || pobj == Py_None) {
|
||||
ei_x_encode_empty_list(x);
|
||||
}
|
||||
else if (PyString_Check(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));
|
||||
}
|
||||
else if (PyInt_Check(pobj)) {
|
||||
ei_x_encode_long(x, PyInt_AsLong(pobj));
|
||||
}
|
||||
else if (PyList_Check(pobj)) {
|
||||
if (PyList_Size(pobj) > 0) {
|
||||
ei_x_encode_list_header(x, PyList_Size(pobj));
|
||||
for (i = 0; i < PyList_Size(pobj); i++) {
|
||||
pobj2 = PyList_GetItem(pobj, i);
|
||||
if (py_to_erl(pobj2, x) < 0) return -1;
|
||||
}
|
||||
}
|
||||
ei_x_encode_empty_list(x);
|
||||
}
|
||||
else if (PyTuple_Check(pobj)) {
|
||||
ei_x_encode_tuple_header(x, PyTuple_Size(pobj));
|
||||
for (i = 0; i < PyTuple_Size(pobj); i++) {
|
||||
pobj2 = PyTuple_GetItem(pobj, i);
|
||||
if (py_to_erl(pobj2, x) < 0) return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return x->index;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void pyerl_init() {
|
||||
|
||||
up.extension = py_erl_init_functions;
|
||||
|
||||
if (!uerl.name) {
|
||||
pyerl_cnode = uwsgi_malloc(sizeof(ei_cnode));
|
||||
memset(pyerl_cnode, 0, sizeof(ei_cnode));
|
||||
if (ei_connect_init(pyerl_cnode, "uwsgi", NULL, 0) < 0) {
|
||||
uwsgi_log("unable to initialize erlang connection\n");
|
||||
exit(1);
|
||||
}
|
||||
uwsgi_log("Erlang C-Node name: %s\n",ei_thisnodename(pyerl_cnode));
|
||||
}
|
||||
else {
|
||||
pyerl_cnode = &uerl.cnode;
|
||||
}
|
||||
|
||||
uwsgi_log("enabled Python<->Erlang bridge\n");
|
||||
|
||||
}
|
||||
|
||||
struct uwsgi_plugin pyerl_plugin = {
|
||||
|
||||
.post_init = pyerl_init,
|
||||
};
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
import os
|
||||
from distutils import sysconfig
|
||||
|
||||
NAME='pyerl'
|
||||
|
||||
ERLANGPATH = os.environ.get('UWSGICONFIG_ERLANGPATH', 'erl')
|
||||
|
||||
includedir = os.popen(ERLANGPATH + " -noshell -noinput -eval \"io:format('~s~n', [code:lib_dir(erl_interface, include)])\" -s erlang halt").read().rstrip()
|
||||
libpath = os.popen(ERLANGPATH + " -noshell -noinput -eval \"io:format('~s~n', [code:lib_dir(erl_interface, lib)])\" -s erlang halt").read().rstrip()
|
||||
|
||||
CFLAGS = [ '-I' + includedir, '-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True)]
|
||||
LDFLAGS = [ '-L' + libpath ]
|
||||
|
||||
LIBS = ['-lei']
|
||||
|
||||
GCC_LIST = ['pyerl']
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
[uwsgi]
|
||||
main_plugin = python,gevent,psgi,lua,php,rack,jvm,jwsgi,ring,mono,transformation_toupper,coroae,v8,cgi,xslt,webdav,ssi,ldap,gccgo,rados,pypy
|
||||
main_plugin = python,gevent,psgi,lua,php,rack,jvm,jwsgi,ring,mono,transformation_toupper,coroae,v8,cgi,xslt,webdav,ssi,ldap,gccgo,rados,pypy,zabbix,curl_cron,tornado,tuntap,pty,mongrel2,alarm_curl,router_radius,airbrake
|
||||
inherit = base
|
||||
|
||||
@@ -2,14 +2,11 @@
|
||||
xml = auto
|
||||
yaml = true
|
||||
json = auto
|
||||
zeromq = auto
|
||||
ssl = auto
|
||||
pcre = auto
|
||||
routing = auto
|
||||
debug = false
|
||||
unbit = false
|
||||
xml_implementation = libxml2
|
||||
yaml_implementation = auto
|
||||
malloc_implementation = libc
|
||||
extras =
|
||||
plugins =
|
||||
|
||||
@@ -2,14 +2,11 @@
|
||||
xml = false
|
||||
yaml = false
|
||||
json = false
|
||||
zeromq = false
|
||||
ssl = false
|
||||
pcre = false
|
||||
routing = false
|
||||
debug = false
|
||||
unbit = false
|
||||
xml_implementation = none
|
||||
yaml_implementation = none
|
||||
malloc_implementation = libc
|
||||
extras =
|
||||
plugins =
|
||||
|
||||
+2
-5
@@ -1,15 +1,12 @@
|
||||
[uwsgi]
|
||||
xml = true
|
||||
yaml = true
|
||||
xml = libxml2
|
||||
yaml = libyaml
|
||||
json = true
|
||||
zeromq = true
|
||||
ssl = true
|
||||
pcre = true
|
||||
routing = true
|
||||
debug = false
|
||||
unbit = false
|
||||
xml_implementation = libxml2
|
||||
yaml_implementation = libyaml
|
||||
malloc_implementation = libc
|
||||
extras =
|
||||
plugins =
|
||||
|
||||
+2
-5
@@ -1,15 +1,12 @@
|
||||
[uwsgi]
|
||||
xml = true
|
||||
yaml = true
|
||||
xml = expat
|
||||
yaml = embedded
|
||||
json = false
|
||||
zeromq = false
|
||||
ssl = true
|
||||
pcre = true
|
||||
routing = true
|
||||
debug = false
|
||||
unbit = true
|
||||
xml_implementation = expat
|
||||
yaml_implementation = auto
|
||||
malloc_implementation = libc
|
||||
extras =
|
||||
plugins =
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
[uwsgi]
|
||||
xml = expat
|
||||
yaml = embedded
|
||||
json = true
|
||||
ssl = true
|
||||
pcre = true
|
||||
routing = true
|
||||
debug = false
|
||||
unbit = false
|
||||
malloc_implementation = libc
|
||||
extras =
|
||||
plugins =
|
||||
bin_name = uwsgi
|
||||
append_version =
|
||||
plugin_dir = /opt/unbit/uwsgi/plugins
|
||||
embedded_plugins =
|
||||
as_shared_library = false
|
||||
|
||||
locking = auto
|
||||
event = auto
|
||||
timer = auto
|
||||
filemonitor = auto
|
||||
|
||||
blacklist =
|
||||
whitelist =
|
||||
|
||||
embed_files =
|
||||
|
||||
embed_config =
|
||||
+62
-17
@@ -28,7 +28,6 @@ void uwsgi_async_queue_is_full(time_t now) {
|
||||
}
|
||||
|
||||
void uwsgi_async_init() {
|
||||
int i;
|
||||
|
||||
uwsgi.async_queue = event_queue_init();
|
||||
|
||||
@@ -40,16 +39,9 @@ void uwsgi_async_init() {
|
||||
|
||||
uwsgi.rb_async_timeouts = uwsgi_init_rb_timer();
|
||||
|
||||
// a stack of unused cores
|
||||
uwsgi.async_queue_unused = uwsgi_malloc(sizeof(struct wsgi_request *) * uwsgi.async);
|
||||
|
||||
// fill it with default values
|
||||
for (i = 0; i < uwsgi.async; i++) {
|
||||
uwsgi.async_queue_unused[i] = &uwsgi.workers[uwsgi.mywid].cores[i].req;
|
||||
}
|
||||
|
||||
// the first available core is the last one
|
||||
uwsgi.async_queue_unused_ptr = uwsgi.async - 1;
|
||||
// optimization, this array maps file descriptor to requests
|
||||
uwsgi.async_waiting_fd_table = uwsgi_calloc(sizeof(struct wsgi_request *) * uwsgi.max_fd);
|
||||
uwsgi.async_proto_fd_table = uwsgi_calloc(sizeof(struct wsgi_request *) * uwsgi.max_fd);
|
||||
|
||||
}
|
||||
|
||||
@@ -173,6 +165,11 @@ static void async_expire_timeouts(uint64_t now) {
|
||||
|
||||
int async_add_fd_read(struct wsgi_request *wsgi_req, int fd, int timeout) {
|
||||
|
||||
if (uwsgi.async < 2 || !uwsgi.async_waiting_fd_table){
|
||||
uwsgi_log_verbose("ASYNC call without async mode !!!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct uwsgi_async_fd *last_uad = NULL, *uad = wsgi_req->waiting_fds;
|
||||
|
||||
if (fd < 0)
|
||||
@@ -224,8 +221,47 @@ static int async_wait_fd_read(int fd, int timeout) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int async_wait_fd_read2(int fd0, int fd1, int timeout, int *fd) {
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
wsgi_req->async_ready_fd = 0;
|
||||
|
||||
if (async_add_fd_read(wsgi_req, fd0, timeout)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (async_add_fd_read(wsgi_req, fd1, timeout)) {
|
||||
// reset already registered fd
|
||||
async_reset_request(wsgi_req);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (uwsgi.schedule_to_main) {
|
||||
uwsgi.schedule_to_main(wsgi_req);
|
||||
}
|
||||
|
||||
if (wsgi_req->async_timed_out) {
|
||||
wsgi_req->async_timed_out = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (wsgi_req->async_ready_fd) {
|
||||
*fd = wsgi_req->async_last_ready_fd;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void async_add_timeout(struct wsgi_request *wsgi_req, int timeout) {
|
||||
|
||||
if (uwsgi.async < 2 || !uwsgi.rb_async_timeouts) {
|
||||
uwsgi_log_verbose("ASYNC call without async mode !!!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
wsgi_req->async_ready_fd = 0;
|
||||
|
||||
if (timeout > 0 && wsgi_req->async_timeout == NULL) {
|
||||
@@ -236,6 +272,11 @@ void async_add_timeout(struct wsgi_request *wsgi_req, int timeout) {
|
||||
|
||||
int async_add_fd_write(struct wsgi_request *wsgi_req, int fd, int timeout) {
|
||||
|
||||
if (uwsgi.async < 2 || !uwsgi.async_waiting_fd_table) {
|
||||
uwsgi_log_verbose("ASYNC call without async mode !!!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct uwsgi_async_fd *last_uad = NULL, *uad = wsgi_req->waiting_fds;
|
||||
|
||||
if (fd < 0)
|
||||
@@ -295,9 +336,8 @@ void async_schedule_to_req(void) {
|
||||
// a trick to avoid calling routes again
|
||||
uwsgi.wsgi_req->is_routing = 1;
|
||||
#endif
|
||||
if (uwsgi.p[uwsgi.wsgi_req->uh->modifier1]->request(uwsgi.wsgi_req) <= UWSGI_OK) {
|
||||
goto end;
|
||||
}
|
||||
uwsgi.wsgi_req->async_status = uwsgi.p[uwsgi.wsgi_req->uh->modifier1]->request(uwsgi.wsgi_req);
|
||||
if (uwsgi.wsgi_req->async_status <= UWSGI_OK) goto end;
|
||||
|
||||
if (uwsgi.schedule_to_main) {
|
||||
uwsgi.schedule_to_main(uwsgi.wsgi_req);
|
||||
@@ -320,7 +360,8 @@ void async_schedule_to_req_green(void) {
|
||||
}
|
||||
#endif
|
||||
for(;;) {
|
||||
if (uwsgi.p[wsgi_req->uh->modifier1]->request(wsgi_req) <= UWSGI_OK) {
|
||||
wsgi_req->async_status = uwsgi.p[wsgi_req->uh->modifier1]->request(wsgi_req);
|
||||
if (wsgi_req->async_status <= UWSGI_OK) {
|
||||
break;
|
||||
}
|
||||
wsgi_req->switches++;
|
||||
@@ -366,10 +407,13 @@ void async_loop() {
|
||||
void *events = event_queue_alloc(64);
|
||||
struct uwsgi_socket *uwsgi_sock;
|
||||
|
||||
uwsgi_async_init();
|
||||
|
||||
uwsgi.async_runqueue = NULL;
|
||||
|
||||
uwsgi.wait_write_hook = async_wait_fd_write;
|
||||
uwsgi.wait_read_hook = async_wait_fd_read;
|
||||
uwsgi.wait_read2_hook = async_wait_fd_read2;
|
||||
|
||||
if (uwsgi.signal_socket > -1) {
|
||||
event_queue_add_fd_read(uwsgi.async_queue, uwsgi.signal_socket);
|
||||
@@ -478,7 +522,8 @@ void async_loop() {
|
||||
// remove fd from event poll and fd proto table
|
||||
uwsgi.async_proto_fd_table[interesting_fd] = NULL;
|
||||
event_queue_del_fd(uwsgi.async_queue, interesting_fd, event_queue_read());
|
||||
// put request in the runqueue
|
||||
// put request in the runqueue (set it as UWSGI_OK to signal the first run)
|
||||
uwsgi.wsgi_req->async_status = UWSGI_OK;
|
||||
runqueue_push(uwsgi.wsgi_req);
|
||||
continue;
|
||||
}
|
||||
@@ -488,7 +533,7 @@ void async_loop() {
|
||||
continue;
|
||||
}
|
||||
// re-add timer
|
||||
async_add_timeout(uwsgi.wsgi_req, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
async_add_timeout(uwsgi.wsgi_req, uwsgi.socket_timeout);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -64,7 +64,7 @@ int uwsgi_buffer_insert_chunked(struct uwsgi_buffer *ub, size_t pos, size_t len)
|
||||
// 0xFFFFFFFFFFFFFFFF\r\n\0
|
||||
char chunked[19];
|
||||
int ret = snprintf(chunked, 19, "%X\r\n", (unsigned int) len);
|
||||
if (ret <= 0 || ret > 19) {
|
||||
if (ret <= 0 || ret >= 19) {
|
||||
return -1;
|
||||
}
|
||||
return uwsgi_buffer_insert(ub, pos, chunked, ret);
|
||||
@@ -74,7 +74,7 @@ int uwsgi_buffer_append_chunked(struct uwsgi_buffer *ub, size_t len) {
|
||||
// 0xFFFFFFFFFFFFFFFF\r\n\0
|
||||
char chunked[19];
|
||||
int ret = snprintf(chunked, 19, "%X\r\n", (unsigned int) len);
|
||||
if (ret <= 0 || ret > 19) {
|
||||
if (ret <= 0 || ret >= 19) {
|
||||
return -1;
|
||||
}
|
||||
return uwsgi_buffer_append(ub, chunked, ret);
|
||||
@@ -245,7 +245,7 @@ int uwsgi_buffer_append_ipv4(struct uwsgi_buffer *ub, void *addr) {
|
||||
int uwsgi_buffer_num64(struct uwsgi_buffer *ub, int64_t num) {
|
||||
char buf[sizeof(UMAX64_STR)+1];
|
||||
int ret = snprintf(buf, sizeof(UMAX64_STR)+1, "%lld", (long long) num);
|
||||
if (ret <= 0 || ret > (int) (sizeof(UMAX64_STR)+1)) {
|
||||
if (ret <= 0 || ret >= (int) (sizeof(UMAX64_STR)+1)) {
|
||||
return -1;
|
||||
}
|
||||
return uwsgi_buffer_append(ub, buf, ret);
|
||||
@@ -268,7 +268,7 @@ int uwsgi_buffer_append_keyval32(struct uwsgi_buffer *ub, char *key, uint32_t ke
|
||||
int uwsgi_buffer_append_keynum(struct uwsgi_buffer *ub, char *key, uint16_t keylen, int64_t num) {
|
||||
char buf[sizeof(UMAX64_STR)+1];
|
||||
int ret = snprintf(buf, (sizeof(UMAX64_STR)+1), "%lld", (long long) num);
|
||||
if (ret <= 0 || ret > (int) (sizeof(UMAX64_STR)+1)) {
|
||||
if (ret <= 0 || ret >= (int) (sizeof(UMAX64_STR)+1)) {
|
||||
return -1;
|
||||
}
|
||||
if (uwsgi_buffer_u16le(ub, keylen)) return -1;
|
||||
@@ -280,7 +280,7 @@ int uwsgi_buffer_append_keynum(struct uwsgi_buffer *ub, char *key, uint16_t keyl
|
||||
int uwsgi_buffer_append_valnum(struct uwsgi_buffer *ub, int64_t num) {
|
||||
char buf[sizeof(UMAX64_STR)+1];
|
||||
int ret = snprintf(buf, (sizeof(UMAX64_STR)+1), "%lld", (long long) num);
|
||||
if (ret <= 0 || ret > (int) (sizeof(UMAX64_STR)+1)) {
|
||||
if (ret <= 0 || ret >= (int) (sizeof(UMAX64_STR)+1)) {
|
||||
return -1;
|
||||
}
|
||||
if (uwsgi_buffer_u16le(ub, ret)) return -1;
|
||||
@@ -340,7 +340,7 @@ int uwsgi_buffer_send(struct uwsgi_buffer *ub, int fd) {
|
||||
char *ptr = ub->buf;
|
||||
|
||||
while (remains > 0) {
|
||||
int ret = uwsgi_waitfd_write(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd_write(fd, uwsgi.socket_timeout);
|
||||
if (ret > 0) {
|
||||
ssize_t len = write(fd, ptr, remains);
|
||||
if (len > 0) {
|
||||
|
||||
+14
-14
@@ -1483,7 +1483,7 @@ char *uwsgi_cache_magic_get(char *key, uint16_t keylen, uint64_t *vallen, uint64
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return NULL;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
@@ -1495,7 +1495,7 @@ char *uwsgi_cache_magic_get(char *key, uint16_t keylen, uint64_t *vallen, uint64
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return NULL;
|
||||
@@ -1526,7 +1526,7 @@ char *uwsgi_cache_magic_get(char *key, uint16_t keylen, uint64_t *vallen, uint64
|
||||
}
|
||||
|
||||
// read the raw value from the socket
|
||||
if (uwsgi_read_whole_true_nb(fd, ub->buf, ucmc.size, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_read_whole_true_nb(fd, ub->buf, ucmc.size, uwsgi.socket_timeout)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return NULL;
|
||||
@@ -1585,7 +1585,7 @@ int uwsgi_cache_magic_exists(char *key, uint16_t keylen, char *cache) {
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return 0;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return 0;
|
||||
@@ -1597,7 +1597,7 @@ int uwsgi_cache_magic_exists(char *key, uint16_t keylen, char *cache) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return 0;
|
||||
@@ -1652,7 +1652,7 @@ int uwsgi_cache_magic_set(char *key, uint16_t keylen, char *value, uint64_t vall
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return -1;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
@@ -1670,7 +1670,7 @@ int uwsgi_cache_magic_set(char *key, uint16_t keylen, char *value, uint64_t vall
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, value, vallen, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, value, vallen, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return -1;
|
||||
@@ -1730,7 +1730,7 @@ int uwsgi_cache_magic_del(char *key, uint16_t keylen, char *cache) {
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return -1;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
@@ -1742,7 +1742,7 @@ int uwsgi_cache_magic_del(char *key, uint16_t keylen, char *cache) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return -1;
|
||||
@@ -1803,7 +1803,7 @@ int uwsgi_cache_magic_clear(char *cache) {
|
||||
int fd = uwsgi_connect(cache_server, 0, 1);
|
||||
if (fd < 0) return -1;
|
||||
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return -1;
|
||||
@@ -1815,7 +1815,7 @@ int uwsgi_cache_magic_clear(char *cache) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &ucmc)) {
|
||||
if (cache_magic_send_and_manage(fd, ub, NULL, 0, uwsgi.socket_timeout, &ucmc)) {
|
||||
close(fd);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return -1;
|
||||
@@ -1859,7 +1859,7 @@ void uwsgi_cache_sync_from_nodes(struct uwsgi_cache *uc) {
|
||||
goto next;
|
||||
}
|
||||
|
||||
if (uwsgi_write_nb(fd, ub->buf, ub->pos, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_write_nb(fd, ub->buf, ub->pos, uwsgi.socket_timeout)) {
|
||||
uwsgi_buffer_destroy(ub);
|
||||
uwsgi_log("[cache-sync] unable to write to the cache server\n");
|
||||
close(fd);
|
||||
@@ -1867,7 +1867,7 @@ void uwsgi_cache_sync_from_nodes(struct uwsgi_cache *uc) {
|
||||
}
|
||||
|
||||
size_t rlen = ub->pos;
|
||||
if (uwsgi_read_with_realloc(fd, &ub->buf, &rlen, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], NULL, NULL)) {
|
||||
if (uwsgi_read_with_realloc(fd, &ub->buf, &rlen, uwsgi.socket_timeout, NULL, NULL)) {
|
||||
uwsgi_buffer_destroy(ub);
|
||||
uwsgi_log("[cache-sync] unable to read from the cache server\n");
|
||||
close(fd);
|
||||
@@ -1876,7 +1876,7 @@ void uwsgi_cache_sync_from_nodes(struct uwsgi_cache *uc) {
|
||||
|
||||
uwsgi_hooked_parse(ub->buf, rlen, cache_sync_hook, uc);
|
||||
|
||||
if (uwsgi_read_nb(fd, (char *) uc->items, uc->filesize, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_read_nb(fd, (char *) uc->items, uc->filesize, uwsgi.socket_timeout)) {
|
||||
uwsgi_buffer_destroy(ub);
|
||||
close(fd);
|
||||
uwsgi_log("[cache-sync] unable to read from the cache server\n");
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ extern struct uwsgi_server uwsgi;
|
||||
static ssize_t uwsgi_chunked_input_recv(struct wsgi_request *wsgi_req, int timeout, int nb) {
|
||||
|
||||
if (timeout == 0) timeout = uwsgi.chunked_input_timeout;
|
||||
if (timeout == 0) timeout = uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT];
|
||||
if (timeout == 0) timeout = uwsgi.socket_timeout;
|
||||
|
||||
int ret = -1;
|
||||
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
int uwsgi_simple_wait_milliseconds_hook(int timeout) {
|
||||
return poll(NULL, 0, timeout);
|
||||
}
|
||||
|
||||
|
||||
// in the future we will need to use the best clock source for each os/system
|
||||
time_t uwsgi_now() {
|
||||
return uwsgi.clock->seconds();
|
||||
|
||||
+5
-4
@@ -720,18 +720,18 @@ char *uwsgi_manage_placeholder(char *key) {
|
||||
}
|
||||
else if (!strcmp(p, "++")) {
|
||||
if (current_value) {
|
||||
int64_t tmp_value = strtoll(current_value, NULL, 10);
|
||||
int64_t tmp_num = strtoll(current_value, NULL, 10);
|
||||
free(current_value);
|
||||
current_value = uwsgi_64bit2str(tmp_value+1);
|
||||
current_value = uwsgi_64bit2str(tmp_num+1);
|
||||
}
|
||||
state = concat;
|
||||
continue;
|
||||
}
|
||||
else if (!strcmp(p, "--")) {
|
||||
if (current_value) {
|
||||
int64_t tmp_value = strtoll(current_value, NULL, 10);
|
||||
int64_t tmp_num = strtoll(current_value, NULL, 10);
|
||||
free(current_value);
|
||||
current_value = uwsgi_64bit2str(tmp_value-1);
|
||||
current_value = uwsgi_64bit2str(tmp_num-1);
|
||||
}
|
||||
state = concat;
|
||||
continue;
|
||||
@@ -795,6 +795,7 @@ char *uwsgi_manage_placeholder(char *key) {
|
||||
// reset state to concat
|
||||
state = concat;
|
||||
}
|
||||
free(tmp_value);
|
||||
|
||||
return current_value;
|
||||
}
|
||||
|
||||
+129
-13
@@ -6,7 +6,7 @@ extern struct uwsgi_server uwsgi;
|
||||
|
||||
External uwsgi daemons
|
||||
|
||||
There are 3 kind of daemons (read: external applications) that can be managed
|
||||
There are 3 kinds of daemons (read: external applications) that can be managed
|
||||
by uWSGI.
|
||||
|
||||
1) dumb daemons (attached with --attach-daemon)
|
||||
@@ -14,12 +14,12 @@ extern struct uwsgi_server uwsgi;
|
||||
and the process is respawned
|
||||
2) smart daemons with daemonization
|
||||
you specify a pidfile and a command
|
||||
- on startup - if the pidfile does not exists or contains a not-available pid (checked with kill(pid, 0))
|
||||
the daemon is respawned
|
||||
- on master ckeck - if the pidfile does not exist or if it point to a non-existent pid
|
||||
the daemon is respawned
|
||||
- on startup - if the pidfile does not exist or contains a non-available pid (checked with kill(pid, 0))
|
||||
the daemon is respawned
|
||||
- on master check - if the pidfile does not exist or if it points to a non-existent pid
|
||||
the daemon is respawned
|
||||
3) smart daemons without daemonization
|
||||
same as 2, but the daemonization and pidfile creation is managed by uWSGI
|
||||
same as 2, but the daemonization and pidfile creation are managed by uWSGI
|
||||
|
||||
status:
|
||||
|
||||
@@ -55,7 +55,7 @@ void uwsgi_daemons_smart_check() {
|
||||
if (ud->pid > 0) {
|
||||
if (!kill(ud->pid, 0)) {
|
||||
uwsgi_log("[uwsgi_daemons] stopping legion \"%s\" daemon: %s (pid: %d)\n", ud->legion, ud->command, ud->pid);
|
||||
kill(-ud->pid, SIGTERM);
|
||||
kill(-ud->pid, ud->stop_signal);
|
||||
}
|
||||
else {
|
||||
// pid already died
|
||||
@@ -232,12 +232,12 @@ void uwsgi_detach_daemons() {
|
||||
if (ud->pid > 0 && !ud->pidfile) {
|
||||
#endif
|
||||
uwsgi_log("[uwsgi-daemons] stopping daemon (pid: %d): %s\n", (int) ud->pid, ud->command);
|
||||
// try to gracefully stop daemon, kill it if it won't die
|
||||
// try to stop daemon gracefully, kill it if it won't die
|
||||
// if mercy is not set then wait up to 3 seconds
|
||||
time_t timeout = uwsgi_now() + (uwsgi.reload_mercy ? uwsgi.reload_mercy : 3);
|
||||
int waitpid_status;
|
||||
while (!kill(ud->pid, 0)) {
|
||||
kill(-ud->pid, SIGTERM);
|
||||
kill(-ud->pid, ud->stop_signal);
|
||||
sleep(1);
|
||||
waitpid(-ud->pid, &waitpid_status, WNOHANG);
|
||||
if (uwsgi_now() >= timeout) {
|
||||
@@ -291,6 +291,20 @@ void uwsgi_spawn_daemon(struct uwsgi_daemon *ud) {
|
||||
uwsgi_close_all_sockets();
|
||||
uwsgi_close_all_fds();
|
||||
|
||||
if (ud->gid) {
|
||||
if (setgid(ud->gid)) {
|
||||
uwsgi_error("uwsgi_spawn_daemon()/setgid()");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (ud->uid) {
|
||||
if (setuid(ud->uid)) {
|
||||
uwsgi_error("uwsgi_spawn_daemon()/setuid()");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (ud->daemonize) {
|
||||
/* refork... */
|
||||
pid = fork();
|
||||
@@ -304,7 +318,7 @@ void uwsgi_spawn_daemon(struct uwsgi_daemon *ud) {
|
||||
uwsgi_write_pidfile(ud->pidfile);
|
||||
}
|
||||
|
||||
if (!uwsgi.daemons_honour_stdin) {
|
||||
if (!uwsgi.daemons_honour_stdin && !ud->honour_stdin) {
|
||||
// /dev/null will became stdin
|
||||
uwsgi_remap_fd(0, "/dev/null");
|
||||
}
|
||||
@@ -328,7 +342,7 @@ void uwsgi_spawn_daemon(struct uwsgi_daemon *ud) {
|
||||
sleep((unsigned int) throttle);
|
||||
}
|
||||
|
||||
uwsgi_log("[uwsgi-daemons] %sspawning \"%s\"\n", ud->respawns > 0 ? "re" : "", ud->command);
|
||||
uwsgi_log("[uwsgi-daemons] %sspawning \"%s\" (uid: %d gid: %d)\n", ud->respawns > 0 ? "re" : "", ud->command, (int) getuid(), (int) getgid());
|
||||
uwsgi_exec_command_with_args(ud->command);
|
||||
uwsgi_log("[uwsgi-daemons] unable to spawn \"%s\"\n", ud->command);
|
||||
|
||||
@@ -347,6 +361,8 @@ void uwsgi_opt_add_daemon(char *opt, char *value, void *none) {
|
||||
int daemonize = 0;
|
||||
int freq = 10;
|
||||
char *space = NULL;
|
||||
int stop_signal = SIGTERM;
|
||||
int reload_signal = 0;
|
||||
|
||||
char *command = uwsgi_str(value);
|
||||
|
||||
@@ -385,7 +401,7 @@ void uwsgi_opt_add_daemon(char *opt, char *value, void *none) {
|
||||
}
|
||||
|
||||
if (!uwsgi_ud) {
|
||||
uwsgi.daemons = uwsgi_malloc(sizeof(struct uwsgi_daemon));
|
||||
uwsgi.daemons = uwsgi_calloc(sizeof(struct uwsgi_daemon));
|
||||
uwsgi_ud = uwsgi.daemons;
|
||||
}
|
||||
else {
|
||||
@@ -394,7 +410,7 @@ void uwsgi_opt_add_daemon(char *opt, char *value, void *none) {
|
||||
uwsgi_ud = uwsgi_ud->next;
|
||||
}
|
||||
|
||||
uwsgi_ud = uwsgi_malloc(sizeof(struct uwsgi_daemon));
|
||||
uwsgi_ud = uwsgi_calloc(sizeof(struct uwsgi_daemon));
|
||||
old_ud->next = uwsgi_ud;
|
||||
}
|
||||
|
||||
@@ -409,6 +425,8 @@ void uwsgi_opt_add_daemon(char *opt, char *value, void *none) {
|
||||
uwsgi_ud->daemonize = daemonize;
|
||||
uwsgi_ud->pidfile = pidfile;
|
||||
uwsgi_ud->control = 0;
|
||||
uwsgi_ud->stop_signal = stop_signal;
|
||||
uwsgi_ud->reload_signal = reload_signal;
|
||||
if (!strcmp(opt, "attach-control-daemon")) {
|
||||
uwsgi_ud->control = 1;
|
||||
}
|
||||
@@ -419,3 +437,101 @@ void uwsgi_opt_add_daemon(char *opt, char *value, void *none) {
|
||||
uwsgi.daemons_cnt++;
|
||||
|
||||
}
|
||||
|
||||
void uwsgi_opt_add_daemon2(char *opt, char *value, void *none) {
|
||||
|
||||
struct uwsgi_daemon *uwsgi_ud = uwsgi.daemons, *old_ud;
|
||||
|
||||
char *d_command = NULL;
|
||||
char *d_freq = NULL;
|
||||
char *d_pidfile = NULL;
|
||||
char *d_control = NULL;
|
||||
char *d_legion = NULL;
|
||||
char *d_daemonize = NULL;
|
||||
char *d_touch = NULL;
|
||||
char *d_stopsignal = NULL;
|
||||
char *d_reloadsignal = NULL;
|
||||
char *d_stdin = NULL;
|
||||
char *d_uid = NULL;
|
||||
char *d_gid = NULL;
|
||||
|
||||
char *arg = uwsgi_str(value);
|
||||
|
||||
if (uwsgi_kvlist_parse(arg, strlen(arg), ',', '=',
|
||||
"command", &d_command,
|
||||
"cmd", &d_command,
|
||||
"exec", &d_command,
|
||||
"freq", &d_freq,
|
||||
"pidfile", &d_pidfile,
|
||||
"control", &d_control,
|
||||
"daemonize", &d_daemonize,
|
||||
"daemon", &d_daemonize,
|
||||
"touch", &d_touch,
|
||||
"stopsignal", &d_stopsignal,
|
||||
"stop_signal", &d_stopsignal,
|
||||
"reloadsignal", &d_reloadsignal,
|
||||
"reload_signal", &d_reloadsignal,
|
||||
"stdin", &d_stdin,
|
||||
"uid", &d_uid,
|
||||
"gid", &d_gid,
|
||||
NULL)) {
|
||||
uwsgi_log("invalid --%s keyval syntax\n", opt);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!d_command) {
|
||||
uwsgi_log("--%s: you need to specify a 'command' key\n", opt);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifndef UWSGI_SSL
|
||||
if (d_legion) {
|
||||
uwsgi_log("legion subsystem is not supported on this uWSGI version, rebuild with ssl support\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
if (!uwsgi_ud) {
|
||||
uwsgi.daemons = uwsgi_calloc(sizeof(struct uwsgi_daemon));
|
||||
uwsgi_ud = uwsgi.daemons;
|
||||
}
|
||||
else {
|
||||
while (uwsgi_ud) {
|
||||
old_ud = uwsgi_ud;
|
||||
uwsgi_ud = uwsgi_ud->next;
|
||||
}
|
||||
|
||||
uwsgi_ud = uwsgi_calloc(sizeof(struct uwsgi_daemon));
|
||||
old_ud->next = uwsgi_ud;
|
||||
}
|
||||
uwsgi_ud->command = d_command;
|
||||
uwsgi_ud->freq = d_freq ? atoi(d_freq) : 10;
|
||||
uwsgi_ud->daemonize = d_daemonize ? 1 : 0;
|
||||
uwsgi_ud->pidfile = d_pidfile;
|
||||
uwsgi_ud->stop_signal = d_stopsignal ? atoi(d_stopsignal) : SIGTERM;
|
||||
uwsgi_ud->reload_signal = d_reloadsignal ? atoi(d_reloadsignal) : 0;
|
||||
uwsgi_ud->control = d_control ? 1 : 0;
|
||||
uwsgi_ud->uid = d_uid ? atoi(d_uid) : 0;
|
||||
uwsgi_ud->gid = d_gid ? atoi(d_gid) : 0;
|
||||
uwsgi_ud->honour_stdin = d_stdin ? 1 : 0;
|
||||
#ifdef UWSGI_SSL
|
||||
uwsgi_ud->legion = d_legion;
|
||||
#endif
|
||||
|
||||
if (d_touch) {
|
||||
size_t i,rlen = 0;
|
||||
char **argv = uwsgi_split_quoted(d_touch, strlen(d_touch), ";", &rlen);
|
||||
for(i=0;i<rlen;i++) {
|
||||
uwsgi_string_new_list(&uwsgi_ud->touch, argv[i]);
|
||||
}
|
||||
if (argv) free(argv);
|
||||
}
|
||||
|
||||
uwsgi.daemons_cnt++;
|
||||
|
||||
free(arg);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+54
-12
@@ -59,12 +59,12 @@ void uwsgi_emperor_blacklist_add(char *id) {
|
||||
uebi->throttle_level += (uwsgi.emperor_throttle * 1000);
|
||||
}
|
||||
else {
|
||||
uwsgi_log("[emperor] maximum throttle level for vassal %s reached !!!\n", id);
|
||||
uwsgi_log_verbose("[emperor] maximum throttle level for vassal %s reached !!!\n", id);
|
||||
uebi->throttle_level = uebi->throttle_level / 2;
|
||||
}
|
||||
uebi->attempt++;
|
||||
if (uebi->attempt == 2) {
|
||||
uwsgi_log("[emperor] unloyal bad behaving vassal found: %s throttling it...\n", id);
|
||||
uwsgi_log_verbose("[emperor] unloyal bad behaving vassal found: %s throttling it...\n", id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -603,7 +603,7 @@ void emperor_del(struct uwsgi_instance *c_ui) {
|
||||
uwsgi_log("[emperor] %s stop-hook returned %d\n", c_ui->name, stop_hook_ret);
|
||||
}
|
||||
|
||||
uwsgi_log("[emperor] removed uwsgi instance %s\n", c_ui->name);
|
||||
uwsgi_log_verbose("[emperor] removed uwsgi instance %s\n", c_ui->name);
|
||||
// put the instance in the blacklist (or update its throttling value)
|
||||
if (!c_ui->loyal) {
|
||||
uwsgi_emperor_blacklist_add(c_ui->name);
|
||||
@@ -632,7 +632,7 @@ void emperor_stop(struct uwsgi_instance *c_ui) {
|
||||
c_ui->status = 1;
|
||||
c_ui->cursed_at = uwsgi_now();
|
||||
|
||||
uwsgi_log("[emperor] stop the uwsgi instance %s\n", c_ui->name);
|
||||
uwsgi_log_verbose("[emperor] stop the uwsgi instance %s\n", c_ui->name);
|
||||
}
|
||||
|
||||
void emperor_curse(struct uwsgi_instance *c_ui) {
|
||||
@@ -642,7 +642,7 @@ void emperor_curse(struct uwsgi_instance *c_ui) {
|
||||
c_ui->status = 1;
|
||||
c_ui->cursed_at = uwsgi_now();
|
||||
|
||||
uwsgi_log("[emperor] curse the uwsgi instance %s (pid: %d)\n", c_ui->name, (int) c_ui->pid);
|
||||
uwsgi_log_verbose("[emperor] curse the uwsgi instance %s (pid: %d)\n", c_ui->name, (int) c_ui->pid);
|
||||
|
||||
}
|
||||
|
||||
@@ -675,8 +675,12 @@ void emperor_respawn(struct uwsgi_instance *c_ui, time_t mod) {
|
||||
c_ui->respawns++;
|
||||
c_ui->last_mod = mod;
|
||||
c_ui->last_run = uwsgi_now();
|
||||
// reset readyness
|
||||
c_ui->ready = 0;
|
||||
// reset accepting
|
||||
c_ui->accepting = 0;
|
||||
|
||||
uwsgi_log("[emperor] reload the uwsgi instance %s\n", c_ui->name);
|
||||
uwsgi_log_verbose("[emperor] reload the uwsgi instance %s\n", c_ui->name);
|
||||
}
|
||||
|
||||
void emperor_add(struct uwsgi_emperor_scanner *ues, char *name, time_t born, char *config, uint32_t config_size, uid_t uid, gid_t gid, char *socket_name) {
|
||||
@@ -697,12 +701,12 @@ void emperor_add(struct uwsgi_emperor_scanner *ues, char *name, time_t born, cha
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
int now = tv.tv_sec;
|
||||
uint64_t micros = (tv.tv_sec * 1000 * 1000) + tv.tv_usec;
|
||||
uint64_t micros = (tv.tv_sec * 1000ULL * 1000ULL) + tv.tv_usec;
|
||||
|
||||
// blacklist check
|
||||
struct uwsgi_emperor_blacklist_item *uebi = uwsgi_emperor_blacklist_check(name);
|
||||
if (uebi) {
|
||||
uint64_t i_micros = (uebi->last_attempt.tv_sec * 1000 * 1000) + uebi->last_attempt.tv_usec + uebi->throttle_level;
|
||||
uint64_t i_micros = (uebi->last_attempt.tv_sec * 1000ULL * 1000ULL) + uebi->last_attempt.tv_usec + uebi->throttle_level;
|
||||
if (i_micros > micros) {
|
||||
return;
|
||||
}
|
||||
@@ -763,6 +767,9 @@ void emperor_add(struct uwsgi_emperor_scanner *ues, char *name, time_t born, cha
|
||||
n_ui->uid = uid;
|
||||
n_ui->gid = gid;
|
||||
n_ui->last_mod = born;
|
||||
// start non-ready
|
||||
n_ui->last_ready = 0;
|
||||
n_ui->ready = 0;
|
||||
// start without loyalty
|
||||
n_ui->last_loyal = 0;
|
||||
n_ui->loyal = 0;
|
||||
@@ -1552,7 +1559,7 @@ void emperor_loop() {
|
||||
if (byte == 17) {
|
||||
ui_current->loyal = 1;
|
||||
ui_current->last_loyal = uwsgi_now();
|
||||
uwsgi_log("[emperor] vassal %s is now loyal\n", ui_current->name);
|
||||
uwsgi_log_verbose("[emperor] vassal %s is now loyal\n", ui_current->name);
|
||||
// remove it from the blacklist
|
||||
uwsgi_emperor_blacklist_remove(ui_current->name);
|
||||
// TODO post-start hook
|
||||
@@ -1565,12 +1572,22 @@ void emperor_loop() {
|
||||
emperor_stop(ui_current);
|
||||
}
|
||||
else if (byte == 30 && uwsgi.emperor_broodlord > 0 && uwsgi.emperor_broodlord_count < uwsgi.emperor_broodlord) {
|
||||
uwsgi_log("[emperor] going in broodlord mode: launching zergs for %s\n", ui_current->name);
|
||||
uwsgi_log_verbose("[emperor] going in broodlord mode: launching zergs for %s\n", ui_current->name);
|
||||
char *zerg_name = uwsgi_concat3(ui_current->name, ":", "zerg");
|
||||
// here we discard socket name as broodlord/zerg cannot be on demand
|
||||
emperor_add(ui_current->scanner, zerg_name, uwsgi_now(), NULL, 0, ui_current->uid, ui_current->gid, NULL);
|
||||
free(zerg_name);
|
||||
}
|
||||
else if (byte == 5) {
|
||||
ui_current->accepting = 1;
|
||||
ui_current->last_accepting = uwsgi_now();
|
||||
uwsgi_log_verbose("[emperor] vassal %s is ready to accept requests\n", ui_current->name);
|
||||
}
|
||||
else if (byte == 1) {
|
||||
ui_current->ready = 1;
|
||||
ui_current->last_ready = uwsgi_now();
|
||||
uwsgi_log_verbose("[emperor] vassal %s has been spawned\n", ui_current->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1729,7 +1746,8 @@ void emperor_send_stats(int fd) {
|
||||
goto end0;
|
||||
struct uwsgi_emperor_scanner *ues = emperor_scanners;
|
||||
while (ues) {
|
||||
uwsgi_stats_str(us, ues->arg);
|
||||
if (uwsgi_stats_str(us, ues->arg))
|
||||
goto end0;
|
||||
ues = ues->next;
|
||||
if (ues) {
|
||||
if (uwsgi_stats_comma(us))
|
||||
@@ -1773,8 +1791,16 @@ void emperor_send_stats(int fd) {
|
||||
goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "loyal", (unsigned long long) c_ui->loyal))
|
||||
goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "ready", (unsigned long long) c_ui->ready))
|
||||
goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "accepting", (unsigned long long) c_ui->accepting))
|
||||
goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "last_loyal", (unsigned long long) c_ui->last_loyal))
|
||||
goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "last_ready", (unsigned long long) c_ui->last_ready))
|
||||
goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "last_accepting", (unsigned long long) c_ui->last_accepting))
|
||||
goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "first_run", (unsigned long long) c_ui->first_run))
|
||||
goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "last_run", (unsigned long long) c_ui->last_run))
|
||||
@@ -1864,7 +1890,7 @@ void emperor_send_stats(int fd) {
|
||||
size_t remains = us->pos;
|
||||
off_t pos = 0;
|
||||
while (remains > 0) {
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
goto end0;
|
||||
}
|
||||
@@ -2027,12 +2053,14 @@ void uwsgi_master_manage_emperor() {
|
||||
uwsgi_log_verbose("received message %d from emperor\n", byte);
|
||||
// remove me
|
||||
if (byte == 0) {
|
||||
uwsgi_hooks_run(uwsgi.hook_emperor_stop, "emperor-stop", 0);
|
||||
close(uwsgi.emperor_fd);
|
||||
if (!uwsgi.status.brutally_reloading)
|
||||
kill_them_all(0);
|
||||
}
|
||||
// reload me
|
||||
else if (byte == 1) {
|
||||
uwsgi_hooks_run(uwsgi.hook_emperor_reload, "emperor-reload", 0);
|
||||
// un-lazy the stack to trigger a real reload
|
||||
uwsgi.lazy = 0;
|
||||
uwsgi_block_signal(SIGHUP);
|
||||
@@ -2042,6 +2070,7 @@ void uwsgi_master_manage_emperor() {
|
||||
}
|
||||
else {
|
||||
uwsgi_log("lost connection with my emperor !!!\n");
|
||||
uwsgi_hooks_run(uwsgi.hook_emperor_lost, "emperor-lost", 0);
|
||||
close(uwsgi.emperor_fd);
|
||||
if (!uwsgi.status.brutally_reloading)
|
||||
kill_them_all(0);
|
||||
@@ -2105,3 +2134,16 @@ void uwsgi_master_manage_emperor_proxy() {
|
||||
|
||||
close(ep_client);
|
||||
}
|
||||
|
||||
static void emperor_notify_ready() {
|
||||
if (!uwsgi.has_emperor) return;
|
||||
char byte = 1;
|
||||
if (write(uwsgi.emperor_fd, &byte, 1) != 1) {
|
||||
uwsgi_error("emperor_notify_ready()/write()");
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_setup_emperor() {
|
||||
if (!uwsgi.has_emperor) return;
|
||||
uwsgi.notify_ready = emperor_notify_ready;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,30 @@
|
||||
#include <uwsgi.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
static int error_page(struct wsgi_request *wsgi_req, struct uwsgi_string_list *l) {
|
||||
struct uwsgi_string_list *usl = NULL;
|
||||
uwsgi_foreach(usl, l) {
|
||||
struct stat st;
|
||||
if (!stat(usl->value, &st)) {
|
||||
int fd = open(usl->value, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
if (uwsgi_response_add_header(wsgi_req, "Content-Type", 12, "text/html", 9)) { close(fd); return 0;}
|
||||
if (uwsgi_response_add_content_length(wsgi_req, st.st_size)) { close(fd); return 0;}
|
||||
uwsgi_response_sendfile_do(wsgi_req, fd, 0, st.st_size);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// generate internal server error message
|
||||
void uwsgi_500(struct wsgi_request *wsgi_req) {
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, "500 Internal Server Error", 25)) return;
|
||||
if (uwsgi_response_add_connection_close(wsgi_req)) return;
|
||||
if (error_page(wsgi_req, uwsgi.error_page_500)) return;
|
||||
if (uwsgi_response_add_header(wsgi_req, "Content-Type", 12, "text/plain", 10)) return;
|
||||
uwsgi_response_write_body_do(wsgi_req, "Internal Server Error", 21);
|
||||
}
|
||||
|
||||
@@ -11,6 +32,7 @@ void uwsgi_500(struct wsgi_request *wsgi_req) {
|
||||
void uwsgi_404(struct wsgi_request *wsgi_req) {
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, "404 Not Found", 13)) return;
|
||||
if (uwsgi_response_add_connection_close(wsgi_req)) return;
|
||||
if (error_page(wsgi_req, uwsgi.error_page_404)) return;
|
||||
if (uwsgi_response_add_header(wsgi_req, "Content-Type", 12, "text/plain", 10)) return;
|
||||
uwsgi_response_write_body_do(wsgi_req, "Not Found", 9);
|
||||
}
|
||||
@@ -18,6 +40,7 @@ void uwsgi_404(struct wsgi_request *wsgi_req) {
|
||||
void uwsgi_403(struct wsgi_request *wsgi_req) {
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, "403 Forbidden", 13)) return;
|
||||
if (uwsgi_response_add_connection_close(wsgi_req)) return;
|
||||
if (error_page(wsgi_req, uwsgi.error_page_403)) return;
|
||||
if (uwsgi_response_add_content_type(wsgi_req, "text/plain", 10)) return;
|
||||
uwsgi_response_write_body_do(wsgi_req, "Forbidden", 9);
|
||||
}
|
||||
|
||||
@@ -1231,6 +1231,8 @@ static int timerfd_create(clockid_t __clock_id, int __flags) {
|
||||
return syscall(283, __clock_id, __flags);
|
||||
#elif defined(__i386__)
|
||||
return syscall(322, __clock_id, __flags);
|
||||
#elif defined(__arm__)
|
||||
return syscall(350, __clock_id, __flags);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
@@ -1241,6 +1243,10 @@ static int timerfd_settime(int __ufd, int __flags, __const struct itimerspec *__
|
||||
return syscall(286, __ufd, __flags, __utmr, __otmr);
|
||||
#elif defined(__i386__)
|
||||
return syscall(325, __ufd, __flags, __utmr, __otmr);
|
||||
#elif defined(__arm__)
|
||||
return syscall(353, __ufd, __flags, __utmr, __otmr);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
+24
-10
@@ -24,16 +24,29 @@ static char *uwsgi_fifo_by_slot() {
|
||||
return uwsgi.master_fifo->value;
|
||||
}
|
||||
|
||||
static void uwsgi_fifo_set_slot_zero() { uwsgi.master_fifo_slot = 0; }
|
||||
static void uwsgi_fifo_set_slot_one() { uwsgi.master_fifo_slot = 1; }
|
||||
static void uwsgi_fifo_set_slot_two() { uwsgi.master_fifo_slot = 2; }
|
||||
static void uwsgi_fifo_set_slot_three() { uwsgi.master_fifo_slot = 3; }
|
||||
static void uwsgi_fifo_set_slot_four() { uwsgi.master_fifo_slot = 4; }
|
||||
static void uwsgi_fifo_set_slot_five() { uwsgi.master_fifo_slot = 5; }
|
||||
static void uwsgi_fifo_set_slot_six() { uwsgi.master_fifo_slot = 6; }
|
||||
static void uwsgi_fifo_set_slot_seven() { uwsgi.master_fifo_slot = 7; }
|
||||
static void uwsgi_fifo_set_slot_eight() { uwsgi.master_fifo_slot = 8; }
|
||||
static void uwsgi_fifo_set_slot_nine() { uwsgi.master_fifo_slot = 9; }
|
||||
#define announce_fifo uwsgi_log_verbose("active master fifo is now %s\n", uwsgi_fifo_by_slot())
|
||||
|
||||
static void uwsgi_fifo_set_slot_zero() { uwsgi.master_fifo_slot = 0; announce_fifo; }
|
||||
static void uwsgi_fifo_set_slot_one() { uwsgi.master_fifo_slot = 1; announce_fifo; }
|
||||
static void uwsgi_fifo_set_slot_two() { uwsgi.master_fifo_slot = 2; announce_fifo; }
|
||||
static void uwsgi_fifo_set_slot_three() { uwsgi.master_fifo_slot = 3; announce_fifo; }
|
||||
static void uwsgi_fifo_set_slot_four() { uwsgi.master_fifo_slot = 4; announce_fifo; }
|
||||
static void uwsgi_fifo_set_slot_five() { uwsgi.master_fifo_slot = 5; announce_fifo; }
|
||||
static void uwsgi_fifo_set_slot_six() { uwsgi.master_fifo_slot = 6; announce_fifo; }
|
||||
static void uwsgi_fifo_set_slot_seven() { uwsgi.master_fifo_slot = 7; announce_fifo; }
|
||||
static void uwsgi_fifo_set_slot_eight() { uwsgi.master_fifo_slot = 8; announce_fifo; }
|
||||
static void uwsgi_fifo_set_slot_nine() { uwsgi.master_fifo_slot = 9; announce_fifo; }
|
||||
|
||||
static void subscriptions_blocker() {
|
||||
if (uwsgi.subscriptions_blocked) {
|
||||
uwsgi_log_verbose("subscriptions re-enabled\n");
|
||||
uwsgi.subscriptions_blocked = 0;
|
||||
}
|
||||
else {
|
||||
uwsgi.subscriptions_blocked = 1;
|
||||
uwsgi_log_verbose("subscriptions blocked\n");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -71,6 +84,7 @@ void uwsgi_master_fifo_prepare() {
|
||||
uwsgi_fifo_table['r'] = grace_them_all;
|
||||
uwsgi_fifo_table['R'] = reap_them_all;
|
||||
uwsgi_fifo_table['s'] = stats;
|
||||
uwsgi_fifo_table['S'] = subscriptions_blocker;
|
||||
uwsgi_fifo_table['w'] = uwsgi_reload_workers;
|
||||
uwsgi_fifo_table['W'] = uwsgi_brutally_reload_workers;
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ struct uwsgi_gateway *register_gateway(char *name, void (*loop) (int, void *), v
|
||||
ug->num = num;
|
||||
ug->fullname = fullname;
|
||||
ug->data = data;
|
||||
ug->uid = 0;
|
||||
ug->gid = 0;
|
||||
|
||||
#if defined(SOCK_SEQPACKET) && defined(__linux__)
|
||||
if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, ug->internal_subscription_pipe)) {
|
||||
@@ -90,6 +92,22 @@ void gateway_respawn(int id) {
|
||||
signal(SIGSTOP, SIG_IGN);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
|
||||
if (ug->gid) {
|
||||
uwsgi_log("%s %d setgid() to %d\n", ug->name, ug->num, (int) ug->gid);
|
||||
if (setgid(ug->gid)) {
|
||||
uwsgi_error("gateway_respawn()/setgid()");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (ug->uid) {
|
||||
uwsgi_log("%s %d setuid() to %d\n", ug->name, ug->num, (int) ug->uid);
|
||||
if (setuid(ug->uid)) {
|
||||
uwsgi_error("gateway_respawn()/setuid()");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
ug->loop(id, ug->data);
|
||||
// never here !!! (i hope)
|
||||
exit(1);
|
||||
|
||||
+305
-3
@@ -55,6 +55,22 @@ static int uwsgi_hook_chdir(char *arg) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_mkdir(char *arg) {
|
||||
int ret = mkdir(arg, 0777);
|
||||
if (ret) {
|
||||
uwsgi_error("uwsgi_hook_mkdir()");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_putenv(char *arg) {
|
||||
int ret = putenv(arg);
|
||||
if (ret) {
|
||||
uwsgi_error("uwsgi_hook_putenv()");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_exec(char *arg) {
|
||||
int ret = uwsgi_run_command_and_wait(NULL, arg);
|
||||
if (ret != 0) {
|
||||
@@ -78,6 +94,263 @@ static int uwsgi_hook_print(char *arg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_unlink(char *arg) {
|
||||
int ret = unlink(arg);
|
||||
if (ret) {
|
||||
uwsgi_error("uwsgi_hook_unlink()/unlink()");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_writefifo(char *arg) {
|
||||
char *space = strchr(arg, ' ');
|
||||
if (!space) {
|
||||
uwsgi_log("invalid hook writefifo syntax, must be: <file> <string>\n");
|
||||
return -1;
|
||||
}
|
||||
*space = 0;
|
||||
int fd = open(arg, O_WRONLY|O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
uwsgi_error_open(arg);
|
||||
*space = ' ';
|
||||
if (errno == ENODEV) return 0;
|
||||
#ifdef ENXIO
|
||||
if (errno == ENXIO) return 0;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
*space = ' ';
|
||||
size_t l = strlen(space+1);
|
||||
if (write(fd, space+1, l) != (ssize_t) l) {
|
||||
uwsgi_error("uwsgi_hook_writefifo()/write()");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_write(char *arg) {
|
||||
char *space = strchr(arg, ' ');
|
||||
if (!space) {
|
||||
uwsgi_log("invalid hook write syntax, must be: <file> <string>\n");
|
||||
return -1;
|
||||
}
|
||||
*space = 0;
|
||||
int fd = open(arg, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
uwsgi_error_open(arg);
|
||||
*space = ' ';
|
||||
return -1;
|
||||
}
|
||||
*space = ' ';
|
||||
size_t l = strlen(space+1);
|
||||
if (write(fd, space+1, l) != (ssize_t) l) {
|
||||
uwsgi_error("uwsgi_hook_write()/write()");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_append(char *arg) {
|
||||
char *space = strchr(arg, ' ');
|
||||
if (!space) {
|
||||
uwsgi_log("invalid hook append syntax, must be: <file> <string>\n");
|
||||
return -1;
|
||||
}
|
||||
*space = 0;
|
||||
int fd = open(arg, O_WRONLY|O_CREAT|O_APPEND, 0666);
|
||||
if (fd < 0) {
|
||||
uwsgi_error_open(arg);
|
||||
*space = ' ';
|
||||
return -1;
|
||||
}
|
||||
*space = ' ';
|
||||
size_t l = strlen(space+1);
|
||||
if (write(fd, space+1, l) != (ssize_t) l) {
|
||||
uwsgi_error("uwsgi_hook_append()/write()");
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int uwsgi_hook_writen(char *arg) {
|
||||
char *space = strchr(arg, ' ');
|
||||
if (!space) {
|
||||
uwsgi_log("invalid hook writen syntax, must be: <file> <string>\n");
|
||||
return -1;
|
||||
}
|
||||
*space = 0;
|
||||
int fd = open(arg, O_WRONLY|O_CREAT|O_TRUNC, 0666);
|
||||
if (fd < 0) {
|
||||
uwsgi_error_open(arg);
|
||||
*space = ' ';
|
||||
return -1;
|
||||
}
|
||||
*space = ' ';
|
||||
size_t l = strlen(space+1);
|
||||
char *buf = uwsgi_malloc(l + 1);
|
||||
memcpy(buf, space+1, l);
|
||||
buf[l] = '\n';
|
||||
if (write(fd, buf, l+1) != (ssize_t) (l+1)) {
|
||||
uwsgi_error("uwsgi_hook_writen()/write()");
|
||||
free(buf);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
free(buf);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_appendn(char *arg) {
|
||||
char *space = strchr(arg, ' ');
|
||||
if (!space) {
|
||||
uwsgi_log("invalid hook appendn syntax, must be: <file> <string>\n");
|
||||
return -1;
|
||||
}
|
||||
*space = 0;
|
||||
int fd = open(arg, O_WRONLY|O_CREAT|O_APPEND, 0666);
|
||||
if (fd < 0) {
|
||||
uwsgi_error_open(arg);
|
||||
*space = ' ';
|
||||
return -1;
|
||||
}
|
||||
*space = ' ';
|
||||
size_t l = strlen(space+1);
|
||||
char *buf = uwsgi_malloc(l + 1);
|
||||
memcpy(buf, space+1, l);
|
||||
buf[l] = '\n';
|
||||
if (write(fd, buf, l+1) != (ssize_t) (l+1)) {
|
||||
uwsgi_error("uwsgi_hook_appendn()/write()");
|
||||
free(buf);
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
free(buf);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int uwsgi_hook_chmod(char *arg) {
|
||||
char *space = strchr(arg, ' ');
|
||||
if (!space) {
|
||||
uwsgi_log("invalid hook chmod syntax, must be: <file> <mode>\n");
|
||||
return -1;
|
||||
}
|
||||
*space = 0;
|
||||
int error = 0;
|
||||
mode_t mask = uwsgi_mode_t(space+1, &error);
|
||||
if (error) {
|
||||
uwsgi_log("invalid hook chmod mask: %s\n", space+1);
|
||||
*space = ' ';
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = chmod(arg, mask);
|
||||
*space = ' ';
|
||||
if (ret) {
|
||||
uwsgi_error("uwsgi_hook_chmod()/chmod()");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_chown(char *arg) {
|
||||
char *space = strchr(arg, ' ');
|
||||
if (!space) {
|
||||
uwsgi_log("invalid hook chown syntax, must be: <file> <uid> <gid>\n");
|
||||
return -1;
|
||||
}
|
||||
*space = 0;
|
||||
|
||||
char *space2 = strchr(space+1, ' ');
|
||||
if (!space2) {
|
||||
*space = ' ';
|
||||
uwsgi_log("invalid hook chown syntax, must be: <file> <uid> <gid>\n");
|
||||
return -1;
|
||||
}
|
||||
*space2 = 0;
|
||||
|
||||
struct passwd *pw = getpwnam(space+1);
|
||||
if (!pw) {
|
||||
uwsgi_log("unable to find uid %s\n", space+1);
|
||||
*space = ' ';
|
||||
*space2 = ' ';
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct group *gr = getgrnam(space2+1);
|
||||
if (!gr) {
|
||||
uwsgi_log("unable to find gid %s\n", space2+1);
|
||||
*space = ' ';
|
||||
*space2 = ' ';
|
||||
return -1;
|
||||
}
|
||||
int ret = chown(arg, pw->pw_uid, gr->gr_gid);
|
||||
*space = ' ';
|
||||
*space2 = ' ';
|
||||
if (ret) {
|
||||
uwsgi_error("uwsgi_hook_chown()/chown)");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int uwsgi_hook_chown2(char *arg) {
|
||||
char *space = strchr(arg, ' ');
|
||||
if (!space) {
|
||||
uwsgi_log("invalid hook chown2 syntax, must be: <file> <uid> <gid>\n");
|
||||
return -1;
|
||||
}
|
||||
*space = 0;
|
||||
|
||||
char *space2 = strchr(space+1, ' ');
|
||||
if (!space2) {
|
||||
*space = ' ';
|
||||
uwsgi_log("invalid hook chown2 syntax, must be: <file> <uid> <gid>\n");
|
||||
return -1;
|
||||
}
|
||||
*space2 = 0;
|
||||
|
||||
if (!is_a_number(space+1)) {
|
||||
uwsgi_log("invalid hook chown2 syntax, uid must be a number\n");
|
||||
*space = ' ';
|
||||
*space2 = ' ';
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!is_a_number(space2+1)) {
|
||||
uwsgi_log("invalid hook chown2 syntax, gid must be a number\n");
|
||||
*space = ' ';
|
||||
*space2 = ' ';
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = chown(arg, atoi(space+1), atoi(space2+1));
|
||||
*space = ' ';
|
||||
*space2 = ' ';
|
||||
if (ret) {
|
||||
uwsgi_error("uwsgi_hook_chown2()/chown)");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int uwsgi_hook_hostname(char *arg) {
|
||||
#ifdef __CYGWIN__
|
||||
return -1;
|
||||
#else
|
||||
return sethostname(arg, strlen(arg));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int uwsgi_hook_callint(char *arg) {
|
||||
char *space = strchr(arg, ' ');
|
||||
if (space) {
|
||||
@@ -175,8 +448,23 @@ static int uwsgi_hook_callret(char *arg) {
|
||||
|
||||
void uwsgi_register_base_hooks() {
|
||||
uwsgi_register_hook("cd", uwsgi_hook_chdir);
|
||||
uwsgi_register_hook("chdir", uwsgi_hook_chdir);
|
||||
|
||||
uwsgi_register_hook("mkdir", uwsgi_hook_mkdir);
|
||||
uwsgi_register_hook("putenv", uwsgi_hook_putenv);
|
||||
uwsgi_register_hook("chmod", uwsgi_hook_chmod);
|
||||
uwsgi_register_hook("chown", uwsgi_hook_chown);
|
||||
uwsgi_register_hook("chown2", uwsgi_hook_chown2);
|
||||
|
||||
uwsgi_register_hook("exec", uwsgi_hook_exec);
|
||||
|
||||
uwsgi_register_hook("write", uwsgi_hook_write);
|
||||
uwsgi_register_hook("writen", uwsgi_hook_writen);
|
||||
uwsgi_register_hook("append", uwsgi_hook_append);
|
||||
uwsgi_register_hook("appendn", uwsgi_hook_appendn);
|
||||
uwsgi_register_hook("writefifo", uwsgi_hook_writefifo);
|
||||
uwsgi_register_hook("unlink", uwsgi_hook_unlink);
|
||||
|
||||
uwsgi_register_hook("mount", uwsgi_mount_hook);
|
||||
uwsgi_register_hook("umount", uwsgi_umount_hook);
|
||||
|
||||
@@ -186,6 +474,8 @@ void uwsgi_register_base_hooks() {
|
||||
uwsgi_register_hook("callint", uwsgi_hook_callint);
|
||||
uwsgi_register_hook("callintret", uwsgi_hook_callintret);
|
||||
|
||||
uwsgi_register_hook("hostname", uwsgi_hook_hostname);
|
||||
|
||||
// for testing
|
||||
uwsgi_register_hook("exit", uwsgi_hook_exit);
|
||||
uwsgi_register_hook("print", uwsgi_hook_print);
|
||||
@@ -200,14 +490,26 @@ void uwsgi_hooks_run(struct uwsgi_string_list *l, char *phase, int fatal) {
|
||||
exit(1);
|
||||
}
|
||||
*colon = 0;
|
||||
struct uwsgi_hook *uh = uwsgi_hook_by_name(usl->value);
|
||||
int private = 0;
|
||||
char *action = usl->value;
|
||||
// private hook ?
|
||||
if (action[0] == '!') {
|
||||
action++;
|
||||
private = 1;
|
||||
}
|
||||
struct uwsgi_hook *uh = uwsgi_hook_by_name(action);
|
||||
if (!uh) {
|
||||
uwsgi_log("hook not found: %s\n", usl->value);
|
||||
uwsgi_log("hook action not found: %s\n", action);
|
||||
exit(1);
|
||||
}
|
||||
*colon = ':';
|
||||
|
||||
uwsgi_log("running \"%s\" (%s)...\n", usl->value, phase);
|
||||
if (private) {
|
||||
uwsgi_log("running --- PRIVATE HOOK --- (%s)...\n", phase);
|
||||
}
|
||||
else {
|
||||
uwsgi_log("running \"%s\" (%s)...\n", usl->value, phase);
|
||||
}
|
||||
|
||||
int ret = uh->func(colon+1);
|
||||
if (fatal && ret != 0) {
|
||||
|
||||
+10
-8
@@ -117,11 +117,11 @@ void uwsgi_init_default() {
|
||||
uwsgi.max_vars = MAX_VARS;
|
||||
uwsgi.vec_size = 4 + 1 + (4 * MAX_VARS);
|
||||
|
||||
uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] = 4;
|
||||
uwsgi.shared->options[UWSGI_OPTION_LOGGING] = 1;
|
||||
uwsgi.socket_timeout = 4;
|
||||
uwsgi.logging_options.enabled = 1;
|
||||
|
||||
// a workers hould be running for at least 10 seconds
|
||||
uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] = 10;
|
||||
uwsgi.min_worker_lifetime = 10;
|
||||
|
||||
uwsgi.shared->spooler_frequency = 30;
|
||||
|
||||
@@ -170,6 +170,8 @@ void uwsgi_init_default() {
|
||||
|
||||
uwsgi.wait_read_hook = uwsgi_simple_wait_read_hook;
|
||||
uwsgi.wait_write_hook = uwsgi_simple_wait_write_hook;
|
||||
uwsgi.wait_milliseconds_hook = uwsgi_simple_wait_milliseconds_hook;
|
||||
uwsgi.wait_read2_hook = uwsgi_simple_wait_read2_hook;
|
||||
|
||||
uwsgi_websockets_init();
|
||||
|
||||
@@ -194,7 +196,7 @@ void uwsgi_setup_reload() {
|
||||
uwsgi.reloads++;
|
||||
//convert reloads to string
|
||||
int rlen = snprintf(env_reload_buf, 10, "%u", uwsgi.reloads);
|
||||
if (rlen > 0) {
|
||||
if (rlen > 0 && rlen < 10) {
|
||||
env_reload_buf[rlen] = 0;
|
||||
if (setenv("UWSGI_RELOADS", env_reload_buf, 1)) {
|
||||
uwsgi_error("setenv()");
|
||||
@@ -411,7 +413,7 @@ void sanitize_args() {
|
||||
uwsgi.cores = uwsgi.threads;
|
||||
}
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
if (uwsgi.harakiri_options.workers > 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");
|
||||
}
|
||||
@@ -447,13 +449,13 @@ void sanitize_args() {
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME] > 0 && uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] >= uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME]) {
|
||||
if (uwsgi.max_worker_lifetime > 0 && uwsgi.min_worker_lifetime >= uwsgi.max_worker_lifetime) {
|
||||
uwsgi_log("invalid min-worker-lifetime value (%d), must be lower than max-worker-lifetime (%d)\n",
|
||||
uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME], uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME]);
|
||||
uwsgi.min_worker_lifetime, uwsgi.max_worker_lifetime);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (uwsgi.cheaper_rss_limit_soft && uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] != 1 && uwsgi.force_get_memusage != 1) {
|
||||
if (uwsgi.cheaper_rss_limit_soft && uwsgi.logging_options.memory_report != 1 && uwsgi.force_get_memusage != 1) {
|
||||
uwsgi_log("enabling cheaper-rss-limit-soft requires enabling also memory-report\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ int uwsgi_waitfd_event(int fd, int timeout, int event) {
|
||||
struct pollfd upoll;
|
||||
|
||||
if (!timeout)
|
||||
timeout = uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT];
|
||||
timeout = uwsgi.socket_timeout;
|
||||
|
||||
timeout = timeout * 1000;
|
||||
if (timeout < 0)
|
||||
@@ -586,11 +586,13 @@ int *uwsgi_attach_fd(int fd, int *count_ptr, char *code, size_t code_len) {
|
||||
len = recvmsg(fd, &msg, 0);
|
||||
if (len <= 0) {
|
||||
uwsgi_error("recvmsg()");
|
||||
free(msg_control);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (code && code_len > 0) {
|
||||
if (uwsgi_strncmp(id, code_len, code, code_len)) {
|
||||
free(msg_control);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -606,15 +608,19 @@ int *uwsgi_attach_fd(int fd, int *count_ptr, char *code, size_t code_len) {
|
||||
}
|
||||
|
||||
cmsg = CMSG_FIRSTHDR(&msg);
|
||||
if (!cmsg)
|
||||
if (!cmsg) {
|
||||
free(msg_control);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
|
||||
free(msg_control);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((size_t) (cmsg->cmsg_len - ((char *) CMSG_DATA(cmsg) - (char *) cmsg)) > (size_t) (sizeof(int) * (count + 1))) {
|
||||
uwsgi_log("not enough space for sockets data, consider increasing it\n");
|
||||
free(msg_control);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -756,11 +762,12 @@ int uwsgi_write_true_nb(int fd, char *buf, size_t remains, int timeout) {
|
||||
int ret;
|
||||
|
||||
while(remains > 0) {
|
||||
errno = 0;
|
||||
ssize_t len = write(fd, ptr, remains);
|
||||
if (len > 0) goto written;
|
||||
if (len == 0) return -1;
|
||||
if (len < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) goto wait;
|
||||
if (uwsgi_is_again()) goto wait;
|
||||
return -1;
|
||||
}
|
||||
wait:
|
||||
@@ -911,7 +918,7 @@ ssize_t uwsgi_read_true_nb(int fd, char *buf, size_t len, int timeout) {
|
||||
}
|
||||
if (rlen == 0) return -1;
|
||||
if (rlen < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) goto wait;
|
||||
if (uwsgi_is_again()) goto wait;
|
||||
}
|
||||
return -1;
|
||||
wait:
|
||||
@@ -961,7 +968,7 @@ int uwsgi_read_with_realloc(int fd, char **buffer, size_t *rlen, int timeout, ui
|
||||
if (len > 0) goto readok;
|
||||
if (len == 0) return -1;
|
||||
if (len < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) goto wait;
|
||||
if (uwsgi_is_again()) goto wait;
|
||||
return -1;
|
||||
}
|
||||
wait:
|
||||
@@ -1003,7 +1010,7 @@ readok:
|
||||
if (len > 0) goto readok2;
|
||||
if (len == 0) return -1;
|
||||
if (len < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINPROGRESS) goto wait2;
|
||||
if (uwsgi_is_again()) goto wait2;
|
||||
return -1;
|
||||
}
|
||||
wait2:
|
||||
@@ -1215,3 +1222,204 @@ void uwsgi_remap_fd(int fd, char *filename) {
|
||||
}
|
||||
}
|
||||
|
||||
int uwsgi_is_connected(int fd) {
|
||||
int soopt;
|
||||
socklen_t solen = sizeof(int);
|
||||
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *) (&soopt), &solen) < 0) {
|
||||
return 0;
|
||||
}
|
||||
/* is something bad ? */
|
||||
if (soopt) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_pass_cred(int fd, char *code, size_t code_len) {
|
||||
#ifdef SCM_CREDENTIALS
|
||||
struct msghdr cr_msg;
|
||||
struct cmsghdr *cmsg;
|
||||
struct iovec cr_iov;
|
||||
void *cr_msg_control = uwsgi_calloc(CMSG_SPACE(sizeof(struct ucred)));
|
||||
|
||||
cr_iov.iov_base = code;
|
||||
cr_iov.iov_len = code_len;
|
||||
|
||||
cr_msg.msg_name = NULL;
|
||||
cr_msg.msg_namelen = 0;
|
||||
|
||||
cr_msg.msg_iov = &cr_iov;
|
||||
cr_msg.msg_iovlen = 1;
|
||||
|
||||
cr_msg.msg_flags = 0;
|
||||
cr_msg.msg_control = cr_msg_control;
|
||||
cr_msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
|
||||
|
||||
cmsg = CMSG_FIRSTHDR(&cr_msg);
|
||||
cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred));
|
||||
cmsg->cmsg_level = SOL_SOCKET;
|
||||
cmsg->cmsg_type = SCM_CREDENTIALS;
|
||||
|
||||
struct ucred *u = (struct ucred*) CMSG_DATA(cmsg);
|
||||
u->pid = getpid();
|
||||
u->uid = getuid();
|
||||
u->gid = getgid();
|
||||
|
||||
if (sendmsg(fd, &cr_msg, 0) < 0) {
|
||||
uwsgi_error("uwsgi_pass_cred()/sendmsg()");
|
||||
free(cr_msg_control);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(cr_msg_control);
|
||||
return 0;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
int uwsgi_pass_cred2(int fd, char *code, size_t code_len, struct sockaddr *addr, size_t addr_len) {
|
||||
#ifdef SCM_CREDENTIALS
|
||||
struct msghdr cr_msg;
|
||||
struct cmsghdr *cmsg;
|
||||
struct iovec cr_iov;
|
||||
void *cr_msg_control = uwsgi_calloc(CMSG_SPACE(sizeof(struct ucred)));
|
||||
|
||||
cr_iov.iov_base = code;
|
||||
cr_iov.iov_len = code_len;
|
||||
|
||||
cr_msg.msg_name = addr;
|
||||
cr_msg.msg_namelen = addr_len;
|
||||
|
||||
cr_msg.msg_iov = &cr_iov;
|
||||
cr_msg.msg_iovlen = 1;
|
||||
|
||||
cr_msg.msg_flags = 0;
|
||||
cr_msg.msg_control = cr_msg_control;
|
||||
cr_msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
|
||||
|
||||
cmsg = CMSG_FIRSTHDR(&cr_msg);
|
||||
cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred));
|
||||
cmsg->cmsg_level = SOL_SOCKET;
|
||||
cmsg->cmsg_type = SCM_CREDENTIALS;
|
||||
|
||||
struct ucred *u = (struct ucred*) CMSG_DATA(cmsg);
|
||||
u->pid = getpid();
|
||||
u->uid = getuid();
|
||||
u->gid = getgid();
|
||||
|
||||
if (sendmsg(fd, &cr_msg, 0) < 0) {
|
||||
uwsgi_error("uwsgi_pass_cred2()/sendmsg()");
|
||||
free(cr_msg_control);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(cr_msg_control);
|
||||
return 0;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_recv_cred(int fd, char *code, size_t code_len, pid_t *pid, uid_t *uid, gid_t *gid) {
|
||||
#ifdef SCM_CREDENTIALS
|
||||
struct iovec iov;
|
||||
int ret = -1;
|
||||
|
||||
void *msg_control = uwsgi_calloc(CMSG_SPACE(sizeof(struct ucred)));
|
||||
|
||||
iov.iov_base = uwsgi_malloc(code_len);
|
||||
iov.iov_len = code_len;
|
||||
|
||||
struct msghdr msg;
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
msg.msg_control = msg_control;
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
|
||||
|
||||
ssize_t len = recvmsg(fd, &msg, 0);
|
||||
if (len <= 0) {
|
||||
uwsgi_error("uwsgi_recv_cred()/recvmsg()");
|
||||
goto clear;
|
||||
}
|
||||
|
||||
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
|
||||
if (!cmsg) goto clear;
|
||||
|
||||
if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_CREDENTIALS) {
|
||||
goto clear;
|
||||
}
|
||||
|
||||
if (uwsgi_strncmp(code, code_len, iov.iov_base, iov.iov_len)) goto clear;
|
||||
|
||||
struct ucred *u = (struct ucred *) CMSG_DATA(cmsg);
|
||||
*pid = u->pid;
|
||||
*uid = u->uid;
|
||||
*gid = u->gid;
|
||||
ret = 0;
|
||||
|
||||
clear:
|
||||
free(msg_control);
|
||||
free(iov.iov_base);
|
||||
return ret;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
ssize_t uwsgi_recv_cred2(int fd, char *buf, size_t buf_len, pid_t *pid, uid_t *uid, gid_t *gid) {
|
||||
#ifdef SCM_CREDENTIALS
|
||||
struct iovec iov;
|
||||
ssize_t ret = -1;
|
||||
|
||||
void *msg_control = uwsgi_calloc(CMSG_SPACE(sizeof(struct ucred)));
|
||||
|
||||
iov.iov_base = buf;
|
||||
iov.iov_len = buf_len;
|
||||
|
||||
struct msghdr msg;
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
msg.msg_control = msg_control;
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
|
||||
|
||||
ssize_t len = recvmsg(fd, &msg, 0);
|
||||
if (len <= 0) {
|
||||
uwsgi_error("uwsgi_recv_cred2()/recvmsg()");
|
||||
goto clear;
|
||||
}
|
||||
|
||||
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
|
||||
if (!cmsg) goto clear;
|
||||
|
||||
if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_CREDENTIALS) {
|
||||
goto clear;
|
||||
}
|
||||
|
||||
struct ucred *u = (struct ucred *) CMSG_DATA(cmsg);
|
||||
*pid = u->pid;
|
||||
*uid = u->uid;
|
||||
*gid = u->gid;
|
||||
ret = len;
|
||||
|
||||
clear:
|
||||
free(msg_control);
|
||||
return ret;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+82
-4
@@ -4,13 +4,90 @@
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
#ifdef UWSGI_JSON_YAJL
|
||||
#include <yajl/yajl_tree.h>
|
||||
|
||||
void uwsgi_json_config(char *file, char *magic_table[]) {
|
||||
size_t len = 0;
|
||||
|
||||
char *object_asked = "uwsgi";
|
||||
char *colon;
|
||||
|
||||
if (uwsgi_check_scheme(file)) {
|
||||
colon = uwsgi_get_last_char(file, '/');
|
||||
colon = uwsgi_get_last_char(colon, ':');
|
||||
}
|
||||
else {
|
||||
colon = uwsgi_get_last_char(file, ':');
|
||||
}
|
||||
|
||||
if (colon) {
|
||||
colon[0] = 0;
|
||||
if (colon[1] != 0) {
|
||||
object_asked = colon + 1;
|
||||
}
|
||||
}
|
||||
|
||||
uwsgi_log_initial("[uWSGI] getting JSON configuration from %s\n", file);
|
||||
|
||||
char *json_data = uwsgi_open_and_read(file, &len, 1, magic_table);
|
||||
|
||||
char errbuf[1024];
|
||||
yajl_val node = yajl_tree_parse((const char *)json_data, errbuf, sizeof(errbuf));
|
||||
|
||||
if (!node) {
|
||||
uwsgi_log("error parsing JSON data: %s\n", errbuf);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const char * path[] = { object_asked, NULL };
|
||||
yajl_val v = yajl_tree_get(node, path, yajl_t_any);
|
||||
if (!YAJL_IS_OBJECT(v)) {
|
||||
uwsgi_log("you must define a object named %s in your JSON data\n", object_asked);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
size_t i;
|
||||
for(i=0;i<v->u.object.len;i++) {
|
||||
char *key = (char *) v->u.object.keys[i];
|
||||
yajl_val o = v->u.object.values[i];
|
||||
if (YAJL_IS_STRING(o)) {
|
||||
add_exported_option(key, YAJL_GET_STRING(o) , 0);
|
||||
}
|
||||
else if (YAJL_IS_TRUE(o)) {
|
||||
add_exported_option(key, strdup("1"), 0);
|
||||
}
|
||||
else if (YAJL_IS_FALSE(o) || YAJL_IS_NULL(o)) {
|
||||
add_exported_option(key, strdup("0"), 0);
|
||||
}
|
||||
else if (YAJL_IS_NUMBER(o) || YAJL_IS_INTEGER(o)) {
|
||||
add_exported_option(key, YAJL_GET_NUMBER(o), 0);
|
||||
}
|
||||
else if (YAJL_IS_ARRAY(o)) {
|
||||
size_t j;
|
||||
for(j=0;j<o->u.array.len;j++) {
|
||||
yajl_val a_o = o->u.array.values[j];
|
||||
if (YAJL_IS_STRING(a_o)) {
|
||||
add_exported_option(key, YAJL_GET_STRING(a_o) , 0);
|
||||
}
|
||||
else if (YAJL_IS_TRUE(a_o)) {
|
||||
add_exported_option(key, strdup("1"), 0);
|
||||
}
|
||||
else if (YAJL_IS_FALSE(a_o) || YAJL_IS_NULL(a_o)) {
|
||||
add_exported_option(key, strdup("0"), 0);
|
||||
}
|
||||
else if (YAJL_IS_NUMBER(a_o) || YAJL_IS_INTEGER(a_o)) {
|
||||
add_exported_option(key, YAJL_GET_NUMBER(a_o), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#include <jansson.h>
|
||||
|
||||
|
||||
/*
|
||||
I really love the jansson library...
|
||||
*/
|
||||
|
||||
void uwsgi_json_config(char *file, char *magic_table[]) {
|
||||
|
||||
size_t len = 0;
|
||||
@@ -111,3 +188,4 @@ void uwsgi_json_config(char *file, char *magic_table[]) {
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
+4
-1
@@ -737,6 +737,7 @@ void uwsgi_legion_add(struct uwsgi_legion *ul) {
|
||||
|
||||
int uwsgi_legion_announce(struct uwsgi_legion *ul) {
|
||||
struct uwsgi_buffer *ub = uwsgi_buffer_new(4096);
|
||||
unsigned char *encrypted = NULL;
|
||||
|
||||
if (uwsgi_buffer_append_keyval(ub, "legion", 6, ul->legion, ul->legion_len))
|
||||
goto err;
|
||||
@@ -769,7 +770,7 @@ int uwsgi_legion_announce(struct uwsgi_legion *ul) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
unsigned char *encrypted = uwsgi_malloc(ub->pos + 4 + EVP_MAX_BLOCK_LENGTH);
|
||||
encrypted = uwsgi_malloc(ub->pos + 4 + EVP_MAX_BLOCK_LENGTH);
|
||||
if (EVP_EncryptInit_ex(ul->encrypt_ctx, NULL, NULL, NULL, NULL) <= 0) {
|
||||
uwsgi_error("[uwsgi-legion] EVP_EncryptInit_ex()");
|
||||
goto err;
|
||||
@@ -808,6 +809,7 @@ int uwsgi_legion_announce(struct uwsgi_legion *ul) {
|
||||
return 0;
|
||||
err:
|
||||
uwsgi_buffer_destroy(ub);
|
||||
free(encrypted);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -824,6 +826,7 @@ void uwsgi_opt_legion_mcast(char *opt, char *value, void *foobar) {
|
||||
exit(1);
|
||||
}
|
||||
uwsgi_legion_register_node(ul, uwsgi_str(ul->addr));
|
||||
free(legion);
|
||||
}
|
||||
|
||||
void uwsgi_opt_legion_node(char *opt, char *value, void *foobar) {
|
||||
|
||||
@@ -647,6 +647,7 @@ void *uwsgi_robust_mutexes_watchdog_loop(void *arg) {
|
||||
for(;;) {
|
||||
uwsgi_lock(uwsgi.the_thunder_lock);
|
||||
uwsgi_unlock(uwsgi.the_thunder_lock);
|
||||
sleep(1);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+182
-225
@@ -119,6 +119,36 @@ void uwsgi_log_verbose(const char *fmt, ...) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
commodity function mainly useful in log rotation
|
||||
*/
|
||||
void uwsgi_logfile_write(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
char logpkt[4096];
|
||||
|
||||
struct timeval tv;
|
||||
char ctime_storage[26];
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
#if defined(__sun__) && !defined(__clang__)
|
||||
ctime_r((const time_t *) &tv.tv_sec, ctime_storage, 26);
|
||||
#else
|
||||
ctime_r((const time_t *) &tv.tv_sec, ctime_storage);
|
||||
#endif
|
||||
memcpy(logpkt, ctime_storage, 24);
|
||||
memcpy(logpkt + 24, " - ", 3);
|
||||
|
||||
int rlen = 24 + 3;
|
||||
|
||||
va_start(ap, fmt);
|
||||
rlen += vsnprintf(logpkt + rlen, 4096 - rlen, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
// do not check for errors
|
||||
rlen = write(uwsgi.original_log_fd, logpkt, rlen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void fix_logpipe_buf(int *fd) {
|
||||
int so_bufsize;
|
||||
@@ -211,49 +241,6 @@ void create_logpipe(void) {
|
||||
|
||||
}
|
||||
|
||||
#ifdef UWSGI_ZEROMQ
|
||||
// the zeromq logger
|
||||
ssize_t uwsgi_zeromq_logger(struct uwsgi_logger *ul, char *message, size_t len) {
|
||||
|
||||
if (!ul->configured) {
|
||||
|
||||
if (!ul->arg) {
|
||||
uwsgi_log_safe("invalid zeromq syntax\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *ctx = uwsgi_zeromq_init();
|
||||
|
||||
ul->data = zmq_socket(ctx, ZMQ_PUSH);
|
||||
if (ul->data == NULL) {
|
||||
uwsgi_error_safe("zmq_socket()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (zmq_connect(ul->data, ul->arg) < 0) {
|
||||
uwsgi_error_safe("zmq_connect()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ul->configured = 1;
|
||||
}
|
||||
|
||||
zmq_msg_t msg;
|
||||
if (zmq_msg_init_size(&msg, len) == 0) {
|
||||
memcpy(zmq_msg_data(&msg), message, len);
|
||||
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,0,0)
|
||||
zmq_sendmsg(ul->data, &msg, 0);
|
||||
#else
|
||||
zmq_send(ul->data, &msg, 0);
|
||||
#endif
|
||||
zmq_msg_close(&msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// log to the specified file or udp address
|
||||
void logto(char *logfile) {
|
||||
|
||||
@@ -519,7 +506,6 @@ void uwsgi_check_logrotate(void) {
|
||||
}
|
||||
|
||||
void uwsgi_log_rotate() {
|
||||
char message[1024];
|
||||
if (!uwsgi.logfile) return;
|
||||
char *rot_name = uwsgi.log_backupname;
|
||||
int need_free = 0;
|
||||
@@ -529,24 +515,21 @@ void uwsgi_log_rotate() {
|
||||
free(ts_str);
|
||||
need_free = 1;
|
||||
}
|
||||
int ret = snprintf(message, 1024, "[%d] logsize: %llu, triggering rotation to %s...\n", (int) uwsgi_now(), (unsigned long long) uwsgi.shared->logsize, rot_name);
|
||||
if (ret > 0) {
|
||||
if (write(uwsgi.original_log_fd, message, ret) != ret) {
|
||||
// very probably this will never be printed
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
}
|
||||
// this will be rawly written to the logfile
|
||||
uwsgi_logfile_write("logsize: %llu, triggering rotation to %s...\n", (unsigned long long) uwsgi.shared->logsize, rot_name);
|
||||
if (rename(uwsgi.logfile, rot_name) == 0) {
|
||||
// reopen logfile dup'it and eventually gracefully reload workers;
|
||||
// reopen logfile and dup'it, on dup2 error, exit(1)
|
||||
int fd = open(uwsgi.logfile, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP);
|
||||
if (fd < 0) {
|
||||
// this will be written to the original file
|
||||
uwsgi_error_open(uwsgi.logfile);
|
||||
grace_them_all(0);
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
if (dup2(fd, uwsgi.original_log_fd) < 0) {
|
||||
uwsgi_error("dup2()");
|
||||
grace_them_all(0);
|
||||
// this could be lost :(
|
||||
uwsgi_error("uwsgi_log_rotate()/dup2()");
|
||||
exit(1);
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
@@ -562,7 +545,7 @@ void uwsgi_log_reopen() {
|
||||
char message[1024];
|
||||
if (!uwsgi.logfile) return;
|
||||
int ret = snprintf(message, 1024, "[%d] logsize: %llu, triggering log-reopen...\n", (int) uwsgi_now(), (unsigned long long) uwsgi.shared->logsize);
|
||||
if (ret > 0) {
|
||||
if (ret > 0 && ret < 1024) {
|
||||
if (write(uwsgi.original_log_fd, message, ret) != ret) {
|
||||
// very probably this will never be printed
|
||||
uwsgi_error("write()");
|
||||
@@ -578,7 +561,7 @@ void uwsgi_log_reopen() {
|
||||
return;
|
||||
}
|
||||
ret = snprintf(message, 1024, "[%d] %s reopened.\n", (int) uwsgi_now(), uwsgi.logfile);
|
||||
if (ret > 0) {
|
||||
if (ret > 0 && ret < 1024) {
|
||||
if (write(uwsgi.original_log_fd, message, ret) != ret) {
|
||||
// very probably this will never be printed
|
||||
uwsgi_error("write()");
|
||||
@@ -590,7 +573,7 @@ void uwsgi_log_reopen() {
|
||||
|
||||
void log_request(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int log_it = uwsgi.shared->options[UWSGI_OPTION_LOGGING];
|
||||
int log_it = uwsgi.logging_options.enabled;
|
||||
|
||||
if (wsgi_req->do_not_log)
|
||||
return;
|
||||
@@ -600,22 +583,25 @@ void log_request(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
/* conditional logging */
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_ZERO] && wsgi_req->response_size == 0) {
|
||||
if (uwsgi.logging_options.zero && wsgi_req->response_size == 0) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_SLOW] && (uint32_t) wsgi_req_time >= uwsgi.shared->options[UWSGI_OPTION_LOG_SLOW]) {
|
||||
if (uwsgi.logging_options.slow && (uint32_t) wsgi_req_time >= uwsgi.logging_options.slow) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_4xx] && (wsgi_req->status >= 400 && wsgi_req->status <= 499)) {
|
||||
if (uwsgi.logging_options._4xx && (wsgi_req->status >= 400 && wsgi_req->status <= 499)) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_5xx] && (wsgi_req->status >= 500 && wsgi_req->status <= 599)) {
|
||||
if (uwsgi.logging_options._5xx && (wsgi_req->status >= 500 && wsgi_req->status <= 599)) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_BIG] && (wsgi_req->response_size >= uwsgi.shared->options[UWSGI_OPTION_LOG_BIG])) {
|
||||
if (uwsgi.logging_options.big && (wsgi_req->response_size >= uwsgi.logging_options.big)) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_LOG_SENDFILE] && wsgi_req->via == UWSGI_VIA_SENDFILE) {
|
||||
if (uwsgi.logging_options.sendfile && wsgi_req->via == UWSGI_VIA_SENDFILE) {
|
||||
goto logit;
|
||||
}
|
||||
if (uwsgi.logging_options.ioerror && wsgi_req->read_errors > 0 && wsgi_req->write_errors > 0) {
|
||||
goto logit;
|
||||
}
|
||||
|
||||
@@ -700,7 +686,7 @@ void uwsgi_logit_simple(struct wsgi_request *wsgi_req) {
|
||||
logvecpos++;
|
||||
}
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1) {
|
||||
if (uwsgi.logging_options.memory_report == 1) {
|
||||
rlen = snprintf(mempkt, 4096, "{address space usage: %lld bytes/%lluMB} {rss usage: %llu bytes/%lluMB} ", (unsigned long long) uwsgi.workers[uwsgi.mywid].vsz_size, (unsigned long long) uwsgi.workers[uwsgi.mywid].vsz_size / 1024 / 1024,
|
||||
(unsigned long long) uwsgi.workers[uwsgi.mywid].rss_size, (unsigned long long) uwsgi.workers[uwsgi.mywid].rss_size / 1024 / 1024);
|
||||
logvec[logvecpos].iov_base = mempkt;
|
||||
@@ -981,6 +967,14 @@ void uwsgi_logit_lf(struct wsgi_request *wsgi_req) {
|
||||
uwsgi.logvectors[wsgi_req->async_id][pos].iov_len = 0;
|
||||
}
|
||||
}
|
||||
// var
|
||||
else if (logchunk->type == 5) {
|
||||
uint16_t value_len = 0;
|
||||
char *value = uwsgi_get_var(wsgi_req, logchunk->ptr, logchunk->len, &value_len);
|
||||
// could be NULL
|
||||
uwsgi.logvectors[wsgi_req->async_id][pos].iov_base = value;
|
||||
uwsgi.logvectors[wsgi_req->async_id][pos].iov_len = (size_t) value_len;
|
||||
}
|
||||
// metric
|
||||
else if (logchunk->type == 4) {
|
||||
int64_t metric = uwsgi_metric_get(logchunk->ptr, NULL);
|
||||
@@ -1012,10 +1006,6 @@ void uwsgi_logit_lf(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_logit_lf_strftime(struct wsgi_request *wsgi_req) {
|
||||
uwsgi_log("lf strftime\n");
|
||||
}
|
||||
|
||||
void uwsgi_build_log_format(char *format) {
|
||||
int state = 0;
|
||||
char *ptr = format;
|
||||
@@ -1139,6 +1129,16 @@ static ssize_t uwsgi_lf_ftime(struct wsgi_request * wsgi_req, char **buf) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t uwsgi_lf_tmsecs(struct wsgi_request * wsgi_req, char **buf) {
|
||||
*buf = uwsgi_64bit2str(wsgi_req->start_of_request / (int64_t) 1000);
|
||||
return strlen(*buf);
|
||||
}
|
||||
|
||||
static ssize_t uwsgi_lf_tmicros(struct wsgi_request * wsgi_req, char **buf) {
|
||||
*buf = uwsgi_64bit2str(wsgi_req->start_of_request);
|
||||
return strlen(*buf);
|
||||
}
|
||||
|
||||
static ssize_t uwsgi_lf_micros(struct wsgi_request * wsgi_req, char **buf) {
|
||||
*buf = uwsgi_num2str(wsgi_req->end_of_request - wsgi_req->start_of_request);
|
||||
return strlen(*buf);
|
||||
@@ -1214,6 +1214,54 @@ static ssize_t uwsgi_lf_headers(struct wsgi_request * wsgi_req, char **buf) {
|
||||
return strlen(*buf);
|
||||
}
|
||||
|
||||
static ssize_t uwsgi_lf_werr(struct wsgi_request * wsgi_req, char **buf) {
|
||||
*buf = uwsgi_num2str((int) wsgi_req->write_errors);
|
||||
return strlen(*buf);
|
||||
}
|
||||
|
||||
static ssize_t uwsgi_lf_rerr(struct wsgi_request * wsgi_req, char **buf) {
|
||||
*buf = uwsgi_num2str((int) wsgi_req->read_errors);
|
||||
return strlen(*buf);
|
||||
}
|
||||
|
||||
static ssize_t uwsgi_lf_ioerr(struct wsgi_request * wsgi_req, char **buf) {
|
||||
*buf = uwsgi_num2str((int) (wsgi_req->write_errors + wsgi_req->read_errors));
|
||||
return strlen(*buf);
|
||||
}
|
||||
|
||||
struct uwsgi_logchunk *uwsgi_register_logchunk(char *name, ssize_t (*func)(struct wsgi_request *, char **), int need_free) {
|
||||
struct uwsgi_logchunk *old_logchunk = NULL, *logchunk = uwsgi.registered_logchunks;
|
||||
while(logchunk) {
|
||||
if (!strcmp(logchunk->name, name)) goto found;
|
||||
old_logchunk = logchunk;
|
||||
logchunk = logchunk->next;
|
||||
}
|
||||
logchunk = uwsgi_calloc(sizeof(struct uwsgi_logchunk));
|
||||
logchunk->name = name;
|
||||
if (old_logchunk) {
|
||||
old_logchunk->next = logchunk;
|
||||
}
|
||||
else {
|
||||
uwsgi.registered_logchunks = logchunk;
|
||||
}
|
||||
found:
|
||||
logchunk->func = func;
|
||||
logchunk->free = need_free;
|
||||
logchunk->type = 3;
|
||||
return logchunk;
|
||||
}
|
||||
|
||||
struct uwsgi_logchunk *uwsgi_get_logchunk_by_name(char *name, size_t name_len) {
|
||||
struct uwsgi_logchunk *logchunk = uwsgi.registered_logchunks;
|
||||
while(logchunk) {
|
||||
if (!uwsgi_strncmp(name, name_len, logchunk->name, strlen(logchunk->name))) {
|
||||
return logchunk;
|
||||
}
|
||||
logchunk = logchunk->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void uwsgi_add_logchunk(int variable, int pos, char *ptr, size_t len) {
|
||||
|
||||
struct uwsgi_logchunk *logchunk = uwsgi.logchunks;
|
||||
@@ -1234,11 +1282,12 @@ void uwsgi_add_logchunk(int variable, int pos, char *ptr, size_t len) {
|
||||
}
|
||||
|
||||
/*
|
||||
0 -> raw test
|
||||
0 -> raw text
|
||||
1 -> offsetof variable
|
||||
2 -> logvar
|
||||
3 -> func
|
||||
4 -> metric
|
||||
5 -> request variable
|
||||
*/
|
||||
|
||||
logchunk->type = variable;
|
||||
@@ -1248,163 +1297,26 @@ void uwsgi_add_logchunk(int variable, int pos, char *ptr, size_t len) {
|
||||
logchunk->len = len;
|
||||
// variable
|
||||
if (variable) {
|
||||
if (!uwsgi_strncmp(ptr, len, "uri", 3)) {
|
||||
logchunk->pos = offsetof(struct wsgi_request, uri);
|
||||
logchunk->pos_len = offsetof(struct wsgi_request, uri_len);
|
||||
struct uwsgi_logchunk *rlc = uwsgi_get_logchunk_by_name(ptr, len);
|
||||
if (rlc) {
|
||||
if (rlc->type == 1) {
|
||||
logchunk->pos = rlc->pos;
|
||||
logchunk->pos_len = rlc->pos_len;
|
||||
}
|
||||
else if (rlc->type == 3) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = rlc->func;
|
||||
logchunk->free = rlc->free;
|
||||
}
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "method", 6)) {
|
||||
logchunk->pos = offsetof(struct wsgi_request, method);
|
||||
logchunk->pos_len = offsetof(struct wsgi_request, method_len);
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "user", 4)) {
|
||||
logchunk->pos = offsetof(struct wsgi_request, remote_user);
|
||||
logchunk->pos_len = offsetof(struct wsgi_request, remote_user_len);
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "addr", 4)) {
|
||||
logchunk->pos = offsetof(struct wsgi_request, remote_addr);
|
||||
logchunk->pos_len = offsetof(struct wsgi_request, remote_addr_len);
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "host", 4)) {
|
||||
logchunk->pos = offsetof(struct wsgi_request, host);
|
||||
logchunk->pos_len = offsetof(struct wsgi_request, host_len);
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "proto", 5)) {
|
||||
logchunk->pos = offsetof(struct wsgi_request, protocol);
|
||||
logchunk->pos_len = offsetof(struct wsgi_request, protocol_len);
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "uagent", 6)) {
|
||||
logchunk->pos = offsetof(struct wsgi_request, user_agent);
|
||||
logchunk->pos_len = offsetof(struct wsgi_request, user_agent_len);
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "referer", 7)) {
|
||||
logchunk->pos = offsetof(struct wsgi_request, referer);
|
||||
logchunk->pos_len = offsetof(struct wsgi_request, referer_len);
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "status", 6)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_status;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "rsize", 5)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_rsize;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "hsize", 5)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_hsize;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "size", 4)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_size;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "cl", 2)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_cl;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "micros", 6)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_micros;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "msecs", 5)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_msecs;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "time", 4)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_time;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "ltime", 5)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_ltime;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "ftime", 5)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_ftime;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "ctime", 5)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_ctime;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "epoch", 5)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_epoch;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "pid", 3)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_pid;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "wid", 3)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_wid;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "switches", 8)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_switches;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "vars", 4)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_vars;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "core", 4)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_core;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "vsz", 3)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_vsz;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "rss", 3)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_rss;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "vszM", 4)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_vszM;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "rssM", 4)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_rssM;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "pktsize", 7)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_pktsize;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "modifier1", 9)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_modifier1;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "modifier2", 9)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_modifier2;
|
||||
logchunk->free = 1;
|
||||
}
|
||||
else if (!uwsgi_strncmp(ptr, len, "headers", 7)) {
|
||||
logchunk->type = 3;
|
||||
logchunk->func = uwsgi_lf_headers;
|
||||
logchunk->free = 1;
|
||||
// var
|
||||
else if (!uwsgi_starts_with(ptr, len, "var.", 4)) {
|
||||
logchunk->type = 5;
|
||||
logchunk->ptr = ptr+4;
|
||||
logchunk->len = len-4;
|
||||
logchunk->free = 0;
|
||||
}
|
||||
// metric
|
||||
else if (!uwsgi_starts_with(ptr, len, "metric.", 7)) {
|
||||
logchunk->type = 4;
|
||||
logchunk->ptr = uwsgi_concat2n(ptr+7, len - 7, "", 0);
|
||||
@@ -1980,6 +1892,51 @@ end:
|
||||
return buf;
|
||||
}
|
||||
|
||||
#define r_logchunk(x) uwsgi_register_logchunk(#x, uwsgi_lf_ ## x, 1)
|
||||
#define r_logchunk_offset(x, y) { struct uwsgi_logchunk *lc = uwsgi_register_logchunk(#x, NULL, 0); lc->pos = offsetof(struct wsgi_request, y); lc->pos_len = offsetof(struct wsgi_request, y ## _len); lc->type = 1; lc->free=0;}
|
||||
void uwsgi_register_logchunks() {
|
||||
// offsets
|
||||
r_logchunk_offset(uri, uri);
|
||||
r_logchunk_offset(method, method);
|
||||
r_logchunk_offset(user, remote_user);
|
||||
r_logchunk_offset(addr, remote_addr);
|
||||
r_logchunk_offset(host, host);
|
||||
r_logchunk_offset(proto, protocol);
|
||||
r_logchunk_offset(uagent, user_agent);
|
||||
r_logchunk_offset(referer, referer);
|
||||
|
||||
// funcs
|
||||
r_logchunk(status);
|
||||
r_logchunk(rsize);
|
||||
r_logchunk(hsize);
|
||||
r_logchunk(size);
|
||||
r_logchunk(cl);
|
||||
r_logchunk(micros);
|
||||
r_logchunk(msecs);
|
||||
r_logchunk(tmsecs);
|
||||
r_logchunk(tmicros);
|
||||
r_logchunk(time);
|
||||
r_logchunk(ltime);
|
||||
r_logchunk(ftime);
|
||||
r_logchunk(ctime);
|
||||
r_logchunk(epoch);
|
||||
r_logchunk(pid);
|
||||
r_logchunk(wid);
|
||||
r_logchunk(switches);
|
||||
r_logchunk(vars);
|
||||
r_logchunk(core);
|
||||
r_logchunk(vsz);
|
||||
r_logchunk(rss);
|
||||
r_logchunk(vszM);
|
||||
r_logchunk(rssM);
|
||||
r_logchunk(pktsize);
|
||||
r_logchunk(modifier1);
|
||||
r_logchunk(modifier2);
|
||||
r_logchunk(headers);
|
||||
r_logchunk(werr);
|
||||
r_logchunk(rerr);
|
||||
r_logchunk(ioerr);
|
||||
}
|
||||
|
||||
void uwsgi_log_encoders_register_embedded() {
|
||||
uwsgi_register_log_encoder("prefix", uwsgi_log_encoder_prefix);
|
||||
|
||||
+110
-73
@@ -168,53 +168,34 @@ void expire_rb_timeouts(struct uwsgi_rbtree *tree) {
|
||||
}
|
||||
}
|
||||
|
||||
int uwsgi_get_tcp_info(int fd) {
|
||||
static void get_tcp_info(struct uwsgi_socket *uwsgi_sock) {
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
int fd = uwsgi_sock->fd;
|
||||
struct tcp_info ti;
|
||||
socklen_t tis = sizeof(struct tcp_info);
|
||||
|
||||
if (!getsockopt(fd, IPPROTO_TCP, TCP_INFO, &uwsgi.shared->ti, &tis)) {
|
||||
if (!getsockopt(fd, IPPROTO_TCP, TCP_INFO, &ti, &tis)) {
|
||||
|
||||
// checks for older kernels
|
||||
#if defined(__linux__)
|
||||
if (!uwsgi.shared->ti.tcpi_sacked) {
|
||||
if (!ti.tcpi_sacked) {
|
||||
#elif defined(__FreeBSD__)
|
||||
if (!uwsgi.shared->ti.__tcpi_sacked) {
|
||||
if (!ti.__tcpi_sacked) {
|
||||
#endif
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
uwsgi.shared->load = (uint64_t) uwsgi.shared->ti.tcpi_unacked;
|
||||
uwsgi.shared->max_load = (uint64_t) uwsgi.shared->ti.tcpi_sacked;
|
||||
uwsgi_sock->queue = (uint64_t) ti.tcpi_unacked;
|
||||
uwsgi_sock->max_queue = (uint64_t) ti.tcpi_sacked;
|
||||
#elif defined(__FreeBSD__)
|
||||
uwsgi.shared->load = (uint64_t) uwsgi.shared->ti.__tcpi_unacked;
|
||||
uwsgi.shared->max_load = (uint64_t) uwsgi.shared->ti.__tcpi_sacked;
|
||||
uwsgi_sock->queue = (uint64_t) ti.__tcpi_unacked;
|
||||
uwsgi_sock->max_queue = (uint64_t) ti.__tcpi_sacked;
|
||||
#endif
|
||||
|
||||
uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS] = uwsgi.shared->load;
|
||||
if (uwsgi.vassal_sos_backlog > 0 && uwsgi.has_emperor) {
|
||||
if (uwsgi.shared->load >= (uint64_t) uwsgi.vassal_sos_backlog) {
|
||||
// ask emperor for help
|
||||
char byte = 30;
|
||||
if (write(uwsgi.emperor_fd, &byte, 1) != 1) {
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
else {
|
||||
uwsgi_log("asking emperor for reinforcements (backlog: %llu)...\n", (unsigned long long) uwsgi.shared->load);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (uwsgi.shared->load >= uwsgi.shared->max_load) {
|
||||
uwsgi_log_verbose("*** uWSGI listen queue of socket %d full !!! (%llu/%llu) ***\n", fd, (unsigned long long) uwsgi.shared->load, (unsigned long long) uwsgi.shared->max_load);
|
||||
uwsgi.shared->options[UWSGI_OPTION_BACKLOG_ERRORS]++;
|
||||
}
|
||||
|
||||
return uwsgi.shared->load;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -227,25 +208,61 @@ int uwsgi_get_tcp_info(int fd) {
|
||||
|
||||
#ifdef SIOBKLGQ
|
||||
|
||||
int get_linux_unbit_SIOBKLGQ(int fd) {
|
||||
static void get_linux_unbit_SIOBKLGQ(struct uwsgi_socket *uwsgi_sock) {
|
||||
|
||||
int fd = uwsgi_sock->fd;
|
||||
int queue = 0;
|
||||
if (ioctl(fd, SIOBKLGQ, &queue) >= 0) {
|
||||
uwsgi.shared->load = queue;
|
||||
uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS] = queue;
|
||||
if (queue >= uwsgi.listen_queue) {
|
||||
uwsgi_log_verbose("*** uWSGI listen queue of socket %d full !!! (%d/%d) ***\n", fd, queue, uwsgi.listen_queue);
|
||||
uwsgi.shared->options[UWSGI_OPTION_BACKLOG_ERRORS]++;
|
||||
}
|
||||
return queue;
|
||||
uwsgi_sock->queue = (uint64_t) queue;
|
||||
uwsgi_sock->max_queue = (uint64_t) uwsgi.listen_queue;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static void master_check_listen_queue() {
|
||||
|
||||
uint64_t backlog = 0;
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
while(uwsgi_sock) {
|
||||
if (uwsgi_sock->family == AF_INET) {
|
||||
get_tcp_info(uwsgi_sock);
|
||||
}
|
||||
#ifdef __linux__
|
||||
#ifdef SIOBKLGQ
|
||||
else if (uwsgi_sock->family == AF_UNIX) {
|
||||
get_linux_unbit_SIOBKLGQ(uwsgi_sock);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (uwsgi_sock->queue > backlog) {
|
||||
backlog = uwsgi_sock->queue;
|
||||
}
|
||||
if (uwsgi_sock->queue > 0 && uwsgi_sock->queue >= uwsgi_sock->max_queue) {
|
||||
uwsgi_log_verbose("*** uWSGI listen queue of socket \"%s\" (fd: %d) full !!! (%llu/%llu) ***\n", uwsgi_sock->name, uwsgi_sock->fd, (unsigned long long) uwsgi_sock->queue, (unsigned long long) uwsgi_sock->max_queue);
|
||||
}
|
||||
uwsgi_sock = uwsgi_sock->next;
|
||||
}
|
||||
|
||||
// TODO load should be something more advanced based on different values
|
||||
uwsgi.shared->load = backlog;
|
||||
|
||||
uwsgi.shared->backlog = backlog;
|
||||
|
||||
if (uwsgi.vassal_sos_backlog > 0 && uwsgi.has_emperor) {
|
||||
if (uwsgi.shared->backlog >= (uint64_t) uwsgi.vassal_sos_backlog) {
|
||||
// ask emperor for help
|
||||
char byte = 30;
|
||||
if (write(uwsgi.emperor_fd, &byte, 1) != 1) {
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
else {
|
||||
uwsgi_log_verbose("asking Emperor for reinforcements (backlog: %llu)...\n", (unsigned long long) uwsgi.shared->backlog);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int master_loop(char **argv, char **environ) {
|
||||
|
||||
@@ -358,6 +375,18 @@ int master_loop(char **argv, char **environ) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
if (uwsgi.setns_socket) {
|
||||
uwsgi.setns_socket_fd = bind_to_unix(uwsgi.setns_socket, uwsgi.listen_queue, 0, 0);
|
||||
if (uwsgi.setns_socket_fd < 0) exit(1);
|
||||
if (chmod(uwsgi.setns_socket, S_IRUSR|S_IWUSR)) {
|
||||
uwsgi_error("[setns-socket] chmod()");
|
||||
exit(1);
|
||||
}
|
||||
event_queue_add_fd_read(uwsgi.master_queue, uwsgi.setns_socket_fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (uwsgi.zerg_server) {
|
||||
uwsgi.zerg_server_fd = bind_to_unix(uwsgi.zerg_server, uwsgi.listen_queue, 0, 0);
|
||||
event_queue_add_fd_read(uwsgi.master_queue, uwsgi.zerg_server_fd);
|
||||
@@ -471,6 +500,14 @@ int master_loop(char **argv, char **environ) {
|
||||
usl = usl->next;
|
||||
}
|
||||
uwsgi_check_touches(uwsgi.touch_signal);
|
||||
// daemon touches
|
||||
struct uwsgi_daemon *ud = uwsgi.daemons;
|
||||
while (ud) {
|
||||
if (ud->touch) {
|
||||
uwsgi_check_touches(ud->touch);
|
||||
}
|
||||
ud = ud->next;
|
||||
}
|
||||
|
||||
// fsmon
|
||||
uwsgi_fsmon_setup();
|
||||
@@ -578,10 +615,10 @@ int master_loop(char **argv, char **environ) {
|
||||
if (diedpid == 0) {
|
||||
|
||||
/* all processes ok, doing status scan after N seconds */
|
||||
check_interval = uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
check_interval = uwsgi.master_interval;
|
||||
if (!check_interval) {
|
||||
check_interval = 1;
|
||||
uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL] = 1;
|
||||
uwsgi.master_interval = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -680,43 +717,25 @@ int master_loop(char **argv, char **environ) {
|
||||
// check for idle
|
||||
uwsgi_master_check_idle();
|
||||
|
||||
check_interval = uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
check_interval = uwsgi.master_interval;
|
||||
if (!check_interval) {
|
||||
check_interval = 1;
|
||||
uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL] = 1;
|
||||
uwsgi.master_interval = 1;
|
||||
}
|
||||
|
||||
|
||||
// get listen_queue status
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
int tmp_queue = 0;
|
||||
while (uwsgi_sock) {
|
||||
if (uwsgi_sock->family == AF_INET) {
|
||||
uwsgi_sock->queue = uwsgi_get_tcp_info(uwsgi_sock->fd);
|
||||
}
|
||||
#ifdef __linux__
|
||||
#ifdef SIOBKLGQ
|
||||
else if (uwsgi_sock->family == AF_UNIX) {
|
||||
uwsgi_sock->queue = get_linux_unbit_SIOBKLGQ(uwsgi_sock->fd);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (uwsgi_sock->queue > tmp_queue) {
|
||||
tmp_queue = uwsgi_sock->queue;
|
||||
}
|
||||
uwsgi_sock = uwsgi_sock->next;
|
||||
}
|
||||
// fix queue size on multiple sockets
|
||||
uwsgi.shared->load = tmp_queue;
|
||||
// check listen_queue status
|
||||
master_check_listen_queue();
|
||||
|
||||
int someone_killed = 0;
|
||||
// check if some worker has to die (harakiri, evil checks...)
|
||||
uwsgi_master_check_workers_deadline();
|
||||
if (uwsgi_master_check_workers_deadline()) someone_killed++;
|
||||
if (uwsgi_master_check_gateways_deadline()) someone_killed++;
|
||||
if (uwsgi_master_check_mules_deadline()) someone_killed++;
|
||||
if (uwsgi_master_check_spoolers_deadline()) someone_killed++;
|
||||
if (uwsgi_master_check_crons_deadline()) someone_killed++;
|
||||
|
||||
uwsgi_master_check_gateways_deadline();
|
||||
uwsgi_master_check_mules_deadline();
|
||||
uwsgi_master_check_spoolers_deadline();
|
||||
uwsgi_master_check_crons_deadline();
|
||||
// this could trigger a complete exit...
|
||||
uwsgi_master_check_mountpoints();
|
||||
|
||||
#ifdef __linux__
|
||||
@@ -780,8 +799,26 @@ int master_loop(char **argv, char **environ) {
|
||||
uwsgi_route_signal(signum);
|
||||
uwsgi_log_verbose("[uwsgi-touch-signal] raising %u\n", signum);
|
||||
}
|
||||
|
||||
// daemon touches
|
||||
struct uwsgi_daemon *ud = uwsgi.daemons;
|
||||
while (ud) {
|
||||
if (ud->pid > 0 && ud->touch) {
|
||||
touched = uwsgi_check_touches(ud->touch);
|
||||
if (touched) {
|
||||
uwsgi_log_verbose("*** %s has been touched... reloading daemon \"%s\" (pid: %d) !!! ***\n", touched, ud->command, (int) ud->pid);
|
||||
if (kill(ud->pid, ud->stop_signal)) {
|
||||
uwsgi_error("[uwsgi-daemon/touch] kill()");
|
||||
}
|
||||
}
|
||||
}
|
||||
ud = ud->next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// allows the KILL signal to be delivered;
|
||||
if (someone_killed > 0) sleep(1);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
+32
-9
@@ -48,6 +48,8 @@ void uwsgi_master_check_chain() {
|
||||
}
|
||||
uwsgi_block_signal(SIGHUP);
|
||||
for(i=1;i<=uwsgi.numproc;i++) {
|
||||
// do not curse a worker until the old one is ready
|
||||
if (uwsgi.workers[i].accepting == 0) break;
|
||||
if (uwsgi.workers[i].pid > 0 && uwsgi.workers[i].cheaped == 0 && uwsgi.workers[i].cursed_at == 0 && i == uwsgi.status.chain_reloading) {
|
||||
uwsgi_curse(i, SIGHUP);
|
||||
break;
|
||||
@@ -120,6 +122,8 @@ void uwsgi_master_check_idle() {
|
||||
}
|
||||
else {
|
||||
uwsgi.workers[i].pid = 0;
|
||||
uwsgi.workers[i].rss_size = 0;
|
||||
uwsgi.workers[i].vsz_size = 0;
|
||||
}
|
||||
}
|
||||
uwsgi_add_sockets_to_queue(uwsgi.master_queue, -1);
|
||||
@@ -129,19 +133,22 @@ void uwsgi_master_check_idle() {
|
||||
|
||||
}
|
||||
|
||||
void uwsgi_master_check_workers_deadline() {
|
||||
int uwsgi_master_check_workers_deadline() {
|
||||
int i;
|
||||
int ret = 0;
|
||||
for (i = 1; i <= uwsgi.numproc; i++) {
|
||||
/* first check for harakiri */
|
||||
if (uwsgi.workers[i].harakiri > 0) {
|
||||
if (uwsgi.workers[i].harakiri < (time_t) uwsgi.current_time) {
|
||||
trigger_harakiri(i);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
/* then user-defined harakiri */
|
||||
if (uwsgi.workers[i].user_harakiri > 0) {
|
||||
if (uwsgi.workers[i].user_harakiri < (time_t) uwsgi.current_time) {
|
||||
trigger_harakiri(i);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
// then for evil memory checkers
|
||||
@@ -150,6 +157,7 @@ void uwsgi_master_check_workers_deadline() {
|
||||
uwsgi_log("*** EVIL RELOAD ON WORKER %d ADDRESS SPACE: %lld (pid: %d) ***\n", i, (long long) uwsgi.workers[i].vsz_size, uwsgi.workers[i].pid);
|
||||
kill(uwsgi.workers[i].pid, SIGKILL);
|
||||
uwsgi.workers[i].vsz_size = 0;
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
if (uwsgi.evil_reload_on_rss) {
|
||||
@@ -157,15 +165,17 @@ void uwsgi_master_check_workers_deadline() {
|
||||
uwsgi_log("*** EVIL RELOAD ON WORKER %d RSS: %lld (pid: %d) ***\n", i, (long long) uwsgi.workers[i].rss_size, uwsgi.workers[i].pid);
|
||||
kill(uwsgi.workers[i].pid, SIGKILL);
|
||||
uwsgi.workers[i].rss_size = 0;
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
// check if worker was running longer than allowed lifetime
|
||||
if (uwsgi.workers[i].pid > 0 && uwsgi.workers[i].cheaped == 0 && uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME] > 0) {
|
||||
if (uwsgi.workers[i].pid > 0 && uwsgi.workers[i].cheaped == 0 && uwsgi.max_worker_lifetime > 0) {
|
||||
uint64_t lifetime = uwsgi_now() - uwsgi.workers[i].last_spawn;
|
||||
if (lifetime > uwsgi.shared->options[UWSGI_OPTION_MAX_WORKER_LIFETIME] && uwsgi.workers[i].manage_next_request == 1) {
|
||||
if (lifetime > uwsgi.max_worker_lifetime && uwsgi.workers[i].manage_next_request == 1) {
|
||||
uwsgi_log("worker %d lifetime reached, it was running for %llu second(s)\n", i, (unsigned long long) lifetime);
|
||||
uwsgi.workers[i].manage_next_request = 0;
|
||||
kill(uwsgi.workers[i].pid, SIGWINCH);
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,29 +184,32 @@ void uwsgi_master_check_workers_deadline() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void uwsgi_master_check_gateways_deadline() {
|
||||
int uwsgi_master_check_gateways_deadline() {
|
||||
|
||||
int i;
|
||||
|
||||
int ret = 0;
|
||||
for (i = 0; i < ushared->gateways_cnt; i++) {
|
||||
if (ushared->gateways_harakiri[i] > 0) {
|
||||
if (ushared->gateways_harakiri[i] < (time_t) uwsgi.current_time) {
|
||||
if (ushared->gateways[i].pid > 0) {
|
||||
uwsgi_log("*** HARAKIRI ON GATEWAY %s %d (pid: %d) ***\n", ushared->gateways[i].name, ushared->gateways[i].num, ushared->gateways[i].pid);
|
||||
kill(ushared->gateways[i].pid, SIGKILL);
|
||||
ret = 1;
|
||||
}
|
||||
ushared->gateways_harakiri[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void uwsgi_master_check_mules_deadline() {
|
||||
int uwsgi_master_check_mules_deadline() {
|
||||
int i;
|
||||
int ret = 0;
|
||||
|
||||
for (i = 0; i < uwsgi.mules_cnt; i++) {
|
||||
if (uwsgi.mules[i].harakiri > 0) {
|
||||
@@ -204,6 +217,7 @@ void uwsgi_master_check_mules_deadline() {
|
||||
uwsgi_log("*** HARAKIRI ON MULE %d HANDLING SIGNAL %d (pid: %d) ***\n", i + 1, uwsgi.mules[i].signum, uwsgi.mules[i].pid);
|
||||
kill(uwsgi.mules[i].pid, SIGKILL);
|
||||
uwsgi.mules[i].harakiri = 0;
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
// user harakiri
|
||||
@@ -212,26 +226,32 @@ void uwsgi_master_check_mules_deadline() {
|
||||
uwsgi_log("*** HARAKIRI ON MULE %d (pid: %d) ***\n", i + 1, uwsgi.mules[i].pid);
|
||||
kill(uwsgi.mules[i].pid, SIGKILL);
|
||||
uwsgi.mules[i].user_harakiri = 0;
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void uwsgi_master_check_spoolers_deadline() {
|
||||
int uwsgi_master_check_spoolers_deadline() {
|
||||
int ret = 0;
|
||||
struct uwsgi_spooler *uspool = uwsgi.spoolers;
|
||||
while (uspool) {
|
||||
if (uspool->harakiri > 0 && uspool->harakiri < (time_t) uwsgi.current_time) {
|
||||
uwsgi_log("*** HARAKIRI ON THE SPOOLER (pid: %d) ***\n", uspool->pid);
|
||||
kill(uspool->pid, SIGKILL);
|
||||
uspool->harakiri = 0;
|
||||
ret = 1;
|
||||
}
|
||||
if (uspool->user_harakiri > 0 && uspool->user_harakiri < (time_t) uwsgi.current_time) {
|
||||
uwsgi_log("*** HARAKIRI ON THE SPOOLER (pid: %d) ***\n", uspool->pid);
|
||||
kill(uspool->pid, SIGKILL);
|
||||
uspool->user_harakiri = 0;
|
||||
ret = 1;
|
||||
}
|
||||
uspool = uspool->next;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -314,15 +334,18 @@ int uwsgi_master_check_cron_death(int diedpid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uwsgi_master_check_crons_deadline() {
|
||||
int uwsgi_master_check_crons_deadline() {
|
||||
int ret = 0;
|
||||
struct uwsgi_cron *uc = uwsgi.crons;
|
||||
while (uc) {
|
||||
if (uc->pid >= 0 && uc->harakiri > 0 && uc->harakiri < (time_t) uwsgi.current_time) {
|
||||
uwsgi_log("*** HARAKIRI ON CRON \"%s\" (pid: %d) ***\n", uc->command, uc->pid);
|
||||
kill(-uc->pid, SIGKILL);
|
||||
ret = 1;
|
||||
}
|
||||
uc = uc->next;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void uwsgi_master_check_mountpoints() {
|
||||
|
||||
@@ -51,6 +51,12 @@ int uwsgi_master_manage_events(int interesting_fd) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
if (uwsgi.setns_socket && uwsgi.setns_socket_fd > -1 && interesting_fd == uwsgi.setns_socket_fd) {
|
||||
uwsgi_master_manage_setns(uwsgi.setns_socket_fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (uwsgi_fsmon_event(interesting_fd)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
+188
-13
@@ -101,7 +101,7 @@ int uwsgi_calc_cheaper(void) {
|
||||
|
||||
int i;
|
||||
static time_t last_check = 0;
|
||||
int check_interval = uwsgi.shared->options[UWSGI_OPTION_MASTER_INTERVAL];
|
||||
int check_interval = uwsgi.master_interval;
|
||||
|
||||
if (!last_check)
|
||||
last_check = uwsgi_now();
|
||||
@@ -186,6 +186,8 @@ int uwsgi_calc_cheaper(void) {
|
||||
uwsgi_log("worker %d should die...\n", oldest_worker);
|
||||
#endif
|
||||
uwsgi.workers[oldest_worker].cheaped = 1;
|
||||
uwsgi.workers[oldest_worker].rss_size = 0;
|
||||
uwsgi.workers[oldest_worker].vsz_size = 0;
|
||||
uwsgi.workers[oldest_worker].manage_next_request = 0;
|
||||
uwsgi_curse(oldest_worker, SIGWINCH);
|
||||
}
|
||||
@@ -330,7 +332,7 @@ int uwsgi_cheaper_algo_backlog(int can_spawn) {
|
||||
|
||||
int i;
|
||||
#ifdef __linux__
|
||||
int backlog = uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS];
|
||||
int backlog = uwsgi.shared->backlog;
|
||||
#else
|
||||
int backlog = 0;
|
||||
#endif
|
||||
@@ -383,14 +385,14 @@ void uwsgi_reload(char **argv) {
|
||||
// call master cleanup hooks
|
||||
uwsgi_master_cleanup_hooks();
|
||||
|
||||
// call atexit user exec
|
||||
uwsgi_exec_atexit();
|
||||
|
||||
if (uwsgi.exit_on_reload) {
|
||||
uwsgi_log("uWSGI: GAME OVER (insert coin)\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// call atexit user exec
|
||||
uwsgi_exec_atexit();
|
||||
|
||||
uwsgi_log("binary reloading uWSGI...\n");
|
||||
}
|
||||
else {
|
||||
@@ -584,6 +586,19 @@ void uwsgi_fixup_fds(int wid, int muleid, struct uwsgi_gateway *ug) {
|
||||
}
|
||||
|
||||
if (uwsgi.master_fifo_fd > -1) close(uwsgi.master_fifo_fd);
|
||||
|
||||
#ifdef __linux__
|
||||
for(i=0;i<uwsgi.setns_fds_count;i++) {
|
||||
close(uwsgi.setns_fds[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
// fd alarms
|
||||
struct uwsgi_alarm_fd *uafd = uwsgi.alarm_fds;
|
||||
while(uafd) {
|
||||
close(uafd->fd);
|
||||
uafd = uafd->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -592,6 +607,8 @@ void uwsgi_fixup_fds(int wid, int muleid, struct uwsgi_gateway *ug) {
|
||||
int uwsgi_respawn_worker(int wid) {
|
||||
|
||||
int respawns = uwsgi.workers[wid].respawn_count;
|
||||
// the workers is not accepting (obviously)
|
||||
uwsgi.workers[wid].accepting = 0;
|
||||
// we count the respawns before errors...
|
||||
uwsgi.workers[wid].respawn_count++;
|
||||
// ... same for update time
|
||||
@@ -711,9 +728,9 @@ struct uwsgi_stats *uwsgi_master_generate_stats() {
|
||||
goto end;
|
||||
|
||||
#ifdef __linux__
|
||||
if (uwsgi_stats_keylong_comma(us, "listen_queue", (unsigned long long) uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS]))
|
||||
if (uwsgi_stats_keylong_comma(us, "listen_queue", (unsigned long long) uwsgi.shared->backlog))
|
||||
goto end;
|
||||
if (uwsgi_stats_keylong_comma(us, "listen_queue_errors", (unsigned long long) uwsgi.shared->options[UWSGI_OPTION_BACKLOG_ERRORS]))
|
||||
if (uwsgi_stats_keylong_comma(us, "listen_queue_errors", (unsigned long long) uwsgi.shared->backlog_errors))
|
||||
goto end;
|
||||
#endif
|
||||
|
||||
@@ -955,6 +972,9 @@ struct uwsgi_stats *uwsgi_master_generate_stats() {
|
||||
if (uwsgi_stats_keylong_comma(us, "queue", (unsigned long long) uwsgi_sock->queue))
|
||||
goto end;
|
||||
|
||||
if (uwsgi_stats_keylong_comma(us, "max_queue", (unsigned long long) uwsgi_sock->max_queue))
|
||||
goto end;
|
||||
|
||||
if (uwsgi_stats_keylong_comma(us, "shared", (unsigned long long) uwsgi_sock->shared))
|
||||
goto end;
|
||||
|
||||
@@ -990,6 +1010,8 @@ struct uwsgi_stats *uwsgi_master_generate_stats() {
|
||||
goto end;
|
||||
if (uwsgi_stats_keylong_comma(us, "pid", (unsigned long long) uwsgi.workers[i + 1].pid))
|
||||
goto end;
|
||||
if (uwsgi_stats_keylong_comma(us, "accepting", (unsigned long long) uwsgi.workers[i + 1].accepting))
|
||||
goto end;
|
||||
if (uwsgi_stats_keylong_comma(us, "requests", (unsigned long long) uwsgi.workers[i + 1].requests))
|
||||
goto end;
|
||||
if (uwsgi_stats_keylong_comma(us, "delta_requests", (unsigned long long) uwsgi.workers[i + 1].delta_requests))
|
||||
@@ -1076,7 +1098,7 @@ struct uwsgi_stats *uwsgi_master_generate_stats() {
|
||||
if (uwsgi_stats_keylong_comma(us, "exceptions", ua->exceptions))
|
||||
goto end;
|
||||
|
||||
if (ua->chdir) {
|
||||
if (*ua->chdir) {
|
||||
if (uwsgi_stats_keyval(us, "chdir", ua->chdir))
|
||||
goto end;
|
||||
}
|
||||
@@ -1129,6 +1151,9 @@ struct uwsgi_stats *uwsgi_master_generate_stats() {
|
||||
if (uwsgi_stats_keylong_comma(us, "write_errors", (unsigned long long) uc->write_errors))
|
||||
goto end;
|
||||
|
||||
if (uwsgi_stats_keylong_comma(us, "read_errors", (unsigned long long) uc->read_errors))
|
||||
goto end;
|
||||
|
||||
if (uwsgi_stats_keylong_comma(us, "in_request", (unsigned long long) uc->in_request))
|
||||
goto end;
|
||||
|
||||
@@ -1446,7 +1471,7 @@ void uwsgi_register_cheaper_algo(char *name, int (*func) (int)) {
|
||||
|
||||
void trigger_harakiri(int i) {
|
||||
int j;
|
||||
uwsgi_log("*** HARAKIRI ON WORKER %d (pid: %d, try: %d) ***\n", i, uwsgi.workers[i].pid, uwsgi.workers[i].pending_harakiri + 1);
|
||||
uwsgi_log_verbose("*** HARAKIRI ON WORKER %d (pid: %d, try: %d) ***\n", i, uwsgi.workers[i].pid, uwsgi.workers[i].pending_harakiri + 1);
|
||||
if (uwsgi.harakiri_verbose) {
|
||||
#ifdef __linux__
|
||||
int proc_file;
|
||||
@@ -1494,15 +1519,12 @@ void trigger_harakiri(int i) {
|
||||
}
|
||||
}
|
||||
|
||||
kill(uwsgi.workers[i].pid, SIGUSR2);
|
||||
// allow SIGUSR2 to be delivered
|
||||
sleep(1);
|
||||
uwsgi_dump_worker(i, "HARAKIRI");
|
||||
kill(uwsgi.workers[i].pid, SIGKILL);
|
||||
if (!uwsgi.workers[i].pending_harakiri)
|
||||
uwsgi.workers[i].harakiri_count++;
|
||||
uwsgi.workers[i].pending_harakiri++;
|
||||
}
|
||||
// to avoid races
|
||||
|
||||
}
|
||||
|
||||
@@ -1642,6 +1664,8 @@ void uwsgi_go_cheap() {
|
||||
uwsgi.status.is_cheap = 1;
|
||||
for (i = 1; i <= uwsgi.numproc; i++) {
|
||||
uwsgi.workers[i].cheaped = 1;
|
||||
uwsgi.workers[i].rss_size = 0;
|
||||
uwsgi.workers[i].vsz_size = 0;
|
||||
if (uwsgi.workers[i].pid == 0)
|
||||
continue;
|
||||
uwsgi_log("killing worker %d (pid: %d)\n", i, (int) uwsgi.workers[i].pid);
|
||||
@@ -1654,3 +1678,154 @@ void uwsgi_go_cheap() {
|
||||
uwsgi_add_sockets_to_queue(uwsgi.master_queue, -1);
|
||||
uwsgi_log("cheap mode enabled: waiting for socket connection...\n");
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
void uwsgi_setns_preopen() {
|
||||
struct dirent *de;
|
||||
DIR *ns = opendir("/proc/self/ns");
|
||||
if (!ns) {
|
||||
uwsgi_error("uwsgi_setns_preopen()/opendir()");
|
||||
exit(1);
|
||||
}
|
||||
while ((de = readdir(ns)) != NULL) {
|
||||
if (strlen(de->d_name) > 0 && de->d_name[0] == '.') continue;
|
||||
struct uwsgi_string_list *usl = NULL;
|
||||
int found = 0;
|
||||
uwsgi_foreach(usl, uwsgi.setns_socket_skip) {
|
||||
if (!strcmp(de->d_name, usl->value)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) continue;
|
||||
char *filename = uwsgi_concat2("/proc/self/ns/", de->d_name);
|
||||
uwsgi.setns_fds[uwsgi.setns_fds_count] = open(filename, O_RDONLY);
|
||||
if (uwsgi.setns_fds[uwsgi.setns_fds_count] < 0) {
|
||||
uwsgi_error_open(filename);
|
||||
free(filename);
|
||||
exit(1);
|
||||
}
|
||||
free(filename);
|
||||
uwsgi.setns_fds_count++;
|
||||
}
|
||||
closedir(ns);
|
||||
}
|
||||
void uwsgi_master_manage_setns(int fd) {
|
||||
|
||||
struct sockaddr_un snsun;
|
||||
socklen_t snsun_len = sizeof(struct sockaddr_un);
|
||||
|
||||
int setns_client = accept(fd, (struct sockaddr *) &snsun, &snsun_len);
|
||||
if (setns_client < 0) {
|
||||
uwsgi_error("uwsgi_master_manage_setns()/accept()");
|
||||
return;
|
||||
}
|
||||
|
||||
int i;
|
||||
int tmp_fds[64];
|
||||
int *fds = tmp_fds;
|
||||
int num_fds = 0;
|
||||
|
||||
struct msghdr sn_msg;
|
||||
void *sn_msg_control;
|
||||
struct iovec sn_iov[2];
|
||||
struct cmsghdr *cmsg;
|
||||
DIR *ns = NULL;
|
||||
|
||||
if (uwsgi.setns_fds_count) {
|
||||
fds = uwsgi.setns_fds;
|
||||
num_fds = uwsgi.setns_fds_count;
|
||||
goto send;
|
||||
}
|
||||
|
||||
struct dirent *de;
|
||||
ns = opendir("/proc/self/ns");
|
||||
if (!ns) {
|
||||
close(setns_client);
|
||||
uwsgi_error("uwsgi_master_manage_setns()/opendir()");
|
||||
return;
|
||||
}
|
||||
while ((de = readdir(ns)) != NULL) {
|
||||
if (strlen(de->d_name) > 0 && de->d_name[0] == '.') continue;
|
||||
struct uwsgi_string_list *usl = NULL;
|
||||
int found = 0;
|
||||
uwsgi_foreach(usl, uwsgi.setns_socket_skip) {
|
||||
if (!strcmp(de->d_name, usl->value)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) continue;
|
||||
char *filename = uwsgi_concat2("/proc/self/ns/", de->d_name);
|
||||
fds[num_fds] = open(filename, O_RDONLY);
|
||||
if (fds[num_fds] < 0) {
|
||||
uwsgi_error_open(filename);
|
||||
free(filename);
|
||||
goto clear;
|
||||
}
|
||||
free(filename);
|
||||
num_fds++;
|
||||
}
|
||||
|
||||
send:
|
||||
|
||||
sn_msg_control = uwsgi_malloc(CMSG_SPACE(sizeof(int) * num_fds));
|
||||
|
||||
sn_iov[0].iov_base = "uwsgi-setns";
|
||||
sn_iov[0].iov_len = 11;
|
||||
sn_iov[1].iov_base = &num_fds;
|
||||
sn_iov[1].iov_len = sizeof(int);
|
||||
|
||||
sn_msg.msg_name = NULL;
|
||||
sn_msg.msg_namelen = 0;
|
||||
|
||||
sn_msg.msg_iov = sn_iov;
|
||||
sn_msg.msg_iovlen = 2;
|
||||
|
||||
sn_msg.msg_flags = 0;
|
||||
sn_msg.msg_control = sn_msg_control;
|
||||
sn_msg.msg_controllen = CMSG_SPACE(sizeof(int) * num_fds);
|
||||
|
||||
cmsg = CMSG_FIRSTHDR(&sn_msg);
|
||||
cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds);
|
||||
cmsg->cmsg_level = SOL_SOCKET;
|
||||
cmsg->cmsg_type = SCM_RIGHTS;
|
||||
|
||||
int *sn_fd_ptr = (int *) CMSG_DATA(cmsg);
|
||||
for(i=0;i<num_fds;i++) {
|
||||
sn_fd_ptr[i] = fds[i];
|
||||
}
|
||||
|
||||
if (sendmsg(setns_client, &sn_msg, 0) < 0) {
|
||||
uwsgi_error("uwsgi_master_manage_setns()/sendmsg()");
|
||||
}
|
||||
|
||||
free(sn_msg_control);
|
||||
|
||||
clear:
|
||||
close(setns_client);
|
||||
if (ns) {
|
||||
closedir(ns);
|
||||
for(i=0;i<num_fds;i++) {
|
||||
close(fds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
this is racey, but the worst thing would be printing garbage in the logs...
|
||||
*/
|
||||
void uwsgi_dump_worker(int wid, char *msg) {
|
||||
int i;
|
||||
uwsgi_log_verbose("%s !!! worker %d status !!!\n", msg, wid);
|
||||
for(i=0;i<uwsgi.cores;i++) {
|
||||
struct uwsgi_core *uc = &uwsgi.workers[wid].cores[i];
|
||||
struct wsgi_request *wsgi_req = &uc->req;
|
||||
if (uc->in_request) {
|
||||
uwsgi_log_verbose("%s [core %d] %.*s - %.*s %.*s since %llu\n", msg, i, wsgi_req->remote_addr_len, wsgi_req->remote_addr, wsgi_req->method_len, wsgi_req->method, wsgi_req->uri_len, wsgi_req->uri, (unsigned long long) (wsgi_req->start_of_request/(1000*1000)));
|
||||
}
|
||||
}
|
||||
uwsgi_log_verbose("%s !!! end of worker %d status !!!\n",msg, wid);
|
||||
}
|
||||
|
||||
+20
-9
@@ -465,7 +465,7 @@ static void *uwsgi_metrics_loop(void *arg) {
|
||||
if (uwsgi.metrics_dir && metric->map) {
|
||||
if (value != new_value) {
|
||||
int ret = snprintf(metric->map, uwsgi.page_size, "%lld\n", (long long) new_value);
|
||||
if (ret > 0) {
|
||||
if (ret > 0 && ret < uwsgi.page_size) {
|
||||
memset(metric->map+ret, 0, 4096-ret);
|
||||
}
|
||||
}
|
||||
@@ -694,11 +694,11 @@ int64_t uwsgi_metric_getn(char *name, size_t nlen, char *oid, size_t olen) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define uwsgi_metric_name(f, n) if (snprintf(buf, 4096, f, n) <= 1) { uwsgi_log("unable to register metric name %s\n", f); exit(1);}
|
||||
#define uwsgi_metric_name2(f, n, n2) if (snprintf(buf, 4096, f, n, n2) <= 1) { uwsgi_log("unable to register metric name %s\n", f); exit(1);}
|
||||
#define uwsgi_metric_name(f, n) ret = snprintf(buf, 4096, f, n); if (ret <= 1 || ret >= 4096) { uwsgi_log("unable to register metric name %s\n", f); exit(1);}
|
||||
#define uwsgi_metric_name2(f, n, n2) ret = snprintf(buf, 4096, f, n, n2); if (ret <= 1 || ret >= 4096) { uwsgi_log("unable to register metric name %s\n", f); exit(1);}
|
||||
|
||||
#define uwsgi_metric_oid(f, n) if (snprintf(buf2, 4096, f, n) <= 1) { uwsgi_log("unable to register metric oid %s\n", f); exit(1);}
|
||||
#define uwsgi_metric_oid2(f, n, n2) if (snprintf(buf2, 4096, f, n, n2) <= 1) { uwsgi_log("unable to register metric oid %s\n", f); exit(1);}
|
||||
#define uwsgi_metric_oid(f, n) ret = snprintf(buf2, 4096, f, n); if (ret <= 1 || ret >= 4096) { uwsgi_log("unable to register metric oid %s\n", f); exit(1);}
|
||||
#define uwsgi_metric_oid2(f, n, n2) ret = snprintf(buf2, 4096, f, n, n2); if (ret <= 1 || ret >= 4096) { uwsgi_log("unable to register metric oid %s\n", f); exit(1);}
|
||||
|
||||
void uwsgi_setup_metrics() {
|
||||
|
||||
@@ -732,6 +732,9 @@ void uwsgi_setup_metrics() {
|
||||
struct uwsgi_metric *total_tx = uwsgi_register_metric_do("core.total_tx", "5.100", UWSGI_METRIC_COUNTER, "sum", NULL, 0, NULL, 1);
|
||||
struct uwsgi_metric *total_rss = uwsgi_register_metric_do("core.total_rss", "5.101", UWSGI_METRIC_GAUGE, "sum", NULL, 0, NULL, 1);
|
||||
struct uwsgi_metric *total_vsz = uwsgi_register_metric_do("core.total_vsz", "5.102", UWSGI_METRIC_GAUGE, "sum", NULL, 0, NULL, 1);
|
||||
struct uwsgi_metric *total_avg_rt = uwsgi_register_metric_do("core.avg_response_time", "5.103", UWSGI_METRIC_GAUGE, "avg", NULL, 0, NULL, 1);
|
||||
|
||||
int ret;
|
||||
|
||||
// create the 'worker' namespace
|
||||
int i;
|
||||
@@ -750,19 +753,23 @@ void uwsgi_setup_metrics() {
|
||||
uwsgi_register_metric(buf, buf2, UWSGI_METRIC_COUNTER, "ptr", &uwsgi.workers[i].respawn_count, 0, NULL);
|
||||
|
||||
uwsgi_metric_name("worker.%d.avg_response_time", i) ; uwsgi_metric_oid("3.%d.8", i);
|
||||
uwsgi_register_metric(buf, buf2, UWSGI_METRIC_GAUGE, "ptr", &uwsgi.workers[i].avg_response_time, 0, NULL);
|
||||
struct uwsgi_metric *avg_rt = uwsgi_register_metric(buf, buf2, UWSGI_METRIC_GAUGE, "ptr", &uwsgi.workers[i].avg_response_time, 0, NULL);
|
||||
if (i > 0) uwsgi_metric_add_child(total_avg_rt, avg_rt);
|
||||
|
||||
uwsgi_metric_name("worker.%d.total_tx", i) ; uwsgi_metric_oid("3.%d.9", i);
|
||||
struct uwsgi_metric *tx = uwsgi_register_metric(buf, buf2, UWSGI_METRIC_COUNTER, "ptr", &uwsgi.workers[i].tx, 0, NULL);
|
||||
uwsgi_metric_add_child(total_tx, tx);
|
||||
if (i > 0) uwsgi_metric_add_child(total_tx, tx);
|
||||
|
||||
uwsgi_metric_name("worker.%d.rss_size", i) ; uwsgi_metric_oid("3.%d.11", i);
|
||||
struct uwsgi_metric *rss = uwsgi_register_metric(buf, buf2, UWSGI_METRIC_GAUGE, "ptr", &uwsgi.workers[i].rss_size, 0, NULL);
|
||||
uwsgi_metric_add_child(total_rss, rss);
|
||||
if (i > 0) uwsgi_metric_add_child(total_rss, rss);
|
||||
|
||||
uwsgi_metric_name("worker.%d.vsz_size", i) ; uwsgi_metric_oid("3.%d.12", i);
|
||||
struct uwsgi_metric *vsz = uwsgi_register_metric(buf, buf2, UWSGI_METRIC_GAUGE, "ptr", &uwsgi.workers[i].vsz_size, 0, NULL);
|
||||
uwsgi_metric_add_child(total_vsz, vsz);
|
||||
if (i > 0) uwsgi_metric_add_child(total_vsz, vsz);
|
||||
|
||||
// skip core metrics for core 0
|
||||
if (i == 0) continue;
|
||||
|
||||
int j;
|
||||
for(j=0;j<uwsgi.cores;j++) {
|
||||
@@ -784,6 +791,9 @@ void uwsgi_setup_metrics() {
|
||||
uwsgi_metric_name2("worker.%d.core.%d.exceptions", i, j) ; uwsgi_metric_oid2("3.%d.2.%d.7", i, j);
|
||||
uwsgi_register_metric(buf, buf2, UWSGI_METRIC_COUNTER, "ptr", &uwsgi.workers[i].cores[j].exceptions, 0, NULL);
|
||||
|
||||
uwsgi_metric_name2("worker.%d.core.%d.read_errors", i, j) ; uwsgi_metric_oid2("3.%d.2.%d.8", i, j);
|
||||
uwsgi_register_metric(buf, buf2, UWSGI_METRIC_COUNTER, "ptr", &uwsgi.workers[i].cores[j].read_errors, 0, NULL);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -791,6 +801,7 @@ void uwsgi_setup_metrics() {
|
||||
uwsgi_metric_append(total_tx);
|
||||
uwsgi_metric_append(total_rss);
|
||||
uwsgi_metric_append(total_vsz);
|
||||
uwsgi_metric_append(total_avg_rt);
|
||||
|
||||
// sockets
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
|
||||
+11
-3
@@ -54,6 +54,9 @@ static struct uwsgi_mount_flag umflags[] = {
|
||||
#ifdef MS_REMOUNT
|
||||
{"remount", MS_REMOUNT},
|
||||
#endif
|
||||
#ifdef MS_NOSUID
|
||||
{"nosuid", MS_NOSUID},
|
||||
#endif
|
||||
#ifdef MS_SYNCHRONOUS
|
||||
{"sync", MS_SYNCHRONOUS},
|
||||
#endif
|
||||
@@ -102,7 +105,7 @@ uint64_t uwsgi_mount_flag(char *mflag) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_mount(char *fs, char *what, char *where, char *flags) {
|
||||
int uwsgi_mount(char *fs, char *what, char *where, char *flags, char *data) {
|
||||
#if defined(__FreeBSD__) || defined(__GNU_kFreeBSD__)
|
||||
struct iovec iov[6];
|
||||
#endif
|
||||
@@ -121,7 +124,7 @@ int uwsgi_mount(char *fs, char *what, char *where, char *flags) {
|
||||
free(mflags);
|
||||
parsed:
|
||||
#ifdef __linux__
|
||||
return mount(what, where, fs, mountflags, NULL);
|
||||
return mount(what, where, fs, mountflags, data);
|
||||
#elif defined(__FreeBSD__) || defined(__GNU_kFreeBSD__)
|
||||
iov[0].iov_base = "fstype";
|
||||
iov[0].iov_len = 7;
|
||||
@@ -197,6 +200,7 @@ unmountable:
|
||||
}
|
||||
|
||||
int uwsgi_mount_hook(char *arg) {
|
||||
char *data = NULL;
|
||||
char *tmp_arg = uwsgi_str(arg);
|
||||
char *fs = tmp_arg;
|
||||
char *what = strchr(fs, ' ');
|
||||
@@ -208,8 +212,12 @@ int uwsgi_mount_hook(char *arg) {
|
||||
char *flags = strchr(where, ' ');
|
||||
if (flags) {
|
||||
*flags = 0; flags++;
|
||||
data = strchr(flags, ' ');
|
||||
if (data) {
|
||||
*data = 0; data++;
|
||||
}
|
||||
}
|
||||
if (uwsgi_mount(fs, what, where, flags)) {
|
||||
if (uwsgi_mount(fs, what, where, flags, data)) {
|
||||
uwsgi_error("uwsgi_mount()");
|
||||
free(tmp_arg);
|
||||
return -1;
|
||||
|
||||
@@ -77,6 +77,7 @@ void uwsgi_mule(int id) {
|
||||
}
|
||||
}
|
||||
|
||||
uwsgi_hooks_run(uwsgi.hook_as_mule, "as-mule", 1);
|
||||
uwsgi_mule_run();
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#include "uwsgi.h"
|
||||
#include <uwsgi.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
#include <uwsgi.h>
|
||||
|
||||
#define UWSGI_BUILD_DIR ".uwsgi_plugins_builder"
|
||||
|
||||
/*
|
||||
|
||||
steps:
|
||||
|
||||
mkdir(.uwsgi_plugin_builder)
|
||||
generate .uwsgi_plugin_builder/uwsgi.h
|
||||
generate .uwsgi_plugin_builder/uwsgiconfig.py
|
||||
setenv(UWSGI_PLUGINS_BUILDER_CFLAGS=uwsgi_cflags)
|
||||
exec PYTHON .uwsgi_plugin_builder/uwsgiconfig.py --extra-plugin <directory> [name]
|
||||
|
||||
*/
|
||||
|
||||
void uwsgi_build_plugin(char *directory) {
|
||||
|
||||
if (!uwsgi_file_exists(UWSGI_BUILD_DIR)) {
|
||||
if (mkdir(UWSGI_BUILD_DIR, S_IRWXU) < 0) {
|
||||
uwsgi_error("uwsgi_build_plugin()/mkdir() " UWSGI_BUILD_DIR "/");
|
||||
_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
char *dot_h = uwsgi_get_dot_h();
|
||||
if (!dot_h) {
|
||||
uwsgi_log("unable to generate uwsgi.h");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
if (strlen(dot_h) == 0) {
|
||||
free(dot_h);
|
||||
uwsgi_log("invalid uwsgi.h");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
int dot_h_fd = open(UWSGI_BUILD_DIR "/uwsgi.h", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
|
||||
if (dot_h_fd < 0) {
|
||||
uwsgi_error_open(UWSGI_BUILD_DIR "/uwsgi.h");
|
||||
free(dot_h);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
ssize_t dot_h_len = (ssize_t) strlen(dot_h);
|
||||
if (write(dot_h_fd, dot_h, dot_h_len) != dot_h_len) {
|
||||
uwsgi_error("uwsgi_build_plugin()/write()");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
char *config_py = uwsgi_get_config_py();
|
||||
if (!config_py) {
|
||||
uwsgi_log("unable to generate uwsgiconfig.py");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
if (strlen(config_py) == 0) {
|
||||
uwsgi_log("invalid uwsgiconfig.py");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
int config_py_fd = open(UWSGI_BUILD_DIR "/uwsgiconfig.py", O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
|
||||
if (config_py_fd < 0) {
|
||||
uwsgi_error_open(UWSGI_BUILD_DIR "/uwsgiconfig.py");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
ssize_t config_py_len = (ssize_t) strlen(config_py);
|
||||
if (write(config_py_fd, config_py, config_py_len) != config_py_len) {
|
||||
uwsgi_error("uwsgi_build_plugin()/write()");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
char *cflags = uwsgi_get_cflags();
|
||||
if (!cflags) {
|
||||
uwsgi_log("unable to find cflags\n");
|
||||
_exit(1);
|
||||
}
|
||||
if (strlen(cflags) == 0) {
|
||||
uwsgi_log("invalid cflags\n");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
if (setenv("UWSGI_PLUGINS_BUILDER_CFLAGS", cflags, 1)) {
|
||||
uwsgi_error("uwsgi_build_plugin()/setenv()");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
// now run the python script
|
||||
char *argv[6];
|
||||
|
||||
argv[0] = getenv("PYTHON");
|
||||
if (!argv[0]) argv[0] = "python";
|
||||
|
||||
argv[1] = UWSGI_BUILD_DIR "/uwsgiconfig.py";
|
||||
argv[2] = "--extra-plugin";
|
||||
char *space = strchr(directory, ' ');
|
||||
if (space) {
|
||||
*space = 0;
|
||||
argv[3] = directory;
|
||||
argv[4] = space+1;
|
||||
argv[5] = NULL;
|
||||
}
|
||||
else {
|
||||
argv[3] = directory;
|
||||
argv[4] = NULL;
|
||||
}
|
||||
|
||||
execvp(argv[0], argv);
|
||||
// never here...
|
||||
_exit(1);
|
||||
}
|
||||
+1
-1
@@ -77,7 +77,7 @@ int uwsgi_upload_progress_update(struct wsgi_request *wsgi_req, int fd, size_t r
|
||||
char buf[4096];
|
||||
|
||||
int ret = snprintf(buf, 4096, "{ \"state\" : \"uploading\", \"received\" : %llu, \"size\" : %llu }\r\n", (unsigned long long) (wsgi_req->post_cl - remains), (unsigned long long) wsgi_req->post_cl);
|
||||
if (ret < 0) {
|
||||
if (ret <= 0 || ret >= 4096) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+27
-76
@@ -18,81 +18,6 @@ static size_t get_content_length(char *buf, uint16_t size) {
|
||||
}
|
||||
|
||||
|
||||
ssize_t send_udp_message(uint8_t modifier1, uint8_t modifier2, char *host, char *message, uint16_t message_size) {
|
||||
|
||||
int fd;
|
||||
struct sockaddr_in udp_addr;
|
||||
struct sockaddr_un un_addr;
|
||||
char *udp_port;
|
||||
ssize_t ret;
|
||||
|
||||
struct uwsgi_header *uh;
|
||||
|
||||
udp_port = strchr(host, ':');
|
||||
if (udp_port) {
|
||||
udp_port[0] = 0;
|
||||
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
uwsgi_error("socket()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&udp_addr, 0, sizeof(struct sockaddr_in));
|
||||
udp_addr.sin_family = AF_INET;
|
||||
udp_addr.sin_port = htons(atoi(udp_port + 1));
|
||||
udp_addr.sin_addr.s_addr = inet_addr(host);
|
||||
}
|
||||
else {
|
||||
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
uwsgi_error("socket()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&un_addr, 0, sizeof(struct sockaddr_un));
|
||||
un_addr.sun_family = AF_UNIX;
|
||||
// use 102 as the magic number
|
||||
strncat(un_addr.sun_path, host, 102);
|
||||
|
||||
}
|
||||
|
||||
if (message) {
|
||||
uh = (struct uwsgi_header *) message;
|
||||
}
|
||||
else {
|
||||
uh = (struct uwsgi_header *) uwsgi_malloc(4);
|
||||
}
|
||||
|
||||
uh->modifier1 = modifier1;
|
||||
#ifdef __BIG_ENDIAN__
|
||||
uh->pktsize = uwsgi_swap16(message_size);
|
||||
#else
|
||||
uh->pktsize = message_size;
|
||||
#endif
|
||||
uh->modifier2 = modifier2;
|
||||
|
||||
if (udp_port) {
|
||||
ret = sendto(fd, (char *) uh, message_size + 4, 0, (struct sockaddr *) &udp_addr, sizeof(udp_addr));
|
||||
udp_port[0] = ':';
|
||||
}
|
||||
else {
|
||||
ret = sendto(fd, (char *) uh, message_size + 4, 0, (struct sockaddr *) &un_addr, sizeof(un_addr));
|
||||
}
|
||||
if (ret < 0) {
|
||||
uwsgi_error("send_udp_message()/sendto()");
|
||||
}
|
||||
close(fd);
|
||||
|
||||
if ((char *) uh != message) {
|
||||
free(uh);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_read_response(int fd, struct uwsgi_header *uh, int timeout, char **buf) {
|
||||
|
||||
char *ptr = (char *) uh;
|
||||
@@ -412,6 +337,12 @@ static int uwsgi_proto_check_11(struct wsgi_request *wsgi_req, char *key, char *
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!uwsgi_proto_key("HTTP_ORIGIN", 11)) {
|
||||
wsgi_req->http_origin = buf;
|
||||
wsgi_req->http_origin_len = len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -563,7 +494,7 @@ static int uwsgi_proto_check_18(struct wsgi_request *wsgi_req, char *key, char *
|
||||
|
||||
|
||||
static int uwsgi_proto_check_20(struct wsgi_request *wsgi_req, char *key, char *buf, uint16_t len) {
|
||||
if (uwsgi.log_x_forwarded_for && !uwsgi_proto_key("HTTP_X_FORWARDED_FOR", 20)) {
|
||||
if (uwsgi.logging_options.log_x_forwarded_for && !uwsgi_proto_key("HTTP_X_FORWARDED_FOR", 20)) {
|
||||
wsgi_req->remote_addr = buf;
|
||||
wsgi_req->remote_addr_len = len;
|
||||
return 0;
|
||||
@@ -589,9 +520,28 @@ static int uwsgi_proto_check_22(struct wsgi_request *wsgi_req, char *key, char *
|
||||
wsgi_req->if_modified_since_len = len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!uwsgi_proto_key("HTTP_SEC_WEBSOCKET_KEY", 22)) {
|
||||
wsgi_req->http_sec_websocket_key = buf;
|
||||
wsgi_req->http_sec_websocket_key_len = len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_proto_check_27(struct wsgi_request *wsgi_req, char *key, char *buf, uint16_t len) {
|
||||
|
||||
if (!uwsgi_proto_key("HTTP_SEC_WEBSOCKET_PROTOCOL", 27)) {
|
||||
wsgi_req->http_sec_websocket_protocol = buf;
|
||||
wsgi_req->http_sec_websocket_protocol_len = len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void uwsgi_proto_hooks_setup() {
|
||||
int i = 0;
|
||||
for(i=0;i<UWSGI_PROTO_MAX_CHECK;i++) {
|
||||
@@ -609,6 +559,7 @@ void uwsgi_proto_hooks_setup() {
|
||||
uwsgi.proto_hooks[18] = uwsgi_proto_check_18;
|
||||
uwsgi.proto_hooks[20] = uwsgi_proto_check_20;
|
||||
uwsgi.proto_hooks[22] = uwsgi_proto_check_22;
|
||||
uwsgi.proto_hooks[27] = uwsgi_proto_check_27;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+70
-15
@@ -24,6 +24,39 @@ int uwsgi_simple_wait_read_hook(int fd, int timeout) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int uwsgi_simple_wait_read2_hook(int fd0, int fd1, int timeout, int *fd) {
|
||||
struct pollfd upoll[2];
|
||||
timeout = timeout * 1000;
|
||||
|
||||
upoll[0].fd = fd0;
|
||||
upoll[0].events = POLLIN;
|
||||
upoll[0].revents = 0;
|
||||
|
||||
upoll[1].fd = fd1;
|
||||
upoll[1].events = POLLIN;
|
||||
upoll[1].revents = 0;
|
||||
|
||||
int ret = poll(upoll, 2, timeout);
|
||||
|
||||
if (ret > 0) {
|
||||
if (upoll[0].revents & POLLIN) {
|
||||
*fd = fd0;
|
||||
return 1;
|
||||
}
|
||||
if (upoll[1].revents & POLLIN) {
|
||||
*fd = fd1;
|
||||
return 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (ret < 0) {
|
||||
uwsgi_error("uwsgi_simple_wait_read_hook2()/poll()");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
seek()/rewind() language-independent implementations.
|
||||
*/
|
||||
@@ -32,14 +65,16 @@ void uwsgi_request_body_seek(struct wsgi_request *wsgi_req, off_t pos) {
|
||||
if (wsgi_req->post_file) {
|
||||
if (pos < 0) {
|
||||
if (fseek(wsgi_req->post_file, pos, SEEK_CUR)) {
|
||||
uwsgi_error("uwsgi_request_body_seek()/fseek()");
|
||||
uwsgi_req_error("uwsgi_request_body_seek()/fseek()");
|
||||
wsgi_req->read_errors++;
|
||||
}
|
||||
wsgi_req->post_pos = ftell(wsgi_req->post_file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fseek(wsgi_req->post_file, pos, SEEK_SET)) {
|
||||
uwsgi_error("uwsgi_request_body_seek()/fseek()");
|
||||
uwsgi_req_error("uwsgi_request_body_seek()/fseek()");
|
||||
wsgi_req->read_errors++;
|
||||
}
|
||||
wsgi_req->post_pos = ftell(wsgi_req->post_file);
|
||||
return;
|
||||
@@ -95,7 +130,7 @@ static int consume_body_for_readline(struct wsgi_request *wsgi_req) {
|
||||
if (wsgi_req->post_readline_size - wsgi_req->post_readline_watermark < remains) {
|
||||
char *tmp_buf = realloc(wsgi_req->post_readline_buf, wsgi_req->post_readline_size + remains);
|
||||
if (!tmp_buf) {
|
||||
uwsgi_error("consume_body_for_readline()/realloc()");
|
||||
uwsgi_req_error("consume_body_for_readline()/realloc()");
|
||||
return -1;
|
||||
}
|
||||
wsgi_req->post_readline_buf = tmp_buf;
|
||||
@@ -114,7 +149,7 @@ static int consume_body_for_readline(struct wsgi_request *wsgi_req) {
|
||||
if (wsgi_req->post_file) {
|
||||
size_t ret = fread(wsgi_req->post_readline_buf + wsgi_req->post_readline_watermark, remains, 1, wsgi_req->post_file);
|
||||
if (ret == 0) {
|
||||
uwsgi_error("consume_body_for_readline()/fread()");
|
||||
uwsgi_req_error("consume_body_for_readline()/fread()");
|
||||
return -1;
|
||||
}
|
||||
wsgi_req->post_pos += remains;
|
||||
@@ -140,6 +175,7 @@ static int consume_body_for_readline(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
if (len == 0) {
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
return -1;
|
||||
}
|
||||
if (len < 0) {
|
||||
@@ -147,6 +183,7 @@ static int consume_body_for_readline(struct wsgi_request *wsgi_req) {
|
||||
goto wait;
|
||||
}
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
return -1;
|
||||
}
|
||||
wait:
|
||||
@@ -159,6 +196,7 @@ wait:
|
||||
return 0;
|
||||
}
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
return -1;
|
||||
}
|
||||
// 0 means timeout
|
||||
@@ -167,6 +205,7 @@ wait:
|
||||
return -1;
|
||||
}
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -204,7 +243,8 @@ char *uwsgi_request_body_readline(struct wsgi_request *wsgi_req, ssize_t hint, s
|
||||
size_t amount = UMIN(uwsgi.buffer_size, wsgi_req->post_cl);
|
||||
wsgi_req->post_readline_buf = malloc(amount);
|
||||
if (!wsgi_req->post_readline_buf) {
|
||||
uwsgi_error("uwsgi_request_body_readline()/malloc()");
|
||||
uwsgi_req_error("uwsgi_request_body_readline()/malloc()");
|
||||
wsgi_req->read_errors++;
|
||||
*rlen = -1;
|
||||
return NULL;
|
||||
}
|
||||
@@ -217,6 +257,7 @@ char *uwsgi_request_body_readline(struct wsgi_request *wsgi_req, ssize_t hint, s
|
||||
if (wsgi_req->post_pos >= wsgi_req->post_cl) break;
|
||||
|
||||
if (consume_body_for_readline(wsgi_req)) {
|
||||
wsgi_req->read_errors++;
|
||||
*rlen = -1;
|
||||
return NULL;
|
||||
}
|
||||
@@ -272,8 +313,9 @@ char *uwsgi_request_body_read(struct wsgi_request *wsgi_req, ssize_t hint, ssize
|
||||
if (avail > wsgi_req->post_read_buf_size) {
|
||||
char *tmp_buf = realloc(wsgi_req->post_read_buf, avail);
|
||||
if (!tmp_buf) {
|
||||
uwsgi_error("uwsgi_request_body_read()/realloc()");
|
||||
uwsgi_req_error("uwsgi_request_body_read()/realloc()");
|
||||
*rlen = -1;
|
||||
wsgi_req->read_errors++;
|
||||
return NULL;
|
||||
}
|
||||
wsgi_req->post_read_buf = tmp_buf;
|
||||
@@ -320,7 +362,8 @@ char *uwsgi_request_body_read(struct wsgi_request *wsgi_req, ssize_t hint, ssize
|
||||
if (!wsgi_req->post_read_buf) {
|
||||
wsgi_req->post_read_buf = malloc(remains);
|
||||
if (!wsgi_req->post_read_buf) {
|
||||
uwsgi_error("uwsgi_request_body_read()/malloc()");
|
||||
uwsgi_req_error("uwsgi_request_body_read()/malloc()");
|
||||
wsgi_req->read_errors++;
|
||||
*rlen = -1;
|
||||
return NULL;
|
||||
}
|
||||
@@ -331,7 +374,8 @@ char *uwsgi_request_body_read(struct wsgi_request *wsgi_req, ssize_t hint, ssize
|
||||
if ((remains+*rlen) > wsgi_req->post_read_buf_size) {
|
||||
char *tmp_buf = realloc(wsgi_req->post_read_buf, (remains+*rlen));
|
||||
if (!tmp_buf) {
|
||||
uwsgi_error("uwsgi_request_body_read()/realloc()");
|
||||
uwsgi_req_error("uwsgi_request_body_read()/realloc()");
|
||||
wsgi_req->read_errors++;
|
||||
*rlen = -1;
|
||||
return NULL;
|
||||
}
|
||||
@@ -348,7 +392,8 @@ char *uwsgi_request_body_read(struct wsgi_request *wsgi_req, ssize_t hint, ssize
|
||||
if (wsgi_req->post_file) {
|
||||
if (fread(wsgi_req->post_read_buf + *rlen, remains, 1, wsgi_req->post_file) != 1) {
|
||||
*rlen = -1;
|
||||
uwsgi_error("uwsgi_request_body_read()/fread()");
|
||||
uwsgi_req_error("uwsgi_request_body_read()/fread()");
|
||||
wsgi_req->read_errors++;
|
||||
return NULL;
|
||||
}
|
||||
*rlen += remains;
|
||||
@@ -378,6 +423,7 @@ char *uwsgi_request_body_read(struct wsgi_request *wsgi_req, ssize_t hint, ssize
|
||||
}
|
||||
*rlen = -1;
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
return NULL;
|
||||
}
|
||||
wait:
|
||||
@@ -398,6 +444,7 @@ wait:
|
||||
}
|
||||
else {
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -409,6 +456,7 @@ wait:
|
||||
}
|
||||
*rlen = -1;
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -428,8 +476,8 @@ int uwsgi_postbuffer_do_in_mem(struct wsgi_request *wsgi_req) {
|
||||
char *ptr = wsgi_req->post_buffering_buf;
|
||||
|
||||
while (remains > 0) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
inc_harakiri(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
inc_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
ssize_t rlen = wsgi_req->socket->proto_read_body(wsgi_req, ptr, remains);
|
||||
@@ -447,6 +495,7 @@ int uwsgi_postbuffer_do_in_mem(struct wsgi_request *wsgi_req) {
|
||||
goto wait;
|
||||
}
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -462,6 +511,7 @@ wait:
|
||||
}
|
||||
if (ret < 0) {
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
return -1;
|
||||
}
|
||||
uwsgi_read_timeout(remains);
|
||||
@@ -482,7 +532,8 @@ int uwsgi_postbuffer_do_in_disk(struct wsgi_request *wsgi_req) {
|
||||
|
||||
wsgi_req->post_file = uwsgi_tmpfile();
|
||||
if (!wsgi_req->post_file) {
|
||||
uwsgi_error("uwsgi_postbuffer_do_in_disk()/uwsgi_tmpfile()");
|
||||
uwsgi_req_error("uwsgi_postbuffer_do_in_disk()/uwsgi_tmpfile()");
|
||||
wsgi_req->read_errors++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -499,8 +550,8 @@ int uwsgi_postbuffer_do_in_disk(struct wsgi_request *wsgi_req) {
|
||||
while (post_remains > 0) {
|
||||
|
||||
// during post buffering we need to constantly reset the harakiri
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
inc_harakiri(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
inc_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
// we use the already available post buffering buffer to read chunks....
|
||||
@@ -518,6 +569,7 @@ int uwsgi_postbuffer_do_in_disk(struct wsgi_request *wsgi_req) {
|
||||
goto wait;
|
||||
}
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
goto end;
|
||||
}
|
||||
|
||||
@@ -531,11 +583,13 @@ wait:
|
||||
}
|
||||
else {
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
}
|
||||
goto end;
|
||||
}
|
||||
if (ret < 0) {
|
||||
uwsgi_read_error(remains);
|
||||
wsgi_req->read_errors++;
|
||||
goto end;
|
||||
}
|
||||
uwsgi_read_timeout(remains);
|
||||
@@ -543,7 +597,8 @@ wait:
|
||||
|
||||
write:
|
||||
if (fwrite(wsgi_req->post_buffering_buf, rlen, 1, wsgi_req->post_file) != 1) {
|
||||
uwsgi_error("uwsgi_postbuffer_do_in_disk()/fwrite()");
|
||||
uwsgi_req_error("uwsgi_postbuffer_do_in_disk()/fwrite()");
|
||||
wsgi_req->read_errors++;
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -705,7 +705,7 @@ static int uwsgi_router_flush(struct uwsgi_route *ur, char *arg) {
|
||||
static int transform_fixcl(struct wsgi_request *wsgi_req, struct uwsgi_transformation *ut) {
|
||||
char buf[sizeof(UMAX64_STR)+1];
|
||||
int ret = snprintf(buf, sizeof(UMAX64_STR)+1, "%llu", (unsigned long long) ut->chunk->pos);
|
||||
if (ret <= 0 || ret > (int) (sizeof(UMAX64_STR)+1)) {
|
||||
if (ret <= 0 || ret >= (int) (sizeof(UMAX64_STR)+1)) {
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
@@ -962,7 +962,7 @@ static int uwsgi_router_chdir_func(struct wsgi_request *wsgi_req, struct uwsgi_r
|
||||
struct uwsgi_buffer *ub = uwsgi_routing_translate(wsgi_req, ur, *subject, *subject_len, ur->data, ur->data_len);
|
||||
if (!ub) return UWSGI_ROUTE_BREAK;
|
||||
if (chdir(ub->buf)) {
|
||||
uwsgi_error("uwsgi_router_chdir_func()/chdir()");
|
||||
uwsgi_req_error("uwsgi_router_chdir_func()/chdir()");
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return UWSGI_ROUTE_BREAK;
|
||||
}
|
||||
@@ -1656,7 +1656,7 @@ static char *uwsgi_route_var_uwsgi(struct wsgi_request *wsgi_req, char *key, uin
|
||||
}
|
||||
|
||||
else if (!uwsgi_strncmp(key, keylen, "lq", 2)) {
|
||||
ret = uwsgi_num2str(uwsgi.shared->load);
|
||||
ret = uwsgi_num2str(uwsgi.shared->backlog);
|
||||
*vallen = strlen(ret);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -117,7 +117,7 @@ char *uwsgi_do_rpc(char *node, char *func, uint8_t argc, char *argv[], uint16_t
|
||||
return NULL;
|
||||
|
||||
// wait for connection;
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_write_hook(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
@@ -156,14 +156,14 @@ char *uwsgi_do_rpc(char *node, char *func, uint8_t argc, char *argv[], uint16_t
|
||||
}
|
||||
|
||||
// ok the request is ready, let's send it in non blocking way
|
||||
if (uwsgi_write_true_nb(fd, buffer, buffer_size+4, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_write_true_nb(fd, buffer, buffer_size+4, uwsgi.socket_timeout)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
// ok time to wait for the response in non blocking way
|
||||
size_t rlen = buffer_size+4;
|
||||
uint8_t modifier2 = 0;
|
||||
if (uwsgi_read_with_realloc(fd, &buffer, &rlen, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], NULL, &modifier2)) {
|
||||
if (uwsgi_read_with_realloc(fd, &buffer, &rlen, uwsgi.socket_timeout, NULL, &modifier2)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ char *uwsgi_do_rpc(char *node, char *func, uint8_t argc, char *argv[], uint16_t
|
||||
rlen = content_len;
|
||||
|
||||
// read the raw value from the socket
|
||||
if (uwsgi_read_whole_true_nb(fd, buffer, rlen, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT])) {
|
||||
if (uwsgi_read_whole_true_nb(fd, buffer, rlen, uwsgi.socket_timeout)) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,366 @@
|
||||
#include <uwsgi.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
/*
|
||||
|
||||
This is an high-performance memory area shared by all workers/cores/threads
|
||||
|
||||
Contrary to the caching subsystem it is 1-copy (caching for non-c apps is 2-copy)
|
||||
|
||||
Languages not allowing that kind of access should emulate it calling uwsgi_malloc and then copying it back to
|
||||
the language object.
|
||||
|
||||
The memory areas could be monitored for changes (read: cores can be suspended while waiting for values)
|
||||
|
||||
You can configure multiple areas specifying multiple --sharedarea options
|
||||
|
||||
This is a very low-level api, try to use it to build higher-level primitives or rely on the caching subsystem
|
||||
|
||||
*/
|
||||
|
||||
struct uwsgi_sharedarea *uwsgi_sharedarea_get_by_id(int id, uint64_t pos) {
|
||||
if (id > uwsgi.sharedareas_cnt-1) return NULL;
|
||||
struct uwsgi_sharedarea *sa = uwsgi.sharedareas[id];
|
||||
if (pos > sa->max_pos) return NULL;
|
||||
return sa;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_update(int id) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, 0);
|
||||
if (!sa) return -1;
|
||||
sa->updates++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_rlock(int id) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, 0);
|
||||
if (!sa) return -1;
|
||||
uwsgi_rlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_wlock(int id) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, 0);
|
||||
if (!sa) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_unlock(int id) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, 0);
|
||||
if (!sa) return -1;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int64_t uwsgi_sharedarea_read(int id, uint64_t pos, char *blob, uint64_t len) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + len > sa->max_pos + 1) return -1;
|
||||
if (len == 0) len = (sa->max_pos + 1) - pos;
|
||||
if (sa->honour_used && sa->used-pos < len) len = sa->used-pos ;
|
||||
uwsgi_rlock(sa->lock);
|
||||
memcpy(blob, sa->area + pos, len);
|
||||
sa->hits++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return len;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_write(int id, uint64_t pos, char *blob, uint64_t len) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + len > sa->max_pos + 1) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
memcpy(sa->area + pos, blob, len);
|
||||
sa->updates++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_read64(int id, uint64_t pos, int64_t *value) {
|
||||
int64_t rlen = uwsgi_sharedarea_read(id, pos, (char *) value, 8);
|
||||
return rlen == 8 ? 0 : -1;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_write64(int id, uint64_t pos, int64_t *value) {
|
||||
return uwsgi_sharedarea_write(id, pos, (char *) value, 8);
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_read8(int id, uint64_t pos, int8_t *value) {
|
||||
int64_t rlen = uwsgi_sharedarea_read(id, pos, (char *) value, 1);
|
||||
return rlen == 1 ? 0 : -1;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_write8(int id, uint64_t pos, int8_t *value) {
|
||||
return uwsgi_sharedarea_write(id, pos, (char *) value, 1);
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_read16(int id, uint64_t pos, int16_t *value) {
|
||||
int64_t rlen = uwsgi_sharedarea_read(id, pos, (char *) value, 2);
|
||||
return rlen == 2 ? 0 : -1;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_write16(int id, uint64_t pos, int16_t *value) {
|
||||
return uwsgi_sharedarea_write(id, pos, (char *) value, 2);
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_sharedarea_read32(int id, uint64_t pos, int32_t *value) {
|
||||
int64_t rlen = uwsgi_sharedarea_read(id, pos, (char *) value, 4);
|
||||
return rlen == 4 ? 0 : -1;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_write32(int id, uint64_t pos, int32_t *value) {
|
||||
return uwsgi_sharedarea_write(id, pos, (char *) value, 4);
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_inc8(int id, uint64_t pos, int8_t amount) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + 1 > sa->max_pos + 1) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
int8_t *n_ptr = (int8_t *) (sa->area + pos);
|
||||
*n_ptr+=amount;
|
||||
sa->updates++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_inc16(int id, uint64_t pos, int16_t amount) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + 2 > sa->max_pos + 1) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
int16_t *n_ptr = (int16_t *) (sa->area + pos);
|
||||
*n_ptr+=amount;
|
||||
sa->updates++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_inc32(int id, uint64_t pos, int32_t amount) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + 4 > sa->max_pos + 1) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
int32_t *n_ptr = (int32_t *) (sa->area + pos);
|
||||
*n_ptr+=amount;
|
||||
sa->updates++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_inc64(int id, uint64_t pos, int64_t amount) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + 4 > sa->max_pos + 1) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
int64_t *n_ptr = (int64_t *) (sa->area + pos);
|
||||
*n_ptr+=amount;
|
||||
sa->updates++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_sharedarea_dec8(int id, uint64_t pos, int8_t amount) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + 1 > sa->max_pos + 1) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
int8_t *n_ptr = (int8_t *) (sa->area + pos);
|
||||
*n_ptr-=amount;
|
||||
sa->updates++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_dec16(int id, uint64_t pos, int16_t amount) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + 2 > sa->max_pos + 1) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
int16_t *n_ptr = (int16_t *) (sa->area + pos);
|
||||
*n_ptr-=amount;
|
||||
sa->updates++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_dec32(int id, uint64_t pos, int32_t amount) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + 4 > sa->max_pos + 1) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
int32_t *n_ptr = (int32_t *) (sa->area + pos);
|
||||
*n_ptr-=amount;
|
||||
sa->updates++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_dec64(int id, uint64_t pos, int64_t amount) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (pos + 4 > sa->max_pos + 1) return -1;
|
||||
uwsgi_wlock(sa->lock);
|
||||
int64_t *n_ptr = (int64_t *) (sa->area + pos);
|
||||
*n_ptr-=amount;
|
||||
sa->updates++;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
returns:
|
||||
0 -> on updates
|
||||
-1 -> on error
|
||||
-2 -> on timeout
|
||||
*/
|
||||
int uwsgi_sharedarea_wait(int id, int freq, int timeout) {
|
||||
int waiting = 0;
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, 0);
|
||||
if (!sa) return -1;
|
||||
if (!freq) freq = 100;
|
||||
uwsgi_rlock(sa->lock);
|
||||
uint64_t updates = sa->updates;
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
while(timeout == 0 || (timeout > 0 && (waiting/1000) >= timeout)) {
|
||||
uwsgi.wait_milliseconds_hook(freq);
|
||||
waiting += freq;
|
||||
// lock sa
|
||||
uwsgi_rlock(sa->lock);
|
||||
if (sa->updates != updates) {
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
return 0;
|
||||
}
|
||||
// unlock sa
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
int uwsgi_sharedarea_new_id() {
|
||||
int id = uwsgi.sharedareas_cnt;
|
||||
uwsgi.sharedareas_cnt++;
|
||||
if (!uwsgi.sharedareas) {
|
||||
uwsgi.sharedareas = uwsgi_malloc(sizeof(struct uwsgi_sharedarea *));
|
||||
}
|
||||
else {
|
||||
struct uwsgi_sharedarea **usa = realloc(uwsgi.sharedareas, ((sizeof(struct uwsgi_sharedarea *)) * uwsgi.sharedareas_cnt));
|
||||
if (!usa) {
|
||||
uwsgi_error("uwsgi_sharedarea_init()/realloc()");
|
||||
exit(1);
|
||||
}
|
||||
uwsgi.sharedareas = usa;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
static struct uwsgi_sharedarea *announce_sa(struct uwsgi_sharedarea *sa) {
|
||||
uwsgi_log("sharedarea %d created at %p (%d pages, area at %p)\n", sa->id, sa, sa->pages, sa->area);
|
||||
return sa;
|
||||
}
|
||||
|
||||
struct uwsgi_sharedarea *uwsgi_sharedarea_init(int pages) {
|
||||
int id = uwsgi_sharedarea_new_id();
|
||||
uwsgi.sharedareas[id] = uwsgi_calloc_shared(uwsgi.page_size * (pages + 1));
|
||||
uwsgi.sharedareas[id]->area = ((char *) uwsgi.sharedareas[id]) + uwsgi.page_size;
|
||||
uwsgi.sharedareas[id]->id = id;
|
||||
uwsgi.sharedareas[id]->fd = -1;
|
||||
uwsgi.sharedareas[id]->pages = pages;
|
||||
uwsgi.sharedareas[id]->max_pos = (uwsgi.page_size * pages) -1;
|
||||
char *id_str = uwsgi_num2str(id);
|
||||
uwsgi.sharedareas[id]->lock = uwsgi_rwlock_init(uwsgi_concat2("sharedarea", id_str));
|
||||
free(id_str);
|
||||
return announce_sa(uwsgi.sharedareas[id]);
|
||||
}
|
||||
|
||||
struct uwsgi_sharedarea *uwsgi_sharedarea_init_ptr(char *area, uint64_t len) {
|
||||
int id = uwsgi_sharedarea_new_id();
|
||||
uwsgi.sharedareas[id] = uwsgi_calloc_shared(sizeof(struct uwsgi_sharedarea));
|
||||
uwsgi.sharedareas[id]->area = area;
|
||||
uwsgi.sharedareas[id]->id = id;
|
||||
uwsgi.sharedareas[id]->fd = -1;
|
||||
uwsgi.sharedareas[id]->pages = len / uwsgi.page_size;
|
||||
if (len % uwsgi.page_size != 0) uwsgi.sharedareas[id]->pages++;
|
||||
uwsgi.sharedareas[id]->max_pos = len-1;
|
||||
char *id_str = uwsgi_num2str(id);
|
||||
uwsgi.sharedareas[id]->lock = uwsgi_rwlock_init(uwsgi_concat2("sharedarea", id_str));
|
||||
free(id_str);
|
||||
return announce_sa(uwsgi.sharedareas[id]);
|
||||
}
|
||||
|
||||
struct uwsgi_sharedarea *uwsgi_sharedarea_init_keyval(char *arg) {
|
||||
char *s_pages = NULL;
|
||||
char *s_file = NULL;
|
||||
char *s_fd = NULL;
|
||||
char *s_ptr = NULL;
|
||||
char *s_size = NULL;
|
||||
if (uwsgi_kvlist_parse(arg, strlen(arg), ',', '=',
|
||||
"pages", &s_pages,
|
||||
"file", &s_file,
|
||||
"fd", &s_fd,
|
||||
"ptr", &s_ptr,
|
||||
"size", &s_size,
|
||||
NULL)) {
|
||||
uwsgi_log("invalid sharedarea keyval syntax\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uint64_t len = 0;
|
||||
int pages = 0;
|
||||
if (s_size) {
|
||||
len = uwsgi_n64(s_size);
|
||||
pages = len / uwsgi.page_size;
|
||||
if (len % uwsgi.page_size != 0) pages++;
|
||||
}
|
||||
|
||||
if (s_pages) {
|
||||
pages = atoi(s_pages);
|
||||
}
|
||||
|
||||
char *area = NULL;
|
||||
struct uwsgi_sharedarea *sa = NULL;
|
||||
if (s_file) {
|
||||
}
|
||||
else if (s_fd) {
|
||||
}
|
||||
else if (s_ptr) {
|
||||
}
|
||||
|
||||
if (pages) {
|
||||
if (!area) {
|
||||
sa = uwsgi_sharedarea_init(pages);
|
||||
}
|
||||
else {
|
||||
uwsgi_sharedarea_init_ptr(area, len);
|
||||
}
|
||||
}
|
||||
|
||||
if (s_pages) free(s_pages);
|
||||
if (s_file) free(s_file);
|
||||
if (s_fd) free(s_fd);
|
||||
if (s_ptr) free(s_ptr);
|
||||
if (s_size) free(s_size);
|
||||
|
||||
return sa;
|
||||
}
|
||||
|
||||
|
||||
void uwsgi_sharedareas_init() {
|
||||
struct uwsgi_string_list *usl = NULL;
|
||||
uwsgi_foreach(usl, uwsgi.sharedareas_list) {
|
||||
char *is_keyval = strchr(usl->value, '=');
|
||||
if (!is_keyval) {
|
||||
uwsgi_sharedarea_init(atoi(usl->value));
|
||||
}
|
||||
else {
|
||||
uwsgi_sharedarea_init_keyval(usl->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -45,21 +45,21 @@ int uwsgi_signal_handler(uint8_t sig) {
|
||||
uwsgi.workers[uwsgi.mywid].sig = 1;
|
||||
uwsgi.workers[uwsgi.mywid].signum = sig;
|
||||
uwsgi.workers[uwsgi.mywid].signals++;
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
set_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
}
|
||||
else if (uwsgi.muleid > 0) {
|
||||
uwsgi.mules[uwsgi.muleid - 1].sig = 1;
|
||||
uwsgi.mules[uwsgi.muleid - 1].signum = sig;
|
||||
uwsgi.mules[uwsgi.muleid - 1].signals++;
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MULE_HARAKIRI] > 0) {
|
||||
set_mule_harakiri(uwsgi.shared->options[UWSGI_OPTION_MULE_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.mules > 0) {
|
||||
set_mule_harakiri(uwsgi.harakiri_options.mules);
|
||||
}
|
||||
}
|
||||
else if (uwsgi.i_am_a_spooler && (getpid() == uwsgi.i_am_a_spooler->pid)) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) {
|
||||
set_spooler_harakiri(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.spoolers > 0) {
|
||||
set_spooler_harakiri(uwsgi.harakiri_options.spoolers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ int uwsgi_signal_handler(uint8_t sig) {
|
||||
}
|
||||
}
|
||||
else if (uwsgi.i_am_a_spooler && (getpid() == uwsgi.i_am_a_spooler->pid)) {
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) {
|
||||
if (uwsgi.harakiri_options.spoolers > 0) {
|
||||
set_spooler_harakiri(0);
|
||||
}
|
||||
}
|
||||
@@ -269,7 +269,7 @@ int uwsgi_remote_signal_send(char *addr, uint8_t sig) {
|
||||
uh.pktsize = 0;
|
||||
uh.modifier2 = sig;
|
||||
|
||||
int fd = uwsgi_connect(addr, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0);
|
||||
int fd = uwsgi_connect(addr, uwsgi.socket_timeout, 0);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
|
||||
@@ -279,7 +279,7 @@ int uwsgi_remote_signal_send(char *addr, uint8_t sig) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = uwsgi_read_response(fd, &uh, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], NULL);
|
||||
int ret = uwsgi_read_response(fd, &uh, uwsgi.socket_timeout, NULL);
|
||||
|
||||
close(fd);
|
||||
return ret;
|
||||
|
||||
+18
-4
@@ -750,7 +750,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) {
|
||||
if (!uwsgi.no_defer_accept) {
|
||||
|
||||
#ifdef __linux__
|
||||
if (setsockopt(serverfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], sizeof(int))) {
|
||||
if (setsockopt(serverfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &uwsgi.socket_timeout, sizeof(int))) {
|
||||
uwsgi_error("TCP_DEFER_ACCEPT setsockopt()");
|
||||
}
|
||||
// OSX has no SO_ACCEPTFILTER !!!
|
||||
@@ -1928,20 +1928,34 @@ found:
|
||||
return up;
|
||||
}
|
||||
|
||||
int uwsgi_socket_passcred(int fd) {
|
||||
#ifdef SO_PASSCRED
|
||||
int optval = 1;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &optval, sizeof(optval)) < 0) {
|
||||
uwsgi_error("uwsgi_socket_passcred()/setsockopt()");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void uwsgi_protocols_register() {
|
||||
uwsgi_register_protocol("uwsgi", uwsgi_proto_uwsgi_setup);
|
||||
uwsgi_register_protocol("puwsgi", uwsgi_proto_puwsgi_setup);
|
||||
|
||||
uwsgi_register_protocol("http", uwsgi_proto_http_setup);
|
||||
|
||||
#ifdef UWSGI_SSL
|
||||
uwsgi_register_protocol("suwsgi", uwsgi_proto_suwsgi_setup);
|
||||
uwsgi_register_protocol("https", uwsgi_proto_https_setup);
|
||||
#endif
|
||||
uwsgi_register_protocol("fastcgi", uwsgi_proto_fastcgi_setup);
|
||||
uwsgi_register_protocol("fastcgi-nph", uwsgi_proto_fastcgi_nph_setup);
|
||||
|
||||
uwsgi_register_protocol("scgi", uwsgi_proto_scgi_setup);
|
||||
uwsgi_register_protocol("scgi-nph", uwsgi_proto_scgi_nph_setup);
|
||||
#ifdef UWSGI_ZEROMQ
|
||||
uwsgi_register_protocol("zmq", uwsgi_proto_zmq_setup);
|
||||
#endif
|
||||
|
||||
uwsgi_register_protocol("raw", uwsgi_proto_raw_setup);
|
||||
}
|
||||
|
||||
+3
-3
@@ -552,11 +552,11 @@ void spooler_manage_task(struct uwsgi_spooler *uspool, char *dir, char *task) {
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (uwsgi.p[i]->spooler) {
|
||||
time_t now = uwsgi_now();
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) {
|
||||
set_spooler_harakiri(uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.spoolers > 0) {
|
||||
set_spooler_harakiri(uwsgi.harakiri_options.spoolers);
|
||||
}
|
||||
ret = uwsgi.p[i]->spooler(task, spool_buf, uh.pktsize, body, body_len);
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SPOOLER_HARAKIRI] > 0) {
|
||||
if (uwsgi.harakiri_options.spoolers > 0) {
|
||||
set_spooler_harakiri(0);
|
||||
}
|
||||
if (ret == 0)
|
||||
|
||||
+31
-1
@@ -132,7 +132,6 @@ static int uwsgi_sni_cb(SSL *ssl, int *ad, void *arg) {
|
||||
free(sni_dir_key);
|
||||
free(sni_dir_client_ca);
|
||||
SSL_set_SSL_CTX(ssl, usl->custom_ptr);
|
||||
uwsgi_log("[uwsgi-sni for pid %d] added context for %s\n", (int) getpid(), servername);
|
||||
return SSL_TLSEXT_ERR_OK;
|
||||
}
|
||||
done:
|
||||
@@ -511,10 +510,41 @@ struct uwsgi_string_list *uwsgi_ssl_add_sni_item(char *name, char *crt, char *ke
|
||||
SSL_CTX *ctx = uwsgi_ssl_new_server_context(name, crt, key, ciphers, client_ca);
|
||||
if (!ctx) {
|
||||
uwsgi_log("[uwsgi-ssl] DANGER unable to initialize context for \"%s\"\n", name);
|
||||
free(name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct uwsgi_string_list *usl = uwsgi_string_new_list(&uwsgi.sni, name);
|
||||
usl->custom_ptr = ctx;
|
||||
// mark it as dynamic
|
||||
usl->custom = 1;
|
||||
uwsgi_log_verbose("[uwsgi-sni for pid %d] added SSL context for %s\n", (int) getpid(), name);
|
||||
return usl;
|
||||
}
|
||||
|
||||
void uwsgi_ssl_del_sni_item(char *name, uint16_t name_len) {
|
||||
struct uwsgi_string_list *usl = NULL, *last_sni = NULL, *sni_item = NULL;
|
||||
uwsgi_foreach(usl, uwsgi.sni) {
|
||||
if (!uwsgi_strncmp(usl->value, usl->len, name, name_len) && usl->custom) {
|
||||
sni_item = usl;
|
||||
break;
|
||||
}
|
||||
last_sni = usl;
|
||||
}
|
||||
|
||||
if (!sni_item) return;
|
||||
|
||||
if (last_sni) {
|
||||
last_sni->next = sni_item->next;
|
||||
}
|
||||
else {
|
||||
uwsgi.sni = sni_item->next;
|
||||
}
|
||||
|
||||
// we are free to destroy it as no more clients are using it
|
||||
SSL_CTX_free((SSL_CTX *) sni_item->custom_ptr);
|
||||
free(sni_item->value);
|
||||
free(sni_item);
|
||||
|
||||
uwsgi_log_verbose("[uwsgi-sni for pid %d] destroyed SSL context for %s\n",(int) getpid(), name);
|
||||
}
|
||||
|
||||
+2
-1
@@ -450,7 +450,8 @@ int uwsgi_real_file_serve(struct wsgi_request *wsgi_req, char *real_filename, si
|
||||
if (wsgi_req->if_modified_since_len) {
|
||||
time_t ims = parse_http_date(wsgi_req->if_modified_since, wsgi_req->if_modified_since_len);
|
||||
if (st->st_mtime <= ims) {
|
||||
uwsgi_response_prepare_headers(wsgi_req, "304 Not Modified", 16);
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, "304 Not Modified", 16))
|
||||
return -1;
|
||||
return uwsgi_response_write_headers_do(wsgi_req);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -111,7 +111,7 @@ int uwsgi_stats_keyval(struct uwsgi_stats *us, char *key, char *value) {
|
||||
size_t available = watermark - ptr;
|
||||
|
||||
int ret = snprintf(ptr, available, "\"%s\":\"%s\"", key, value);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
while (ret >= (int) available) {
|
||||
char *new_base = realloc(us->base, us->size + us->chunk);
|
||||
@@ -123,7 +123,7 @@ int uwsgi_stats_keyval(struct uwsgi_stats *us, char *key, char *value) {
|
||||
watermark = us->base + us->size;
|
||||
available = watermark - ptr;
|
||||
ret = snprintf(ptr, available, "\"%s\":\"%s\"", key, value);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ int uwsgi_stats_keyvalnum(struct uwsgi_stats *us, char *key, char *value, unsign
|
||||
size_t available = watermark - ptr;
|
||||
|
||||
int ret = snprintf(ptr, available, "\"%s\":\"%s%llu\"", key, value, num);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
while (ret >= (int) available) {
|
||||
char *new_base = realloc(us->base, us->size + us->chunk);
|
||||
@@ -161,7 +161,7 @@ int uwsgi_stats_keyvalnum(struct uwsgi_stats *us, char *key, char *value, unsign
|
||||
watermark = us->base + us->size;
|
||||
available = watermark - ptr;
|
||||
ret = snprintf(ptr, available, "\"%s\":\"%s%llu\"", key, value, num);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ int uwsgi_stats_keyvaln(struct uwsgi_stats *us, char *key, char *value, int vall
|
||||
size_t available = watermark - ptr;
|
||||
|
||||
int ret = snprintf(ptr, available, "\"%s\":\"%.*s\"", key, vallen, value);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
while (ret >= (int) available) {
|
||||
char *new_base = realloc(us->base, us->size + us->chunk);
|
||||
@@ -200,7 +200,7 @@ int uwsgi_stats_keyvaln(struct uwsgi_stats *us, char *key, char *value, int vall
|
||||
watermark = us->base + us->size;
|
||||
available = watermark - ptr;
|
||||
ret = snprintf(ptr, available, "\"%s\":\"%.*s\"", key, vallen, value);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ int uwsgi_stats_key(struct uwsgi_stats *us, char *key) {
|
||||
size_t available = watermark - ptr;
|
||||
|
||||
int ret = snprintf(ptr, available, "\"%s\":", key);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
while (ret >= (int) available) {
|
||||
char *new_base = realloc(us->base, us->size + us->chunk);
|
||||
@@ -239,7 +239,7 @@ int uwsgi_stats_key(struct uwsgi_stats *us, char *key) {
|
||||
watermark = us->base + us->size;
|
||||
available = watermark - ptr;
|
||||
ret = snprintf(ptr, available, "\"%s\":", key);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -254,7 +254,7 @@ int uwsgi_stats_str(struct uwsgi_stats *us, char *str) {
|
||||
size_t available = watermark - ptr;
|
||||
|
||||
int ret = snprintf(ptr, available, "\"%s\"", str);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
while (ret >= (int) available) {
|
||||
char *new_base = realloc(us->base, us->size + us->chunk);
|
||||
@@ -266,7 +266,7 @@ int uwsgi_stats_str(struct uwsgi_stats *us, char *str) {
|
||||
watermark = us->base + us->size;
|
||||
available = watermark - ptr;
|
||||
ret = snprintf(ptr, available, "\"%s\"", str);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ int uwsgi_stats_keylong(struct uwsgi_stats *us, char *key, unsigned long long nu
|
||||
size_t available = watermark - ptr;
|
||||
|
||||
int ret = snprintf(ptr, available, "\"%s\":%llu", key, num);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
while (ret >= (int) available) {
|
||||
char *new_base = realloc(us->base, us->size + us->chunk);
|
||||
@@ -299,7 +299,7 @@ int uwsgi_stats_keylong(struct uwsgi_stats *us, char *key, unsigned long long nu
|
||||
watermark = us->base + us->size;
|
||||
available = watermark - ptr;
|
||||
ret = snprintf(ptr, available, "\"%s\":%llu", key, num);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ int uwsgi_stats_keyslong(struct uwsgi_stats *us, char *key, long long num) {
|
||||
size_t available = watermark - ptr;
|
||||
|
||||
int ret = snprintf(ptr, available, "\"%s\":%lld", key, num);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
while (ret >= (int) available) {
|
||||
char *new_base = realloc(us->base, us->size + us->chunk);
|
||||
@@ -337,7 +337,7 @@ int uwsgi_stats_keyslong(struct uwsgi_stats *us, char *key, long long num) {
|
||||
watermark = us->base + us->size;
|
||||
available = watermark - ptr;
|
||||
ret = snprintf(ptr, available, "\"%s\":%lld", key, num);
|
||||
if (ret < 0)
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -379,7 +379,7 @@ void uwsgi_send_stats(int fd, struct uwsgi_stats *(*func) (void)) {
|
||||
size_t remains = us->pos;
|
||||
off_t pos = 0;
|
||||
while (remains > 0) {
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
goto end0;
|
||||
}
|
||||
|
||||
+164
-11
@@ -20,6 +20,51 @@
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
#ifdef UWSGI_SSL
|
||||
static void uwsgi_subscription_sni_check(struct uwsgi_subscribe_slot *current_slot, struct uwsgi_subscribe_req *usr) {
|
||||
if (usr->sni_key_len > 0 && usr->sni_crt_len > 0) {
|
||||
if (!current_slot->sni_enabled) {
|
||||
char *sni_key = uwsgi_concat2n(usr->sni_key, usr->sni_key_len, "", 0);
|
||||
char *sni_crt = uwsgi_concat2n(usr->sni_crt, usr->sni_crt_len, "", 0);
|
||||
char *sni_ca = NULL;
|
||||
if (usr->sni_ca_len > 0) {
|
||||
sni_ca = uwsgi_concat2n(usr->sni_ca, usr->sni_ca_len, "", 0);
|
||||
}
|
||||
char *servername = NULL;
|
||||
char *colon = memchr(current_slot->key, ':', current_slot->keylen);
|
||||
if (colon) {
|
||||
servername = uwsgi_concat2n(current_slot->key, colon-current_slot->key, "", 0);
|
||||
}
|
||||
else {
|
||||
servername = uwsgi_concat2n(current_slot->key, current_slot->keylen, "", 0);
|
||||
}
|
||||
if (uwsgi_ssl_add_sni_item(servername, sni_crt, sni_key, uwsgi.sni_dir_ciphers , sni_ca)) {
|
||||
current_slot->sni_enabled = 1;
|
||||
}
|
||||
if (sni_key) free(sni_key);
|
||||
if (sni_crt) free(sni_crt);
|
||||
if (sni_ca) free(sni_ca);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int uwsgi_subscription_credentials_check(struct uwsgi_subscribe_slot *slot, struct uwsgi_subscribe_req *usr) {
|
||||
struct uwsgi_string_list *usl = NULL;
|
||||
uwsgi_foreach(usl, uwsgi.subscriptions_credentials_check_dir) {
|
||||
char *filename = uwsgi_concat2n(usl->value, usl->len, slot->key, slot->keylen);
|
||||
struct stat st;
|
||||
int ret = stat(filename, &st);
|
||||
free(filename);
|
||||
if (ret != 0) continue;
|
||||
if (st.st_uid != usr->uid) continue;
|
||||
if (st.st_gid != usr->gid) continue;
|
||||
// accepted...
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct uwsgi_subscribe_slot *uwsgi_get_subscribe_slot(struct uwsgi_subscribe_slot **slot, char *key, uint16_t keylen) {
|
||||
|
||||
if (keylen > 0xff)
|
||||
@@ -305,6 +350,12 @@ int uwsgi_remove_subscribe_node(struct uwsgi_subscribe_slot **slot, struct uwsgi
|
||||
EVP_PKEY_free(node_slot->sign_public_key);
|
||||
EVP_MD_CTX_destroy(node_slot->sign_ctx);
|
||||
}
|
||||
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
|
||||
// if there is a SNI context active, destroy it
|
||||
if (node_slot->sni_enabled) {
|
||||
uwsgi_ssl_del_sni_item(node_slot->key, node_slot->keylen);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
free(node_slot);
|
||||
slot[hash_key] = NULL;
|
||||
@@ -358,6 +409,11 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (uwsgi.subscriptions_credentials_check_dir && !uwsgi_subscription_credentials_check(current_slot, usr)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
node = current_slot->nodes;
|
||||
while (node) {
|
||||
if (!uwsgi_strncmp(node->name, node->len, usr->address, usr->address_len)) {
|
||||
@@ -388,6 +444,8 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo
|
||||
uwsgi_log("[uwsgi-subscription for pid %d] invalid (sniffed ?) packet sent for slot: %.*s node: %.*s unix_check: %lu\n", (int) uwsgi.mypid, usr->keylen, usr->key, usr->address_len, usr->address, (unsigned long) usr->unix_check);
|
||||
return NULL;
|
||||
}
|
||||
// check here as we are sure the node will be added
|
||||
uwsgi_subscription_sni_check(current_slot, usr);
|
||||
#endif
|
||||
|
||||
node = uwsgi_malloc(sizeof(struct uwsgi_subscribe_node));
|
||||
@@ -396,7 +454,8 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo
|
||||
node->modifier2 = usr->modifier2;
|
||||
node->requests = 0;
|
||||
node->last_requests = 0;
|
||||
node->transferred = 0;
|
||||
node->tx = 0;
|
||||
node->rx = 0;
|
||||
node->reference = 0;
|
||||
node->death_mark = 0;
|
||||
node->failcnt = 0;
|
||||
@@ -407,6 +466,9 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo
|
||||
if (!node->weight)
|
||||
node->weight = 1;
|
||||
node->wrr = 0;
|
||||
node->pid = usr->pid;
|
||||
node->uid = usr->uid;
|
||||
node->gid = usr->gid;
|
||||
node->last_check = uwsgi_now();
|
||||
node->slot = current_slot;
|
||||
memcpy(node->name, usr->address, usr->address_len);
|
||||
@@ -464,16 +526,27 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo
|
||||
#endif
|
||||
current_slot->keylen = usr->keylen;
|
||||
memcpy(current_slot->key, usr->key, usr->keylen);
|
||||
if (uwsgi.subscriptions_credentials_check_dir) {
|
||||
if (!uwsgi_subscription_credentials_check(current_slot, usr)) {
|
||||
free(current_slot);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
current_slot->key[usr->keylen] = 0;
|
||||
current_slot->hits = 0;
|
||||
|
||||
#ifdef UWSGI_SSL
|
||||
current_slot->sni_enabled = 0;
|
||||
uwsgi_subscription_sni_check(current_slot, usr);
|
||||
#endif
|
||||
current_slot->nodes = uwsgi_malloc(sizeof(struct uwsgi_subscribe_node));
|
||||
current_slot->nodes->slot = current_slot;
|
||||
current_slot->nodes->len = usr->address_len;
|
||||
current_slot->nodes->reference = 0;
|
||||
current_slot->nodes->requests = 0;
|
||||
current_slot->nodes->last_requests = 0;
|
||||
current_slot->nodes->transferred = 0;
|
||||
current_slot->nodes->tx = 0;
|
||||
current_slot->nodes->rx = 0;
|
||||
current_slot->nodes->death_mark = 0;
|
||||
current_slot->nodes->failcnt = 0;
|
||||
current_slot->nodes->modifier1 = usr->modifier1;
|
||||
@@ -485,6 +558,9 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo
|
||||
if (!current_slot->nodes->weight)
|
||||
current_slot->nodes->weight = 1;
|
||||
current_slot->nodes->wrr = 0;
|
||||
current_slot->nodes->pid = usr->pid;
|
||||
current_slot->nodes->uid = usr->uid;
|
||||
current_slot->nodes->gid = usr->gid;
|
||||
memcpy(current_slot->nodes->name, usr->address, usr->address_len);
|
||||
current_slot->nodes->last_check = uwsgi_now();
|
||||
|
||||
@@ -516,8 +592,64 @@ struct uwsgi_subscribe_node *uwsgi_add_subscribe_node(struct uwsgi_subscribe_slo
|
||||
|
||||
}
|
||||
|
||||
static void send_subscription(char *host, char *message, uint16_t message_size) {
|
||||
|
||||
void uwsgi_send_subscription(char *udp_address, char *key, size_t keysize, uint8_t modifier1, uint8_t modifier2, uint8_t cmd, char *socket_name, char *sign) {
|
||||
int fd;
|
||||
struct sockaddr_in udp_addr;
|
||||
struct sockaddr_un un_addr;
|
||||
ssize_t ret;
|
||||
|
||||
char *udp_port = strchr(host, ':');
|
||||
if (udp_port) {
|
||||
udp_port[0] = 0;
|
||||
|
||||
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
uwsgi_error("send_subscription()/socket()");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&udp_addr, 0, sizeof(struct sockaddr_in));
|
||||
udp_addr.sin_family = AF_INET;
|
||||
udp_addr.sin_port = htons(atoi(udp_port + 1));
|
||||
udp_addr.sin_addr.s_addr = inet_addr(host);
|
||||
}
|
||||
else {
|
||||
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
if (fd < 0) {
|
||||
uwsgi_error("send_subscription()/socket()");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&un_addr, 0, sizeof(struct sockaddr_un));
|
||||
un_addr.sun_family = AF_UNIX;
|
||||
// use 102 as the magic number
|
||||
strncat(un_addr.sun_path, host, 102);
|
||||
|
||||
}
|
||||
|
||||
if (udp_port) {
|
||||
ret = sendto(fd, message, message_size, 0, (struct sockaddr *) &udp_addr, sizeof(udp_addr));
|
||||
udp_port[0] = ':';
|
||||
}
|
||||
else {
|
||||
if (uwsgi.subscriptions_use_credentials) {
|
||||
// could be useless as internally the socket could add them automagically
|
||||
ret = uwsgi_pass_cred2(fd, message, message_size, (struct sockaddr *) &un_addr, sizeof(un_addr));
|
||||
}
|
||||
else {
|
||||
ret = sendto(fd, message, message_size, 0, (struct sockaddr *) &un_addr, sizeof(un_addr));
|
||||
}
|
||||
}
|
||||
if (ret < 0) {
|
||||
uwsgi_error("send_subscription()/sendto()");
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
|
||||
void uwsgi_send_subscription(char *udp_address, char *key, size_t keysize, uint8_t modifier1, uint8_t modifier2, uint8_t cmd, char *socket_name, char *sign, char *sni_key, char *sni_crt, char *sni_ca) {
|
||||
|
||||
if (socket_name == NULL && !uwsgi.sockets)
|
||||
return;
|
||||
@@ -560,8 +692,22 @@ void uwsgi_send_subscription(char *udp_address, char *key, size_t keysize, uint8
|
||||
}
|
||||
#endif
|
||||
|
||||
if (sni_key) {
|
||||
if (uwsgi_buffer_append_keyval(ub, "sni_key", 7, sni_key, strlen(sni_key))) goto end;
|
||||
}
|
||||
|
||||
send_udp_message(224, cmd, udp_address, ub->buf, ub->pos - 4);
|
||||
if (sni_crt) {
|
||||
if (uwsgi_buffer_append_keyval(ub, "sni_crt", 7, sni_crt, strlen(sni_crt))) goto end;
|
||||
}
|
||||
|
||||
if (sni_ca) {
|
||||
if (uwsgi_buffer_append_keyval(ub, "sni_ca", 6, sni_ca, strlen(sni_ca))) goto end;
|
||||
}
|
||||
|
||||
// add uwsgi header
|
||||
if (uwsgi_buffer_set_uh(ub, 224, cmd)) goto end;
|
||||
|
||||
send_subscription(udp_address, ub->buf, ub->pos);
|
||||
end:
|
||||
uwsgi_buffer_destroy(ub);
|
||||
}
|
||||
@@ -679,7 +825,7 @@ void uwsgi_subscribe(char *subscription, uint8_t cmd) {
|
||||
modifier1_len = strlen(modifier1);
|
||||
keysize = strlen(key);
|
||||
}
|
||||
uwsgi_send_subscription(udp_address, key, keysize, uwsgi_str_num(modifier1, modifier1_len), 0, cmd, socket_name, sign);
|
||||
uwsgi_send_subscription(udp_address, key, keysize, uwsgi_str_num(modifier1, modifier1_len), 0, cmd, socket_name, sign, NULL, NULL, NULL);
|
||||
modifier1 = NULL;
|
||||
modifier1_len = 0;
|
||||
}
|
||||
@@ -697,7 +843,7 @@ void uwsgi_subscribe(char *subscription, uint8_t cmd) {
|
||||
modifier1_len = strlen(modifier1);
|
||||
keysize = strlen(key);
|
||||
}
|
||||
uwsgi_send_subscription(udp_address, key, keysize, uwsgi_str_num(modifier1, modifier1_len), 0, cmd, socket_name, sign);
|
||||
uwsgi_send_subscription(udp_address, key, keysize, uwsgi_str_num(modifier1, modifier1_len), 0, cmd, socket_name, sign, NULL, NULL, NULL);
|
||||
modifier1 = NULL;
|
||||
modifier1_len = 0;
|
||||
lines[i] = '\n';
|
||||
@@ -709,9 +855,8 @@ void uwsgi_subscribe(char *subscription, uint8_t cmd) {
|
||||
}
|
||||
keysize++;
|
||||
}
|
||||
|
||||
free(lines);
|
||||
}
|
||||
free(lines);
|
||||
}
|
||||
else {
|
||||
modifier1 = strchr(subscription_key + 1, ',');
|
||||
@@ -727,7 +872,7 @@ void uwsgi_subscribe(char *subscription, uint8_t cmd) {
|
||||
modifier1_len = strlen(modifier1);
|
||||
}
|
||||
|
||||
uwsgi_send_subscription(udp_address, subscription_key + 1, strlen(subscription_key + 1), uwsgi_str_num(modifier1, modifier1_len), 0, cmd, socket_name, sign);
|
||||
uwsgi_send_subscription(udp_address, subscription_key + 1, strlen(subscription_key + 1), uwsgi_str_num(modifier1, modifier1_len), 0, cmd, socket_name, sign, NULL, NULL, NULL);
|
||||
if (modifier1)
|
||||
modifier1[-1] = ',';
|
||||
if (sign)
|
||||
@@ -752,6 +897,9 @@ void uwsgi_subscribe2(char *arg, uint8_t cmd) {
|
||||
char *s2_modifier1 = NULL;
|
||||
char *s2_modifier2 = NULL;
|
||||
char *s2_check = NULL;
|
||||
char *s2_sni_key = NULL;
|
||||
char *s2_sni_crt = NULL;
|
||||
char *s2_sni_ca = NULL;
|
||||
|
||||
if (uwsgi_kvlist_parse(arg, strlen(arg), ',', '=',
|
||||
"server", &s2_server,
|
||||
@@ -763,6 +911,9 @@ void uwsgi_subscribe2(char *arg, uint8_t cmd) {
|
||||
"modifier2", &s2_modifier2,
|
||||
"sign", &s2_sign,
|
||||
"check", &s2_check,
|
||||
"sni_key", &s2_sni_key,
|
||||
"sni_crt", &s2_sni_crt,
|
||||
"sni_ca", &s2_sni_ca,
|
||||
NULL)) {
|
||||
return;
|
||||
}
|
||||
@@ -798,7 +949,7 @@ void uwsgi_subscribe2(char *arg, uint8_t cmd) {
|
||||
modifier2 = atoi(s2_modifier2);
|
||||
}
|
||||
|
||||
uwsgi_send_subscription(s2_server, s2_key, strlen(s2_key), modifier1, modifier2, cmd, s2_addr, s2_sign);
|
||||
uwsgi_send_subscription(s2_server, s2_key, strlen(s2_key), modifier1, modifier2, cmd, s2_addr, s2_sign, s2_sni_key, s2_sni_crt, s2_sni_ca);
|
||||
end:
|
||||
if (s2_server) free(s2_server);
|
||||
if (s2_key) free(s2_key);
|
||||
@@ -812,6 +963,8 @@ end:
|
||||
}
|
||||
|
||||
void uwsgi_subscribe_all(uint8_t cmd, int verbose) {
|
||||
|
||||
if (uwsgi.subscriptions_blocked) return;
|
||||
// -- subscribe
|
||||
struct uwsgi_string_list *subscriptions = uwsgi.subscriptions;
|
||||
while (subscriptions) {
|
||||
|
||||
+286
-198
@@ -47,7 +47,7 @@ void inc_harakiri(int sec) {
|
||||
uwsgi.workers[uwsgi.mywid].harakiri += sec;
|
||||
}
|
||||
else {
|
||||
alarm(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] + sec);
|
||||
alarm(uwsgi.harakiri_options.workers + sec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +206,8 @@ void uwsgi_set_cgroup() {
|
||||
if (!uwsgi.cgroup)
|
||||
return;
|
||||
|
||||
if (getuid()) return;
|
||||
if (getuid())
|
||||
return;
|
||||
|
||||
usl = uwsgi.cgroup;
|
||||
|
||||
@@ -278,41 +279,41 @@ void uwsgi_set_cgroup() {
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_CAP
|
||||
void uwsgi_apply_cap(cap_value_t *cap, int caps_count) {
|
||||
cap_value_t minimal_cap_values[] = { CAP_SYS_CHROOT, CAP_SETUID, CAP_SETGID, CAP_SETPCAP };
|
||||
void uwsgi_apply_cap(cap_value_t * cap, int caps_count) {
|
||||
cap_value_t minimal_cap_values[] = { CAP_SYS_CHROOT, CAP_SETUID, CAP_SETGID, CAP_SETPCAP };
|
||||
|
||||
cap_t caps = cap_init();
|
||||
cap_t caps = cap_init();
|
||||
|
||||
if (!caps) {
|
||||
uwsgi_error("cap_init()");
|
||||
exit(1);
|
||||
}
|
||||
cap_clear(caps);
|
||||
if (!caps) {
|
||||
uwsgi_error("cap_init()");
|
||||
exit(1);
|
||||
}
|
||||
cap_clear(caps);
|
||||
|
||||
cap_set_flag(caps, CAP_EFFECTIVE, 4, minimal_cap_values, CAP_SET);
|
||||
cap_set_flag(caps, CAP_EFFECTIVE, 4, minimal_cap_values, CAP_SET);
|
||||
|
||||
cap_set_flag(caps, CAP_PERMITTED, 4, minimal_cap_values, CAP_SET);
|
||||
cap_set_flag(caps, CAP_PERMITTED, caps_count, cap, CAP_SET);
|
||||
cap_set_flag(caps, CAP_PERMITTED, 4, minimal_cap_values, CAP_SET);
|
||||
cap_set_flag(caps, CAP_PERMITTED, caps_count, cap, CAP_SET);
|
||||
|
||||
cap_set_flag(caps, CAP_INHERITABLE, caps_count, cap, CAP_SET);
|
||||
cap_set_flag(caps, CAP_INHERITABLE, caps_count, cap, CAP_SET);
|
||||
|
||||
if (cap_set_proc(caps) < 0) {
|
||||
uwsgi_error("cap_set_proc()");
|
||||
exit(1);
|
||||
}
|
||||
cap_free(caps);
|
||||
if (cap_set_proc(caps) < 0) {
|
||||
uwsgi_error("cap_set_proc()");
|
||||
exit(1);
|
||||
}
|
||||
cap_free(caps);
|
||||
|
||||
#ifdef __linux__
|
||||
#ifdef SECBIT_KEEP_CAPS
|
||||
if (prctl(SECBIT_KEEP_CAPS, 1, 0, 0, 0) < 0) {
|
||||
uwsgi_error("prctl()");
|
||||
exit(1);
|
||||
}
|
||||
if (prctl(SECBIT_KEEP_CAPS, 1, 0, 0, 0) < 0) {
|
||||
uwsgi_error("prctl()");
|
||||
exit(1);
|
||||
}
|
||||
#else
|
||||
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) {
|
||||
uwsgi_error("prctl()");
|
||||
exit(1);
|
||||
}
|
||||
if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0) {
|
||||
uwsgi_error("prctl()");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@@ -517,7 +518,7 @@ void uwsgi_as_root() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (in_jail) {
|
||||
if (in_jail || uwsgi.jailed) {
|
||||
uwsgi_hooks_run(uwsgi.hook_post_jail, "post-jail", 1);
|
||||
struct uwsgi_string_list *usl = NULL;
|
||||
uwsgi_foreach(usl, uwsgi.mount_post_jail) {
|
||||
@@ -587,7 +588,7 @@ void uwsgi_as_root() {
|
||||
exit(1);
|
||||
}
|
||||
#ifdef __linux__
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG]) {
|
||||
if (uwsgi.logging_options.memory_report) {
|
||||
uwsgi_log("*** Warning, on linux system you have to bind-mount the /proc fs in your chroot to get memory debug/report.\n");
|
||||
}
|
||||
#endif
|
||||
@@ -603,10 +604,10 @@ void uwsgi_as_root() {
|
||||
}
|
||||
*space = 0;
|
||||
#if defined(MS_REC) && defined(MS_PRIVATE)
|
||||
if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL)) {
|
||||
uwsgi_error("mount()");
|
||||
exit(1);
|
||||
}
|
||||
if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) {
|
||||
uwsgi_error("mount()");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
if (chdir(arg)) {
|
||||
uwsgi_error("pivot_root()/chdir()");
|
||||
@@ -619,7 +620,7 @@ void uwsgi_as_root() {
|
||||
uwsgi_error("pivot_root()");
|
||||
exit(1);
|
||||
}
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG]) {
|
||||
if (uwsgi.logging_options.memory_report) {
|
||||
uwsgi_log("*** Warning, on linux system you have to bind-mount the /proc fs in your chroot to get memory debug/report.\n");
|
||||
}
|
||||
free(arg);
|
||||
@@ -632,25 +633,25 @@ void uwsgi_as_root() {
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) && !defined(OBSOLETE_LINUX_KERNEL)
|
||||
if (uwsgi.unshare2 && !uwsgi.reloads) {
|
||||
if (uwsgi.unshare2 && !uwsgi.reloads) {
|
||||
|
||||
if (unshare(uwsgi.unshare2)) {
|
||||
uwsgi_error("unshare()");
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
uwsgi_log("[linux-namespace] applied unshare() mask: %d\n", uwsgi.unshare2);
|
||||
}
|
||||
if (unshare(uwsgi.unshare2)) {
|
||||
uwsgi_error("unshare()");
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
uwsgi_log("[linux-namespace] applied unshare() mask: %d\n", uwsgi.unshare2);
|
||||
}
|
||||
#ifdef CLONE_NEWUSER
|
||||
if (uwsgi.unshare2 & CLONE_NEWUSER) {
|
||||
if (setuid(0)) {
|
||||
uwsgi_error("uwsgi_as_root()/setuid(0)");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (uwsgi.unshare2 & CLONE_NEWUSER) {
|
||||
if (setuid(0)) {
|
||||
uwsgi_error("uwsgi_as_root()/setuid(0)");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
in_jail = 1;
|
||||
}
|
||||
in_jail = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (uwsgi.refork_as_root) {
|
||||
@@ -1027,7 +1028,7 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
uwsgi.workers[uwsgi.mywid].avg_response_time = (uwsgi.workers[uwsgi.mywid].avg_response_time + tmp_rt) / 2;
|
||||
|
||||
// get memory usage
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1 || uwsgi.force_get_memusage) {
|
||||
if (uwsgi.logging_options.memory_report == 1 || uwsgi.force_get_memusage) {
|
||||
get_memusage(&rss, &vsz);
|
||||
uwsgi.workers[uwsgi.mywid].vsz_size = vsz;
|
||||
uwsgi.workers[uwsgi.mywid].rss_size = rss;
|
||||
@@ -1038,6 +1039,7 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
uwsgi.workers[uwsgi.mywid].requests++;
|
||||
uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].requests++;
|
||||
uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].write_errors += wsgi_req->write_errors;
|
||||
uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].read_errors += wsgi_req->read_errors;
|
||||
// this is used for MAX_REQUESTS
|
||||
uwsgi.workers[uwsgi.mywid].delta_requests++;
|
||||
}
|
||||
@@ -1073,6 +1075,13 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
if (!wsgi_req->is_raw && uwsgi.p[wsgi_req->uh->modifier1]->after_request)
|
||||
uwsgi.p[wsgi_req->uh->modifier1]->after_request(wsgi_req);
|
||||
|
||||
// after_request custom hooks
|
||||
struct uwsgi_string_list *usl = NULL;
|
||||
uwsgi_foreach(usl, uwsgi.after_request_hooks) {
|
||||
void (*func) (struct wsgi_request *) = (void (*)(struct wsgi_request *)) usl->custom_ptr;
|
||||
func(wsgi_req);
|
||||
}
|
||||
|
||||
if (uwsgi.threads > 1) {
|
||||
// now the thread can die...
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &tmp_id);
|
||||
@@ -1099,7 +1108,7 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
// defunct process reaper
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_REAPER] == 1) {
|
||||
if (uwsgi.reaper == 1) {
|
||||
while (waitpid(WAIT_ANY, &waitpid_status, WNOHANG) > 0);
|
||||
}
|
||||
|
||||
@@ -1137,6 +1146,9 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
if (wsgi_req->websocket_buf) {
|
||||
uwsgi_buffer_destroy(wsgi_req->websocket_buf);
|
||||
}
|
||||
if (wsgi_req->websocket_send_buf) {
|
||||
uwsgi_buffer_destroy(wsgi_req->websocket_send_buf);
|
||||
}
|
||||
|
||||
|
||||
// reset request
|
||||
@@ -1148,21 +1160,21 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
|
||||
// yes, this is pretty useless but we cannot ensure all of the plugin have the same behaviour
|
||||
uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].in_request = 0;
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MAX_REQUESTS] > 0 && uwsgi.workers[uwsgi.mywid].delta_requests >= uwsgi.shared->options[UWSGI_OPTION_MAX_REQUESTS]
|
||||
&& (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] * 1000000)) {
|
||||
if (uwsgi.max_requests > 0 && uwsgi.workers[uwsgi.mywid].delta_requests >= uwsgi.max_requests
|
||||
&& (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.min_worker_lifetime * 1000000)) {
|
||||
goodbye_cruel_world();
|
||||
}
|
||||
|
||||
if (uwsgi.reload_on_as && (rlim_t) vsz >= uwsgi.reload_on_as && (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] * 1000000)) {
|
||||
if (uwsgi.reload_on_as && (rlim_t) vsz >= uwsgi.reload_on_as && (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.min_worker_lifetime * 1000000)) {
|
||||
goodbye_cruel_world();
|
||||
}
|
||||
|
||||
if (uwsgi.reload_on_rss && (rlim_t) rss >= uwsgi.reload_on_rss && (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.shared->options[UWSGI_OPTION_MIN_WORKER_LIFETIME] * 1000000)) {
|
||||
if (uwsgi.reload_on_rss && (rlim_t) rss >= uwsgi.reload_on_rss && (end_of_request - (uwsgi.workers[uwsgi.mywid].last_spawn * 1000000) >= uwsgi.min_worker_lifetime * 1000000)) {
|
||||
goodbye_cruel_world();
|
||||
}
|
||||
|
||||
|
||||
// ready to accept request, if i am a vassal signal Emperor about my loyalty
|
||||
// after the first request, if i am a vassal, signal Emperor about my loyalty
|
||||
if (uwsgi.has_emperor && !uwsgi.loyal) {
|
||||
uwsgi_log("announcing my loyalty to the Emperor...\n");
|
||||
char byte = 17;
|
||||
@@ -1333,13 +1345,13 @@ int wsgi_req_async_recv(struct wsgi_request *wsgi_req) {
|
||||
if (event_queue_add_fd_read(uwsgi.async_queue, wsgi_req->fd) < 0)
|
||||
return -1;
|
||||
|
||||
async_add_timeout(wsgi_req, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
async_add_timeout(wsgi_req, uwsgi.socket_timeout);
|
||||
uwsgi.async_proto_fd_table[wsgi_req->fd] = wsgi_req;
|
||||
}
|
||||
|
||||
// enter harakiri mode
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
set_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1370,8 +1382,8 @@ int wsgi_req_recv(int queue, struct wsgi_request *wsgi_req) {
|
||||
}
|
||||
|
||||
// enter harakiri mode
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
set_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
#ifdef UWSGI_ROUTING
|
||||
@@ -1549,15 +1561,7 @@ void parse_sys_envs(char **envs) {
|
||||
char *earg, *eq_pos;
|
||||
|
||||
while (*uenvs) {
|
||||
if (!strncmp(*uenvs, "UWSGI_", 6) &&
|
||||
strncmp(*uenvs, "UWSGI_RELOADS=", 14) &&
|
||||
strncmp(*uenvs, "UWSGI_VASSALS_DIR=", 18) &&
|
||||
strncmp(*uenvs, "UWSGI_EMPEROR_FD=", 17) &&
|
||||
strncmp(*uenvs, "UWSGI_BROODLORD_NUM=", 20) &&
|
||||
strncmp(*uenvs, "UWSGI_EMPEROR_FD_CONFIG=", 24) &&
|
||||
strncmp(*uenvs, "UWSGI_EMPEROR_PROXY=", 20) &&
|
||||
strncmp(*uenvs, "UWSGI_JAIL_PID=", 15) &&
|
||||
strncmp(*uenvs, "UWSGI_ORIGINAL_PROC_NAME=", 25)) {
|
||||
if (!strncmp(*uenvs, "UWSGI_", 6) && strncmp(*uenvs, "UWSGI_RELOADS=", 14) && strncmp(*uenvs, "UWSGI_VASSALS_DIR=", 18) && strncmp(*uenvs, "UWSGI_EMPEROR_FD=", 17) && strncmp(*uenvs, "UWSGI_BROODLORD_NUM=", 20) && strncmp(*uenvs, "UWSGI_EMPEROR_FD_CONFIG=", 24) && strncmp(*uenvs, "UWSGI_EMPEROR_PROXY=", 20) && strncmp(*uenvs, "UWSGI_JAIL_PID=", 15) && strncmp(*uenvs, "UWSGI_ORIGINAL_PROC_NAME=", 25)) {
|
||||
earg = uwsgi_malloc(strlen(*uenvs + 6) + 1);
|
||||
env_to_arg(*uenvs + 6, earg);
|
||||
eq_pos = strchr(earg, '=');
|
||||
@@ -1860,7 +1864,7 @@ int uwsgi_num2str2n(int num, char *ptr, int size) {
|
||||
|
||||
int uwsgi_long2str2n(unsigned long long num, char *ptr, int size) {
|
||||
int ret = snprintf(ptr, size, "%llu", num);
|
||||
if (ret < 0)
|
||||
if (ret <= 0 || ret > size)
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -2768,6 +2772,7 @@ static struct uwsgi_unshare_id uwsgi_unshare_list[] = {
|
||||
{"ns", CLONE_NEWNS},
|
||||
{"fs", CLONE_NEWNS},
|
||||
{"mount", CLONE_NEWNS},
|
||||
{"mnt", CLONE_NEWNS},
|
||||
#endif
|
||||
#ifdef CLONE_SYSVSEM
|
||||
{"sysvsem", CLONE_SYSVSEM},
|
||||
@@ -2887,7 +2892,7 @@ static int uwsgi_get_cap_id(char *name) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int uwsgi_build_cap(char *what, cap_value_t **cap) {
|
||||
int uwsgi_build_cap(char *what, cap_value_t ** cap) {
|
||||
|
||||
int cap_id;
|
||||
char *caps = uwsgi_str(what);
|
||||
@@ -3181,128 +3186,139 @@ void http_url_decode(char *buf, uint16_t * len, char *dst) {
|
||||
|
||||
for (i = 0; i < *len; i++) {
|
||||
char c = buf[i];
|
||||
if (c == '#') break;
|
||||
switch(status) {
|
||||
case zero:
|
||||
if (c == '%') {
|
||||
status = percent1;
|
||||
break;
|
||||
}
|
||||
if (c == '/') {
|
||||
status = slash;
|
||||
break;
|
||||
}
|
||||
*ptr++ = c;
|
||||
new_len++;
|
||||
if (c == '#')
|
||||
break;
|
||||
switch (status) {
|
||||
case zero:
|
||||
if (c == '%') {
|
||||
status = percent1;
|
||||
break;
|
||||
case percent1:
|
||||
if (c == '%') {
|
||||
*ptr++ = '%';
|
||||
new_len++;
|
||||
status = zero;
|
||||
break;
|
||||
}
|
||||
value[0] = c;
|
||||
status = percent2;
|
||||
}
|
||||
if (c == '/') {
|
||||
status = slash;
|
||||
break;
|
||||
case percent2:
|
||||
value[1] = c;
|
||||
*ptr++ = hex2num(value);
|
||||
}
|
||||
*ptr++ = c;
|
||||
new_len++;
|
||||
break;
|
||||
case percent1:
|
||||
if (c == '%') {
|
||||
*ptr++ = '%';
|
||||
new_len++;
|
||||
status = zero;
|
||||
break;
|
||||
case slash:
|
||||
if (c == '.') {
|
||||
status = dot;
|
||||
break;
|
||||
}
|
||||
// we could be at the first round (in non slash)
|
||||
if (i > 0 || !no_slash) {
|
||||
*ptr++ = '/'; new_len++;
|
||||
}
|
||||
if (c == '%') {
|
||||
status = percent1;
|
||||
break;
|
||||
}
|
||||
if (c == '/') {
|
||||
status = slash;
|
||||
break;
|
||||
}
|
||||
*ptr++ = c; new_len++;
|
||||
status = zero;
|
||||
}
|
||||
value[0] = c;
|
||||
status = percent2;
|
||||
break;
|
||||
case percent2:
|
||||
value[1] = c;
|
||||
*ptr++ = hex2num(value);
|
||||
new_len++;
|
||||
status = zero;
|
||||
break;
|
||||
case slash:
|
||||
if (c == '.') {
|
||||
status = dot;
|
||||
break;
|
||||
case dot:
|
||||
if (c == '.') {
|
||||
status = dotdot;
|
||||
break;
|
||||
}
|
||||
if (c == '/') {
|
||||
status = slash;
|
||||
break;
|
||||
}
|
||||
if (i > 1) {
|
||||
*ptr++ = '/'; new_len++;
|
||||
}
|
||||
*ptr++ = '.'; new_len++;
|
||||
if (c == '%') {
|
||||
status = percent1;
|
||||
break;
|
||||
}
|
||||
*ptr++ = c; new_len++;
|
||||
status = zero;
|
||||
}
|
||||
// we could be at the first round (in non slash)
|
||||
if (i > 0 || !no_slash) {
|
||||
*ptr++ = '/';
|
||||
new_len++;
|
||||
}
|
||||
if (c == '%') {
|
||||
status = percent1;
|
||||
break;
|
||||
case dotdot:
|
||||
// here we need to remove a segment
|
||||
if (c == '/') {
|
||||
current_new_len = new_len;
|
||||
while(current_new_len) {
|
||||
current_new_len--;
|
||||
ptr--;
|
||||
if (dst[current_new_len] == '/') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (c == '/') {
|
||||
status = slash;
|
||||
break;
|
||||
}
|
||||
*ptr++ = c;
|
||||
new_len++;
|
||||
status = zero;
|
||||
break;
|
||||
case dot:
|
||||
if (c == '.') {
|
||||
status = dotdot;
|
||||
break;
|
||||
}
|
||||
if (c == '/') {
|
||||
status = slash;
|
||||
break;
|
||||
}
|
||||
if (i > 1) {
|
||||
*ptr++ = '/';
|
||||
new_len++;
|
||||
}
|
||||
*ptr++ = '.';
|
||||
new_len++;
|
||||
if (c == '%') {
|
||||
status = percent1;
|
||||
break;
|
||||
}
|
||||
*ptr++ = c;
|
||||
new_len++;
|
||||
status = zero;
|
||||
break;
|
||||
case dotdot:
|
||||
// here we need to remove a segment
|
||||
if (c == '/') {
|
||||
current_new_len = new_len;
|
||||
while (current_new_len) {
|
||||
current_new_len--;
|
||||
ptr--;
|
||||
if (dst[current_new_len] == '/') {
|
||||
break;
|
||||
}
|
||||
new_len = current_new_len;
|
||||
status = slash;
|
||||
break;
|
||||
}
|
||||
if (i > 2) {
|
||||
*ptr++ = '/'; new_len++;
|
||||
}
|
||||
*ptr++ = '.'; new_len++;
|
||||
*ptr++ = '.'; new_len++;
|
||||
if (c == '%') {
|
||||
status = percent1;
|
||||
break;
|
||||
}
|
||||
*ptr++ = c; new_len++;
|
||||
status = zero;
|
||||
break;
|
||||
new_len = current_new_len;
|
||||
status = slash;
|
||||
break;
|
||||
}
|
||||
if (i > 2) {
|
||||
*ptr++ = '/';
|
||||
new_len++;
|
||||
}
|
||||
*ptr++ = '.';
|
||||
new_len++;
|
||||
*ptr++ = '.';
|
||||
new_len++;
|
||||
if (c == '%') {
|
||||
status = percent1;
|
||||
break;
|
||||
}
|
||||
*ptr++ = c;
|
||||
new_len++;
|
||||
status = zero;
|
||||
break;
|
||||
// over engineering
|
||||
default:
|
||||
*ptr++ = c;
|
||||
new_len++;
|
||||
break;
|
||||
default:
|
||||
*ptr++ = c;
|
||||
new_len++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch(status) {
|
||||
case slash:
|
||||
case dot:
|
||||
*ptr++ = '/'; new_len++;
|
||||
break;
|
||||
case dotdot:
|
||||
current_new_len = new_len;
|
||||
while(current_new_len) {
|
||||
if (dst[current_new_len-1] == '/') {
|
||||
break;
|
||||
}
|
||||
current_new_len--;
|
||||
switch (status) {
|
||||
case slash:
|
||||
case dot:
|
||||
*ptr++ = '/';
|
||||
new_len++;
|
||||
break;
|
||||
case dotdot:
|
||||
current_new_len = new_len;
|
||||
while (current_new_len) {
|
||||
if (dst[current_new_len - 1] == '/') {
|
||||
break;
|
||||
}
|
||||
new_len = current_new_len;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
current_new_len--;
|
||||
}
|
||||
new_len = current_new_len;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
*len = new_len;
|
||||
@@ -3562,7 +3578,7 @@ void uwsgi_set_cpu_affinity() {
|
||||
base_cpu = base_cpu % uwsgi.cpus;
|
||||
}
|
||||
ret = snprintf(buf, 4096, "mapping worker %d to CPUs:", uwsgi.mywid);
|
||||
if (ret < 25) {
|
||||
if (ret < 25 || ret >= 4096) {
|
||||
uwsgi_log("unable to initialize cpu affinity !!!\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -3580,7 +3596,7 @@ void uwsgi_set_cpu_affinity() {
|
||||
base_cpu = 0;
|
||||
CPU_SET(base_cpu, &cpuset);
|
||||
ret = snprintf(buf + pos, 4096 - pos, " %d", base_cpu);
|
||||
if (ret < 2) {
|
||||
if (ret < 2 || ret >= 4096) {
|
||||
uwsgi_log("unable to initialize cpu affinity !!!\n");
|
||||
exit(1);
|
||||
}
|
||||
@@ -3843,7 +3859,7 @@ int uwsgi_send_http_stats(int fd) {
|
||||
|
||||
char buf[4096];
|
||||
|
||||
int ret = uwsgi_waitfd(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd(fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0)
|
||||
return -1;
|
||||
|
||||
@@ -3922,23 +3938,26 @@ char *uwsgi_strip(char *src) {
|
||||
|
||||
void uwsgi_uuid(char *buf) {
|
||||
#ifdef UWSGI_UUID
|
||||
uuid_t uuid_zmq;
|
||||
uuid_generate(uuid_zmq);
|
||||
uuid_unparse(uuid_zmq, buf);
|
||||
uuid_t uuid_value;
|
||||
uuid_generate(uuid_value);
|
||||
uuid_unparse(uuid_value, buf);
|
||||
#else
|
||||
int i,r[11];
|
||||
if (!uwsgi_file_exists("/dev/urandom")) goto fallback;
|
||||
int i, r[11];
|
||||
if (!uwsgi_file_exists("/dev/urandom"))
|
||||
goto fallback;
|
||||
int fd = open("/dev/urandom", O_RDONLY);
|
||||
if (fd < 0) goto fallback;
|
||||
for(i=0;i<11;i++) {
|
||||
if (fd < 0)
|
||||
goto fallback;
|
||||
for (i = 0; i < 11; i++) {
|
||||
if (read(fd, &r[i], 4) != 4) {
|
||||
close(fd); goto fallback;
|
||||
close(fd);
|
||||
goto fallback;
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
goto done;
|
||||
fallback:
|
||||
for(i=0;i<11;i++) {
|
||||
for (i = 0; i < 11; i++) {
|
||||
r[i] = rand();
|
||||
}
|
||||
done:
|
||||
@@ -4328,15 +4347,84 @@ void uwsgi_exit(int status) {
|
||||
}
|
||||
|
||||
int uwsgi_base128(struct uwsgi_buffer *ub, uint64_t l, int first) {
|
||||
if( l > 127 ) {
|
||||
if (uwsgi_base128(ub, l/128, 0)) return -1;
|
||||
if (l > 127) {
|
||||
if (uwsgi_base128(ub, l / 128, 0))
|
||||
return -1;
|
||||
}
|
||||
l %= 128;
|
||||
if(first) {
|
||||
if (uwsgi_buffer_u8(ub, (uint8_t) l)) return -1;
|
||||
if (first) {
|
||||
if (uwsgi_buffer_u8(ub, (uint8_t) l))
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
if (uwsgi_buffer_u8(ub, 0x80 | (uint8_t) l)) return -1;
|
||||
if (uwsgi_buffer_u8(ub, 0x80 | (uint8_t) l))
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
void uwsgi_setns(char *path) {
|
||||
int (*u_setns) (int, int) = (int (*)(int, int)) dlsym(RTLD_DEFAULT, "setns");
|
||||
if (!u_setns) {
|
||||
uwsgi_log("your system misses setns() syscall !!!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// cound be overwritten
|
||||
int count = 64;
|
||||
|
||||
uwsgi_log("joining namespaces from %s ...\n", path);
|
||||
for (;;) {
|
||||
int ns_fd = uwsgi_connect(path, 30, 0);
|
||||
if (ns_fd < 0) {
|
||||
uwsgi_error("uwsgi_setns()/uwsgi_connect()");
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
int *fds = uwsgi_attach_fd(ns_fd, &count, "uwsgi-setns", 11);
|
||||
if (fds && count > 0) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
if (fds[i] > -1) {
|
||||
if (u_setns(fds[i], 0) < 0) {
|
||||
uwsgi_error("uwsgi_setns()/setns()");
|
||||
exit(1);
|
||||
}
|
||||
close(fds[i]);
|
||||
}
|
||||
}
|
||||
free(fds);
|
||||
break;
|
||||
}
|
||||
if (fds)
|
||||
free(fds);
|
||||
close(ns_fd);
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
mode_t uwsgi_mode_t(char *value, int *error) {
|
||||
mode_t mode = 0;
|
||||
*error = 0;
|
||||
|
||||
if (strlen(value) < 3) {
|
||||
*error = 1;
|
||||
return mode;
|
||||
}
|
||||
|
||||
if (strlen(value) == 3) {
|
||||
mode = (mode << 3) + (value[0] - '0');
|
||||
mode = (mode << 3) + (value[1] - '0');
|
||||
mode = (mode << 3) + (value[2] - '0');
|
||||
}
|
||||
else {
|
||||
mode = (mode << 3) + (value[1] - '0');
|
||||
mode = (mode << 3) + (value[2] - '0');
|
||||
mode = (mode << 3) + (value[3] - '0');
|
||||
}
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
|
||||
+228
-112
@@ -76,13 +76,13 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"processes", required_argument, 'p', "spawn the specified number of workers/processes", uwsgi_opt_set_int, &uwsgi.numproc, 0},
|
||||
{"workers", required_argument, 'p', "spawn the specified number of workers/processes", uwsgi_opt_set_int, &uwsgi.numproc, 0},
|
||||
{"thunder-lock", no_argument, 0, "serialize accept() usage (if possible)", uwsgi_opt_true, &uwsgi.use_thunder_lock, 0},
|
||||
{"harakiri", required_argument, 't', "set harakiri timeout", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_HARAKIRI, 0},
|
||||
{"harakiri", required_argument, 't', "set harakiri timeout", uwsgi_opt_set_int, &uwsgi.harakiri_options.workers, 0},
|
||||
{"harakiri-verbose", no_argument, 0, "enable verbose mode for harakiri", uwsgi_opt_true, &uwsgi.harakiri_verbose, 0},
|
||||
{"harakiri-no-arh", no_argument, 0, "do not enable harakiri during after-request-hook", uwsgi_opt_true, &uwsgi.harakiri_no_arh, 0},
|
||||
{"no-harakiri-arh", no_argument, 0, "do not enable harakiri during after-request-hook", uwsgi_opt_true, &uwsgi.harakiri_no_arh, 0},
|
||||
{"no-harakiri-after-req-hook", no_argument, 0, "do not enable harakiri during after-request-hook", uwsgi_opt_true, &uwsgi.harakiri_no_arh, 0},
|
||||
{"backtrace-depth", required_argument, 0, "set backtrace depth", uwsgi_opt_set_int, &uwsgi.backtrace_depth, 0},
|
||||
{"mule-harakiri", required_argument, 0, "set harakiri timeout for mule tasks", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MULE_HARAKIRI, 0},
|
||||
{"mule-harakiri", required_argument, 0, "set harakiri timeout for mule tasks", uwsgi_opt_set_int, &uwsgi.harakiri_options.mules, 0},
|
||||
#ifdef UWSGI_XML
|
||||
{"xmlconfig", required_argument, 'x', "load config from xml file", uwsgi_opt_load_xml, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"xml", required_argument, 'x', "load config from xml file", uwsgi_opt_load_xml, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
@@ -99,6 +99,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"set-ph", required_argument, 0, "set a placeholder", uwsgi_opt_set_placeholder, (void *) 1, UWSGI_OPT_IMMEDIATE},
|
||||
{"get", required_argument, 0, "print the specified option value and exit", uwsgi_opt_add_string_list, &uwsgi.get_list, UWSGI_OPT_NO_INITIAL},
|
||||
{"declare-option", required_argument, 0, "declare a new uWSGI custom option", uwsgi_opt_add_custom_option, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"declare-option2", required_argument, 0, "declare a new uWSGI custom option (non-immediate)", uwsgi_opt_add_custom_option, NULL, 0},
|
||||
|
||||
{"for", required_argument, 0, "(opt logic) for cycle", uwsgi_opt_logic, (void *) uwsgi_logic_opt_for, UWSGI_OPT_IMMEDIATE},
|
||||
{"for-glob", required_argument, 0, "(opt logic) for cycle (expand glob)", uwsgi_opt_logic, (void *) uwsgi_logic_opt_for_glob, UWSGI_OPT_IMMEDIATE},
|
||||
@@ -164,9 +165,9 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"max-vars", required_argument, 'v', "set the amount of internal iovec/vars structures", uwsgi_opt_max_vars, NULL, 0},
|
||||
{"max-apps", required_argument, 0, "set the maximum number of per-worker applications", uwsgi_opt_set_int, &uwsgi.max_apps, 0},
|
||||
{"buffer-size", required_argument, 'b', "set internal buffer size", uwsgi_opt_set_16bit, &uwsgi.buffer_size, 0},
|
||||
{"memory-report", no_argument, 'm', "enable memory report", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_MEMORY_DEBUG, 0},
|
||||
{"memory-report", no_argument, 'm', "enable memory report", uwsgi_opt_true, &uwsgi.logging_options.memory_report, 0},
|
||||
{"profiler", required_argument, 0, "enable the specified profiler", uwsgi_opt_set_str, &uwsgi.profiler, 0},
|
||||
{"cgi-mode", no_argument, 'c', "force CGI-mode for plugins supporting it", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_CGI_MODE, 0},
|
||||
{"cgi-mode", no_argument, 'c', "force CGI-mode for plugins supporting it", uwsgi_opt_true, &uwsgi.cgi_mode, 0},
|
||||
{"abstract-socket", no_argument, 'a', "force UNIX socket in abstract mode (Linux only)", uwsgi_opt_true, &uwsgi.abstract_socket, 0},
|
||||
{"chmod-socket", optional_argument, 'C', "chmod-socket", uwsgi_opt_chmod_socket, NULL, 0},
|
||||
{"chmod", optional_argument, 'C', "chmod-socket", uwsgi_opt_chmod_socket, NULL, 0},
|
||||
@@ -248,18 +249,18 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"print-sym", required_argument, 0, "print content of the specified binary symbol", uwsgi_print_sym, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"print-symbol", required_argument, 0, "print content of the specified binary symbol", uwsgi_print_sym, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
|
||||
{"reaper", no_argument, 'r', "call waitpid(-1,...) after each request to get rid of zombies", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_REAPER, 0},
|
||||
{"max-requests", required_argument, 'R', "reload workers after the specified amount of managed requests", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MAX_REQUESTS, 0},
|
||||
{"min-worker-lifetime", required_argument, 0, "number of seconds worker must run before being reloaded (default is 60)", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MIN_WORKER_LIFETIME, 0},
|
||||
{"max-worker-lifetime", required_argument, 0, "reload workers after the specified amount of seconds (default is disabled)", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MAX_WORKER_LIFETIME, 0},
|
||||
{"reaper", no_argument, 'r', "call waitpid(-1,...) after each request to get rid of zombies", uwsgi_opt_true, &uwsgi.reaper, 0},
|
||||
{"max-requests", required_argument, 'R', "reload workers after the specified amount of managed requests", uwsgi_opt_set_64bit, &uwsgi.max_requests, 0},
|
||||
{"min-worker-lifetime", required_argument, 0, "number of seconds worker must run before being reloaded (default is 60)", uwsgi_opt_set_64bit, &uwsgi.min_worker_lifetime, 0},
|
||||
{"max-worker-lifetime", required_argument, 0, "reload workers after the specified amount of seconds (default is disabled)", uwsgi_opt_set_64bit, &uwsgi.max_worker_lifetime, 0},
|
||||
|
||||
{"socket-timeout", required_argument, 'z', "set internal sockets timeout", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_SOCKET_TIMEOUT, 0},
|
||||
{"socket-timeout", required_argument, 'z', "set internal sockets timeout", uwsgi_opt_set_int, &uwsgi.socket_timeout, 0},
|
||||
{"no-fd-passing", no_argument, 0, "disable file descriptor passing", uwsgi_opt_true, &uwsgi.no_fd_passing, 0},
|
||||
{"locks", required_argument, 0, "create the specified number of shared locks", uwsgi_opt_set_int, &uwsgi.locks, 0},
|
||||
{"lock-engine", required_argument, 0, "set the lock engine", uwsgi_opt_set_str, &uwsgi.lock_engine, 0},
|
||||
{"ftok", required_argument, 0, "set the ipcsem key via ftok() for avoiding duplicates", uwsgi_opt_set_str, &uwsgi.ftok, 0},
|
||||
{"persistent-ipcsem", no_argument, 0, "do not remove ipcsem's on shutdown", uwsgi_opt_true, &uwsgi.persistent_ipcsem, 0},
|
||||
{"sharedarea", required_argument, 'A', "create a raw shared memory area of specified pages", uwsgi_opt_set_int, &uwsgi.sharedareasize, 0},
|
||||
{"sharedarea", required_argument, 'A', "create a raw shared memory area of specified pages (note: it supports keyval too)", uwsgi_opt_add_string_list, &uwsgi.sharedareas_list, 0},
|
||||
|
||||
{"safe-fd", required_argument, 0, "do not close the specified file descriptor", uwsgi_opt_safe_fd, NULL, 0},
|
||||
{"fd-safe", required_argument, 0, "do not close the specified file descriptor", uwsgi_opt_safe_fd, NULL, 0},
|
||||
@@ -297,7 +298,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"spooler-processes", required_argument, 0, "set the number of processes for spoolers", uwsgi_opt_set_int, &uwsgi.spooler_numproc, UWSGI_OPT_IMMEDIATE},
|
||||
{"spooler-quiet", no_argument, 0, "do not be verbose with spooler tasks", uwsgi_opt_true, &uwsgi.spooler_quiet, 0},
|
||||
{"spooler-max-tasks", required_argument, 0, "set the maximum number of tasks to run before recycling a spooler", uwsgi_opt_set_int, &uwsgi.spooler_max_tasks, 0},
|
||||
{"spooler-harakiri", required_argument, 0, "set harakiri timeout for spooler tasks", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_SPOOLER_HARAKIRI, 0},
|
||||
{"spooler-harakiri", required_argument, 0, "set harakiri timeout for spooler tasks", uwsgi_opt_set_int, &uwsgi.harakiri_options.spoolers, 0},
|
||||
|
||||
{"mule", optional_argument, 0, "add a mule", uwsgi_opt_add_mule, NULL, UWSGI_OPT_MASTER},
|
||||
{"mules", required_argument, 0, "add the specified number of mules", uwsgi_opt_add_mules, NULL, UWSGI_OPT_MASTER},
|
||||
@@ -316,7 +317,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
|
||||
{"rpc-max", required_argument, 0, "maximum number of rpc slots (default: 64)", uwsgi_opt_set_64bit, &uwsgi.rpc_max, 0},
|
||||
|
||||
{"disable-logging", no_argument, 'L', "disable request logging", uwsgi_opt_dyn_false, (void *) UWSGI_OPTION_LOGGING, 0},
|
||||
{"disable-logging", no_argument, 'L', "disable request logging", uwsgi_opt_false, &uwsgi.logging_options.enabled, 0},
|
||||
|
||||
{"flock", required_argument, 0, "lock the specified file before starting, exit if locked", uwsgi_opt_flock, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"flock-wait", required_argument, 0, "lock the specified file before starting, wait if locked", uwsgi_opt_flock_wait, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
@@ -344,7 +345,13 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
#ifdef __linux__
|
||||
{"unshare", required_argument, 0, "unshare() part of the processes and put it in a new namespace", uwsgi_opt_set_unshare, &uwsgi.unshare, 0},
|
||||
{"unshare2", required_argument, 0, "unshare() part of the processes and put it in a new namespace after rootfs change", uwsgi_opt_set_unshare, &uwsgi.unshare2, 0},
|
||||
{"setns-socket", required_argument, 0, "expose a unix socket returning namespace fds from /proc/self/ns", uwsgi_opt_set_str, &uwsgi.setns_socket, UWSGI_OPT_MASTER},
|
||||
{"setns-socket-skip", required_argument, 0, "skip the specified entry when sending setns file descriptors", uwsgi_opt_add_string_list, &uwsgi.setns_socket_skip, 0},
|
||||
{"setns-skip", required_argument, 0, "skip the specified entry when sending setns file descriptors", uwsgi_opt_add_string_list, &uwsgi.setns_socket_skip, 0},
|
||||
{"setns", required_argument, 0, "join a namespace created by an external uWSGI instance", uwsgi_opt_set_str, &uwsgi.setns, 0},
|
||||
{"setns-preopen", no_argument, 0, "open /proc/self/ns as soon as possible and cache fds", uwsgi_opt_true, &uwsgi.setns_preopen, 0},
|
||||
#endif
|
||||
{"jailed", no_argument, 0, "mark the instance as jailed (force the execution of post_jail hooks)", uwsgi_opt_true, &uwsgi.jailed, 0},
|
||||
#if defined(__FreeBSD__) || defined(__GNU_kFreeBSD__)
|
||||
{"jail", required_argument, 0, "put the instance in a FreeBSD jail", uwsgi_opt_set_str, &uwsgi.jail, 0},
|
||||
{"jail-ip4", required_argument, 0, "add an ipv4 address to the FreeBSD jail", uwsgi_opt_add_string_list, &uwsgi.jail_ip4, 0},
|
||||
@@ -373,9 +380,22 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"hook-as-user-atexit", required_argument, 0, "run the specified hook before app exit and reload", uwsgi_opt_add_string_list, &uwsgi.hook_as_user_atexit, 0},
|
||||
{"hook-pre-app", required_argument, 0, "run the specified hook before app loading", uwsgi_opt_add_string_list, &uwsgi.hook_pre_app, 0},
|
||||
{"hook-post-app", required_argument, 0, "run the specified hook after app loading", uwsgi_opt_add_string_list, &uwsgi.hook_post_app, 0},
|
||||
{"hook-accepting", required_argument, 0, "run the specified hook after each worker enter the accepting phase", uwsgi_opt_add_string_list, &uwsgi.hook_accepting, 0},
|
||||
{"hook-accepting1", required_argument, 0, "run the specified hook after the first worker enters the accepting phase", uwsgi_opt_add_string_list, &uwsgi.hook_accepting1, 0},
|
||||
{"hook-accepting-once", required_argument, 0, "run the specified hook after each worker enter the accepting phase (once per-instance)", uwsgi_opt_add_string_list, &uwsgi.hook_accepting_once, 0},
|
||||
{"hook-accepting1-once", required_argument, 0, "run the specified hook after the first worker enters the accepting phase (once per instance)", uwsgi_opt_add_string_list, &uwsgi.hook_accepting1_once, 0},
|
||||
|
||||
{"hook-as-vassal", required_argument, 0, "run the specified command before exec()ing the vassal", uwsgi_opt_add_string_list, &uwsgi.hook_as_vassal, 0},
|
||||
{"hook-as-emperor", required_argument, 0, "run the specified command in the emperor after the vassal has been started", uwsgi_opt_add_string_list, &uwsgi.hook_as_emperor, 0},
|
||||
{"hook-emperor-stop", required_argument, 0, "run the specified hook when the Emperor send a stop message", uwsgi_opt_add_string_list, &uwsgi.hook_emperor_stop, 0},
|
||||
{"hook-emperor-reload", required_argument, 0, "run the specified hook when the Emperor send a reload message", uwsgi_opt_add_string_list, &uwsgi.hook_emperor_reload, 0},
|
||||
{"hook-emperor-lost", required_argument, 0, "run the specified hook when the Emperor connection is lost", uwsgi_opt_add_string_list, &uwsgi.hook_emperor_lost, 0},
|
||||
|
||||
{"hook-as-vassal", required_argument, 0, "run the specified hook before exec()ing the vassal", uwsgi_opt_add_string_list, &uwsgi.hook_as_vassal, 0},
|
||||
{"hook-as-emperor", required_argument, 0, "run the specified hook in the emperor after the vassal has been started", uwsgi_opt_add_string_list, &uwsgi.hook_as_emperor, 0},
|
||||
|
||||
{"hook-as-mule", required_argument, 0, "run the specified hook in each mule", uwsgi_opt_add_string_list, &uwsgi.hook_as_mule, 0},
|
||||
|
||||
{"after-request-hook", required_argument, 0, "run the specified function/symbol after each request", uwsgi_opt_add_string_list, &uwsgi.after_request_hooks, 0},
|
||||
{"after-request-call", required_argument, 0, "run the specified function/symbol after each request", uwsgi_opt_add_string_list, &uwsgi.after_request_hooks, 0},
|
||||
|
||||
{"exec-asap", required_argument, 0, "run the specified command as soon as possible", uwsgi_opt_add_string_list, &uwsgi.exec_asap, 0},
|
||||
{"exec-pre-jail", required_argument, 0, "run the specified command before jailing", uwsgi_opt_add_string_list, &uwsgi.exec_pre_jail, 0},
|
||||
@@ -449,12 +469,6 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
#ifdef UWSGI_JSON
|
||||
{"json", required_argument, 'j', "load config from json file", uwsgi_opt_load_json, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"js", required_argument, 'j', "load config from json file", uwsgi_opt_load_json, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
#endif
|
||||
#ifdef UWSGI_ZEROMQ
|
||||
{"zeromq", required_argument, 0, "create a zeromq pub/sub pair", uwsgi_opt_add_lazy_socket, "zmq", 0},
|
||||
{"zmq", required_argument, 0, "create a zeromq pub/sub pair", uwsgi_opt_add_lazy_socket, "zmq", 0},
|
||||
{"zeromq-socket", required_argument, 0, "create a zeromq pub/sub pair", uwsgi_opt_add_lazy_socket, "zmq", 0},
|
||||
{"zmq-socket", required_argument, 0, "create a zeromq pub/sub pair", uwsgi_opt_add_lazy_socket, "zmq", 0},
|
||||
#endif
|
||||
{"weight", required_argument, 0, "weight of the instance (used by clustering/lb/subscriptions)", uwsgi_opt_set_64bit, &uwsgi.weight, 0},
|
||||
{"auto-weight", required_argument, 0, "set weight of the instance (used by clustering/lb/subscriptions) automatically", uwsgi_opt_true, &uwsgi.auto_weight, 0},
|
||||
@@ -570,6 +584,8 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"subscriptions-sign-check", required_argument, 0, "set digest algorithm and certificate directory for secured subscription system", uwsgi_opt_scd, NULL, UWSGI_OPT_MASTER},
|
||||
{"subscriptions-sign-check-tolerance", required_argument, 0, "set the maximum tolerance (in seconds) of clock skew for secured subscription system", uwsgi_opt_set_int, &uwsgi.subscriptions_sign_check_tolerance, UWSGI_OPT_MASTER},
|
||||
#endif
|
||||
{"subscriptions-credentials-check", required_argument, 0, "add a directory to search for subscriptions key credentials", uwsgi_opt_add_string_list, &uwsgi.subscriptions_credentials_check_dir, UWSGI_OPT_MASTER},
|
||||
{"subscriptions-use-credentials", no_argument, 0, "enable management of SCM_CREDENTIALS in subscriptions UNIX sockets", uwsgi_opt_true, &uwsgi.subscriptions_use_credentials, 0},
|
||||
{"subscription-algo", required_argument, 0, "set load balancing algorithm for the subscription system", uwsgi_opt_ssa, NULL, 0},
|
||||
{"subscription-dotsplit", no_argument, 0, "try to fallback to the next part (dot based) in subscription key", uwsgi_opt_true, &uwsgi.subscription_dotsplit, 0},
|
||||
{"subscribe-to", required_argument, 0, "subscribe to the specified subscription server", uwsgi_opt_add_string_list, &uwsgi.subscriptions, UWSGI_OPT_MASTER},
|
||||
@@ -595,7 +611,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"sni-regexp", required_argument, 0, "add an SNI-governed SSL context (the key is a regexp)", uwsgi_opt_sni, NULL, 0},
|
||||
#endif
|
||||
#endif
|
||||
{"check-interval", required_argument, 0, "set the interval (in seconds) of master checks", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_MASTER_INTERVAL, 0},
|
||||
{"check-interval", required_argument, 0, "set the interval (in seconds) of master checks", uwsgi_opt_set_int, &uwsgi.master_interval, UWSGI_OPT_MASTER},
|
||||
{"forkbomb-delay", required_argument, 0, "sleep for the specified number of seconds when a forkbomb is detected", uwsgi_opt_set_int, &uwsgi.forkbomb_delay, UWSGI_OPT_MASTER},
|
||||
{"binary-path", required_argument, 0, "force binary path", uwsgi_opt_set_str, &uwsgi.binary_path, 0},
|
||||
{"privileged-binary-patch", required_argument, 0, "patch the uwsgi binary with a new command (before privileges drop)", uwsgi_opt_set_str, &uwsgi.privileged_binary_patch, 0},
|
||||
@@ -649,9 +665,6 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"alarm-list", no_argument, 0, "list enabled alarms", uwsgi_opt_true, &uwsgi.alarms_list, 0},
|
||||
{"alarms-list", no_argument, 0, "list enabled alarms", uwsgi_opt_true, &uwsgi.alarms_list, 0},
|
||||
{"alarm-msg-size", required_argument, 0, "set the max size of an alarm message (default 8192)", uwsgi_opt_set_64bit, &uwsgi.alarm_msg_size, 0},
|
||||
#ifdef UWSGI_ZEROMQ
|
||||
{"log-zeromq", required_argument, 0, "send logs to a zeromq server", uwsgi_opt_set_logger, "zeromq", UWSGI_OPT_MASTER | UWSGI_OPT_LOG_MASTER},
|
||||
#endif
|
||||
{"log-master", no_argument, 0, "delegate logging to master process", uwsgi_opt_true, &uwsgi.log_master, UWSGI_OPT_MASTER},
|
||||
{"log-master-bufsize", required_argument, 0, "set the buffer size for the master logger. bigger log messages will be truncated", uwsgi_opt_set_64bit, &uwsgi.log_master_bufsize, 0},
|
||||
{"log-master-stream", no_argument, 0, "create the master logpipe as SOCK_STREAM", uwsgi_opt_true, &uwsgi.log_master_stream, 0},
|
||||
@@ -665,14 +678,15 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"log-date", optional_argument, 0, "prefix logs with date or a strftime string", uwsgi_opt_log_date, NULL, 0},
|
||||
{"log-prefix", optional_argument, 0, "prefix logs with a string", uwsgi_opt_log_date, NULL, 0},
|
||||
|
||||
{"log-zero", no_argument, 0, "log responses without body", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_LOG_ZERO, 0},
|
||||
{"log-slow", required_argument, 0, "log requests slower than the specified number of milliseconds", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_LOG_SLOW, 0},
|
||||
{"log-4xx", no_argument, 0, "log requests with a 4xx response", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_LOG_4xx, 0},
|
||||
{"log-5xx", no_argument, 0, "log requests with a 5xx response", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_LOG_5xx, 0},
|
||||
{"log-big", required_argument, 0, "log requestes bigger than the specified size", uwsgi_opt_set_dyn, (void *) UWSGI_OPTION_LOG_BIG, 0},
|
||||
{"log-sendfile", required_argument, 0, "log sendfile requests", uwsgi_opt_dyn_true, (void *) UWSGI_OPTION_LOG_SENDFILE, 0},
|
||||
{"log-zero", no_argument, 0, "log responses without body", uwsgi_opt_true, &uwsgi.logging_options.zero, 0},
|
||||
{"log-slow", required_argument, 0, "log requests slower than the specified number of milliseconds", uwsgi_opt_set_int, &uwsgi.logging_options.slow, 0},
|
||||
{"log-4xx", no_argument, 0, "log requests with a 4xx response", uwsgi_opt_true, &uwsgi.logging_options._4xx, 0},
|
||||
{"log-5xx", no_argument, 0, "log requests with a 5xx response", uwsgi_opt_true, &uwsgi.logging_options._5xx, 0},
|
||||
{"log-big", required_argument, 0, "log requestes bigger than the specified size", uwsgi_opt_set_64bit, &uwsgi.logging_options.big, 0},
|
||||
{"log-sendfile", required_argument, 0, "log sendfile requests", uwsgi_opt_true, &uwsgi.logging_options.sendfile, 0},
|
||||
{"log-ioerror", required_argument, 0, "log requests with io errors", uwsgi_opt_true, &uwsgi.logging_options.ioerror, 0},
|
||||
{"log-micros", no_argument, 0, "report response time in microseconds instead of milliseconds", uwsgi_opt_true, &uwsgi.log_micros, 0},
|
||||
{"log-x-forwarded-for", no_argument, 0, "use the ip from X-Forwarded-For header instead of REMOTE_ADDR", uwsgi_opt_true, &uwsgi.log_x_forwarded_for, 0},
|
||||
{"log-x-forwarded-for", no_argument, 0, "use the ip from X-Forwarded-For header instead of REMOTE_ADDR", uwsgi_opt_true, &uwsgi.logging_options.log_x_forwarded_for, 0},
|
||||
{"master-as-root", no_argument, 0, "leave master process running as root", uwsgi_opt_true, &uwsgi.master_as_root, 0},
|
||||
|
||||
{"drop-after-init", no_argument, 0, "run privileges drop after plugin initialization", uwsgi_opt_true, &uwsgi.drop_after_init, 0},
|
||||
@@ -687,7 +701,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"cheap", no_argument, 0, "set cheap mode (spawn workers only after the first request)", uwsgi_opt_true, &uwsgi.status.is_cheap, UWSGI_OPT_MASTER},
|
||||
{"cheaper", required_argument, 0, "set cheaper mode (adaptive process spawning)", uwsgi_opt_set_int, &uwsgi.cheaper_count, UWSGI_OPT_MASTER | UWSGI_OPT_CHEAPER},
|
||||
{"cheaper-initial", required_argument, 0, "set the initial number of processes to spawn in cheaper mode", uwsgi_opt_set_int, &uwsgi.cheaper_initial, UWSGI_OPT_MASTER | UWSGI_OPT_CHEAPER},
|
||||
{"cheaper-algo", required_argument, 0, "choose to algorithm used for adaptive process spawning)", uwsgi_opt_set_str, &uwsgi.requested_cheaper_algo, UWSGI_OPT_MASTER},
|
||||
{"cheaper-algo", required_argument, 0, "choose to algorithm used for adaptive process spawning", uwsgi_opt_set_str, &uwsgi.requested_cheaper_algo, UWSGI_OPT_MASTER},
|
||||
{"cheaper-step", required_argument, 0, "number of additional processes to spawn at each overload", uwsgi_opt_set_int, &uwsgi.cheaper_step, UWSGI_OPT_MASTER | UWSGI_OPT_CHEAPER},
|
||||
{"cheaper-overload", required_argument, 0, "increase workers after specified overload", uwsgi_opt_set_64bit, &uwsgi.cheaper_overload, UWSGI_OPT_MASTER | UWSGI_OPT_CHEAPER},
|
||||
{"cheaper-algo-list", no_argument, 0, "list enabled cheapers algorithms", uwsgi_opt_true, &uwsgi.cheaper_algo_list, 0},
|
||||
@@ -770,6 +784,11 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"routers-list", no_argument, 0, "list enabled routers", uwsgi_opt_true, &uwsgi.router_list, 0},
|
||||
#endif
|
||||
|
||||
|
||||
{"error-page-403", required_argument, 0, "add an error page (html) for managed 403 response", uwsgi_opt_add_string_list, &uwsgi.error_page_403, 0},
|
||||
{"error-page-404", required_argument, 0, "add an error page (html) for managed 404 response", uwsgi_opt_add_string_list, &uwsgi.error_page_404, 0},
|
||||
{"error-page-500", required_argument, 0, "add an error page (html) for managed 500 response", uwsgi_opt_add_string_list, &uwsgi.error_page_500, 0},
|
||||
|
||||
{"websockets-ping-freq", required_argument, 0, "set the frequency (in seconds) of websockets automatic ping packets", uwsgi_opt_set_int, &uwsgi.websockets_ping_freq, 0},
|
||||
{"websocket-ping-freq", required_argument, 0, "set the frequency (in seconds) of websockets automatic ping packets", uwsgi_opt_set_int, &uwsgi.websockets_ping_freq, 0},
|
||||
|
||||
@@ -895,6 +914,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"legion-smart-attach-daemon2", required_argument, 0, "same as --smart-attach-daemon2 but daemon runs only on legion lord node", uwsgi_opt_add_daemon, NULL, UWSGI_OPT_MASTER},
|
||||
#endif
|
||||
{"daemons-honour-stdin", no_argument, 0, "do not change the stdin of external daemons to /dev/null", uwsgi_opt_true, &uwsgi.daemons_honour_stdin, UWSGI_OPT_MASTER},
|
||||
{"attach-daemon2", required_argument, 0, "attach-daemon keyval variant (supports smart modes too)", uwsgi_opt_add_daemon2, NULL, UWSGI_OPT_MASTER},
|
||||
{"plugins", required_argument, 0, "load uWSGI plugins", uwsgi_opt_load_plugin, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"plugin", required_argument, 0, "load uWSGI plugins", uwsgi_opt_load_plugin, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"need-plugins", required_argument, 0, "load uWSGI plugins (exit on error)", uwsgi_opt_load_plugin, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
@@ -916,6 +936,8 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"exit", optional_argument, 0, "force exit() of the instance", uwsgi_opt_exit, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"cflags", no_argument, 0, "report uWSGI CFLAGS (useful for building external plugins)", uwsgi_opt_cflags, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"dot-h", no_argument, 0, "dump the uwsgi.h used for building the core (useful for building external plugins)", uwsgi_opt_dot_h, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"config-py", no_argument, 0, "dump the uwsgiconfig.py used for building the core (useful for building external plugins)", uwsgi_opt_config_py, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"build-plugin", required_argument, 0, "build a uWSGI plugin for the current binary", uwsgi_opt_build_plugin, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
{"version", no_argument, 0, "print uWSGI version", uwsgi_opt_print, UWSGI_VERSION, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0}
|
||||
};
|
||||
@@ -1354,7 +1376,7 @@ void what_i_am_doing() {
|
||||
#else
|
||||
ctime_r((const time_t *) &wsgi_req->start_of_request_in_sec, ctime_storage);
|
||||
#endif
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now()) {
|
||||
if (uwsgi.harakiri_options.workers > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now()) {
|
||||
uwsgi_log("HARAKIRI: --- uWSGI worker %d core %d (pid: %d) WAS managing request %.*s since %.*s ---\n", (int) uwsgi.mywid, i, (int) uwsgi.mypid, wsgi_req->uri_len, wsgi_req->uri, 24, ctime_storage);
|
||||
}
|
||||
else {
|
||||
@@ -1371,14 +1393,14 @@ void what_i_am_doing() {
|
||||
#else
|
||||
ctime_r((const time_t *) &wsgi_req->start_of_request_in_sec, ctime_storage);
|
||||
#endif
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now()) {
|
||||
if (uwsgi.harakiri_options.workers > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now()) {
|
||||
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_storage);
|
||||
}
|
||||
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_storage);
|
||||
}
|
||||
}
|
||||
else if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now() && uwsgi.workers[uwsgi.mywid].sig) {
|
||||
else if (uwsgi.harakiri_options.workers > 0 && uwsgi.workers[uwsgi.mywid].harakiri < uwsgi_now() && uwsgi.workers[uwsgi.mywid].sig) {
|
||||
uwsgi_log("HARAKIRI: --- uWSGI worker %d (pid: %d) WAS handling signal %d ---\n", (int) uwsgi.mywid, (int) uwsgi.mypid, uwsgi.workers[uwsgi.mywid].signum);
|
||||
}
|
||||
}
|
||||
@@ -1847,14 +1869,19 @@ void uwsgi_init_random() {
|
||||
|
||||
#ifdef UWSGI_AS_SHARED_LIBRARY
|
||||
int uwsgi_init(int argc, char *argv[], char *envp[]) {
|
||||
#else
|
||||
int main(int argc, char *argv[], char *envp[]) {
|
||||
#endif
|
||||
uwsgi_setup(argc, argv, envp);
|
||||
return uwsgi_run();
|
||||
}
|
||||
|
||||
void uwsgi_setup(int argc, char *argv[], char *envp[]) {
|
||||
#ifdef UWSGI_AS_SHARED_LIBRARY
|
||||
#ifdef __APPLE__
|
||||
char ***envPtr = _NSGetEnviron();
|
||||
environ = *envPtr;
|
||||
#endif
|
||||
|
||||
#else
|
||||
int main(int argc, char *argv[], char *envp[]) {
|
||||
#endif
|
||||
|
||||
int i;
|
||||
@@ -1990,17 +2017,13 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
}
|
||||
uwsgi.hostname_len = strlen(uwsgi.hostname);
|
||||
|
||||
#ifdef UWSGI_ZEROMQ
|
||||
uwsgi_register_logger("zeromq", uwsgi_zeromq_logger);
|
||||
uwsgi_register_logger("zmq", uwsgi_zeromq_logger);
|
||||
#endif
|
||||
|
||||
#ifdef UWSGI_ROUTING
|
||||
uwsgi_register_embedded_routers();
|
||||
#endif
|
||||
|
||||
// call here to allows plugin to override hooks
|
||||
uwsgi_register_base_hooks();
|
||||
uwsgi_register_logchunks();
|
||||
uwsgi_log_encoders_register_embedded();
|
||||
|
||||
// register base metrics (so plugins can override them)
|
||||
@@ -2027,6 +2050,12 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
uwsgi.magic_table['V'] = UWSGI_VERSION;
|
||||
uwsgi.magic_table['k'] = uwsgi_num2str(uwsgi.cpus);
|
||||
uwsgi.magic_table['['] = "\033";
|
||||
uwsgi.magic_table['u'] = uwsgi_num2str((int)getuid());
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
uwsgi.magic_table['U'] = pw ? pw->pw_name : uwsgi.magic_table['u'];
|
||||
uwsgi.magic_table['g'] = uwsgi_num2str((int)getgid());
|
||||
struct group *gr = getgrgid(getgid());
|
||||
uwsgi.magic_table['G'] = gr ? gr->gr_name : uwsgi.magic_table['g'];
|
||||
|
||||
// you can embed a ini file in the uWSGi binary with default options
|
||||
#ifdef UWSGI_EMBED_CONFIG
|
||||
@@ -2259,6 +2288,16 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
// initialize shared sockets
|
||||
uwsgi_setup_shared_sockets();
|
||||
|
||||
#ifdef __linux__
|
||||
if (uwsgi.setns_preopen) {
|
||||
uwsgi_setns_preopen();
|
||||
}
|
||||
// eventually join a linux namespace
|
||||
if (uwsgi.setns) {
|
||||
uwsgi_setns(uwsgi.setns);
|
||||
}
|
||||
#endif
|
||||
|
||||
// start the Emperor if needed
|
||||
if (uwsgi.early_emperor && uwsgi.emperor) {
|
||||
uwsgi_emperor_start();
|
||||
@@ -2318,7 +2357,6 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO pluginize basic Linux namespace support
|
||||
#if defined(__linux__) && !defined(__ia64__)
|
||||
if (uwsgi.ns) {
|
||||
@@ -2331,10 +2369,6 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
#if defined(__linux__) && !defined(__ia64__)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// never here
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -2526,9 +2560,6 @@ int uwsgi_start(void *v_argv) {
|
||||
}
|
||||
}
|
||||
uwsgi_log_initial("- async cores set to %d - fd table size: %d\n", uwsgi.async, (int) uwsgi.max_fd);
|
||||
// optimization, this array maps file descriptor to requests
|
||||
uwsgi.async_waiting_fd_table = uwsgi_calloc(sizeof(struct wsgi_request *) * uwsgi.max_fd);
|
||||
uwsgi.async_proto_fd_table = uwsgi_calloc(sizeof(struct wsgi_request *) * uwsgi.max_fd);
|
||||
}
|
||||
|
||||
#ifdef UWSGI_DEBUG
|
||||
@@ -2551,12 +2582,8 @@ int uwsgi_start(void *v_argv) {
|
||||
// allocate rpc structures
|
||||
uwsgi_rpc_init();
|
||||
|
||||
// setup sharedarea
|
||||
if (uwsgi.sharedareasize > 0) {
|
||||
uwsgi.sharedarea = uwsgi_calloc_shared(uwsgi.page_size * uwsgi.sharedareasize);
|
||||
uwsgi_log("shared area mapped at %p, you can access it with uwsgi.sharedarea* functions.\n", uwsgi.sharedarea);
|
||||
uwsgi.sa_lock = uwsgi_rwlock_init("sharedarea");
|
||||
}
|
||||
// initialize sharedareas
|
||||
uwsgi_sharedareas_init();
|
||||
|
||||
uwsgi.snmp_lock = uwsgi_lock_init("snmp");
|
||||
|
||||
@@ -2615,6 +2642,7 @@ int uwsgi_start(void *v_argv) {
|
||||
uwsgi_setup_systemd();
|
||||
uwsgi_setup_upstart();
|
||||
uwsgi_setup_zerg();
|
||||
uwsgi_setup_emperor();
|
||||
}
|
||||
|
||||
|
||||
@@ -2846,9 +2874,10 @@ unsafe:
|
||||
if (uwsgi.logformat) {
|
||||
uwsgi_build_log_format(uwsgi.logformat);
|
||||
uwsgi.logit = uwsgi_logit_lf;
|
||||
if (uwsgi.logformat_strftime) {
|
||||
uwsgi.logit = uwsgi_logit_lf_strftime;
|
||||
}
|
||||
// TODO check it
|
||||
//if (uwsgi.logformat_strftime) {
|
||||
//uwsgi.logit = uwsgi_logit_lf_strftime;
|
||||
//}
|
||||
uwsgi.logvectors = uwsgi_malloc(sizeof(struct iovec *) * uwsgi.cores);
|
||||
for (j = 0; j < uwsgi.cores; j++) {
|
||||
uwsgi.logvectors[j] = uwsgi_malloc(sizeof(struct iovec) * uwsgi.logformat_vectors);
|
||||
@@ -2907,6 +2936,15 @@ next:
|
||||
}
|
||||
}
|
||||
|
||||
// initialize after_request hooks
|
||||
uwsgi_foreach(usl, uwsgi.after_request_hooks) {
|
||||
usl->custom_ptr = dlsym(RTLD_DEFAULT, usl->value);
|
||||
if (!usl->custom_ptr) {
|
||||
uwsgi_log("unable to find symbol/function \"%s\"\n", usl->value);
|
||||
exit(1);
|
||||
}
|
||||
uwsgi_log("added \"%s(struct wsgi_request *)\" to the after-request chain\n", usl->value);
|
||||
}
|
||||
|
||||
if (uwsgi.daemonize2) {
|
||||
masterpid = uwsgi_daemonize2();
|
||||
@@ -3050,9 +3088,14 @@ next2:
|
||||
|
||||
|
||||
// END OF INITIALIZATION
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int uwsgi_run() {
|
||||
|
||||
// !!! from now on, we could be in the master or in a worker !!!
|
||||
|
||||
int i;
|
||||
|
||||
if (getpid() == masterpid && uwsgi.master_process == 1) {
|
||||
#ifdef UWSGI_AS_SHARED_LIBRARY
|
||||
@@ -3166,22 +3209,21 @@ void uwsgi_worker_run() {
|
||||
// some apps could be mounted only on specific workers
|
||||
uwsgi_init_worker_mount_apps();
|
||||
|
||||
|
||||
#ifdef UWSGI_ZEROMQ
|
||||
// setup zeromq context (if required) one per-worker
|
||||
if (uwsgi.zeromq) {
|
||||
uwsgi_zeromq_init_sockets();
|
||||
}
|
||||
#endif
|
||||
|
||||
//postpone the queue initialization as kevent
|
||||
//do not pass kfd after fork()
|
||||
if (uwsgi.async > 1) {
|
||||
uwsgi_async_init();
|
||||
// a stack of unused cores
|
||||
uwsgi.async_queue_unused = uwsgi_malloc(sizeof(struct wsgi_request *) * uwsgi.async);
|
||||
|
||||
// fill it with default values
|
||||
for (i = 0; i < uwsgi.async; i++) {
|
||||
uwsgi.async_queue_unused[i] = &uwsgi.workers[uwsgi.mywid].cores[i].req;
|
||||
}
|
||||
|
||||
// the first available core is the last one
|
||||
uwsgi.async_queue_unused_ptr = uwsgi.async - 1;
|
||||
}
|
||||
|
||||
// setup UNIX signals for the worker
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && !uwsgi.master_process) {
|
||||
if (uwsgi.harakiri_options.workers > 0 && !uwsgi.master_process) {
|
||||
signal(SIGALRM, (void *) &harakiri);
|
||||
}
|
||||
uwsgi_unix_signal(SIGHUP, gracefully_kill);
|
||||
@@ -3271,6 +3313,28 @@ void uwsgi_ignition() {
|
||||
}
|
||||
}
|
||||
|
||||
// mark the worker as "accepting" (this is a mark used by chain reloading)
|
||||
uwsgi.workers[uwsgi.mywid].accepting = 1;
|
||||
// ready to accept request, if i am a vassal signal Emperor about it
|
||||
if (uwsgi.has_emperor && uwsgi.mywid == 1) {
|
||||
char byte = 5;
|
||||
if (write(uwsgi.emperor_fd, &byte, 1) != 1) {
|
||||
uwsgi_error("write()");
|
||||
}
|
||||
}
|
||||
|
||||
// run accepting hooks
|
||||
uwsgi_hooks_run(uwsgi.hook_accepting, "accepting", 1);
|
||||
if (uwsgi.workers[uwsgi.mywid].respawn_count == 1) {
|
||||
uwsgi_hooks_run(uwsgi.hook_accepting_once, "accepting-once", 1);
|
||||
}
|
||||
|
||||
if (uwsgi.mywid == 1) {
|
||||
uwsgi_hooks_run(uwsgi.hook_accepting1, "accepting1", 1);
|
||||
if (uwsgi.workers[uwsgi.mywid].respawn_count == 1) {
|
||||
uwsgi_hooks_run(uwsgi.hook_accepting1_once, "accepting1-once", 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi.loop) {
|
||||
void (*u_loop) (void) = uwsgi_get_loop(uwsgi.loop);
|
||||
@@ -3604,6 +3668,17 @@ void uwsgi_opt_true(char *opt, char *value, void *key) {
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_opt_false(char *opt, char *value, void *key) {
|
||||
|
||||
int *ptr = (int *) key;
|
||||
*ptr = 0;
|
||||
if (value) {
|
||||
if (!strcasecmp("false", value) || !strcasecmp("off", value) || !strcasecmp("no", value) || !strcmp("0", value)) {
|
||||
*ptr = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_opt_set_immediate_gid(char *opt, char *value, void *none) {
|
||||
gid_t gid = atoi(value);
|
||||
if (gid == 0) {
|
||||
@@ -3680,6 +3755,42 @@ void uwsgi_opt_set_int(char *opt, char *value, void *key) {
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_opt_uid(char *opt, char *value, void *key) {
|
||||
uid_t uid = atoi(value);
|
||||
if (!uid) {
|
||||
struct passwd *p = getpwnam(value);
|
||||
if (p) {
|
||||
uid = p->pw_uid;
|
||||
}
|
||||
else {
|
||||
uwsgi_log("unable to find user %s\n", value);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (key) {
|
||||
uid_t *ptr = (uid_t *) key;
|
||||
*ptr = uid;
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_opt_gid(char *opt, char *value, void *key) {
|
||||
gid_t gid = atoi(value);
|
||||
if (!gid) {
|
||||
struct group *g = getgrnam(value);
|
||||
if (g) {
|
||||
gid = g->gr_gid;
|
||||
}
|
||||
else {
|
||||
uwsgi_log("unable to find group %s\n", value);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (key) {
|
||||
gid_t *ptr = (gid_t *) key;
|
||||
*ptr = gid;
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_opt_set_rawint(char *opt, char *value, void *key) {
|
||||
int *ptr = (int *) key;
|
||||
if (value) {
|
||||
@@ -3718,28 +3829,7 @@ void uwsgi_opt_set_16bit(char *opt, char *value, void *key) {
|
||||
|
||||
void uwsgi_opt_set_megabytes(char *opt, char *value, void *key) {
|
||||
uint64_t *ptr = (uint64_t *) key;
|
||||
*ptr = (strtoul(value, NULL, 10)) * 1024 * 1024;
|
||||
}
|
||||
|
||||
void uwsgi_opt_set_dyn(char *opt, char *value, void *key) {
|
||||
|
||||
long *fake_ptr = (long *) key;
|
||||
uint8_t dyn_opt_id = (long) fake_ptr;
|
||||
uwsgi.shared->options[dyn_opt_id] = atoi(value);
|
||||
}
|
||||
|
||||
void uwsgi_opt_dyn_true(char *opt, char *value, void *key) {
|
||||
|
||||
long *fake_ptr = (long *) key;
|
||||
uint8_t dyn_opt_id = (long) fake_ptr;
|
||||
uwsgi.shared->options[dyn_opt_id] = 1;
|
||||
}
|
||||
|
||||
void uwsgi_opt_dyn_false(char *opt, char *value, void *key) {
|
||||
|
||||
long *fake_ptr = (long *) key;
|
||||
uint8_t dyn_opt_id = (long) fake_ptr;
|
||||
uwsgi.shared->options[dyn_opt_id] = 0;
|
||||
*ptr = (uint64_t)strtoul(value, NULL, 10) * 1024 * 1024;
|
||||
}
|
||||
|
||||
void uwsgi_opt_set_str(char *opt, char *value, void *key) {
|
||||
@@ -3958,27 +4048,14 @@ void uwsgi_opt_scd(char *opt, char *value, void *foobar) {
|
||||
#endif
|
||||
|
||||
void uwsgi_opt_set_umask(char *opt, char *value, void *mode) {
|
||||
|
||||
mode_t umask_mode = 0;
|
||||
|
||||
if (strlen(value) < 3) {
|
||||
int error = 0;
|
||||
mode_t mask = uwsgi_mode_t(value, &error);
|
||||
if (error) {
|
||||
uwsgi_log("invalid umask: %s\n", value);
|
||||
}
|
||||
umask_mode = 0;
|
||||
if (strlen(value) == 3) {
|
||||
umask_mode = (umask_mode << 3) + (value[0] - '0');
|
||||
umask_mode = (umask_mode << 3) + (value[1] - '0');
|
||||
umask_mode = (umask_mode << 3) + (value[2] - '0');
|
||||
}
|
||||
else {
|
||||
umask_mode = (umask_mode << 3) + (value[1] - '0');
|
||||
umask_mode = (umask_mode << 3) + (value[2] - '0');
|
||||
umask_mode = (umask_mode << 3) + (value[3] - '0');
|
||||
}
|
||||
umask(umask_mode);
|
||||
umask(mask);
|
||||
|
||||
uwsgi.do_not_change_umask = 1;
|
||||
|
||||
}
|
||||
|
||||
void uwsgi_opt_exit(char *opt, char *value, void *none) {
|
||||
@@ -4518,6 +4595,45 @@ void uwsgi_opt_dot_h(char *opt, char *filename, void *foobar) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
extern char *uwsgi_config_py;
|
||||
char *uwsgi_get_config_py() {
|
||||
char *src = uwsgi_config_py;
|
||||
size_t len = strlen(src);
|
||||
char *ptr = uwsgi_malloc(len / 2);
|
||||
char *base = ptr;
|
||||
size_t i;
|
||||
unsigned int u;
|
||||
for (i = 0; i < len; i += 2) {
|
||||
sscanf(src + i, "%2x", &u);
|
||||
*ptr++ = (char) u;
|
||||
}
|
||||
#ifdef UWSGI_ZLIB
|
||||
struct uwsgi_buffer *ub = uwsgi_zlib_decompress(base, ptr-base);
|
||||
if (!ub) {
|
||||
free(base);
|
||||
return "";
|
||||
}
|
||||
// add final null byte
|
||||
uwsgi_buffer_append(ub, "\0", 1);
|
||||
free(base);
|
||||
// base is the final blob
|
||||
base = ub->buf;
|
||||
ub->buf = NULL;
|
||||
uwsgi_buffer_destroy(ub);
|
||||
#endif
|
||||
return base;
|
||||
}
|
||||
|
||||
void uwsgi_opt_config_py(char *opt, char *filename, void *foobar) {
|
||||
fprintf(stdout, "%s\n", uwsgi_get_config_py());
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
void uwsgi_opt_build_plugin(char *opt, char *directory, void *foobar) {
|
||||
uwsgi_build_plugin(directory);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void uwsgi_opt_connect_and_read(char *opt, char *address, void *foobar) {
|
||||
|
||||
|
||||
+86
-13
@@ -10,9 +10,17 @@
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
static struct uwsgi_buffer *uwsgi_websocket_message(char *msg, size_t len) {
|
||||
struct uwsgi_buffer *ub = uwsgi_buffer_new(10 + len);
|
||||
if (uwsgi_buffer_u8(ub, 0x81)) goto error;
|
||||
static struct uwsgi_buffer *uwsgi_websocket_message(struct wsgi_request *wsgi_req, char *msg, size_t len, uint8_t opcode) {
|
||||
struct uwsgi_buffer *ub = wsgi_req->websocket_send_buf;
|
||||
if (!ub) {
|
||||
wsgi_req->websocket_send_buf = uwsgi_buffer_new(10 + len);
|
||||
ub = wsgi_req->websocket_send_buf;
|
||||
}
|
||||
else {
|
||||
// reset the buffer
|
||||
ub->pos = 0;
|
||||
}
|
||||
if (uwsgi_buffer_u8(ub, opcode)) goto error;
|
||||
if (len < 126) {
|
||||
if (uwsgi_buffer_u8(ub, len)) goto error;
|
||||
}
|
||||
@@ -29,7 +37,6 @@ static struct uwsgi_buffer *uwsgi_websocket_message(char *msg, size_t len) {
|
||||
return ub;
|
||||
|
||||
error:
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -66,27 +73,72 @@ static int uwsgi_websockets_check_pingpong(struct wsgi_request *wsgi_req) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_websocket_send_do(struct wsgi_request *wsgi_req, char *msg, size_t len) {
|
||||
struct uwsgi_buffer *ub = uwsgi_websocket_message(msg, len);
|
||||
static int uwsgi_websocket_send_do(struct wsgi_request *wsgi_req, char *msg, size_t len, uint8_t opcode) {
|
||||
struct uwsgi_buffer *ub = uwsgi_websocket_message(wsgi_req, msg, len, opcode);
|
||||
if (!ub) return -1;
|
||||
|
||||
ssize_t ret = uwsgi_response_write_body_do(wsgi_req, ub->buf, ub->pos);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return ret;
|
||||
|
||||
return uwsgi_response_write_body_do(wsgi_req, ub->buf, ub->pos);
|
||||
}
|
||||
|
||||
static int uwsgi_websocket_send_from_sharedarea_do(struct wsgi_request *wsgi_req, int id, uint64_t pos, uint64_t len, uint8_t opcode) {
|
||||
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_get_by_id(id, pos);
|
||||
if (!sa) return -1;
|
||||
if (!len) {
|
||||
len = sa->honour_used ? sa->used-pos : ((sa->max_pos+1)-pos);
|
||||
}
|
||||
uwsgi_rlock(sa->lock);
|
||||
sa->hits++;
|
||||
struct uwsgi_buffer *ub = uwsgi_websocket_message(wsgi_req, sa->area, len, opcode);
|
||||
uwsgi_rwunlock(sa->lock);
|
||||
if (!ub) return -1;
|
||||
|
||||
return uwsgi_response_write_body_do(wsgi_req, ub->buf, ub->pos);
|
||||
}
|
||||
|
||||
int uwsgi_websocket_send(struct wsgi_request *wsgi_req, char *msg, size_t len) {
|
||||
if (wsgi_req->websocket_closed) {
|
||||
return -1;
|
||||
}
|
||||
ssize_t ret = uwsgi_websocket_send_do(wsgi_req, msg, len);
|
||||
ssize_t ret = uwsgi_websocket_send_do(wsgi_req, msg, len, 0x81);
|
||||
if (ret < 0) {
|
||||
wsgi_req->websocket_closed = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int uwsgi_websocket_send_from_sharedarea(struct wsgi_request *wsgi_req, int id, uint64_t pos, uint64_t len) {
|
||||
if (wsgi_req->websocket_closed) {
|
||||
return -1;
|
||||
}
|
||||
ssize_t ret = uwsgi_websocket_send_from_sharedarea_do(wsgi_req, id, pos, len, 0x81);
|
||||
if (ret < 0) {
|
||||
wsgi_req->websocket_closed = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int uwsgi_websocket_send_binary(struct wsgi_request *wsgi_req, char *msg, size_t len) {
|
||||
if (wsgi_req->websocket_closed) {
|
||||
return -1;
|
||||
}
|
||||
ssize_t ret = uwsgi_websocket_send_do(wsgi_req, msg, len, 0x82);
|
||||
if (ret < 0) {
|
||||
wsgi_req->websocket_closed = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int uwsgi_websocket_send_binary_from_sharedarea(struct wsgi_request *wsgi_req, int id, uint64_t pos, uint64_t len) {
|
||||
if (wsgi_req->websocket_closed) {
|
||||
return -1;
|
||||
}
|
||||
ssize_t ret = uwsgi_websocket_send_from_sharedarea_do(wsgi_req, id, pos, len, 0x82);
|
||||
if (ret < 0) {
|
||||
wsgi_req->websocket_closed = 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void uwsgi_websocket_parse_header(struct wsgi_request *wsgi_req) {
|
||||
uint8_t byte1 = wsgi_req->websocket_buf->buf[0];
|
||||
uint8_t byte2 = wsgi_req->websocket_buf->buf[1];
|
||||
@@ -315,18 +367,39 @@ ssize_t uwsgi_websockets_simple_send(struct wsgi_request *wsgi_req, struct uwsgi
|
||||
return len;
|
||||
}
|
||||
|
||||
int uwsgi_websocket_handshake(struct wsgi_request *wsgi_req, char *key, uint16_t key_len, char *origin, uint16_t origin_len) {
|
||||
int uwsgi_websocket_handshake(struct wsgi_request *wsgi_req, char *key, uint16_t key_len, char *origin, uint16_t origin_len, char *proto, uint16_t proto_len) {
|
||||
#ifdef UWSGI_SSL
|
||||
if (!key_len) {
|
||||
key = wsgi_req->http_sec_websocket_key;
|
||||
key_len = wsgi_req->http_sec_websocket_key_len;
|
||||
}
|
||||
if (key_len == 0) return -1;
|
||||
|
||||
char sha1[20];
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, "101 Web Socket Protocol Handshake", 33)) return -1;
|
||||
if (uwsgi_response_add_header(wsgi_req, "Upgrade", 7, "WebSocket", 9)) return -1;
|
||||
if (uwsgi_response_add_header(wsgi_req, "Connection", 10, "Upgrade", 7)) return -1;
|
||||
if (origin_len > 0) {
|
||||
|
||||
// if origin was requested or proto_len is specified, send it back
|
||||
if (wsgi_req->http_origin_len > 0 || origin_len > 0) {
|
||||
if (!origin_len) {
|
||||
origin = wsgi_req->http_origin;
|
||||
origin_len = wsgi_req->http_origin_len;
|
||||
}
|
||||
if (uwsgi_response_add_header(wsgi_req, "Sec-WebSocket-Origin", 20, origin, origin_len)) return -1;
|
||||
}
|
||||
else {
|
||||
if (uwsgi_response_add_header(wsgi_req, "Sec-WebSocket-Origin", 20, "*", 1)) return -1;
|
||||
}
|
||||
|
||||
// if protocol was requested or proto_len is specified, send it back
|
||||
if (wsgi_req->http_sec_websocket_protocol_len > 0 || proto_len > 0) {
|
||||
if (!proto_len) {
|
||||
proto = wsgi_req->http_sec_websocket_protocol;
|
||||
proto_len = wsgi_req->http_sec_websocket_protocol_len;
|
||||
}
|
||||
if (uwsgi_response_add_header(wsgi_req, "Sec-WebSocket-Protocol", 22, proto, proto_len)) return -1;
|
||||
}
|
||||
// generate websockets sha1 and encode it to base64
|
||||
if (!uwsgi_sha1_2n(key, key_len, "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", 36, sha1)) return -1;
|
||||
size_t b64_len = 0;
|
||||
|
||||
+246
-9
@@ -5,7 +5,7 @@ extern struct uwsgi_server uwsgi;
|
||||
int uwsgi_response_add_content_length(struct wsgi_request *wsgi_req, uint64_t cl) {
|
||||
char buf[sizeof(UMAX64_STR)+1];
|
||||
int ret = snprintf(buf, sizeof(UMAX64_STR)+1, "%llu", (unsigned long long) cl);
|
||||
if (ret <= 0 || ret > (int) (sizeof(UMAX64_STR)+1)) {
|
||||
if (ret <= 0 || ret >= (int) (sizeof(UMAX64_STR)+1)) {
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ int uwsgi_response_add_content_range(struct wsgi_request *wsgi_req, uint64_t sta
|
||||
end = cl-1;
|
||||
}
|
||||
int ret = snprintf(buf, 6+(sizeof(UMAX64_STR)*3)+4, "bytes %llu-%llu/%llu", (unsigned long long) start, (unsigned long long) end, (unsigned long long) cl);
|
||||
if (ret <= 0 || ret > (int) (6+(sizeof(UMAX64_STR)*3)+4)) {
|
||||
if (ret <= 0 || ret >= (int) (6+(sizeof(UMAX64_STR)*3)+4)) {
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ int uwsgi_response_add_header_force(struct wsgi_request *wsgi_req, char *key, ui
|
||||
return uwsgi_response_add_header_do(wsgi_req, key, key_len, value, value_len);
|
||||
}
|
||||
|
||||
int uwsgi_response_write_headers_do(struct wsgi_request *wsgi_req) {
|
||||
static int uwsgi_response_write_headers_do0(struct wsgi_request *wsgi_req) {
|
||||
if (wsgi_req->headers_sent || !wsgi_req->headers || wsgi_req->response_size || wsgi_req->write_errors) {
|
||||
return UWSGI_OK;
|
||||
}
|
||||
@@ -209,11 +209,20 @@ int uwsgi_response_write_headers_do(struct wsgi_request *wsgi_req) {
|
||||
|
||||
if (wsgi_req->socket->proto_fix_headers(wsgi_req)) { wsgi_req->write_errors++ ; return -1;}
|
||||
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
|
||||
int uwsgi_response_write_headers_do(struct wsgi_request *wsgi_req) {
|
||||
|
||||
int ret = uwsgi_response_write_headers_do0(wsgi_req);
|
||||
if (ret != UWSGI_AGAIN) return ret;
|
||||
|
||||
for(;;) {
|
||||
errno = 0;
|
||||
int ret = wsgi_req->socket->proto_write_headers(wsgi_req, wsgi_req->headers->buf, wsgi_req->headers->pos);
|
||||
if (ret < 0) {
|
||||
if (!uwsgi.ignore_write_errors) {
|
||||
uwsgi_error("uwsgi_response_write_headers_do()");
|
||||
uwsgi_req_error("uwsgi_response_write_headers_do()");
|
||||
}
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
@@ -221,6 +230,7 @@ int uwsgi_response_write_headers_do(struct wsgi_request *wsgi_req) {
|
||||
if (ret == UWSGI_OK) {
|
||||
break;
|
||||
}
|
||||
if (!uwsgi_is_again()) continue;
|
||||
ret = uwsgi_wait_write_req(wsgi_req);
|
||||
if (ret < 0) { wsgi_req->write_errors++; return -1;}
|
||||
if (ret == 0) {
|
||||
@@ -238,6 +248,100 @@ int uwsgi_response_write_headers_do(struct wsgi_request *wsgi_req) {
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
private function for highly optimized writes (1 single syscall for headers and body)
|
||||
*/
|
||||
static int uwsgi_response_writev_headers_and_body_do(struct wsgi_request *wsgi_req, char *buf, size_t len) {
|
||||
|
||||
struct iovec iov[2];
|
||||
|
||||
int ret = uwsgi_response_write_headers_do0(wsgi_req);
|
||||
if (ret != UWSGI_AGAIN) return ret;
|
||||
|
||||
iov[0].iov_base = wsgi_req->headers->buf;
|
||||
iov[0].iov_len = wsgi_req->headers->pos;
|
||||
iov[1].iov_base = buf;
|
||||
iov[1].iov_len = len;
|
||||
|
||||
size_t iov_len = 2;
|
||||
for(;;) {
|
||||
errno = 0;
|
||||
// no need to use writev if a single iovec remains
|
||||
if (iov_len == 1) {
|
||||
buf = iov[0].iov_base;
|
||||
len = iov[0].iov_len;
|
||||
// update counters
|
||||
wsgi_req->headers_size += wsgi_req->headers->pos;
|
||||
wsgi_req->headers_sent = 1;
|
||||
wsgi_req->response_size += wsgi_req->write_pos - wsgi_req->headers_size;
|
||||
wsgi_req->write_pos = 0;
|
||||
goto fallback;
|
||||
}
|
||||
int ret = wsgi_req->socket->proto_writev(wsgi_req, iov, &iov_len);
|
||||
if (ret < 0) {
|
||||
if (!uwsgi.ignore_write_errors) {
|
||||
uwsgi_req_error("uwsgi_response_writev_headers_and_body_do()");
|
||||
}
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
if (ret == UWSGI_OK) {
|
||||
break;
|
||||
}
|
||||
if (!uwsgi_is_again()) continue;
|
||||
ret = uwsgi_wait_write_req(wsgi_req);
|
||||
if (ret < 0) { wsgi_req->write_errors++; return -1;}
|
||||
if (ret == 0) {
|
||||
uwsgi_log("uwsgi_response_writev_headers_and_body_do() TIMEOUT !!!\n");
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
wsgi_req->headers_size += wsgi_req->headers->pos;
|
||||
wsgi_req->response_size += len;
|
||||
wsgi_req->headers_sent = 1;
|
||||
|
||||
// reset for the next write
|
||||
wsgi_req->write_pos = 0;
|
||||
|
||||
return UWSGI_OK;
|
||||
|
||||
fallback:
|
||||
|
||||
for(;;) {
|
||||
errno = 0;
|
||||
int ret = wsgi_req->socket->proto_write(wsgi_req, buf, len);
|
||||
if (ret < 0) {
|
||||
if (!uwsgi.ignore_write_errors) {
|
||||
// here we use the parent name
|
||||
uwsgi_req_error("uwsgi_response_write_body_do()");
|
||||
}
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
if (ret == UWSGI_OK) {
|
||||
break;
|
||||
}
|
||||
if (!uwsgi_is_again()) continue;
|
||||
ret = uwsgi_wait_write_req(wsgi_req);
|
||||
if (ret < 0) { wsgi_req->write_errors++; return -1;}
|
||||
if (ret == 0) {
|
||||
// here we use the parent name
|
||||
uwsgi_log("uwsgi_response_write_body_do() TIMEOUT !!!\n");
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
wsgi_req->response_size += wsgi_req->write_pos;
|
||||
// reset for the next write
|
||||
wsgi_req->write_pos = 0;
|
||||
|
||||
return UWSGI_OK;
|
||||
|
||||
}
|
||||
|
||||
// this is the function called by all request plugins to send chunks to the client
|
||||
int uwsgi_response_write_body_do(struct wsgi_request *wsgi_req, char *buf, size_t len) {
|
||||
|
||||
@@ -278,6 +382,9 @@ int uwsgi_response_write_body_do(struct wsgi_request *wsgi_req, char *buf, size_
|
||||
write:
|
||||
// send headers if not already sent
|
||||
if (!wsgi_req->headers_sent) {
|
||||
if (wsgi_req->socket->proto_writev && len > 0 && wsgi_req->headers) {
|
||||
return uwsgi_response_writev_headers_and_body_do(wsgi_req, buf, len);
|
||||
}
|
||||
int ret = uwsgi_response_write_headers_do(wsgi_req);
|
||||
if (ret == UWSGI_OK) goto sendbody;
|
||||
if (ret == UWSGI_AGAIN) return UWSGI_AGAIN;
|
||||
@@ -290,10 +397,11 @@ sendbody:
|
||||
if (len == 0) return UWSGI_OK;
|
||||
|
||||
for(;;) {
|
||||
errno = 0;
|
||||
int ret = wsgi_req->socket->proto_write(wsgi_req, buf, len);
|
||||
if (ret < 0) {
|
||||
if (!uwsgi.ignore_write_errors) {
|
||||
uwsgi_error("uwsgi_response_write_body_do()");
|
||||
uwsgi_req_error("uwsgi_response_write_body_do()");
|
||||
}
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
@@ -301,6 +409,7 @@ sendbody:
|
||||
if (ret == UWSGI_OK) {
|
||||
break;
|
||||
}
|
||||
if (!uwsgi_is_again()) continue;
|
||||
ret = uwsgi_wait_write_req(wsgi_req);
|
||||
if (ret < 0) { wsgi_req->write_errors++; return -1;}
|
||||
if (ret == 0) {
|
||||
@@ -317,6 +426,130 @@ sendbody:
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
int uwsgi_response_writev_body_do(struct wsgi_request *wsgi_req, struct iovec *iov, size_t len) {
|
||||
|
||||
if (wsgi_req->write_errors) return -1;
|
||||
if (wsgi_req->ignore_body) return UWSGI_OK;
|
||||
|
||||
#ifdef UWSGI_ROUTING
|
||||
// special case here, we could need to set transformations before
|
||||
if (!wsgi_req->headers_sent) {
|
||||
// apply response routes
|
||||
if (uwsgi_apply_response_routes(wsgi_req) == UWSGI_ROUTE_BREAK) {
|
||||
// from now on ignore write body requests...
|
||||
wsgi_req->ignore_body = 1;
|
||||
return -1;
|
||||
}
|
||||
wsgi_req->is_response_routing = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t i;
|
||||
int buffering = 0;
|
||||
// transformations apply to every vector
|
||||
for(i=0;i<len;i++) {
|
||||
// if the transformation chain returns 1, we are in buffering mode
|
||||
if (wsgi_req->transformed_chunk_len == 0 && wsgi_req->transformations) {
|
||||
int t_ret = uwsgi_apply_transformations(wsgi_req, iov[i].iov_base, iov[i].iov_len);
|
||||
if (t_ret == 0) {
|
||||
iov[i].iov_base = wsgi_req->transformed_chunk;
|
||||
iov[i].iov_len = wsgi_req->transformed_chunk_len;
|
||||
// reset transformation
|
||||
wsgi_req->transformed_chunk = NULL;
|
||||
wsgi_req->transformed_chunk_len = 0;
|
||||
goto write;
|
||||
}
|
||||
if (t_ret == 1) {
|
||||
buffering = 1;
|
||||
continue;
|
||||
}
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffering) return UWSGI_OK;
|
||||
|
||||
write:
|
||||
// send headers if not already sent
|
||||
if (!wsgi_req->headers_sent) {
|
||||
int ret = uwsgi_response_write_headers_do(wsgi_req);
|
||||
if (ret == UWSGI_OK) goto sendbody;
|
||||
if (ret == UWSGI_AGAIN) return UWSGI_AGAIN;
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
sendbody:
|
||||
|
||||
if (len == 0) return UWSGI_OK;
|
||||
// unfortunately vector based I/O cannot be accomplished on all protocols
|
||||
if (!wsgi_req->socket->proto_writev) goto fallback;
|
||||
|
||||
// we use a copy to avoid mess
|
||||
size_t iov_len = len;
|
||||
for(;;) {
|
||||
errno = 0;
|
||||
int ret = wsgi_req->socket->proto_writev(wsgi_req, iov, &iov_len);
|
||||
if (ret < 0) {
|
||||
if (!uwsgi.ignore_write_errors) {
|
||||
uwsgi_req_error("uwsgi_response_writev_body_do()");
|
||||
}
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
if (ret == UWSGI_OK) {
|
||||
break;
|
||||
}
|
||||
if (!uwsgi_is_again()) continue;
|
||||
ret = uwsgi_wait_write_req(wsgi_req);
|
||||
if (ret < 0) { wsgi_req->write_errors++; return -1;}
|
||||
if (ret == 0) {
|
||||
uwsgi_log("uwsgi_response_writev_body_do() TIMEOUT !!!\n");
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
goto done;
|
||||
|
||||
fallback:
|
||||
|
||||
for(i=0;i<len;i++) {
|
||||
for(;;) {
|
||||
errno = 0;
|
||||
int ret = wsgi_req->socket->proto_write(wsgi_req, iov[i].iov_base, iov[i].iov_len);
|
||||
if (ret < 0) {
|
||||
if (!uwsgi.ignore_write_errors) {
|
||||
uwsgi_req_error("uwsgi_response_writev_body_do()");
|
||||
}
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
if (ret == UWSGI_OK) {
|
||||
break;
|
||||
}
|
||||
if (!uwsgi_is_again()) continue;
|
||||
ret = uwsgi_wait_write_req(wsgi_req);
|
||||
if (ret < 0) { wsgi_req->write_errors++; return -1;}
|
||||
if (ret == 0) {
|
||||
uwsgi_log("uwsgi_response_writev_body_do() TIMEOUT !!!\n");
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
wsgi_req->response_size += wsgi_req->write_pos;
|
||||
// reset for the next write
|
||||
wsgi_req->write_pos = 0;
|
||||
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
|
||||
int uwsgi_response_sendfile_do(struct wsgi_request *wsgi_req, int fd, size_t pos, size_t len) {
|
||||
return uwsgi_response_sendfile_do_can_close(wsgi_req, fd, pos, len, 1);
|
||||
}
|
||||
@@ -349,7 +582,7 @@ sendfile:
|
||||
if (len == 0) {
|
||||
struct stat st;
|
||||
if (fstat(fd, &st)) {
|
||||
uwsgi_error("uwsgi_response_sendfile_do()/fstat()");
|
||||
uwsgi_req_error("uwsgi_response_sendfile_do()/fstat()");
|
||||
wsgi_req->write_errors++;
|
||||
if (can_close) close(fd);
|
||||
return -1;
|
||||
@@ -367,7 +600,7 @@ sendfile:
|
||||
if (!can_close) {
|
||||
int tmp_fd = dup(fd);
|
||||
if (tmp_fd < 0) {
|
||||
uwsgi_error("uwsgi_response_sendfile_do()/dup()");
|
||||
uwsgi_req_error("uwsgi_response_sendfile_do()/dup()");
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
}
|
||||
@@ -388,10 +621,11 @@ sendfile:
|
||||
wsgi_req->via = UWSGI_VIA_SENDFILE;
|
||||
|
||||
for(;;) {
|
||||
errno = 0;
|
||||
int ret = wsgi_req->socket->proto_sendfile(wsgi_req, fd, pos, len);
|
||||
if (ret < 0) {
|
||||
if (!uwsgi.ignore_write_errors) {
|
||||
uwsgi_error("uwsgi_response_sendfile_do()");
|
||||
uwsgi_req_error("uwsgi_response_sendfile_do()");
|
||||
}
|
||||
wsgi_req->write_errors++;
|
||||
if (can_close) close(fd);
|
||||
@@ -400,6 +634,7 @@ sendfile:
|
||||
if (ret == UWSGI_OK) {
|
||||
break;
|
||||
}
|
||||
if (!uwsgi_is_again()) continue;
|
||||
ret = uwsgi_wait_write_req(wsgi_req);
|
||||
if (ret < 0) {
|
||||
wsgi_req->write_errors++;
|
||||
@@ -454,10 +689,11 @@ int uwsgi_simple_write(struct wsgi_request *wsgi_req, char *buf, size_t len) {
|
||||
wsgi_req->write_pos = 0;
|
||||
|
||||
for(;;) {
|
||||
errno = 0;
|
||||
int ret = wsgi_req->socket->proto_write(wsgi_req, buf, len);
|
||||
if (ret < 0) {
|
||||
if (!uwsgi.ignore_write_errors) {
|
||||
uwsgi_error("uwsgi_simple_write()");
|
||||
uwsgi_req_error("uwsgi_simple_write()");
|
||||
}
|
||||
wsgi_req->write_errors++;
|
||||
return -1;
|
||||
@@ -465,6 +701,7 @@ int uwsgi_simple_write(struct wsgi_request *wsgi_req, char *buf, size_t len) {
|
||||
if (ret == UWSGI_OK) {
|
||||
break;
|
||||
}
|
||||
if (!uwsgi_is_again()) continue;
|
||||
ret = uwsgi_wait_write_req(wsgi_req);
|
||||
if (ret < 0) { wsgi_req->write_errors++; return -1;}
|
||||
if (ret == 0) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import uwsgi
|
||||
|
||||
import os
|
||||
|
||||
def application(env, start_response):
|
||||
@@ -15,12 +14,12 @@ def application(env, start_response):
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
yield "--%s\n" % boundary
|
||||
yield "--%s\r\n" % boundary
|
||||
|
||||
while 1:
|
||||
yield "Content-Type: image/jpeg\r\n\r\n"
|
||||
uwsgi.sendfile('screenshot.jpg')
|
||||
yield "--%s\n" % boundary
|
||||
print os.system('screencapture -t jpg -m -T 1 screenshot.jpg')
|
||||
f = open('screenshot.jpg')
|
||||
yield env['wsgi.file_wrapper'](f)
|
||||
yield "\r\n--%s\r\n" % boundary
|
||||
#os.system('./isightcapture -w 640 -h 480 screenshot.jpg')
|
||||
#os.system('screencapture -m -T 1 screenshot.jpg')
|
||||
|
||||
@@ -42,16 +42,6 @@ def application(env, start_response):
|
||||
|
||||
yield '<h2>dynamic options</h2>'
|
||||
|
||||
yield '<b>logging</b>: ' + str(uwsgi.get_option(0)) + '<br/>'
|
||||
yield '<b>max_requests</b>: ' + str(uwsgi.getoption(1)) + '<br/>'
|
||||
yield '<b>socket_timeout</b>: ' + str(uwsgi.getoption(2)) + '<br/>'
|
||||
yield '<b>memory_debug</b>: ' + str(uwsgi.getoption(3)) + '<br/>'
|
||||
yield '<b>master_interval</b>: ' + str(uwsgi.getoption(4)) + '<br/>'
|
||||
yield '<b>harakiri</b>: ' + str(uwsgi.getoption(5)) + '<br/>'
|
||||
yield '<b>cgi_mode</b>: ' + str(uwsgi.get_option(6)) + '<br/>'
|
||||
yield '<b>threads</b>: ' + str(uwsgi.get_option(7)) + '<br/>'
|
||||
yield '<b>process_reaper</b>: ' + str(uwsgi.get_option(8)) + '<br/>'
|
||||
|
||||
yield '<table border="1">'
|
||||
yield '<th>worker id</th><th>pid</th><th>in request</th><th>requests</th><th>running time</th><th>address space</th><th>rss</th>'
|
||||
|
||||
|
||||
@@ -47,11 +47,6 @@ def serve_logo(e, sr):
|
||||
uwsgi.sendfile('logo_uWSGI.png')
|
||||
return ''
|
||||
|
||||
def serve_options(e, sr):
|
||||
sr('200 OK', [('Content-Type', 'text/html')])
|
||||
for opt in range(0,256):
|
||||
yield "<b>%d</b> = %d<br/>" % (opt, uwsgi.get_option(opt))
|
||||
|
||||
def serve_config(e, sr):
|
||||
sr('200 OK', [('Content-Type', 'text/html')])
|
||||
for opt in uwsgi.opt.keys():
|
||||
@@ -61,7 +56,6 @@ routes = {}
|
||||
routes['/xsendfile'] = xsendfile
|
||||
routes['/logo'] = serve_logo
|
||||
routes['/config'] = serve_config
|
||||
routes['/options'] = serve_options
|
||||
|
||||
@postfork
|
||||
def setprocname():
|
||||
@@ -119,11 +113,6 @@ def application(env, start_response):
|
||||
Configuration<br/>
|
||||
<iframe src="/config"></iframe><br/>
|
||||
|
||||
<br/>
|
||||
|
||||
Dynamic options<br/>
|
||||
<iframe src="/options"></iframe><br/>
|
||||
|
||||
<br/>
|
||||
Workers and applications<br/>
|
||||
<table border="1">
|
||||
|
||||
@@ -9,12 +9,6 @@ def serve_logo(e, sr):
|
||||
sr('200 OK', [('Content-Type', 'image/png')])
|
||||
return uwsgi.sendfile('logo_uWSGI.png')
|
||||
|
||||
def serve_options(e, sr):
|
||||
sr('200 OK', [('Content-Type', 'text/html')])
|
||||
for opt in range(0,256):
|
||||
body = "{opt} = {optvalue}<br/>".format(opt=opt, optvalue=uwsgi.get_option(opt))
|
||||
yield bytes(body.encode('ascii'))
|
||||
|
||||
def serve_config(e, sr):
|
||||
sr('200 OK', [('Content-Type', 'text/html')])
|
||||
for opt in uwsgi.opt.keys():
|
||||
@@ -25,7 +19,6 @@ routes = {}
|
||||
routes['/xsendfile'] = xsendfile
|
||||
routes['/logo'] = serve_logo
|
||||
routes['/config'] = serve_config
|
||||
routes['/options'] = serve_options
|
||||
|
||||
def application(env, start_response):
|
||||
|
||||
@@ -43,9 +36,6 @@ Configuration<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
Dynamic options<br/>
|
||||
<iframe src="/options"></iframe><br/>
|
||||
|
||||
""".format(version=uwsgi.version.decode('ascii'))
|
||||
|
||||
return bytes(body.encode('ascii'))
|
||||
|
||||
+15
-2
@@ -52,16 +52,22 @@ int uwsgi_is_a_keep_mount(char *mp) {
|
||||
|
||||
}
|
||||
|
||||
static int uwsgi_ns_start(void *v_argv) {
|
||||
uwsgi_start(v_argv);
|
||||
return uwsgi_run();
|
||||
}
|
||||
|
||||
void linux_namespace_start(void *argv) {
|
||||
for (;;) {
|
||||
char stack[PTHREAD_STACK_MIN];
|
||||
int waitpid_status;
|
||||
char *pid_str = NULL;
|
||||
uwsgi_log("*** jailing uWSGI in %s ***\n", uwsgi.ns);
|
||||
int clone_flags = SIGCHLD | CLONE_NEWUTS | CLONE_NEWPID | CLONE_NEWIPC | CLONE_NEWNS;
|
||||
if (uwsgi.ns_net) {
|
||||
clone_flags |= CLONE_NEWNET;
|
||||
}
|
||||
pid_t pid = clone(uwsgi_start, stack + PTHREAD_STACK_MIN, clone_flags, (void *) argv);
|
||||
pid_t pid = clone(uwsgi_ns_start, stack + PTHREAD_STACK_MIN, clone_flags, (void *) argv);
|
||||
if (pid == -1) {
|
||||
uwsgi_error("clone()");
|
||||
exit(1);
|
||||
@@ -72,10 +78,12 @@ void linux_namespace_start(void *argv) {
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
pid_str = uwsgi_num2str((int) pid);
|
||||
// run the post-jail scripts
|
||||
if (setenv("UWSGI_JAIL_PID", uwsgi_num2str((int) pid), 1)) {
|
||||
if (setenv("UWSGI_JAIL_PID", pid_str, 1)) {
|
||||
uwsgi_error("setenv()");
|
||||
}
|
||||
free(pid_str);
|
||||
uwsgi_hooks_run(uwsgi.hook_post_jail, "post-jail", 1);
|
||||
struct uwsgi_string_list *usl = uwsgi.exec_post_jail;
|
||||
while(usl) {
|
||||
@@ -106,6 +114,11 @@ void linux_namespace_start(void *argv) {
|
||||
if (WIFEXITED(waitpid_status) && WEXITSTATUS(waitpid_status) == 1) {
|
||||
exit(1);
|
||||
}
|
||||
else if (uwsgi.exit_on_reload && WIFEXITED(waitpid_status) && WEXITSTATUS(waitpid_status) == 0) {
|
||||
uwsgi_log("jailed master process exited and exit-on-reload is enabled, shutting down\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
uwsgi_log("pid %d ended. Respawning...\n", (int) pid);
|
||||
}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "../../uwsgi.h"
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
/* uwsgi ADMIN|10 */
|
||||
int uwsgi_request_admin(struct wsgi_request *wsgi_req) {
|
||||
|
||||
uint32_t opt_value = 0;
|
||||
|
||||
if (wsgi_req->uh->pktsize != 0 && wsgi_req->uh->pktsize != 4)
|
||||
return UWSGI_OK;
|
||||
|
||||
// write request
|
||||
if (wsgi_req->uh->pktsize == 4) {
|
||||
memcpy(&opt_value, wsgi_req->buffer, 4);
|
||||
uwsgi_log( "setting internal option %d to %d\n", wsgi_req->uh->modifier2, opt_value);
|
||||
uwsgi.shared->options[wsgi_req->uh->modifier2] = opt_value;
|
||||
|
||||
// ACK
|
||||
wsgi_req->uh->modifier1 = 255;
|
||||
wsgi_req->uh->pktsize = 0;
|
||||
wsgi_req->uh->modifier2 = 1;
|
||||
uwsgi_response_write_body_do(wsgi_req, (char *)wsgi_req->uh , 4);
|
||||
}
|
||||
// get request
|
||||
else {
|
||||
uwsgi_log( "internal option %d = %d\n", wsgi_req->uh->modifier2, uwsgi.shared->options[wsgi_req->uh->modifier2]);
|
||||
|
||||
wsgi_req->uh->modifier1 = 10;
|
||||
wsgi_req->uh->pktsize = 4;
|
||||
uwsgi_response_write_body_do(wsgi_req, (char *)wsgi_req->uh , 4);
|
||||
uwsgi_response_write_body_do(wsgi_req, (char *) &uwsgi.shared->options[wsgi_req->uh->modifier2], 4);
|
||||
}
|
||||
|
||||
return UWSGI_OK;
|
||||
}
|
||||
|
||||
|
||||
struct uwsgi_plugin admin_plugin = {
|
||||
|
||||
.name = "admin",
|
||||
.modifier1 = 10,
|
||||
.request = uwsgi_request_admin,
|
||||
|
||||
};
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
NAME='admin'
|
||||
CFLAGS = []
|
||||
LDFLAGS = []
|
||||
LIBS = []
|
||||
|
||||
GCC_LIST = ['admin_plugin']
|
||||
@@ -222,8 +222,8 @@ static void uwsgi_airbrake_loop(struct uwsgi_thread *ut) {
|
||||
// ARGH !!!
|
||||
if (!curl) return;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.socket_timeout);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, uwsgi.socket_timeout);
|
||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);
|
||||
curl_easy_setopt(curl, CURLOPT_READDATA, ut);
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||
|
||||
@@ -146,8 +146,8 @@ static void uwsgi_alarm_curl_loop(struct uwsgi_thread *ut) {
|
||||
// ARGH !!!
|
||||
if (!curl) return;
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.socket_timeout);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, uwsgi.socket_timeout);
|
||||
curl_easy_setopt(curl, CURLOPT_READFUNCTION, uwsgi_alarm_curl_read_callback);
|
||||
curl_easy_setopt(curl, CURLOPT_READDATA, ut);
|
||||
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
|
||||
|
||||
@@ -281,7 +281,7 @@ static int carbon_push_stats(int retry_cycle, time_t now) {
|
||||
total_busyness += worker_busyness;
|
||||
u_carbon.was_busy[i-1] = 0;
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1 || uwsgi.force_get_memusage) {
|
||||
if (uwsgi.logging_options.memory_report == 1 || uwsgi.force_get_memusage) {
|
||||
// only running workers are counted in total memory stats and if memory-report option is enabled
|
||||
total_rss += uwsgi.workers[i].rss_size;
|
||||
total_vsz += uwsgi.workers[i].vsz_size;
|
||||
@@ -294,7 +294,7 @@ static int carbon_push_stats(int retry_cycle, time_t now) {
|
||||
wok = carbon_write(fd, "%s%s.%s.worker%d.requests %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, i, (unsigned long long) uwsgi.workers[i].requests, (unsigned long long) now);
|
||||
if (!wok) goto clear;
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1 || uwsgi.force_get_memusage) {
|
||||
if (uwsgi.logging_options.memory_report == 1 || uwsgi.force_get_memusage) {
|
||||
wok = carbon_write(fd, "%s%s.%s.worker%d.rss_size %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, i, (unsigned long long) uwsgi.workers[i].rss_size, (unsigned long long) now);
|
||||
if (!wok) goto clear;
|
||||
|
||||
@@ -327,7 +327,7 @@ static int carbon_push_stats(int retry_cycle, time_t now) {
|
||||
|
||||
}
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1 || uwsgi.force_get_memusage) {
|
||||
if (uwsgi.logging_options.memory_report == 1 || uwsgi.force_get_memusage) {
|
||||
wok = carbon_write(fd, "%s%s.%s.rss_size %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, (unsigned long long) total_rss, (unsigned long long) now);
|
||||
if (!wok) goto clear;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ int cheaper_backlog2_algo(int can_spawn) {
|
||||
|
||||
int i;
|
||||
#ifdef __linux__
|
||||
int backlog = uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS];
|
||||
int backlog = uwsgi.socket_timeout;
|
||||
#else
|
||||
int backlog = 0;
|
||||
#endif
|
||||
|
||||
@@ -13,11 +13,13 @@ struct uwsgi_cheaper_busyness_global {
|
||||
uint64_t busyness_max;
|
||||
uint64_t busyness_min;
|
||||
uint64_t *last_values;
|
||||
uint64_t *current_busyness;
|
||||
uint64_t total_avg_busyness;
|
||||
int *was_busy;
|
||||
uint64_t tcheck;
|
||||
uint64_t last_cheaped; // last time worker was cheaped due to low busyness
|
||||
uint64_t next_cheap; // timestamp, we can cheap worker after it
|
||||
uint64_t penalty; // penelty for respawning to fast, it will be added to multiplier
|
||||
uint64_t penalty; // penalty for respawning to fast, it will be added to multiplier
|
||||
uint64_t min_multi; //initial multiplier will be stored here
|
||||
uint64_t cheap_multi; // current multiplier value
|
||||
int last_action; // 1 - spawn workers ; 2 - cheap worker
|
||||
@@ -41,7 +43,7 @@ struct uwsgi_option uwsgi_cheaper_busyness_options[] = {
|
||||
uwsgi_opt_set_64bit, &uwsgi_cheaper_busyness_global.busyness_max, 0},
|
||||
|
||||
{"cheaper-busyness-min", required_argument, 0,
|
||||
"set the cheaper busyness low percent limit, belowe that value worker is considered idle (default 25)",
|
||||
"set the cheaper busyness low percent limit, below that value worker is considered idle (default 25)",
|
||||
uwsgi_opt_set_64bit, &uwsgi_cheaper_busyness_global.busyness_min, 0},
|
||||
|
||||
{"cheaper-busyness-multiplier", required_argument, 0,
|
||||
@@ -57,7 +59,7 @@ struct uwsgi_option uwsgi_cheaper_busyness_options[] = {
|
||||
|
||||
#ifdef __linux__
|
||||
{"cheaper-busyness-backlog-alert", required_argument, 0,
|
||||
"spawn emergency worker(s) if anytime listen queue is higher than this value (default 33)",
|
||||
"spawn emergency worker(s) if any time listen queue is higher than this value (default 33)",
|
||||
uwsgi_opt_set_int, &uwsgi_cheaper_busyness_global.backlog_alert, 0},
|
||||
{"cheaper-busyness-backlog-multiplier", required_argument, 0,
|
||||
"set cheaper multiplier used for emergency workers (default 3)",
|
||||
@@ -148,46 +150,6 @@ int cheaper_busyness_algo(int can_spawn) {
|
||||
// we use microseconds
|
||||
uint64_t t = uwsgi.cheaper_overload*1000000;
|
||||
|
||||
// this happens on the first run, the required memory is allocated
|
||||
if (!uwsgi_cheaper_busyness_global.last_values) {
|
||||
uwsgi_cheaper_busyness_global.last_values = uwsgi_calloc(sizeof(uint64_t) * uwsgi.numproc);
|
||||
}
|
||||
if (!uwsgi_cheaper_busyness_global.was_busy) {
|
||||
uwsgi_cheaper_busyness_global.was_busy = uwsgi_calloc(sizeof(int) * uwsgi.numproc);
|
||||
}
|
||||
|
||||
// set defaults
|
||||
if (!uwsgi_cheaper_busyness_global.busyness_max) uwsgi_cheaper_busyness_global.busyness_max = 50;
|
||||
if (!uwsgi_cheaper_busyness_global.busyness_min) uwsgi_cheaper_busyness_global.busyness_min = 25;
|
||||
if (!uwsgi_cheaper_busyness_global.cheap_multi) uwsgi_cheaper_busyness_global.cheap_multi = 10;
|
||||
if (!uwsgi_cheaper_busyness_global.penalty) uwsgi_cheaper_busyness_global.penalty = 2;
|
||||
|
||||
#ifdef __linux__
|
||||
if (!uwsgi_cheaper_busyness_global.backlog_alert) uwsgi_cheaper_busyness_global.backlog_alert = 33;
|
||||
if (!uwsgi_cheaper_busyness_global.backlog_multi) uwsgi_cheaper_busyness_global.backlog_multi = 3;
|
||||
if (!uwsgi_cheaper_busyness_global.backlog_step) uwsgi_cheaper_busyness_global.backlog_step = 1;
|
||||
if (!uwsgi_cheaper_busyness_global.backlog_nonzero_alert) uwsgi_cheaper_busyness_global.backlog_nonzero_alert = 60;
|
||||
#endif
|
||||
|
||||
if (!uwsgi_cheaper_busyness_global.min_multi) {
|
||||
// store initial multiplier so we don't loose its initial value
|
||||
uwsgi_cheaper_busyness_global.min_multi = uwsgi_cheaper_busyness_global.cheap_multi;
|
||||
// since this is first run we will print current values
|
||||
uwsgi_log("[busyness] settings: min=%llu%%, max=%llu%%, overload=%llu, multiplier=%llu, respawn penalty=%llu\n",
|
||||
uwsgi_cheaper_busyness_global.busyness_min, uwsgi_cheaper_busyness_global.busyness_max,
|
||||
uwsgi.cheaper_overload, uwsgi_cheaper_busyness_global.cheap_multi, uwsgi_cheaper_busyness_global.penalty);
|
||||
#ifdef __linux__
|
||||
uwsgi_log("[busyness] backlog alert is set to %d request(s), step is %d\n",
|
||||
uwsgi_cheaper_busyness_global.backlog_alert, uwsgi_cheaper_busyness_global.backlog_step);
|
||||
uwsgi_log("[busyness] backlog non-zero alert is set to %llu second(s)\n", uwsgi_cheaper_busyness_global.backlog_nonzero_alert);
|
||||
#endif
|
||||
}
|
||||
|
||||
// initialize with current time
|
||||
if (uwsgi_cheaper_busyness_global.tcheck == 0) uwsgi_cheaper_busyness_global.tcheck = uwsgi_micros();
|
||||
|
||||
if (uwsgi_cheaper_busyness_global.next_cheap == 0) set_next_cheap_time();
|
||||
|
||||
int active_workers = 0;
|
||||
uint64_t total_busyness = 0;
|
||||
uint64_t avg_busyness = 0;
|
||||
@@ -202,7 +164,7 @@ int cheaper_busyness_algo(int can_spawn) {
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
int backlog = uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS];
|
||||
int backlog = uwsgi.shared->backlog;
|
||||
#endif
|
||||
|
||||
uint64_t now = uwsgi_micros();
|
||||
@@ -228,11 +190,21 @@ int cheaper_busyness_algo(int can_spawn) {
|
||||
if (uwsgi_cheaper_busyness_global.verbose && active_workers > 1)
|
||||
uwsgi_log("[busyness] worker nr %d %llus average busyness is at %llu%%\n",
|
||||
i+1, uwsgi.cheaper_overload, percent);
|
||||
if (uwsgi.has_metrics) {
|
||||
// update metrics
|
||||
uwsgi_wlock(uwsgi.metrics_lock);
|
||||
uwsgi_cheaper_busyness_global.current_busyness[i] = percent;
|
||||
uwsgi_rwunlock(uwsgi.metrics_lock);
|
||||
}
|
||||
}
|
||||
uwsgi_cheaper_busyness_global.last_values[i] = uwsgi.workers[i+1].running_time;
|
||||
}
|
||||
|
||||
avg_busyness = (active_workers ? total_busyness / active_workers : 0);
|
||||
uwsgi_wlock(uwsgi.metrics_lock);
|
||||
uwsgi_cheaper_busyness_global.total_avg_busyness = avg_busyness;
|
||||
uwsgi_rwunlock(uwsgi.metrics_lock);
|
||||
|
||||
if (uwsgi_cheaper_busyness_global.verbose)
|
||||
uwsgi_log("[busyness] %ds average busyness of %d worker(s) is at %d%%\n",
|
||||
(int) uwsgi.cheaper_overload, (int) active_workers, (int) avg_busyness);
|
||||
@@ -261,7 +233,7 @@ int cheaper_busyness_algo(int can_spawn) {
|
||||
// worker was cheaped and then spawned back in less than current multiplier*cheaper_overload seconds
|
||||
// we will increase the multiplier so that next time worker will need to wait longer before being cheaped
|
||||
uwsgi_cheaper_busyness_global.cheap_multi += uwsgi_cheaper_busyness_global.penalty;
|
||||
uwsgi_log("[busyness] worker(s) respawned to fast, increasing chpeaper multiplier to %llu (+%llu)\n",
|
||||
uwsgi_log("[busyness] worker(s) respawned to fast, increasing cheaper multiplier to %llu (+%llu)\n",
|
||||
uwsgi_cheaper_busyness_global.cheap_multi, uwsgi_cheaper_busyness_global.penalty);
|
||||
} else {
|
||||
decrease_multi();
|
||||
@@ -333,7 +305,7 @@ int cheaper_busyness_algo(int can_spawn) {
|
||||
// time needed to cheap them, than a lot min<busy<max when we do not reset timer
|
||||
// and then another idle cycle than would trigger cheaping
|
||||
if (uwsgi_cheaper_busyness_global.verbose)
|
||||
uwsgi_log("[busyness] %llus average busyness is at %llu%%, %llu non-idle cycle(s), reseting cheaper timer\n",
|
||||
uwsgi_log("[busyness] %llus average busyness is at %llu%%, %llu non-idle cycle(s), resetting cheaper timer\n",
|
||||
uwsgi.cheaper_overload, avg_busyness, uwsgi_cheaper_busyness_global.tolerance_counter);
|
||||
set_next_cheap_time();
|
||||
} else {
|
||||
@@ -385,10 +357,73 @@ void uwsgi_cheaper_register_busyness(void) {
|
||||
uwsgi_register_cheaper_algo("busyness", cheaper_busyness_algo);
|
||||
}
|
||||
|
||||
static int uwsgi_cheaper_busyness_init(void) {
|
||||
if (!uwsgi.requested_cheaper_algo || strcmp(uwsgi.requested_cheaper_algo, "busyness")) return 0;
|
||||
// this happens on the first run, the required memory is allocated
|
||||
uwsgi_cheaper_busyness_global.last_values = uwsgi_calloc(sizeof(uint64_t) * uwsgi.numproc);
|
||||
uwsgi_cheaper_busyness_global.was_busy = uwsgi_calloc(sizeof(int) * uwsgi.numproc);
|
||||
|
||||
if (uwsgi.has_metrics) {
|
||||
// allocate metrics memory
|
||||
uwsgi_cheaper_busyness_global.current_busyness = uwsgi_calloc(sizeof(uint64_t) * uwsgi.numproc);
|
||||
}
|
||||
|
||||
// set defaults
|
||||
if (!uwsgi_cheaper_busyness_global.busyness_max) uwsgi_cheaper_busyness_global.busyness_max = 50;
|
||||
if (!uwsgi_cheaper_busyness_global.busyness_min) uwsgi_cheaper_busyness_global.busyness_min = 25;
|
||||
if (!uwsgi_cheaper_busyness_global.cheap_multi) uwsgi_cheaper_busyness_global.cheap_multi = 10;
|
||||
if (!uwsgi_cheaper_busyness_global.penalty) uwsgi_cheaper_busyness_global.penalty = 2;
|
||||
|
||||
#ifdef __linux__
|
||||
if (!uwsgi_cheaper_busyness_global.backlog_alert) uwsgi_cheaper_busyness_global.backlog_alert = 33;
|
||||
if (!uwsgi_cheaper_busyness_global.backlog_multi) uwsgi_cheaper_busyness_global.backlog_multi = 3;
|
||||
if (!uwsgi_cheaper_busyness_global.backlog_step) uwsgi_cheaper_busyness_global.backlog_step = 1;
|
||||
if (!uwsgi_cheaper_busyness_global.backlog_nonzero_alert) uwsgi_cheaper_busyness_global.backlog_nonzero_alert = 60;
|
||||
#endif
|
||||
|
||||
// store initial multiplier so we don't loose that value
|
||||
uwsgi_cheaper_busyness_global.min_multi = uwsgi_cheaper_busyness_global.cheap_multi;
|
||||
// since this is first run we will print current values
|
||||
uwsgi_log("[busyness] settings: min=%llu%%, max=%llu%%, overload=%llu, multiplier=%llu, respawn penalty=%llu\n",
|
||||
uwsgi_cheaper_busyness_global.busyness_min, uwsgi_cheaper_busyness_global.busyness_max,
|
||||
uwsgi.cheaper_overload, uwsgi_cheaper_busyness_global.cheap_multi, uwsgi_cheaper_busyness_global.penalty);
|
||||
#ifdef __linux__
|
||||
uwsgi_log("[busyness] backlog alert is set to %d request(s), step is %d\n",
|
||||
uwsgi_cheaper_busyness_global.backlog_alert, uwsgi_cheaper_busyness_global.backlog_step);
|
||||
uwsgi_log("[busyness] backlog non-zero alert is set to %llu second(s)\n", uwsgi_cheaper_busyness_global.backlog_nonzero_alert);
|
||||
#endif
|
||||
|
||||
// register metrics if enabled
|
||||
if (uwsgi.has_metrics) {
|
||||
int i;
|
||||
char buf[4096];
|
||||
char buf2[4096];
|
||||
for (i = 0; i < uwsgi.numproc; i++) {
|
||||
if (snprintf(buf, 4096, "worker.%d.plugin.cheaper_busyness.busyness", i+1) <= 0) {
|
||||
uwsgi_log("[busyness] unable to register busyness metric for worker %d\n", i+1);
|
||||
exit(1);
|
||||
}
|
||||
if (snprintf(buf2, 4096, "3.%d.100.1", i+1) <= 0) {
|
||||
uwsgi_log("[busyness] unable to register busyness metric oid for worker %d\n", i+1);
|
||||
exit(1);
|
||||
}
|
||||
uwsgi_register_metric(buf, buf2, UWSGI_METRIC_GAUGE, "ptr", &uwsgi_cheaper_busyness_global.current_busyness[i], 0, NULL);
|
||||
}
|
||||
uwsgi_register_metric("plugin.cheaper_busyness.total_avg_busyness", "4.100.1", UWSGI_METRIC_GAUGE, "ptr", &uwsgi_cheaper_busyness_global.total_avg_busyness, 0, NULL);
|
||||
uwsgi_log("[busyness] metrics registered\n");
|
||||
}
|
||||
|
||||
// initialize timers
|
||||
uwsgi_cheaper_busyness_global.tcheck = uwsgi_micros();
|
||||
set_next_cheap_time();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct uwsgi_plugin cheaper_busyness_plugin = {
|
||||
|
||||
.name = "cheaper_busyness",
|
||||
.on_load = uwsgi_cheaper_register_busyness,
|
||||
.on_load = uwsgi_cheaper_register_busyness,
|
||||
.options = uwsgi_cheaper_busyness_options,
|
||||
|
||||
.init = uwsgi_cheaper_busyness_init
|
||||
};
|
||||
|
||||
@@ -272,6 +272,18 @@ void corerouter_manage_subscription(char *key, uint16_t keylen, char *val, uint1
|
||||
usr->sign = val;
|
||||
usr->sign_len = vallen;
|
||||
}
|
||||
else if (!uwsgi_strncmp("sni_key", 7, key, keylen)) {
|
||||
usr->sni_key = val;
|
||||
usr->sni_key_len = vallen;
|
||||
}
|
||||
else if (!uwsgi_strncmp("sni_crt", 7, key, keylen)) {
|
||||
usr->sni_crt = val;
|
||||
usr->sni_crt_len = vallen;
|
||||
}
|
||||
else if (!uwsgi_strncmp("sni_ca", 6, key, keylen)) {
|
||||
usr->sni_ca = val;
|
||||
usr->sni_ca_len = vallen;
|
||||
}
|
||||
}
|
||||
|
||||
void corerouter_close_peer(struct uwsgi_corerouter *ucr, struct corerouter_peer *peer) {
|
||||
@@ -919,10 +931,13 @@ int uwsgi_corerouter_init(struct uwsgi_corerouter *ucr) {
|
||||
uwsgi_log("starting %s in cheap mode\n", ucr->name);
|
||||
}
|
||||
for (i = 0; i < ucr->processes; i++) {
|
||||
if (register_gateway(ucr->name, uwsgi_corerouter_loop, ucr) == NULL) {
|
||||
struct uwsgi_gateway *ug = register_gateway(ucr->name, uwsgi_corerouter_loop, ucr);
|
||||
if (ug == NULL) {
|
||||
uwsgi_log("unable to register the %s gateway\n", ucr->name);
|
||||
exit(1);
|
||||
}
|
||||
ug->uid = ucr->uid;
|
||||
ug->gid = ucr->gid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1021,6 +1036,9 @@ void corerouter_send_stats(struct uwsgi_corerouter *ucr) {
|
||||
if (uwsgi_stats_keyvaln_comma(us, "key", s_slot->key, s_slot->keylen)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "hash", (unsigned long long) s_slot->hash)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "hits", (unsigned long long) s_slot->hits)) goto end0;
|
||||
#ifdef UWSGI_SSL
|
||||
if (uwsgi_stats_keylong_comma(us, "sni_enabled", (unsigned long long) s_slot->sni_enabled)) goto end0;
|
||||
#endif
|
||||
|
||||
if (uwsgi_stats_key(us , "nodes")) goto end0;
|
||||
if (uwsgi_stats_list_open(us)) goto end0;
|
||||
@@ -1034,9 +1052,13 @@ void corerouter_send_stats(struct uwsgi_corerouter *ucr) {
|
||||
if (uwsgi_stats_keylong_comma(us, "modifier1", (unsigned long long) s_node->modifier1)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "modifier2", (unsigned long long) s_node->modifier2)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "last_check", (unsigned long long) s_node->last_check)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "pid", (unsigned long long) s_node->pid)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "uid", (unsigned long long) s_node->uid)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "gid", (unsigned long long) s_node->gid)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "requests", (unsigned long long) s_node->requests)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "last_requests", (unsigned long long) s_node->last_requests)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "tx", (unsigned long long) s_node->transferred)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "tx", (unsigned long long) s_node->tx)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "rx", (unsigned long long) s_node->rx)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "cores", (unsigned long long) s_node->cores)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "load", (unsigned long long) s_node->load)) goto end0;
|
||||
if (uwsgi_stats_keylong_comma(us, "weight", (unsigned long long) s_node->weight)) goto end0;
|
||||
@@ -1076,7 +1098,7 @@ void corerouter_send_stats(struct uwsgi_corerouter *ucr) {
|
||||
size_t remains = us->pos;
|
||||
off_t pos = 0;
|
||||
while(remains > 0) {
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi_waitfd_write(client_fd, uwsgi.socket_timeout);
|
||||
if (ret <= 0) {
|
||||
goto end0;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
uwsgi_cr_error(peer, f);\
|
||||
return -1;\
|
||||
}\
|
||||
if (peer != peer->session->main_peer && peer->un) peer->un->rx+=len;\
|
||||
peer->out_pos += len;
|
||||
|
||||
#define cr_write_buf(peer, ubuf, f) write(peer->fd, ubuf->buf + ubuf##_pos, ubuf->pos - ubuf##_pos);\
|
||||
@@ -29,6 +30,7 @@
|
||||
uwsgi_cr_error(peer, f);\
|
||||
return -1;\
|
||||
}\
|
||||
if (peer != peer->session->main_peer && peer->un) peer->un->rx+=len;\
|
||||
ubuf##_pos += len;
|
||||
|
||||
#define cr_write_complete(peer) peer->out_pos == peer->out->pos
|
||||
@@ -51,6 +53,7 @@
|
||||
uwsgi_cr_error(peer, f);\
|
||||
return -1;\
|
||||
}\
|
||||
if (peer != peer->session->main_peer && peer->un) peer->un->tx+=len;\
|
||||
peer->in->pos += len;\
|
||||
|
||||
#define cr_read_exact(peer, l, f) read(peer->fd, peer->in->buf + peer->in->pos, (l - peer->in->pos));\
|
||||
@@ -59,6 +62,7 @@
|
||||
uwsgi_cr_error(peer, f);\
|
||||
return -1;\
|
||||
}\
|
||||
if (peer != peer->session->main_peer && peer->un) peer->un->tx+=len;\
|
||||
peer->in->pos += len;\
|
||||
|
||||
#define cr_reset_hooks(peer) if(!peer->session->main_peer->disabled) {\
|
||||
@@ -258,6 +262,9 @@ struct uwsgi_corerouter {
|
||||
|
||||
uint64_t active_sessions;
|
||||
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
|
||||
};
|
||||
|
||||
// a session is started when a client connect to the router
|
||||
|
||||
@@ -4,7 +4,7 @@ common functions for various routers (fastrouter, http...)
|
||||
|
||||
*/
|
||||
|
||||
#include "../../uwsgi.h"
|
||||
#include <uwsgi.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
@@ -79,6 +79,9 @@ void uwsgi_corerouter_setup_sockets(struct uwsgi_corerouter *ucr) {
|
||||
}
|
||||
else {
|
||||
ugs->fd = bind_to_unix_dgram(ugs->name);
|
||||
if (ugs->fd < 1 || (uwsgi.subscriptions_use_credentials && uwsgi_socket_passcred(ugs->fd))) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
uwsgi_socket_nb(ugs->fd);
|
||||
}
|
||||
@@ -113,10 +116,17 @@ void uwsgi_corerouter_manage_subscription(struct uwsgi_corerouter *ucr, int id,
|
||||
int i;
|
||||
struct uwsgi_subscribe_req usr;
|
||||
char bbuf[4096];
|
||||
ssize_t len = -1;
|
||||
|
||||
ssize_t len = recv(ugs->fd, bbuf, 4096, 0);
|
||||
memset(&usr, 0, sizeof(struct uwsgi_subscribe_req));
|
||||
|
||||
if (uwsgi.subscriptions_use_credentials) {
|
||||
len = uwsgi_recv_cred2(ugs->fd, bbuf, 4096, &usr.pid, &usr.uid, &usr.gid);
|
||||
}
|
||||
else {
|
||||
len = recv(ugs->fd, bbuf, 4096, 0);
|
||||
}
|
||||
if (len > 0) {
|
||||
memset(&usr, 0, sizeof(struct uwsgi_subscribe_req));
|
||||
uwsgi_hooked_parse(bbuf + 4, len - 4, corerouter_manage_subscription, &usr);
|
||||
if (usr.sign_len > 0) {
|
||||
// calc the base size
|
||||
|
||||
+41
-12
@@ -12,8 +12,8 @@ static void uwsgi_opt_setup_coroae(char *opt, char *value, void *null) {
|
||||
|
||||
// set async mode
|
||||
uwsgi_opt_set_int(opt, value, &uwsgi.async);
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] < 30) {
|
||||
uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] = 30;
|
||||
if (uwsgi.socket_timeout < 30) {
|
||||
uwsgi.socket_timeout = 30;
|
||||
}
|
||||
// set loop engine
|
||||
uwsgi.loop = "coroae";
|
||||
@@ -51,7 +51,7 @@ SV * coroae_coro_new(CV *block) {
|
||||
XPUSHs(sv_2mortal(newSVpv( "Coro", 4)));
|
||||
XPUSHs(newRV_inc((SV *)block));
|
||||
PUTBACK;
|
||||
call_method("new", G_SCALAR);
|
||||
call_method("new", G_SCALAR|G_EVAL);
|
||||
SPAGAIN;
|
||||
if(SvTRUE(ERRSV)) {
|
||||
uwsgi_log("[uwsgi-perl error] %s", SvPV_nolen(ERRSV));
|
||||
@@ -65,6 +65,33 @@ SV * coroae_coro_new(CV *block) {
|
||||
return newobj;
|
||||
}
|
||||
|
||||
static int coroae_wait_milliseconds(int timeout) {
|
||||
int ret = -1;
|
||||
dSP;
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(SP);
|
||||
XPUSHs(newSVnv(((double)timeout)/1000.0));
|
||||
PUTBACK;
|
||||
call_pv("Coro::AnyEvent::sleep", G_SCALAR|G_EVAL);
|
||||
SPAGAIN;
|
||||
if(SvTRUE(ERRSV)) {
|
||||
uwsgi_log("[uwsgi-perl error] %s", SvPV_nolen(ERRSV));
|
||||
}
|
||||
else {
|
||||
SV *p_ret = POPs;
|
||||
if (SvTRUE(p_ret)) {
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
PUTBACK;
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int coroae_wait_fd_read(int fd, int timeout) {
|
||||
int ret = 0;
|
||||
dSP;
|
||||
@@ -74,7 +101,7 @@ static int coroae_wait_fd_read(int fd, int timeout) {
|
||||
XPUSHs(newSViv(fd));
|
||||
XPUSHs(newSViv(timeout));
|
||||
PUTBACK;
|
||||
call_pv("Coro::AnyEvent::readable", G_SCALAR);
|
||||
call_pv("Coro::AnyEvent::readable", G_SCALAR|G_EVAL);
|
||||
SPAGAIN;
|
||||
if(SvTRUE(ERRSV)) {
|
||||
uwsgi_log("[uwsgi-perl error] %s", SvPV_nolen(ERRSV));
|
||||
@@ -101,13 +128,14 @@ static int coroae_wait_fd_write(int fd, int timeout) {
|
||||
XPUSHs(sv_2mortal(newSViv(fd)));
|
||||
XPUSHs(sv_2mortal(newSViv(timeout)));
|
||||
PUTBACK;
|
||||
call_pv("Coro::AnyEvent::writable", G_SCALAR);
|
||||
call_pv("Coro::AnyEvent::writable", G_SCALAR|G_EVAL);
|
||||
SPAGAIN;
|
||||
if(SvTRUE(ERRSV)) {
|
||||
uwsgi_log("[uwsgi-perl error] %s", SvPV_nolen(ERRSV));
|
||||
}
|
||||
else {
|
||||
if (SvTRUE(POPs)) {
|
||||
SV *p_ret = POPs;
|
||||
if (SvTRUE(p_ret)) {
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
@@ -136,7 +164,7 @@ XS(XS_coroae_accept_request) {
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
int ret = uwsgi.wait_read_hook(wsgi_req->fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_read_hook(wsgi_req->fd, uwsgi.socket_timeout);
|
||||
wsgi_req->switches++;
|
||||
|
||||
if (ret <= 0) {
|
||||
@@ -216,8 +244,8 @@ edge:
|
||||
wsgi_req->start_of_request_in_sec = wsgi_req->start_of_request/1000000;
|
||||
|
||||
// enter harakiri mode
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
set_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
|
||||
@@ -275,7 +303,7 @@ static SV *coroae_add_watcher(int fd, SV *cb) {
|
||||
XPUSHs(newRV_inc(cb));
|
||||
PUTBACK;
|
||||
|
||||
call_method( "io", G_SCALAR);
|
||||
call_method( "io", G_SCALAR|G_EVAL);
|
||||
|
||||
SPAGAIN;
|
||||
if(SvTRUE(ERRSV)) {
|
||||
@@ -306,7 +334,7 @@ static SV *coroae_condvar_new() {
|
||||
XPUSHs(sv_2mortal(newSVpv( "AnyEvent", 8)));
|
||||
PUTBACK;
|
||||
|
||||
call_method( "condvar", G_SCALAR);
|
||||
call_method( "condvar", G_SCALAR|G_EVAL);
|
||||
|
||||
SPAGAIN;
|
||||
if(SvTRUE(ERRSV)) {
|
||||
@@ -332,7 +360,7 @@ static void coroae_wait_condvar(SV *cv) {
|
||||
XPUSHs(cv);
|
||||
PUTBACK;
|
||||
|
||||
call_method( "recv", G_DISCARD);
|
||||
call_method( "recv", G_DISCARD|G_EVAL);
|
||||
|
||||
SPAGAIN;
|
||||
if(SvTRUE(ERRSV)) {
|
||||
@@ -377,6 +405,7 @@ static void coroae_loop() {
|
||||
uwsgi.current_wsgi_req = coroae_current_wsgi_req;
|
||||
uwsgi.wait_write_hook = coroae_wait_fd_write;
|
||||
uwsgi.wait_read_hook = coroae_wait_fd_read;
|
||||
uwsgi.wait_milliseconds_hook = coroae_wait_milliseconds;
|
||||
|
||||
I_CORO_API("uwsgi::coroae");
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ if not coroapi:
|
||||
|
||||
NAME='coroae'
|
||||
CFLAGS = os.popen('perl -MExtUtils::Embed -e ccopts').read().rstrip().split()
|
||||
CFLAGS += ['-Wno-int-to-pointer-cast', '-Wno-error=int-to-pointer-cast', '-I%s/Coro' % coroapi]
|
||||
CFLAGS += ['-Wno-int-to-pointer-cast', '-Wno-error=format', '-Wno-error=int-to-pointer-cast', '-I%s/Coro' % coroapi]
|
||||
LDFLAGS = []
|
||||
LIBS = []
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ static void curl_cron_func(struct uwsgi_cron *uc, time_t now) {
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, uc->command);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, uwsgi.socket_timeout);
|
||||
// use 1 minute as the cron resolution
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 60);
|
||||
uwsgi_log("[uwsgi-curl-cron] requesting %s\n", uc->command);
|
||||
|
||||
@@ -25,7 +25,7 @@ extern "C" void uwsgi_imperial_monitor_mongodb(struct uwsgi_emperor_scanner *ues
|
||||
// the connection object (will be automatically destroyed at each cycle)
|
||||
mongo::DBClientConnection c;
|
||||
// set the socket timeout
|
||||
c.setSoTimeout(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
c.setSoTimeout(uwsgi.socket_timeout);
|
||||
// connect
|
||||
c.connect(uems->address);
|
||||
|
||||
|
||||
@@ -52,9 +52,7 @@ s.send_multipart(['touch','foo.ini',"[uwsgi]\nsocket=:4142"])
|
||||
|
||||
*/
|
||||
|
||||
#ifdef UWSGI_ZEROMQ
|
||||
|
||||
#include "../../uwsgi.h"
|
||||
#include <uwsgi.h>
|
||||
#include <zmq.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
@@ -215,7 +213,11 @@ static void uwsgi_imperial_monitor_zeromq_event(struct uwsgi_emperor_scanner *ue
|
||||
// initialize the zmq PULL socket
|
||||
static void uwsgi_imperial_monitor_zeromq_init(struct uwsgi_emperor_scanner *ues) {
|
||||
|
||||
void *context = uwsgi_zeromq_init();
|
||||
void *context = zmq_init(1);
|
||||
if (!context) {
|
||||
uwsgi_error("uwsgi_imperial_monitor_zeromq_init()/zmq_init()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ues->data = zmq_socket(context, ZMQ_PULL);
|
||||
if (!ues->data) {
|
||||
@@ -256,7 +258,3 @@ struct uwsgi_plugin emperor_zeromq_plugin = {
|
||||
.name = "emperor_zeromq",
|
||||
.on_load = emperor_zeromq_init,
|
||||
};
|
||||
|
||||
#else
|
||||
#error the uWSGI ZeroMQ imperial monitor requires uWSGI zeromq support
|
||||
#endif
|
||||
|
||||
@@ -264,7 +264,7 @@ static void uwsgi_gccgo_request_goroutine(void *arg) {
|
||||
int ret,status;
|
||||
|
||||
for(;;) {
|
||||
ret = uwsgi.wait_read_hook(wsgi_req->fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
ret = uwsgi.wait_read_hook(wsgi_req->fd, uwsgi.socket_timeout);
|
||||
wsgi_req->switches++;
|
||||
|
||||
if (ret <= 0) {
|
||||
@@ -388,8 +388,8 @@ retry:
|
||||
wsgi_req->start_of_request_in_sec = wsgi_req->start_of_request/1000000;
|
||||
|
||||
// enter harakiri mode
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
set_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
// spawn the new goroutine
|
||||
|
||||
@@ -8,8 +8,8 @@ static void uwsgi_opt_setup_gevent(char *opt, char *value, void *null) {
|
||||
|
||||
// set async mode
|
||||
uwsgi_opt_set_int(opt, value, &uwsgi.async);
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] < 30) {
|
||||
uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] = 30;
|
||||
if (uwsgi.socket_timeout < 30) {
|
||||
uwsgi.socket_timeout = 30;
|
||||
}
|
||||
// set loop engine
|
||||
uwsgi.loop = "gevent";
|
||||
@@ -210,8 +210,8 @@ edge:
|
||||
wsgi_req->start_of_request_in_sec = wsgi_req->start_of_request/1000000;
|
||||
|
||||
// enter harakiri mode
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
|
||||
set_harakiri(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI]);
|
||||
if (uwsgi.harakiri_options.workers > 0) {
|
||||
set_harakiri(uwsgi.harakiri_options.workers);
|
||||
}
|
||||
|
||||
// hack to easily pass wsgi_req pointer to the greenlet
|
||||
@@ -257,7 +257,7 @@ PyObject *py_uwsgi_gevent_request(PyObject * self, PyObject * args) {
|
||||
greenlet_switch = PyObject_GetAttrString(current_greenlet, "switch");
|
||||
|
||||
for(;;) {
|
||||
int ret = uwsgi.wait_read_hook(wsgi_req->fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
|
||||
int ret = uwsgi.wait_read_hook(wsgi_req->fd, uwsgi.socket_timeout);
|
||||
wsgi_req->switches++;
|
||||
|
||||
if (ret <= 0) {
|
||||
@@ -349,7 +349,7 @@ static void gevent_loop() {
|
||||
uwsgi_log("!!! Running gevent without threads IS NOT recommended, enable them with --enable-threads !!!\n");
|
||||
}
|
||||
|
||||
if (uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] < 30) {
|
||||
if (uwsgi.socket_timeout < 30) {
|
||||
uwsgi_log("!!! Running gevent with a socket-timeout lower than 30 seconds is not recommended, tune it with --socket-timeout !!!\n");
|
||||
}
|
||||
|
||||
@@ -361,6 +361,7 @@ static void gevent_loop() {
|
||||
|
||||
uwsgi.wait_write_hook = uwsgi_gevent_wait_write_hook;
|
||||
uwsgi.wait_read_hook = uwsgi_gevent_wait_read_hook;
|
||||
uwsgi.wait_milliseconds_hook = uwsgi_gevent_wait_milliseconds_hook;
|
||||
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
int uwsgi_gevent_wait_write_hook(int, int);
|
||||
int uwsgi_gevent_wait_read_hook(int, int);
|
||||
int uwsgi_gevent_wait_milliseconds_hook(int);
|
||||
|
||||
#define GEVENT_SWITCH PyObject *gswitch = python_call(ugevent.greenlet_switch, ugevent.greenlet_switch_args, 0, NULL); Py_DECREF(gswitch)
|
||||
#define GET_CURRENT_GREENLET python_call(ugevent.get_current, ugevent.get_current_args, 0, NULL)
|
||||
|
||||
@@ -98,3 +98,42 @@ int uwsgi_gevent_wait_read_hook(int fd, int timeout) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int uwsgi_gevent_wait_milliseconds_hook(int timeout) {
|
||||
|
||||
PyObject *ret = NULL;
|
||||
|
||||
PyObject *timer = PyObject_CallMethod(ugevent.hub_loop, "timer", "f", ((double) timeout)/1000.0);
|
||||
if (!timer) return -1;
|
||||
|
||||
PyObject *current_greenlet = GET_CURRENT_GREENLET;
|
||||
PyObject *current = PyObject_GetAttrString(current_greenlet, "switch");
|
||||
|
||||
ret = PyObject_CallMethod(timer, "start", "OO", current, timer);
|
||||
if (!ret) {
|
||||
Py_DECREF(current); Py_DECREF(current_greenlet);
|
||||
Py_DECREF(timer);
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(ret);
|
||||
|
||||
ret = PyObject_CallMethod(ugevent.hub, "switch", NULL);
|
||||
if (!ret) {
|
||||
ret = PyObject_CallMethod(timer, "stop", NULL);
|
||||
if (ret) { Py_DECREF(ret); }
|
||||
Py_DECREF(current); Py_DECREF(current_greenlet);
|
||||
Py_DECREF(timer);
|
||||
return -1;
|
||||
}
|
||||
Py_DECREF(ret);
|
||||
|
||||
if (ret == timer) {
|
||||
ret = PyObject_CallMethod(timer, "stop", NULL);
|
||||
if (ret) { Py_DECREF(ret); }
|
||||
Py_DECREF(current); Py_DECREF(current_greenlet);
|
||||
Py_DECREF(timer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ static void uwsgi_glusterfs_add_mountpoint(char *arg, size_t arg_len) {
|
||||
static void uwsgi_glusterfs_setup() {
|
||||
|
||||
if (!uglusterfs.timeout) {
|
||||
uglusterfs.timeout = uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT];
|
||||
uglusterfs.timeout = uwsgi.socket_timeout;
|
||||
}
|
||||
|
||||
struct uwsgi_string_list *usl = uglusterfs.mountpoints;
|
||||
|
||||
@@ -90,7 +90,7 @@ ssize_t uwsgi_graylog2_logger(struct uwsgi_logger *ul, char *message, size_t len
|
||||
int rlen = snprintf(g2c.json_buf, MAX_GELF, "{ \"version\": \"1.0\", \"host\": \"%s\", \"short_message\": \"%.*s\", \"full_message\": \"%.*s\", \"timestamp\": %d, \"level\": 5, \"facility\": \"uWSGI-%s\" }",
|
||||
g2c.host, truncated, g2c.escaped_buf, (int)g2c.escaped_len, g2c.escaped_buf, (int) uwsgi_now(), UWSGI_VERSION);
|
||||
|
||||
if (rlen > 0) {
|
||||
if (rlen > 0 && rlen < MAX_GELF) {
|
||||
if (compressBound((uLong) rlen) <= MAX_GELF) {
|
||||
if (compress((Bytef *) ul->buf, &destLen, (Bytef *) g2c.json_buf, (uLong) rlen) == Z_OK) {
|
||||
return sendto(ul->fd, ul->buf, destLen, 0, (const struct sockaddr *) &ul->addr, ul->addr_len);
|
||||
|
||||
@@ -169,7 +169,7 @@ static struct uwsgi_gridfs_mountpoint *uwsgi_gridfs_add_mountpoint(char *arg, si
|
||||
ugm->timeout = atoi(ugm->timeout_str);
|
||||
}
|
||||
else {
|
||||
ugm->timeout = uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT];
|
||||
ugm->timeout = uwsgi.socket_timeout;
|
||||
}
|
||||
|
||||
if (ugm->prefix) {
|
||||
|
||||
+7
-1
@@ -54,6 +54,8 @@ struct uwsgi_option http_options[] = {
|
||||
{"http-ss", required_argument, 0, "run the http router stats server", uwsgi_opt_set_str, &uhttp.cr.stats_server, 0},
|
||||
{"http-harakiri", required_argument, 0, "enable http router harakiri", uwsgi_opt_set_int, &uhttp.cr.harakiri, 0},
|
||||
{"http-stud-prefix", required_argument, 0, "expect a stud prefix (1byte family + 4/16 bytes address) on connections from the specified address", uwsgi_opt_add_addr_list, &uhttp.stud_prefix, 0},
|
||||
{"http-uid", required_argument, 0, "drop http routr privileges to the specified uid", uwsgi_opt_uid, &uhttp.cr.uid, 0 },
|
||||
{"http-gid", required_argument, 0, "drop http routr privileges to the specified gid", uwsgi_opt_gid, &uhttp.cr.gid, 0 },
|
||||
{0, 0, 0, 0, 0, 0, 0},
|
||||
};
|
||||
|
||||
@@ -616,6 +618,9 @@ ssize_t http_parse(struct corerouter_peer *main_peer) {
|
||||
|
||||
// is it http body ?
|
||||
if (hr->rnrn == 4) {
|
||||
// something bad happened in keepalive mode...
|
||||
if (!main_peer->session->peers) return -1;
|
||||
|
||||
if (hr->content_length == 0 && !hr->raw_body) {
|
||||
// ignore data...
|
||||
main_peer->in->pos = 0;
|
||||
@@ -869,7 +874,8 @@ int http_alloc_session(struct uwsgi_corerouter *ucr, struct uwsgi_gateway_socket
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
uwsgi_cr_set_hooks(cs->main_peer, cs->main_peer->last_hook_read, NULL);
|
||||
if (uwsgi_cr_set_hooks(cs->main_peer, cs->main_peer->last_hook_read, NULL))
|
||||
return -1;
|
||||
cs->close = hr_session_close;
|
||||
break;
|
||||
}
|
||||
|
||||
+2
-1
@@ -432,7 +432,8 @@ static uint16_t ldap_passwd_check(struct uwsgi_ldapauth_config *ulc, char *auth)
|
||||
LDAPMessage *msg, *entry;
|
||||
// use the minimal amount of memory
|
||||
char *filter = uwsgi_malloc( strlen(ulc->login_attr) + (colon-auth) + strlen(ulc->filter) + 7);
|
||||
if (snprintf(filter, 1024, "(&(%s=%.*s)%s)", ulc->login_attr, (int) (colon-auth), auth, ulc->filter) <= 0) {
|
||||
ret = snprintf(filter, 1024, "(&(%s=%.*s)%s)", ulc->login_attr, (int) (colon-auth), auth, ulc->filter);
|
||||
if (ret <= 0 || ret >= 1024) {
|
||||
free(filter);
|
||||
uwsgi_error("ldap_passwd_check()/sprintfn(filter)");
|
||||
goto close;
|
||||
|
||||
@@ -7,14 +7,16 @@ static int uwsgi_libtcc_hook(char *arg) {
|
||||
char *func_base = "uwsgi_libtcc_func";
|
||||
size_t func_len = strlen(func_base) + sizeof(UMAX64_STR);
|
||||
char *func_name = uwsgi_malloc(func_len);
|
||||
if (snprintf(func_name, func_len, "%s%llu", func_base, uwsgi_libtcc_counter) < (int) strlen(func_base)) {
|
||||
int ret = snprintf(func_name, func_len, "%s%llu", func_base, uwsgi_libtcc_counter);
|
||||
if (ret < (int) strlen(func_base) || ret >= (int) func_len) {
|
||||
free(func_name);
|
||||
return -1;
|
||||
}
|
||||
uwsgi_libtcc_counter++;
|
||||
size_t source_len = 64 + func_len + strlen(arg);
|
||||
char *source = uwsgi_malloc(source_len);
|
||||
if (snprintf(source, source_len, "void %s() { %s ;}", func_name, arg) < (int) ( strlen(func_base) + strlen(arg))) {
|
||||
ret = snprintf(source, source_len, "void %s() { %s ;}", func_name, arg);
|
||||
if (ret < (int) ( strlen(func_base) + strlen(arg)) || ret >= (int) (source_len)) {
|
||||
free(func_name);
|
||||
free(source);
|
||||
return -1;
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#include <uwsgi.h>
|
||||
#include <zmq.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
static struct uwsgi_option uwsgi_zmq_logger_options[] = {
|
||||
{"log-zeromq", required_argument, 0, "send logs to a zeromq server", uwsgi_opt_set_logger, "zeromq", UWSGI_OPT_MASTER | UWSGI_OPT_LOG_MASTER},
|
||||
{NULL, 0, 0, NULL, NULL, NULL, 0},
|
||||
};
|
||||
|
||||
// the zeromq logger
|
||||
static ssize_t uwsgi_zeromq_logger(struct uwsgi_logger *ul, char *message, size_t len) {
|
||||
|
||||
if (!ul->configured) {
|
||||
|
||||
if (!ul->arg) {
|
||||
uwsgi_log_safe("invalid zeromq syntax\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *ctx = zmq_init(1);
|
||||
if (!ctx) exit(1);
|
||||
|
||||
ul->data = zmq_socket(ctx, ZMQ_PUSH);
|
||||
if (ul->data == NULL) {
|
||||
uwsgi_error_safe("zmq_socket()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (zmq_connect(ul->data, ul->arg) < 0) {
|
||||
uwsgi_error_safe("zmq_connect()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ul->configured = 1;
|
||||
}
|
||||
|
||||
zmq_msg_t msg;
|
||||
if (zmq_msg_init_size(&msg, len) == 0) {
|
||||
memcpy(zmq_msg_data(&msg), message, len);
|
||||
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,0,0)
|
||||
zmq_sendmsg(ul->data, &msg, 0);
|
||||
#else
|
||||
zmq_send(ul->data, &msg, 0);
|
||||
#endif
|
||||
zmq_msg_close(&msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void uwsgi_zmq_logger_register() {
|
||||
uwsgi_register_logger("zmq", uwsgi_zeromq_logger);
|
||||
uwsgi_register_logger("zeromq", uwsgi_zeromq_logger);
|
||||
}
|
||||
|
||||
struct uwsgi_plugin logzmq_plugin = {
|
||||
.name = "logzmq",
|
||||
.options = uwsgi_zmq_logger_options,
|
||||
.on_load = uwsgi_zmq_logger_register,
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
NAME='logzmq'
|
||||
CFLAGS = []
|
||||
LDFLAGS = []
|
||||
LIBS = ['-lzmq']
|
||||
|
||||
GCC_LIST = ['plugin']
|
||||
+273
-6
@@ -5,8 +5,10 @@
|
||||
#include <lauxlib.h>
|
||||
|
||||
#if LUA_VERSION_NUM < 502
|
||||
# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
|
||||
# define luaL_newuwsgilib(L,l) luaL_register(L, "uwsgi",l)
|
||||
# define lua_rawlen lua_objlen
|
||||
#else
|
||||
# define luaL_newuwsgilib(L,l) lua_newtable(L);luaL_setfuncs (L, l, 0);lua_pushvalue(L,-1);lua_setglobal(L,"uwsgi")
|
||||
#endif
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
@@ -16,6 +18,7 @@ struct uwsgi_lua {
|
||||
char *shell;
|
||||
char *filename;
|
||||
struct uwsgi_string_list *load;
|
||||
int gc_freq;
|
||||
} ulua;
|
||||
|
||||
struct uwsgi_plugin lua_plugin;
|
||||
@@ -40,6 +43,7 @@ static struct uwsgi_option uwsgi_lua_options[] = {
|
||||
{"lua-load", required_argument, 0, "load a lua file", uwsgi_opt_add_string_list, &ulua.load, 0},
|
||||
{"lua-shell", no_argument, 0, "run the lua interactive shell (debug.debug())", uwsgi_opt_luashell, NULL, 0},
|
||||
{"luashell", no_argument, 0, "run the lua interactive shell (debug.debug())", uwsgi_opt_luashell, NULL, 0},
|
||||
{"lua-gc-freq", no_argument, 0, "set the lua gc frequency (default: 0, runs after every request)", uwsgi_opt_set_int, &ulua.gc_freq, 0},
|
||||
|
||||
{0, 0, 0, 0},
|
||||
|
||||
@@ -265,6 +269,250 @@ error:
|
||||
|
||||
}
|
||||
|
||||
static int uwsgi_api_async_sleep(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc == 0) goto end;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
int timeout = lua_tonumber(L, 1);
|
||||
|
||||
if (timeout >= 0) {
|
||||
async_add_timeout(wsgi_req, timeout);
|
||||
}
|
||||
end:
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int uwsgi_api_wait_fd_read(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc == 0) goto end;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
int fd = lua_tonumber(L, 1);
|
||||
int timeout = 0;
|
||||
if (argc > 1) {
|
||||
timeout = lua_tonumber(L, 2);
|
||||
}
|
||||
|
||||
if (async_add_fd_read(wsgi_req, fd, timeout)) {
|
||||
lua_pushstring(L, "unable to call async_add_fd_read()");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
end:
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int uwsgi_api_wait_fd_write(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc == 0) goto end;
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
int fd = lua_tonumber(L, 1);
|
||||
int timeout = 0;
|
||||
if (argc > 1) {
|
||||
timeout = lua_tonumber(L, 2);
|
||||
}
|
||||
|
||||
if (async_add_fd_write(wsgi_req, fd, timeout)) {
|
||||
lua_pushstring(L, "unable to call async_add_fd_write()");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
end:
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int uwsgi_api_async_connect(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc == 0) goto end;
|
||||
|
||||
int fd = uwsgi_connect((char *)lua_tostring(L, 1), 0, 1);
|
||||
lua_pushnumber(L, fd);
|
||||
return 1;
|
||||
end:
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int uwsgi_api_is_connected(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc == 0) goto end;
|
||||
int fd = lua_tonumber(L, 1);
|
||||
if (uwsgi_is_connected(fd)) {
|
||||
lua_pushboolean(L, 1);
|
||||
return 1;
|
||||
}
|
||||
lua_pushboolean(L, 0);
|
||||
return 1;
|
||||
end:
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int uwsgi_api_close(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc == 0) goto end;
|
||||
int fd = lua_tonumber(L, 1);
|
||||
close(fd);
|
||||
end:
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int uwsgi_api_ready_fd(lua_State *L) {
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
int fd = uwsgi_ready_fd(wsgi_req);
|
||||
lua_pushnumber(L, fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int uwsgi_api_websocket_handshake(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
|
||||
const char *key = NULL, *origin = NULL, *proto = NULL;
|
||||
size_t key_len = 0, origin_len = 0, proto_len = 0;
|
||||
|
||||
if (argc > 0) {
|
||||
key = lua_tolstring(L, 1, &key_len);
|
||||
if (argc > 1) {
|
||||
origin = lua_tolstring(L, 2, &origin_len);
|
||||
if (argc > 2) {
|
||||
proto = lua_tolstring(L, 3, &proto_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
if (uwsgi_websocket_handshake(wsgi_req, (char *)key, key_len, (char *)origin, origin_len, (char *) proto, proto_len)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
|
||||
error:
|
||||
lua_pushstring(L, "unable to complete websocket handshake");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_api_websocket_send(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc == 0) goto error;
|
||||
|
||||
size_t message_len = 0;
|
||||
const char *message = lua_tolstring(L, 1, &message_len);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (uwsgi_websocket_send(wsgi_req, (char *) message, message_len)) {
|
||||
goto error;
|
||||
}
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
error:
|
||||
lua_pushstring(L, "unable to send websocket message");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_api_websocket_send_binary(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc == 0) goto error;
|
||||
|
||||
size_t message_len = 0;
|
||||
const char *message = lua_tolstring(L, 1, &message_len);
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (uwsgi_websocket_send_binary(wsgi_req, (char *) message, message_len)) {
|
||||
goto error;
|
||||
}
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
error:
|
||||
lua_pushstring(L, "unable to send websocket binary message");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_api_websocket_send_from_sharedarea(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc < 2) goto error;
|
||||
|
||||
int id = lua_tonumber(L, 1);
|
||||
uint64_t pos = lua_tonumber(L, 2);
|
||||
uint64_t len = 0;
|
||||
if (argc > 2) {
|
||||
len = lua_tonumber(L, 3);
|
||||
}
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (uwsgi_websocket_send_from_sharedarea(wsgi_req, id, pos, len)) {
|
||||
goto error;
|
||||
}
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
error:
|
||||
lua_pushstring(L, "unable to send websocket message from sharedarea");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_api_websocket_send_binary_from_sharedarea(lua_State *L) {
|
||||
uint8_t argc = lua_gettop(L);
|
||||
if (argc < 2) goto error;
|
||||
|
||||
int id = lua_tonumber(L, 1);
|
||||
uint64_t pos = lua_tonumber(L, 2);
|
||||
uint64_t len = 0;
|
||||
if (argc > 2) {
|
||||
len = lua_tonumber(L, 3);
|
||||
}
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
|
||||
if (uwsgi_websocket_send_binary_from_sharedarea(wsgi_req, id, pos, len)) {
|
||||
goto error;
|
||||
}
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
error:
|
||||
lua_pushstring(L, "unable to send websocket message from sharedarea");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int uwsgi_api_websocket_recv(lua_State *L) {
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
struct uwsgi_buffer *ub = uwsgi_websocket_recv(wsgi_req);
|
||||
if (!ub) {
|
||||
lua_pushstring(L, "unable to receive websocket message");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
lua_pushlstring(L, ub->buf, ub->pos);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int uwsgi_api_websocket_recv_nb(lua_State *L) {
|
||||
struct wsgi_request *wsgi_req = current_wsgi_req();
|
||||
struct uwsgi_buffer *ub = uwsgi_websocket_recv_nb(wsgi_req);
|
||||
if (!ub) {
|
||||
lua_pushstring(L, "unable to receive websocket message");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
lua_pushlstring(L, ub->buf, ub->pos);
|
||||
uwsgi_buffer_destroy(ub);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int uwsgi_api_cache_get(lua_State *L) {
|
||||
|
||||
@@ -366,9 +614,25 @@ static const luaL_Reg uwsgi_api[] = {
|
||||
{"register_signal", uwsgi_api_register_signal},
|
||||
{"register_rpc", uwsgi_api_register_rpc},
|
||||
|
||||
{"websocket_handshake", uwsgi_api_websocket_handshake},
|
||||
{"websocket_recv", uwsgi_api_websocket_recv},
|
||||
{"websocket_recv_nb", uwsgi_api_websocket_recv_nb},
|
||||
{"websocket_send", uwsgi_api_websocket_send},
|
||||
{"websocket_send_from_sharedarea", uwsgi_api_websocket_send_from_sharedarea},
|
||||
{"websocket_send_binary", uwsgi_api_websocket_send_binary},
|
||||
{"websocket_send_binary_from_sharedarea", uwsgi_api_websocket_send_binary_from_sharedarea},
|
||||
|
||||
{"lock", uwsgi_api_lock},
|
||||
{"unlock", uwsgi_api_unlock},
|
||||
|
||||
{"async_sleep", uwsgi_api_async_sleep},
|
||||
{"async_connect", uwsgi_api_async_connect},
|
||||
{"is_connected", uwsgi_api_is_connected},
|
||||
{"close", uwsgi_api_close},
|
||||
{"wait_fd_read", uwsgi_api_wait_fd_read},
|
||||
{"wait_fd_write", uwsgi_api_wait_fd_write},
|
||||
{"ready_fd", uwsgi_api_ready_fd},
|
||||
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -416,7 +680,7 @@ static void uwsgi_lua_app() {
|
||||
for(i=0;i<uwsgi.cores;i++) {
|
||||
ulua.L[i] = luaL_newstate();
|
||||
luaL_openlibs(ulua.L[i]);
|
||||
luaL_newlib(ulua.L[i], uwsgi_api);
|
||||
luaL_newuwsgilib(ulua.L[i], uwsgi_api);
|
||||
|
||||
lua_pushstring(ulua.L[i], UWSGI_VERSION);
|
||||
lua_setfield(ulua.L[i], -2, "version");
|
||||
@@ -526,7 +790,7 @@ static int uwsgi_lua_request(struct wsgi_request *wsgi_req) {
|
||||
uwsgi_log("%s\n", lua_tostring(L, -1));
|
||||
lua_pop(L, 1);
|
||||
lua_pushvalue(L, -1);
|
||||
goto clear;
|
||||
goto clear2;
|
||||
}
|
||||
|
||||
//uwsgi_log("%d %s %s %s\n",i,lua_typename(L, lua_type(L, -3)), lua_typename(L, lua_type(L, -2)) , lua_typename(L, lua_type(L, -1)));
|
||||
@@ -534,7 +798,8 @@ static int uwsgi_lua_request(struct wsgi_request *wsgi_req) {
|
||||
// send status
|
||||
if (lua_type(L, -3) == LUA_TSTRING || lua_type(L, -3) == LUA_TNUMBER) {
|
||||
http = lua_tolstring(L, -3, &slen);
|
||||
uwsgi_response_prepare_headers(wsgi_req, (char *) http, slen);
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, (char *) http, slen))
|
||||
goto clear2;
|
||||
}
|
||||
else {
|
||||
uwsgi_log("[uwsgi-lua] invalid response status !!!\n");
|
||||
@@ -565,11 +830,13 @@ static int uwsgi_lua_request(struct wsgi_request *wsgi_req) {
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
}
|
||||
|
||||
clear:
|
||||
lua_pop(L, 4);
|
||||
clear2:
|
||||
// set frequency
|
||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||
if (!ulua.gc_freq || uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].requests % ulua.gc_freq == 0) {
|
||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||
}
|
||||
|
||||
return UWSGI_OK;
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ done:
|
||||
ums = (struct uwsgi_mongodb_state *) ul->data;
|
||||
|
||||
if (ums->fd == -1) {
|
||||
ums->fd = uwsgi_connect(ums->address, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0);
|
||||
ums->fd = uwsgi_connect(ums->address, uwsgi.socket_timeout, 0);
|
||||
}
|
||||
|
||||
if (ums->fd == -1) return -1;
|
||||
|
||||
@@ -1,39 +1,21 @@
|
||||
/*
|
||||
|
||||
generic ZeroMQ functions + Mongrel2 protocol parser
|
||||
Mongrel2 protocol parser
|
||||
|
||||
*/
|
||||
|
||||
#include <uwsgi.h>
|
||||
#include <zmq.h>
|
||||
|
||||
extern struct uwsgi_server uwsgi;
|
||||
|
||||
void *uwsgi_zeromq_init() {
|
||||
if (!uwsgi.zmq_context) {
|
||||
uwsgi.zmq_context = zmq_init(1);
|
||||
if (uwsgi.zmq_context == NULL) {
|
||||
uwsgi_error("zmq_init()");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
return uwsgi.zmq_context;
|
||||
}
|
||||
|
||||
void uwsgi_zeromq_init_sockets() {
|
||||
|
||||
uwsgi_zeromq_init();
|
||||
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
while (uwsgi_sock) {
|
||||
if (!uwsgi_sock->proto_name || strcmp(uwsgi_sock->proto_name, "zmq")) {
|
||||
goto zmq_next;
|
||||
}
|
||||
uwsgi_proto_zeromq_setup(uwsgi_sock);
|
||||
zmq_next:
|
||||
uwsgi_sock = uwsgi_sock->next;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
static struct uwsgi_option mongrel2_options[] = {
|
||||
{"zeromq", required_argument, 0, "create a mongrel2/zeromq pub/sub pair", uwsgi_opt_add_lazy_socket, "mongrel2", 0},
|
||||
{"zmq", required_argument, 0, "create a mongrel2/zeromq pub/sub pair", uwsgi_opt_add_lazy_socket, "mongrel2", 0},
|
||||
{"zeromq-socket", required_argument, 0, "create a mongrel2/zeromq pub/sub pair", uwsgi_opt_add_lazy_socket, "mongrel2", 0},
|
||||
{"zmq-socket", required_argument, 0, "create a mongrel2/zeromq pub/sub pair", uwsgi_opt_add_lazy_socket, "mongrel2", 0},
|
||||
{"mongrel2", required_argument, 0, "create a mongrel2/zeromq pub/sub pair", uwsgi_opt_add_lazy_socket, "mongrel2", 0},
|
||||
};
|
||||
|
||||
#ifdef UWSGI_JSON
|
||||
#include <jansson.h>
|
||||
@@ -290,7 +272,7 @@ int uwsgi_proto_zeromq_parser(struct wsgi_request *wsgi_req) {
|
||||
|
||||
void uwsgi_proto_zeromq_thread_fixup(struct uwsgi_socket *uwsgi_sock, int async_id) {
|
||||
|
||||
void *tmp_zmq_pull = zmq_socket(uwsgi.zmq_context, ZMQ_PULL);
|
||||
void *tmp_zmq_pull = zmq_socket(uwsgi_sock->ctx, ZMQ_PULL);
|
||||
if (tmp_zmq_pull == NULL) {
|
||||
uwsgi_error("zmq_socket()");
|
||||
exit(1);
|
||||
@@ -315,7 +297,7 @@ void uwsgi_proto_zeromq_thread_fixup(struct uwsgi_socket *uwsgi_sock, int async_
|
||||
#endif
|
||||
}
|
||||
|
||||
// fake function, the bosy is i na file or completely in memory
|
||||
// fake function, the body is in a file or completely in memory
|
||||
ssize_t uwsgi_proto_zeromq_read_body(struct wsgi_request *wsgi_req, char *buf, size_t len) {
|
||||
return 0;
|
||||
}
|
||||
@@ -563,106 +545,121 @@ int uwsgi_proto_zeromq_sendfile(struct wsgi_request *wsgi_req, int fd, size_t po
|
||||
return UWSGI_AGAIN;
|
||||
}
|
||||
|
||||
void uwsgi_proto_zeromq_setup(struct uwsgi_socket *uwsgi_sock) {
|
||||
|
||||
char *responder = strchr(uwsgi_sock->name, ',');
|
||||
if (!responder) {
|
||||
uwsgi_log("invalid zeromq address\n");
|
||||
exit(1);
|
||||
}
|
||||
uwsgi_sock->receiver = uwsgi_concat2n(uwsgi_sock->name, responder - uwsgi_sock->name, "", 0);
|
||||
responder++;
|
||||
|
||||
uwsgi_sock->pub = zmq_socket(uwsgi.zmq_context, ZMQ_PUB);
|
||||
if (uwsgi_sock->pub == NULL) {
|
||||
uwsgi_error("zmq_socket()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
// generate uuid
|
||||
uuid_t uuid_zmq;
|
||||
uuid_generate(uuid_zmq);
|
||||
uuid_unparse(uuid_zmq, uwsgi_sock->uuid);
|
||||
|
||||
if (zmq_setsockopt(uwsgi_sock->pub, ZMQ_IDENTITY, uwsgi_sock->uuid, 36) < 0) {
|
||||
uwsgi_error("zmq_setsockopt()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (zmq_connect(uwsgi_sock->pub, responder) < 0) {
|
||||
uwsgi_error("zmq_connect()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uwsgi_log("zeromq UUID for responder %s on worker %d: %.*s\n", responder, uwsgi.mywid, 36, uwsgi_sock->uuid);
|
||||
|
||||
static void uwsgi_proto_mongrel2_setup(struct uwsgi_socket *uwsgi_sock) {
|
||||
uwsgi_sock->proto = uwsgi_proto_zeromq_parser;
|
||||
uwsgi_sock->proto_accept = uwsgi_proto_zeromq_accept;
|
||||
uwsgi_sock->proto_prepare_headers = uwsgi_proto_base_prepare_headers;
|
||||
uwsgi_sock->proto_add_header = uwsgi_proto_base_add_header;
|
||||
uwsgi_sock->proto_fix_headers = uwsgi_proto_base_fix_headers;
|
||||
uwsgi_sock->proto_read_body = uwsgi_proto_zeromq_read_body;
|
||||
uwsgi_sock->proto_write = uwsgi_proto_zeromq_write;
|
||||
uwsgi_sock->proto_write_headers = uwsgi_proto_zeromq_write;
|
||||
uwsgi_sock->proto_sendfile = uwsgi_proto_zeromq_sendfile;
|
||||
uwsgi_sock->proto_close = uwsgi_proto_zeromq_close;
|
||||
uwsgi_sock->proto_accept = uwsgi_proto_zeromq_accept;
|
||||
uwsgi_sock->proto_prepare_headers = uwsgi_proto_base_prepare_headers;
|
||||
uwsgi_sock->proto_add_header = uwsgi_proto_base_add_header;
|
||||
uwsgi_sock->proto_fix_headers = uwsgi_proto_base_fix_headers;
|
||||
uwsgi_sock->proto_read_body = uwsgi_proto_zeromq_read_body;
|
||||
uwsgi_sock->proto_write = uwsgi_proto_zeromq_write;
|
||||
uwsgi_sock->proto_write_headers = uwsgi_proto_zeromq_write;
|
||||
uwsgi_sock->proto_sendfile = uwsgi_proto_zeromq_sendfile;
|
||||
uwsgi_sock->proto_close = uwsgi_proto_zeromq_close;
|
||||
|
||||
uwsgi_sock->proto_thread_fixup = uwsgi_proto_zeromq_thread_fixup;
|
||||
uwsgi_sock->proto_thread_fixup = uwsgi_proto_zeromq_thread_fixup;
|
||||
|
||||
uwsgi_sock->edge_trigger = 1;
|
||||
uwsgi_sock->retry = uwsgi_malloc(sizeof(int) * uwsgi.threads);
|
||||
uwsgi_sock->retry[0] = 1;
|
||||
uwsgi_sock->edge_trigger = 1;
|
||||
uwsgi_sock->retry = uwsgi_malloc(sizeof(int) * uwsgi.threads);
|
||||
uwsgi_sock->retry[0] = 1;
|
||||
|
||||
// inform loop engine about edge trigger status
|
||||
uwsgi.is_et = 1;
|
||||
uwsgi_sock->fd = -1;
|
||||
|
||||
};
|
||||
|
||||
static void mongrel2_register_proto() {
|
||||
uwsgi_register_protocol("mongrel2", uwsgi_proto_mongrel2_setup);
|
||||
}
|
||||
|
||||
static void mongrel2_connect() {
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
while(uwsgi_sock) {
|
||||
uwsgi_sock->ctx = zmq_init(1);
|
||||
if (!uwsgi_sock->ctx) {
|
||||
uwsgi_error("mongrel2_connect()/zmq_init()");
|
||||
exit(1);
|
||||
}
|
||||
char *responder = strchr(uwsgi_sock->name, ',');
|
||||
if (!responder) {
|
||||
uwsgi_log("invalid zeromq address\n");
|
||||
exit(1);
|
||||
}
|
||||
uwsgi_sock->receiver = uwsgi_concat2n(uwsgi_sock->name, responder - uwsgi_sock->name, "", 0);
|
||||
responder++;
|
||||
|
||||
uwsgi_sock->pub = zmq_socket(uwsgi_sock->ctx, ZMQ_PUB);
|
||||
if (uwsgi_sock->pub == NULL) {
|
||||
uwsgi_error("mongrel2_connect()/zmq_socket()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// generate uuid
|
||||
uwsgi_uuid(uwsgi_sock->uuid);
|
||||
|
||||
if (zmq_setsockopt(uwsgi_sock->pub, ZMQ_IDENTITY, uwsgi_sock->uuid, 36) < 0) {
|
||||
uwsgi_error("mongrel2_connect()/zmq_setsockopt()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (zmq_connect(uwsgi_sock->pub, responder) < 0) {
|
||||
uwsgi_error("mongrel2_connect()/zmq_connect()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
uwsgi_log("zeromq UUID for responder %s on worker %d: %.*s\n", responder, uwsgi.mywid, 36, uwsgi_sock->uuid);
|
||||
|
||||
// inform loop engine about edge trigger status
|
||||
uwsgi.is_et = 1;
|
||||
|
||||
|
||||
// initialize a lock for multithread usage
|
||||
if (uwsgi.threads > 1) {
|
||||
pthread_mutex_init(&uwsgi_sock->lock, NULL);
|
||||
}
|
||||
// initialize a lock for multithread usage
|
||||
if (uwsgi.threads > 1) {
|
||||
pthread_mutex_init(&uwsgi_sock->lock, NULL);
|
||||
}
|
||||
|
||||
// one pull per-thread
|
||||
if (pthread_key_create(&uwsgi_sock->key, NULL)) {
|
||||
uwsgi_error("pthread_key_create()");
|
||||
exit(1);
|
||||
}
|
||||
// one pull per-thread
|
||||
if (pthread_key_create(&uwsgi_sock->key, NULL)) {
|
||||
uwsgi_error("mongrel2_connect()/pthread_key_create()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void *tmp_zmq_pull = zmq_socket(uwsgi.zmq_context, ZMQ_PULL);
|
||||
if (tmp_zmq_pull == NULL) {
|
||||
uwsgi_error("zmq_socket()");
|
||||
exit(1);
|
||||
}
|
||||
if (zmq_connect(tmp_zmq_pull, uwsgi_sock->receiver) < 0) {
|
||||
uwsgi_error("zmq_connect()");
|
||||
exit(1);
|
||||
}
|
||||
void *tmp_zmq_pull = zmq_socket(uwsgi_sock->ctx, ZMQ_PULL);
|
||||
if (tmp_zmq_pull == NULL) {
|
||||
uwsgi_error("mongrel2_connect()/zmq_socket()");
|
||||
exit(1);
|
||||
}
|
||||
if (zmq_connect(tmp_zmq_pull, uwsgi_sock->receiver) < 0) {
|
||||
uwsgi_error("mongrel2_connect()/zmq_connect()");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pthread_setspecific(uwsgi_sock->key, tmp_zmq_pull);
|
||||
pthread_setspecific(uwsgi_sock->key, tmp_zmq_pull);
|
||||
|
||||
#ifdef ZMQ_FD
|
||||
size_t zmq_socket_len = sizeof(int);
|
||||
if (zmq_getsockopt(pthread_getspecific(uwsgi_sock->key), ZMQ_FD, &uwsgi_sock->fd, &zmq_socket_len) < 0) {
|
||||
uwsgi_error("zmq_getsockopt()");
|
||||
exit(1);
|
||||
}
|
||||
if (uwsgi.threads > 1) {
|
||||
uwsgi_sock->fd_threads = uwsgi_malloc(sizeof(int) * uwsgi.threads);
|
||||
uwsgi_sock->fd_threads[0] = uwsgi_sock->fd;
|
||||
}
|
||||
#else
|
||||
uwsgi_sock->fd = -1;
|
||||
size_t zmq_socket_len = sizeof(int);
|
||||
if (zmq_getsockopt(pthread_getspecific(uwsgi_sock->key), ZMQ_FD, &uwsgi_sock->fd, &zmq_socket_len) < 0) {
|
||||
uwsgi_error("mongrel2_connect()/zmq_getsockopt()");
|
||||
exit(1);
|
||||
}
|
||||
if (uwsgi.threads > 1) {
|
||||
uwsgi_sock->fd_threads = uwsgi_malloc(sizeof(int) * uwsgi.threads);
|
||||
uwsgi_sock->fd_threads[0] = uwsgi_sock->fd;
|
||||
}
|
||||
#endif
|
||||
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_sock->bound = 1;
|
||||
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3,0,0)
|
||||
uwsgi_sock->recv_flag = ZMQ_DONTWAIT;
|
||||
uwsgi_sock->recv_flag = ZMQ_DONTWAIT;
|
||||
#else
|
||||
uwsgi_sock->recv_flag = ZMQ_NOBLOCK;
|
||||
uwsgi_sock->recv_flag = ZMQ_NOBLOCK;
|
||||
#endif
|
||||
uwsgi_sock = uwsgi_sock->next;
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_proto_zmq_setup(struct uwsgi_socket *uwsgi_sock) {
|
||||
uwsgi.zeromq = 1;
|
||||
}
|
||||
struct uwsgi_plugin mongrel2_plugin = {
|
||||
.name = "mongrel2",
|
||||
.options = mongrel2_options,
|
||||
.post_fork = mongrel2_connect,
|
||||
.on_load = mongrel2_register_proto,
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
NAME='mongrel2'
|
||||
CFLAGS = []
|
||||
LDFLAGS = []
|
||||
LIBS = ['-lzmq']
|
||||
|
||||
GCC_LIST = ['mongrel2']
|
||||
@@ -26,7 +26,7 @@ int nagios() {
|
||||
}
|
||||
|
||||
|
||||
int fd = uwsgi_connect(uwsgi.sockets->name, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], 0);
|
||||
int fd = uwsgi_connect(uwsgi.sockets->name, uwsgi.socket_timeout, 0);
|
||||
if (fd < 0) {
|
||||
fprintf(stdout, "UWSGI CRITICAL: could not connect() to workers %s\n", strerror(errno));
|
||||
if (errno == EPERM || errno == EACCES) {
|
||||
@@ -45,7 +45,7 @@ int nagios() {
|
||||
}
|
||||
|
||||
|
||||
int ret = uwsgi_read_response(fd, &uh, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], &buf);
|
||||
int ret = uwsgi_read_response(fd, &uh, uwsgi.socket_timeout, &buf);
|
||||
|
||||
if (ret == -2) {
|
||||
fprintf(stdout, "UWSGI CRITICAL: timed out waiting for response\n");
|
||||
|
||||
@@ -92,11 +92,13 @@ static int sapi_uwsgi_send_headers(sapi_headers_struct *sapi_headers)
|
||||
int hrc = SG(sapi_headers).http_response_code;
|
||||
if (!hrc) hrc = 200;
|
||||
uwsgi_num2str2n(hrc, status, 4);
|
||||
uwsgi_response_prepare_headers(wsgi_req, status, 3);
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, status, 3))
|
||||
return SAPI_HEADER_SEND_FAILED;
|
||||
}
|
||||
else {
|
||||
char *sl = SG(sapi_headers).http_status_line;
|
||||
uwsgi_response_prepare_headers(wsgi_req, sl + 9 , strlen(sl + 9));
|
||||
if (uwsgi_response_prepare_headers(wsgi_req, sl + 9 , strlen(sl + 9)))
|
||||
return SAPI_HEADER_SEND_FAILED;
|
||||
}
|
||||
|
||||
h = zend_llist_get_first_ex(&sapi_headers->headers, &pos);
|
||||
|
||||
@@ -63,6 +63,8 @@ struct uwsgi_perl {
|
||||
|
||||
char *shell;
|
||||
int shell_oneshot;
|
||||
|
||||
CV *spooler;
|
||||
};
|
||||
|
||||
void init_perl_embedded_module(void);
|
||||
|
||||
@@ -149,7 +149,7 @@ XS(XS_streaming_write) {
|
||||
|
||||
uwsgi_response_write_body_do(wsgi_req, body, blen);
|
||||
uwsgi_pl_check_write_errors {
|
||||
// noop
|
||||
croak("error while streaming PSGI response");
|
||||
}
|
||||
|
||||
XSRETURN(0);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user