summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_application.c
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-02-14 16:33:35 +0300
committerValentin Bartenev <vbart@nginx.com>2018-02-14 16:33:35 +0300
commit27b00629e1e3af2f8b84aa349351df50f05f3c83 (patch)
treeac658830c5ba40a71ce6a5afb4b46dbe7b1fdb3b /src/nxt_application.c
parent94049bf30f9feccefe805f56b3a75339c25ee39d (diff)
downloadunit-27b00629e1e3af2f8b84aa349351df50f05f3c83.tar.gz
unit-27b00629e1e3af2f8b84aa349351df50f05f3c83.tar.bz2
Fixed race condition while discovering modules.
Previously, the discovery process might exit before the main process received a list of available modules.
Diffstat (limited to 'src/nxt_application.c')
-rw-r--r--src/nxt_application.c62
1 files changed, 42 insertions, 20 deletions
diff --git a/src/nxt_application.c b/src/nxt_application.c
index 7fecd70d..f9ac8a7f 100644
--- a/src/nxt_application.c
+++ b/src/nxt_application.c
@@ -26,6 +26,10 @@ typedef struct {
static nxt_buf_t *nxt_discovery_modules(nxt_task_t *task, const char *path);
static nxt_int_t nxt_discovery_module(nxt_task_t *task, nxt_mp_t *mp,
nxt_array_t *modules, const char *name);
+static void nxt_discovery_completion_handler(nxt_task_t *task, void *obj,
+ void *data);
+static void nxt_discovery_quit(nxt_task_t *task, nxt_port_recv_msg_t *msg,
+ void *data);
static nxt_app_module_t *nxt_app_module_load(nxt_task_t *task,
const char *name);
@@ -46,9 +50,11 @@ static nxt_application_module_t *nxt_app;
nxt_int_t
nxt_discovery_start(nxt_task_t *task, void *data)
{
- nxt_buf_t *b;
- nxt_port_t *main_port;
- nxt_runtime_t *rt;
+ uint32_t stream;
+ nxt_buf_t *b;
+ nxt_int_t ret;
+ nxt_port_t *main_port, *discovery_port;
+ nxt_runtime_t *rt;
nxt_debug(task, "DISCOVERY");
@@ -56,30 +62,26 @@ nxt_discovery_start(nxt_task_t *task, void *data)
b = nxt_discovery_modules(task, rt->modules);
if (nxt_slow_path(b == NULL)) {
- exit(1);
+ return NXT_ERROR;
}
main_port = rt->port_by_type[NXT_PROCESS_MAIN];
+ discovery_port = rt->port_by_type[NXT_PROCESS_DISCOVERY];
- nxt_port_socket_write(task, main_port, NXT_PORT_MSG_MODULES, -1,
- 0, -1, b);
-
- return NXT_OK;
-}
-
+ stream = nxt_port_rpc_register_handler(task, discovery_port,
+ nxt_discovery_quit,
+ nxt_discovery_quit,
+ main_port->pid, NULL);
-static void
-nxt_discovery_completion_handler(nxt_task_t *task, void *obj, void *data)
-{
- nxt_mp_t *mp;
- nxt_buf_t *b;
+ ret = nxt_port_socket_write(task, main_port, NXT_PORT_MSG_MODULES, -1,
+ stream, discovery_port->id, b);
- b = obj;
- mp = b->data;
-
- nxt_mp_destroy(mp);
+ if (nxt_slow_path(ret != NXT_OK)) {
+ nxt_port_rpc_cancel(task, discovery_port, stream);
+ return NXT_ERROR;
+ }
- exit(0);
+ return NXT_OK;
}
@@ -279,6 +281,26 @@ fail:
}
+static void
+nxt_discovery_completion_handler(nxt_task_t *task, void *obj, void *data)
+{
+ nxt_mp_t *mp;
+ nxt_buf_t *b;
+
+ b = obj;
+ mp = b->data;
+
+ nxt_mp_destroy(mp);
+}
+
+
+static void
+nxt_discovery_quit(nxt_task_t *task, nxt_port_recv_msg_t *msg, void *data)
+{
+ nxt_worker_process_quit_handler(task, msg);
+}
+
+
nxt_int_t
nxt_app_start(nxt_task_t *task, void *data)
{