#define MAX_ARGV 100
+
+#if !defined(HAVE_WIN32)
static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_arg);
/*
if (mode_write && pipe(writep) == -1) {
save_errno = errno;
free(bpipe);
- errno = save_errno;
free_pool_memory(tprog);
+ errno = save_errno;
return NULL;
}
if (mode_read && pipe(readp) == -1) {
close(writep[1]);
}
free(bpipe);
- errno = save_errno;
free_pool_memory(tprog);
+ errno = save_errno;
return NULL;
}
/* Start worker process */
close(readp[1]);
}
free(bpipe);
- errno = save_errno;
free_pool_memory(tprog);
+ errno = save_errno;
return NULL;
case 0: /* child */
#ifndef HAVE_WIN32
stat = WTERMSIG(chldstatus);
#else
-#warning "WTERMSIG undefined in Win32 !!!"
+ stat = 1; /* fake child status */
#endif
Dmsg1(800, "Child died from signal %d\n", stat);
stat |= b_errno_signal; /* exit signal returned */
stop_child_timer(bpipe->timer_id);
}
free(bpipe);
- Dmsg1(800, "returning stat = %d\n", stat);
+ Dmsg2(800, "returning stat=%d,%d\n", stat & ~(b_errno_exit|b_errno_signal), stat);
return stat;
}
+/*
+ * Build argc and argv from a string
+ */
+static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_argv)
+{
+ int i;
+ char *p, *q, quote;
+ int argc = 0;
+
+ argc = 0;
+ for (i=0; i<max_argv; i++)
+ bargv[i] = NULL;
+
+ p = cmd;
+ quote = 0;
+ while (*p && (*p == ' ' || *p == '\t'))
+ p++;
+ if (*p == '\"' || *p == '\'') {
+ quote = *p;
+ p++;
+ }
+ if (*p) {
+ while (*p && argc < MAX_ARGV) {
+ q = p;
+ if (quote) {
+ while (*q && *q != quote)
+ q++;
+ quote = 0;
+ } else {
+ while (*q && *q != ' ')
+ q++;
+ }
+ if (*q)
+ *(q++) = '\0';
+ bargv[argc++] = p;
+ p = q;
+ while (*p && (*p == ' ' || *p == '\t'))
+ p++;
+ if (*p == '\"' || *p == '\'') {
+ quote = *p;
+ p++;
+ }
+ }
+ }
+ *bargc = argc;
+}
+#endif /* HAVE_WIN32 */
/*
* Run an external program. Optionally wait a specified number
break;
} else if (stat1 != 0) {
Dmsg1(900, "Run program fgets stat=%d\n", stat1);
- if (bpipe->timer_id) {
- Dmsg1(150, "Run program fgets killed=%d\n", bpipe->timer_id->killed);
- if (bpipe->timer_id->killed) {
- pm_strcat(tmp, _("Program killed by Bacula watchdog (timeout)\n"));
- stat1 = ETIME;
- break;
- }
+ if (bpipe->timer_id && bpipe->timer_id->killed) {
+ Dmsg1(250, "Run program saw fgets killed=%d\n", bpipe->timer_id->killed);
+ break;
}
}
}
+ /*
+ * We always check whether the timer killed the program. We would see
+ * an eof even when it does so we just have to trust the killed flag
+ * and set the timer values to avoid edge cases where the program ends
+ * just as the timer kills it.
+ */
+ if (bpipe->timer_id && bpipe->timer_id->killed) {
+ Dmsg1(150, "Run program fgets killed=%d\n", bpipe->timer_id->killed);
+ pm_strcat(tmp, _("Program killed by Bacula watchdog (timeout)\n"));
+ stat1 = ETIME;
+ }
int len = sizeof_pool_memory(results) - 1;
bstrncpy(results, tmp, len);
Dmsg3(1900, "resadr=0x%x reslen=%d res=%s\n", results, strlen(results), results);
free(buf);
return stat1;
}
-
-/*
- * Build argc and argv from a string
- */
-static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_argv)
-{
- int i;
- char *p, *q, quote;
- int argc = 0;
-
- argc = 0;
- for (i=0; i<max_argv; i++)
- bargv[i] = NULL;
-
- p = cmd;
- quote = 0;
- while (*p && (*p == ' ' || *p == '\t'))
- p++;
- if (*p == '\"' || *p == '\'') {
- quote = *p;
- p++;
- }
- if (*p) {
- while (*p && argc < MAX_ARGV) {
- q = p;
- if (quote) {
- while (*q && *q != quote)
- q++;
- quote = 0;
- } else {
- while (*q && *q != ' ')
- q++;
- }
- if (*q)
- *(q++) = '\0';
- bargv[argc++] = p;
- p = q;
- while (*p && (*p == ' ' || *p == '\t'))
- p++;
- if (*p == '\"' || *p == '\'') {
- quote = *p;
- p++;
- }
- }
- }
- *bargc = argc;
-}