diff options
author | Igor Sysoev <igor@sysoev.ru> | 2017-03-09 18:03:27 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2017-03-09 18:03:27 +0300 |
commit | 6f2c9acd1841ca20a1388b34aef64e9f00459090 (patch) | |
tree | c0b9c1063ec464027d1ca29a793f6c0b7a6878d5 /src/nxt_process.h | |
parent | 5745e4826427155e29c1d520fe77811a0f570689 (diff) | |
download | unit-6f2c9acd1841ca20a1388b34aef64e9f00459090.tar.gz unit-6f2c9acd1841ca20a1388b34aef64e9f00459090.tar.bz2 |
Processes refactoring.
The cycle has been renamed to the runtime.
Diffstat (limited to 'src/nxt_process.h')
-rw-r--r-- | src/nxt_process.h | 112 |
1 files changed, 64 insertions, 48 deletions
diff --git a/src/nxt_process.h b/src/nxt_process.h index 702d39f2..92f673a2 100644 --- a/src/nxt_process.h +++ b/src/nxt_process.h @@ -4,62 +4,95 @@ * Copyright (C) NGINX, Inc. */ -#ifndef _NXT_UNIX_PROCESS_H_INCLUDED_ -#define _NXT_UNIX_PROCESS_H_INCLUDED_ +#ifndef _NXT_PROCESS_H_INCLUDED_ +#define _NXT_PROCESS_H_INCLUDED_ -typedef pid_t nxt_pid_t; +typedef enum { + NXT_PROCESS_SINGLE = 0, + NXT_PROCESS_MASTER, + NXT_PROCESS_CONTROLLER, + NXT_PROCESS_ROUTER, + NXT_PROCESS_WORKER, +} nxt_process_type_t; -#define \ -nxt_sched_yield() \ - sched_yield() +typedef pid_t nxt_pid_t; +typedef uid_t nxt_uid_t; +typedef gid_t nxt_gid_t; -#define \ -nxt_process_id() \ - nxt_pid +typedef struct { + const char *user; + nxt_uid_t uid; + nxt_gid_t base_gid; + nxt_uint_t ngroups; + nxt_gid_t *gids; +} nxt_user_cred_t; +typedef struct nxt_process_init_s nxt_process_init_t; +typedef nxt_int_t (*nxt_process_star_t)(nxt_task_t *task, nxt_runtime_t *rt); -/* - * Solaris declares abort() as __NORETURN, - * raise(SIGABRT) is mostly the same. - */ -#define \ -nxt_abort() \ - (void) raise(SIGABRT) +struct nxt_process_init_s { + nxt_process_star_t start; + const char *name; + nxt_user_cred_t *user_cred; + nxt_port_t *port; + nxt_port_t *master_port; + nxt_port_handler_t *port_handlers; + const nxt_sig_event_t *signals; -typedef void (*nxt_process_start_t)(void *data); + nxt_process_type_t type:8; /* 3 bits */ +}; -NXT_EXPORT nxt_pid_t nxt_process_create(nxt_process_start_t start, void *data, - const char *name); -NXT_EXPORT nxt_pid_t nxt_process_execute(char *name, char **argv, char **envp); -NXT_EXPORT nxt_int_t nxt_process_daemon(void); + +typedef struct { + nxt_pid_t pid; + nxt_array_t *ports; /* of nxt_port_t */ + nxt_process_init_t *init; +} nxt_process_t; + + +NXT_EXPORT nxt_pid_t nxt_process_create(nxt_task_t *task, + nxt_process_init_t *process); +NXT_EXPORT nxt_pid_t nxt_process_execute(nxt_task_t *task, char *name, + char **argv, char **envp); +NXT_EXPORT nxt_int_t nxt_process_daemon(nxt_task_t *task); NXT_EXPORT void nxt_nanosleep(nxt_nsec_t ns); -NXT_EXPORT void nxt_process_arguments(char **orig_argv, char ***orig_envp); +NXT_EXPORT void nxt_process_arguments(nxt_task_t *task, char **orig_argv, + char ***orig_envp); #if (NXT_HAVE_SETPROCTITLE) -#define \ -nxt_process_title(title) \ - setproctitle("%s", title) +#define nxt_process_title(task, fmt, ...) \ + setproctitle(fmt, __VA_ARGS__) #elif (NXT_LINUX || NXT_SOLARIS || NXT_MACOSX) #define NXT_SETPROCTITLE_ARGV 1 -NXT_EXPORT void nxt_process_title(const char *title); +NXT_EXPORT void nxt_process_title(nxt_task_t *task, const char *fmt, ...); -#else +#endif -#define \ -nxt_process_title(title) -#endif +#define nxt_sched_yield() \ + sched_yield() +/* + * Solaris declares abort() as __NORETURN, + * raise(SIGABRT) is mostly the same. + */ + +#define nxt_abort() \ + (void) raise(SIGABRT) + +NXT_EXPORT nxt_int_t nxt_user_cred_get(nxt_task_t *task, nxt_user_cred_t *uc, + const char *group); +NXT_EXPORT nxt_int_t nxt_user_cred_set(nxt_task_t *task, nxt_user_cred_t *uc); NXT_EXPORT extern nxt_pid_t nxt_pid; NXT_EXPORT extern nxt_pid_t nxt_ppid; @@ -67,21 +100,4 @@ NXT_EXPORT extern char **nxt_process_argv; NXT_EXPORT extern char ***nxt_process_environ; -typedef uid_t nxt_uid_t; -typedef gid_t nxt_gid_t; - - -typedef struct { - const char *user; - nxt_uid_t uid; - nxt_gid_t base_gid; - nxt_uint_t ngroups; - nxt_gid_t *gids; -} nxt_user_cred_t; - - -NXT_EXPORT nxt_int_t nxt_user_cred_get(nxt_user_cred_t *uc, const char *group); -NXT_EXPORT nxt_int_t nxt_user_cred_set(nxt_user_cred_t *uc); - - -#endif /* _NXT_UNIX_PROCESS_H_INCLUDED_ */ +#endif /* _NXT_PROCESS_H_INCLUDED_ */ |