Skip to content

Commit

Permalink
Do not crash if wps is NULL. This could happen if a core worker dies …
Browse files Browse the repository at this point in the history
…and gets respawned

Signed-off-by: nook24 <[email protected]>
  • Loading branch information
nook24 committed Mar 23, 2023
1 parent 7940a81 commit d6c4c6e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
52 changes: 27 additions & 25 deletions src/naemon/checks_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,33 +636,35 @@ static void handle_worker_host_check(wproc_result *wpres, void *arg, int flags)
if (currently_running_host_checks > 0)
currently_running_host_checks--;

hst = find_host(cr->host_name);
if (hst && wpres) {
hst->is_executing = FALSE;
memcpy(&cr->rusage, &wpres->rusage, sizeof(wpres->rusage));
cr->start_time.tv_sec = wpres->start.tv_sec;
cr->start_time.tv_usec = wpres->start.tv_usec;
cr->finish_time.tv_sec = wpres->stop.tv_sec;
cr->finish_time.tv_usec = wpres->stop.tv_usec;
if (WIFEXITED(wpres->wait_status)) {
cr->return_code = WEXITSTATUS(wpres->wait_status);
} else {
cr->return_code = STATE_UNKNOWN;
}
if (wpres) {
hst = find_host(cr->host_name);
if (hst) {
hst->is_executing = FALSE;
memcpy(&cr->rusage, &wpres->rusage, sizeof(wpres->rusage));
cr->start_time.tv_sec = wpres->start.tv_sec;
cr->start_time.tv_usec = wpres->start.tv_usec;
cr->finish_time.tv_sec = wpres->stop.tv_sec;
cr->finish_time.tv_usec = wpres->stop.tv_usec;
if (WIFEXITED(wpres->wait_status)) {
cr->return_code = WEXITSTATUS(wpres->wait_status);
} else {
cr->return_code = STATE_UNKNOWN;
}

if (wpres->outstd && *wpres->outstd) {
cr->output = nm_strdup(wpres->outstd);
} else if (wpres->outerr && *wpres->outerr) {
nm_asprintf(&cr->output, "(No output on stdout) stderr: %s", wpres->outerr);
} else {
cr->output = NULL;
}
if (wpres->outstd && *wpres->outstd) {
cr->output = nm_strdup(wpres->outstd);
} else if (wpres->outerr && *wpres->outerr) {
nm_asprintf(&cr->output, "(No output on stdout) stderr: %s", wpres->outerr);
} else {
cr->output = NULL;
}

cr->early_timeout = wpres->early_timeout;
cr->exited_ok = wpres->exited_ok;
cr->engine = NULL;
cr->source = wpres->source;
process_check_result(cr);
cr->early_timeout = wpres->early_timeout;
cr->exited_ok = wpres->exited_ok;
cr->engine = NULL;
cr->source = wpres->source;
process_check_result(cr);
}
}
free_check_result(cr);
nm_free(cr);
Expand Down
7 changes: 6 additions & 1 deletion src/naemon/workers.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ static void run_job_callback(struct wproc_job *job, struct wproc_result *wpres,
{
if (!job || !job->callback)
return;

if (!wpres) {
nm_log(NSLOG_RUNTIME_ERROR, "---!!!--- wpres is null or so TODO REMOVE THIS");
return;
}

(*job->callback)(wpres, job->data, val);
job->callback = NULL;
Expand Down Expand Up @@ -446,7 +451,7 @@ static int handle_worker_result(int sd, int events, void *arg)
nm_log(NSLOG_RUNTIME_ERROR, "wproc: We have have less Core Workers than we should have, trying to respawn Core Worker");

/* Respawn a worker */
if ((ret = spawn_core_worker()) < 0) {
if ((ret = spawn_core_worker()) < 0) {
nm_log(NSLOG_RUNTIME_ERROR, "wproc: Failed to respawn Core Worker");
} else {
nm_log(NSLOG_INFO_MESSAGE, "wproc: Respawning Core Worker %u was successful", ret);
Expand Down

0 comments on commit d6c4c6e

Please sign in to comment.