summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
614259f)
The current mix of writing to an fd doesn't mix as well with
stderr/stdout. And writing to a FILE * is more portable.
enum failtest_result (*failtest_hook)(struct tlist_calls *);
enum failtest_result (*failtest_hook)(struct tlist_calls *);
-static int tracefd = -1;
+static FILE *tracef = NULL, *warnf;
static int traceindent = 0;
static int traceindent = 0;
unsigned int failtest_timeout_ms = 20000;
unsigned int failtest_timeout_ms = 20000;
-static void warn_via_fd(int e, const char *fmt, va_list ap)
+static void do_warn(int e, const char *fmt, va_list ap)
{
char *p = failpath_string();
{
char *p = failpath_string();
- vdprintf(warnfd, fmt, ap);
+ vfprintf(warnf, fmt, ap);
- dprintf(warnfd, ": %s", strerror(e));
- dprintf(warnfd, " [%s]\n", p);
+ fprintf(warnf, ": %s", strerror(e));
+ fprintf(warnf, " [%s]\n", p);
int e = errno;
va_start(ap, fmt);
int e = errno;
va_start(ap, fmt);
- warn_via_fd(e, fmt, ap);
va_list ap;
va_start(ap, fmt);
va_list ap;
va_start(ap, fmt);
- warn_via_fd(-1, fmt, ap);
{
va_list ap;
unsigned int i;
{
va_list ap;
unsigned int i;
+ char *p;
+ static int idx;
return;
for (i = 0; i < traceindent; i++)
return;
for (i = 0; i < traceindent; i++)
- dprintf(tracefd, "%u: ", getpid());
+ p = failpath_string();
+ fprintf(tracef, "%i: %u: %s ", idx++, getpid(), p);
- vdprintf(tracefd, fmt, ap);
+ vfprintf(tracef, fmt, ap);
/* Prevent double-printing (in child and parent) */
fflush(stdout);
/* Prevent double-printing (in child and parent) */
fflush(stdout);
+ fflush(warnf);
+ if (tracef)
+ fflush(tracef);
child = fork();
if (child == -1)
err(1, "forking failed");
if (child == 0) {
traceindent++;
child = fork();
if (child == -1)
err(1, "forking failed");
if (child == 0) {
traceindent++;
struct timeval diff;
const char *p;
char *failpath;
struct timeval diff;
const char *p;
char *failpath;
c = tlist_tail(&history, struct failtest_call, list);
diff = time_sub(time_now(), start);
failpath = failpath_string();
c = tlist_tail(&history, struct failtest_call, list);
diff = time_sub(time_now(), start);
failpath = failpath_string();
- trace("%u->%u (%u.%02u): %s (", getppid(), getpid(),
- (int)diff.tv_sec, (int)diff.tv_usec / 10000,
- failpath);
- free(failpath);
p = strrchr(c->file, '/');
if (p)
p = strrchr(c->file, '/');
if (p)
- trace("%s", c->file);
- trace(":%u)\n", c->line);
+ p = c->file;
+ trace("%u->%u (%u.%02u): %s (%s:%u)\n",
+ getppid(), getpid(),
+ (int)diff.tv_sec, (int)diff.tv_usec / 10000,
+ failpath, p, c->line);
+ free(failpath);
}
/* From here on, we have to clean up! */
our_history_start = tlist_tail(&history, struct failtest_call,
}
/* From here on, we have to clean up! */
our_history_start = tlist_tail(&history, struct failtest_call,
close(control[0]);
close(output[0]);
/* Don't swallow stderr if we're tracing. */
close(control[0]);
close(output[0]);
/* Don't swallow stderr if we're tracing. */
dup2(output[1], STDOUT_FILENO);
dup2(output[1], STDERR_FILENO);
if (output[1] != STDOUT_FILENO
dup2(output[1], STDOUT_FILENO);
dup2(output[1], STDERR_FILENO);
if (output[1] != STDOUT_FILENO
- warnfd = move_fd_to_high(dup(STDERR_FILENO));
+ warnf = fdopen(move_fd_to_high(dup(STDERR_FILENO)), "w");
for (i = 1; i < argc; i++) {
if (!strncmp(argv[i], "--failpath=", strlen("--failpath="))) {
failpath = argv[i] + strlen("--failpath=");
} else if (strcmp(argv[i], "--trace") == 0) {
for (i = 1; i < argc; i++) {
if (!strncmp(argv[i], "--failpath=", strlen("--failpath="))) {
failpath = argv[i] + strlen("--failpath=");
} else if (strcmp(argv[i], "--trace") == 0) {
failtest_timeout_ms = -1;
} else if (!strncmp(argv[i], "--debugpath=",
strlen("--debugpath="))) {
failtest_timeout_ms = -1;
} else if (!strncmp(argv[i], "--debugpath=",
strlen("--debugpath="))) {