Skip to content

Commit

Permalink
mxqd: Revert return status of init_child_process
Browse files Browse the repository at this point in the history
Return 0 on success, -1 on failure.

This change will make the following commit easier to follow.
  • Loading branch information
donald committed Apr 20, 2022
1 parent 891dcc6 commit c51e280
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ static int init_child_process(struct mxq_group_list *glist, struct mxq_job *job)
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 0;
return -1;
}

if (!mx_streq(passwd->pw_name, group->user_name)) {
Expand All @@ -859,7 +859,7 @@ static int init_child_process(struct mxq_group_list *glist, struct mxq_job *job)
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 0;
return -1;
}
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 @@ -871,7 +871,7 @@ static int init_child_process(struct mxq_group_list *glist, struct mxq_job *job)
group->user_uid,
passwd->pw_uid);

return 0;
return -1;
}
}

Expand All @@ -881,7 +881,7 @@ static int init_child_process(struct mxq_group_list *glist, struct mxq_job *job)
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 0;
return -1;
}

mx_setenv_forever("USER", group->user_name);
Expand Down Expand Up @@ -933,7 +933,7 @@ static int init_child_process(struct mxq_group_list *glist, struct mxq_job *job)
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 0;
return -1;
}
dprintf(fh, "%d", group->user_uid);
close(fh);
Expand Down Expand Up @@ -972,39 +972,39 @@ static int init_child_process(struct mxq_group_list *glist, struct mxq_job *job)
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 0;
return -1;
}

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 0;
return -1;
}

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 0;
return -1;
}

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 0;
return -1;
}

umask(job->job_umask);

res=sched_setaffinity(0,sizeof(job->host_cpu_set),&job->host_cpu_set);
if (res<0) mx_log_warning("sched_setaffinity: $m");

return 1;
return 0;
}

/**********************************************************************/
Expand Down Expand Up @@ -1136,7 +1136,7 @@ static int exec_reaper(struct mxq_server *server,struct mxq_group_list *glist, s
}

res = init_child_process(glist, job);
if (!res)
if (res == -1)
return(-1);

mxq_job_set_tmpfilenames(group, job);
Expand Down

0 comments on commit c51e280

Please sign in to comment.