Lines Matching refs:task

29 static nxt_pid_t nxt_process_create(nxt_task_t *task, nxt_process_t *process);
30 static nxt_int_t nxt_process_do_start(nxt_task_t *task, nxt_process_t *process);
31 static nxt_int_t nxt_process_whoami(nxt_task_t *task, nxt_process_t *process);
32 static nxt_int_t nxt_process_setup(nxt_task_t *task, nxt_process_t *process);
33 static nxt_int_t nxt_process_child_fixup(nxt_task_t *task,
35 static void nxt_process_whoami_ok(nxt_task_t *task, nxt_port_recv_msg_t *msg,
37 static void nxt_process_whoami_error(nxt_task_t *task, nxt_port_recv_msg_t *msg,
39 static nxt_int_t nxt_process_send_created(nxt_task_t *task,
41 static nxt_int_t nxt_process_send_ready(nxt_task_t *task,
43 static void nxt_process_created_ok(nxt_task_t *task, nxt_port_recv_msg_t *msg,
45 static void nxt_process_created_error(nxt_task_t *task,
121 nxt_process_use(nxt_task_t *task, nxt_process_t *process, int i) in nxt_process_use() argument
126 nxt_runtime_process_release(task->thread->runtime, process); in nxt_process_use()
132 nxt_process_init_start(nxt_task_t *task, nxt_process_init_t init) in nxt_process_init_start() argument
139 rt = task->thread->runtime; in nxt_process_init_start()
154 ret = nxt_process_start(task, process); in nxt_process_init_start()
156 nxt_process_use(task, process, -1); in nxt_process_init_start()
164 nxt_process_start(nxt_task_t *task, nxt_process_t *process) in nxt_process_start() argument
174 port = nxt_port_new(task, 0, 0, init->type); in nxt_process_start()
179 nxt_process_port_add(task, process, port); in nxt_process_start()
181 ret = nxt_port_socket_init(task, port, 0); in nxt_process_start()
194 ret = init->prefork(task, process, tmp_mp); in nxt_process_start()
200 pid = nxt_process_create(task, process); in nxt_process_start()
211 nxt_process_use(task, process, -1); in nxt_process_start()
219 nxt_process_use(task, process, -1); in nxt_process_start()
222 nxt_port_write_enable(task, port); in nxt_process_start()
235 nxt_port_close(task, port); in nxt_process_start()
240 nxt_port_use(task, port, -1); in nxt_process_start()
247 nxt_process_child_fixup(nxt_task_t *task, nxt_process_t *process) in nxt_process_child_fixup() argument
264 task->thread->tid = 0; in nxt_process_child_fixup()
270 nxt_event_engine_thread_adopt(task->thread->engine); in nxt_process_child_fixup()
272 rt = task->thread->runtime; in nxt_process_child_fixup()
280 nxt_debug(task, "remove not required process %PI", p->pid); in nxt_process_child_fixup()
282 nxt_process_close_ports(task, p); in nxt_process_child_fixup()
288 nxt_debug(task, "remove not ready process %PI", p->pid); in nxt_process_child_fixup()
290 nxt_process_close_ports(task, p); in nxt_process_child_fixup()
302 nxt_debug(task, "remove sibling process %PI", p->pid); in nxt_process_child_fixup()
304 nxt_process_close_ports(task, p); in nxt_process_child_fixup()
314 nxt_process_create(nxt_task_t *task, nxt_process_t *process) in nxt_process_create() argument
323 nxt_alert(task, "clone() failed for %s %E", process->name, nxt_errno); in nxt_process_create()
329 nxt_alert(task, "fork() failed for %s %E", process->name, nxt_errno); in nxt_process_create()
337 ret = nxt_process_child_fixup(task, process); in nxt_process_create()
339 nxt_process_quit(task, 1); in nxt_process_create()
343 ret = nxt_process_setup(task, process); in nxt_process_create()
345 nxt_process_quit(task, 1); in nxt_process_create()
358 nxt_debug(task, "clone(%s): %PI", process->name, pid); in nxt_process_create()
360 nxt_debug(task, "fork(%s): %PI", process->name, pid); in nxt_process_create()
366 rt = task->thread->runtime; in nxt_process_create()
375 nxt_port_use(task, nxt_process_port_first(process), 1); in nxt_process_create()
378 nxt_runtime_process_add(task, process); in nxt_process_create()
386 nxt_process_setup(nxt_task_t *task, nxt_process_t *process) in nxt_process_setup() argument
397 nxt_debug(task, "%s setup", process->name); in nxt_process_setup()
399 nxt_process_title(task, "unit: %s", process->name); in nxt_process_setup()
401 thread = task->thread; in nxt_process_setup()
429 nxt_port_write_enable(task, process->parent_port); in nxt_process_setup()
442 ret = nxt_process_whoami(task, process); in nxt_process_setup()
445 ret = nxt_process_do_start(task, process); in nxt_process_setup()
453 nxt_process_do_start(nxt_task_t *task, nxt_process_t *process) in nxt_process_do_start() argument
459 nxt_runtime_process_add(task, process); in nxt_process_do_start()
464 nxt_port_enable(task, port, init->port_handlers); in nxt_process_do_start()
466 ret = init->setup(task, process); in nxt_process_do_start()
474 ret = nxt_process_send_created(task, process); in nxt_process_do_start()
478 ret = nxt_process_send_ready(task, process); in nxt_process_do_start()
484 ret = init->start(task, &process->data); in nxt_process_do_start()
495 nxt_alert(task, "%s failed to start", process->name); in nxt_process_do_start()
503 nxt_process_whoami(nxt_task_t *task, nxt_process_t *process) in nxt_process_whoami() argument
512 rt = task->thread->runtime; in nxt_process_whoami()
519 nxt_port_enable(task, my_port, &nxt_process_whoami_port_handlers); in nxt_process_whoami()
528 stream = nxt_port_rpc_register_handler(task, my_port, in nxt_process_whoami()
540 ret = nxt_port_socket_write(task, main_port, NXT_PORT_MSG_WHOAMI, in nxt_process_whoami()
544 nxt_alert(task, "%s failed to send WHOAMI message", process->name); in nxt_process_whoami()
545 nxt_port_rpc_cancel(task, my_port, stream); in nxt_process_whoami()
556 nxt_process_whoami_ok(nxt_task_t *task, nxt_port_recv_msg_t *msg, void *data) in nxt_process_whoami_ok() argument
583 rt = task->thread->runtime; in nxt_process_whoami_ok()
588 (void) nxt_port_socket_write(task, port, NXT_PORT_MSG_PROCESS_CREATED, in nxt_process_whoami_ok()
591 nxt_log(task, NXT_LOG_INFO, "%s started", process->name); in nxt_process_whoami_ok()
594 if (nxt_slow_path(nxt_process_do_start(task, process) != NXT_OK)) { in nxt_process_whoami_ok()
595 nxt_process_quit(task, 1); in nxt_process_whoami_ok()
601 nxt_process_whoami_error(nxt_task_t *task, nxt_port_recv_msg_t *msg, void *data) in nxt_process_whoami_error() argument
603 nxt_alert(task, "WHOAMI error"); in nxt_process_whoami_error()
605 nxt_process_quit(task, 1); in nxt_process_whoami_error()
610 nxt_process_send_created(nxt_task_t *task, nxt_process_t *process) in nxt_process_send_created() argument
619 rt = task->thread->runtime; in nxt_process_send_created()
626 stream = nxt_port_rpc_register_handler(task, my_port, in nxt_process_send_created()
635 ret = nxt_port_socket_write(task, main_port, NXT_PORT_MSG_PROCESS_CREATED, in nxt_process_send_created()
639 nxt_alert(task, "%s failed to send CREATED message", process->name); in nxt_process_send_created()
640 nxt_port_rpc_cancel(task, my_port, stream); in nxt_process_send_created()
644 nxt_debug(task, "%s created", process->name); in nxt_process_send_created()
651 nxt_process_created_ok(nxt_task_t *task, nxt_port_recv_msg_t *msg, void *data) in nxt_process_created_ok() argument
663 ret = nxt_process_apply_creds(task, process); in nxt_process_created_ok()
668 nxt_log(task, NXT_LOG_INFO, "%s started", process->name); in nxt_process_created_ok()
670 ret = nxt_process_send_ready(task, process); in nxt_process_created_ok()
675 ret = init->start(task, &process->data); in nxt_process_created_ok()
686 nxt_process_quit(task, 1); in nxt_process_created_ok()
691 nxt_process_created_error(nxt_task_t *task, nxt_port_recv_msg_t *msg, in nxt_process_created_error() argument
700 nxt_alert(task, "%s failed to start", init->name); in nxt_process_created_error()
702 nxt_process_quit(task, 1); in nxt_process_created_error()
707 nxt_process_core_setup(nxt_task_t *task, nxt_process_t *process) in nxt_process_core_setup() argument
711 ret = nxt_process_apply_creds(task, process); in nxt_process_core_setup()
723 nxt_process_creds_set(nxt_task_t *task, nxt_process_t *process, nxt_str_t *user, in nxt_process_creds_set() argument
758 return nxt_credential_get(task, process->mem_pool, process->user_cred, str); in nxt_process_creds_set()
763 nxt_process_apply_creds(nxt_task_t *task, nxt_process_t *process) in nxt_process_apply_creds() argument
768 rt = task->thread->runtime; in nxt_process_apply_creds()
781 ret = nxt_credential_setgids(task, process->user_cred); in nxt_process_apply_creds()
786 ret = nxt_credential_setuid(task, process->user_cred); in nxt_process_apply_creds()
796 nxt_alert(task, "failed to set no_new_privs %E", nxt_errno); in nxt_process_apply_creds()
806 nxt_process_send_ready(nxt_task_t *task, nxt_process_t *process) in nxt_process_send_ready() argument
810 ret = nxt_port_socket_write(task, process->parent_port, in nxt_process_send_ready()
815 nxt_alert(task, "%s failed to send READY message", process->name); in nxt_process_send_ready()
819 nxt_debug(task, "%s sent ready", process->name); in nxt_process_send_ready()
845 nxt_process_execute(nxt_task_t *task, char *name, char **argv, char **envp) in nxt_process_execute() argument
849 nxt_debug(task, "posix_spawn(\"%s\")", name); in nxt_process_execute()
852 nxt_alert(task, "posix_spawn(\"%s\") failed %E", name, nxt_errno); in nxt_process_execute()
861 nxt_process_daemon(nxt_task_t *task) in nxt_process_daemon() argument
889 nxt_debug(task, "fork(): %PI", pid); in nxt_process_daemon()
897 task->thread->tid = 0; in nxt_process_daemon()
899 nxt_debug(task, "daemon"); in nxt_process_daemon()
904 nxt_alert(task, "setsid() failed %E", nxt_errno); in nxt_process_daemon()
940 nxt_alert(task, msg, nxt_errno); in nxt_process_daemon()
963 nxt_process_port_add(nxt_task_t *task, nxt_process_t *process, nxt_port_t *port) in nxt_process_port_add() argument
970 nxt_process_use(task, process, 1); in nxt_process_port_add()
983 nxt_process_close_ports(nxt_task_t *task, nxt_process_t *process) in nxt_process_close_ports() argument
987 nxt_process_use(task, process, 1); in nxt_process_close_ports()
991 nxt_port_close(task, port); in nxt_process_close_ports()
993 nxt_runtime_port_remove(task, port); in nxt_process_close_ports()
997 nxt_process_use(task, process, -1); in nxt_process_close_ports()
1002 nxt_process_quit(nxt_task_t *task, nxt_uint_t exit_status) in nxt_process_quit() argument
1011 rt = task->thread->runtime; in nxt_process_quit()
1013 nxt_debug(task, "close listen connections"); in nxt_process_quit()
1015 listen = &task->thread->engine->listen_connections; in nxt_process_quit()
1025 nxt_fd_event_close(task->thread->engine, &lev->socket); in nxt_process_quit()
1034 nxt_socket_close(task, ls->socket); in nxt_process_quit()
1044 nxt_runtime_quit(task, exit_status); in nxt_process_quit()