diff --git a/emperor.c b/emperor.c index 7b61669b..01bb28f4 100644 --- a/emperor.c +++ b/emperor.c @@ -122,9 +122,10 @@ void emperor_add(char *name, time_t born, char *config, uint32_t config_size) { struct uwsgi_instance *c_ui = ui; struct uwsgi_instance *n_ui = NULL; pid_t pid; - char *argv[4]; + char **argv; char *uef; char **uenvs; + int counter; while (c_ui->ui_next) { c_ui = c_ui->ui_next; @@ -233,7 +234,14 @@ void emperor_add(char *name, time_t born, char *config, uint32_t config_size) { close(n_ui->pipe_config[0]); } + counter = 4; + struct uwsgi_config_template *uct = uwsgi.vassals_templates; + while(uct) { + counter+=2; + uct = uct->next; + } + argv = uwsgi_malloc(sizeof(char *) * counter); // set args argv[0] = uwsgi.binary_path; if (!strcmp(name + (strlen(name) - 4), ".xml")) @@ -247,7 +255,15 @@ void emperor_add(char *name, time_t born, char *config, uint32_t config_size) { if (!strcmp(name + (strlen(name) - 3), ".js")) argv[1] = "--json"; argv[2] = name; - argv[3] = NULL; + counter = 3; + uct = uwsgi.vassals_templates; + while(uct) { + argv[counter] = "--inherit"; + argv[counter+1] = uct->filename; + counter+=2; + uct = uct->next; + } + argv[counter] = NULL; // start !!! if (execvp(argv[0], argv)) { uwsgi_error("execvp()"); @@ -341,6 +357,8 @@ reconnect: ui = &ui_base; + int freq = 0 ; + for (;;) { @@ -351,7 +369,8 @@ reconnect: } } - nevents = event_queue_wait_multi(emperor_queue, 3, events, 64); + nevents = event_queue_wait_multi(emperor_queue, freq, events, 64); + freq = 3; for (i = 0; ifilename); +#ifdef UWSGI_XML + if (!strcmp(uct->filename+strlen(uct->filename)-4, ".xml")) { + uwsgi_xml_config(uct->filename, uwsgi.wsgi_req, 0, magic_table); + } +#endif +#ifdef UWSGI_INI + if (!strcmp(uct->filename+strlen(uct->filename)-4, ".ini")) { + uwsgi_ini_config(uct->filename, magic_table); + } +#endif +#ifdef UWSGI_YAML + if (!strcmp(uct->filename+strlen(uct->filename)-4, ".yml")) { + uwsgi_yaml_config(uct->filename, magic_table); + } + if (!strcmp(uct->filename+strlen(uct->filename)-5, ".yaml")) { + uwsgi_yaml_config(uct->filename, magic_table); + } +#endif +#ifdef UWSGI_JSON + if (!strcmp(uct->filename+strlen(uct->filename)-3, ".js")) { + uwsgi_json_config(uct->filename, magic_table); + } +#endif + uct = uct->next; + } // second pass for (i = 0; i < uwsgi.exported_opts_cnt; i++) { @@ -2010,7 +2014,7 @@ uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100 /*parse xml for tags */ #ifdef UWSGI_XML if (uwsgi.xml_round2 && uwsgi.xml_config != NULL) { - uwsgi_xml_config(uwsgi.wsgi_req, 1, NULL); + uwsgi_xml_config(uwsgi.xml_config, uwsgi.wsgi_req, 1, NULL); } #endif @@ -2443,6 +2447,7 @@ end: char *p; struct uwsgi_static_map *usm, *old_usm; + struct uwsgi_config_template *uct, *old_uct; switch (i) { @@ -2646,6 +2651,48 @@ end: uwsgi.file_serve_mode = 1; } return 1; + case LONG_ARGS_INHERIT: + uct = uwsgi.config_templates; + if (!uct) { + uct = uwsgi_malloc(sizeof(struct uwsgi_config_template)); + uwsgi.config_templates = uct; + } + else { + old_uct = uct; + while(uct->next) { + uct = uct->next; + old_uct = uct; + } + + old_uct->next = uwsgi_malloc(sizeof(struct uwsgi_config_template)); + uct = old_uct->next; + } + + uct->filename = optarg; + uct->next = NULL; + + return 1; + case LONG_ARGS_VASSALS_INHERIT: + uct = uwsgi.vassals_templates; + if (!uct) { + uct = uwsgi_malloc(sizeof(struct uwsgi_config_template)); + uwsgi.vassals_templates = uct; + } + else { + old_uct = uct; + while(uct->next) { + uct = uct->next; + old_uct = uct; + } + + old_uct->next = uwsgi_malloc(sizeof(struct uwsgi_config_template)); + uct = old_uct->next; + } + + uct->filename = optarg; + uct->next = NULL; + + return 1; case LONG_ARGS_STATIC_MAP: usm = uwsgi.static_maps; if (!usm) { diff --git a/uwsgi.h b/uwsgi.h index 058113cc..b51aee37 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -226,6 +226,11 @@ struct uwsgi_help_item { char *value; }; +struct uwsgi_config_template { + char *filename; + struct uwsgi_config_template *next; +}; + struct uwsgi_static_map { char *mountpoint; @@ -414,6 +419,8 @@ struct uwsgi_opt { #define LONG_ARGS_EMPEROR_AMQP_PASSWORD 17098 #define LONG_ARGS_PROTOCOL 17099 #define LONG_ARGS_ZEROMQ 17100 +#define LONG_ARGS_INHERIT 17101 +#define LONG_ARGS_VASSALS_INHERIT 17102 #define UWSGI_OK 0 @@ -827,6 +834,7 @@ struct uwsgi_server { int emperor_fd_config; char *emperor_dir; pid_t emperor_pid; + struct uwsgi_config_template *vassals_templates; int loyal; char *emperor_amqp_vhost; @@ -1019,6 +1027,8 @@ struct uwsgi_server { char *ini; #endif + struct uwsgi_config_template *config_templates; + int single_interpreter; struct uwsgi_shared *shared; @@ -1379,7 +1389,7 @@ void harakiri(void); void stats(int); #ifdef UWSGI_XML -void uwsgi_xml_config(struct wsgi_request *, int, char *[]); +void uwsgi_xml_config(char *, struct wsgi_request *, int, char *[]); #endif void internal_server_error(int, char *); diff --git a/vassals/multi.xml b/vassals/multi.xml index ae9a0e45..9f7d5a62 100644 --- a/vassals/multi.xml +++ b/vassals/multi.xml @@ -7,8 +7,8 @@ %v/../ 127.0.0.1 - %(localhost):3031 - /tmp/%(id).sock + %(localhost):3039 + /tmp/%(id).sock2 4 werkzeug.testapp:test_app diff --git a/xmlconf.c b/xmlconf.c index 0d2b81af..39c028d8 100644 --- a/xmlconf.c +++ b/xmlconf.c @@ -9,7 +9,7 @@ extern struct uwsgi_server uwsgi; #include #include -void uwsgi_xml_config(struct wsgi_request *wsgi_req, int app_tag, char *magic_table[]) { +void uwsgi_xml_config(char *filename, struct wsgi_request *wsgi_req, int app_tag, char *magic_table[]) { xmlDoc *doc = NULL; xmlNode *element = NULL; xmlNode *node = NULL; @@ -26,12 +26,12 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, int app_tag, char *magic_ta char *xml_content; int xml_size = 0; - if (!uwsgi_startswith(uwsgi.xml_config, "http://", 7)) { - colon = uwsgi_get_last_char(uwsgi.xml_config, '/'); + if (!uwsgi_startswith(filename, "http://", 7)) { + colon = uwsgi_get_last_char(filename, '/'); colon = uwsgi_get_last_char(colon, ':'); } else { - colon = uwsgi_get_last_char(uwsgi.xml_config, ':'); + colon = uwsgi_get_last_char(filename, ':'); } if (colon) { colon[0] = 0; @@ -43,16 +43,16 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, int app_tag, char *magic_ta uwsgi_log( "[uWSGI] using xml uwsgi id: %s\n", colon); } - xml_content = uwsgi_open_and_read(uwsgi.xml_config, &xml_size, 0, magic_table); + xml_content = uwsgi_open_and_read(filename, &xml_size, 0, magic_table); - doc = xmlReadMemory(xml_content, xml_size, uwsgi.xml_config, NULL, 0); + doc = xmlReadMemory(xml_content, xml_size, filename, NULL, 0); if (doc == NULL) { - uwsgi_log( "[uWSGI] could not parse file %s.\n", uwsgi.xml_config); + uwsgi_log( "[uWSGI] could not parse file %s.\n", filename); exit(1); } if (!app_tag) { - uwsgi_log( "[uWSGI] parsing config file %s\n", uwsgi.xml_config); + uwsgi_log( "[uWSGI] parsing config file %s\n", filename); } element = xmlDocGetRootElement(doc);