Skip to content

Conversation

@miketweaver
Copy link

@miketweaver miketweaver commented Nov 28, 2025

Problem

On modern 32-bit Linux systems (Raspberry Pi with recent Debian/Raspbian),
the logging system produces corrupted log files with garbage filenames and
timestamps. The /jl API endpoint returns empty results even though log
files exist in the logs/ directory.

Root Cause

Since glibc 2.34, time_t is 64-bit on 32-bit systems to address the
year 2038 problem. The logging code passes time_os_t (which is time_t)
directly to snprintf with %lu format specifier, which expects 32-bit
unsigned long. This type mismatch causes undefined behavior.

Symptoms

  • Log files created with incorrect names (e.g., 5212016.txt instead of 20420.txt)
  • Timestamps in log entries are garbage values
  • /jl?hist=7 API returns [] because expected filenames don't exist
  • Issue manifests on 32-bit ARM Linux with glibc >= 2.34

Solution

Explicitly cast time_os_t values to unsigned long before passing to
snprintf with %lu:

// Before

snprintf(tmp_buffer, TMP_BUFFER_SIZE, "%lu", curr_time / 86400);

// After

snprintf(tmp_buffer, TMP_BUFFER_SIZE, "%lu", (unsigned long)(curr_time / 86400));

Tested on:

  • Raspberry Pi (armv7l, 32-bit)
  • Debian (dietpi) with glibc 2.41
  • Confirmed log files now have correct day-based filenames
  • Confirmed /jl API returns expected log entries

This should be tested on other devices to make sure it doesn't break it for those other devices. I only have this one raspberry pi so it's all I could test with.

On modern 32-bit Linux systems (glibc 2.34+), time_t is 64-bit to avoid the year 2038 problem. However, the logging code used %lu format specifier which expects 32-bit unsigned long, causing undefined behavior when printing 64-bit time values.

This resulted in:
- Log files created with garbage filenames (e.g., "5212016.txt" instead of "20420.txt")
- Corrupted timestamps in log entries
- API returning empty results because it couldn't find files matching the expected day-based naming scheme

Fix by explicitly casting time_os_t values to unsigned long before
passing to snprintf with %lu format specifier.

Affected systems: 32-bit ARM Linux (armv7l) with glibc >= 2.34
Tested on: Raspberry Pi with Debian glibc 2.41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant