Compare commits

...
6 Commits
16 changed files with 448 additions and 266 deletions
+1
View File
@@ -10,3 +10,4 @@ b8f67c6cd0d62f864db9b2b265b4e260ad7d873c 0.9.6-rc2
5f25d1f97f9dde3e391a668c1c610a52a5db8244 0.9.6.1
ef31fc61ac48018c464f28ebfdf865b96bf83f18 0.9.6.2
9e100c1f085034396cec586f0c76ad3f9800d1a5 0.9.7-beta1
ff4111eb8f55b958ec91c70163e10f3372a9b94d 0.9.7-rc1
+21
View File
@@ -1,5 +1,26 @@
*** march 2011 ***
* 0.9.7-rc1 [20110307]
- export %v in emperor mode
- fixed signal race condition in server reload
- fixed http router post handling bug
- added uwsgi.erlang_register_process in pyerl plugin
- fixed unix socket inherit
- fixed linux namespace support in recent kernel/gcc
- ported threading to python 3.2
- add build date to uWSGI startup info
- do not allow clustering without defining a socket
- kill all the gateways/daemons on startup errors
- fixed vacuum after chdir()
- fixed gateways reload
- re-added support for OpenBSD and NetBSD
- fixed post-buffering in python
- use erlang binary for python string
- fixed memory leak in pyerl plugin
- removed broken log rotation (post-poned)
- fixed no_argument options in ini and yaml parsing
* 0.9.7-beta1 [20110301]
- fully modular re-design
-1
View File
@@ -15,7 +15,6 @@ async = true
evdis = false
ldap = false
pcre = auto
stackless = false
debug = false
unbit = false
xml_implementation = libxml2
+1 -27
View File
@@ -84,7 +84,6 @@ void uwsgi_ini_config(char *file, char *magic_table[]) {
int lines = 1;
struct option *lopt, *aopt;
char *section_asked = "uwsgi";
char *colon;
@@ -126,32 +125,7 @@ void uwsgi_ini_config(char *file, char *magic_table[]) {
ini_rstrip(key);
val = ini_lstrip(val);
ini_rstrip(val);
lopt = uwsgi.long_options;
while ((aopt = lopt)) {
if (!aopt->name)
break;
if (!strcmp(key, aopt->name)) {
if (aopt->flag) {
*aopt->flag = aopt->val;
add_exported_option(0, (char *)key);
}
else {
if (aopt->has_arg == optional_argument) {
if (!strcmp("true", val)) {
val = NULL;
}
}
if (aopt->has_arg == no_argument) {
if (!strcmp("false", val) || val[0] == '0') {
lopt++;
continue;
}
}
manage_opt(aopt->val, val);
}
}
lopt++;
}
add_exported_option((char *)key, val, 0);
}
}
}
+80 -23
View File
@@ -125,7 +125,7 @@ void master_loop(char **argv, char **environ) {
char log_buf[4096];
uint64_t current_time = time(NULL);
time_t current_time = time(NULL);
struct timeval last_respawn;
@@ -172,21 +172,19 @@ void master_loop(char **argv, char **environ) {
struct uwsgi_rb_timer *min_timeout;
struct rb_root *rb_timers = uwsgi_init_rb_timer();
struct tm *uwsgi_cron_delta;
// release the GIL
//UWSGI_RELEASE_GIL
/* route signals to workers... */
uwsgi_unix_signal(SIGHUP, grace_them_all);
signal(SIGTERM, (void *) &reap_them_all);
signal(SIGINT, (void *) &kill_them_all);
signal(SIGQUIT, (void *) &kill_them_all);
/* used only to avoid human-errors */
uwsgi_unix_signal(SIGTERM, reap_them_all);
uwsgi_unix_signal(SIGINT, kill_them_all);
uwsgi_unix_signal(SIGQUIT, kill_them_all);
uwsgi_unix_signal(SIGUSR1, stats);
signal(SIGUSR1, (void *) &stats);
uwsgi.master_queue = event_queue_init();
/* route signals to workers... */
#ifdef UWSGI_DEBUG
uwsgi_log("adding %d to signal poll\n", uwsgi.shared->worker_signal_pipe[0]);
#endif
@@ -426,7 +424,7 @@ void master_loop(char **argv, char **environ) {
uwsgi_error("waitpid()");
/* here is better to reload all the uWSGI stack */
uwsgi_log( "something horrible happened...\n");
reap_them_all();
reap_them_all(0);
exit(1);
}
}
@@ -500,6 +498,75 @@ void master_loop(char **argv, char **environ) {
}
}
// check uwsgi-cron table
if (ushared->cron_cnt) {
current_time = time(NULL);
uwsgi_cron_delta = localtime( &current_time );
if (uwsgi_cron_delta) {
// fix month
uwsgi_cron_delta->tm_mon++;
uwsgi_lock(uwsgi.cron_table_lock);
for(i=0;i<ushared->cron_cnt;i++) {
struct uwsgi_cron *ucron = &ushared->cron[i];
int uc_minute, uc_hour, uc_day, uc_month, uc_week;
uc_minute = ucron->minute;
uc_hour = ucron->hour;
uc_day = ucron->day;
uc_month = ucron->month;
uc_week = ucron->week;
if (ucron->minute == -1) uc_minute = uwsgi_cron_delta->tm_min;
if (ucron->hour == -1) uc_hour = uwsgi_cron_delta->tm_hour;
if (ucron->month == -1) uc_month = uwsgi_cron_delta->tm_mon;
// mday and wday are ORed
if (ucron->day == -1 && ucron->week == -1) {
if (ucron->day == -1) uc_day = uwsgi_cron_delta->tm_mday;
if (ucron->week == -1) uc_week = uwsgi_cron_delta->tm_wday;
}
else if (ucron->day == -1) {
ucron->day = uwsgi_cron_delta->tm_mday;
}
else if (ucron->week == -1) {
ucron->week = uwsgi_cron_delta->tm_wday;
}
else {
if (ucron->day == uwsgi_cron_delta->tm_mday) {
ucron->week = uwsgi_cron_delta->tm_wday;
}
else if (ucron->week == uwsgi_cron_delta->tm_wday) {
ucron->day = uwsgi_cron_delta->tm_mday;
}
}
if (uwsgi_cron_delta->tm_min == uc_minute &&
uwsgi_cron_delta->tm_hour == uc_hour &&
uwsgi_cron_delta->tm_mon == uc_month &&
uwsgi_cron_delta->tm_mday == uc_day &&
uwsgi_cron_delta->tm_wday == uc_week) {
// date match, signal it ?
if (current_time - ucron->last_job > 60) {
uwsgi_route_signal(ucron->sig);
ucron->last_job = current_time;
}
}
}
uwsgi_unlock(uwsgi.cron_table_lock);
}
else {
uwsgi_error("localtime()");
}
}
if (rlen > 0) {
if (uwsgi.log_master) {
@@ -524,7 +591,7 @@ void master_loop(char **argv, char **environ) {
if (byte == 0) {
close(uwsgi.emperor_fd);
uwsgi.has_emperor = 0;
kill_them_all();
kill_them_all(0);
}
// reload me
else if (byte == 1) {
@@ -535,7 +602,7 @@ void master_loop(char **argv, char **environ) {
uwsgi_log("lost connection with my emperor !!!\n");
close(uwsgi.emperor_fd);
uwsgi.has_emperor = 0;
kill_them_all();
kill_them_all(0);
}
}
}
@@ -713,16 +780,6 @@ void master_loop(char **argv, char **environ) {
// recalculate requests counter on race conditions risky configurations
// a bit of inaccuracy is better than locking;)
if (uwsgi.cores > 1) {
for(i=1;i<uwsgi.numproc+1;i++) {
tmp_counter = 0;
for(j=0;j<uwsgi.cores;j++) {
tmp_counter += uwsgi.core[j]->requests;
}
uwsgi.workers[i].requests = tmp_counter;
}
}
if (uwsgi.numproc > 1) {
tmp_counter = 0;
for(i=1;i<uwsgi.numproc+1;i++) {
@@ -736,7 +793,7 @@ void master_loop(char **argv, char **environ) {
for(i=0;i< (int)uwsgi.cache_max_items;i++) {
uwsgi_wlock(uwsgi.cache_lock);
if (uwsgi.cache_items[i].expires) {
if (uwsgi.cache_items[i].expires < current_time) {
if (uwsgi.cache_items[i].expires < (uint64_t) current_time) {
uwsgi_cache_del(uwsgi.cache_items[i].key, uwsgi.cache_items[i].keysize);
}
}
+3
View File
@@ -798,6 +798,9 @@ int uwsgi_python_xml(char *node, char *content) {
uwsgi.wsgi_req->module_len = strlen(uwsgi.wsgi_req->module);
return init_uwsgi_app(LOADER_DYN, uwsgi.wsgi_req, uwsgi.wsgi_req, interpreter);
}
else {
return init_uwsgi_app(LOADER_UWSGI, content, uwsgi.wsgi_req, interpreter);
}
return 1;
}
else if (!strcmp("pyhome", node)) {
+20
View File
@@ -181,6 +181,25 @@ PyObject *py_uwsgi_close(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_add_cron(PyObject * self, PyObject * args) {
uint8_t uwsgi_signal;
int minute, hour, day, month, week;
if (!PyArg_ParseTuple(args, "Biiiii:add_cron", &uwsgi_signal, &minute, &hour, &day, &month, &week)) {
return NULL;
}
if (uwsgi_signal_add_cron(uwsgi_signal, minute, hour, day, month, week)) {
return PyErr_Format(PyExc_ValueError, "unable to add cron");
}
Py_INCREF(Py_True);
return Py_True;
}
PyObject *py_uwsgi_add_timer(PyObject * self, PyObject * args) {
uint8_t uwsgi_signal;
@@ -2343,6 +2362,7 @@ static PyMethodDef uwsgi_advanced_methods[] = {
{"add_file_monitor", py_uwsgi_add_file_monitor, METH_VARARGS, ""},
{"add_timer", py_uwsgi_add_timer, METH_VARARGS, ""},
{"add_rb_timer", py_uwsgi_add_rb_timer, METH_VARARGS, ""},
{"add_cron", py_uwsgi_add_cron, METH_VARARGS, ""},
{"register_rpc", py_uwsgi_register_rpc, METH_VARARGS, ""},
{"rpc", py_uwsgi_rpc, METH_VARARGS, ""},
+25
View File
@@ -91,6 +91,31 @@ int uwsgi_add_timer(uint8_t sig, int secs) {
}
int uwsgi_signal_add_cron(uint8_t sig, int minute, int hour, int day, int month, int week) {
uwsgi_lock(uwsgi.cron_table_lock);
if (ushared->cron_cnt < MAX_CRONS) {
ushared->cron[ushared->cron_cnt].sig = sig;
ushared->cron[ushared->cron_cnt].minute = minute;
ushared->cron[ushared->cron_cnt].hour = hour;
ushared->cron[ushared->cron_cnt].day = day;
ushared->cron[ushared->cron_cnt].month = month;
ushared->cron[ushared->cron_cnt].week = week;
ushared->cron_cnt++;
}
else {
uwsgi_log("you can register max %d cron !!!\n", MAX_CRONS);
uwsgi_unlock(uwsgi.cron_table_lock);
return -1;
}
uwsgi_unlock(uwsgi.cron_table_lock);
return 0;
}
int uwsgi_signal_add_rb_timer(uint8_t sig, int secs, int iterations) {
uwsgi_lock(uwsgi.rb_timer_table_lock);
+3
View File
@@ -0,0 +1,3 @@
def application(env, start_response):
while 1:
pass
+19 -61
View File
@@ -394,10 +394,6 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
uwsgi.workers[0].requests++;
uwsgi.workers[uwsgi.mywid].requests++;
if (uwsgi.cores > 1) {
uwsgi.core[wsgi_req->async_id]->requests++;
}
// after_request hook
if (uwsgi.p[wsgi_req->uh.modifier1]->after_request) uwsgi.p[wsgi_req->uh.modifier1]->after_request(wsgi_req);
@@ -504,7 +500,7 @@ polling:
if (read(uwsgi.sockets_poll[uwsgi.sockets_cnt].fd, &uwsgi_signal, 1) <= 0) {
if (uwsgi.no_orphans) {
uwsgi_log_verbose("uWSGI worker %d screams: UAAAAAAH my master died, i will follow him...\n", uwsgi.mywid);
end_me();
end_me(0);
}
}
else {
@@ -614,13 +610,11 @@ void env_to_arg(char *src, char *dst) {
void parse_sys_envs(char **envs) {
struct option *lopt, *aopt;
char **uenvs = envs;
char *earg, *eq_pos;
while(*uenvs) {
if (!strncmp(*uenvs, "UWSGI_", 6)) {
if (!strncmp(*uenvs, "UWSGI_", 6) && strncmp(*uenvs, "UWSGI_RELOADS=",14)) {
earg = uwsgi_malloc(strlen(*uenvs+6)+1);
env_to_arg(*uenvs+6, earg);
eq_pos = strchr(earg, '=');
@@ -629,27 +623,7 @@ void parse_sys_envs(char **envs) {
}
eq_pos[0] = 0;
lopt = uwsgi.long_options;
while ((aopt = lopt)) {
if (!aopt->name)
break;
if (!strcmp(earg, aopt->name)) {
if (aopt->flag) {
*aopt->flag = aopt->val;
}
else {
if (eq_pos[1] != 0) {
manage_opt(aopt->val, eq_pos+1);
}
else {
manage_opt(aopt->val, NULL);
}
}
}
lopt++;
}
add_exported_option(earg, eq_pos+1, 0);
}
uenvs++;
}
@@ -1173,37 +1147,7 @@ end:
return 0;
}
void add_exported_option(int i, char *value) {
char *key = NULL;
struct option *lopt, *aopt;
if (i == 0) {
key = value;
value = NULL;
}
else {
lopt = uwsgi.long_options;
while ((aopt = lopt)) {
if (!aopt->name)
break;
if (aopt->val == 0 && *aopt->flag == i) {
key = (char *) aopt->name;
break;
}
if (aopt->val == i) {
key = (char *) aopt->name;
break;
}
lopt++;
}
}
//uwsgi_log("%s = %s\n", key, value);
if (!key) return;
void add_exported_option(char *key, char *value, int configured) {
if (!uwsgi.exported_opts) {
uwsgi.exported_opts = uwsgi_malloc(sizeof(struct uwsgi_opt*));
@@ -1216,10 +1160,10 @@ void add_exported_option(int i, char *value) {
}
}
uwsgi.exported_opts[uwsgi.exported_opts_cnt] = uwsgi_malloc(sizeof(struct uwsgi_opt));
uwsgi.exported_opts[uwsgi.exported_opts_cnt]->key = key;
uwsgi.exported_opts[uwsgi.exported_opts_cnt]->value = value;
uwsgi.exported_opts[uwsgi.exported_opts_cnt]->configured = configured;
uwsgi.exported_opts_cnt++;
}
@@ -1489,6 +1433,7 @@ void init_magic_table(char *magic_table[]) {
}
magic_table['%'] = "%";
magic_table['('] = "%(";
}
char *uwsgi_get_last_char(char *what, char c) {
@@ -1654,3 +1599,16 @@ void uwsgi_unix_signal(int signum, void (*func)(int)) {
uwsgi_error("sigaction()");
}
}
char *uwsgi_get_exported_opt(char *key) {
int i;
for (i = 0; i < uwsgi.exported_opts_cnt; i++) {
if (!strcmp(uwsgi.exported_opts[i]->key, key)) {
return uwsgi.exported_opts[i]->value;
}
}
return NULL;
}
+186 -75
View File
@@ -160,6 +160,7 @@ static struct option long_base_options[] = {
{"plugins", required_argument, 0, LONG_ARGS_PLUGINS},
{"remap-modifier", required_argument, 0, LONG_ARGS_REMAP_MODIFIER},
{"dump-options", no_argument, &uwsgi.dump_options, 1},
{"show-config", no_argument, &uwsgi.show_config, 1},
{"print", required_argument, 0, LONG_ARGS_PRINT},
{"version", no_argument, 0, LONG_ARGS_VERSION},
{0, 0, 0, 0}
@@ -194,16 +195,16 @@ void gracefully_kill(int signum)
if (UWSGI_IS_IN_REQUEST) {
uwsgi.workers[uwsgi.mywid].manage_next_request = 0;
} else {
reload_me();
reload_me(0);
}
}
void reload_me()
void reload_me(int signum)
{
exit(UWSGI_RELOAD_CODE);
}
void end_me()
void end_me(int signum)
{
exit(UWSGI_END_CODE);
}
@@ -214,7 +215,7 @@ void goodbye_cruel_world()
exit(0);
}
void kill_them_all()
void kill_them_all(int signum)
{
int i;
uwsgi.to_hell = 1;
@@ -266,18 +267,18 @@ void grace_them_all(int signum)
void uwsgi_nuclear_blast() {
if (!uwsgi.workers) {
reap_them_all();
reap_them_all(0);
}
else if (uwsgi.master_process) {
if (getpid() == uwsgi.workers[0].pid) {
reap_them_all();
reap_them_all(0);
}
}
exit(1);
}
void reap_them_all()
void reap_them_all(int signum)
{
int i;
uwsgi.to_heaven = 1;
@@ -312,7 +313,7 @@ void harakiri()
exit(0);
}
void stats()
void stats(int signum)
{
//fix this for better logging(this cause races)
struct uwsgi_app *ua = NULL;
@@ -425,7 +426,7 @@ static void vacuum(void)
int main(int argc, char *argv[], char *envp[])
{
int i;
int i, j;
int rlen;
FILE *pidfile;
@@ -584,21 +585,14 @@ int main(int argc, char *argv[], char *envp[])
while ((i = getopt_long(argc, argv, short_options, uwsgi.long_options, &uwsgi.option_index)) != -1) {
if (i == 0) {
add_exported_option(0, (char *)uwsgi.long_options[uwsgi.option_index].name);
add_exported_option((char *)uwsgi.long_options[uwsgi.option_index].name, "1", 0);
}
else {
add_exported_option((char *)uwsgi.long_options[uwsgi.option_index].name, optarg, 1);
manage_opt(i, optarg);
}
}
if (uwsgi.dump_options) {
struct option *lopt = uwsgi.long_options;
while(lopt->name) {
uwsgi_log("--%s\n", lopt->name);
lopt++;
}
}
if (optind < argc) {
char *lazy = argv[optind];
@@ -647,10 +641,18 @@ int main(int argc, char *argv[], char *envp[])
}
}
if (gethostname(uwsgi.hostname, 255)) {
uwsgi_error("gethostname()");
}
uwsgi.hostname_len = strlen(uwsgi.hostname);
magic_table['v'] = uwsgi.cwd;
magic_table['h'] = uwsgi.hostname;
#ifdef UWSGI_XML
if (uwsgi.xml_config != NULL) {
magic_table['o'] = uwsgi.xml_config;
magic_table['v'] = uwsgi.emperor_dir;
if (uwsgi.xml_config[0] == '/') {
magic_table['p'] = uwsgi.xml_config;
}
@@ -662,12 +664,12 @@ int main(int argc, char *argv[], char *envp[])
if (uwsgi_get_last_char(uwsgi.xml_config, '.')) magic_table['e'] = uwsgi_get_last_char(uwsgi.xml_config, '.')+1;
if (uwsgi_get_last_char(magic_table['s'], '.')) magic_table['n'] = uwsgi_concat2n(magic_table['s'], uwsgi_get_last_char(magic_table['s'], '.')-magic_table['s'], "", 0) ;
uwsgi_xml_config(uwsgi.wsgi_req, 0, magic_table);
uwsgi.xml_config = magic_table['p'];
}
#endif
#ifdef UWSGI_INI
if (uwsgi.ini != NULL) {
magic_table['o'] = uwsgi.ini;
magic_table['v'] = uwsgi.emperor_dir;
if (uwsgi.ini[0] == '/') {
magic_table['p'] = uwsgi.ini;
}
@@ -685,7 +687,6 @@ int main(int argc, char *argv[], char *envp[])
#ifdef UWSGI_YAML
if (uwsgi.yaml != NULL) {
magic_table['o'] = uwsgi.yaml;
magic_table['v'] = uwsgi.emperor_dir;
if (uwsgi.yaml[0] == '/') {
magic_table['p'] = uwsgi.yaml;
}
@@ -708,12 +709,121 @@ int main(int argc, char *argv[], char *envp[])
//parse environ
parse_sys_envs(environ);
if (gethostname(uwsgi.hostname, 255)) {
uwsgi_error("gethostname()");
// second pass
for (i = 0; i < uwsgi.exported_opts_cnt; i++) {
int has_percent = 0;
char *magic_key = NULL;
char *magic_val = NULL;
if (uwsgi.exported_opts[i]->value && !uwsgi.exported_opts[i]->configured) {
for(j=0;j<(int)strlen(uwsgi.exported_opts[i]->value);j++) {
if (uwsgi.exported_opts[i]->value[j] == '%') {
has_percent = 1;
}
else if (uwsgi.exported_opts[i]->value[j] == '(' && has_percent == 1) {
has_percent = 2;
magic_key = uwsgi.exported_opts[i]->value + j + 1;
}
else if (has_percent > 1) {
if (uwsgi.exported_opts[i]->value[j] == ')') {
if (has_percent <= 2) {
magic_key = NULL;
has_percent = 0;
continue;
}
#ifdef UWSGI_DEBUG
uwsgi_log("need to interpret the %.*s tag\n", has_percent-2, magic_key);
#endif
char *tmp_magic_key = uwsgi_concat2n(magic_key, has_percent-2, "", 0);
magic_val = uwsgi_get_exported_opt(tmp_magic_key);
free(tmp_magic_key);
if (!magic_val) {
magic_key = NULL;
has_percent = 0;
continue;
}
uwsgi.exported_opts[i]->value = uwsgi_concat4n(
uwsgi.exported_opts[i]->value, (magic_key-2) - uwsgi.exported_opts[i]->value,
magic_val, strlen(magic_val),
magic_key + (has_percent-1),
strlen(magic_key + (has_percent-1)), "", 0);
#ifdef UWSGI_DEBUG
uwsgi_log("computed new value = %s\n", uwsgi.exported_opts[i]->value);
#endif
magic_key = NULL;
has_percent = 0;
}
else {
has_percent++;
}
}
else {
has_percent = 0;
}
}
}
}
uwsgi.hostname_len = strlen(uwsgi.hostname);
// ok, the options dictionary is available, lets manage it
struct option *lopt = uwsgi.long_options;
struct option *aopt;
char *val;
for(i=0;i<uwsgi.exported_opts_cnt;i++) {
if (uwsgi.exported_opts[i]->configured) continue;
lopt = uwsgi.long_options;;
while ((aopt = lopt)) {
if (!aopt->name) break;
if (!strcmp(aopt->name, uwsgi.exported_opts[i]->key)) {
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++;
}
}
/* uWSGI IS CONFIGURED !!! */
if (uwsgi.dump_options) {
struct option *lopt = uwsgi.long_options;
while(lopt->name) {
uwsgi_log("--%s\n", lopt->name);
lopt++;
}
}
if (uwsgi.show_config) {
fprintf(stdout, "\n;uWSGI instance configuration\n[uwsgi]\n");
for(i=0;i<uwsgi.exported_opts_cnt;i++) {
if (uwsgi.exported_opts[i]->value) {
fprintf(stdout,"%s = %s\n", uwsgi.exported_opts[i]->key, uwsgi.exported_opts[i]->value);
}
else {
fprintf(stdout,"%s = true\n", uwsgi.exported_opts[i]->key);
}
}
fprintf(stdout, ";end of configuration\n\n");
}
#ifdef UWSGI_UDP
@@ -812,6 +922,7 @@ options_parsed:
if (uwsgi.ns) {
for(;;) {
char stack[PTHREAD_STACK_MIN];
int waitpid_status;
uwsgi_log("*** jailing uWSGI in %s ***\n", uwsgi.ns);
pid_t pid = clone(uwsgi_start, stack+PTHREAD_STACK_MIN, SIGCHLD|CLONE_NEWUTS|CLONE_NEWPID|CLONE_NEWIPC|CLONE_NEWNS, (void *)argv);
if (pid == -1) {
@@ -819,11 +930,17 @@ options_parsed:
exit(1);
}
uwsgi_log("waiting for jailed master (pid: %d) death...\n", (int) pid);
pid = waitpid(pid, NULL, 0);
pid = waitpid(pid, &waitpid_status, 0);
if (pid < 0) {
uwsgi_error("waitpid()");
exit(1);
}
// in Linux this is reliable
if (WIFEXITED(waitpid_status) && WEXITSTATUS(waitpid_status) == 1) {
exit(1);
}
uwsgi_log("pid %d ended. Respawning...\n", (int) pid);
}
}
@@ -880,25 +997,9 @@ int uwsgi_start(void *v_argv) {
int unmounted = 1;
char *delim0, *delim1;
while(unmounted) {
unmounted = 0;
procmounts = fopen("/proc/self/mounts", "r");
while(fgets(line,1024,procmounts) != NULL) {
delim0 = strchr(line, ' ');
delim0++;
delim1 = strchr(delim0, ' ');
*delim1 = 0;
if (!umount(delim0)) {
unmounted++;
}
}
fclose(procmounts);
}
uwsgi_log("unmounting /proc\n");
if (umount("/proc")) {
uwsgi_error("umount()");
if (chdir(uwsgi.ns)) {
uwsgi_error("chdir()");
exit(1);
}
char *ns_tmp_mountpoint = uwsgi_concat2(uwsgi.ns, "/.uwsgi_ns_tmp_mountpoint");
@@ -913,25 +1014,49 @@ int uwsgi_start(void *v_argv) {
if (chdir(ns_tmp_mountpoint)) {
uwsgi_error("chdir()");
}
if (pivot_root(".", ns_tmp_mountpoint2)) {
uwsgi_error("pivot_root()");
exit(1);
}
if (umount("/.uwsgi_ns_tmp_mountpoint")) {
uwsgi_error("umount tmp()");
if (chdir("/")) {
uwsgi_error("chdir()");
exit(1);
}
rmdir("/.uwsgi_ns_tmp_mountpoint/.uwsgi_ns_tmp_mountpoint");
rmdir("/.uwsgi_ns_tmp_mountpoint");
free(ns_tmp_mountpoint2);
free(ns_tmp_mountpoint);
uwsgi_log("remounting /proc\n");
if (mount("proc","/proc", "proc", 0, NULL)) {
uwsgi_error("mount()");
}
while(unmounted) {
unmounted = 0;
procmounts = fopen("/proc/self/mounts", "r");
while(fgets(line,1024,procmounts) != NULL) {
delim0 = strchr(line, ' ');
delim0++;
delim1 = strchr(delim0, ' ');
*delim1 = 0;
if (!strcmp(delim0,"/") || !strcmp(delim0,"/proc")) continue;
if (!umount(delim0)) {
unmounted++;
}
}
fclose(procmounts);
}
if (rmdir("/.uwsgi_ns_tmp_mountpoint/.uwsgi_ns_tmp_mountpoint")) {
uwsgi_error("rmdir()");
}
if (rmdir("/.uwsgi_ns_tmp_mountpoint")) {
uwsgi_error("rmdir()");
}
free(ns_tmp_mountpoint2);
free(ns_tmp_mountpoint);
}
#endif
@@ -1126,6 +1251,10 @@ int uwsgi_start(void *v_argv) {
// daemons table lock
uwsgi.daemon_table_lock = uwsgi_mmap_shared_lock();
uwsgi_lock_init(uwsgi.daemon_table_lock);
// cron table lock
uwsgi.cron_table_lock = uwsgi_mmap_shared_lock();
uwsgi_lock_init(uwsgi.cron_table_lock);
}
if (uwsgi.spool_dir) {
@@ -1765,11 +1894,11 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100
signal(SIGALRM, (void *) &harakiri);
}
uwsgi_unix_signal(SIGHUP, gracefully_kill);
signal(SIGINT, (void *) &end_me);
signal(SIGTERM, (void *) &reload_me);
uwsgi_unix_signal(SIGINT, end_me);
uwsgi_unix_signal(SIGTERM, reload_me);
signal(SIGUSR1, (void *) &stats);
uwsgi_unix_signal(SIGUSR1, stats);
signal(SIGUSR2, (void *) &what_i_am_doing);
@@ -1871,7 +2000,7 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100
end:
if (uwsgi.workers[uwsgi.mywid].manage_next_request == 0) {
reload_me();
reload_me(0);
} else {
goodbye_cruel_world();
}
@@ -2393,14 +2522,12 @@ end:
int j;
if (manage_base_opt(i, optarg)) {
add_exported_option( i, optarg );
return;
}
for (j = 0; j < 0xFF; j++) {
if (uwsgi.p[j]->manage_opt) {
if (uwsgi.p[j]->manage_opt(i, optarg)) {
add_exported_option( i, optarg );
return;
}
}
@@ -2409,7 +2536,6 @@ end:
for (j = 0; j < uwsgi.gp_cnt; j++) {
if (uwsgi.gp[j]->manage_opt) {
if (uwsgi.gp[j]->manage_opt(i, optarg)) {
add_exported_option( i, optarg );
return;
}
}
@@ -2661,27 +2787,12 @@ void build_options() {
void manage_string_opt(char *key, uint16_t keylen, char *val, uint16_t vallen, void *data) {
struct option *lopt, *aopt;
// never free this value
char *key2 = uwsgi_concat2n(key, keylen, "", 0);
char *val2 = uwsgi_concat2n(val, vallen, "", 0);
uwsgi_log("%s = %s\n", key2, val2);
lopt = uwsgi.long_options;
while ((aopt = lopt)) {
if (!aopt->name) break;
if (!strcmp(key2, aopt->name)) {
if (aopt->flag) {
*aopt->flag = aopt->val;
add_exported_option(0, key2);
}
else {
manage_opt(aopt->val, val2);
}
}
lopt++;
}
add_exported_option(key2, val2, 0);
}
#ifdef UWSGI_UDP
+30 -7
View File
@@ -20,6 +20,7 @@
#define MAX_GATEWAYS 64
#define MAX_DAEMONS 8
#define MAX_SUBSCRIPTIONS 8
#define MAX_CRONS 64
#ifndef UWSGI_LOAD_EMBEDDED_PLUGINS
#define UWSGI_LOAD_EMBEDDED_PLUGINS
@@ -273,6 +274,7 @@ struct uwsgi_cache_item {
struct uwsgi_opt {
char *key;
char *value;
int configured;
};
#define MAX_CLUSTER_NODES 100
@@ -721,6 +723,7 @@ struct uwsgi_server {
struct uwsgi_opt **exported_opts;
int exported_opts_cnt;
int dump_options;
int show_config;
//base for all the requests(even on async mode)
struct wsgi_request **wsgi_requests;
struct wsgi_request *wsgi_req;
@@ -976,6 +979,7 @@ struct uwsgi_server {
void *fmon_table_lock;
void *timer_table_lock;
void *rb_timer_table_lock;
void *cron_table_lock;
void *rpc_table_lock;
void *spooler_lock;
@@ -1061,6 +1065,18 @@ struct uwsgi_snmp_server_value {
};
#endif
struct uwsgi_cron {
int minute;
int hour;
int day;
int month;
int week;
time_t last_job;
uint8_t sig;
};
struct uwsgi_shared {
//vga 80 x25 specific !
@@ -1116,6 +1132,9 @@ struct uwsgi_shared {
#ifdef __linux__
struct tcp_info ti;
#endif
struct uwsgi_cron cron[MAX_CRONS];
int cron_cnt;
};
struct uwsgi_core {
@@ -1125,7 +1144,7 @@ struct uwsgi_core {
time_t harakiri;
uint64_t requests;
//uint64_t requests;
uint64_t failed_requests;
//multiple ts per - core are needed only with multiple_interpreter + threads
@@ -1164,11 +1183,11 @@ void warn_pipe(void);
void what_i_am_doing(void);
void goodbye_cruel_world(void);
void gracefully_kill(int);
void reap_them_all(void);
void kill_them_all(void);
void reap_them_all(int);
void kill_them_all(int);
void grace_them_all(int);
void reload_me(void);
void end_me(void);
void reload_me(int);
void end_me(int);
int bind_to_unix(char *, int, int, int);
int bind_to_tcp(char *, int, char *);
int bind_to_udp(char *, int, int);
@@ -1188,7 +1207,7 @@ void log_request(struct wsgi_request *);
void get_memusage(void);
void harakiri(void);
void stats(void);
void stats(int);
#ifdef UWSGI_XML
void uwsgi_xml_config(struct wsgi_request *, int, char *[]);
@@ -1367,7 +1386,7 @@ ssize_t uwsgi_sendfile(struct wsgi_request *);
void uwsgi_register_loop(char *, void *);
void *uwsgi_get_loop(char *);
void add_exported_option(int, char *);
void add_exported_option(char *, char *, int);
ssize_t uwsgi_send_empty_pkt(int , char *, uint8_t , uint8_t);
@@ -1586,3 +1605,7 @@ struct uwsgi_rb_timer *uwsgi_min_rb_timer(struct rb_root *);
void uwsgi_nuclear_blast();
void uwsgi_unix_signal(int, void (*)(int));
char *uwsgi_get_exported_opt(char *);
int uwsgi_signal_add_cron(uint8_t, int, int, int, int, int);
+9
View File
@@ -0,0 +1,9 @@
[uwsgi]
trac = trac.web.main
id = myapp
socket = /tmp/%(id).sock
env = TRAC_ENV=/opt/projects/%(id)
module = %(trac):dispatch_request
processes = 8
master = true
+31
View File
@@ -0,0 +1,31 @@
<uwsgi>
<id>app001</id>
<print>starting dir is %v</print>
<chdir>%v/../</chdir>
<localhost>127.0.0.1</localhost>
<socket>%(localhost):3031</socket>
<socket>/tmp/%(id).sock</socket>
<cpus>4</cpus>
<werkzeug>werkzeug.testapp:test_app</werkzeug>
<master/>
<vhost/>
<vhost-host/>
<processes>%(cpus)</processes>
<app domain="sirius001:9090">
<script>werkzeug.testapp:test_app</script>
</app>
<app domain="sirius002:9090">
<script>uwsgicc</script>
</app>
</uwsgi>
+18 -45
View File
@@ -18,12 +18,11 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, int app_tag, char *magic_ta
xmlChar *xml_uwsgi_mountpoint = NULL;
xmlChar *xml_uwsgi_domain = NULL;
xmlChar *node_mode;
struct option *lopt, *aopt;
char *colon;
char *xml_id;
int i;
char *xml_id;
char *xml_content;
int xml_size = 0;
@@ -105,52 +104,26 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, int app_tag, char *magic_ta
continue;
}
#endif
lopt = uwsgi.long_options;
while ((aopt = lopt)) {
if (!aopt->name)
break;
if (!strcmp((char *) node->name, aopt->name)) {
if (!node->children && aopt->has_arg) {
uwsgi_log( "[uWSGI] %s option need a value. skip.\n", aopt->name);
exit(1);
}
if (node->children) {
if (!node->children->content && aopt->has_arg) {
uwsgi_log( "[uWSGI] %s option need a value. skip.\n", aopt->name);
exit(1);
}
}
node_mode = xmlGetProp(node, (const xmlChar *) "mode");
if (uwsgi.mode && node_mode) {
if (strcmp(uwsgi.mode, (char *) node_mode)) {
continue;
}
}
node_mode = xmlGetProp(node, (const xmlChar *) "mode");
if (uwsgi.mode && node_mode) {
if (strcmp(uwsgi.mode, (char *) node_mode)) {
goto next;
}
}
xml_id = (char *) xmlGetProp(node, (const xmlChar *) "id");
if (colon && xml_id) {
if (strcmp(colon, xml_id)) {
continue;
}
}
xml_id = (char *) xmlGetProp(node, (const xmlChar *) "id");
if (colon && xml_id) {
if (strcmp(colon, xml_id)) {
goto next;
}
}
if (aopt->flag) {
*aopt->flag = aopt->val;
add_exported_option(0, (char *) node->name);
}
else {
if (node->children) {
manage_opt(aopt->val, (char *) node->children->content);
}
else {
manage_opt(aopt->val, NULL);
}
}
}
next:
lopt++;
if (node->children) {
add_exported_option((char *) node->name, (char *) node->children->content, 0);
}
else {
add_exported_option((char *) node->name, "1", 0);
}
}
}
+1 -27
View File
@@ -101,7 +101,6 @@ void uwsgi_yaml_config(char *file, char *magic_table[]) {
int lines = 1;
struct option *lopt, *aopt;
char *section_asked = "uwsgi";
char *colon;
@@ -171,32 +170,7 @@ void uwsgi_yaml_config(char *file, char *magic_table[]) {
//uwsgi_log("YAML: %s = %s\n", key, val);
lopt = uwsgi.long_options;
while ((aopt = lopt)) {
if (!aopt->name)
break;
if (!strcmp(key, aopt->name)) {
if (aopt->flag) {
*aopt->flag = aopt->val;
add_exported_option(0, (char *)key);
}
else {
if (aopt->has_arg == optional_argument) {
if (!strcmp("true", val)) {
val = NULL;
}
}
if (aopt->has_arg == no_argument) {
if (!strcmp("false", val) || val[0] == '0') {
lopt++;
continue;
}
}
manage_opt(aopt->val, val);
}
}
lopt++;
}
add_exported_option((char *)key, val, 0);
}
next:
len -= (yaml_line - yaml);