Introduce uwsgi.binary_argc

If more than uwsgi.binary_path is needed to make uWSGI self-referential on
reload, plugins can use this field to skip processing of N initial arguments.

eg. if uWSGI is embedded in a host application or interpreter::

    python -B -E -m uwsgi --socket=:8000 --show-config [...]

argv[1:5] are intended for Python, and not for processing by uWSGI, even though
uWSGI might want to manage it (process name). The arguments also cannot just be
ignored because they are crucial for proper reloads.
This commit is contained in:
C Anthony Risinger
2015-09-17 03:47:45 -05:00
parent d08275ea12
commit 849a85b250
2 changed files with 28 additions and 0 deletions
+25
View File
@@ -62,6 +62,7 @@ void uwsgi_init_default() {
uwsgi.cpus = 1;
uwsgi.new_argc = -1;
uwsgi.binary_argc = 1;
uwsgi.backtrace_depth = 64;
uwsgi.max_apps = 64;
@@ -261,11 +262,33 @@ void uwsgi_commandline_config() {
int argc = uwsgi.argc;
char **argv = uwsgi.argv;
// we might want to ignore some arguments not meant for us
char binary_argv0_pretty[256] = {'\0'};
char *binary_argv0_actual = NULL;
if (uwsgi.new_argc > -1 && uwsgi.new_argv) {
argc = uwsgi.new_argc;
argv = uwsgi.new_argv;
}
if (uwsgi.binary_argc > 1 && argc >= uwsgi.binary_argc) {
char *pretty = (char *)binary_argv0_pretty;
strncat(pretty, argv[0], 255);
for (i = 1; i < uwsgi.binary_argc; i++) {
if (strlen(pretty) + 1 + strlen(argv[i]) + 1 > 256)
break;
strcat(pretty, " ");
strcat(pretty, argv[i]);
}
argc -= uwsgi.binary_argc - 1;
argv += uwsgi.binary_argc - 1;
binary_argv0_actual = argv[0];
argv[0] = (char *)binary_argv0_pretty;
}
char *optname;
while ((i = getopt_long(argc, argv, uwsgi.short_options, uwsgi.long_options, &uwsgi.option_index)) != -1) {
@@ -289,6 +312,8 @@ void uwsgi_commandline_config() {
add_exported_option(optname, optarg, 0);
}
if (binary_argv0_actual != NULL)
argv[0] = binary_argv0_actual;
#ifdef UWSGI_DEBUG
uwsgi_log("optind:%d argc:%d\n", optind, uwsgi.argc);
+3
View File
@@ -2811,6 +2811,9 @@ struct uwsgi_server {
int spooler_signal_as_task;
int log_worker;
// number of args to consider part of binary_path
int binary_argc;
};
struct uwsgi_rpc {