Skip to content
Snippets Groups Projects
  • Simon McVittie's avatar
    944a376f
    log: Add file descriptor management in _srt_util_set_glib_log_handler() · 944a376f
    Simon McVittie authored
    
    This does a few closely related things.
    
    If standard input, standard output and standard error are closed, we
    open them to point to /dev/null, and if they are close-on-exec, we
    clear their close-on-exec flags. This is to avoid weird side effects:
    most APIs like open() that create new file descriptors guarantee to use
    the lowest-numbered fd that is not already in use, but users of those
    APIs do not expect to be overwriting stdin/stdout/stderr.
    
    Because that operation can involve changing the meaning of stdout and
    stderr, we now optionally save a duplicate of the original standard
    output and standard error, so they can be put back later.
    
    Because we're now saving a duplicate of the original standard output and
    standard error, it also makes sense to implement
    SRT_LOG_FLAGS_DIVERT_STDOUT here. This avoids needing to call
    _srt_divert_stdout_to_stderr() separately in most callers.
    
    Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
    944a376f
    History
    log: Add file descriptor management in _srt_util_set_glib_log_handler()
    Simon McVittie authored
    
    This does a few closely related things.
    
    If standard input, standard output and standard error are closed, we
    open them to point to /dev/null, and if they are close-on-exec, we
    clear their close-on-exec flags. This is to avoid weird side effects:
    most APIs like open() that create new file descriptors guarantee to use
    the lowest-numbered fd that is not already in use, but users of those
    APIs do not expect to be overwriting stdin/stdout/stderr.
    
    Because that operation can involve changing the meaning of stdout and
    stderr, we now optionally save a duplicate of the original standard
    output and standard error, so they can be put back later.
    
    Because we're now saving a duplicate of the original standard output and
    standard error, it also makes sense to implement
    SRT_LOG_FLAGS_DIVERT_STDOUT here. This avoids needing to call
    _srt_divert_stdout_to_stderr() separately in most callers.
    
    Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>