wslog: Check fileno() for errors

fileno() can fail and GLib will assert on negative fd.

Fixes #18684.
This commit is contained in:
João Valverde 2022-11-29 15:41:20 +00:00
parent 129ed6d4c4
commit 7336190bbc
1 changed files with 5 additions and 2 deletions

View File

@ -822,6 +822,7 @@ void ws_log_init(const char *progname,
void (*vcmdarg_err)(const char *, va_list ap))
{
const char *env;
int fd;
if (progname != NULL) {
registered_progname = progname;
@ -830,8 +831,10 @@ void ws_log_init(const char *progname,
current_log_level = DEFAULT_LOG_LEVEL;
stdout_color_enabled = g_log_writer_supports_color(fileno(stdout));
stderr_color_enabled = g_log_writer_supports_color(fileno(stderr));
if ((fd = fileno(stdout)) >= 0)
stdout_color_enabled = g_log_writer_supports_color(fd);
if ((fd = fileno(stderr)) >= 0)
stderr_color_enabled = g_log_writer_supports_color(fd);
/* Set the GLib log handler for the default domain. */
g_log_set_handler(NULL, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL,