wslog: Fix initialization with invalid environment

We can't write to stderr outside of the default writer context.
Wireshark and tshark will block if we do that and dumpcap is
running as capture child.
This commit is contained in:
João Valverde 2021-06-24 02:18:03 +01:00
parent eb3417e38f
commit a370024ca9
1 changed files with 11 additions and 6 deletions

View File

@ -526,6 +526,11 @@ enum ws_log_level ws_log_set_fatal_str(const char *str_level)
}
/*
* We can't write to stderr in ws_log_init() because dumpcap uses stderr
* to communicate with the parent and it will block. Any failures are
* therefore ignored.
*/
void ws_log_init(const char *progname, ws_log_writer_cb *writer)
{
const char *env;
@ -552,17 +557,17 @@ void ws_log_init(const char *progname, ws_log_writer_cb *writer)
current_log_level = DEFAULT_LOG_LEVEL;
env = g_getenv(ENV_VAR_LEVEL);
if (env != NULL && ws_log_set_level_str(env) == LOG_LEVEL_NONE)
fprintf(stderr, "Ignoring invalid environment value %s=\"%s\".\n", ENV_VAR_LEVEL, env);
if (env != NULL)
ws_log_set_level_str(env);
env = g_getenv(ENV_VAR_FATAL);
if (env != NULL)
ws_log_set_fatal_str(env);
env = g_getenv(ENV_VAR_DOMAINS);
if (env != NULL)
ws_log_set_domain_filter(env);
env = g_getenv(ENV_VAR_FATAL);
if (env != NULL && ws_log_set_fatal_str(env) == LOG_LEVEL_NONE)
fprintf(stderr, "Ignoring invalid environment value %s=\"%s\".\n", ENV_VAR_FATAL, env);
env = g_getenv(ENV_VAR_DEBUG);
if (env != NULL)
ws_log_set_debug_filter(env);