summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_process.c
diff options
context:
space:
mode:
authorTiago Natel <t.nateldemoura@f5.com>2019-11-26 16:26:24 +0000
committerTiago Natel <t.nateldemoura@f5.com>2019-11-26 16:26:24 +0000
commit417cc7be7c0c6f6e62f0916f671bbf0a4460226b (patch)
tree1ca53595fb350ab3d9acab11965bcc98606741f7 /src/nxt_process.c
parenta3e5d095016166a78a45c9aade2b19d75d66833f (diff)
downloadunit-417cc7be7c0c6f6e62f0916f671bbf0a4460226b.tar.gz
unit-417cc7be7c0c6f6e62f0916f671bbf0a4460226b.tar.bz2
Refactor of process init.
Introduces the functions nxt_process_init_create() and nxt_process_init_creds_set().
Diffstat (limited to 'src/nxt_process.c')
-rw-r--r--src/nxt_process.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/nxt_process.c b/src/nxt_process.c
index 64356d64..0cb0fbdd 100644
--- a/src/nxt_process.c
+++ b/src/nxt_process.c
@@ -14,7 +14,8 @@
#include <signal.h>
static void nxt_process_start(nxt_task_t *task, nxt_process_t *process);
-static nxt_int_t nxt_user_groups_get(nxt_task_t *task, nxt_user_cred_t *uc);
+static nxt_int_t nxt_user_groups_get(nxt_task_t *task, nxt_mp_t *mp,
+ nxt_user_cred_t *uc);
static nxt_int_t nxt_process_worker_setup(nxt_task_t *task,
nxt_process_t *process, int parentfd);
@@ -526,7 +527,8 @@ nxt_nanosleep(nxt_nsec_t ns)
nxt_int_t
-nxt_user_cred_get(nxt_task_t *task, nxt_user_cred_t *uc, const char *group)
+nxt_user_cred_get(nxt_task_t *task, nxt_mp_t *mp, nxt_user_cred_t *uc,
+ const char *group)
{
struct group *grp;
struct passwd *pwd;
@@ -574,7 +576,7 @@ nxt_user_cred_get(nxt_task_t *task, nxt_user_cred_t *uc, const char *group)
nxt_debug(task, "about to get \"%s\" groups (uid:%d, base gid:%d)",
uc->user, uc->uid, uc->base_gid);
- if (nxt_user_groups_get(task, uc) != NXT_OK) {
+ if (nxt_user_groups_get(task, mp, uc) != NXT_OK) {
return NXT_ERROR;
}
@@ -606,7 +608,7 @@ nxt_user_cred_get(nxt_task_t *task, nxt_user_cred_t *uc, const char *group)
static nxt_int_t
-nxt_user_groups_get(nxt_task_t *task, nxt_user_cred_t *uc)
+nxt_user_groups_get(nxt_task_t *task, nxt_mp_t *mp, nxt_user_cred_t *uc)
{
int ngroups;
gid_t groups[NXT_NGROUPS];
@@ -629,7 +631,7 @@ nxt_user_groups_get(nxt_task_t *task, nxt_user_cred_t *uc)
uc->ngroups = ngroups;
- uc->gids = nxt_malloc(ngroups * sizeof(gid_t));
+ uc->gids = nxt_mp_alloc(mp, ngroups * sizeof(gid_t));
if (nxt_slow_path(uc->gids == NULL)) {
return NXT_ERROR;
}
@@ -640,8 +642,6 @@ nxt_user_groups_get(nxt_task_t *task, nxt_user_cred_t *uc)
nxt_alert(task, "getgrouplist(\"%s\", %d) failed %E", uc->user,
uc->base_gid, nxt_errno);
- nxt_free(uc->gids);
-
return NXT_ERROR;
}
@@ -650,7 +650,7 @@ nxt_user_groups_get(nxt_task_t *task, nxt_user_cred_t *uc)
uc->ngroups = ngroups;
- uc->gids = nxt_malloc(ngroups * sizeof(gid_t));
+ uc->gids = nxt_mp_alloc(mp, ngroups * sizeof(gid_t));
if (nxt_slow_path(uc->gids == NULL)) {
return NXT_ERROR;
}
@@ -692,7 +692,7 @@ nxt_user_groups_get(nxt_task_t *task, nxt_user_cred_t *uc)
*/
static nxt_int_t
-nxt_user_groups_get(nxt_task_t *task, nxt_user_cred_t *uc)
+nxt_user_groups_get(nxt_task_t *task, nxt_mp_t *mp, nxt_user_cred_t *uc)
{
int nsaved, ngroups;
nxt_int_t ret;
@@ -716,7 +716,7 @@ nxt_user_groups_get(nxt_task_t *task, nxt_user_cred_t *uc)
return NXT_OK;
}
- saved = nxt_malloc(nsaved * sizeof(nxt_gid_t));
+ saved = nxt_mp_alloc(mp, nsaved * sizeof(nxt_gid_t));
if (nxt_slow_path(saved == NULL)) {
return NXT_ERROR;
@@ -759,7 +759,7 @@ nxt_user_groups_get(nxt_task_t *task, nxt_user_cred_t *uc)
nxt_debug(task, "getgroups(0, NULL): %d", ngroups);
- uc->gids = nxt_malloc(ngroups * sizeof(nxt_gid_t));
+ uc->gids = nxt_mp_alloc(mp, ngroups * sizeof(nxt_gid_t));
if (nxt_slow_path(uc->gids == NULL)) {
goto restore;
@@ -785,7 +785,7 @@ restore:
free:
- nxt_free(saved);
+ nxt_mp_free(mp, saved);
return ret;
}