Skip to content
  • Paolo Bonzini's avatar
    59bde213
    util/log: do not close and reopen log files when flags are turned off · 59bde213
    Paolo Bonzini authored
    
    
    log_append makes sure that if you turn off the logging (which clears
    log_flags and makes need_to_open_file false) the old log is not
    overwritten.  The usecase is that if you remove or move the file
    QEMU will not keep writing to the old file.  However, this is
    not always the desited behavior, in particular having log_append==1
    after changing the file name makes little sense.
    
    When qemu_set_log_internal is called from the logfile monitor
    command, filename must be non-NULL and therefore changed_name must
    be true.  Therefore, the only case where the file is closed and
    need_to_open_file == false is indeed when log_flags becomes
    zero.  In this case, just flush the file and do not bother
    closing it, thus faking the same append behavior as previously.
    
    The behavioral change is that changing the logfile twice, for
    example log1 -> log2 -> log1, will cause log1 to be overwritten.
    This can simply be documented, since it is not a particularly
    surprising behavior.
    
    Suggested-by: default avatarAlex Bennée <alex.bennee@linaro.org>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
    Reviewed-by: default avatarGreg Kurz <groug@kaod.org>
    Message-Id: <20221025092119.236224-1-pbonzini@redhat.com>
    [groug: nullify global_file before actually closing the file]
    Signed-off-by: default avatarGreg Kurz <groug@kaod.org>
    Message-Id: <20221108140032.1460307-2-groug@kaod.org>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    59bde213
    util/log: do not close and reopen log files when flags are turned off
    Paolo Bonzini authored
    
    
    log_append makes sure that if you turn off the logging (which clears
    log_flags and makes need_to_open_file false) the old log is not
    overwritten.  The usecase is that if you remove or move the file
    QEMU will not keep writing to the old file.  However, this is
    not always the desited behavior, in particular having log_append==1
    after changing the file name makes little sense.
    
    When qemu_set_log_internal is called from the logfile monitor
    command, filename must be non-NULL and therefore changed_name must
    be true.  Therefore, the only case where the file is closed and
    need_to_open_file == false is indeed when log_flags becomes
    zero.  In this case, just flush the file and do not bother
    closing it, thus faking the same append behavior as previously.
    
    The behavioral change is that changing the logfile twice, for
    example log1 -> log2 -> log1, will cause log1 to be overwritten.
    This can simply be documented, since it is not a particularly
    surprising behavior.
    
    Suggested-by: default avatarAlex Bennée <alex.bennee@linaro.org>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
    Reviewed-by: default avatarGreg Kurz <groug@kaod.org>
    Message-Id: <20221025092119.236224-1-pbonzini@redhat.com>
    [groug: nullify global_file before actually closing the file]
    Signed-off-by: default avatarGreg Kurz <groug@kaod.org>
    Message-Id: <20221108140032.1460307-2-groug@kaod.org>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Loading