From 91b14e0b341cebda60846dfa2363fb32ef5b1d14 Mon Sep 17 00:00:00 2001 From: Unbit Date: Wed, 6 Mar 2013 19:13:32 +0100 Subject: [PATCH] improved broodlord mode --- core/emperor.c | 52 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/core/emperor.c b/core/emperor.c index 150ef141..219982d2 100644 --- a/core/emperor.c +++ b/core/emperor.c @@ -185,8 +185,24 @@ void uwsgi_imperial_monitor_directory(struct uwsgi_emperor_scanner *ues) { while (c_ui) { if (c_ui->scanner == ues) { - if (stat(c_ui->name, &st)) { - emperor_stop(c_ui); + if (c_ui->zerg) { + char *colon = strrchr(c_ui->name, ':'); + if (!colon) { + emperor_stop(c_ui); + } + else { + char *filename = uwsgi_calloc(0xff); + memcpy(filename, c_ui->name, colon - c_ui->name); + if (stat(filename, &st)) { + emperor_stop(c_ui); + } + free(filename); + } + } + else { + if (stat(c_ui->name, &st)) { + emperor_stop(c_ui); + } } } c_ui = c_ui->ui_next; @@ -245,9 +261,25 @@ void uwsgi_imperial_monitor_glob(struct uwsgi_emperor_scanner *ues) { while (c_ui) { if (c_ui->scanner == ues) { - if (stat(c_ui->name, &st)) { - emperor_stop(c_ui); - } + if (c_ui->zerg) { + char *colon = strrchr(c_ui->name, ':'); + if (!colon) { + emperor_stop(c_ui); + } + else { + char *filename = uwsgi_calloc(0xff); + memcpy(filename, c_ui->name, colon - c_ui->name); + if (stat(filename, &st)) { + emperor_stop(c_ui); + } + free(filename); + } + } + else { + if (stat(c_ui->name, &st)) { + emperor_stop(c_ui); + } + } } c_ui = c_ui->ui_next; } @@ -601,6 +633,16 @@ void emperor_add(struct uwsgi_emperor_scanner *ues, char *name, time_t born, cha } free(uef); + // add UWSGI_BROODLORD_NUM + if (n_ui->zerg) { + uef = uwsgi_num2str(uwsgi.emperor_broodlord_count); + if (setenv("UWSGI_BROODLORD_NUM", uef, 1)) { + uwsgi_error("setenv()"); + exit(1); + } + free(uef); + } + if (n_ui->use_config) { uef = uwsgi_num2str(n_ui->pipe_config[1]); if (setenv("UWSGI_EMPEROR_FD_CONFIG", uef, 1)) {