mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 05:31:44 +00:00
prepare for more emperor hooks
This commit is contained in:
@@ -859,6 +859,18 @@ int uwsgi_emperor_vassal_start(struct uwsgi_instance *n_ui) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// once the config is sent we can run hooks (they can fail)
|
||||
// exec hooks have access to all of the currently defined vars + UWSGI_VASSAL_PID, UWSGI_VASSAL_UID, UWSGI_VASSAL_GID, UWSGI_VASSAL_CONFIG
|
||||
struct uwsgi_string_list *usl;
|
||||
uwsgi_foreach(usl, uwsgi.exec_as_emperor) {
|
||||
uwsgi_log("running \"%s\" (as-emperor for vassal \"%s\" pid: %d uid: %d gid: %d)...\n", usl->value, n_ui->name, n_ui->pid, n_ui->uid, n_ui->gid);
|
||||
int ret = uwsgi_run_command_putenv_and_wait(NULL, usl->value, NULL, 0);
|
||||
uwsgi_log("command \"%s\" exited with code: %d\n", usl->value, ret);
|
||||
}
|
||||
// 4 call hooks
|
||||
// config / config + pid / config + pid + uid + gid
|
||||
// call
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
|
||||
+49
-15
@@ -2014,23 +2014,9 @@ void uwsgi_exec_command_with_args(char *cmdline) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int uwsgi_run_command_and_wait(char *command, char *arg) {
|
||||
static int uwsgi_run_command_do(char *command, char *arg) {
|
||||
|
||||
char *argv[4];
|
||||
int waitpid_status = 0;
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pid > 0) {
|
||||
if (waitpid(pid, &waitpid_status, 0) < 0) {
|
||||
uwsgi_error("waitpid()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return WEXITSTATUS(waitpid_status);
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0)) {
|
||||
@@ -2058,6 +2044,54 @@ int uwsgi_run_command_and_wait(char *command, char *arg) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int uwsgi_run_command_and_wait(char *command, char *arg) {
|
||||
|
||||
int waitpid_status = 0;
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pid > 0) {
|
||||
if (waitpid(pid, &waitpid_status, 0) < 0) {
|
||||
uwsgi_error("uwsgi_run_command_and_wait()/waitpid()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return WEXITSTATUS(waitpid_status);
|
||||
}
|
||||
return uwsgi_run_command_do(command, arg);
|
||||
}
|
||||
|
||||
int uwsgi_run_command_putenv_and_wait(char *command, char *arg, char **envs, unsigned int nenvs) {
|
||||
|
||||
int waitpid_status = 0;
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pid > 0) {
|
||||
if (waitpid(pid, &waitpid_status, 0) < 0) {
|
||||
uwsgi_error("uwsgi_run_command_and_wait()/waitpid()");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return WEXITSTATUS(waitpid_status);
|
||||
}
|
||||
|
||||
unsigned int i;
|
||||
for(i=0;i<nenvs;i++) {
|
||||
if (putenv(envs[i])) {
|
||||
uwsgi_error("uwsgi_run_command_putenv_and_wait()/putenv()");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
return uwsgi_run_command_do(command, arg);
|
||||
}
|
||||
|
||||
|
||||
pid_t uwsgi_run_command(char *command, int *stdin_fd, int stdout_fd) {
|
||||
|
||||
char *argv[4];
|
||||
|
||||
@@ -313,6 +313,7 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"exec-post-app", required_argument, 0, "run the specified command after app loading", uwsgi_opt_add_string_list, &uwsgi.exec_post_app, 0},
|
||||
|
||||
{"exec-as-vassal", required_argument, 0, "run the specified command before exec()ing the vassal", uwsgi_opt_add_string_list, &uwsgi.exec_as_vassal, 0},
|
||||
{"exec-as-emperor", required_argument, 0, "run the specified command in the emperor after the vassal has been started", uwsgi_opt_add_string_list, &uwsgi.exec_as_emperor, 0},
|
||||
|
||||
{"wait-for-interface", required_argument, 0, "wait for the specified network interface to come up before running root hooks", uwsgi_opt_add_string_list, &uwsgi.wait_for_interface, 0},
|
||||
{"wait-for-interface-timeout", required_argument, 0, "set the timeout for wait-for-interface", uwsgi_opt_set_int, &uwsgi.wait_for_interface_timeout, 0},
|
||||
@@ -339,6 +340,11 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
{"call-as-vassal1", required_argument, 0, "call the specified function(char *) before exec()ing the vassal", uwsgi_opt_add_string_list, &uwsgi.call_as_vassal1, 0},
|
||||
{"call-as-vassal3", required_argument, 0, "call the specified function(char *, uid_t, gid_t) before exec()ing the vassal", uwsgi_opt_add_string_list, &uwsgi.call_as_vassal3, 0},
|
||||
|
||||
{"call-as-emperor", required_argument, 0, "call the specified function() in the emperor after the vassal has been started", uwsgi_opt_add_string_list, &uwsgi.call_as_emperor, 0},
|
||||
{"call-as-emperor1", required_argument, 0, "call the specified function(char *) in the emperor after the vassal has been started", uwsgi_opt_add_string_list, &uwsgi.call_as_emperor1, 0},
|
||||
{"call-as-emperor2", required_argument, 0, "call the specified function(char *, pid_t) in the emperor after the vassal has been started", uwsgi_opt_add_string_list, &uwsgi.call_as_emperor2, 0},
|
||||
{"call-as-emperor4", required_argument, 0, "call the specified function(char *, pid_t, uid_t, gid_t) in the emperor after the vassal has been started", uwsgi_opt_add_string_list, &uwsgi.call_as_emperor4, 0},
|
||||
|
||||
|
||||
|
||||
{"ini", required_argument, 0, "load config from ini file", uwsgi_opt_load_ini, NULL, UWSGI_OPT_IMMEDIATE},
|
||||
|
||||
@@ -1899,6 +1899,7 @@ struct uwsgi_server {
|
||||
struct uwsgi_string_list *exec_post_app;
|
||||
|
||||
struct uwsgi_string_list *exec_as_vassal;
|
||||
struct uwsgi_string_list *exec_as_emperor;
|
||||
|
||||
struct uwsgi_string_list *call_pre_jail;
|
||||
struct uwsgi_string_list *call_post_jail;
|
||||
@@ -1913,6 +1914,11 @@ struct uwsgi_server {
|
||||
struct uwsgi_string_list *call_as_vassal1;
|
||||
struct uwsgi_string_list *call_as_vassal3;
|
||||
|
||||
struct uwsgi_string_list *call_as_emperor;
|
||||
struct uwsgi_string_list *call_as_emperor1;
|
||||
struct uwsgi_string_list *call_as_emperor2;
|
||||
struct uwsgi_string_list *call_as_emperor4;
|
||||
|
||||
struct uwsgi_string_list *wait_for_interface;
|
||||
int wait_for_interface_timeout;
|
||||
|
||||
@@ -3149,6 +3155,7 @@ void uwsgi_add_sockets_to_queue(int, int);
|
||||
void uwsgi_del_sockets_from_queue(int);
|
||||
|
||||
int uwsgi_run_command_and_wait(char *, char *);
|
||||
int uwsgi_run_command_putenv_and_wait(char *, char *, char **, unsigned int);
|
||||
int uwsgi_call_symbol(char *);
|
||||
|
||||
void uwsgi_manage_signal_cron(time_t);
|
||||
|
||||
Reference in New Issue
Block a user