Commit 7859e954 authored by Rusty Russell's avatar Rusty Russell

failtest: report errors in children directly to original stderr.

This is useful for debugging failtest itself, as well as for things
like tracing.
parent 163daaf4
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
enum failtest_result (*failtest_hook)(struct tlist_calls *); enum failtest_result (*failtest_hook)(struct tlist_calls *);
static int tracefd = -1; static int tracefd = -1;
static int warnfd;
unsigned int failtest_timeout_ms = 20000; unsigned int failtest_timeout_ms = 20000;
...@@ -150,6 +151,37 @@ static char *failpath_string(void) ...@@ -150,6 +151,37 @@ static char *failpath_string(void)
return ret; return ret;
} }
static void warn_via_fd(int e, const char *fmt, va_list ap)
{
char *p = failpath_string();
vdprintf(warnfd, fmt, ap);
if (e != -1)
dprintf(warnfd, ": %s", strerror(e));
dprintf(warnfd, " [%s]\n", p);
free(p);
}
static void fwarn(const char *fmt, ...)
{
va_list ap;
int e = errno;
va_start(ap, fmt);
warn_via_fd(e, fmt, ap);
va_end(ap);
}
static void fwarnx(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
warn_via_fd(-1, fmt, ap);
va_end(ap);
}
static void tell_parent(enum info_type type) static void tell_parent(enum info_type type)
{ {
if (control_fd != -1) if (control_fd != -1)
...@@ -1085,12 +1117,13 @@ void failtest_init(int argc, char *argv[]) ...@@ -1085,12 +1117,13 @@ void failtest_init(int argc, char *argv[])
unsigned int i; unsigned int i;
orig_pid = getpid(); orig_pid = getpid();
warnfd = move_fd_to_high(dup(STDERR_FILENO));
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (!strncmp(argv[i], "--failpath=", strlen("--failpath="))) { if (!strncmp(argv[i], "--failpath=", strlen("--failpath="))) {
failpath = argv[i] + strlen("--failpath="); failpath = argv[i] + strlen("--failpath=");
} else if (strcmp(argv[i], "--tracepath") == 0) { } else if (strcmp(argv[i], "--tracepath") == 0) {
tracefd = move_fd_to_high(STDERR_FILENO); tracefd = warnfd;
failtest_timeout_ms = -1; failtest_timeout_ms = -1;
} else if (!strncmp(argv[i], "--debugpath=", } else if (!strncmp(argv[i], "--debugpath=",
strlen("--debugpath="))) { strlen("--debugpath="))) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment