Skip to content

Commit

Permalink
Make stderr line-buffered for logging
Browse files Browse the repository at this point in the history
qrexec_logv uses several separate fprintf() calls for a single message.
Since stderr is unbuffered by default, this sometimes leads to
splitting one log message with another. Avoid the issue by turning
stderr into line-buffered mode.
Documentation for setlinebuf() (or more precisely - for underlying
setvbuf()) says it can be called only after opening the stream but
before any other operation. Since setup_logging() is called as the first
thing in main(), it should be okay.
  • Loading branch information
marmarek committed May 28, 2024
1 parent 1e05472 commit 6760cfa
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libqrexec/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@ void setup_logging(const char *program_name) {
errx(125, "File descriptor %d is closed, cannot continue", i);
}

/* qrexec_logv() uses several separate fprintf calls, print them at once */
errno = 0;
if (setvbuf(stderr, NULL, _IOLBF, 0))
warn("Failed to enable line buffering on stderr");

Check warning on line 94 in libqrexec/log.c

View check run for this annotation

Codecov / codecov/patch

libqrexec/log.c#L94

Added line #L94 was not covered by tests

qrexec_program_name = program_name;
}

0 comments on commit 6760cfa

Please sign in to comment.