From 63c955c597cb35f66f497cf25ec1494138e3727d Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 10:31:29 -0700 Subject: [PATCH 01/40] API: libcrmcommon: Deprecate crm_time_calculate_duration() Pacemaker should not be used for general-purpose date/time manipulation. There's no need to calculate a duration (as the difference between two crm_time_t objects) for the purpose of administering Pacemaker. Where Pacemaker uses durations, it parses them directly from strings. A crm_time_t object can be displayed as a string if desired, and then a user can compare two strings through whatever method they desire. Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 2 -- include/crm/common/iso8601_compat.h | 3 +++ lib/common/iso8601.c | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 469a577cfc8..48c3ac9cc55 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -70,8 +70,6 @@ char *crm_time_as_string(const crm_time_t *dt, int flags); #define crm_time_usecs 0x400 crm_time_t *crm_time_parse_duration(const char *duration_str); -crm_time_t *crm_time_calculate_duration(const crm_time_t *dt, - const crm_time_t *value); int crm_time_compare(const crm_time_t *a, const crm_time_t *b); diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index fa83f4a2c36..124f44018a7 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -79,6 +79,9 @@ void crm_time_free_period(crm_time_period_t *period); //! \deprecated Do not use crm_time_period_t *crm_time_parse_period(const char *period_str); +//! \deprecated Do not use +crm_time_t *crm_time_calculate_duration(const crm_time_t *dt, + const crm_time_t *value); #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 083bc15dccb..43616c3f51e 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1634,12 +1634,6 @@ subtract_time(const crm_time_t *dt1, const crm_time_t *dt2, bool as_duration) return result; } -crm_time_t * -crm_time_calculate_duration(const crm_time_t *dt, const crm_time_t *value) -{ - return subtract_time(dt, value, true); -} - crm_time_t * crm_time_subtract(const crm_time_t *dt, const crm_time_t *value) { @@ -2412,5 +2406,11 @@ crm_time_parse_period(const char *period_str) return NULL; } +crm_time_t * +crm_time_calculate_duration(const crm_time_t *dt, const crm_time_t *value) +{ + return subtract_time(dt, value, true); +} + // LCOV_EXCL_STOP // End deprecated API From 90d276e29c5d12c31b2a24e1cc60e04c8ef5c188 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 10:45:20 -0700 Subject: [PATCH 02/40] Refactor: libcrmcommon: New pcmk__time_parse_duration() To replace crm_time_parse_duration(). Signed-off-by: Reid Wahl --- cts/cli/regression.dates.exp | 2 +- cts/cts-cli.in | 1 - include/crm/common/iso8601_internal.h | 2 + lib/common/iso8601.c | 35 ++++-- lib/common/strings.c | 2 +- lib/common/tests/iso8601/Makefile.am | 2 +- .../iso8601/crm_time_parse_duration_test.c | 110 ------------------ .../iso8601/pcmk__time_parse_duration_test.c | 110 ++++++++++++++++++ tools/crm_resource_ban.c | 2 +- tools/iso8601.c | 6 +- 10 files changed, 147 insertions(+), 125 deletions(-) delete mode 100644 lib/common/tests/iso8601/crm_time_parse_duration_test.c create mode 100644 lib/common/tests/iso8601/pcmk__time_parse_duration_test.c diff --git a/cts/cli/regression.dates.exp b/cts/cli/regression.dates.exp index b72d92ae688..bb0378ab81d 100644 --- a/cts/cli/regression.dates.exp +++ b/cts/cli/regression.dates.exp @@ -64,7 +64,7 @@ iso8601: Invalid interval specified: P1Y/2019-02-29 00:00:00Z =#=#=#= End test: Invalid period - [P1Y/2019-02-29 00:00:00Z] - Invalid parameter (2) =#=#=#= * Passed: iso8601 - Invalid period - [P1Y/2019-02-29 00:00:00Z] =#=#=#= Begin test: Invalid period - [2019-01-01 00:00:00Z/P] =#=#=#= -crm_time_parse_duration error: 'P' is not a valid ISO 8601 time duration because nothing follows 'P' +pcmk__time_parse_duration error: 'P' is not a valid ISO 8601 time duration because nothing follows 'P' iso8601: Invalid interval specified: 2019-01-01 00:00:00Z/P =#=#=#= End test: Invalid period - [2019-01-01 00:00:00Z/P] - Invalid parameter (2) =#=#=#= * Passed: iso8601 - Invalid period - [2019-01-01 00:00:00Z/P] diff --git a/cts/cts-cli.in b/cts/cts-cli.in index 8f557ce4b45..b111a6055b7 100644 --- a/cts/cts-cli.in +++ b/cts/cts-cli.in @@ -251,7 +251,6 @@ def sanitize_output(s): (r'(duration = TRUE; + diff->duration = true; return diff; invalid: + /* @COMPAT Setting errno is required only for backward compatibility with + * crm_time_parse_duration() + */ crm_time_free(diff); errno = EINVAL; return NULL; } +/*! + * \brief Parse a time duration from an ISO 8601 duration specification + * + * \param[in] period_s ISO 8601 duration specification (optionally followed by + * whitespace, after which the rest of the string will be + * ignored) + * + * \return New time object on success, NULL (and set errno) otherwise + * \note It is the caller's responsibility to return the result using + * crm_time_free(). + */ +crm_time_t * +crm_time_parse_duration(const char *period_s) +{ + return pcmk__time_parse_duration(period_s); +} + /*! * \internal * \brief Set one time object to another if the other is earlier @@ -2329,7 +2350,7 @@ crm_time_parse_period(const char *period_str) period = pcmk__assert_alloc(1, sizeof(crm_time_period_t)); if (period_str[0] == 'P') { - period->diff = crm_time_parse_duration(period_str); + period->diff = pcmk__time_parse_duration(period_str); if (period->diff == NULL) { goto invalid; } @@ -2350,7 +2371,7 @@ crm_time_parse_period(const char *period_str) original); goto invalid; } - period->diff = crm_time_parse_duration(period_str); + period->diff = pcmk__time_parse_duration(period_str); if (period->diff == NULL) { goto invalid; } diff --git a/lib/common/strings.c b/lib/common/strings.c index 72ea9f02213..6e71fa6ca6b 100644 --- a/lib/common/strings.c +++ b/lib/common/strings.c @@ -372,7 +372,7 @@ pcmk_parse_interval_spec(const char *input, unsigned int *result_ms) } if (input[0] == 'P') { - crm_time_t *period_s = crm_time_parse_duration(input); + crm_time_t *period_s = pcmk__time_parse_duration(input); if (period_s != NULL) { msec = crm_time_get_seconds(period_s); diff --git a/lib/common/tests/iso8601/Makefile.am b/lib/common/tests/iso8601/Makefile.am index 92ac3b5b273..8dd1ef06f48 100644 --- a/lib/common/tests/iso8601/Makefile.am +++ b/lib/common/tests/iso8601/Makefile.am @@ -15,10 +15,10 @@ include $(top_srcdir)/mk/unittest.mk check_PROGRAMS = crm_time_add_days_test check_PROGRAMS += crm_time_add_seconds_test check_PROGRAMS += crm_time_add_years_test -check_PROGRAMS += crm_time_parse_duration_test check_PROGRAMS += pcmk__add_time_from_xml_test check_PROGRAMS += pcmk__readable_interval_test check_PROGRAMS += pcmk__set_time_if_earlier_test check_PROGRAMS += pcmk__time_format_hr_test +check_PROGRAMS += pcmk__time_parse_duration_test TESTS = $(check_PROGRAMS) diff --git a/lib/common/tests/iso8601/crm_time_parse_duration_test.c b/lib/common/tests/iso8601/crm_time_parse_duration_test.c deleted file mode 100644 index 58015e82422..00000000000 --- a/lib/common/tests/iso8601/crm_time_parse_duration_test.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2024 the Pacemaker project contributors - * - * The version control history for this file may have further details. - * - * This source code is licensed under the GNU General Public License version 2 - * or later (GPLv2+) WITHOUT ANY WARRANTY. - */ - -#include - -#include - -#include -#include "crmcommon_private.h" - -static void -empty_arg(void **state) -{ - assert_null(crm_time_parse_duration(NULL)); - assert_null(crm_time_parse_duration("")); -} - -static void -invalid_arg(void **state) -{ - // Valid except doesn't start with P - assert_null(crm_time_parse_duration("X3Y6M4DT12H30M5S")); - - // Illegal character after P - assert_null(crm_time_parse_duration("P")); - assert_null(crm_time_parse_duration("P 3Y6M4DT12H30M5S")); - assert_null(crm_time_parse_duration("PX3Y6M4DT12H30M5S")); - - // Missing or invalid units - assert_null(crm_time_parse_duration("P3Y6M4DT12H30M5")); - assert_null(crm_time_parse_duration("P3Y6M4DT12H30M5X")); - assert_null(crm_time_parse_duration("P3X6M4DT12H30M5S")); - assert_null(crm_time_parse_duration("PT")); - assert_null(crm_time_parse_duration("P/")); - -#if 0 - // @TODO The current implementation treats these as valid - - // Units out of order - assert_null(crm_time_parse_duration("P6M3Y4DT12H30M5S")); - assert_null(crm_time_parse_duration("P6M3DT12HY430M5S")); - - // Same unit specified multiple times - assert_null(crm_time_parse_duration("P6Y4M3D1MT12H30M5S")); - - // Weeks mixed with other units - assert_null(crm_time_parse_duration("P6Y4M3W3D1MT12H30M5S")); - assert_null(crm_time_parse_duration("P3WT12H30M5S")); -#endif -} - -static void -overflow(void **state) -{ - // Too large - assert_null(crm_time_parse_duration("P2147483648Y6M4DT12H30M5S")); - assert_null(crm_time_parse_duration("P3Y2147483648M4DT12H30M5S")); - assert_null(crm_time_parse_duration("P3Y6M2147483648DT12H30M5S")); - assert_null(crm_time_parse_duration("P3Y6M4DT2147483648H30M5S")); - assert_null(crm_time_parse_duration("P3Y6M4DT12H2147483648M5S")); - assert_null(crm_time_parse_duration("P3Y6M4DT12H30MP2147483648S")); - - // Too small - assert_null(crm_time_parse_duration("P-2147483648Y6M4DT12H30M5S")); - assert_null(crm_time_parse_duration("P3Y-2147483648M4DT12H30M5S")); - assert_null(crm_time_parse_duration("P3Y6M-2147483648DT12H30M5S")); - assert_null(crm_time_parse_duration("P3Y6M4DT-2147483648H30M5S")); - assert_null(crm_time_parse_duration("P3Y6M4DT12H-2147483648M5S")); - assert_null(crm_time_parse_duration("P3Y6M4DT12H30MP-2147483648S")); -} - -static void -valid_arg(void **state) -{ - // @TODO Check result value - assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30M5S")); - assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30M-5S")); - assert_non_null(crm_time_parse_duration("P3Y6M4DT12H-30M5S")); - assert_non_null(crm_time_parse_duration("P3Y6M4DT-12H30M5S")); - assert_non_null(crm_time_parse_duration("P3Y6M-4DT12H30M5S")); - assert_non_null(crm_time_parse_duration("P3Y-6M4DT12H30M5S")); - assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30M")); - assert_non_null(crm_time_parse_duration("P3Y6M4D")); - assert_non_null(crm_time_parse_duration("P1M")); // 1 month - assert_non_null(crm_time_parse_duration("PT1M")); // 1 minute - assert_non_null(crm_time_parse_duration("P7W")); - -#if 0 - // @TODO Current implementation can't handle these cases - - // Fractional value for last unit - assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30.5M")); - assert_non_null(crm_time_parse_duration("P3Y6M4DT12H30,5M")); - - // P--
T:: format - assert_non_null(crm_time_parse_duration("P0003-02-01T11:10:09"); -#endif -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(empty_arg), - cmocka_unit_test(invalid_arg), - cmocka_unit_test(overflow), - cmocka_unit_test(valid_arg)); diff --git a/lib/common/tests/iso8601/pcmk__time_parse_duration_test.c b/lib/common/tests/iso8601/pcmk__time_parse_duration_test.c new file mode 100644 index 00000000000..76acc590741 --- /dev/null +++ b/lib/common/tests/iso8601/pcmk__time_parse_duration_test.c @@ -0,0 +1,110 @@ +/* + * Copyright 2024-2026 the Pacemaker project contributors + * + * The version control history for this file may have further details. + * + * This source code is licensed under the GNU General Public License version 2 + * or later (GPLv2+) WITHOUT ANY WARRANTY. + */ + +#include + +#include + +#include +#include "crmcommon_private.h" + +static void +empty_arg(void **state) +{ + assert_null(pcmk__time_parse_duration(NULL)); + assert_null(pcmk__time_parse_duration("")); +} + +static void +invalid_arg(void **state) +{ + // Valid except doesn't start with P + assert_null(pcmk__time_parse_duration("X3Y6M4DT12H30M5S")); + + // Illegal character after P + assert_null(pcmk__time_parse_duration("P")); + assert_null(pcmk__time_parse_duration("P 3Y6M4DT12H30M5S")); + assert_null(pcmk__time_parse_duration("PX3Y6M4DT12H30M5S")); + + // Missing or invalid units + assert_null(pcmk__time_parse_duration("P3Y6M4DT12H30M5")); + assert_null(pcmk__time_parse_duration("P3Y6M4DT12H30M5X")); + assert_null(pcmk__time_parse_duration("P3X6M4DT12H30M5S")); + assert_null(pcmk__time_parse_duration("PT")); + assert_null(pcmk__time_parse_duration("P/")); + +#if 0 + // @TODO The current implementation treats these as valid + + // Units out of order + assert_null(pcmk__time_parse_duration("P6M3Y4DT12H30M5S")); + assert_null(pcmk__time_parse_duration("P6M3DT12HY430M5S")); + + // Same unit specified multiple times + assert_null(pcmk__time_parse_duration("P6Y4M3D1MT12H30M5S")); + + // Weeks mixed with other units + assert_null(pcmk__time_parse_duration("P6Y4M3W3D1MT12H30M5S")); + assert_null(pcmk__time_parse_duration("P3WT12H30M5S")); +#endif +} + +static void +overflow(void **state) +{ + // Too large + assert_null(pcmk__time_parse_duration("P2147483648Y6M4DT12H30M5S")); + assert_null(pcmk__time_parse_duration("P3Y2147483648M4DT12H30M5S")); + assert_null(pcmk__time_parse_duration("P3Y6M2147483648DT12H30M5S")); + assert_null(pcmk__time_parse_duration("P3Y6M4DT2147483648H30M5S")); + assert_null(pcmk__time_parse_duration("P3Y6M4DT12H2147483648M5S")); + assert_null(pcmk__time_parse_duration("P3Y6M4DT12H30MP2147483648S")); + + // Too small + assert_null(pcmk__time_parse_duration("P-2147483648Y6M4DT12H30M5S")); + assert_null(pcmk__time_parse_duration("P3Y-2147483648M4DT12H30M5S")); + assert_null(pcmk__time_parse_duration("P3Y6M-2147483648DT12H30M5S")); + assert_null(pcmk__time_parse_duration("P3Y6M4DT-2147483648H30M5S")); + assert_null(pcmk__time_parse_duration("P3Y6M4DT12H-2147483648M5S")); + assert_null(pcmk__time_parse_duration("P3Y6M4DT12H30MP-2147483648S")); +} + +static void +valid_arg(void **state) +{ + // @TODO Check result value + assert_non_null(pcmk__time_parse_duration("P3Y6M4DT12H30M5S")); + assert_non_null(pcmk__time_parse_duration("P3Y6M4DT12H30M-5S")); + assert_non_null(pcmk__time_parse_duration("P3Y6M4DT12H-30M5S")); + assert_non_null(pcmk__time_parse_duration("P3Y6M4DT-12H30M5S")); + assert_non_null(pcmk__time_parse_duration("P3Y6M-4DT12H30M5S")); + assert_non_null(pcmk__time_parse_duration("P3Y-6M4DT12H30M5S")); + assert_non_null(pcmk__time_parse_duration("P3Y6M4DT12H30M")); + assert_non_null(pcmk__time_parse_duration("P3Y6M4D")); + assert_non_null(pcmk__time_parse_duration("P1M")); // 1 month + assert_non_null(pcmk__time_parse_duration("PT1M")); // 1 minute + assert_non_null(pcmk__time_parse_duration("P7W")); + +#if 0 + // @TODO Current implementation can't handle these cases + + // Fractional value for last unit + assert_non_null(pcmk__time_parse_duration("P3Y6M4DT12H30.5M")); + assert_non_null(pcmk__time_parse_duration("P3Y6M4DT12H30,5M")); + + // P--
T:: format + assert_non_null(pcmk__time_parse_duration("P0003-02-01T11:10:09"); +#endif +} + +PCMK__UNIT_TEST(NULL, NULL, + cmocka_unit_test(empty_arg), + cmocka_unit_test(invalid_arg), + cmocka_unit_test(overflow), + cmocka_unit_test(valid_arg)); diff --git a/tools/crm_resource_ban.c b/tools/crm_resource_ban.c index e52268b4335..a83bee1e89c 100644 --- a/tools/crm_resource_ban.c +++ b/tools/crm_resource_ban.c @@ -31,7 +31,7 @@ parse_cli_lifetime(pcmk__output_t *out, const char *move_lifetime) return NULL; } - duration = crm_time_parse_duration(move_lifetime); + duration = pcmk__time_parse_duration(move_lifetime); if (duration == NULL) { out->err(out, "Invalid duration specified: %s\n" "Please refer to https://en.wikipedia.org/wiki/ISO_8601#Durations " diff --git a/tools/iso8601.c b/tools/iso8601.c index 303d12ab520..da784df3f1d 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -299,7 +299,7 @@ parse_period(const char *period_str, crm_time_t **start, crm_time_t **end) tzset(); if (period_str[0] == 'P') { - diff = crm_time_parse_duration(period_str); + diff = pcmk__time_parse_duration(period_str); if (diff == NULL) { goto invalid; } @@ -319,7 +319,7 @@ parse_period(const char *period_str, crm_time_t **start, crm_time_t **end) "has two durations", original); goto invalid; } - diff = crm_time_parse_duration(period_str); + diff = pcmk__time_parse_duration(period_str); if (diff == NULL) { goto invalid; } @@ -471,7 +471,7 @@ main(int argc, char **argv) } if (options.duration_s) { - duration = crm_time_parse_duration(options.duration_s); + duration = pcmk__time_parse_duration(options.duration_s); if (duration == NULL) { exit_code = CRM_EX_INVALID_PARAM; From ab7373c924746591623646958bcadff59fafda91 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 13:32:45 -0700 Subject: [PATCH 03/40] API: libcrmcommon: Deprecate crm_time_parse_duration() Pacemaker parses durations from strings in a few places. However, there is no need for external code to do this for the purpose of administering Pacemaker. Pacemaker should not be used for general-purpose date/time manipulation. Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 2 -- include/crm/common/iso8601_compat.h | 4 ++++ lib/common/iso8601.c | 23 ++++++----------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 48c3ac9cc55..ccf9369090a 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -69,8 +69,6 @@ char *crm_time_as_string(const crm_time_t *dt, int flags); #define crm_time_epoch 0x200 #define crm_time_usecs 0x400 -crm_time_t *crm_time_parse_duration(const char *duration_str); - int crm_time_compare(const crm_time_t *a, const crm_time_t *b); int crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 124f44018a7..b823a530d83 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -82,6 +82,10 @@ crm_time_period_t *crm_time_parse_period(const char *period_str); //! \deprecated Do not use crm_time_t *crm_time_calculate_duration(const crm_time_t *dt, const crm_time_t *value); + +//! \deprecated Do not use +crm_time_t *crm_time_parse_duration(const char *duration_str); + #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 0be63347cc9..4647edcfa52 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1357,23 +1357,6 @@ pcmk__time_parse_duration(const char *period_s) return NULL; } -/*! - * \brief Parse a time duration from an ISO 8601 duration specification - * - * \param[in] period_s ISO 8601 duration specification (optionally followed by - * whitespace, after which the rest of the string will be - * ignored) - * - * \return New time object on success, NULL (and set errno) otherwise - * \note It is the caller's responsibility to return the result using - * crm_time_free(). - */ -crm_time_t * -crm_time_parse_duration(const char *period_s) -{ - return pcmk__time_parse_duration(period_s); -} - /*! * \internal * \brief Set one time object to another if the other is earlier @@ -2433,5 +2416,11 @@ crm_time_calculate_duration(const crm_time_t *dt, const crm_time_t *value) return subtract_time(dt, value, true); } +crm_time_t * +crm_time_parse_duration(const char *period_s) +{ + return pcmk__time_parse_duration(period_s); +} + // LCOV_EXCL_STOP // End deprecated API From cc4b6cad30de6f46678229d561ea8587aaec2422 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 17:34:32 -0700 Subject: [PATCH 04/40] Refactor: libcrmcommon: Clean up includes in scheduler.h Add a couple of missing includes elsewhere, since they break otherwise. Signed-off-by: Reid Wahl --- include/crm/common/scheduler.h | 16 +++++----------- include/crm/pengine/status.h | 4 ++-- include/pacemaker.h | 1 + 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/include/crm/common/scheduler.h b/include/crm/common/scheduler.h index e7d3b27ac7b..b01f970a32b 100644 --- a/include/crm/common/scheduler.h +++ b/include/crm/common/scheduler.h @@ -10,19 +10,13 @@ #ifndef PCMK__CRM_COMMON_SCHEDULER__H #define PCMK__CRM_COMMON_SCHEDULER__H -#include -#include // time_t -#include // xmlNode -#include // GList, GHashTable +#include // bool +#include // uint64_t -#include // crm_time_t +#include // GList +#include // xmlNode -#include -#include -#include -#include -#include -#include +#include // pcmk_node_t, pcmk_scheduler_t #ifdef __cplusplus extern "C" { diff --git a/include/crm/pengine/status.h b/include/crm/pengine/status.h index 8d7722c72b0..d46428b6870 100644 --- a/include/crm/pengine/status.h +++ b/include/crm/pengine/status.h @@ -1,5 +1,5 @@ /* - * Copyright 2004-2025 the Pacemaker project contributors + * Copyright 2004-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -12,7 +12,7 @@ # include // gboolean # include // bool -# include +# include // pe_find # include // pcmk_node_t, pcmk_resource_t, etc. # include diff --git a/include/pacemaker.h b/include/pacemaker.h index a766a964230..c474f2b18da 100644 --- a/include/pacemaker.h +++ b/include/pacemaker.h @@ -16,6 +16,7 @@ # include # include +# include // crm_time_t # include # include From 9f3d7bdd3d9973158a2c6571e2aa5698dda29bbf Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 17:42:55 -0700 Subject: [PATCH 05/40] Refactor: various: Drop crm_time_new_undefined() internally Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 10 +++++----- .../tests/iso8601/pcmk__set_time_if_earlier_test.c | 4 ++-- lib/common/tests/rules/pcmk__evaluate_condition_test.c | 4 ++-- lib/common/tests/rules/pcmk_evaluate_rule_test.c | 10 +++++----- .../tests/xml_element/pcmk__xe_get_datetime_test.c | 4 ++-- lib/pacemaker/pcmk_sched_location.c | 2 +- lib/pengine/utils.c | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 4647edcfa52..aef1a4506de 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -482,7 +482,7 @@ parse_date(const char *date_str) goto parse_time_segment; } - dt = crm_time_new_undefined(); + dt = pcmk__assert_alloc(1, sizeof(crm_time_t)); if ((strncasecmp(PCMK__VALUE_EPOCH, date_str, 5) == 0) && ((date_str[5] == '\0') @@ -640,7 +640,7 @@ copy_time_to_utc(const crm_time_t *dt) pcmk__assert(dt != NULL); - utc = crm_time_new_undefined(); + utc = pcmk__assert_alloc(1, sizeof(crm_time_t)); utc->years = dt->years; utc->days = dt->days; utc->seconds = dt->seconds; @@ -1316,7 +1316,7 @@ pcmk__time_parse_duration(const char *period_s) goto invalid; } - diff = crm_time_new_undefined(); + diff = pcmk__assert_alloc(1, sizeof(crm_time_t)); for (const char *current = period_s + 1; current[0] && (current[0] != '/') && !isspace(current[0]); @@ -1387,7 +1387,7 @@ pcmk__set_time_if_earlier(crm_time_t *target, const crm_time_t *source) crm_time_t * pcmk_copy_time(const crm_time_t *source) { - crm_time_t *target = crm_time_new_undefined(); + crm_time_t *target = pcmk__assert_alloc(1, sizeof(crm_time_t)); *target = *source; return target; @@ -1408,7 +1408,7 @@ crm_time_t * pcmk__copy_timet(time_t source_sec) { const struct tm *source = localtime(&source_sec); - crm_time_t *target = crm_time_new_undefined(); + crm_time_t *target = pcmk__assert_alloc(1, sizeof(crm_time_t)); int h_offset = 0; int m_offset = 0; diff --git a/lib/common/tests/iso8601/pcmk__set_time_if_earlier_test.c b/lib/common/tests/iso8601/pcmk__set_time_if_earlier_test.c index c4bf0140825..79821c3de2e 100644 --- a/lib/common/tests/iso8601/pcmk__set_time_if_earlier_test.c +++ b/lib/common/tests/iso8601/pcmk__set_time_if_earlier_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -36,7 +36,7 @@ static void target_undefined(void **state) { crm_time_t *source = crm_time_new("2024-01-01 00:29:59 +01:00"); - crm_time_t *target = crm_time_new_undefined(); + crm_time_t *target = pcmk__assert_alloc(1, sizeof(crm_time_t)); pcmk__set_time_if_earlier(target, source); assert_int_equal(crm_time_compare(target, source), 0); diff --git a/lib/common/tests/rules/pcmk__evaluate_condition_test.c b/lib/common/tests/rules/pcmk__evaluate_condition_test.c index be0931a0267..7327ad01fc9 100644 --- a/lib/common/tests/rules/pcmk__evaluate_condition_test.c +++ b/lib/common/tests/rules/pcmk__evaluate_condition_test.c @@ -42,7 +42,7 @@ static void null_invalid(void **state) { xmlNode *xml = NULL; - crm_time_t *next_change = crm_time_new_undefined(); + crm_time_t *next_change = pcmk__assert_alloc(1, sizeof(crm_time_t)); assert_int_equal(pcmk__evaluate_condition(NULL, NULL, next_change), EINVAL); @@ -63,7 +63,7 @@ static void invalid_expression(void **state) { xmlNode *xml = pcmk__xml_parse(EXPR_INVALID); - crm_time_t *next_change = crm_time_new_undefined(); + crm_time_t *next_change = pcmk__assert_alloc(1, sizeof(crm_time_t)); assert_int_equal(pcmk__evaluate_condition(xml, &rule_input, next_change), pcmk_rc_unpack_error); diff --git a/lib/common/tests/rules/pcmk_evaluate_rule_test.c b/lib/common/tests/rules/pcmk_evaluate_rule_test.c index 0a028076c58..f0ce9d23b49 100644 --- a/lib/common/tests/rules/pcmk_evaluate_rule_test.c +++ b/lib/common/tests/rules/pcmk_evaluate_rule_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2024-2025 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -43,7 +43,7 @@ static void null_invalid(void **state) { xmlNode *xml = NULL; - crm_time_t *next_change = crm_time_new_undefined(); + crm_time_t *next_change = pcmk__assert_alloc(1, sizeof(crm_time_t)); assert_int_equal(pcmk_evaluate_rule(NULL, NULL, next_change), EINVAL); @@ -69,7 +69,7 @@ static void id_missing(void **state) { xmlNode *xml = pcmk__xml_parse(RULE_OP_MISSING_ID); - crm_time_t *next_change = crm_time_new_undefined(); + crm_time_t *next_change = pcmk__assert_alloc(1, sizeof(crm_time_t)); assert_int_equal(pcmk_evaluate_rule(xml, &rule_input, next_change), pcmk_rc_unpack_error); @@ -85,7 +85,7 @@ good_idref(void **state) { xmlNode *parent_xml = pcmk__xml_parse(RULE_IDREF_PARENT); xmlNode *rule_xml = pcmk__xe_create(parent_xml, PCMK_XE_RULE); - crm_time_t *next_change = crm_time_new_undefined(); + crm_time_t *next_change = pcmk__assert_alloc(1, sizeof(crm_time_t)); pcmk__xe_set(rule_xml, PCMK_XA_ID_REF, "r"); assert_int_equal(pcmk_evaluate_rule(rule_xml, &rule_input, next_change), @@ -100,7 +100,7 @@ bad_idref(void **state) { xmlNode *parent_xml = pcmk__xml_parse(RULE_IDREF_PARENT); xmlNode *rule_xml = pcmk__xe_create(parent_xml, PCMK_XE_RULE); - crm_time_t *next_change = crm_time_new_undefined(); + crm_time_t *next_change = pcmk__assert_alloc(1, sizeof(crm_time_t)); pcmk__xe_set(rule_xml, PCMK_XA_ID_REF, "x"); assert_int_equal(pcmk_evaluate_rule(rule_xml, &rule_input, next_change), diff --git a/lib/common/tests/xml_element/pcmk__xe_get_datetime_test.c b/lib/common/tests/xml_element/pcmk__xe_get_datetime_test.c index bad68bffbf1..c488d3f7243 100644 --- a/lib/common/tests/xml_element/pcmk__xe_get_datetime_test.c +++ b/lib/common/tests/xml_element/pcmk__xe_get_datetime_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -51,7 +51,7 @@ static void nonnull_time_invalid(void **state) { xmlNode *xml = pcmk__xml_parse(REFERENCE_XML); - crm_time_t *t = crm_time_new_undefined(); + crm_time_t *t = pcmk__assert_alloc(1, sizeof(crm_time_t)); assert_int_equal(pcmk__xe_get_datetime(xml, ATTR_PRESENT, &t), EINVAL); diff --git a/lib/pacemaker/pcmk_sched_location.c b/lib/pacemaker/pcmk_sched_location.c index 641f7716c92..2d11f3b964c 100644 --- a/lib/pacemaker/pcmk_sched_location.c +++ b/lib/pacemaker/pcmk_sched_location.c @@ -362,7 +362,7 @@ unpack_rsc_location(xmlNode *xml_obj, pcmk_resource_t *rsc, location->role_filter = role; } else { - crm_time_t *next_change = crm_time_new_undefined(); + crm_time_t *next_change = pcmk__assert_alloc(1, sizeof(crm_time_t)); xmlNode *rule_xml = pcmk__xe_first_child(xml_obj, PCMK_XE_RULE, NULL, NULL); pcmk_rule_input_t rule_input = { diff --git a/lib/pengine/utils.c b/lib/pengine/utils.c index 37cdf3807dc..aff4f8617bd 100644 --- a/lib/pengine/utils.c +++ b/lib/pengine/utils.c @@ -727,7 +727,7 @@ pe__unpack_dataset_nvpairs(const xmlNode *xml_obj, const char *set_name, return; } - next_change = crm_time_new_undefined(); + next_change = pcmk__assert_alloc(1, sizeof(crm_time_t)); pcmk__unpack_nvpair_blocks(xml_obj, set_name, always_first, rule_input, hash, next_change, scheduler->input->doc); From 75e562a29678714c99a73cb9da67875a4a90a555 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:05:05 -0700 Subject: [PATCH 06/40] API: libcrmcommon: Deprecate crm_time_new_undefined() Use crm_time_new() to create a new crm_time_t object from a string (or NULL to use the current time). There is no need for external callers to create an uninitialized object and then set the fields (such as years) later. Pacemaker should not be used for general-purpose date/time manipulation. pcmk_evaluate_rule() can take an uninitialized (undefined) crm_time_t object as the next_change argument and update it as appropriate. However, that argument is for use by the scheduler, not for external callers. Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 1 - include/crm/common/iso8601_compat.h | 3 +++ lib/common/iso8601.c | 20 ++++++-------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index ccf9369090a..b01c4836d86 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -52,7 +52,6 @@ typedef struct crm_time_s crm_time_t; * A timezone of 'Z' denotes UTC time */ crm_time_t *crm_time_new(const char *string); -crm_time_t *crm_time_new_undefined(void); void crm_time_free(crm_time_t * dt); bool crm_time_is_defined(const crm_time_t *t); diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index b823a530d83..112674aadbe 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -86,6 +86,9 @@ crm_time_t *crm_time_calculate_duration(const crm_time_t *dt, //! \deprecated Do not use crm_time_t *crm_time_parse_duration(const char *duration_str); +//! \deprecated Do not use +crm_time_t *crm_time_new_undefined(void); + #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index aef1a4506de..3b04a39276b 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -74,20 +74,6 @@ ((QB_ABS(usec) < QB_TIME_US_IN_SEC) \ && (((sec) == 0) || ((usec) == 0) || (((sec) < 0) == ((usec) < 0)))) -/*! - * \brief Allocate memory for an uninitialized time object - * - * \return Newly allocated time object (guaranteed not to be \c NULL) - * - * \note The caller is responsible for freeing the return value using - * \c crm_time_free(). - */ -crm_time_t * -crm_time_new_undefined(void) -{ - return pcmk__assert_alloc(1, sizeof(crm_time_t)); -} - /*! * \internal * \brief Check whether a year is positive and representable by four digits @@ -2422,5 +2408,11 @@ crm_time_parse_duration(const char *period_s) return pcmk__time_parse_duration(period_s); } +crm_time_t * +crm_time_new_undefined(void) +{ + return pcmk__assert_alloc(1, sizeof(crm_time_t)); +} + // LCOV_EXCL_STOP // End deprecated API From 0e6d29a1f0508af461ebfe8a1e8d9491aa2b8338 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:15:09 -0700 Subject: [PATCH 07/40] Refactor: libcrmcommon: New pcmk__time_is_initialized() To replace crm_time_is_defined(). Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 1 + lib/common/iso8601.c | 30 +++++++++++++++++++++------ lib/pacemaker/pcmk_sched_location.c | 2 +- lib/pengine/utils.c | 2 +- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 11bb67e8048..57d0601a60e 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -27,6 +27,7 @@ extern "C" { #endif bool pcmk__time_valid_year(int year); +bool pcmk__time_is_initialized(const crm_time_t *dt); void pcmk__time_get_ywd(const crm_time_t *dt, uint32_t *y, uint32_t *w, uint32_t *d); char *pcmk__time_format_hr(const char *format, const crm_time_t *dt, int usec); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 3b04a39276b..41f1712d895 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -655,6 +655,26 @@ crm_time_new(const char *date_time) return parse_date(date_time); } +/*! + * \brief Check whether a time object has been initialized yet + * + * \param[in] dt Time object to check + * + * \return \c true if time object has been initialized, or \c false otherwise + */ +bool +pcmk__time_is_initialized(const crm_time_t *dt) +{ + // Any nonzero member indicates something has been done to dt + return (dt != NULL) + && ((dt->years != 0) + || (dt->months != 0) + || (dt->days != 0) + || (dt->seconds != 0) + || (dt->offset != 0) + || (dt->duration)); +} + /*! * \brief Check whether a time object has been initialized yet * @@ -665,9 +685,7 @@ crm_time_new(const char *date_time) bool crm_time_is_defined(const crm_time_t *t) { - // Any nonzero member indicates something has been done to t - return (t != NULL) && (t->years || t->months || t->days || t->seconds - || t->offset || t->duration); + return pcmk__time_is_initialized(t); } void @@ -987,7 +1005,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) GString *buf = NULL; char *result = NULL; - if (!crm_time_is_defined(dt)) { + if (!pcmk__time_is_initialized(dt)) { return pcmk__str_copy(""); } @@ -1324,7 +1342,7 @@ pcmk__time_parse_duration(const char *period_s) } } - if (!crm_time_is_defined(diff)) { + if (!pcmk__time_is_initialized(diff)) { pcmk__err("'%s' is not a valid ISO 8601 time duration because no " "amounts and units given", period_s); @@ -1359,7 +1377,7 @@ pcmk__set_time_if_earlier(crm_time_t *target, const crm_time_t *source) if ((target == NULL) || (source == NULL) - || (crm_time_is_defined(target) + || (pcmk__time_is_initialized(target) && (crm_time_compare(source, target) >= 0))) { return; diff --git a/lib/pacemaker/pcmk_sched_location.c b/lib/pacemaker/pcmk_sched_location.c index 2d11f3b964c..44891c98240 100644 --- a/lib/pacemaker/pcmk_sched_location.c +++ b/lib/pacemaker/pcmk_sched_location.c @@ -379,7 +379,7 @@ unpack_rsc_location(xmlNode *xml_obj, pcmk_resource_t *rsc, /* If there is a point in the future when the evaluation of a rule will * change, make sure the scheduler is re-run by that time. */ - if (crm_time_is_defined(next_change)) { + if (pcmk__time_is_initialized(next_change)) { time_t t = (time_t) crm_time_get_seconds_since_epoch(next_change); pcmk__update_recheck_time(t, rsc->priv->scheduler, diff --git a/lib/pengine/utils.c b/lib/pengine/utils.c index aff4f8617bd..bb3d5c03b0d 100644 --- a/lib/pengine/utils.c +++ b/lib/pengine/utils.c @@ -731,7 +731,7 @@ pe__unpack_dataset_nvpairs(const xmlNode *xml_obj, const char *set_name, pcmk__unpack_nvpair_blocks(xml_obj, set_name, always_first, rule_input, hash, next_change, scheduler->input->doc); - if (crm_time_is_defined(next_change)) { + if (pcmk__time_is_initialized(next_change)) { time_t recheck = (time_t) crm_time_get_seconds_since_epoch(next_change); pcmk__update_recheck_time(recheck, scheduler, "rule evaluation"); From 49f124891ab50b4aff9af814554e2c983ffe296c Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:17:00 -0700 Subject: [PATCH 08/40] API: libcrmcommon: Deprecate crm_time_is_defined() External callers should always be using crm_time_new() to create a crm_time_t object. Such objects will be initialized ("defined"). Pacemaker does not return crm_time_t objects via public API functions, except as an output argument of pcmk_evaluate_rule(). However, that argument is for use by the scheduler, not for external callers. Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 1 - include/crm/common/iso8601_compat.h | 3 +++ lib/common/iso8601.c | 19 ++++++------------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index b01c4836d86..e0426665dc0 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,7 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -bool crm_time_is_defined(const crm_time_t *t); char *crm_time_as_string(const crm_time_t *dt, int flags); #define crm_time_log_date 0x001 diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 112674aadbe..05889f933bb 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -89,6 +89,9 @@ crm_time_t *crm_time_parse_duration(const char *duration_str); //! \deprecated Do not use crm_time_t *crm_time_new_undefined(void); +//! \deprecated Do not use +bool crm_time_is_defined(const crm_time_t *t); + #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 41f1712d895..4f48cda2cca 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -675,19 +675,6 @@ pcmk__time_is_initialized(const crm_time_t *dt) || (dt->duration)); } -/*! - * \brief Check whether a time object has been initialized yet - * - * \param[in] t Time object to check - * - * \return \c true if time object has been initialized, \c false otherwise - */ -bool -crm_time_is_defined(const crm_time_t *t) -{ - return pcmk__time_is_initialized(t); -} - void crm_time_free(crm_time_t * dt) { @@ -2432,5 +2419,11 @@ crm_time_new_undefined(void) return pcmk__assert_alloc(1, sizeof(crm_time_t)); } +bool +crm_time_is_defined(const crm_time_t *t) +{ + return pcmk__time_is_initialized(t); +} + // LCOV_EXCL_STOP // End deprecated API From 49f158356ca86730afc99765131fe38a910df6f8 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:27:20 -0700 Subject: [PATCH 09/40] Refactor: libcrmcommon: New pcmk__time_text() To replace crm_time_as_string(). Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 1 + lib/common/iso8601.c | 21 ++++++++++++++--- lib/pacemaker/pcmk_simulate.c | 2 +- tools/crm_resource_ban.c | 4 ++-- tools/iso8601.c | 33 +++++++++++++++------------ 5 files changed, 40 insertions(+), 21 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 57d0601a60e..33b4f0b55cc 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -30,6 +30,7 @@ bool pcmk__time_valid_year(int year); bool pcmk__time_is_initialized(const crm_time_t *dt); void pcmk__time_get_ywd(const crm_time_t *dt, uint32_t *y, uint32_t *w, uint32_t *d); +char *pcmk__time_text(const crm_time_t *dt, int flags); char *pcmk__time_format_hr(const char *format, const crm_time_t *dt, int usec); char *pcmk__epoch2str(const time_t *source, uint32_t flags); char *pcmk__timespec2str(const struct timespec *ts, uint32_t flags); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 4f48cda2cca..2b5fa9b9983 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -689,7 +689,7 @@ pcmk__time_log_as(const char *file, const char *function, int line, uint8_t level, const char *prefix, const crm_time_t *dt, uint32_t flags) { - char *date_s = crm_time_as_string(dt, flags); + char *date_s = pcmk__time_text(dt, flags); if (prefix != NULL) { char *old = date_s; @@ -1104,6 +1104,21 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) return result; } +/*! + * \internal + * \brief Get a string representation of a \c crm_time_t object + * + * \param[in] dt Time to convert to string + * \param[in] flags Group of \c crm_time_* string format options + * + * \note The caller is responsible for freeing the return value using \c free(). + */ +char * +pcmk__time_text(const crm_time_t *dt, int flags) +{ + return time_as_string_common(dt, 0, flags); +} + /*! * \brief Get a string representation of a \p crm_time_t object * @@ -1115,7 +1130,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) char * crm_time_as_string(const crm_time_t *dt, int flags) { - return time_as_string_common(dt, 0, flags); + return pcmk__time_text(dt, flags); } // Parse an ISO 8601 numeric value and return number of characters consumed @@ -2098,7 +2113,7 @@ pcmk__epoch2str(const time_t *source, uint32_t flags) } dt = pcmk__copy_timet(epoch_time); - result = crm_time_as_string(dt, flags); + result = pcmk__time_text(dt, flags); crm_time_free(dt); return result; diff --git a/lib/pacemaker/pcmk_simulate.c b/lib/pacemaker/pcmk_simulate.c index 4db2d34ef3d..5f231e2ee07 100644 --- a/lib/pacemaker/pcmk_simulate.c +++ b/lib/pacemaker/pcmk_simulate.c @@ -521,7 +521,7 @@ set_effective_date(pcmk_scheduler_t *scheduler, bool print_original, scheduler->priv->now = pcmk__copy_timet(original_date); if (print_original) { - char *when = crm_time_as_string(scheduler->priv->now, flags); + char *when = pcmk__time_text(scheduler->priv->now, flags); out->info(out, "Using the original execution date of: %s", when); free(when); diff --git a/tools/crm_resource_ban.c b/tools/crm_resource_ban.c index a83bee1e89c..d7a594bc45c 100644 --- a/tools/crm_resource_ban.c +++ b/tools/crm_resource_ban.c @@ -1,5 +1,5 @@ /* - * Copyright 2004-2025 the Pacemaker project contributors + * Copyright 2004-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -53,7 +53,7 @@ parse_cli_lifetime(pcmk__output_t *out, const char *move_lifetime) pcmk__time_log(LOG_INFO, "now ", now, time_flags); pcmk__time_log(LOG_INFO, "later ", later, time_flags); pcmk__time_log(LOG_INFO, "duration", duration, duration_flags); - later_s = crm_time_as_string(later, time_flags); + later_s = pcmk__time_text(later, time_flags); out->info(out, "Migration will take effect until: %s", later_s); crm_time_free(duration); diff --git a/tools/iso8601.c b/tools/iso8601.c index da784df3f1d..2b2d44faa27 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -131,7 +131,7 @@ date_default(pcmk__output_t *out, va_list args) char *date_s = NULL; opts |= crm_time_log_date | crm_time_log_timeofday; - date_s = crm_time_as_string(date, opts); + date_s = pcmk__time_text(date, opts); out->info(out, "%s: %s", prefix, date_s); @@ -150,7 +150,7 @@ date_xml(pcmk__output_t *out, va_list args) char *date_s = NULL; opts |= crm_time_log_date | crm_time_log_timeofday; - date_s = crm_time_as_string(date, opts); + date_s = pcmk__time_text(date, opts); pcmk__output_create_xml_text_node(out, PCMK_XE_DATE, date_s); free(date_s); @@ -164,7 +164,7 @@ duration_default(pcmk__output_t *out, va_list args) crm_time_t *time = va_arg(args, crm_time_t *); int opts = va_arg(args, int); - char *date_s = crm_time_as_string(time, opts | crm_time_log_duration); + char *date_s = pcmk__time_text(time, opts|crm_time_log_duration); out->info(out, "Duration: %s", date_s); @@ -179,7 +179,7 @@ duration_xml(pcmk__output_t *out, va_list args) crm_time_t *time = va_arg(args, crm_time_t *); int opts = va_arg(args, int); - char *date_s = crm_time_as_string(time, opts | crm_time_log_duration); + char *date_s = pcmk__time_text(time, opts|crm_time_log_duration); pcmk__output_create_xml_text_node(out, PCMK_XE_DURATION, date_s); free(date_s); @@ -196,7 +196,7 @@ duration_ends_default(pcmk__output_t *out, va_list args) char *date_s = NULL; opts |= crm_time_log_date | crm_time_log_timeofday | crm_time_log_with_timezone; - date_s = crm_time_as_string(time, opts); + date_s = pcmk__time_text(time, opts); out->info(out, "Duration ends at: %s", date_s); @@ -214,7 +214,7 @@ duration_ends_xml(pcmk__output_t *out, va_list args) char *date_s = NULL; opts |= crm_time_log_date | crm_time_log_timeofday | crm_time_log_with_timezone; - date_s = crm_time_as_string(time, opts); + date_s = pcmk__time_text(time, opts); pcmk__output_create_xml_text_node(out, PCMK_XE_DURATION_ENDS, date_s); free(date_s); @@ -234,12 +234,12 @@ period_default(pcmk__output_t *out, va_list args) opts |= crm_time_log_date | crm_time_log_timeofday; - start_s = crm_time_as_string(start, opts); + start_s = pcmk__time_text(start, opts); if (start_s == NULL) { return pcmk_rc_no_output; } - end_s = crm_time_as_string(end, opts); + end_s = pcmk__time_text(end, opts); if (end_s == NULL) { free(start_s); return pcmk_rc_no_output; @@ -265,12 +265,12 @@ period_xml(pcmk__output_t *out, va_list args) opts |= crm_time_log_date | crm_time_log_timeofday; - start_s = crm_time_as_string(start, opts); + start_s = pcmk__time_text(start, opts); if (start_s == NULL) { return pcmk_rc_no_output; } - end_s = crm_time_as_string(end, opts); + end_s = pcmk__time_text(end, opts); if (end_s == NULL) { free(start_s); return pcmk_rc_no_output; @@ -513,9 +513,10 @@ main(int argc, char **argv) out->message(out, "duration_ends", later, options.print_options); if (options.expected_s) { - char *dt_s = crm_time_as_string(later, - options.print_options | crm_time_log_date | - crm_time_log_timeofday); + char *dt_s = pcmk__time_text(later, + options.print_options + |crm_time_log_date + |crm_time_log_timeofday); if (!pcmk__str_eq(options.expected_s, dt_s, pcmk__str_casei)) { exit_code = CRM_EX_ERROR; goto done; @@ -525,8 +526,10 @@ main(int argc, char **argv) crm_time_free(later); } else if (date_time && options.expected_s) { - char *dt_s = crm_time_as_string(date_time, - options.print_options | crm_time_log_date | crm_time_log_timeofday); + char *dt_s = pcmk__time_text(date_time, + options.print_options + |crm_time_log_date + |crm_time_log_timeofday); if (!pcmk__str_eq(options.expected_s, dt_s, pcmk__str_casei)) { exit_code = CRM_EX_ERROR; From 996311c4b360456ac15a933d93aaee3c185dfead Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:28:04 -0700 Subject: [PATCH 10/40] API: libcrmcommon: Deprecate crm_time_as_string() Pacemaker should not be used for general-purpose date/time manipulation. It also does not return crm_time_t objects (except in the case of pcmk_evaluate_rule(), as discussed in previous commit messages). So external callers have no need to convert a crm_time_t to a string representation. Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 2 -- include/crm/common/iso8601_compat.h | 3 +++ lib/common/iso8601.c | 20 ++++++-------------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index e0426665dc0..07e20d1301b 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,8 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -char *crm_time_as_string(const crm_time_t *dt, int flags); - #define crm_time_log_date 0x001 #define crm_time_log_timeofday 0x002 #define crm_time_log_with_timezone 0x004 diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 05889f933bb..282637248d7 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -92,6 +92,9 @@ crm_time_t *crm_time_new_undefined(void); //! \deprecated Do not use bool crm_time_is_defined(const crm_time_t *t); +//! \deprecated Do not use +char *crm_time_as_string(const crm_time_t *dt, int flags); + #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 2b5fa9b9983..e2cebac9ca6 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1119,20 +1119,6 @@ pcmk__time_text(const crm_time_t *dt, int flags) return time_as_string_common(dt, 0, flags); } -/*! - * \brief Get a string representation of a \p crm_time_t object - * - * \param[in] dt Time to convert to string - * \param[in] flags Group of \p crm_time_* string format options - * - * \note The caller is responsible for freeing the return value using \p free(). - */ -char * -crm_time_as_string(const crm_time_t *dt, int flags) -{ - return pcmk__time_text(dt, flags); -} - // Parse an ISO 8601 numeric value and return number of characters consumed static int parse_int(const char *str, int *result) @@ -2440,5 +2426,11 @@ crm_time_is_defined(const crm_time_t *t) return pcmk__time_is_initialized(t); } +char * +crm_time_as_string(const crm_time_t *dt, int flags) +{ + return pcmk__time_text(dt, flags); +} + // LCOV_EXCL_STOP // End deprecated API From 45a0716a26a49ff7b9a5f0b6f8761696411c968e Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:33:41 -0700 Subject: [PATCH 11/40] Refactor: libcrmcommon: New pcmk__time_fmt_date flag To replace crm_time_log_date. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 7 +++++++ lib/common/iso8601.c | 10 +++++----- lib/common/tls.c | 5 +++-- lib/fencing/st_output.c | 2 +- lib/pacemaker/pcmk_output.c | 6 +++--- lib/pacemaker/pcmk_simulate.c | 2 +- lib/pengine/pe_output.c | 2 +- tools/crm_resource_ban.c | 2 +- tools/iso8601.c | 20 ++++++++++++-------- 9 files changed, 34 insertions(+), 22 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 33b4f0b55cc..fe01f861478 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -26,6 +26,13 @@ extern "C" { #endif +/* @COMPAT These must be kept in line with the deprecated crm_time_* flags until + * those are removed + */ +enum pcmk__time_fmt_flags { + pcmk__time_fmt_date = (UINT32_C(1) << 0), +}; + bool pcmk__time_valid_year(int year); bool pcmk__time_is_initialized(const crm_time_t *dt); void pcmk__time_get_ywd(const crm_time_t *dt, uint32_t *y, uint32_t *w, diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index e2cebac9ca6..0c4658df0a6 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -440,7 +440,7 @@ valid_time(const crm_time_t *dt) static crm_time_t * parse_date(const char *date_str) { - const uint32_t flags = crm_time_log_date|crm_time_log_timeofday; + const uint32_t flags = pcmk__time_fmt_date|crm_time_log_timeofday; const char *time_s = NULL; crm_time_t *dt = NULL; @@ -619,7 +619,7 @@ parse_date(const char *date_str) static crm_time_t * copy_time_to_utc(const crm_time_t *dt) { - const uint32_t flags = crm_time_log_date + const uint32_t flags = pcmk__time_fmt_date |crm_time_log_timeofday |crm_time_log_with_timezone; crm_time_t *utc = NULL; @@ -1034,7 +1034,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) // As readable string - if (pcmk__is_set(flags, crm_time_log_date)) { + if (pcmk__is_set(flags, pcmk__time_fmt_date)) { if (pcmk__is_set(flags, crm_time_weeks)) { // YYYY-WW-D if (dt->days > 0) { uint32_t y = 0; @@ -1359,7 +1359,7 @@ pcmk__time_parse_duration(const char *period_s) void pcmk__set_time_if_earlier(crm_time_t *target, const crm_time_t *source) { - const int flags = crm_time_log_date + const int flags = pcmk__time_fmt_date |crm_time_log_timeofday |crm_time_log_with_timezone; @@ -2241,7 +2241,7 @@ crm_time_january1_weekday(int year) void crm_time_set(crm_time_t *target, const crm_time_t *source) { - const uint32_t flags = crm_time_log_date + const uint32_t flags = pcmk__time_fmt_date |crm_time_log_timeofday |crm_time_log_with_timezone; diff --git a/lib/common/tls.c b/lib/common/tls.c index 3ba6aa94661..f9bab37348d 100644 --- a/lib/common/tls.c +++ b/lib/common/tls.c @@ -27,7 +27,7 @@ #include // QB_XS #include -#include // crm_time_free, crm_time_log_date +#include // crm_time_* #include // CRM_CHECK #include // pcmk_rc_* @@ -474,7 +474,8 @@ pcmk__tls_check_cert_expiration(gnutls_session_t session) crm_time_t *expiry_t = pcmk__copy_timet(expiry); pcmk__time_log(LOG_WARNING, "TLS certificate will expire on", - expiry_t, crm_time_log_date|crm_time_log_timeofday); + expiry_t, + pcmk__time_fmt_date|crm_time_log_timeofday); crm_time_free(expiry_t); } } diff --git a/lib/fencing/st_output.c b/lib/fencing/st_output.c index 5e5ad1209fd..b31753f90cb 100644 --- a/lib/fencing/st_output.c +++ b/lib/fencing/st_output.c @@ -49,7 +49,7 @@ timespec_string(time_t sec, long nsec, bool show_usec) { }; return pcmk__timespec2str(&ts, - crm_time_log_date + pcmk__time_fmt_date |crm_time_log_timeofday |crm_time_log_with_timezone |(show_usec? crm_time_usecs : 0)); diff --git a/lib/pacemaker/pcmk_output.c b/lib/pacemaker/pcmk_output.c index 69d02d9087e..98a55b93fe8 100644 --- a/lib/pacemaker/pcmk_output.c +++ b/lib/pacemaker/pcmk_output.c @@ -755,7 +755,7 @@ pacemakerd_health(pcmk__output_t *out, va_list args) if (last_updated != 0) { last_updated_s = pcmk__epoch2str(&last_updated, - crm_time_log_date + pcmk__time_fmt_date |crm_time_log_timeofday |crm_time_log_with_timezone); } @@ -796,7 +796,7 @@ pacemakerd_health_html(pcmk__output_t *out, va_list args) if (last_updated != 0) { last_updated_s = pcmk__epoch2str(&last_updated, - crm_time_log_date + pcmk__time_fmt_date |crm_time_log_timeofday |crm_time_log_with_timezone); } @@ -860,7 +860,7 @@ pacemakerd_health_xml(pcmk__output_t *out, va_list args) if (last_updated != 0) { last_updated_s = pcmk__epoch2str(&last_updated, - crm_time_log_date + pcmk__time_fmt_date |crm_time_log_timeofday |crm_time_log_with_timezone); } diff --git a/lib/pacemaker/pcmk_simulate.c b/lib/pacemaker/pcmk_simulate.c index 5f231e2ee07..55a8793e83a 100644 --- a/lib/pacemaker/pcmk_simulate.c +++ b/lib/pacemaker/pcmk_simulate.c @@ -498,7 +498,7 @@ static void set_effective_date(pcmk_scheduler_t *scheduler, bool print_original, const char *use_date) { - static const uint32_t flags = crm_time_log_date|crm_time_log_timeofday; + static const uint32_t flags = pcmk__time_fmt_date|crm_time_log_timeofday; pcmk__output_t *out = scheduler->priv->out; time_t original_date = 0; diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c index b351205fc75..1b6345ff52f 100644 --- a/lib/pengine/pe_output.c +++ b/lib/pengine/pe_output.c @@ -1669,7 +1669,7 @@ failed_action_xml(pcmk__output_t *out, va_list args) { unsigned int interval_ms = 0; char *interval_ms_s = NULL; char *rc_change = pcmk__epoch2str(&epoch, - crm_time_log_date + pcmk__time_fmt_date |crm_time_log_timeofday |crm_time_log_with_timezone); diff --git a/tools/crm_resource_ban.c b/tools/crm_resource_ban.c index d7a594bc45c..093a08e6607 100644 --- a/tools/crm_resource_ban.c +++ b/tools/crm_resource_ban.c @@ -24,7 +24,7 @@ parse_cli_lifetime(pcmk__output_t *out, const char *move_lifetime) crm_time_t *now = NULL; crm_time_t *later = NULL; crm_time_t *duration = NULL; - const uint32_t duration_flags = crm_time_log_date|crm_time_log_timeofday; + const uint32_t duration_flags = pcmk__time_fmt_date|crm_time_log_timeofday; const uint32_t time_flags = duration_flags|crm_time_log_with_timezone; if (move_lifetime == NULL) { diff --git a/tools/iso8601.c b/tools/iso8601.c index 2b2d44faa27..f9e5d6932bd 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -130,7 +130,7 @@ date_default(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= crm_time_log_date | crm_time_log_timeofday; + opts |= pcmk__time_fmt_date|crm_time_log_timeofday; date_s = pcmk__time_text(date, opts); out->info(out, "%s: %s", prefix, date_s); @@ -149,7 +149,7 @@ date_xml(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= crm_time_log_date | crm_time_log_timeofday; + opts |= pcmk__time_fmt_date|crm_time_log_timeofday; date_s = pcmk__time_text(date, opts); pcmk__output_create_xml_text_node(out, PCMK_XE_DATE, date_s); @@ -195,7 +195,9 @@ duration_ends_default(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= crm_time_log_date | crm_time_log_timeofday | crm_time_log_with_timezone; + opts |= pcmk__time_fmt_date + |crm_time_log_timeofday + |crm_time_log_with_timezone; date_s = pcmk__time_text(time, opts); out->info(out, "Duration ends at: %s", date_s); @@ -213,7 +215,9 @@ duration_ends_xml(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= crm_time_log_date | crm_time_log_timeofday | crm_time_log_with_timezone; + opts |= pcmk__time_fmt_date + |crm_time_log_timeofday + |crm_time_log_with_timezone; date_s = pcmk__time_text(time, opts); pcmk__output_create_xml_text_node(out, PCMK_XE_DURATION_ENDS, date_s); @@ -232,7 +236,7 @@ period_default(pcmk__output_t *out, va_list args) char *start_s = NULL; char *end_s = NULL; - opts |= crm_time_log_date | crm_time_log_timeofday; + opts |= pcmk__time_fmt_date|crm_time_log_timeofday; start_s = pcmk__time_text(start, opts); if (start_s == NULL) { @@ -263,7 +267,7 @@ period_xml(pcmk__output_t *out, va_list args) char *start_s = NULL; char *end_s = NULL; - opts |= crm_time_log_date | crm_time_log_timeofday; + opts |= pcmk__time_fmt_date|crm_time_log_timeofday; start_s = pcmk__time_text(start, opts); if (start_s == NULL) { @@ -515,7 +519,7 @@ main(int argc, char **argv) if (options.expected_s) { char *dt_s = pcmk__time_text(later, options.print_options - |crm_time_log_date + |pcmk__time_fmt_date |crm_time_log_timeofday); if (!pcmk__str_eq(options.expected_s, dt_s, pcmk__str_casei)) { exit_code = CRM_EX_ERROR; @@ -528,7 +532,7 @@ main(int argc, char **argv) } else if (date_time && options.expected_s) { char *dt_s = pcmk__time_text(date_time, options.print_options - |crm_time_log_date + |pcmk__time_fmt_date |crm_time_log_timeofday); if (!pcmk__str_eq(options.expected_s, dt_s, pcmk__str_casei)) { From b846a9bee9d6720be0779410c39b5d55e5ef2036 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:37:29 -0700 Subject: [PATCH 12/40] API: libcrmcommon: Deprecate crm_time_log_date Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 1 - include/crm/common/iso8601_compat.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 07e20d1301b..ac6c5dd2c74 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,7 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -#define crm_time_log_date 0x001 #define crm_time_log_timeofday 0x002 #define crm_time_log_with_timezone 0x004 #define crm_time_log_duration 0x008 diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 282637248d7..70108907147 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -29,6 +29,9 @@ extern "C" { * release. */ +//! \deprecated Do not use +#define crm_time_log_date 0x001 + //! \deprecated Do not use typedef struct crm_time_period_s { crm_time_t *start; From 660c7fb3f98e101c9e45e8fe6407d8893ba65de6 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:43:47 -0700 Subject: [PATCH 13/40] Refactor: libcrmcommon: New pcmk__time_fmt_time To replace crm_time_log_timeofday. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 1 + lib/common/iso8601.c | 10 +++++----- lib/common/tls.c | 3 +-- lib/fencing/st_output.c | 2 +- lib/pacemaker/pcmk_output.c | 6 +++--- lib/pacemaker/pcmk_simulate.c | 2 +- lib/pengine/pe_output.c | 2 +- tools/crm_resource_ban.c | 2 +- tools/iso8601.c | 20 ++++++++------------ 9 files changed, 22 insertions(+), 26 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index fe01f861478..f9d6fd80265 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -31,6 +31,7 @@ extern "C" { */ enum pcmk__time_fmt_flags { pcmk__time_fmt_date = (UINT32_C(1) << 0), + pcmk__time_fmt_time = (UINT32_C(1) << 1), }; bool pcmk__time_valid_year(int year); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 0c4658df0a6..c82edfa6b2e 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -440,7 +440,7 @@ valid_time(const crm_time_t *dt) static crm_time_t * parse_date(const char *date_str) { - const uint32_t flags = pcmk__time_fmt_date|crm_time_log_timeofday; + const uint32_t flags = pcmk__time_fmt_date|pcmk__time_fmt_time; const char *time_s = NULL; crm_time_t *dt = NULL; @@ -620,7 +620,7 @@ static crm_time_t * copy_time_to_utc(const crm_time_t *dt) { const uint32_t flags = pcmk__time_fmt_date - |crm_time_log_timeofday + |pcmk__time_fmt_time |crm_time_log_with_timezone; crm_time_t *utc = NULL; @@ -1068,7 +1068,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) } } - if (pcmk__is_set(flags, crm_time_log_timeofday)) { + if (pcmk__is_set(flags, pcmk__time_fmt_time)) { uint32_t h = 0, m = 0, s = 0; if (buf->len > 0) { @@ -1360,7 +1360,7 @@ void pcmk__set_time_if_earlier(crm_time_t *target, const crm_time_t *source) { const int flags = pcmk__time_fmt_date - |crm_time_log_timeofday + |pcmk__time_fmt_time |crm_time_log_with_timezone; if ((target == NULL) @@ -2242,7 +2242,7 @@ void crm_time_set(crm_time_t *target, const crm_time_t *source) { const uint32_t flags = pcmk__time_fmt_date - |crm_time_log_timeofday + |pcmk__time_fmt_time |crm_time_log_with_timezone; pcmk__trace("target=%p, source=%p", target, source); diff --git a/lib/common/tls.c b/lib/common/tls.c index f9bab37348d..1d834a59812 100644 --- a/lib/common/tls.c +++ b/lib/common/tls.c @@ -474,8 +474,7 @@ pcmk__tls_check_cert_expiration(gnutls_session_t session) crm_time_t *expiry_t = pcmk__copy_timet(expiry); pcmk__time_log(LOG_WARNING, "TLS certificate will expire on", - expiry_t, - pcmk__time_fmt_date|crm_time_log_timeofday); + expiry_t, pcmk__time_fmt_date|pcmk__time_fmt_time); crm_time_free(expiry_t); } } diff --git a/lib/fencing/st_output.c b/lib/fencing/st_output.c index b31753f90cb..95262650c9f 100644 --- a/lib/fencing/st_output.c +++ b/lib/fencing/st_output.c @@ -50,7 +50,7 @@ timespec_string(time_t sec, long nsec, bool show_usec) { return pcmk__timespec2str(&ts, pcmk__time_fmt_date - |crm_time_log_timeofday + |pcmk__time_fmt_time |crm_time_log_with_timezone |(show_usec? crm_time_usecs : 0)); } diff --git a/lib/pacemaker/pcmk_output.c b/lib/pacemaker/pcmk_output.c index 98a55b93fe8..c6e1c5678a5 100644 --- a/lib/pacemaker/pcmk_output.c +++ b/lib/pacemaker/pcmk_output.c @@ -756,7 +756,7 @@ pacemakerd_health(pcmk__output_t *out, va_list args) if (last_updated != 0) { last_updated_s = pcmk__epoch2str(&last_updated, pcmk__time_fmt_date - |crm_time_log_timeofday + |pcmk__time_fmt_time |crm_time_log_with_timezone); } @@ -797,7 +797,7 @@ pacemakerd_health_html(pcmk__output_t *out, va_list args) if (last_updated != 0) { last_updated_s = pcmk__epoch2str(&last_updated, pcmk__time_fmt_date - |crm_time_log_timeofday + |pcmk__time_fmt_time |crm_time_log_with_timezone); } @@ -861,7 +861,7 @@ pacemakerd_health_xml(pcmk__output_t *out, va_list args) if (last_updated != 0) { last_updated_s = pcmk__epoch2str(&last_updated, pcmk__time_fmt_date - |crm_time_log_timeofday + |pcmk__time_fmt_time |crm_time_log_with_timezone); } diff --git a/lib/pacemaker/pcmk_simulate.c b/lib/pacemaker/pcmk_simulate.c index 55a8793e83a..be5c7da5ded 100644 --- a/lib/pacemaker/pcmk_simulate.c +++ b/lib/pacemaker/pcmk_simulate.c @@ -498,7 +498,7 @@ static void set_effective_date(pcmk_scheduler_t *scheduler, bool print_original, const char *use_date) { - static const uint32_t flags = pcmk__time_fmt_date|crm_time_log_timeofday; + static const uint32_t flags = pcmk__time_fmt_date|pcmk__time_fmt_time; pcmk__output_t *out = scheduler->priv->out; time_t original_date = 0; diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c index 1b6345ff52f..e0d1c646ee5 100644 --- a/lib/pengine/pe_output.c +++ b/lib/pengine/pe_output.c @@ -1670,7 +1670,7 @@ failed_action_xml(pcmk__output_t *out, va_list args) { char *interval_ms_s = NULL; char *rc_change = pcmk__epoch2str(&epoch, pcmk__time_fmt_date - |crm_time_log_timeofday + |pcmk__time_fmt_time |crm_time_log_with_timezone); pcmk__xe_get_uint(xml_op, PCMK_META_INTERVAL, &interval_ms); diff --git a/tools/crm_resource_ban.c b/tools/crm_resource_ban.c index 093a08e6607..89f2b14cc9a 100644 --- a/tools/crm_resource_ban.c +++ b/tools/crm_resource_ban.c @@ -24,7 +24,7 @@ parse_cli_lifetime(pcmk__output_t *out, const char *move_lifetime) crm_time_t *now = NULL; crm_time_t *later = NULL; crm_time_t *duration = NULL; - const uint32_t duration_flags = pcmk__time_fmt_date|crm_time_log_timeofday; + const uint32_t duration_flags = pcmk__time_fmt_date|pcmk__time_fmt_time; const uint32_t time_flags = duration_flags|crm_time_log_with_timezone; if (move_lifetime == NULL) { diff --git a/tools/iso8601.c b/tools/iso8601.c index f9e5d6932bd..c3e84bea898 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -130,7 +130,7 @@ date_default(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= pcmk__time_fmt_date|crm_time_log_timeofday; + opts |= pcmk__time_fmt_date|pcmk__time_fmt_time; date_s = pcmk__time_text(date, opts); out->info(out, "%s: %s", prefix, date_s); @@ -149,7 +149,7 @@ date_xml(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= pcmk__time_fmt_date|crm_time_log_timeofday; + opts |= pcmk__time_fmt_date|pcmk__time_fmt_time; date_s = pcmk__time_text(date, opts); pcmk__output_create_xml_text_node(out, PCMK_XE_DATE, date_s); @@ -195,9 +195,7 @@ duration_ends_default(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= pcmk__time_fmt_date - |crm_time_log_timeofday - |crm_time_log_with_timezone; + opts |= pcmk__time_fmt_date|pcmk__time_fmt_time|crm_time_log_with_timezone; date_s = pcmk__time_text(time, opts); out->info(out, "Duration ends at: %s", date_s); @@ -215,9 +213,7 @@ duration_ends_xml(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= pcmk__time_fmt_date - |crm_time_log_timeofday - |crm_time_log_with_timezone; + opts |= pcmk__time_fmt_date|pcmk__time_fmt_time|crm_time_log_with_timezone; date_s = pcmk__time_text(time, opts); pcmk__output_create_xml_text_node(out, PCMK_XE_DURATION_ENDS, date_s); @@ -236,7 +232,7 @@ period_default(pcmk__output_t *out, va_list args) char *start_s = NULL; char *end_s = NULL; - opts |= pcmk__time_fmt_date|crm_time_log_timeofday; + opts |= pcmk__time_fmt_date|pcmk__time_fmt_time; start_s = pcmk__time_text(start, opts); if (start_s == NULL) { @@ -267,7 +263,7 @@ period_xml(pcmk__output_t *out, va_list args) char *start_s = NULL; char *end_s = NULL; - opts |= pcmk__time_fmt_date|crm_time_log_timeofday; + opts |= pcmk__time_fmt_date|pcmk__time_fmt_time; start_s = pcmk__time_text(start, opts); if (start_s == NULL) { @@ -520,7 +516,7 @@ main(int argc, char **argv) char *dt_s = pcmk__time_text(later, options.print_options |pcmk__time_fmt_date - |crm_time_log_timeofday); + |pcmk__time_fmt_time); if (!pcmk__str_eq(options.expected_s, dt_s, pcmk__str_casei)) { exit_code = CRM_EX_ERROR; goto done; @@ -533,7 +529,7 @@ main(int argc, char **argv) char *dt_s = pcmk__time_text(date_time, options.print_options |pcmk__time_fmt_date - |crm_time_log_timeofday); + |pcmk__time_fmt_time); if (!pcmk__str_eq(options.expected_s, dt_s, pcmk__str_casei)) { exit_code = CRM_EX_ERROR; From aa5bc31a963ea38d47de6ae2a25bf4f044c41da4 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:44:38 -0700 Subject: [PATCH 14/40] API: libcrmcommon: Deprecate crm_time_log_timeofday Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 1 - include/crm/common/iso8601_compat.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index ac6c5dd2c74..570e9de045b 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,7 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -#define crm_time_log_timeofday 0x002 #define crm_time_log_with_timezone 0x004 #define crm_time_log_duration 0x008 diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 70108907147..dc60ec7b94f 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -32,6 +32,9 @@ extern "C" { //! \deprecated Do not use #define crm_time_log_date 0x001 +//! \deprecated Do not use +#define crm_time_log_timeofday 0x002 + //! \deprecated Do not use typedef struct crm_time_period_s { crm_time_t *start; From eb5476dfbebb00d632341600dc5f98f41370c0b4 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:47:01 -0700 Subject: [PATCH 15/40] Refactor: libcrmcommon: New pcmk__time_fmt_timezone To replace crm_time_log_with_timezone. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 1 + lib/common/iso8601.c | 12 +++++------- lib/fencing/st_output.c | 2 +- lib/pacemaker/pcmk_output.c | 6 +++--- lib/pengine/pe_output.c | 2 +- tools/crm_resource_ban.c | 2 +- tools/iso8601.c | 6 +++--- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index f9d6fd80265..6511397458d 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -32,6 +32,7 @@ extern "C" { enum pcmk__time_fmt_flags { pcmk__time_fmt_date = (UINT32_C(1) << 0), pcmk__time_fmt_time = (UINT32_C(1) << 1), + pcmk__time_fmt_timezone = (UINT32_C(1) << 2), }; bool pcmk__time_valid_year(int year); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index c82edfa6b2e..22c3a99da4e 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -621,7 +621,7 @@ copy_time_to_utc(const crm_time_t *dt) { const uint32_t flags = pcmk__time_fmt_date |pcmk__time_fmt_time - |crm_time_log_with_timezone; + |pcmk__time_fmt_timezone; crm_time_t *utc = NULL; pcmk__assert(dt != NULL); @@ -1027,7 +1027,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) } // Convert to UTC if local timezone was not requested - if ((dt->offset != 0) && !pcmk__is_set(flags, crm_time_log_with_timezone)) { + if ((dt->offset != 0) && !pcmk__is_set(flags, pcmk__time_fmt_timezone)) { utc = copy_time_to_utc(dt); dt = utc; } @@ -1085,9 +1085,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) } } - if (pcmk__is_set(flags, crm_time_log_with_timezone) - && (dt->offset != 0)) { - + if (pcmk__is_set(flags, pcmk__time_fmt_timezone) && (dt->offset != 0)) { seconds_to_hms(dt->offset, &h, &m, NULL); g_string_append_printf(buf, " %c%.2" PRIu32 ":%.2" PRIu32, ((dt->offset < 0)? '-' : '+'), h, m); @@ -1361,7 +1359,7 @@ pcmk__set_time_if_earlier(crm_time_t *target, const crm_time_t *source) { const int flags = pcmk__time_fmt_date |pcmk__time_fmt_time - |crm_time_log_with_timezone; + |pcmk__time_fmt_timezone; if ((target == NULL) || (source == NULL) @@ -2243,7 +2241,7 @@ crm_time_set(crm_time_t *target, const crm_time_t *source) { const uint32_t flags = pcmk__time_fmt_date |pcmk__time_fmt_time - |crm_time_log_with_timezone; + |pcmk__time_fmt_timezone; pcmk__trace("target=%p, source=%p", target, source); diff --git a/lib/fencing/st_output.c b/lib/fencing/st_output.c index 95262650c9f..710e9357aae 100644 --- a/lib/fencing/st_output.c +++ b/lib/fencing/st_output.c @@ -51,7 +51,7 @@ timespec_string(time_t sec, long nsec, bool show_usec) { return pcmk__timespec2str(&ts, pcmk__time_fmt_date |pcmk__time_fmt_time - |crm_time_log_with_timezone + |pcmk__time_fmt_timezone |(show_usec? crm_time_usecs : 0)); } diff --git a/lib/pacemaker/pcmk_output.c b/lib/pacemaker/pcmk_output.c index c6e1c5678a5..7df5120c3bf 100644 --- a/lib/pacemaker/pcmk_output.c +++ b/lib/pacemaker/pcmk_output.c @@ -757,7 +757,7 @@ pacemakerd_health(pcmk__output_t *out, va_list args) last_updated_s = pcmk__epoch2str(&last_updated, pcmk__time_fmt_date |pcmk__time_fmt_time - |crm_time_log_with_timezone); + |pcmk__time_fmt_timezone); } rc = out->info(out, "Status of %s: '%s' (last updated %s)", @@ -798,7 +798,7 @@ pacemakerd_health_html(pcmk__output_t *out, va_list args) last_updated_s = pcmk__epoch2str(&last_updated, pcmk__time_fmt_date |pcmk__time_fmt_time - |crm_time_log_with_timezone); + |pcmk__time_fmt_timezone); } msg = pcmk__assert_asprintf("Status of %s: '%s' (last updated %s)", @@ -862,7 +862,7 @@ pacemakerd_health_xml(pcmk__output_t *out, va_list args) last_updated_s = pcmk__epoch2str(&last_updated, pcmk__time_fmt_date |pcmk__time_fmt_time - |crm_time_log_with_timezone); + |pcmk__time_fmt_timezone); } pcmk__output_create_xml_node(out, PCMK_XE_PACEMAKERD, diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c index e0d1c646ee5..86135a40582 100644 --- a/lib/pengine/pe_output.c +++ b/lib/pengine/pe_output.c @@ -1671,7 +1671,7 @@ failed_action_xml(pcmk__output_t *out, va_list args) { char *rc_change = pcmk__epoch2str(&epoch, pcmk__time_fmt_date |pcmk__time_fmt_time - |crm_time_log_with_timezone); + |pcmk__time_fmt_timezone); pcmk__xe_get_uint(xml_op, PCMK_META_INTERVAL, &interval_ms); interval_ms_s = pcmk__assert_asprintf("%u", interval_ms); diff --git a/tools/crm_resource_ban.c b/tools/crm_resource_ban.c index 89f2b14cc9a..f169660a85c 100644 --- a/tools/crm_resource_ban.c +++ b/tools/crm_resource_ban.c @@ -25,7 +25,7 @@ parse_cli_lifetime(pcmk__output_t *out, const char *move_lifetime) crm_time_t *later = NULL; crm_time_t *duration = NULL; const uint32_t duration_flags = pcmk__time_fmt_date|pcmk__time_fmt_time; - const uint32_t time_flags = duration_flags|crm_time_log_with_timezone; + const uint32_t time_flags = duration_flags|pcmk__time_fmt_timezone; if (move_lifetime == NULL) { return NULL; diff --git a/tools/iso8601.c b/tools/iso8601.c index c3e84bea898..803683a6657 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -59,7 +59,7 @@ modifier_cb(const char *option_name, const char *optarg, void *data, } else if (pcmk__str_any_of(option_name, "--epoch", "-S", NULL)) { options.print_options |= crm_time_epoch; } else if (pcmk__str_any_of(option_name, "--local", "-L", NULL)) { - options.print_options |= crm_time_log_with_timezone; + options.print_options |= pcmk__time_fmt_timezone; } else if (pcmk__str_any_of(option_name, "--ordinal", "-O", NULL)) { options.print_options |= crm_time_ordinal; } else if (pcmk__str_any_of(option_name, "--week", "-W", NULL)) { @@ -195,7 +195,7 @@ duration_ends_default(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= pcmk__time_fmt_date|pcmk__time_fmt_time|crm_time_log_with_timezone; + opts |= pcmk__time_fmt_date|pcmk__time_fmt_time|pcmk__time_fmt_timezone; date_s = pcmk__time_text(time, opts); out->info(out, "Duration ends at: %s", date_s); @@ -213,7 +213,7 @@ duration_ends_xml(pcmk__output_t *out, va_list args) char *date_s = NULL; - opts |= pcmk__time_fmt_date|pcmk__time_fmt_time|crm_time_log_with_timezone; + opts |= pcmk__time_fmt_date|pcmk__time_fmt_time|pcmk__time_fmt_timezone; date_s = pcmk__time_text(time, opts); pcmk__output_create_xml_text_node(out, PCMK_XE_DURATION_ENDS, date_s); From 2e5f99d227079e42796104ca42e81b3a97497c8b Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:47:29 -0700 Subject: [PATCH 16/40] API: libcrmcommon: Deprecate crm_time_log_with_timezone Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 1 - include/crm/common/iso8601_compat.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 570e9de045b..214ed30abbc 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,7 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -#define crm_time_log_with_timezone 0x004 #define crm_time_log_duration 0x008 #define crm_time_ordinal 0x010 diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index dc60ec7b94f..784371b1e75 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -35,6 +35,9 @@ extern "C" { //! \deprecated Do not use #define crm_time_log_timeofday 0x002 +//! \deprecated Do not use +#define crm_time_log_with_timezone 0x004 + //! \deprecated Do not use typedef struct crm_time_period_s { crm_time_t *start; From 4adca8735bc2728002560a97a310dfdbd0358e45 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:49:53 -0700 Subject: [PATCH 17/40] Refactor: libcrmcommon: New pcmk__time_fmt_duration To replace crm_time_log_duration. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 3 +++ lib/common/iso8601.c | 2 +- tools/iso8601.c | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 6511397458d..f6f83a46244 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -33,6 +33,9 @@ enum pcmk__time_fmt_flags { pcmk__time_fmt_date = (UINT32_C(1) << 0), pcmk__time_fmt_time = (UINT32_C(1) << 1), pcmk__time_fmt_timezone = (UINT32_C(1) << 2), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + pcmk__time_fmt_duration = (UINT32_C(1) << 3), }; bool pcmk__time_valid_year(int year); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 22c3a99da4e..71f515e3b90 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1004,7 +1004,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) * These never depend on time zone. */ - if (pcmk__is_set(flags, crm_time_log_duration)) { + if (pcmk__is_set(flags, pcmk__time_fmt_duration)) { duration_as_string(dt, usec, pcmk__is_set(flags, crm_time_usecs), buf); goto done; } diff --git a/tools/iso8601.c b/tools/iso8601.c index 803683a6657..da9cf3434a5 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -164,7 +164,7 @@ duration_default(pcmk__output_t *out, va_list args) crm_time_t *time = va_arg(args, crm_time_t *); int opts = va_arg(args, int); - char *date_s = pcmk__time_text(time, opts|crm_time_log_duration); + char *date_s = pcmk__time_text(time, opts|pcmk__time_fmt_duration); out->info(out, "Duration: %s", date_s); @@ -179,7 +179,7 @@ duration_xml(pcmk__output_t *out, va_list args) crm_time_t *time = va_arg(args, crm_time_t *); int opts = va_arg(args, int); - char *date_s = pcmk__time_text(time, opts|crm_time_log_duration); + char *date_s = pcmk__time_text(time, opts|pcmk__time_fmt_duration); pcmk__output_create_xml_text_node(out, PCMK_XE_DURATION, date_s); free(date_s); From e0e9729279268c57b2e20ff5afb3d532e9352b86 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:50:22 -0700 Subject: [PATCH 18/40] API: libcrmcommon: Deprecate crm_time_log_duration Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 2 -- include/crm/common/iso8601_compat.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 214ed30abbc..ae7ce172ca9 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,8 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -#define crm_time_log_duration 0x008 - #define crm_time_ordinal 0x010 #define crm_time_weeks 0x020 #define crm_time_seconds 0x100 diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 784371b1e75..a0f839fb792 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -38,6 +38,9 @@ extern "C" { //! \deprecated Do not use #define crm_time_log_with_timezone 0x004 +//! \deprecated Do not use +#define crm_time_log_duration 0x008 + //! \deprecated Do not use typedef struct crm_time_period_s { crm_time_t *start; From f5ddcce7591afd574f9b2acbcd714d55d54cbbc2 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:51:40 -0700 Subject: [PATCH 19/40] Refactor: libcrmcommon: New pcmk__time_fmt_ordinal To replace crm_time_ordinal. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 3 +++ lib/common/iso8601.c | 2 +- tools/iso8601.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index f6f83a46244..ae548f90486 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -36,6 +36,9 @@ enum pcmk__time_fmt_flags { // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) pcmk__time_fmt_duration = (UINT32_C(1) << 3), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + pcmk__time_fmt_ordinal = (UINT32_C(1) << 4), }; bool pcmk__time_valid_year(int year); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 71f515e3b90..89259cef907 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1047,7 +1047,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) y, w, d); } - } else if (pcmk__is_set(flags, crm_time_ordinal)) { // YYYY-DDD + } else if (pcmk__is_set(flags, pcmk__time_fmt_ordinal)) { // YYYY-DDD uint32_t y = 0; uint32_t d = 0; diff --git a/tools/iso8601.c b/tools/iso8601.c index da9cf3434a5..54d37e792a3 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -61,7 +61,7 @@ modifier_cb(const char *option_name, const char *optarg, void *data, } else if (pcmk__str_any_of(option_name, "--local", "-L", NULL)) { options.print_options |= pcmk__time_fmt_timezone; } else if (pcmk__str_any_of(option_name, "--ordinal", "-O", NULL)) { - options.print_options |= crm_time_ordinal; + options.print_options |= pcmk__time_fmt_ordinal; } else if (pcmk__str_any_of(option_name, "--week", "-W", NULL)) { options.print_options |= crm_time_weeks; } From 04a95fe8065943578df1d1119d3e4ef0eabe5dba Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:52:11 -0700 Subject: [PATCH 20/40] API: libcrmcommon: Deprecate crm_time_ordinal Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 1 - include/crm/common/iso8601_compat.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index ae7ce172ca9..44e618195c1 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,7 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -#define crm_time_ordinal 0x010 #define crm_time_weeks 0x020 #define crm_time_seconds 0x100 #define crm_time_epoch 0x200 diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index a0f839fb792..4d1dc5271bd 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -41,6 +41,9 @@ extern "C" { //! \deprecated Do not use #define crm_time_log_duration 0x008 +//! \deprecated Do not use +#define crm_time_ordinal 0x010 + //! \deprecated Do not use typedef struct crm_time_period_s { crm_time_t *start; From 677732550131950781897bf3ae970849d2982ab1 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:54:04 -0700 Subject: [PATCH 21/40] Refactor: libcrmcommon: New pcmk__time_fmt_weeks To replace crm_time_weeks. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 3 +++ lib/common/iso8601.c | 2 +- tools/iso8601.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index ae548f90486..1789082dffd 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -39,6 +39,9 @@ enum pcmk__time_fmt_flags { // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) pcmk__time_fmt_ordinal = (UINT32_C(1) << 4), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + pcmk__time_fmt_weeks = (UINT32_C(1) << 5), }; bool pcmk__time_valid_year(int year); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 89259cef907..8d208256c5c 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1035,7 +1035,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) // As readable string if (pcmk__is_set(flags, pcmk__time_fmt_date)) { - if (pcmk__is_set(flags, crm_time_weeks)) { // YYYY-WW-D + if (pcmk__is_set(flags, pcmk__time_fmt_weeks)) { // YYYY-WW-D if (dt->days > 0) { uint32_t y = 0; uint32_t w = 0; diff --git a/tools/iso8601.c b/tools/iso8601.c index 54d37e792a3..a93f90f32f5 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -63,7 +63,7 @@ modifier_cb(const char *option_name, const char *optarg, void *data, } else if (pcmk__str_any_of(option_name, "--ordinal", "-O", NULL)) { options.print_options |= pcmk__time_fmt_ordinal; } else if (pcmk__str_any_of(option_name, "--week", "-W", NULL)) { - options.print_options |= crm_time_weeks; + options.print_options |= pcmk__time_fmt_weeks; } return TRUE; From 801c7597290b6f1535228966cdc8e331dd78170e Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:54:26 -0700 Subject: [PATCH 22/40] API: libcrmcommon: Deprecate crm_time_weeks Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 1 - include/crm/common/iso8601_compat.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 44e618195c1..1fac69d4a77 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,7 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -#define crm_time_weeks 0x020 #define crm_time_seconds 0x100 #define crm_time_epoch 0x200 #define crm_time_usecs 0x400 diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 4d1dc5271bd..29af2fea30a 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -44,6 +44,9 @@ extern "C" { //! \deprecated Do not use #define crm_time_ordinal 0x010 +//! \deprecated Do not use +#define crm_time_weeks 0x020 + //! \deprecated Do not use typedef struct crm_time_period_s { crm_time_t *start; From afef1dd1d19638488dd6b750ffa92735cc63811e Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:56:33 -0700 Subject: [PATCH 23/40] Refactor: libcrmcommon: New pcmk__time_fmt_seconds To replace crm_time_seconds. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 3 +++ lib/common/iso8601.c | 4 ++-- tools/iso8601.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 1789082dffd..82c6f2cb14c 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -42,6 +42,9 @@ enum pcmk__time_fmt_flags { // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) pcmk__time_fmt_weeks = (UINT32_C(1) << 5), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + pcmk__time_fmt_seconds = (UINT32_C(1) << 8), }; bool pcmk__time_valid_year(int year); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 8d208256c5c..3e05f302ed8 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1009,10 +1009,10 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) goto done; } - if (pcmk__any_flags_set(flags, crm_time_seconds|crm_time_epoch)) { + if (pcmk__any_flags_set(flags, pcmk__time_fmt_seconds|crm_time_epoch)) { long long seconds = 0; - if (pcmk__is_set(flags, crm_time_seconds)) { + if (pcmk__is_set(flags, pcmk__time_fmt_seconds)) { seconds = crm_time_get_seconds(dt); } else { seconds = crm_time_get_seconds_since_epoch(dt); diff --git a/tools/iso8601.c b/tools/iso8601.c index a93f90f32f5..50d40fdcd58 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -55,7 +55,7 @@ modifier_cb(const char *option_name, const char *optarg, void *data, GError **error) { if (pcmk__str_any_of(option_name, "--seconds", "-s", NULL)) { - options.print_options |= crm_time_seconds; + options.print_options |= pcmk__time_fmt_seconds; } else if (pcmk__str_any_of(option_name, "--epoch", "-S", NULL)) { options.print_options |= crm_time_epoch; } else if (pcmk__str_any_of(option_name, "--local", "-L", NULL)) { From a8a5b3c4398777c685f79902e53217f1854d344b Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:57:07 -0700 Subject: [PATCH 24/40] API: libcrmcommon: Deprecate crm_time_seconds Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 1 - include/crm/common/iso8601_compat.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 1fac69d4a77..744dd1d2117 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,7 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -#define crm_time_seconds 0x100 #define crm_time_epoch 0x200 #define crm_time_usecs 0x400 diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 29af2fea30a..3085a52c0f3 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -47,6 +47,9 @@ extern "C" { //! \deprecated Do not use #define crm_time_weeks 0x020 +//! \deprecated Do not use +#define crm_time_seconds 0x100 + //! \deprecated Do not use typedef struct crm_time_period_s { crm_time_t *start; From 6fccffc6c632f525d5300443355e2d9483ac2ae6 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:58:17 -0700 Subject: [PATCH 25/40] Refactor: libcrmcommon: New pcmk__time_fmt_epoch To replace crm_time_epoch. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 3 +++ lib/common/iso8601.c | 3 ++- tools/iso8601.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 82c6f2cb14c..ef3aea7ba43 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -45,6 +45,9 @@ enum pcmk__time_fmt_flags { // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) pcmk__time_fmt_seconds = (UINT32_C(1) << 8), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + pcmk__time_fmt_epoch = (UINT32_C(1) << 9), }; bool pcmk__time_valid_year(int year); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 3e05f302ed8..faa8a6f943a 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1009,7 +1009,8 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) goto done; } - if (pcmk__any_flags_set(flags, pcmk__time_fmt_seconds|crm_time_epoch)) { + if (pcmk__any_flags_set(flags, + pcmk__time_fmt_seconds|pcmk__time_fmt_epoch)) { long long seconds = 0; if (pcmk__is_set(flags, pcmk__time_fmt_seconds)) { diff --git a/tools/iso8601.c b/tools/iso8601.c index 50d40fdcd58..fd2c27d91e7 100644 --- a/tools/iso8601.c +++ b/tools/iso8601.c @@ -57,7 +57,7 @@ modifier_cb(const char *option_name, const char *optarg, void *data, if (pcmk__str_any_of(option_name, "--seconds", "-s", NULL)) { options.print_options |= pcmk__time_fmt_seconds; } else if (pcmk__str_any_of(option_name, "--epoch", "-S", NULL)) { - options.print_options |= crm_time_epoch; + options.print_options |= pcmk__time_fmt_epoch; } else if (pcmk__str_any_of(option_name, "--local", "-L", NULL)) { options.print_options |= pcmk__time_fmt_timezone; } else if (pcmk__str_any_of(option_name, "--ordinal", "-O", NULL)) { From f31267f4f67bd5f57ba3fca11d03535fd5488d94 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:58:40 -0700 Subject: [PATCH 26/40] API: libcrmcommon: Deprecate crm_time_epoch Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 1 - include/crm/common/iso8601_compat.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 744dd1d2117..9a7192d0fb4 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,7 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -#define crm_time_epoch 0x200 #define crm_time_usecs 0x400 int crm_time_compare(const crm_time_t *a, const crm_time_t *b); diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 3085a52c0f3..5c7b4471616 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -50,6 +50,9 @@ extern "C" { //! \deprecated Do not use #define crm_time_seconds 0x100 +//! \deprecated Do not use +#define crm_time_epoch 0x200 + //! \deprecated Do not use typedef struct crm_time_period_s { crm_time_t *start; From 3044398e034dccb210657c88ac8f590ba012104d Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:01:59 -0700 Subject: [PATCH 27/40] Refactor: libcrmcommon: New pcmk__time_fmt_usecs To replace crm_time_usecs. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 2 ++ lib/common/iso8601.c | 11 ++++++----- lib/fencing/st_output.c | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index ef3aea7ba43..a913f25e59b 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -48,6 +48,8 @@ enum pcmk__time_fmt_flags { // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) pcmk__time_fmt_epoch = (UINT32_C(1) << 9), + + pcmk__time_fmt_usecs = (UINT32_C(1) << 10), }; bool pcmk__time_valid_year(int year); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index faa8a6f943a..cf7c75a9698 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1005,7 +1005,8 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) */ if (pcmk__is_set(flags, pcmk__time_fmt_duration)) { - duration_as_string(dt, usec, pcmk__is_set(flags, crm_time_usecs), buf); + duration_as_string(dt, usec, pcmk__is_set(flags, pcmk__time_fmt_usecs), + buf); goto done; } @@ -1019,7 +1020,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) seconds = crm_time_get_seconds_since_epoch(dt); } - if (pcmk__is_set(flags, crm_time_usecs)) { + if (pcmk__is_set(flags, pcmk__time_fmt_usecs)) { sec_usec_as_string(seconds, usec, buf); } else { g_string_append_printf(buf, "%lld", seconds); @@ -1081,7 +1082,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) "%.2" PRIu32 ":%.2" PRIu32 ":%.2" PRIu32, h, m, s); - if (pcmk__is_set(flags, crm_time_usecs)) { + if (pcmk__is_set(flags, pcmk__time_fmt_usecs)) { g_string_append_printf(buf, ".%06" PRIu32, QB_ABS(usec)); } } @@ -2109,8 +2110,8 @@ pcmk__epoch2str(const time_t *source, uint32_t flags) * \brief Return a human-friendly string corresponding to seconds-and- * nanoseconds value * - * Time is shown with microsecond resolution if \p crm_time_usecs is in \p - * flags. + * Time is shown with microsecond resolution if \c pcmk__time_fmt_usecs is in + * \p flags. * * \param[in] ts Time in seconds and nanoseconds (or \p NULL for current * time) diff --git a/lib/fencing/st_output.c b/lib/fencing/st_output.c index 710e9357aae..1395e3e2008 100644 --- a/lib/fencing/st_output.c +++ b/lib/fencing/st_output.c @@ -52,7 +52,7 @@ timespec_string(time_t sec, long nsec, bool show_usec) { pcmk__time_fmt_date |pcmk__time_fmt_time |pcmk__time_fmt_timezone - |(show_usec? crm_time_usecs : 0)); + |(show_usec? pcmk__time_fmt_usecs : 0)); } /*! From fcd69e7cc2d01e081c9da9068feabf541fa4885c Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:02:23 -0700 Subject: [PATCH 28/40] API: libcrmcommon: Deprecate crm_time_usecs Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 2 -- include/crm/common/iso8601_compat.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 9a7192d0fb4..66aa47e93f0 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,8 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -#define crm_time_usecs 0x400 - int crm_time_compare(const crm_time_t *a, const crm_time_t *b); int crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 5c7b4471616..5065d58da5d 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -53,6 +53,9 @@ extern "C" { //! \deprecated Do not use #define crm_time_epoch 0x200 +//! \deprecated Do not use +#define crm_time_usecs 0x400 + //! \deprecated Do not use typedef struct crm_time_period_s { crm_time_t *start; From ec898730dbe90a1a14a88028d09c2f03a2709228 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:06:37 -0700 Subject: [PATCH 29/40] Refactor: libcrmcommon: New pcmk__time_compare() To replace crm_time_compare(). Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 2 ++ lib/common/iso8601.c | 10 +++++-- lib/common/rules.c | 8 +++--- .../tests/iso8601/crm_time_add_days_test.c | 4 +-- .../tests/iso8601/crm_time_add_seconds_test.c | 4 +-- .../tests/iso8601/crm_time_add_years_test.c | 4 +-- .../iso8601/pcmk__add_time_from_xml_test.c | 26 +++++++++---------- .../iso8601/pcmk__set_time_if_earlier_test.c | 8 +++--- .../nvpair/pcmk__unpack_nvpair_blocks_test.c | 2 +- .../rules/pcmk__evaluate_condition_test.c | 2 +- .../pcmk__evaluate_date_expression_test.c | 4 +-- .../tests/rules/pcmk__unpack_duration_test.c | 4 +-- .../xml_element/pcmk__xe_get_datetime_test.c | 2 +- tools/crm_resource_ban.c | 2 +- 14 files changed, 45 insertions(+), 37 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index a913f25e59b..ce554987045 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -65,6 +65,8 @@ const char *pcmk__readable_interval(unsigned int interval_ms); crm_time_t *pcmk__time_parse_duration(const char *period_s); crm_time_t *pcmk__copy_timet(time_t source_sec); +int pcmk__time_compare(const crm_time_t *a, const crm_time_t *b); + void pcmk__time_log_as(const char *file, const char *function, int line, uint8_t level, const char *prefix, const crm_time_t *dt, uint32_t flags); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index cf7c75a9698..62cd7b4348b 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1366,7 +1366,7 @@ pcmk__set_time_if_earlier(crm_time_t *target, const crm_time_t *source) if ((target == NULL) || (source == NULL) || (pcmk__time_is_initialized(target) - && (crm_time_compare(source, target) >= 0))) { + && (pcmk__time_compare(source, target) >= 0))) { return; } @@ -1650,7 +1650,7 @@ crm_time_subtract(const crm_time_t *dt, const crm_time_t *value) } int -crm_time_compare(const crm_time_t *a, const crm_time_t *b) +pcmk__time_compare(const crm_time_t *a, const crm_time_t *b) { int rc = 0; crm_time_t *t1 = NULL; @@ -1678,6 +1678,12 @@ crm_time_compare(const crm_time_t *a, const crm_time_t *b) return rc; } +int +crm_time_compare(const crm_time_t *a, const crm_time_t *b) +{ + return pcmk__time_compare(a, b); +} + /*! * \brief Add a given number of seconds to a date/time or duration * diff --git a/lib/common/rules.c b/lib/common/rules.c index b840245bc4c..09cd5c7bab6 100644 --- a/lib/common/rules.c +++ b/lib/common/rules.c @@ -332,7 +332,7 @@ evaluate_in_range(const xmlNode *date_expression, const char *id, } } - if ((start != NULL) && (crm_time_compare(now, start) < 0)) { + if ((start != NULL) && (pcmk__time_compare(now, start) < 0)) { pcmk__set_time_if_earlier(next_change, start); crm_time_free(start); crm_time_free(end); @@ -340,7 +340,7 @@ evaluate_in_range(const xmlNode *date_expression, const char *id, } if (end != NULL) { - if (crm_time_compare(now, end) > 0) { + if (pcmk__time_compare(now, end) > 0) { crm_time_free(start); crm_time_free(end); return pcmk_rc_after_range; @@ -392,7 +392,7 @@ evaluate_gt(const xmlNode *date_expression, const char *id, return pcmk_rc_unpack_error; } - if (crm_time_compare(now, start) > 0) { + if (pcmk__time_compare(now, start) > 0) { crm_time_free(start); return pcmk_rc_within_range; } @@ -437,7 +437,7 @@ evaluate_lt(const xmlNode *date_expression, const char *id, return pcmk_rc_unpack_error; } - if (crm_time_compare(now, end) < 0) { + if (pcmk__time_compare(now, end) < 0) { pcmk__set_time_if_earlier(next_change, end); crm_time_free(end); return pcmk_rc_within_range; diff --git a/lib/common/tests/iso8601/crm_time_add_days_test.c b/lib/common/tests/iso8601/crm_time_add_days_test.c index c9ad3616d78..b7995355b48 100644 --- a/lib/common/tests/iso8601/crm_time_add_days_test.c +++ b/lib/common/tests/iso8601/crm_time_add_days_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2024-2025 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -27,7 +27,7 @@ assert_add_days(const char *orig_date_time, int days, assert_non_null(expected); crm_time_add_days(orig, days); - assert_int_equal(crm_time_compare(orig, expected), 0); + assert_int_equal(pcmk__time_compare(orig, expected), 0); crm_time_free(orig); crm_time_free(expected); diff --git a/lib/common/tests/iso8601/crm_time_add_seconds_test.c b/lib/common/tests/iso8601/crm_time_add_seconds_test.c index 4315d7dcb5d..6cb957e689b 100644 --- a/lib/common/tests/iso8601/crm_time_add_seconds_test.c +++ b/lib/common/tests/iso8601/crm_time_add_seconds_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -27,7 +27,7 @@ assert_add_seconds(const char *orig_date_time, int seconds, assert_non_null(expected); crm_time_add_seconds(orig, seconds); - assert_int_equal(crm_time_compare(orig, expected), 0); + assert_int_equal(pcmk__time_compare(orig, expected), 0); crm_time_free(orig); crm_time_free(expected); diff --git a/lib/common/tests/iso8601/crm_time_add_years_test.c b/lib/common/tests/iso8601/crm_time_add_years_test.c index 8ea6b4d1c46..35831673cdb 100644 --- a/lib/common/tests/iso8601/crm_time_add_years_test.c +++ b/lib/common/tests/iso8601/crm_time_add_years_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2024-2025 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -27,7 +27,7 @@ assert_add_years(const char *orig_date_time, int years, assert_non_null(expected); crm_time_add_years(orig, years); - assert_int_equal(crm_time_compare(orig, expected), 0); + assert_int_equal(pcmk__time_compare(orig, expected), 0); crm_time_free(orig); crm_time_free(expected); diff --git a/lib/common/tests/iso8601/pcmk__add_time_from_xml_test.c b/lib/common/tests/iso8601/pcmk__add_time_from_xml_test.c index fa7f6ab183e..ebea2842ab6 100644 --- a/lib/common/tests/iso8601/pcmk__add_time_from_xml_test.c +++ b/lib/common/tests/iso8601/pcmk__add_time_from_xml_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -45,7 +45,7 @@ null_xml_ok(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_years, NULL), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); @@ -70,7 +70,7 @@ missing_attr(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_months, xml), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); @@ -86,7 +86,7 @@ invalid_attr(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_years, xml), pcmk_rc_unpack_error); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); @@ -102,12 +102,12 @@ out_of_range_attr(void **state) xml = pcmk__xml_parse(YEARS_TOO_BIG); assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_years, xml), ERANGE); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); pcmk__xml_free(xml); xml = pcmk__xml_parse(YEARS_TOO_SMALL); assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_years, xml), ERANGE); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); pcmk__xml_free(xml); crm_time_free(t); @@ -123,7 +123,7 @@ add_years(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_years, xml), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); @@ -139,7 +139,7 @@ add_months(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_months, xml), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); @@ -155,7 +155,7 @@ add_weeks(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_weeks, xml), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); @@ -171,7 +171,7 @@ add_days(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_days, xml), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); @@ -187,7 +187,7 @@ add_hours(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_hours, xml), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); @@ -203,7 +203,7 @@ add_minutes(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_minutes, xml), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); @@ -219,7 +219,7 @@ add_seconds(void **state) assert_int_equal(pcmk__add_time_from_xml(t, pcmk__time_seconds, xml), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); diff --git a/lib/common/tests/iso8601/pcmk__set_time_if_earlier_test.c b/lib/common/tests/iso8601/pcmk__set_time_if_earlier_test.c index 79821c3de2e..86d82cb8bab 100644 --- a/lib/common/tests/iso8601/pcmk__set_time_if_earlier_test.c +++ b/lib/common/tests/iso8601/pcmk__set_time_if_earlier_test.c @@ -26,7 +26,7 @@ null_ok(void **state) // Shouldn't assert, crash, or change target pcmk__set_time_if_earlier(target, NULL); - assert_int_equal(crm_time_compare(target, target_copy), 0); + assert_int_equal(pcmk__time_compare(target, target_copy), 0); crm_time_free(target); crm_time_free(target_copy); @@ -39,7 +39,7 @@ target_undefined(void **state) crm_time_t *target = pcmk__assert_alloc(1, sizeof(crm_time_t)); pcmk__set_time_if_earlier(target, source); - assert_int_equal(crm_time_compare(target, source), 0); + assert_int_equal(pcmk__time_compare(target, source), 0); crm_time_free(source); crm_time_free(target); @@ -52,7 +52,7 @@ source_earlier(void **state) crm_time_t *target = crm_time_new("2024-01-01 00:30:00 +01:00"); pcmk__set_time_if_earlier(target, source); - assert_int_equal(crm_time_compare(target, source), 0); + assert_int_equal(pcmk__time_compare(target, source), 0); crm_time_free(source); crm_time_free(target); @@ -66,7 +66,7 @@ source_later(void **state) crm_time_t *target_copy = pcmk_copy_time(target); pcmk__set_time_if_earlier(target, source); - assert_int_equal(crm_time_compare(target, target_copy), 0); + assert_int_equal(pcmk__time_compare(target, target_copy), 0); crm_time_free(source); crm_time_free(target); diff --git a/lib/common/tests/nvpair/pcmk__unpack_nvpair_blocks_test.c b/lib/common/tests/nvpair/pcmk__unpack_nvpair_blocks_test.c index 6bea483f134..c2e9e7a9e9a 100644 --- a/lib/common/tests/nvpair/pcmk__unpack_nvpair_blocks_test.c +++ b/lib/common/tests/nvpair/pcmk__unpack_nvpair_blocks_test.c @@ -144,7 +144,7 @@ rule_fails(void **state) assert_string_equal(g_hash_table_lookup(values, "name1"), "3"); assert_string_equal(g_hash_table_lookup(values, "name2"), "3"); assert_string_equal(g_hash_table_lookup(values, "name3"), "3"); - assert_int_equal(crm_time_compare(next_change, expected_next_change), 0); + assert_int_equal(pcmk__time_compare(next_change, expected_next_change), 0); pcmk__xml_free(xml); crm_time_free(now); diff --git a/lib/common/tests/rules/pcmk__evaluate_condition_test.c b/lib/common/tests/rules/pcmk__evaluate_condition_test.c index 7327ad01fc9..32d1ab23048 100644 --- a/lib/common/tests/rules/pcmk__evaluate_condition_test.c +++ b/lib/common/tests/rules/pcmk__evaluate_condition_test.c @@ -130,7 +130,7 @@ date_expression(void **state) rule_input.now = now; assert_int_equal(pcmk__evaluate_condition(xml, &rule_input, next_change), pcmk_rc_before_range); - assert_int_equal(crm_time_compare(next_change, reference), 0); + assert_int_equal(pcmk__time_compare(next_change, reference), 0); rule_input.now = NULL; crm_time_free(reference); diff --git a/lib/common/tests/rules/pcmk__evaluate_date_expression_test.c b/lib/common/tests/rules/pcmk__evaluate_date_expression_test.c index cfb6bdbf7f5..bed8fc3e998 100644 --- a/lib/common/tests/rules/pcmk__evaluate_date_expression_test.c +++ b/lib/common/tests/rules/pcmk__evaluate_date_expression_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2024-2025 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -52,7 +52,7 @@ assert_date_expression(const xmlNode *xml, const char *now_s, if (check_next_change) { crm_time_t *reference = crm_time_new(reference_s); - assert_int_equal(crm_time_compare(next_change, reference), 0); + assert_int_equal(pcmk__time_compare(next_change, reference), 0); crm_time_free(reference); crm_time_free(next_change); } diff --git a/lib/common/tests/rules/pcmk__unpack_duration_test.c b/lib/common/tests/rules/pcmk__unpack_duration_test.c index 2eba68e24e7..978dd8d1bab 100644 --- a/lib/common/tests/rules/pcmk__unpack_duration_test.c +++ b/lib/common/tests/rules/pcmk__unpack_duration_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2024 the Pacemaker project contributors + * Copyright 2024-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -99,7 +99,7 @@ all_valid(void **state) crm_time_t *reference = crm_time_new("2025-03-21 16:01:01"); assert_int_equal(pcmk__unpack_duration(duration, start, &end), pcmk_rc_ok); - assert_int_equal(crm_time_compare(end, reference), 0); + assert_int_equal(pcmk__time_compare(end, reference), 0); crm_time_free(start); crm_time_free(end); diff --git a/lib/common/tests/xml_element/pcmk__xe_get_datetime_test.c b/lib/common/tests/xml_element/pcmk__xe_get_datetime_test.c index c488d3f7243..34c4103abd9 100644 --- a/lib/common/tests/xml_element/pcmk__xe_get_datetime_test.c +++ b/lib/common/tests/xml_element/pcmk__xe_get_datetime_test.c @@ -79,7 +79,7 @@ attr_valid(void **state) crm_time_t *reference = crm_time_new(REFERENCE_ISO8601); assert_int_equal(pcmk__xe_get_datetime(xml, ATTR_PRESENT, &t), pcmk_rc_ok); - assert_int_equal(crm_time_compare(t, reference), 0); + assert_int_equal(pcmk__time_compare(t, reference), 0); crm_time_free(t); crm_time_free(reference); diff --git a/tools/crm_resource_ban.c b/tools/crm_resource_ban.c index f169660a85c..656cb17cf4e 100644 --- a/tools/crm_resource_ban.c +++ b/tools/crm_resource_ban.c @@ -496,7 +496,7 @@ cli_resource_clear_all_expired(xmlNode *root, cib_t *cib_conn, const char *rsc, continue; // Treat as unexpired } - if (crm_time_compare(now, end) == 1) { + if (pcmk__time_compare(now, end) > 0) { xmlNode *fragment = NULL; xmlNode *location = NULL; From c000874dce3673120eaeb421fc312691f5ea740b Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:07:17 -0700 Subject: [PATCH 30/40] API: libcrmcommon: Deprecate crm_time_compare() Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 2 -- include/crm/common/iso8601_compat.h | 3 +++ lib/common/iso8601.c | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 66aa47e93f0..daa4ea7a1fe 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,8 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -int crm_time_compare(const crm_time_t *a, const crm_time_t *b); - int crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, uint32_t *s); int crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 5065d58da5d..48050685f08 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -122,6 +122,9 @@ bool crm_time_is_defined(const crm_time_t *t); //! \deprecated Do not use char *crm_time_as_string(const crm_time_t *dt, int flags); +//! \deprecated Do not use +int crm_time_compare(const crm_time_t *a, const crm_time_t *b); + #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 62cd7b4348b..1414f957c60 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1678,12 +1678,6 @@ pcmk__time_compare(const crm_time_t *a, const crm_time_t *b) return rc; } -int -crm_time_compare(const crm_time_t *a, const crm_time_t *b) -{ - return pcmk__time_compare(a, b); -} - /*! * \brief Add a given number of seconds to a date/time or duration * @@ -2438,5 +2432,11 @@ crm_time_as_string(const crm_time_t *dt, int flags) return pcmk__time_text(dt, flags); } +int +crm_time_compare(const crm_time_t *a, const crm_time_t *b) +{ + return pcmk__time_compare(a, b); +} + // LCOV_EXCL_STOP // End deprecated API From d0b6ca9da4d77348135c75ccfc6e88384ca8ffcb Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 21:19:11 -0700 Subject: [PATCH 31/40] Refactor: libcrmcommon: Ignore crm_time_get_timeofday() return value It's always TRUE. Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 1414f957c60..4f471d2fa33 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1077,14 +1077,12 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) g_string_append_c(buf, ' '); } - if (crm_time_get_timeofday(dt, &h, &m, &s)) { - g_string_append_printf(buf, - "%.2" PRIu32 ":%.2" PRIu32 ":%.2" PRIu32, - h, m, s); + crm_time_get_timeofday(dt, &h, &m, &s); + g_string_append_printf(buf, "%.2" PRIu32 ":%.2" PRIu32 ":%.2" PRIu32, + h, m, s); - if (pcmk__is_set(flags, pcmk__time_fmt_usecs)) { - g_string_append_printf(buf, ".%06" PRIu32, QB_ABS(usec)); - } + if (pcmk__is_set(flags, pcmk__time_fmt_usecs)) { + g_string_append_printf(buf, ".%06" PRIu32, QB_ABS(usec)); } if (pcmk__is_set(flags, pcmk__time_fmt_timezone) && (dt->offset != 0)) { From 065d54c0a72e7cd6415902cd1d2dc0527108fd80 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:15:22 -0700 Subject: [PATCH 32/40] Refactor: libcrmcommon: New pcmk__time_get_timeofday() To replace crm_time_get_timeofday(). Signed-off-by: Reid Wahl --- lib/common/crmcommon_private.h | 4 ++++ lib/common/iso8601.c | 16 ++++++++++++---- lib/common/rules.c | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/common/crmcommon_private.h b/lib/common/crmcommon_private.h index a53ba60746e..d25b6a5bf1d 100644 --- a/lib/common/crmcommon_private.h +++ b/lib/common/crmcommon_private.h @@ -203,6 +203,10 @@ enum pcmk__time_component { pcmk__time_seconds, }; +G_GNUC_INTERNAL +void pcmk__time_get_timeofday(const crm_time_t *dt, uint32_t *hour, + uint32_t *minute, uint32_t *second); + G_GNUC_INTERNAL const char *pcmk__time_component_attr(enum pcmk__time_component component); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 4f471d2fa33..ee850ad1368 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -706,13 +706,21 @@ pcmk__time_log_as(const char *file, const char *function, int line, free(date_s); } +void +pcmk__time_get_timeofday(const crm_time_t *dt, uint32_t *hour, + uint32_t *minute, uint32_t *second) +{ + pcmk__assert((dt != NULL) && (hour != NULL) && (minute != NULL) + && (second != NULL)); + + seconds_to_hms(dt->seconds, hour, minute, second); +} + int crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, uint32_t *s) { - pcmk__assert((dt != NULL) && (h != NULL) && (m != NULL) && (s != NULL)); - - seconds_to_hms(dt->seconds, h, m, s); + pcmk__time_get_timeofday(dt, h, m, s); return TRUE; } @@ -1077,7 +1085,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) g_string_append_c(buf, ' '); } - crm_time_get_timeofday(dt, &h, &m, &s); + pcmk__time_get_timeofday(dt, &h, &m, &s); g_string_append_printf(buf, "%.2" PRIu32 ":%.2" PRIu32 ":%.2" PRIu32, h, m, s); diff --git a/lib/common/rules.c b/lib/common/rules.c index 09cd5c7bab6..51bf9fe27b1 100644 --- a/lib/common/rules.c +++ b/lib/common/rules.c @@ -188,8 +188,8 @@ pcmk__evaluate_date_spec(const xmlNode *date_spec, const crm_time_t *now) &(ranges[2].value)); // Hour, minute, second - crm_time_get_timeofday(now, &(ranges[3].value), &(ranges[4].value), - &(ranges[5].value)); + pcmk__time_get_timeofday(now, &(ranges[3].value), &(ranges[4].value), + &(ranges[5].value)); // Year (redundant) and day of year crm_time_get_ordinal(now, &(ranges[0].value), &(ranges[6].value)); From 6525503fa45b67697ec69bd5afb30866a067709f Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:09:33 -0700 Subject: [PATCH 33/40] API: libcrmcommon: Deprecate crm_time_get_timeofday() External callers have no need to inspect a crm_time_t object. Pacemaker should not be used for general-purpose date/time manipulation. Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 2 -- include/crm/common/iso8601_compat.h | 4 ++++ lib/common/iso8601.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index daa4ea7a1fe..102e90b38cf 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,8 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -int crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, - uint32_t *s); int crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, uint32_t *d); int crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d); diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 48050685f08..4ef54e01541 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -125,6 +125,10 @@ char *crm_time_as_string(const crm_time_t *dt, int flags); //! \deprecated Do not use int crm_time_compare(const crm_time_t *a, const crm_time_t *b); +//! \deprecated Do not use +int crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, + uint32_t *s); + #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index ee850ad1368..6363a6f6f70 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -716,14 +716,6 @@ pcmk__time_get_timeofday(const crm_time_t *dt, uint32_t *hour, seconds_to_hms(dt->seconds, hour, minute, second); } -int -crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, - uint32_t *s) -{ - pcmk__time_get_timeofday(dt, h, m, s); - return TRUE; -} - long long crm_time_get_seconds(const crm_time_t *dt) { @@ -2444,5 +2436,13 @@ crm_time_compare(const crm_time_t *a, const crm_time_t *b) return pcmk__time_compare(a, b); } +int +crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, + uint32_t *s) +{ + pcmk__time_get_timeofday(dt, h, m, s); + return TRUE; +} + // LCOV_EXCL_STOP // End deprecated API From 8fd90a7c80812d3ce570e6f6f252743bc5833719 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:13:36 -0700 Subject: [PATCH 34/40] Refactor: libcrmcommon: Ignore crm_time_get_gregorian() return value It always returns TRUE. Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 6363a6f6f70..d8e0b92f257 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1062,11 +1062,10 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) uint32_t m = 0; uint32_t d = 0; - if (crm_time_get_gregorian(dt, &y, &m, &d)) { - g_string_append_printf(buf, - "%.4" PRIu32 "-%.2" PRIu32 "-%.2" PRIu32, - y, m, d); - } + crm_time_get_gregorian(dt, &y, &m, &d); + g_string_append_printf(buf, + "%.4" PRIu32 "-%.2" PRIu32 "-%.2" PRIu32, + y, m, d); } } From d62dbe445e59fb56a7df4bd80d707f5f312eef0f Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:22:06 -0700 Subject: [PATCH 35/40] Refactor: libcrmcommon: New pcmk__time_get_ymd() To replace crm_time_get_gregorian(). Signed-off-by: Reid Wahl --- lib/common/crmcommon_private.h | 4 ++++ lib/common/iso8601.c | 28 +++++++++++++++++----------- lib/common/rules.c | 4 ++-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/common/crmcommon_private.h b/lib/common/crmcommon_private.h index d25b6a5bf1d..55734a30e15 100644 --- a/lib/common/crmcommon_private.h +++ b/lib/common/crmcommon_private.h @@ -207,6 +207,10 @@ G_GNUC_INTERNAL void pcmk__time_get_timeofday(const crm_time_t *dt, uint32_t *hour, uint32_t *minute, uint32_t *second); +G_GNUC_INTERNAL +void pcmk__time_get_ymd(const crm_time_t *dt, uint32_t *year, uint32_t *month, + uint32_t *day); + G_GNUC_INTERNAL const char *pcmk__time_component_attr(enum pcmk__time_component component); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index d8e0b92f257..34f15f52f5e 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -766,14 +766,15 @@ crm_time_get_seconds_since_epoch(const crm_time_t *dt) return (dt == NULL)? 0 : (crm_time_get_seconds(dt) - EPOCH_SECONDS); } -int -crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, - uint32_t *d) +void +pcmk__time_get_ymd(const crm_time_t *dt, uint32_t *year, uint32_t *month, + uint32_t *day) { int months = 0; int days = dt->days; - pcmk__assert((dt != NULL) && (y != NULL) && (m != NULL) && (d != NULL)); + pcmk__assert((dt != NULL) && (year != NULL) && (month != NULL) + && (day != NULL)); if(dt->years != 0) { for (months = 1; months <= 12 && days > 0; months++) { @@ -794,11 +795,16 @@ crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, /* This is a duration not including months, still don't convert the days field */ } - *y = dt->years; - *m = months; - *d = days; - pcmk__trace("%.4d-%.3d -> %.4d-%.2d-%.2d", dt->years, dt->days, dt->years, - months, days); + *year = dt->years; + *month = months; + *day = days; +} + +int +crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, + uint32_t *d) +{ + pcmk__time_get_ymd(dt, y, m, d); return TRUE; } @@ -1062,7 +1068,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) uint32_t m = 0; uint32_t d = 0; - crm_time_get_gregorian(dt, &y, &m, &d); + pcmk__time_get_ymd(dt, &y, &m, &d); g_string_append_printf(buf, "%.4" PRIu32 "-%.2" PRIu32 "-%.2" PRIu32, y, m, d); @@ -1752,7 +1758,7 @@ crm_time_add_months(crm_time_t *dt, int value) uint32_t day = 0; int days_in_month = 0; - crm_time_get_gregorian(dt, &year, &month, &day); + pcmk__time_get_ymd(dt, &year, &month, &day); if (value > 0) { for (int i = value; i > 0; i--) { diff --git a/lib/common/rules.c b/lib/common/rules.c index 51bf9fe27b1..27eaa6fe41e 100644 --- a/lib/common/rules.c +++ b/lib/common/rules.c @@ -184,8 +184,8 @@ pcmk__evaluate_date_spec(const xmlNode *date_spec, const crm_time_t *now) } // Year, month, day - crm_time_get_gregorian(now, &(ranges[0].value), &(ranges[1].value), - &(ranges[2].value)); + pcmk__time_get_ymd(now, &(ranges[0].value), &(ranges[1].value), + &(ranges[2].value)); // Hour, minute, second pcmk__time_get_timeofday(now, &(ranges[3].value), &(ranges[4].value), From 6be35453dad5fe62de551bf61a260a961771bc34 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:22:51 -0700 Subject: [PATCH 36/40] API: libcrmcommon: Deprecate crm_time_get_gregorian() External callers have no need to inspect a crm_time_t object. Pacemaker should not be used for general-purpose date/time manipulation. Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 2 -- include/crm/common/iso8601_compat.h | 4 ++++ lib/common/iso8601.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 102e90b38cf..814c2942140 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,8 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -int crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, - uint32_t *d); int crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d); /* Time in seconds since 0000-01-01 00:00:00Z */ diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 4ef54e01541..0ebed008dc4 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -129,6 +129,10 @@ int crm_time_compare(const crm_time_t *a, const crm_time_t *b); int crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, uint32_t *s); +//! \deprecated Do not use +int crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, + uint32_t *d); + #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 34f15f52f5e..9d8e8d074df 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -800,14 +800,6 @@ pcmk__time_get_ymd(const crm_time_t *dt, uint32_t *year, uint32_t *month, *day = days; } -int -crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, - uint32_t *d) -{ - pcmk__time_get_ymd(dt, y, m, d); - return TRUE; -} - int crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d) { @@ -2449,5 +2441,13 @@ crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, return TRUE; } +int +crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, + uint32_t *d) +{ + pcmk__time_get_ymd(dt, y, m, d); + return TRUE; +} + // LCOV_EXCL_STOP // End deprecated API From 4a92af532e5b476ea9fcb5318e5f7a6b96c837c7 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:29:18 -0700 Subject: [PATCH 37/40] Refactor: libcrmcommon: Drop crm_time_get_ordinal() internally Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 7 +------ lib/common/rules.c | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 9d8e8d074df..73d437328e4 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1048,12 +1048,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) } } else if (pcmk__is_set(flags, pcmk__time_fmt_ordinal)) { // YYYY-DDD - uint32_t y = 0; - uint32_t d = 0; - - if (crm_time_get_ordinal(dt, &y, &d)) { - g_string_append_printf(buf, "%" PRIu32 "-%.3" PRIu32, y, d); - } + g_string_append_printf(buf, "%d-%.3d", dt->years, dt->days); } else { // YYYY-MM-DD uint32_t y = 0; diff --git a/lib/common/rules.c b/lib/common/rules.c index 27eaa6fe41e..847a11b60ce 100644 --- a/lib/common/rules.c +++ b/lib/common/rules.c @@ -191,8 +191,8 @@ pcmk__evaluate_date_spec(const xmlNode *date_spec, const crm_time_t *now) pcmk__time_get_timeofday(now, &(ranges[3].value), &(ranges[4].value), &(ranges[5].value)); - // Year (redundant) and day of year - crm_time_get_ordinal(now, &(ranges[0].value), &(ranges[6].value)); + // Day of year + ranges[6].value = now->days; // Week year, week of week year, day of week pcmk__time_get_ywd(now, &(ranges[7].value), &(ranges[8].value), From 6ae822bf364c9e111c867ae4a47c641c93403828 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:30:20 -0700 Subject: [PATCH 38/40] API: libcrmcommon: Deprecate crm_time_get_ordinal() External callers have no need to inspect a crm_time_t object. Pacemaker should not be used for general-purpose date/time manipulation. Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 2 -- include/crm/common/iso8601_compat.h | 3 +++ lib/common/iso8601.c | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 814c2942140..01c8a5b1418 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,8 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -int crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d); - /* Time in seconds since 0000-01-01 00:00:00Z */ long long crm_time_get_seconds(const crm_time_t *dt); diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index 0ebed008dc4..c4c62a51d04 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -133,6 +133,9 @@ int crm_time_get_timeofday(const crm_time_t *dt, uint32_t *h, uint32_t *m, int crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, uint32_t *d); +//! \deprecated Do not use +int crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d); + #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 73d437328e4..7a0fdc8dd19 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -800,16 +800,6 @@ pcmk__time_get_ymd(const crm_time_t *dt, uint32_t *year, uint32_t *month, *day = days; } -int -crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d) -{ - pcmk__assert((dt != NULL) && (y != NULL) && (d != NULL)); - - *y = dt->years; - *d = dt->days; - return TRUE; -} - void pcmk__time_get_ywd(const crm_time_t *dt, uint32_t *y, uint32_t *w, uint32_t *d) { @@ -2444,5 +2434,15 @@ crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, return TRUE; } +int +crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d) +{ + pcmk__assert((dt != NULL) && (y != NULL) && (d != NULL)); + + *y = dt->years; + *d = dt->days; + return TRUE; +} + // LCOV_EXCL_STOP // End deprecated API From 30df7dc1f9b7a2e7798bc2a56347788322931a71 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:34:48 -0700 Subject: [PATCH 39/40] Refactor: libcrmcommon: New pcmk__time_get_seconds() To replace crm_time_get_seconds(). Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 1 + lib/common/iso8601.c | 15 +++++++++++---- lib/common/strings.c | 2 +- lib/pengine/pe_actions.c | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index ce554987045..0e05ea9b4fb 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -54,6 +54,7 @@ enum pcmk__time_fmt_flags { bool pcmk__time_valid_year(int year); bool pcmk__time_is_initialized(const crm_time_t *dt); +long long pcmk__time_get_seconds(const crm_time_t *dt); void pcmk__time_get_ywd(const crm_time_t *dt, uint32_t *y, uint32_t *w, uint32_t *d); char *pcmk__time_text(const crm_time_t *dt, int flags); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 7a0fdc8dd19..ef9f7da04d1 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -716,8 +716,9 @@ pcmk__time_get_timeofday(const crm_time_t *dt, uint32_t *hour, seconds_to_hms(dt->seconds, hour, minute, second); } +// Time in seconds since 0000-01-01 00:00:00Z long long -crm_time_get_seconds(const crm_time_t *dt) +pcmk__time_get_seconds(const crm_time_t *dt) { crm_time_t *utc = NULL; long long days = 0; @@ -759,11 +760,17 @@ crm_time_get_seconds(const crm_time_t *dt) return seconds; } -#define EPOCH_SECONDS 62135596800ULL /* Calculated using crm_time_get_seconds() */ +long long +crm_time_get_seconds(const crm_time_t *dt) +{ + return pcmk__time_get_seconds(dt); +} + +#define EPOCH_SECONDS 62135596800ULL // Calculated using pcmk__time_get_seconds long long crm_time_get_seconds_since_epoch(const crm_time_t *dt) { - return (dt == NULL)? 0 : (crm_time_get_seconds(dt) - EPOCH_SECONDS); + return (dt == NULL)? 0 : (pcmk__time_get_seconds(dt) - EPOCH_SECONDS); } void @@ -1003,7 +1010,7 @@ time_as_string_common(const crm_time_t *dt, int usec, uint32_t flags) long long seconds = 0; if (pcmk__is_set(flags, pcmk__time_fmt_seconds)) { - seconds = crm_time_get_seconds(dt); + seconds = pcmk__time_get_seconds(dt); } else { seconds = crm_time_get_seconds_since_epoch(dt); } diff --git a/lib/common/strings.c b/lib/common/strings.c index 6e71fa6ca6b..0a6feff7b19 100644 --- a/lib/common/strings.c +++ b/lib/common/strings.c @@ -375,7 +375,7 @@ pcmk_parse_interval_spec(const char *input, unsigned int *result_ms) crm_time_t *period_s = pcmk__time_parse_duration(input); if (period_s != NULL) { - msec = crm_time_get_seconds(period_s); + msec = pcmk__time_get_seconds(period_s); msec = QB_MIN(msec, UINT_MAX / 1000) * 1000; crm_time_free(period_s); } diff --git a/lib/pengine/pe_actions.c b/lib/pengine/pe_actions.c index 2e8d3237c62..bd9b52dc5b3 100644 --- a/lib/pengine/pe_actions.c +++ b/lib/pengine/pe_actions.c @@ -593,7 +593,7 @@ unpack_interval_origin(const char *value, const xmlNode *xml_obj, } // Get seconds since origin (negative if origin is in the future) - result = crm_time_get_seconds(now) - crm_time_get_seconds(origin); + result = pcmk__time_get_seconds(now) - pcmk__time_get_seconds(origin); crm_time_free(origin); // Calculate seconds from closest interval to now From 9629516d280d0166fadaca4e5083364d1904d8c7 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:36:11 -0700 Subject: [PATCH 40/40] API: libcrmcommon: Deprecate crm_time_get_seconds() External callers have no need to inspect a crm_time_t object. Pacemaker should not be used for general-purpose date/time manipulation. Signed-off-by: Reid Wahl --- include/crm/common/iso8601.h | 3 --- include/crm/common/iso8601_compat.h | 3 +++ lib/common/iso8601.c | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/crm/common/iso8601.h b/include/crm/common/iso8601.h index 01c8a5b1418..2d2b4566602 100644 --- a/include/crm/common/iso8601.h +++ b/include/crm/common/iso8601.h @@ -54,9 +54,6 @@ typedef struct crm_time_s crm_time_t; crm_time_t *crm_time_new(const char *string); void crm_time_free(crm_time_t * dt); -/* Time in seconds since 0000-01-01 00:00:00Z */ -long long crm_time_get_seconds(const crm_time_t *dt); - /* Time in seconds since 1970-01-01 00:00:00Z */ long long crm_time_get_seconds_since_epoch(const crm_time_t *dt); diff --git a/include/crm/common/iso8601_compat.h b/include/crm/common/iso8601_compat.h index c4c62a51d04..3c08c6b3388 100644 --- a/include/crm/common/iso8601_compat.h +++ b/include/crm/common/iso8601_compat.h @@ -136,6 +136,9 @@ int crm_time_get_gregorian(const crm_time_t *dt, uint32_t *y, uint32_t *m, //! \deprecated Do not use int crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d); +//! \deprecated Do not use +long long crm_time_get_seconds(const crm_time_t *dt); + #ifdef __cplusplus } #endif diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index ef9f7da04d1..363f2e7f503 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -760,12 +760,6 @@ pcmk__time_get_seconds(const crm_time_t *dt) return seconds; } -long long -crm_time_get_seconds(const crm_time_t *dt) -{ - return pcmk__time_get_seconds(dt); -} - #define EPOCH_SECONDS 62135596800ULL // Calculated using pcmk__time_get_seconds long long crm_time_get_seconds_since_epoch(const crm_time_t *dt) @@ -2451,5 +2445,11 @@ crm_time_get_ordinal(const crm_time_t *dt, uint32_t *y, uint32_t *d) return TRUE; } +long long +crm_time_get_seconds(const crm_time_t *dt) +{ + return pcmk__time_get_seconds(dt); +} + // LCOV_EXCL_STOP // End deprecated API