From 21de5c1d1895495477c39f47449f57b680e34140 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Tue, 18 Jul 2017 22:27:13 +0300 Subject: Added application name in process title. --- src/nxt_application.h | 1 + src/nxt_master_process.c | 45 ++++++++++++++++++++++++++++++++------------- src/nxt_router.c | 7 ++++++- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/nxt_application.h b/src/nxt_application.h index 73370806..97250324 100644 --- a/src/nxt_application.h +++ b/src/nxt_application.h @@ -46,6 +46,7 @@ typedef struct { struct nxt_common_app_conf_s { + nxt_str_t name; nxt_str_t type; nxt_app_type_t type_id; nxt_str_t user; diff --git a/src/nxt_master_process.c b/src/nxt_master_process.c index 3cb62830..5473afab 100644 --- a/src/nxt_master_process.c +++ b/src/nxt_master_process.c @@ -136,6 +136,7 @@ static nxt_conf_map_t nxt_common_app_conf[] = { static void nxt_port_master_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) { + u_char *start; size_t dump_size; nxt_mp_t *mp; nxt_int_t ret; @@ -156,7 +157,16 @@ nxt_port_master_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) mp = nxt_mp_create(1024, 128, 256, 32); - conf = nxt_conf_json_parse(mp, b->mem.pos, b->mem.free); + nxt_memzero(&app_conf, sizeof(nxt_common_app_conf_t)); + + start = b->mem.pos; + + app_conf.name.start = start; + app_conf.name.length = nxt_strlen(start); + + start += app_conf.name.length + 1; + + conf = nxt_conf_json_parse(mp, start, b->mem.free); b->mem.pos = b->mem.free; if (conf == NULL) { @@ -164,8 +174,6 @@ nxt_port_master_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg) return; } - nxt_memzero(&app_conf, sizeof(nxt_common_app_conf_t)); - app_conf.user = nobody; ret = nxt_conf_map_object(conf, nxt_common_app_conf, @@ -308,30 +316,36 @@ nxt_master_start_worker_process(nxt_task_t *task, nxt_runtime_t *rt, nxt_common_app_conf_t *app_conf, uint32_t stream) { char *user, *group; + u_char *title, *last, *end; + size_t size; nxt_process_init_t *init; - init = nxt_malloc(sizeof(nxt_process_init_t) - + sizeof(nxt_user_cred_t) - + app_conf->user.length + 1 - + app_conf->group.length + 1); + size = sizeof(nxt_process_init_t) + + sizeof(nxt_user_cred_t) + + app_conf->user.length + 1 + + app_conf->group.length + 1 + + app_conf->name.length + sizeof("\"\" application"); + + init = nxt_malloc(size); if (nxt_slow_path(init == NULL)) { return NXT_ERROR; } - init->user_cred = (nxt_user_cred_t *) (init + 1); - + init->user_cred = nxt_pointer_to(init, sizeof(nxt_process_init_t)); user = nxt_pointer_to(init->user_cred, sizeof(nxt_user_cred_t)); nxt_memcpy(user, app_conf->user.start, app_conf->user.length); - user[app_conf->user.length] = '\0'; + last = nxt_pointer_to(user, app_conf->user.length); + *last++ = '\0'; init->user_cred->user = user; if (app_conf->group.start != NULL) { - group = nxt_pointer_to(user, app_conf->user.length + 1); + group = (char *) last; nxt_memcpy(group, app_conf->group.start, app_conf->group.length); - group[app_conf->group.length] = '\0'; + end = nxt_pointer_to(group, app_conf->group.length); + *last++ = '\0'; } else { group = NULL; @@ -341,8 +355,13 @@ nxt_master_start_worker_process(nxt_task_t *task, nxt_runtime_t *rt, return NXT_ERROR; } + title = last; + end = title + app_conf->name.length + sizeof("\"\" application"); + + nxt_sprintf(title, end, "\"%V\" application%Z", &app_conf->name); + init->start = nxt_app_start; - init->name = "worker process"; + init->name = (char *) title; init->port_handlers = nxt_app_process_port_handlers; init->signals = nxt_worker_process_signals; init->type = NXT_PROCESS_WORKER; diff --git a/src/nxt_router.c b/src/nxt_router.c index fbd3462e..0774b158 100644 --- a/src/nxt_router.c +++ b/src/nxt_router.c @@ -1930,6 +1930,7 @@ nxt_router_gen_error(nxt_task_t *task, nxt_conn_t *c, int code, static void nxt_router_send_sw_request(nxt_task_t *task, void *obj, void *data) { + size_t size; nxt_buf_t *b; nxt_app_t *app; nxt_port_t *port; @@ -1961,8 +1962,12 @@ nxt_router_send_sw_request(nxt_task_t *task, void *obj, void *data) rt = task->thread->runtime; port = rt->port_by_type[NXT_PROCESS_MASTER]; - b = nxt_buf_mem_alloc(port->mem_pool, app->conf.length, 0); + size = app->name.length + 1 + app->conf.length; + b = nxt_buf_mem_alloc(port->mem_pool, size, 0); + + nxt_buf_cpystr(b, &app->name); + *b->mem.free++ = '\0'; nxt_buf_cpystr(b, &app->conf); nxt_port_socket_write(task, port, NXT_PORT_MSG_DATA, -1, sw->stream, 0, b); -- cgit