Skip to content

Commit f63b799

Browse files
committed
message: cache color settings before async start
The async log drain could be the first caller to inspect NO_COLOR and TERM while startup was still able to clear MAGIC through file_init(). Environment reads and updates are not safely synchronized. Resolve and cache the stderr color decision in message_async_start() before creating the drain thread. Subsequent drain output uses the cached result, avoiding concurrent environment access without changing startup ordering.
1 parent 61e6f26 commit f63b799

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/library/message.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ int message_async_start(void)
464464
memory_order_relaxed) != LOG_ASYNC_OFF)
465465
return 0;
466466

467+
/* file_init() clears MAGIC later in startup. Cache the stderr color
468+
* environment before the drain thread can read it concurrently. */
469+
if (message_mode == MSG_STDERR)
470+
(void)stderr_color_enabled();
471+
467472
if (sem_init(&log_sem, 0, 0))
468473
return errno;
469474

0 commit comments

Comments
 (0)