If we're metadumping to stdout, we don't want xfs_db's various dbprintf
statements dumping to stdout because that'll corrupt the metadump.
Therefore, let outf point to the existing stdout and redirect stdout to
stderr for the duration of the dump operation.
Reported-by: David Shaw <dshaw@jabberwocky.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
xfs_agnumber_t agno;
int c;
int start_iocur_sp;
+ bool stdout_metadump = false;
char *p;
exitcode = 1;
free(metablock);
return 0;
}
+ /*
+ * Redirect stdout to stderr for the duration of the
+ * metadump operation so that dbprintf and other messages
+ * are sent to the console instead of polluting the
+ * metadump stream.
+ */
outf = stdout;
+ stdout = stderr;
+ stdout_metadump = true;
} else {
outf = fopen(argv[optind], "wb");
if (outf == NULL) {
exitcode = write_index() < 0;
if (progress_since_warning)
- fputc('\n', (outf == stdout) ? stderr : stdout);
+ fputc('\n', stdout_metadump ? stderr : stdout);
- if (outf != stdout)
+ if (stdout_metadump)
+ stdout = outf;
+ else
fclose(outf);
/* cleanup iocur stack */