Skip to content

Commit

Permalink
mxqd: Inline user_process into exec_reaper
Browse files Browse the repository at this point in the history
  • Loading branch information
donald committed Apr 20, 2022
1 parent 665a677 commit 891dcc6
Showing 1 changed file with 32 additions and 46 deletions.
78 changes: 32 additions & 46 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1098,15 +1098,43 @@ static int mxq_redirect_input(char *stdin_fname)
return 1;
}

static int user_process(struct mxq_server *server, struct mxq_group_list *glist, struct mxq_job *job)
{
static const char REAPER_PNAME[] = "mxqd reaper";

static int is_reaper(pid_t pid) {
char comm[16];
if (mx_proc_get_comm(pid, comm) == NULL)
return 0;
if (strcmp(comm, REAPER_PNAME) == 0)
return 1;
else
return 0;
}

static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, struct mxq_job *job) {
int res;
char **argv;

struct mxq_group *group;

group = &glist->group;

res = prctl(PR_SET_NAME, REAPER_PNAME, NULL, NULL, NULL);
if (res < 0) {
mx_log_err("reaper_process set name: %m");
return res;
}

res = setsid();
if (res < 0) {
mx_log_err("reaper_process setsid: %m");
return res;
}

res = prctl(PR_SET_CHILD_SUBREAPER, 1);
if (res < 0) {
mx_log_err("set subreaper: %m");
return res;
}

res = init_child_process(glist, job);
if (!res)
return(-1);
Expand Down Expand Up @@ -1135,7 +1163,7 @@ static int user_process(struct mxq_server *server, struct mxq_group_list *glist,
return(res);
}

argv = mx_strvec_from_str(job->job_argv_str);
char **argv = mx_strvec_from_str(job->job_argv_str);
if (!argv) {
mx_log_err("job=%s(%d):%lu:%lu Can't recaculate commandline. str_to_strvev(%s) failed: %m",
group->user_name,
Expand Down Expand Up @@ -1179,48 +1207,6 @@ static int user_process(struct mxq_server *server, struct mxq_group_list *glist,
return res;
}

static const char REAPER_PNAME[] = "mxqd reaper";

static int is_reaper(pid_t pid) {
char comm[16];
if (mx_proc_get_comm(pid, comm) == NULL)
return 0;
if (strcmp(comm, REAPER_PNAME) == 0)
return 1;
else
return 0;
}

static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, struct mxq_job *job) {
int res;

struct mxq_group *group;

group = &glist->group;

res = prctl(PR_SET_NAME, REAPER_PNAME, NULL, NULL, NULL);
if (res < 0) {
mx_log_err("reaper_process set name: %m");
return res;
}

res = setsid();
if (res < 0) {
mx_log_err("reaper_process setsid: %m");
return res;
}

res = prctl(PR_SET_CHILD_SUBREAPER, 1);
if (res < 0) {
mx_log_err("set subreaper: %m");
return res;
}

res = user_process(server, glist, job);
mx_log_err("user process:: %m");
return res;
}

static unsigned long start_job(struct mxq_group_list *glist)
{
struct mxq_server *server;
Expand Down

0 comments on commit 891dcc6

Please sign in to comment.