Skip to content
  • Alexander Slobodeniuk's avatar
    gmessages: introduce g_log_writer_default_set_debug_domains() · e862f34d
    Alexander Slobodeniuk authored
    The problem is that resetting the environment of a
    proccess is not safe, this is mentioned in the man
    pages of the setenv, and also by the concept:
    when we get a constant string returned by the getenv,
    we need to be guaranteed that this string will exist
    during all that time we are using it. While setting
    the same env var to another value destroys this string
    inside of libc.
    
    Now looking at the should_drop_message(), we can see
    that it just gets the environment on every call. Getting
    the environment is safe, but however there's no safe way
    to switch the logging domains selection: setenv can't be
    used because of the reasons listed above.
    
    That is why g_log_writer_default_set_debug_domains() is
    needed: it's just a safe replacement for the setenv in this case.
    
    Now should_drop_message() still reads the environment, but
    does so only on the first call, after that the domains are
    stored internally, and can only be changed by
    g_log_writer_default_set_debug_domains().
    
    This also means that now resetting G_MESSAGES_DEBUG env
    var in runtime has no effect. But in any case this is not
    what the user should do, because resetting the environment
    in runtime is not correct.
    e862f34d