Skip to content

Commit

Permalink
mxqd: Cleanup reaper_process()
Browse files Browse the repository at this point in the history
  • Loading branch information
mariux committed Nov 3, 2015
1 parent 790d4cf commit f9be941
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ int user_process(struct mxq_group_list *glist, struct mxq_job *job)
return res;
}

int reaper_process(struct mxq_server *server,struct mxq_group_list *group,struct mxq_job *job) {
int reaper_process(struct mxq_server *server,struct mxq_group_list *glist, struct mxq_job *job) {
pid_t pid;
struct rusage rusage;
int status;
Expand All @@ -911,6 +911,10 @@ int reaper_process(struct mxq_server *server,struct mxq_group_list *group,struc
FILE *out;
int res;

struct mxq_group *group;

group = &glist->group;

reset_signals();

signal(SIGINT, SIG_IGN);
Expand All @@ -919,50 +923,51 @@ int reaper_process(struct mxq_server *server,struct mxq_group_list *group,struc
signal(SIGXCPU, SIG_IGN);

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

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

pid = fork();
if (pid < 0) {
mx_log_err("fork: %m");
return(pid);
return pid;
} else if (pid == 0) {
res=user_process(group,job);
res = user_process(glist, job);
_exit(EX__MAX+1);
}
gettimeofday(&job->stats_starttime, NULL);

while (1) {
waited_pid=wait(&waited_status);
if (waited_pid<0) {
waited_pid = wait(&waited_status);
if (waited_pid < 0) {
if (errno==ECHILD) {
break;
} else {
mx_log_warning("reaper: wait: %m");
sleep(1);
}
}
if (waited_pid==pid) {
status=waited_status;
if (waited_pid == pid) {
status = waited_status;
}
}
gettimeofday(&now, NULL);
timersub(&now, &job->stats_starttime, &realtime);
res=getrusage(RUSAGE_CHILDREN,&rusage);
if (res<0) {
res = getrusage(RUSAGE_CHILDREN, &rusage);
if (res < 0) {
mx_log_err("reaper: getrusage: %m");
return(res);
}

mx_asprintf_forever(&finished_job_filename,"%s/%lu.stat",server->finished_jobsdir,job->job_id);
mx_asprintf_forever(&finished_job_tmpfilename,"%s.tmp",finished_job_filename);
mx_asprintf_forever(&finished_job_filename, "%s/%lu.stat", server->finished_jobsdir, job->job_id);
mx_asprintf_forever(&finished_job_tmpfilename, "%s.tmp", finished_job_filename);

out=fopen(finished_job_tmpfilename,"w");
if (!out) {
Expand Down

0 comments on commit f9be941

Please sign in to comment.