Compare commits

...
26 Commits
Author SHA1 Message Date
roberto@debian32 b7525475d8 ready for 0.9.8 release 2011-06-05 08:20:23 +02:00
roberto@debian32 f35a36ac02 set a mercy mode for INT/QUIT 2011-06-05 07:38:58 +02:00
roberto@netbsd64 3b53f89a24 netbsd fix 2011-06-05 09:17:38 +02:00
roberto@debian32 764d94e41b support for abstract unix socket prefixed with \0 2011-06-04 08:55:49 +02:00
roberto@indianajones 0292e15497 add /lib to linker on SunOS-derived systems 2011-06-02 19:35:05 +01:00
roberto@debian32 bde4ac7b2f uWSGI 0.9.8-rc4 2011-06-02 18:53:49 +02:00
roberto@debian32 c71fa3abd1 Added tag 0.9.8-rc4 for changeset 0f1f3924ee53 2011-06-02 18:53:38 +02:00
roberto@indianajones d2abdb5d3a fix accept() to receive the correct ip 2011-06-02 18:44:48 +01:00
roberto@indianajones 1392791837 OpenIndiana is now officially supported 2011-06-02 15:15:35 +01:00
roberto@goyle 6f7d9634d5 allows log-date 2011-06-02 12:08:56 +02:00
roberto@goyle 82b95114a8 added welcome.py 2011-06-02 11:38:18 +02:00
roberto@debian32 d90e701acd use int in uwsgi.version_info 2011-06-01 13:02:33 +02:00
roberto@debian32 42993022bb python3 fix 2011-06-01 12:55:20 +02:00
roberto@dj1 29b1e46252 uwsgi.version_info 2011-06-01 05:52:46 -05:00
roberto@sirius 260cea639f better myadmin.py 2011-06-01 10:04:57 +02:00
roberto@sirius 208aea8aca two new management flag for backlog queue 2011-06-01 10:00:17 +02:00
roberto@sirius f164d401d3 another uwsgi_log fix 2011-06-01 09:47:58 +02:00
roberto@dj1 5e1c34a08b really fix uwsgi_log 2011-06-01 02:15:53 -05:00
roberto@debian32 9c7b596a0d fixed uwsgi_log 2011-06-01 08:38:51 +02:00
roberto@debian32 5ff34ac6d0 a couple of admin plugin fixes 2011-06-01 08:12:50 +02:00
roberto@debian32 e304e34929 throw exception on too much big spool requests 2011-06-01 07:11:54 +02:00
roberto@dj1 6d7848248d added --early-emperor option 2011-05-31 08:44:26 -05:00
roberto@sirius dbc0da0586 support for idle mode in single process mode 2011-05-31 14:26:57 +02:00
roberto@debian32 fecdcf9d10 allows sub-emperors (emperors generated by emperors) 2011-05-31 08:56:03 +02:00
roberto@sirius bfd0ab2301 fixed a typo 2011-05-30 19:10:01 +02:00
roberto@sirius 8002777e75 uWSGI 0.9.8-rc3 2011-05-30 19:04:05 +02:00
29 changed files with 651 additions and 251 deletions
+4
View File
@@ -0,0 +1,4 @@
syntax: glob
*.o
*.pyc
+2
View File
@@ -22,3 +22,5 @@ d9b9b540f7dce8cb05d2e61ca8b4d75f2ea25f62 0.9.7.1
a5f13497b39269621f8f1e56e14d2cc141452e79 0.9.7.2
d1e57707f6317f134fea7d12f6588d8690f74f3f 0.9.8-rc1
e91bc724325e14c13b8f548c0b6a315c48a1c32a 0.9.8-rc2
4fb424d52f226a0a087fea89709f5eb540e03f25 0.9.8-rc3
0f1f3924ee5309a9990d9af1ffc68846e3dfb31b 0.9.8-rc4
+34
View File
@@ -1,5 +1,39 @@
*** may 2011 ***
* 0.9.8-rc4 [20110602]
- fixed REMOTE_ADDR when --protocol=http
- official support for OpenIndiana
- added a welcome.py test script
- new api attribute uwsgi.version_info
- improved the admin plugin
- two new management flag for backlog queue monitoring
- fixed uwsgi_log for bigger loglines
- new option --early-emperor to allows out-of-jail emperors
- emperor can now spawn other emperors (sub-emperors)
- fixed idle mode in single-process
- fixed solaris iovec
* 0.9.8-rc3 [20110530]
- snapshotting support
- fixed python 3.x spooler
- improvements for grunt processes
- better abstract unix socket
- --log-socket allows logging to generic DGRAM sockets
- a bunch of solaris fixes
- new option --no-fd-passing for fastrouter
- --fastrouter-subscription-slot to set the number of slot in subscription server
- unlimited shared sockets
- fixed netlink compilation
- auto-reconnect on emperor+amqp server disconnection
- various emperor fixes
- unlimited fastrouter sockets
- better cgroup support
- --add-header option allow adding of custom HTTP response headers
- cheap and idle operational modes
* 0.9.8-rc2 [20110521]
- new option --die-on-term
+2
View File
@@ -318,7 +318,9 @@ void *async_loop(void *arg1) {
// parsing complete
if (!proto_parser_status) {
// remove fd from event poll and fd proto table
#ifndef UWSGI_EVENT_USE_PORT
event_queue_del_fd(uwsgi.async_queue, interesting_fd, event_queue_read());
#endif
uwsgi.async_proto_fd_table[interesting_fd] = NULL;
// put request in the runqueue
runqueue_push(uwsgi.wsgi_req);
+1
View File
@@ -25,6 +25,7 @@ yaml_implementation = auto
malloc_implementation = libc
plugins =
bin_name = uwsgi
append_version =
plugin_dir = .
embedded_plugins = python, ping, cache, nagios, rpc, fastrouter, http, ugreen
+8 -3
View File
@@ -328,7 +328,12 @@ void emperor_loop() {
events = event_queue_alloc(64);
uwsgi_log("*** starting uWSGI Emperor ***\n");
if (uwsgi.has_emperor) {
uwsgi_log("*** starting uWSGI sub-Emperor ***\n");
}
else {
uwsgi_log("*** starting uWSGI Emperor ***\n");
}
amqp_port = strchr(uwsgi.emperor_dir, ':');
@@ -356,7 +361,7 @@ reconnect:
event_queue_add_fd_read(emperor_queue, amqp_fd);
}
else {
if (!glob(uwsgi.emperor_dir, GLOB_MARK, NULL, &g)) {
if (!glob(uwsgi.emperor_dir, GLOB_MARK|GLOB_NOCHECK, NULL, &g)) {
if (g.gl_pathc == 1 && g.gl_pathv[0][strlen(g.gl_pathv[0]) - 1] == '/') {
simple_mode = 1;
if (chdir(uwsgi.emperor_dir)) {
@@ -531,7 +536,7 @@ reconnect:
closedir(dir);
}
else {
if (glob(uwsgi.emperor_dir, GLOB_MARK, NULL, &g)) {
if (glob(uwsgi.emperor_dir, GLOB_MARK|GLOB_NOCHECK, NULL, &g)) {
uwsgi_error("glob()");
continue;
}
+26 -22
View File
@@ -96,8 +96,11 @@ void get_linux_tcp_info(int fd) {
if (!uwsgi.shared->ti.tcpi_sacked) {
return;
}
uwsgi.shared->options[UWSGI_OPTION_BACKLOG_STATUS] = uwsgi.shared->ti.tcpi_unacked;
if (uwsgi.shared->ti.tcpi_unacked >= uwsgi.shared->ti.tcpi_sacked) {
uwsgi_log_verbose("*** uWSGI listen queue of socket %d full !!! (%d/%d) ***\n", fd, uwsgi.shared->ti.tcpi_unacked, uwsgi.shared->ti.tcpi_sacked);
uwsgi.shared->options[UWSGI_OPTION_BACKLOG_ERRORS]++;
}
}
}
@@ -924,29 +927,30 @@ void master_loop(char **argv, char **environ) {
for(i=1;i<uwsgi.numproc+1;i++)
tmp_counter += uwsgi.workers[i].requests;
uwsgi.workers[0].requests = tmp_counter;
if (uwsgi.idle > 0 && !uwsgi.cheap) {
uwsgi.current_time = time(NULL);
if (!last_request_timecheck) last_request_timecheck = uwsgi.current_time;
if (last_request_count != uwsgi.workers[0].requests) {
last_request_timecheck = uwsgi.current_time;
last_request_count = uwsgi.workers[0].requests;
}
else if (uwsgi.current_time - last_request_timecheck > uwsgi.idle) {
uwsgi_log("workers have been inactive for more than %d seconds\n", uwsgi.idle);
for(i=1;i<=uwsgi.numproc;i++) {
if (uwsgi.workers[i].pid == 0) continue;
kill(uwsgi.workers[i].pid, SIGKILL);
if (waitpid(uwsgi.workers[i].pid, &waitpid_status, 0) < 0) {
uwsgi_error("waitpid()");
}
}
master_has_children = 0;
uwsgi.cheap = 1;
uwsgi_add_sockets_to_queue(uwsgi.master_queue);
uwsgi_log("cheap mode enabled: waiting for socket connection...\n");
last_request_timecheck = 0;
continue;
}
if (uwsgi.idle > 0 && !uwsgi.cheap) {
uwsgi.current_time = time(NULL);
if (!last_request_timecheck) last_request_timecheck = uwsgi.current_time;
if (last_request_count != uwsgi.workers[0].requests) {
last_request_timecheck = uwsgi.current_time;
last_request_count = uwsgi.workers[0].requests;
}
else if (uwsgi.current_time - last_request_timecheck > uwsgi.idle) {
uwsgi_log("workers have been inactive for more than %d seconds\n", uwsgi.idle);
for(i=1;i<=uwsgi.numproc;i++) {
if (uwsgi.workers[i].pid == 0) continue;
kill(uwsgi.workers[i].pid, SIGKILL);
if (waitpid(uwsgi.workers[i].pid, &waitpid_status, 0) < 0) {
uwsgi_error("waitpid()");
}
}
master_has_children = 0;
uwsgi.cheap = 1;
uwsgi_add_sockets_to_queue(uwsgi.master_queue);
uwsgi_log("cheap mode enabled: waiting for socket connection...\n");
last_request_timecheck = 0;
continue;
}
}
+11 -1
View File
@@ -2,6 +2,16 @@ import uwsgi
import struct
import sys
print sys.argv
if len(sys.argv) == 3:
chunks = uwsgi.send_message(sys.argv[1], 10, int(sys.argv[2]), '')
print uwsgi.send_uwsgi_message(sys.argv[1], int(sys.argv[2]), 10, int(sys.argv[3]), struct.pack("i", int(sys.argv[4])))
pkt = ''
for chunk in chunks:
pkt += chunk
print "%d = %d" % (int(sys.argv[2]), struct.unpack("I", pkt)[0])
elif len(sys.argv) == 4:
uwsgi.send_message(sys.argv[1], 10, int(sys.argv[2]), struct.pack("I", int(sys.argv[3])))
+47 -17
View File
@@ -1,28 +1,58 @@
#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;
int i;
ssize_t len;
if (wsgi_req->uh.pktsize >= 4) {
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);
// TODO: check endianess ?
}
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;
i = write(wsgi_req->poll.fd, wsgi_req, 4);
if (i != 4) {
uwsgi_error("write()");
}
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;
len = write(wsgi_req->poll.fd, wsgi_req, 4);
if (len != 4) {
uwsgi_error("write()");
}
}
// 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;
len = write(wsgi_req->poll.fd, wsgi_req, 4);
if (len != 4) {
uwsgi_error("write()");
return UWSGI_OK;
}
len = write(wsgi_req->poll.fd, (char *) &uwsgi.shared->options[wsgi_req->uh.modifier2], 4);
if (len != 4) {
uwsgi_error("write()");
}
}
return UWSGI_OK;
}
struct uwsgi_plugin admin_plugin = {
.name = "admin",
.modifier1 = 10,
.request = uwsgi_request_admin,
};
+7
View File
@@ -0,0 +1,7 @@
NAME='admin'
CFLAGS = []
LDFLAGS = []
LIBS = []
GCC_LIST = ['admin_plugin']
+4 -2
View File
@@ -114,7 +114,6 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
uwsgi_log("%s = %s\n", PyString_AsString(k), PyString_AsString(env_value));
if (PyObject_SetItem(py_environ, k, env_value)) {
uwsgi_log("cazzo\n");
PyErr_Print();
}
@@ -521,6 +520,9 @@ PyObject *uwsgi_file_loader(void *arg1) {
PyObject *wsgi_file_module, *wsgi_file_dict;
PyObject *wsgi_file_callable;
char *callable = up.callable;
if (!callable) callable = "application";
wsgi_file_module = uwsgi_pyimport_by_filename("uwsgi_wsgi_file", filename);
// no need to check here for module import as it is already done by uwsgi_pyimport_by_file
@@ -530,7 +532,7 @@ PyObject *uwsgi_file_loader(void *arg1) {
exit(1);
}
wsgi_file_callable = PyDict_GetItemString(wsgi_file_dict, "application");
wsgi_file_callable = PyDict_GetItemString(wsgi_file_dict, callable);
if (!wsgi_file_callable) {
PyErr_Print();
uwsgi_log( "unable to find \"application\" callable in file %s\n", filename);
+14
View File
@@ -428,6 +428,20 @@ void init_uwsgi_embedded_module() {
exit(1);
}
PyObject *uwsgi_py_version_info = PyTuple_New(5);
PyTuple_SetItem(uwsgi_py_version_info, 0, PyInt_FromLong(UWSGI_VERSION_BASE));
PyTuple_SetItem(uwsgi_py_version_info, 1, PyInt_FromLong(UWSGI_VERSION_MAJOR));
PyTuple_SetItem(uwsgi_py_version_info, 2, PyInt_FromLong(UWSGI_VERSION_MINOR));
PyTuple_SetItem(uwsgi_py_version_info, 3, PyInt_FromLong(UWSGI_VERSION_REVISION));
PyTuple_SetItem(uwsgi_py_version_info, 4, PyString_FromString(UWSGI_VERSION_CUSTOM));
if (PyDict_SetItemString(up.embedded_dict, "version_info", uwsgi_py_version_info)) {
PyErr_Print();
exit(1);
}
if (PyDict_SetItemString(up.embedded_dict, "hostname", PyString_FromStringAndSize(uwsgi.hostname, uwsgi.hostname_len))) {
PyErr_Print();
exit(1);
+1 -4
View File
@@ -1192,8 +1192,7 @@ PyObject *py_uwsgi_send_spool(PyObject * self, PyObject * args, PyObject *kw) {
}
else {
Py_DECREF(zero);
Py_INCREF(Py_None);
return Py_None;
return PyErr_Format(PyExc_ValueError, "spooler packet cannot be more than %d bytes", uwsgi.buffer_size);
}
}
else {
@@ -1555,7 +1554,6 @@ PyObject *uwsgi_Iter_next(PyObject * self) {
ui->has_cl = 1;
ui->size = uh.pktsize;
ui->sent = 0;
uwsgi_log("NEED TO READ %d\n", uh.pktsize);
}
}
@@ -2345,7 +2343,6 @@ static PyMethodDef uwsgi_advanced_methods[] = {
{"load_plugin", py_uwsgi_load_plugin, METH_VARARGS, ""},
{"lock", py_uwsgi_lock, METH_VARARGS, ""},
{"unlock", py_uwsgi_unlock, METH_VARARGS, ""},
{"send", py_uwsgi_send, METH_VARARGS, ""},
{"cl", py_uwsgi_cl, METH_VARARGS, ""},
{"listen_queue", py_uwsgi_listen_queue, METH_VARARGS, ""},
+19
View File
@@ -180,12 +180,31 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) {
wsgi_req->hvec[j].iov_base = nl;
wsgi_req->hvec[j].iov_len = NL_SIZE;
#ifdef __sun__
int remains = j + 1;
int iov_size;
struct iovec* iov_ptr = wsgi_req->hvec;
ssize_t iov_ret;
while(remains) {
iov_size = UMIN(remains, IOV_MAX);
UWSGI_RELEASE_GIL
iov_ret = wsgi_req->socket->proto_writev_header(wsgi_req, iov_ptr, iov_size);
UWSGI_GET_GIL
if (iov_ret < 0) {
uwsgi_error("writev()");
}
wsgi_req->headers_size += iov_ret;
iov_ptr += iov_size;
remains -= iov_size;
}
#else
UWSGI_RELEASE_GIL
wsgi_req->headers_size = wsgi_req->socket->proto_writev_header(wsgi_req, wsgi_req->hvec, j + 1);
UWSGI_GET_GIL
if (wsgi_req->headers_size < 0) {
uwsgi_error("writev()");
}
#endif
//uwsgi_log("%d %p\n", wsgi_req->poll.fd, up.wsgi_writeout);
Py_INCREF(up.wsgi_writeout);
+2 -1
View File
@@ -17,7 +17,7 @@ uint16_t proto_base_add_uwsgi_header(struct wsgi_request *wsgi_req, char *key, u
key[i] = '_';
}
else {
key[i] = toupper(key[i]);
key[i] = toupper((int)key[i]);
}
}
@@ -90,6 +90,7 @@ uint16_t proto_base_add_uwsgi_var(struct wsgi_request * wsgi_req, char *key, uin
int uwsgi_proto_base_accept(struct wsgi_request *wsgi_req, int fd) {
wsgi_req->c_len = sizeof(struct sockaddr_un);
return accept(fd, (struct sockaddr *) &wsgi_req->c_addr, (socklen_t *) & wsgi_req->c_len);
}
+10 -9
View File
@@ -89,6 +89,8 @@ static int http_parse(struct wsgi_request *wsgi_req, char *watermark) {
char *ptr = wsgi_req->proto_parser_buf;
char *base = ptr;
char *query_string = NULL;
char ip[INET_ADDRSTRLEN+1];
struct sockaddr_in *http_sin = (struct sockaddr_in *) &wsgi_req->c_addr;
// REQUEST_METHOD
while (ptr < watermark) {
@@ -146,15 +148,14 @@ static int http_parse(struct wsgi_request *wsgi_req, char *watermark) {
// SERVER_PORT
wsgi_req->uh.pktsize += proto_base_add_uwsgi_var(wsgi_req, "SERVER_PORT", 11, "3031", 4);
/*
// REMOTE_ADDR
if (inet_ntop(AF_INET, &h_session->ip_addr, h_session->ip, INET_ADDRSTRLEN)) {
h_session->uh.pktsize += proto_base_add_uwsgi_var(h_session->iov, h_session->uss+c, h_session->uss+c+2, "REMOTE_ADDR", 11, h_session->ip, strlen(h_session->ip));
}
else {
uwsgi_error("inet_ntop()");
}
*/
// REMOTE_ADDR
memset(ip, 0, INET_ADDRSTRLEN+1);
if (inet_ntop(AF_INET, (void *) &http_sin->sin_addr.s_addr, ip, INET_ADDRSTRLEN)) {
wsgi_req->uh.pktsize += proto_base_add_uwsgi_var(wsgi_req, "REMOTE_ADDR", 11, ip, strlen(ip));
}
else {
uwsgi_error("inet_ntop()");
}
//HEADERS
base = ptr;
+35 -7
View File
@@ -6,6 +6,7 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
int serverfd;
struct sockaddr_un *uws_addr;
socklen_t len;
// leave 1 byte for abstract namespace (108 linux -> 104 bsd/mac)
if (strlen(socket_name) > 102) {
@@ -16,6 +17,9 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
if (socket_name[0] == '@') {
abstract_socket = 1;
}
else if (strlen(socket_name) > 1 && socket_name[0] == '\\' && socket_name[1] == '0') {
abstract_socket = 1;
}
uws_addr = malloc(sizeof(struct sockaddr_un));
if (uws_addr == NULL) {
@@ -41,16 +45,23 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
uws_addr->sun_family = AF_UNIX;
if (socket_name[0] == '@') {
memcpy(uws_addr->sun_path + abstract_socket, socket_name+1, strlen(socket_name+1));
memcpy(uws_addr->sun_path + abstract_socket, socket_name+1, UMIN(strlen(socket_name+1), 101));
len = strlen(socket_name) + 1;
}
else if (strlen(socket_name) > 1 && socket_name[0] == '\\' && socket_name[1] == '0') {
memcpy(uws_addr->sun_path + abstract_socket, socket_name+2, UMIN(strlen(socket_name+2), 101));
len = strlen(socket_name+1) + 1;
}
else {
memcpy(uws_addr->sun_path + abstract_socket, socket_name, strlen(socket_name));
memcpy(uws_addr->sun_path + abstract_socket, socket_name, UMIN(strlen(socket_name), 102));
len = strlen(socket_name);
}
#ifdef __HAIKU__
if (bind(serverfd, (struct sockaddr *) uws_addr, sizeof(struct sockaddr_un))) {
#else
if (bind(serverfd, (struct sockaddr *) uws_addr, strlen(socket_name) + abstract_socket + ((void *) uws_addr->sun_path - (void *) uws_addr)) != 0) {
if (bind(serverfd, (struct sockaddr *) uws_addr, len + ((void *) uws_addr->sun_path - (void *) uws_addr)) != 0) {
#endif
uwsgi_error("bind()");
uwsgi_nuclear_blast();
@@ -260,11 +271,23 @@ int connect_to_unix(char *socket_name, int timeout, int async) {
struct pollfd uwsgi_poll;
struct sockaddr_un uws_addr;
socklen_t un_size = sizeof(struct sockaddr_un);
memset(&uws_addr, 0, sizeof(struct sockaddr_un));
uws_addr.sun_family = AF_UNIX;
memcpy(uws_addr.sun_path, socket_name, 102);
if (socket_name[0] == '@'){
un_size = sizeof(uws_addr.sun_family) + strlen(socket_name) + 1;
memcpy(uws_addr.sun_path+1, socket_name+1, UMIN(strlen(socket_name+1), 101));
}
else if (strlen(socket_name) > 1 && socket_name[0] == '\\' && socket_name[1] == '0') {
un_size = sizeof(uws_addr.sun_family) + strlen(socket_name+1) + 1;
memcpy(uws_addr.sun_path+1, socket_name+2, UMIN(strlen(socket_name+2), 101));
}
else {
memcpy(uws_addr.sun_path, socket_name, UMIN(strlen(socket_name), 102));
}
uwsgi_poll.fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (uwsgi_poll.fd < 0) {
@@ -274,7 +297,7 @@ int connect_to_unix(char *socket_name, int timeout, int async) {
uwsgi_poll.events = POLLIN;
if (timed_connect(&uwsgi_poll, (const struct sockaddr *) &uws_addr, sizeof(struct sockaddr_un), timeout, async)) {
if (timed_connect(&uwsgi_poll, (const struct sockaddr *) &uws_addr, un_size, timeout, async)) {
uwsgi_error("connect()");
close(uwsgi_poll.fd);
return -1;
@@ -414,10 +437,15 @@ socklen_t socket_to_un_addr(char *socket_name, struct sockaddr_un *sun_addr) {
// abstract socket
if (socket_name[0] == '@') {
memcpy(sun_addr->sun_path+1, socket_name+1, len-1);
memcpy(sun_addr->sun_path+1, socket_name+1, UMIN(len-1, 101));
len = strlen(socket_name) + 1;
}
else if (len > 1 && socket_name[0] == '\\' && socket_name[1] == '0') {
memcpy(sun_addr->sun_path+1, socket_name+2, UMIN(len-2, 101));
len = strlen(socket_name+1) + 1;
}
else {
memcpy(sun_addr->sun_path, socket_name, len);
memcpy(sun_addr->sun_path, socket_name, UMIN(len, 102));
}
return sizeof(sun_addr->sun_family)+len;
+1 -1
View File
@@ -6,7 +6,7 @@ def application(env, start_response):
start_response( '200 OK', [ ('Content-Type','text/html') ])
start_time = time.time()
for i in range(1,100000):
uwsgi.green_schedule()
uwsgi.suspend()
# print every 100
if i % 100 == 0:
yield "<h1>%d</h1>\n" % i
+14 -1
View File
@@ -905,6 +905,7 @@ void uwsgi_log(const char *fmt, ...) {
va_list ap;
char logpkt[4096];
int rlen = 0;
int ret;
struct timeval tv;
char sftime[64];
@@ -929,9 +930,21 @@ void uwsgi_log(const char *fmt, ...) {
}
va_start(ap, fmt);
rlen += vsnprintf(logpkt + rlen, 4096 - rlen, fmt, ap);
ret = vsnprintf(logpkt + rlen, 4096 - rlen, fmt, ap);
va_end(ap);
if (ret >= 4096) {
char *tmp_buf = uwsgi_malloc(rlen + ret + 1);
memcpy(tmp_buf, logpkt, rlen);
va_start(ap, fmt);
ret = vsnprintf(tmp_buf + rlen, ret+1, fmt, ap);
va_end(ap);
rlen = write(2, tmp_buf, rlen+ret);
free(tmp_buf);
return;
}
rlen+=ret;
// do not check for errors
rlen = write(2, logpkt, rlen);
}
+235 -179
View File
@@ -64,6 +64,7 @@ static struct option long_base_options[] = {
{"single-interpreter", no_argument, 0, 'i'},
{"master", no_argument, 0, 'M'},
{"emperor", required_argument, 0, LONG_ARGS_EMPEROR},
{"early-emperor", no_argument, &uwsgi.early_emperor, 1},
{"emperor-amqp-vhost", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_VHOST},
{"emperor-amqp-username", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_USERNAME},
{"emperor-amqp-password", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_PASSWORD},
@@ -165,6 +166,7 @@ static struct option long_base_options[] = {
#endif
{"log-master", no_argument, 0, LONG_ARGS_LOG_MASTER},
{"logdate", optional_argument, 0, LONG_ARGS_LOG_DATE},
{"log-date", optional_argument, 0, LONG_ARGS_LOG_DATE},
{"log-prefix", optional_argument, 0, LONG_ARGS_LOG_DATE},
{"log-zero", no_argument, 0, LONG_ARGS_LOG_ZERO},
{"log-slow", required_argument, 0, LONG_ARGS_LOG_SLOW},
@@ -221,48 +223,48 @@ static struct option long_base_options[] = {
void uwsgi_configure(void) {
struct option *lopt = uwsgi.long_options;
struct option *aopt;
char *val;
struct option *aopt;
char *val;
int i;
int is_retry;
int found;
for (i = 0; i < uwsgi.exported_opts_cnt; i++) {
for (i = 0; i < uwsgi.exported_opts_cnt; i++) {
if (uwsgi.exported_opts[i]->configured)
continue;
if (uwsgi.exported_opts[i]->configured)
continue;
is_retry = 0;
retry:
retry:
found = 0;
lopt = uwsgi.long_options;;
while ((aopt = lopt)) {
if (!aopt->name)
break;
lopt = uwsgi.long_options;;
while ((aopt = lopt)) {
if (!aopt->name)
break;
if (!strcmp(aopt->name, uwsgi.exported_opts[i]->key)) {
if (!strcmp(aopt->name, uwsgi.exported_opts[i]->key)) {
found = 1;
val = uwsgi.exported_opts[i]->value;
val = uwsgi.exported_opts[i]->value;
if (aopt->flag)
*aopt->flag = aopt->val;
else if (val) {
if (aopt->has_arg == optional_argument) {
if (!strcasecmp("true", val)) {
val = NULL;
}
}
if (aopt->has_arg == no_argument) {
if (!strcasecmp("false", val) || val[0] == '0') {
lopt++;
continue;
}
}
manage_opt(aopt->val, val);
}
}
lopt++;
}
if (aopt->flag)
*aopt->flag = aopt->val;
else if (val) {
if (aopt->has_arg == optional_argument) {
if (!strcasecmp("true", val)) {
val = NULL;
}
}
if (aopt->has_arg == no_argument) {
if (!strcasecmp("false", val) || val[0] == '0') {
lopt++;
continue;
}
}
manage_opt(aopt->val, val);
}
}
lopt++;
}
if (!found && uwsgi.autoload && !is_retry) {
DIR *pdir;
@@ -272,7 +274,7 @@ retry:
uwsgi_fatal_error("opendir()");
}
while ((dp = readdir(pdir)) != NULL) {
if (!strncmp("_plugin.so", dp->d_name+(strlen(dp->d_name)-10), 19)) {
if (!strncmp("_plugin.so", dp->d_name + (strlen(dp->d_name) - 10), 19)) {
if (uwsgi_load_plugin(-1, dp->d_name, uwsgi.exported_opts[i]->key, 2)) {
uwsgi_log("option \"%s\" found in plugin %s\n", uwsgi.exported_opts[i]->key, dp->d_name);
found = 1;
@@ -289,7 +291,7 @@ retry:
}
closedir(pdir);
}
}
}
}
@@ -335,26 +337,26 @@ void warn_pipe() {
#ifdef UWSGI_THREADING
// in threading mode we need to use the cancel pthread subsystem
void wait_for_threads() {
int i, ret;
int i, ret;
pthread_mutex_lock(&uwsgi.six_feet_under_lock);
for(i=0;i<uwsgi.threads;i++) {
if (!pthread_equal(uwsgi.core[i]->thread_id, pthread_self())) {
pthread_cancel(uwsgi.core[i]->thread_id);
}
}
pthread_mutex_lock(&uwsgi.six_feet_under_lock);
for (i = 0; i < uwsgi.threads; i++) {
if (!pthread_equal(uwsgi.core[i]->thread_id, pthread_self())) {
pthread_cancel(uwsgi.core[i]->thread_id);
}
}
// wait for thread termination
for(i=0;i<uwsgi.threads;i++) {
if (!pthread_equal(uwsgi.core[i]->thread_id, pthread_self())) {
ret = pthread_join(uwsgi.core[i]->thread_id, NULL);
if (ret) {
uwsgi_log("pthread_join() = %d\n", ret);
}
}
}
// wait for thread termination
for (i = 0; i < uwsgi.threads; i++) {
if (!pthread_equal(uwsgi.core[i]->thread_id, pthread_self())) {
ret = pthread_join(uwsgi.core[i]->thread_id, NULL);
if (ret) {
uwsgi_log("pthread_join() = %d\n", ret);
}
}
}
pthread_mutex_unlock(&uwsgi.six_feet_under_lock);
pthread_mutex_unlock(&uwsgi.six_feet_under_lock);
}
#endif
@@ -370,7 +372,7 @@ void gracefully_kill(int signum) {
if (!uwsgi.core[wsgi_req->async_id]->in_request) {
exit(UWSGI_RELOAD_CODE);
}
return;
return;
// never here
}
#endif
@@ -406,6 +408,14 @@ void goodbye_cruel_world() {
void kill_them_all(int signum) {
int i;
uwsgi.to_hell = 1;
if (uwsgi.reload_mercy > 0) {
uwsgi.master_mercy = time(NULL) + uwsgi.reload_mercy;
}
else {
uwsgi.master_mercy = time(NULL) + 5;
}
uwsgi_log("SIGINT/SIGQUIT received...killing workers...\n");
for (i = 1; i <= uwsgi.numproc; i++) {
if (uwsgi.workers[i].pid > 0)
@@ -413,16 +423,17 @@ void kill_them_all(int signum) {
}
#ifdef UWSGI_SPOOLER
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
kill(uwsgi.shared->spooler_pid, SIGKILL);
uwsgi_log( "killed the spooler with pid %d\n", uwsgi.shared->spooler_pid);
}
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
kill(uwsgi.shared->spooler_pid, SIGKILL);
uwsgi_log("killed the spooler with pid %d\n", uwsgi.shared->spooler_pid);
}
#endif
if (uwsgi.emperor_pid >= 0) {
kill(uwsgi.emperor_pid, SIGKILL);
uwsgi_log( "killed the emperor with pid %d\n", uwsgi.emperor_pid);
waitpid(uwsgi.emperor_pid, &i, 0);
uwsgi_log("killed the emperor with pid %d\n", uwsgi.emperor_pid);
}
@@ -441,22 +452,24 @@ void grace_them_all(int signum) {
int i;
int waitpid_status;
if (!uwsgi.lazy) uwsgi.to_heaven = 1;
if (!uwsgi.lazy)
uwsgi.to_heaven = 1;
if (uwsgi.reload_mercy > 0) {
uwsgi.master_mercy = time(NULL) + uwsgi.reload_mercy;
}
#ifdef UWSGI_SPOOLER
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
kill(uwsgi.shared->spooler_pid, SIGKILL);
uwsgi_log( "killed the spooler with pid %d\n", uwsgi.shared->spooler_pid);
}
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
kill(uwsgi.shared->spooler_pid, SIGKILL);
uwsgi_log("killed the spooler with pid %d\n", uwsgi.shared->spooler_pid);
}
#endif
if (uwsgi.emperor_pid >= 0) {
kill(uwsgi.emperor_pid, SIGKILL);
uwsgi_log( "killed the emperor with pid %d\n", uwsgi.emperor_pid);
waitpid(uwsgi.emperor_pid, &i, 0);
uwsgi_log("killed the emperor with pid %d\n", uwsgi.emperor_pid);
}
for (i = 0; i < uwsgi.shared->daemons_cnt; i++) {
@@ -476,8 +489,8 @@ void grace_them_all(int signum) {
if (uwsgi.workers[i].snapshot > 0) {
kill(uwsgi.workers[i].snapshot, SIGKILL);
if (waitpid(uwsgi.workers[i].snapshot, &waitpid_status, 0) < 0) {
uwsgi_error("waitpid()");
}
uwsgi_error("waitpid()");
}
}
if (uwsgi.workers[i].pid > 0) {
if (uwsgi.auto_snapshot > 0 && i > uwsgi.auto_snapshot) {
@@ -517,7 +530,8 @@ void uwsgi_nuclear_blast() {
void reap_them_all(int signum) {
int i;
if (!uwsgi.lazy) uwsgi.to_heaven = 1;
if (!uwsgi.lazy)
uwsgi.to_heaven = 1;
for (i = 0; i < uwsgi.shared->daemons_cnt; i++) {
if (uwsgi.shared->daemons[i].pid > 0)
@@ -529,6 +543,12 @@ void reap_them_all(int signum) {
kill(uwsgi.gateways[i].pid, SIGKILL);
}
if (uwsgi.emperor_pid >= 0) {
kill(uwsgi.emperor_pid, SIGKILL);
waitpid(uwsgi.emperor_pid, &i, 0);
uwsgi_log("killed the emperor with pid %d\n", uwsgi.emperor_pid);
}
if (!uwsgi.workers)
return;
@@ -558,9 +578,9 @@ void snapshot_me(int signum) {
uwsgi.workers[uwsgi.mywid].manage_next_request = 0;
#ifdef UWSGI_THREADING
if (uwsgi.threads > 1) {
wait_for_threads();
}
if (uwsgi.threads > 1) {
wait_for_threads();
}
#endif
uwsgi.snapshot = 1;
uwsgi_log("[snapshot] process %d taken\n", (int) getpid());
@@ -664,7 +684,7 @@ static void vacuum(void) {
uwsgi_error("chdir()");
}
}
while(uwsgi_sock) {
while (uwsgi_sock) {
if (uwsgi_sock->family == AF_UNIX) {
if (unlink(uwsgi_sock->name)) {
uwsgi_error("unlink()");
@@ -1193,7 +1213,7 @@ int main(int argc, char *argv[], char *envp[]) {
}
struct uwsgi_socket *shared_sock = uwsgi.shared_sockets;
while(shared_sock) {
while (shared_sock) {
char *tcp_port = strchr(shared_sock->name, ':');
if (tcp_port == NULL) {
shared_sock->fd = bind_to_unix(shared_sock->name, uwsgi.listen_queue, uwsgi.chmod_socket, uwsgi.abstract_socket);
@@ -1211,10 +1231,38 @@ int main(int argc, char *argv[], char *envp[]) {
exit(1);
}
shared_sock->bound = 1;
shared_sock = shared_sock->next;
}
// start the Emperor if needed
if (uwsgi.early_emperor && uwsgi.emperor_dir) {
if (!uwsgi.sockets && !uwsgi.gateways_cnt && !uwsgi.master_process) {
uwsgi_notify_ready();
emperor_loop();
// never here
exit(1);
}
uwsgi.emperor_pid = fork();
if (uwsgi.emperor_pid < 0) {
uwsgi_error("pid()");
exit(1);
}
else if (uwsgi.emperor_pid == 0) {
#ifdef __linux__
if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0)) {
uwsgi_error("prctl()");
}
#endif
emperor_loop();
// never here
exit(1);
}
}
// call jail systems
for (i = 0; i < uwsgi.gp_cnt; i++) {
if (uwsgi.gp[i]->jail) {
@@ -1260,7 +1308,7 @@ int uwsgi_start(void *v_argv) {
struct uwsgi_socket *uwsgi_sock;
#ifdef __linux__
uwsgi_set_cgroup();
uwsgi_set_cgroup();
if (uwsgi.ns) {
linux_namespace_jail();
@@ -1342,13 +1390,13 @@ int uwsgi_start(void *v_argv) {
// start the Emperor if needed
if (uwsgi.emperor_dir) {
if (!uwsgi.early_emperor && uwsgi.emperor_dir) {
if (!uwsgi.sockets && !uwsgi.gateways_cnt && !uwsgi.master_process) {
uwsgi_notify_ready();
emperor_loop();
// never here
exit(1);
// never here
exit(1);
}
uwsgi.emperor_pid = fork();
@@ -1357,6 +1405,11 @@ int uwsgi_start(void *v_argv) {
exit(1);
}
else if (uwsgi.emperor_pid == 0) {
#ifdef __linux__
if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0)) {
uwsgi_error("prctl()");
}
#endif
emperor_loop();
// never here
exit(1);
@@ -1534,7 +1587,7 @@ int uwsgi_start(void *v_argv) {
//check for inherited sockets
if (uwsgi.is_a_reload) {
uwsgi_sock = uwsgi.sockets;
while(uwsgi_sock) {
while (uwsgi_sock) {
//a bit overengineering
if (uwsgi_sock->name[0] != 0) {
for (j = 3; j < sysconf(_SC_OPEN_MAX); j++) {
@@ -1559,7 +1612,7 @@ int uwsgi_start(void *v_argv) {
gsa.sa = (struct sockaddr *) &usa;
if (!getsockname(j, gsa.sa, &socket_type_len)) {
uwsgi_sock = uwsgi.sockets;
while(uwsgi_sock) {
while (uwsgi_sock) {
if (uwsgi_sock->fd == j && uwsgi_sock->bound) {
useless = 0;
break;
@@ -1573,7 +1626,7 @@ int uwsgi_start(void *v_argv) {
}
//now bind all the unbound sockets
uwsgi_sock = uwsgi.sockets;
while(uwsgi_sock) {
while (uwsgi_sock) {
if (!uwsgi_sock->bound) {
char *tcp_port = strchr(uwsgi_sock->name, ':');
if (tcp_port == NULL) {
@@ -1598,7 +1651,7 @@ int uwsgi_start(void *v_argv) {
int zero_used = 0;
uwsgi_sock = uwsgi.sockets;
while(uwsgi_sock) {
while (uwsgi_sock) {
if (uwsgi_sock->bound && uwsgi_sock->fd == 0) {
zero_used = 1;
break;
@@ -1610,14 +1663,13 @@ int uwsgi_start(void *v_argv) {
socket_type_len = sizeof(struct sockaddr_un);
gsa.sa = (struct sockaddr *) &usa;
if (!getsockname(0, gsa.sa, &socket_type_len)) {
if (gsa.sa->sa_family == AF_UNIX) {
uwsgi_sock = uwsgi_new_socket(usa.sa_un.sun_path);
uwsgi_log("uwsgi socket %d inherited UNIX address %s fd 0\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name);
}
else {
uwsgi_sock = uwsgi_new_socket(":0");
uwsgi_log("uwsgi socket %d inherited INET address %s fd 0\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name);
}
if (gsa.sa->sa_family == AF_UNIX) {
uwsgi_sock = uwsgi_new_socket(usa.sa_un.sun_path);
uwsgi_log("uwsgi socket %d inherited UNIX address %s fd 0\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name);
}
else {
uwsgi_sock = uwsgi_new_socket(":0");
uwsgi_log("uwsgi socket %d inherited INET address %s fd 0\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name);
}
}
else {
@@ -1639,7 +1691,7 @@ int uwsgi_start(void *v_argv) {
// put listening socket in non-blocking state and set the protocol
uwsgi_sock = uwsgi.sockets;
while(uwsgi_sock) {
while (uwsgi_sock) {
uwsgi_sock->arg = fcntl(uwsgi_sock->fd, F_GETFL, NULL);
if (uwsgi_sock->arg < 0) {
uwsgi_error("fcntl()");
@@ -1702,10 +1754,11 @@ int uwsgi_start(void *v_argv) {
}
#endif
}
// initialize request plugin only if workers or master are available
if (uwsgi.sockets || uwsgi.master_process) {
if (uwsgi.sockets || uwsgi.master_process || uwsgi.no_server) {
for (i = 0; i < 0xFF; i++) {
if (uwsgi.p[i]->init) {
uwsgi.p[i]->init();
@@ -1743,7 +1796,7 @@ int uwsgi_start(void *v_argv) {
}
#endif
if (!uwsgi.sockets && !uwsgi.gateways_cnt && !uwsgi.no_server && !uwsgi.udp_socket) {
if (!uwsgi.sockets && !uwsgi.gateways_cnt && !uwsgi.no_server && !uwsgi.udp_socket && !uwsgi.emperor_dir) {
uwsgi_log("The -s/--socket option is missing and stdin is not a socket.\n");
exit(1);
}
@@ -1756,7 +1809,7 @@ int uwsgi_start(void *v_argv) {
#ifdef UWSGI_DEBUG
uwsgi_sock = uwsgi.sockets;
while(uwsgi_sock) {
while (uwsgi_sock) {
so_bufsize_len = sizeof(int);
if (getsockopt(uwsgi_sock->fd, SOL_SOCKET, SO_RCVBUF, &so_bufsize, &so_bufsize_len)) {
uwsgi_error("getsockopt()");
@@ -1855,7 +1908,7 @@ int uwsgi_start(void *v_argv) {
uwsgi_log("no-server mode requested. Goodbye.\n");
exit(0);
}
//is this a proxy only worker ?
if (!uwsgi.master_process && uwsgi.numproc == 0) {
exit(0);
@@ -1926,9 +1979,10 @@ int uwsgi_start(void *v_argv) {
if (!uwsgi.cheap) {
for (i = 2 - uwsgi.master_process; i < uwsgi.numproc + 1; i++) {
if (uwsgi_respawn_worker(i)) break;
if (uwsgi_respawn_worker(i))
break;
gettimeofday(&last_respawn, NULL);
uwsgi.respawn_delta = last_respawn.tv_sec;
uwsgi.respawn_delta = last_respawn.tv_sec;
}
}
@@ -1939,58 +1993,58 @@ int uwsgi_start(void *v_argv) {
}
uwsgi_sock = uwsgi.sockets;
while(uwsgi_sock) {
struct uwsgi_string_list *usl = uwsgi.map_socket;
while (uwsgi_sock) {
struct uwsgi_string_list *usl = uwsgi.map_socket;
int enabled = 1;
while(usl) {
while (usl) {
char *colon = strchr(usl->value, ':');
if (uwsgi_str_num(usl->value, colon-usl->value) == uwsgi_get_socket_num(uwsgi_sock)) {
char *colon = strchr(usl->value, ':');
if (uwsgi_str_num(usl->value, colon - usl->value) == uwsgi_get_socket_num(uwsgi_sock)) {
enabled = 0;
char *p = strtok(colon+1, ",");
while (p != NULL) {
int w = atoi(p);
if (w < 1 || w > uwsgi.numproc) {
uwsgi_log("invalid worker num: %d\n", w);
exit(1);
}
char *p = strtok(colon + 1, ",");
while (p != NULL) {
int w = atoi(p);
if (w < 1 || w > uwsgi.numproc) {
uwsgi_log("invalid worker num: %d\n", w);
exit(1);
}
if (w == uwsgi.mywid) {
enabled = 1;
uwsgi_log("mapped socket %d (%s) to worker %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi.mywid);
break;
}
p = strtok(NULL, ",");
}
p = strtok(NULL, ",");
}
}
usl = usl->next;
}
usl = usl->next;
}
if (!enabled) {
int fd = uwsgi_sock->fd;
close(fd);
fd = open("/dev/null", O_RDONLY);
if (fd < 0) {
uwsgi_error_open("/dev/null");
exit(1);
}
if (fd != uwsgi_sock->fd) {
if (dup2(fd, uwsgi_sock->fd)) {
uwsgi_error("dup2()");
exit(1);
}
close(fd);
}
fd = open("/dev/null", O_RDONLY);
if (fd < 0) {
uwsgi_error_open("/dev/null");
exit(1);
}
if (fd != uwsgi_sock->fd) {
if (dup2(fd, uwsgi_sock->fd)) {
uwsgi_error("dup2()");
exit(1);
}
close(fd);
}
uwsgi_sock->disabled = 1;
}
uwsgi_sock = uwsgi_sock->next;
}
}
uwsgi_sock = uwsgi.sockets;
while(uwsgi_sock) {
while (uwsgi_sock) {
if (uwsgi_sock->disabled) {
uwsgi_sock = uwsgi_del_socket(uwsgi_sock);
}
@@ -2046,9 +2100,9 @@ int uwsgi_start(void *v_argv) {
}
uwsgi.core = uwsgi_malloc(sizeof(struct uwsgi_core *) * uwsgi.cores);
for (j = 0; j < uwsgi.cores; j++) {
uwsgi.core[j] = uwsgi_malloc(sizeof(struct uwsgi_core));
memset(uwsgi.core[j], 0, sizeof(struct uwsgi_core));
for (j = 0; j < uwsgi.cores; j++) {
uwsgi.core[j] = uwsgi_malloc(sizeof(struct uwsgi_core));
memset(uwsgi.core[j], 0, sizeof(struct uwsgi_core));
}
if (uwsgi.master_as_root) {
@@ -2178,7 +2232,7 @@ int uwsgi_start(void *v_argv) {
uwsgi_unix_signal(SIGHUP, gracefully_kill);
uwsgi_unix_signal(SIGINT, end_me);
uwsgi_unix_signal(SIGTERM, end_me);
if (uwsgi.auto_snapshot) {
uwsgi_unix_signal(SIGURG, snapshot_me);
}
@@ -2195,10 +2249,10 @@ int uwsgi_start(void *v_argv) {
// run fixup handler
for (i = 0; i < 0xFF; i++) {
if (uwsgi.p[i]->fixup) {
uwsgi.p[i]->fixup();
}
}
if (uwsgi.p[i]->fixup) {
uwsgi.p[i]->fixup();
}
}
if (uwsgi.chdir2) {
if (chdir(uwsgi.chdir2)) {
@@ -2271,10 +2325,11 @@ void uwsgi_ignition() {
int i;
// snapshot workers do not enter the loop until a specific signal (SIGURG) is raised...
if (uwsgi.snapshot) {
wait_for_call_of_duty:
if (uwsgi.snapshot) {
wait_for_call_of_duty:
uwsgi_sig_pause();
if (uwsgi.snapshot) goto wait_for_call_of_duty;
if (uwsgi.snapshot)
goto wait_for_call_of_duty;
uwsgi_log("[snapshot] process %d is the new worker %d\n", (int) getpid(), uwsgi.mywid);
}
@@ -2461,7 +2516,7 @@ static int manage_base_opt(int i, char *optarg) {
uwsgi.log_socket = 1;
uwsgi.log_master = 1;
uwsgi.master_process = 1;
log_socket(optarg);
log_socket(optarg);
return 1;
case LONG_ARGS_LOG_SYSLOG:
log_syslog(optarg);
@@ -2470,12 +2525,12 @@ static int manage_base_opt(int i, char *optarg) {
uwsgi.master_process = 1;
return 1;
#ifdef UWSGI_ZEROMQ
case LONG_ARGS_LOG_ZEROMQ:
log_zeromq(optarg);
uwsgi.log_master = 1;
uwsgi.master_process = 1;
return 1;
#endif
case LONG_ARGS_LOG_ZEROMQ:
log_zeromq(optarg);
uwsgi.log_master = 1;
uwsgi.master_process = 1;
return 1;
#endif
case LONG_ARGS_PRINT:
uwsgi_log("%s\n", optarg);
return 1;
@@ -3701,48 +3756,49 @@ void uwsgi_init_all_apps() {
int i, j;
for (i = 0; i < 0xFF; i++) {
if (uwsgi.p[i]->init_apps) {
uwsgi.p[i]->init_apps();
}
}
if (uwsgi.p[i]->init_apps) {
uwsgi.p[i]->init_apps();
}
}
for (i = 0; i < uwsgi.gp_cnt; i++) {
if (uwsgi.gp[i]->init_apps) {
uwsgi.gp[i]->init_apps();
}
}
for (i = 0; i < uwsgi.gp_cnt; i++) {
if (uwsgi.gp[i]->init_apps) {
uwsgi.gp[i]->init_apps();
}
}
/*parse xml for <app> tags */
/*parse xml for <app> tags */
#ifdef UWSGI_XML
if (uwsgi.xml_round2 && uwsgi.xml_config != NULL) {
uwsgi_xml_config(uwsgi.xml_config, uwsgi.wsgi_req, 1, NULL);
}
if (uwsgi.xml_round2 && uwsgi.xml_config != NULL) {
uwsgi_xml_config(uwsgi.xml_config, uwsgi.wsgi_req, 1, NULL);
}
#endif
for (i = 0; i < uwsgi.mounts_cnt; i++) {
char *what = strchr(uwsgi.mounts[i], '=');
if (what) {
what[0] = 0;
what++;
uwsgi_log("mounting %s on %s\n", what, uwsgi.mounts[i]);
for (j = 0; j < 0xFF; j++) {
if (uwsgi.p[j]->mount_app) {
if (uwsgi.p[j]->mount_app(uwsgi.mounts[i], what) != -1)
break;
}
}
what--;
what[0] = '=';
}
else {
uwsgi_log("invalid mountpoint: %s\n", uwsgi.mounts[i]);
exit(1);
}
}
for (i = 0; i < uwsgi.mounts_cnt; i++) {
char *what = strchr(uwsgi.mounts[i], '=');
if (what) {
what[0] = 0;
what++;
uwsgi_log("mounting %s on %s\n", what, uwsgi.mounts[i]);
for (j = 0; j < 0xFF; j++) {
if (uwsgi.p[j]->mount_app) {
if (uwsgi.p[j]->mount_app(uwsgi.mounts[i], what) != -1)
break;
}
}
what--;
what[0] = '=';
}
else {
uwsgi_log("invalid mountpoint: %s\n", uwsgi.mounts[i]);
exit(1);
}
}
// no app initialized and virtualhosting enabled
if (uwsgi.apps_cnt == 0 && uwsgi.vhost) {
uwsgi.apps_cnt = 1;
}
// no app initialized and virtualhosting enabled
if (uwsgi.apps_cnt == 0) {
uwsgi_log("*** no app loaded. going in full dynamic mode ***\n");
uwsgi.apps_cnt = 1;
}
}
+7 -2
View File
@@ -473,6 +473,8 @@ struct uwsgi_opt {
#define UWSGI_OPTION_LOG_5xx 12
#define UWSGI_OPTION_LOG_BIG 13
#define UWSGI_OPTION_LOG_SENDFILE 14
#define UWSGI_OPTION_BACKLOG_STATUS 15
#define UWSGI_OPTION_BACKLOG_ERRORS 16
#define UWSGI_MODIFIER_ADMIN_REQUEST 10
#define UWSGI_MODIFIER_SPOOL_REQUEST 17
@@ -669,8 +671,10 @@ struct wsgi_request {
struct msghdr msg;
union {
struct cmsghdr cmsg;
#ifndef __NetBSD__
char control [CMSG_SPACE (sizeof (int))];
} msg_control;
#endif
} msg_control;
struct timeval start_of_request;
struct timeval end_of_request;
@@ -858,6 +862,7 @@ struct uwsgi_server {
int has_emperor;
int emperor_fd;
int emperor_fd_config;
int early_emperor;
char *emperor_dir;
pid_t emperor_pid;
struct uwsgi_config_template *vassals_templates;
@@ -1309,7 +1314,7 @@ struct uwsgi_shared {
//vga 80 x25 specific !
char warning_message[81];
uint32_t options[0xFF];
uint32_t options[256];
struct uwsgi_cluster_node nodes[MAX_CLUSTER_NODES];
+40 -2
View File
@@ -1,6 +1,6 @@
# uWSGI build system
uwsgi_version = '0.9.8-dev'
uwsgi_version = '0.9.8'
import os
import re
@@ -176,7 +176,7 @@ class uConf(object):
if uwsgi_os == 'Linux':
self.gcc_list.append('lib/linux_ns')
self.gcc_list.append('lib/netlink')
self.cflags = ['-DUWSGI_VERSION="\\"' + uwsgi_version + '\\""', '-O2', '-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split()
self.cflags = ['-O2', '-Wall', '-Werror', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split()
try:
gcc_version = str(spcall("%s -dumpversion" % GCC))
except:
@@ -237,6 +237,8 @@ class uConf(object):
def get_gcll(self):
global uwsgi_version
self.cflags.append('-DUWSGI_BUILD_DATE="\\"%s\\""' % time.strftime("%d %B %Y %H:%M:%S"))
kvm_list = ['FreeBSD', 'OpenBSD', 'NetBSD', 'DragonFly']
@@ -246,6 +248,7 @@ class uConf(object):
if uwsgi_os == 'SunOS':
self.libs.append('-lsendfile')
self.gcc_list.append('lib/sun_fixes')
self.ldflags.append('-L/lib')
if not uwsgi_os_v.startswith('Nexenta'):
self.libs.remove('-rdynamic')
@@ -407,6 +410,41 @@ class uConf(object):
if os.path.exists('/usr/lib/libuuid.so') or os.path.exists('/usr/local/lib/libuuid.so'):
self.libs.append('-luuid')
if self.get('append_version'):
if not self.get('append_version').startswith('-'):
uwsgi_version += '-'
uwsgi_version += self.get('append_version')
self.cflags.append('-DUWSGI_VERSION="\\"' + uwsgi_version + '\\""')
uver_whole = uwsgi_version.split('-', 1)
if len(uver_whole) == 1:
uver_custom = ''
else:
uver_custom = uver_whole[1]
uver_dots = uver_whole[0].split('.')
uver_base = uver_dots[0]
uver_maj = uver_dots[1]
uver_min = '0'
uver_rev = '0'
if len(uver_dots) > 2:
uver_min = uver_dots[2]
if len(uver_dots) > 3:
uver_rev = uver_dots[3]
self.cflags.append('-DUWSGI_VERSION_BASE="' + uver_base + '"')
self.cflags.append('-DUWSGI_VERSION_MAJOR="' + uver_maj + '"')
self.cflags.append('-DUWSGI_VERSION_MINOR="' + uver_min + '"')
self.cflags.append('-DUWSGI_VERSION_REVISION="' + uver_rev + '"')
self.cflags.append('-DUWSGI_VERSION_CUSTOM="\\"' + uver_custom + '\\""')
if self.get('async'):
self.cflags.append("-DUWSGI_ASYNC")
self.gcc_list.append('async')
+6
View File
@@ -0,0 +1,6 @@
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
+6
View File
@@ -0,0 +1,6 @@
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World! app2 !!!"
+6
View File
@@ -0,0 +1,6 @@
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World! app3"
+6
View File
@@ -0,0 +1,6 @@
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World! app4"
+6
View File
@@ -0,0 +1,6 @@
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World! app5"
+49
View File
@@ -0,0 +1,49 @@
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
upstream uwsgi_server {
server 127.0.0.1:3031;
}
include uwsgi_params;
uwsgi_param UWSGI_FILE $app;
uwsgi_param UWSGI_PYHOME $virtualenv;
server {
listen 8026;
server_name flask001;
set $app vhosttest/flask001/app1.py;
set $virtualenv vhosttest/venv001;
location / {
uwsgi_pass uwsgi_server;
}
}
server {
listen 8026;
server_name flask002;
set $app vhosttest/flask002/app2.py;
set $virtualenv vhosttest/venv001;
location / {
uwsgi_pass uwsgi_server;
}
}
}
+48
View File
@@ -0,0 +1,48 @@
import uwsgi
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 xrange(0,256):
yield "%d = %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():
yield "%s = %s<br/>" % (opt, uwsgi.opt[opt])
routes = {}
routes['/logo'] = serve_logo
routes['/config'] = serve_config
routes['/options'] = serve_options
def application(env, start_response):
if routes.has_key(env['PATH_INFO']):
return routes[env['PATH_INFO']](env, start_response)
start_response('200 OK', [('Content-Type', 'text/html')])
return """
<img src="/logo"/> version %s<br/>
<hr size="1"/>
Configuration<br/>
<iframe src="/config"></iframe><br/>
<br/>
Dynamic options<br/>
<iframe src="/options"></iframe><br/>
""" % (uwsgi.version)