Skip to content

Fix timezone refresh issue (issue #424)#172

Open
rgerhards wants to merge 3 commits intomainfrom
bugfix-issue-424-tz-refresh-16606718362046625825
Open

Fix timezone refresh issue (issue #424)#172
rgerhards wants to merge 3 commits intomainfrom
bugfix-issue-424-tz-refresh-16606718362046625825

Conversation

@rgerhards
Copy link
Owner

Implement periodic timezone update using tzset() protected by a read-write lock.
Replace localtime_r calls with thread-safe datetime.sys_localtime_r wrapper.
This ensures rsyslog detects system timezone changes (e.g. /etc/localtime) without restart.
The check is performed every 5 minutes.


PR created automatically by Jules for task 16606718362046625825 started by @rgerhards

Implement periodic timezone update using `tzset()` protected by a read-write lock.
Replace `localtime_r` calls with thread-safe `datetime.sys_localtime_r` wrapper.
This ensures rsyslog detects system timezone changes (e.g. `/etc/localtime`) without restart.
The check is performed every 5 minutes.

Reference: rsyslog#424

Co-authored-by: rgerhards <1482123+rgerhards@users.noreply.github.com>
@google-labs-jules
Copy link

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link

Summary of Changes

Hello @rgerhards, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a long-standing issue where rsyslog failed to detect system timezone changes without a restart. It introduces a robust, thread-safe mechanism to periodically refresh timezone information by wrapping localtime_r calls and utilizing tzset() under a read-write lock. This ensures that rsyslog instances running for extended periods will correctly reflect any modifications to the system's timezone settings, enhancing operational reliability and reducing the need for manual intervention.

Highlights

  • Thread-Safe Timezone Handling: Introduced a new thread-safe wrapper, datetime.sys_localtime_r, to replace direct localtime_r calls across various modules, ensuring consistent and safe time conversions.
  • Periodic Timezone Updates: Implemented a mechanism within the datetime module to periodically refresh system timezone information using tzset(), protected by a read-write lock.
  • Dynamic Timezone Detection: Configured the main rsyslog daemon loop to trigger these timezone updates at least every 5 minutes, allowing rsyslog to detect and adapt to system timezone changes without requiring a restart.
  • Centralized Time Management: Centralized timezone management within the datetime module, exposing new functions (updateTimezone and sys_localtime_r) through its interface.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • contrib/imtuxedoulog/imtuxedoulog.c
    • Included the datetime.h header.
    • Declared and used the datetime object interface.
    • Replaced localtime_r with datetime.sys_localtime_r for time conversions.
  • plugins/impstats/impstats.c
    • Included the datetime.h header.
    • Declared and used the datetime object interface.
    • Replaced localtime_r with datetime.sys_localtime_r for time conversions.
  • runtime/datetime.c
    • Included pthread.h for thread synchronization primitives.
    • Added a pthread_rwlock_t named mutClock to protect timezone data.
    • Implemented sys_localtime_r to provide a thread-safe wrapper around localtime_r using a read lock.
    • Implemented updateTimezone to call tzset() under a write lock.
    • Replaced an internal localtime_r call with sys_localtime_r.
    • Initialized and destroyed the mutClock read-write lock during module initialization and exit.
    • Exposed sys_localtime_r and updateTimezone through the datetime object interface.
  • runtime/datetime.h
    • Included time.h for time-related definitions.
    • Added updateTimezone and sys_localtime_r function pointers to the datetime interface.
    • Incremented the datetime interface version to 12.
  • runtime/nsd_mbedtls.c
    • Declared and used the datetime object interface.
    • Replaced localtime_r with datetime.sys_localtime_r for time conversions.
  • runtime/operatingstate.c
    • Included datetime.h and obj.h headers.
    • Declared and used the datetime object interface.
    • Replaced localtime_r with datetime.sys_localtime_r for time conversions.
    • Added objUse and objRelease calls for the datetime object.
  • runtime/queue.c
    • Replaced localtime_r with datetime.sys_localtime_r for time conversions.
  • runtime/statsobj.c
    • Included the datetime.h header.
    • Declared and used the datetime object interface.
    • Replaced localtime_r with datetime.sys_localtime_r for time conversions.
    • Added objUse and objRelease calls for the datetime object.
  • tools/rsyslogd.c
    • Replaced localtime_r with datetime.sys_localtime_r for time conversions.
    • Introduced logic in the main loop to call datetime.updateTimezone() every 5 minutes.
    • Adjusted the tvSelectTimeout to ensure the main loop wakes up at least every 5 minutes for timezone checks.
Activity
  • The pull request was automatically generated by Jules based on a task initiated by @rgerhards.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism for periodic timezone updates to handle system timezone changes without restarting rsyslog. This is achieved by wrapping localtime_r calls in a new datetime.sys_localtime_r function, which is protected by a read-write lock. A new updateTimezone function, also lock-protected, calls tzset() periodically.

The changes are well-implemented across various modules. I've found one critical issue and one opportunity for improvement:

  • A missing objUse() call for the datetime object in the impstats plugin, which will likely lead to a crash.
  • The use of a magic number for the timezone update interval, which could be replaced by a constant to improve maintainability.

Overall, this is a valuable improvement for rsyslog's robustness in dynamic environments. Addressing the identified issues will make it even better.

#if defined(OS_LINUX) || defined(_POSIX_VERSION)
struct tm tm_local;
localtime_r(&t, &tm_local);
datetime.sys_localtime_r(&t, &tm_local);

Choose a reason for hiding this comment

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

critical

The datetime object is used here, but it is not acquired via objUse(datetime, CORE_COMPONENT) in BEGINmodInit(). This will likely cause a crash at runtime. Please add the objUse call in BEGINmodInit() to properly initialize the datetime module interface.

Comment on lines +2095 to +2096
if (tvSelectTimeout.tv_sec > 300)
tvSelectTimeout.tv_sec = 300; /* we want to check for TZ updates at least every 5 minutes */

Choose a reason for hiding this comment

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

medium

The magic number 300 is used here and later in mainloop() for the timezone update interval. To improve readability and maintainability, it would be better to define a constant for this value (e.g. #define TZ_UPDATE_INTERVAL 300) and use it in both places.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 82a4bbed93

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

#if defined(OS_LINUX) || defined(_POSIX_VERSION)
struct tm tm_local;
localtime_r(&t, &tm_local);
datetime.sys_localtime_r(&t, &tm_local);

Choose a reason for hiding this comment

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

P1 Badge Load datetime interface before calling sys_localtime_r

generateZabbixStats() now calls datetime.sys_localtime_r, but BEGINmodInit in this file never acquires the datetime interface via objUse(datetime, CORE_COMPONENT). Because DEFobjCurrIf(datetime) initializes the interface struct with null function pointers, enabling the Zabbix stats format on POSIX/Linux can dereference a null callback the first time stats are emitted and crash rsyslog.

Useful? React with 👍 / 👎.

Comment on lines +2095 to +2096
if (tvSelectTimeout.tv_sec > 300)
tvSelectTimeout.tv_sec = 300; /* we want to check for TZ updates at least every 5 minutes */

Choose a reason for hiding this comment

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

P2 Badge Keep janitor interval independent from timezone polling

Capping wait_timeout() to 300 seconds makes the main loop wake every 5 minutes even when janitorInterval is configured higher, and janitorRun() is executed unconditionally after each wake. This changes existing behavior by effectively ignoring configured janitor intervals above 5 minutes, which can increase janitor callback frequency and operational overhead in production.

Useful? React with 👍 / 👎.

google-labs-jules bot and others added 2 commits February 11, 2026 12:58
- Add `#include "obj-types.h"` to `runtime/datetime.h` to fix missing `datetime_if_t`.
- Fix include order in `runtime/operatingstate.c` and `runtime/statsobj.c`.
- Ensure `obj` is defined via `DEFobjStaticHelpers` where needed.
- Implement thread-safe timezone handling with `datetime.updateTimezone()` and `datetime.sys_localtime_r`.
- Apply code formatting via `devtools/format-code.sh`.
- Reference: rsyslog#424

Co-authored-by: rgerhards <1482123+rgerhards@users.noreply.github.com>
- Add `#include "datetime.h"` to `runtime/nsd_mbedtls.c` to fix `unknown type name 'datetime_if_t'` error when `ENABLE_MBEDTLS` is set.
- This ensures `datetime_if_t` is defined before `DEFobjCurrIf(datetime)` is expanded.
- Verified compilation of other modified modules (`impstats`, `queue`, `rsyslogd`).
- Reference: rsyslog#424

Co-authored-by: rgerhards <1482123+rgerhards@users.noreply.github.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.

1 participant