~sircmpwn/gmni#22: 
Status line printed after body

Hello,

When using gmni -i, I find that the status line is printed after the body if the output is not a TTY.

Example:

$ gmni -i gemini://celehner.com/hi.txt
20 text/plain
Hello, world!
$ gmni -i gemini://celehner.com/hi.txt | cat
Hello, world!
20 text/plain
Status
RESOLVED FIXED
Submitter
~cel
Assigned to
No-one
Submitted
3 years ago
Updated
3 years ago
Labels
No labels applied.

~ecs 3 years ago

Cannot reproduce:

$ git log --oneline | head -n1
174fbd5 Fix memory leaks
$ git status -s # No output means no local changes
$ make clean all >/dev/null
$ ./gmni -i gemini://celehner.com/hi.txt | cat
20 text/plain
Hello, world!

~cel 3 years ago

Still happens for me on 174fbd5. Using Debian Testing, x64_64, glibc, bash.

It is because of mixing write with buffered I/O (printf). The text output with printf ends up buffered until after the body is already written. Any of the following should fix it:

  • Disable output buffering: setvbuf(stdout, NULL, _IONBF, 0)
  • Call fflush(stdout) after each printf before write
  • Use unbuffered formatted output functions to print status line: dprintf instead of printf
  • Use buffered I/O to write body: fwrite instead of write

~sircmpwn REPORTED FIXED 3 years ago

~cel 3 years ago

Ticket resolved: fixed

Thanks, ~sircmpwn

~sircmpwn 3 years ago

Thank ~ecs, he wrote the patch

~cel 3 years ago

Thanks, ~ecs!

Register here or Log in to comment, or comment via email.