From a8386d83021d9d3552ed4afdcc887918ab02e772 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sun, 29 Dec 2002 21:47:09 +0000 Subject: [PATCH] FreeBSD child status code kludge git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@255 91ce42f0-d328-0410-95d8-f526ca767f89 --- bacula/src/lib/bpipe.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/bacula/src/lib/bpipe.c b/bacula/src/lib/bpipe.c index dd3827edb6..fdb3f634fa 100644 --- a/bacula/src/lib/bpipe.c +++ b/bacula/src/lib/bpipe.c @@ -120,6 +120,7 @@ int close_wpipe(BPIPE *bpipe) int stat = 1; if (bpipe->wfd) { + fflush(bpipe->wfd); if (fclose(bpipe->wfd) != 0) { stat = 0; } @@ -132,9 +133,11 @@ int close_wpipe(BPIPE *bpipe) int close_bpipe(BPIPE *bpipe) { int chldstatus = 0; - int stat = ETIME; + int stat = 0; int wait_option; int remaining_wait; + pid_t wpid = 0; + /* Close pipes */ if (bpipe->rfd) { @@ -155,7 +158,6 @@ int close_bpipe(BPIPE *bpipe) /* wait for worker child to exit */ for ( ;; ) { - pid_t wpid; wpid = waitpid(bpipe->worker_pid, &chldstatus, wait_option); if (wpid == bpipe->worker_pid || (wpid == -1 && errno != EINTR)) { break; @@ -164,16 +166,21 @@ int close_bpipe(BPIPE *bpipe) sleep(1); /* wait one second */ remaining_wait--; } else { + stat = ETIME; /* set timeout, if no other status */ + wpid = -1; break; /* don't wait any longer */ } } - if (WIFEXITED(chldstatus)) { + if (wpid != -1 && WIFEXITED(chldstatus)) { stat = WEXITSTATUS(chldstatus); } if (bpipe->timer_id) { stop_child_timer(bpipe->timer_id); } free(bpipe); +#ifdef HAVE_FREEBSD_OS + stat = 0; /* kludge because FreeBSD doesn't seem to return valid status */ +#endif return stat; } -- 2.39.2