From 4492bf517b378c845935156a2d666dbf509b678d Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Mon, 16 Jul 2012 12:12:47 +0200 Subject: [PATCH] added --privileged-binary-patch-arg and --unprivileged-binary-patch-arg --- core/utils.c | 15 +++++++++++++++ core/uwsgi.c | 16 ++++++++++------ uwsgi.h | 4 ++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/core/utils.c b/core/utils.c index 52142dca..063fc5ad 100644 --- a/core/utils.c +++ b/core/utils.c @@ -737,6 +737,10 @@ void uwsgi_as_root() { uwsgi_error("execvp()"); exit(1); } + + if (uwsgi.unprivileged_binary_patch_arg) { + uwsgi_exec_command_with_args(uwsgi.unprivileged_binary_patch_arg); + } } else { if (uwsgi.chroot && !uwsgi.is_a_reload) { @@ -3375,6 +3379,17 @@ void uwsgi_sig_pause() { sigsuspend(&mask); } +void uwsgi_exec_command_with_args(char *cmdline) { + char *argv[4]; + argv[0] = "/bin/sh"; + argv[1] = "-c"; + argv[2] = cmdline; + argv[3] = NULL; + execvp(argv[0], argv); + uwsgi_error("execvp()"); + exit(1); +} + int uwsgi_run_command_and_wait(char *command, char *arg) { char *argv[4]; diff --git a/core/uwsgi.c b/core/uwsgi.c index c07c6839..b0f06c52 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -2013,12 +2013,16 @@ int main(int argc, char *argv[], char *envp[]) { } // we could now patch the binary - if (uwsgi.privileged_binary_patch) { - uwsgi.argv[0] = uwsgi.privileged_binary_patch; - execvp(uwsgi.privileged_binary_patch, uwsgi.argv); - uwsgi_error("execvp()"); - exit(1); - } + if (uwsgi.privileged_binary_patch) { + uwsgi.argv[0] = uwsgi.privileged_binary_patch; + execvp(uwsgi.privileged_binary_patch, uwsgi.argv); + uwsgi_error("execvp()"); + exit(1); + } + + if (uwsgi.privileged_binary_patch_arg) { + uwsgi_exec_command_with_args(uwsgi.privileged_binary_patch_arg); + } diff --git a/uwsgi.h b/uwsgi.h index bc787ceb..d0a26439 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1351,6 +1351,8 @@ struct uwsgi_server { char *privileged_binary_patch; char *unprivileged_binary_patch; + char *privileged_binary_patch_arg; + char *unprivileged_binary_patch_arg; struct uwsgi_logger *loggers; struct uwsgi_logger *choosen_logger; @@ -3141,6 +3143,8 @@ void emperor_stop(struct uwsgi_instance *); void emperor_respawn(struct uwsgi_instance *, time_t); void emperor_add(struct uwsgi_emperor_scanner *, char *, time_t, char *, uint32_t, uid_t, gid_t); +void uwsgi_exec_command_with_args(char *); + #ifdef UWSGI_AS_SHARED_LIBRARY int uwsgi_init(int, char **, char **); #endif