diff --git a/core/init.c b/core/init.c index 927c3dd1..ce888b01 100644 --- a/core/init.c +++ b/core/init.c @@ -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); diff --git a/uwsgi.h b/uwsgi.h index 583b42c4..77c3434d 100755 --- a/uwsgi.h +++ b/uwsgi.h @@ -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 {