From ff8ca18e8f3bb402a99c4392c263a9eb3b397907 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Sat, 29 Jun 2013 21:57:10 +0200 Subject: [PATCH] added --emperor-nofollow --- core/emperor.c | 84 +++++++++++++++++++++++++++++++++++++------------- core/uwsgi.c | 1 + uwsgi.h | 1 + 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/core/emperor.c b/core/emperor.c index 744afcf3..a7c95b88 100644 --- a/core/emperor.c +++ b/core/emperor.c @@ -234,11 +234,18 @@ void uwsgi_imperial_monitor_directory(struct uwsgi_emperor_scanner *ues) { if (!uwsgi_emperor_is_valid(de->d_name)) continue; - if (stat(de->d_name, &st)) - continue; - - if (!S_ISREG(st.st_mode)) - continue; + if (uwsgi.emperor_nofollow) { + if (lstat(de->d_name, &st)) + continue; + if (!S_ISLNK(st.st_mode) && !S_ISREG(st.st_mode)) + continue; + } + else { + if (stat(de->d_name, &st)) + continue; + if (!S_ISREG(st.st_mode)) + continue; + } ui_current = emperor_get(de->d_name); @@ -294,16 +301,30 @@ void uwsgi_imperial_monitor_directory(struct uwsgi_emperor_scanner *ues) { else { char *filename = uwsgi_calloc(0xff); memcpy(filename, c_ui->name, colon - c_ui->name); - if (stat(filename, &st)) { - emperor_stop(c_ui); + if (uwsgi.emperor_nofollow) { + if (lstat(filename, &st)) { + emperor_stop(c_ui); + } + } + else { + if (stat(filename, &st)) { + emperor_stop(c_ui); + } } free(filename); } } else { - if (stat(c_ui->name, &st)) { - emperor_stop(c_ui); - } + if (uwsgi.emperor_nofollow) { + if (lstat(c_ui->name, &st)) { + emperor_stop(c_ui); + } + } + else { + if (stat(c_ui->name, &st)) { + emperor_stop(c_ui); + } + } } } c_ui = c_ui->ui_next; @@ -328,11 +349,18 @@ void uwsgi_imperial_monitor_glob(struct uwsgi_emperor_scanner *ues) { if (!uwsgi_emperor_is_valid(g.gl_pathv[i])) continue; - if (stat(g.gl_pathv[i], &st)) - continue; - - if (!S_ISREG(st.st_mode)) - continue; + if (uwsgi.emperor_nofollow) { + if (lstat(g.gl_pathv[i], &st)) + continue; + if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode)) + continue; + } + else { + if (stat(g.gl_pathv[i], &st)) + continue; + if (!S_ISREG(st.st_mode)) + continue; + } ui_current = emperor_get(g.gl_pathv[i]); @@ -389,16 +417,30 @@ void uwsgi_imperial_monitor_glob(struct uwsgi_emperor_scanner *ues) { else { char *filename = uwsgi_calloc(0xff); memcpy(filename, c_ui->name, colon - c_ui->name); - if (stat(filename, &st)) { - emperor_stop(c_ui); - } + if (uwsgi.emperor_nofollow) { + if (lstat(filename, &st)) { + emperor_stop(c_ui); + } + } + else { + if (stat(filename, &st)) { + emperor_stop(c_ui); + } + } free(filename); } } else { - if (stat(c_ui->name, &st)) { - emperor_stop(c_ui); - } + if (uwsgi.emperor_nofollow) { + if (lstat(c_ui->name, &st)) { + emperor_stop(c_ui); + } + } + else { + if (stat(c_ui->name, &st)) { + emperor_stop(c_ui); + } + } } } c_ui = c_ui->ui_next; diff --git a/core/uwsgi.c b/core/uwsgi.c index 50a63e9a..7028826a 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -171,6 +171,7 @@ static struct uwsgi_option uwsgi_base_options[] = { {"master", no_argument, 'M', "enable master process", uwsgi_opt_true, &uwsgi.master_process, 0}, {"honour-stdin", no_argument, 0, "do not remap stdin to /dev/null", uwsgi_opt_true, &uwsgi.honour_stdin, 0}, {"emperor", required_argument, 0, "run the Emperor", uwsgi_opt_add_string_list, &uwsgi.emperor, 0}, + {"emperor-nofollow", no_argument, 0, "do not follow symlinks when checking for mtime", uwsgi_opt_true, &uwsgi.emperor_nofollow, 0}, {"emperor-procname", required_argument, 0, "set the Emperor process name", uwsgi_opt_set_str, &uwsgi.emperor_procname, 0}, {"emperor-freq", required_argument, 0, "set the Emperor scan frequency (default 3 seconds)", uwsgi_opt_set_int, &uwsgi.emperor_freq, 0}, {"emperor-required-heartbeat", required_argument, 0, "set the Emperor tolerance about heartbeats", uwsgi_opt_set_int, &uwsgi.emperor_heartbeat, 0}, diff --git a/uwsgi.h b/uwsgi.h index 6299d1ac..15278197 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1672,6 +1672,7 @@ struct uwsgi_server { char *emperor_procname; int emperor_fd; int emperor_queue; + int emperor_nofollow; int emperor_tyrant; int emperor_tyrant_nofollow; int emperor_fd_config;