diff --git a/core/utils.c b/core/utils.c index 12b0e694..4471c435 100644 --- a/core/utils.c +++ b/core/utils.c @@ -372,8 +372,33 @@ void uwsgi_as_root() { #endif } - // now run the scripts needed by root + struct uwsgi_string_list *usl; + uwsgi_foreach(usl, uwsgi.wait_for_interface) { + if (!uwsgi.wait_for_interface_timeout) { + uwsgi.wait_for_interface_timeout = 60; + } + uwsgi_log("waiting for interface %s (max %d seconds) ...\n", usl->value, uwsgi.wait_for_interface_timeout); + int counter = 0; + for(;;) { + if (counter > uwsgi.wait_for_interface_timeout) { + uwsgi_log("interface %s unavailable after %d seconds\n", usl->value, counter); + exit(1); + } + unsigned int index = if_nametoindex(usl->value); + if (index > 0) { + uwsgi_log("interface %s found with index %u\n", usl->value, index); + break; + } + else { + sleep(1); + counter++; + } + } + } + + + // now run the scripts needed by root uwsgi_foreach(usl, uwsgi.exec_as_root) { uwsgi_log("running \"%s\" (as root)...\n", usl->value); int ret = uwsgi_run_command_and_wait(NULL, usl->value); diff --git a/core/uwsgi.c b/core/uwsgi.c index bc0bbff4..7bd1da22 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -314,6 +314,18 @@ static struct uwsgi_option uwsgi_base_options[] = { {"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}, + {"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}, + + {"wait-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-interface-timeout", required_argument, 0, "set the timeout for wait-for-interface", uwsgi_opt_set_int, &uwsgi.wait_for_interface_timeout, 0}, + + {"wait-for-iface", 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-iface-timeout", required_argument, 0, "set the timeout for wait-for-interface", uwsgi_opt_set_int, &uwsgi.wait_for_interface_timeout, 0}, + + {"wait-iface", 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-iface-timeout", required_argument, 0, "set the timeout for wait-for-interface", uwsgi_opt_set_int, &uwsgi.wait_for_interface_timeout, 0}, + {"call-pre-jail", required_argument, 0, "call the specified function before jailing", uwsgi_opt_add_string_list, &uwsgi.call_pre_jail, 0}, {"call-post-jail", required_argument, 0, "call the specified function after jailing", uwsgi_opt_add_string_list, &uwsgi.call_post_jail, 0}, {"call-in-jail", required_argument, 0, "call the specified function in jail after initialization", uwsgi_opt_add_string_list, &uwsgi.call_in_jail, 0}, diff --git a/uwsgi.h b/uwsgi.h index 5387fa06..b4794c67 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -166,6 +166,7 @@ extern "C" { #endif #endif #include +#include #ifdef __linux__ #ifndef MSG_FASTOPEN #define MSG_FASTOPEN 0x20000000 @@ -1912,6 +1913,9 @@ struct uwsgi_server { struct uwsgi_string_list *call_as_vassal1; struct uwsgi_string_list *call_as_vassal3; + struct uwsgi_string_list *wait_for_interface; + int wait_for_interface_timeout; + char *privileged_binary_patch; char *unprivileged_binary_patch; char *privileged_binary_patch_arg;