log: check fclose() results and report safely in logging.cpp #33646

pull cedwies wants to merge 1 commits into bitcoin:master from cedwies:log-safe-fclose changing 1 files +50 −15
  1. cedwies commented at 7:06 pm on October 17, 2025: none

    fclose() can report write errors (for example if the disk is full or the filesystem has a problem). Right now, some fclose() calls in src/logging.cpp ignore the return value. This means errors might go unnoticed and log lines could be lost without warning.

    What this PR does:

    • Add a small helper that prints fclose() errors to stderr (with path and errno).
    • In shutdown: close m_fileout safely and report errors.
    • In reopen: open the new file, swap it in, close the old one, and report errors if closing fails.
    • In shrink/rotate: check all fclose(file) calls and report failures.

    No other behavior changes. Normal logging, rotation, and console output remain unchanged.

  2. DrahtBot added the label Utils/log/libs on Oct 17, 2025
  3. DrahtBot commented at 7:06 pm on October 17, 2025: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33646.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #29641 (scripted-diff: Use LogInfo over LogPrintf [WIP, NOMERGE, DRAFT] by maflcko)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  4. cedwies closed this on Oct 17, 2025

  5. cedwies reopened this on Oct 17, 2025

  6. cedwies force-pushed on Oct 17, 2025
  7. log: check fclose() results and report safely
    Some buffered I/O errors surface only on fclose(). Several fclose() calls in
    src/logging.cpp ignored the return value which can risk silent loss of log lines
    or misleading success during rotate/truncate.
    
    Check return of fclose() and include errno in diagnostics. For the active log sink,
    detach under lock and close outside the lock. On failure, report directly
    to stderr (which avoids recursive logging) and flush. No behavior change on success.
    ddfef829f7
  8. cedwies force-pushed on Oct 17, 2025

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2025-10-31 06:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me