* Version $Id$
*/
/*
- Copyright (C) 2002-2005 Kern Sibbald
+ Copyright (C) 2002-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#include "bacula.h"
#include "jcr.h"
-int execvp_errors[] = {EACCES, ENOEXEC, EFAULT, EINTR, E2BIG,
- ENAMETOOLONG, ENOMEM, ETXTBSY, ENOENT};
+int execvp_errors[] = {
+ EACCES,
+ ENOEXEC,
+ EFAULT,
+ EINTR,
+ E2BIG,
+ ENAMETOOLONG,
+ ENOMEM,
+#ifndef HAVE_WIN32
+ ETXTBSY,
+#endif
+ ENOENT
+};
int num_execvp_errors = (int)(sizeof(execvp_errors)/sizeof(int));
#define MAX_ARGV 100
+
+#if !defined(HAVE_WIN32)
static void build_argc_argv(char *cmd, int *bargc, char *bargv[], int max_arg);
/*
printf("argc=%d argv=%s:\n", i, bargv[i]);
}
#endif
- free_pool_memory(tprog);
/* Each pipe is one way, write one end, read the other, so we need two */
if (mode_write && pipe(writep) == -1) {
save_errno = errno;
free(bpipe);
+ free_pool_memory(tprog);
errno = save_errno;
return NULL;
}
close(writep[1]);
}
free(bpipe);
+ free_pool_memory(tprog);
errno = save_errno;
return NULL;
}
close(readp[1]);
}
free(bpipe);
+ free_pool_memory(tprog);
errno = save_errno;
return NULL;
}
exit(255); /* unknown errno */
-
-
default: /* parent */
break;
}
+ free_pool_memory(tprog);
if (mode_read) {
close(readp[1]); /* close unused parent fds */
bpipe->rfd = fdopen(readp[0], "r"); /* open file descriptor */
}
Dmsg1(800, "child status=%d\n", stat & ~b_errno_exit);
} else if (WIFSIGNALED(chldstatus)) { /* process died */
+#ifndef HAVE_WIN32
stat = WTERMSIG(chldstatus);
- Dmsg1(800, "Child died from signale %d\n", stat);
+#else
+ 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;
-}