dftracer did not trace fprintf, write on a fileno fd or close on a dup'd fd
PitfallVerified 12 Oct 2026Holds project: dftracer
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
Compared with Darshan or strace, a traced run had no fprintf event, no write on fileno(fp) and only one close for fd plus dup(fd). A later write on a reused fd number was logged under the hash of a closed file.
Cause#
- brahma binds a function only when the dftracer subclass overrides it (
GOTCHA_BINDING_MACRO_IMPLin brahmainclude/brahma/interceptor.h). A base-class method with no override is never hooked. - With
_FORTIFY_SOURCEand optimization,fprintfbecomes__fprintf_chk. brahma needs that name too. fopenandfcloseopen and close the fd inside libc, so the POSIX fd table never sees it. An old entry stays afterfclose.dup,dup2andfcntl(F_DUPFD)did not copy the file hash to the new fd.- brahma had
creat64but notcreatordup3.
Fix#
- brahma: add
creat,dup3,__fprintf_chkand__vfprintf_chk. Declare__vfprintf_chkbefore the__fprintf_chkvarargs macro, because that macro calls it. - dftracer: override
fprintfand the_chknames. Call the real function throughSTDIOBypass.DFTracerLogReentryGuardstops the logger loop. - In
STDIODFTracer::traceandremove_trace, also set the POSIX entry forfileno(fp). Untrack before the realfclose,closeandfreopen. - Copy the hash to the new fd in
dup,dup2,dup3andfcntl(F_DUPFD).
Evidence#
A C program that does fopen, fileno, write, fprintf, fclose, then dup, creat and fdopen, ran with LD_PRELOAD on manylinux_2_28 arm64. Before the fix, the trace had STDIO:fopen STDIO:fileno STDIO:fclose and no write or fprintf. The new test_fd_tracking test (plain and fortify builds) passes with exact counts write=8 close=6 fprintf=1.
Also found by searching
- dftracer trace has no fprintf event but Darshan counts STDIO_WRITES
- write(fileno(fp)) is missing from the dftracer trace
- second close of a dup'd fd is not traced
- write logged under the wrong fhash after fclose and open
- how do I make brahma bind a new libc function