Subject: Re: [bug#72536] [PATCH v3] tap: new `--stderr-prefix' option to prefix test script's stderr

From: Jacob Bachmeyer <[email-masked]>
Date: Fri, 21 Feb 2025 18:40:27 -0600

On 2/21/25 18:21, Richard Hansen wrote:
> On 2/20/25 19:29, Jacob Bachmeyer wrote:
>> Could we filter both stdout and stderr through functions that 
>> timestamp each line, then merge the two and sort on the timestamps?
>
> Unfortunately this wouldn't help---it would be subject to the same 
> reordering race condition.  The timestamp value that is added to a 
> line would depend on when the kernel woke up the reading 
> thread/process, so the timestamps wouldn't always accurately represent 
> the time the test program wrote the line.  If the kernel woke up the 
> stderr and stdout threads in the opposite order of writing, then the 
> timestamps would be in the wrong order.

Now we are getting into the "crazy hack" category, but how about an 
LD_PRELOAD module that gets put in the test process and wraps write(3) 
to add timestamps?

On systems with GNU libc, that module could replace stdout and stderr 
with custom streams that prepend timestamps to the start of each line 
before calling write(2).

For an even crazier (but even less portable) hack, I seem to recall that 
there is a way to attach a BPF program to a process as a syscall filter 
in current Linux kernels.  Could we use *that* to wrap write(2) and add 
timestamps?  :-)

-- Jacob