diff options
| author | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-02 16:36:42 +0000 |
|---|---|---|
| committer | bitflash-maintainer <noreply@bitflash.invalid> | 2026-09-02 16:36:42 +0000 |
| commit | 123ae2e017d90fd18b291db3d76033781c1ead84 (patch) | |
| tree | 691c494b9d19c28f9bc1ad7c128d8083c55a870c /src/util.h | |
| parent | 2661de141e46dadfb2903bb12e72dc87c5a64375 (diff) | |
log: measure the debug log with a size type that can hold it
GetFilesize() returned int while ftell() returns long, so a debug.log of
2 GiB or more came back negative. Its only caller is the -maxdebugfilesize
roll added in ae1c6a7, which skips the roll on a negative size: the
rotation written for issue #34 would have switched itself off permanently
at exactly the size it exists to prevent. Production was at 1.95 GiB
growing 51-129 MB/day, about a day short of crossing 2 GiB.
The same truncation capped the comparison at INT_MAX (2047.99 MB), so
-maxdebugfilesize=2048 or higher could never be exceeded and disabled
rotation outright. Both failures were silent.
Widen the return to int64 and seek with ftello/fseeko (_ftelli64 and
_fseeki64 on Windows). The roll in util.h is the function's only caller
in the tree, so no other behaviour changes. A 32-bit off_t would
reintroduce the same truncation, so its width is now a compile-time
assertion rather than a silent runtime surprise.
Diffstat (limited to 'src/util.h')
| -rw-r--r-- | src/util.h | 6 |
1 files changed, 3 insertions, 3 deletions
| @@ -154,7 +154,7 @@ void ParseString(const string& str, char c, vector<string>& v); | |||
| 154 | string FormatMoney(int64 n, bool fPlus=false); | 154 | string FormatMoney(int64 n, bool fPlus=false); |
| 155 | bool ParseMoney(const char* pszIn, int64& nRet); | 155 | bool ParseMoney(const char* pszIn, int64& nRet); |
| 156 | bool FileExists(const char* psz); | 156 | bool FileExists(const char* psz); |
| 157 | int GetFilesize(FILE* file); | 157 | int64 GetFilesize(FILE* file); |
| 158 | uint64 GetRand(uint64 nMax); | 158 | uint64 GetRand(uint64 nMax); |
| 159 | int64 GetTime(); | 159 | int64 GetTime(); |
| 160 | int64 GetAdjustedTime(); | 160 | int64 GetAdjustedTime(); |
| @@ -410,8 +410,8 @@ inline int OutputDebugStringF(const char* pszFormat, ...) | |||
| 410 | // so a rename is safe here: the next line simply reopens the | 410 | // so a rename is safe here: the next line simply reopens the |
| 411 | // path. One generation is kept as debug.log.old; logrotate | 411 | // path. One generation is kept as debug.log.old; logrotate |
| 412 | // (contrib/logrotate/) handles anything longer-term. | 412 | // (contrib/logrotate/) handles anything longer-term. |
| 413 | int nSize = GetFilesize(fileout); | 413 | int64 nSize = GetFilesize(fileout); |
| 414 | if (nSize >= 0 && (int64)nSize > nMaxDebugFileSize) | 414 | if (nSize >= 0 && nSize > nMaxDebugFileSize) |
| 415 | { | 415 | { |
| 416 | fclose(fileout); | 416 | fclose(fileout); |
| 417 | string strOldFile = strDebugFile + ".old"; | 417 | string strOldFile = strDebugFile + ".old"; |