break;
}
if (remaining_wait > 0) {
- sleep(1); /* wait one second */
+ bmicrosleep(1, 0); /* wait one second */
remaining_wait--;
} else {
- stat = ETIME; /* set timeout, if no other status */
+ stat = 1; /* set error status */
+ errno = ETIME; /* set timed out */
wpid = -1;
break; /* don't wait any longer */
}
}
- if (wpid != -1 && WIFEXITED(chldstatus)) {
- stat = WEXITSTATUS(chldstatus);
+ if (wpid > 0) {
+ if (WIFEXITED(chldstatus)) { /* process exit()ed */
+ stat = WEXITSTATUS(chldstatus);
+ } else if (WIFSIGNALED(chldstatus)) { /* process died */
+ stat = 1;
+ }
if (stat != 0) {
- errno = ECHILD;
+ errno = ECHILD; /* set child errno */
}
- }
+ }
if (bpipe->timer_id) {
stop_child_timer(bpipe->timer_id);
}
* Run an external program. Optionally wait a specified number
* of seconds. Program killed if wait exceeded. Optionally
* return the output from the program (normally a single line).
+ *
+ * Contrary to my normal calling conventions, this program
+ *
+ * Returns: 0 on success
+ * non-zero on error
*/
int run_program(char *prog, int wait, POOLMEM *results)
{
}
if (results) {
results[0] = 0;
- stat1 = fgets(results, sizeof_pool_memory(results), bpipe->rfd) != NULL;
+ stat1 = fgets(results, sizeof_pool_memory(results), bpipe->rfd) == NULL;
} else {
- stat1 = 1;
+ stat1 = 0;
}
stat2 = close_bpipe(bpipe);
- return stat1 && stat2;
+ return stat2 != 0 ? stat2 : stat1;
}