Skip to content

Commit

Permalink
mxqd: Do not return status from exec_reaper
Browse files Browse the repository at this point in the history
exec_reaper only returns on failure, so don't return a status value.
  • Loading branch information
donald committed Apr 20, 2022
1 parent 7bff727 commit a475703
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ static int is_reaper(pid_t pid) {
return 0;
}

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

struct mxq_group *group;
Expand All @@ -929,19 +929,19 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
res = prctl(PR_SET_NAME, REAPER_PNAME, NULL, NULL, NULL);
if (res < 0) {
mx_log_err("reaper_process set name: %m");
return res;
return;
}

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

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

struct passwd *passwd;
Expand All @@ -955,7 +955,7 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
if (!passwd) {
mx_log_err("job=%s(%d):%lu:%lu getpwuid(): %m",
group->user_name, group->user_uid, group->group_id, job->job_id);
return -1;
return;
}

if (!mx_streq(passwd->pw_name, group->user_name)) {
Expand All @@ -972,7 +972,7 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
if (!passwd) {
mx_log_err("job=%s(%d):%lu:%lu getpwnam(): %m",
group->user_name, group->user_uid, group->group_id, job->job_id);
return -1;
return;
}
if (passwd->pw_uid != group->user_uid) {
mx_log_fatal("job=%s(%d):%lu:%lu user_name=%s does not map to uid=%d but to pw_uid=%d. Aborting Child execution.",
Expand All @@ -984,7 +984,7 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
group->user_uid,
passwd->pw_uid);

return -1;
return;
}
}

Expand All @@ -994,7 +994,7 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
if (res != 0) {
mx_log_err("job=%s(%d):%lu:%lu clearenv(): %m",
group->user_name, group->user_uid, group->group_id, job->job_id);
return -1;
return;
}

mx_setenv_forever("USER", group->user_name);
Expand Down Expand Up @@ -1046,7 +1046,7 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
if (fh == -1) {
mx_log_err("job=%s(%d):%lu:%lu open(%s) failed: %m",
group->user_name, group->user_uid, group->group_id, job->job_id, "/proc/self/loginuid");
return -1;
return;
}
dprintf(fh, "%d", group->user_uid);
close(fh);
Expand Down Expand Up @@ -1085,31 +1085,31 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
if (res == -1) {
mx_log_err("job=%s(%d):%lu:%lu initgroups() failed: %m",
group->user_name, group->user_uid, group->group_id, job->job_id);
return -1;
return;
}

res = setregid(group->user_gid, group->user_gid);
if (res == -1) {
mx_log_err("job=%s(%d):%lu:%lu setregid(%d, %d) failed: %m",
group->user_name, group->user_uid, group->group_id, job->job_id,
group->user_gid, group->user_gid);
return -1;
return;
}

res = setreuid(-1, group->user_uid);
if (res == -1) {
mx_log_err("job=%s(%d):%lu:%lu setreuid(%d, %d) failed: %m",
group->user_name, group->user_uid, group->group_id, job->job_id,
group->user_uid, group->user_uid);
return -1;
return;
}

res = chdir(job->job_workdir);
if (res == -1) {
mx_log_err("job=%s(%d):%lu:%lu chdir(%s) failed: %m",
group->user_name, group->user_uid, group->group_id, job->job_id,
job->job_workdir);
return -1;
return;
}

umask(job->job_umask);
Expand All @@ -1127,7 +1127,7 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
group->group_id,
job->job_id,
res);
return(res);
return;
}

res = mxq_redirect_output(job->tmp_stdout, job->tmp_stderr);
Expand All @@ -1138,7 +1138,7 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
group->group_id,
job->job_id,
res);
return(res);
return;
}

char **argv = mx_strvec_from_str(job->job_argv_str);
Expand All @@ -1149,7 +1149,7 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
group->group_id,
job->job_id,
job->job_argv_str);
return -errno;
return;
}

int argc = 0;
Expand All @@ -1172,17 +1172,16 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
group->user_uid,
group->group_id,
job->job_id);
return -errno;
return;
}

res = execvp(new_argv[0], new_argv);
execvp(new_argv[0], new_argv);
mx_log_err("job=%s(%d):%lu:%lu execvp(\"%s\", ...): %m",
group->user_name,
group->user_uid,
group->group_id,
job->job_id,
argv[0]);
return res;
}

static unsigned long start_job(struct mxq_group_list *glist)
Expand Down Expand Up @@ -1257,14 +1256,14 @@ static unsigned long start_job(struct mxq_group_list *glist)
server->flock = NULL;
mx_mysql_finish(&server->mysql);

res = exec_reaper(server, glist, job);
exec_reaper(server, glist, job);

mxq_job_free_content(job);

mx_log_debug("shutting down reaper, bye bye.");
mx_log_finish();
server_free(server);
_exit(res<0 ? EX__MAX+1 : 0);
_exit(EX__MAX+1);
}

gettimeofday(&job->stats_starttime, NULL);
Expand Down

0 comments on commit a475703

Please sign in to comment.