Skip to content

fix: Convert CMake booleans to C integers for file/console logging flags#859

Merged
Nox-MSFT merged 1 commit intofeature/vnext-deltafrom
henrymorales/logging-fix
Apr 21, 2026
Merged

fix: Convert CMake booleans to C integers for file/console logging flags#859
Nox-MSFT merged 1 commit intofeature/vnext-deltafrom
henrymorales/logging-fix

Conversation

@hmmorales
Copy link
Copy Markdown
Member

@hmmorales hmmorales commented Apr 13, 2026

fix: Convert CMake booleans to C integers for file/console logging flags

🐛 Problem

Commit b7e5e8b0 ("Allow build.sh to disable logging. #796") added #if ADUC_ENABLE_FILE_LOG preprocessor guards in src/logging/zlog/src/init.c, but src/CMakeLists.txt passes the raw CMake boolean:

add_definitions (-DADUC_ENABLE_FILE_LOG=${ADUC_ENABLE_FILE_LOG})  # produces -DADUC_ENABLE_FILE_LOG=ON

In C, #if ON evaluates the undefined identifier ON as 0, silently disabling all file logging at compile time.

Customer impact: No ADU agent log files were created on the vnext\delta branch. Only sw-update.log (written by the swupdate handler's shell script, independent of zlog) was visible.

Note: The customer's du-diagnostics-config.json logPath setting was not a factor — it controls where the diagnostics workflow reads/collects logs, not where the agent writes them (controlled by compile-time ADUC_LOG_FOLDER, default /var/log/adu).


✅ Fix

Changed file: src/CMakeLists.txt

Convert CMake booleans (ON/OFF) to C integers (1/0):

# Before (broken):
add_definitions (-DADUC_ENABLE_FILE_LOG=${ADUC_ENABLE_FILE_LOG})

# After (fixed):
if (ADUC_ENABLE_FILE_LOG)
    add_definitions (-DADUC_ENABLE_FILE_LOG=1)
else ()
    add_definitions (-DADUC_ENABLE_FILE_LOG=0)
endif ()

Same pattern applied to ADUC_ENABLE_CONSOLE_LOG.


📋 Customer follow-up

After rebuilding with this fix, log files will be written to /var/log/adu/. The customer should update their du-diagnostics-config.json logPath to /var/log/adu/ to match, or rebuild with -DADUC_LOG_FOLDER="/adu/logs" to match their existing config.

The ADUC_ENABLE_FILE_LOG and ADUC_ENABLE_CONSOLE_LOG CMake options (ON/OFF)
were passed directly to add_definitions, producing -DADUC_ENABLE_FILE_LOG=ON.
In C, #if ON evaluates the undefined identifier ON as 0, silently disabling
file logging entirely. Convert to 1/0 so the preprocessor guards in
src/logging/zlog/src/init.c work correctly.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@Nox-MSFT Nox-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @hmmorales

@Nox-MSFT Nox-MSFT marked this pull request as ready for review April 21, 2026 22:11
@Nox-MSFT Nox-MSFT merged commit 36c5618 into feature/vnext-delta Apr 21, 2026
12 checks passed
Nox-MSFT added a commit that referenced this pull request Apr 27, 2026
Merge feature/vnext-delta into develop

  New Features

   - Delta Download Handler — Component-based packaging with CacheSourceUpdate API for pre-reboot source file caching, hash verification, and bandwidth savings logging
   - CrossProc Query API SDK — Out-of-proc SDK wrapper with idle pause timer and examples
   - X.509 Certificate Support — Dual certificate auth, interactive demo script, and comprehensive documentation (#763, #764, #770)
   - SWUpdate v2 Handler — Custom extended result codes, workflow-id passthrough, and new Yocto reference scripts
   - V2 Content Downloader Contract — Backward-compatible V2 contract with V1/V2 routing
   - Reboot Synchronization — Lock-based coordination to allow agent cleanup before restart, preventing lost telemetry and state corruption

  Bug Fixes

   - Fix memory leak when initializing zlog multiple times (#801)
   - Fix segmentation fault (#844)
   - Fix double-free in logging library (#843)
   - Fix ARM32 segfault in extension registration — wrong format specifier for long on 32-bit (#841)
   - Fix wrong documentation — off-by-one array access (#808)
   - Fix CMake boolean-to-C conversion silently disabling file logging (#859)
   - Fix feof() bug in system_utils.c causing 0-byte file copies
   - Fix curl downloader default and add connect-timeout with diagnostic logging (#839)
   - Report detailed error result and ExtendedResultCode for failed workflows (#804, #805)

  Platform & Build

   - Add Ubuntu
    24.04 LTS support with GCC 13 (#802)
   - Fix delta library build on Debian 13 / Ubuntu
    24.04 (GCC 14 compatibility)
   - ARM32 compatibility fixes with QEMU-based CI (#841)
   - Docker build matrix: remove Debian 10, add Debian 12
   - Incremental build optimization with hash-based result.h caching
   - Make zlog ref_count thread-safe using atomic operations
   - Shellcheck fixes across all shell scripts (#840)

  Documentation

   - Landing page rewrite with architecture overview, quick-start, and configuration guide
   - 1.2.0 and
    1.3.0-rc1 changelogs
   - Updated platform support and build instructions for all supported distributions

  Validation — Build: 344 targets ✅ | Tests: 702/702 ✅

Co-authored-by: jw-msft <84477130+jw-msft@users.noreply.github.com>
Co-authored-by: AndreRicardo-Zoetis <122284839+AndreRicardo-Zoetis@users.noreply.github.com>
Co-authored-by: Martin Rieva <martin.rieva@zoetis.com>
Co-authored-by: yinaliu <yinaliu@microsoft.com>
Co-authored-by: whereiseva <liuyinan0309@gmail.com>
Co-authored-by: Henry Morales <henrymorales@microsoft.com>
Co-authored-by: hmmorales <100385146+hmmorales@users.noreply.github.com>
Co-authored-by: Dan Mirsky <mirskiy@gmail.com>
Co-authored-by: Daniel Mirsky <danielmirsky@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Chinonso Chukwuogor <nonsochukwuogor@gmail.com>
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.

2 participants