From 63c955c597cb35f66f497cf25ec1494138e3727d Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 10:31:29 -0700 Subject: [PATCH 01/48] 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/48] 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/48] 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/48] 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/48] 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/48] 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 d43b9cfd9aea33964aae23aa1ddec48fb132b919 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:15:09 -0700 Subject: [PATCH 07/48] 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..076ac72f576 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 96e1c619d2ab784c72562d3a0dc087bc34536e65 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:17:00 -0700 Subject: [PATCH 08/48] 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 076ac72f576..dda7eec8b79 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 5d45bef487dac6afff6af27471099eca52c9ea8e Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:27:20 -0700 Subject: [PATCH 09/48] 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 dda7eec8b79..01e33921240 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 69d2d314a0f735a721c0d6f13b1434218da9a1e8 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:28:04 -0700 Subject: [PATCH 10/48] 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 01e33921240..ba4b04ef3ae 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 e900c1154d2b3b18d014a95f3efdb929c548d7a1 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:33:41 -0700 Subject: [PATCH 11/48] 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 | 12 ++++++++++++ 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, 39 insertions(+), 22 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 33b4f0b55cc..b239cd0bd1f 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -26,6 +26,18 @@ extern "C" { #endif +/* @COMPAT These must be kept in line with the deprecated crm_time_* flags until + * those are removed + */ +/*! + * \internal + * \brief Flags for formatting a \c crm_time_t object as a string + */ +enum pcmk__time_fmt_flags { + //! Include date (as YYYY-WW-D, YYYY-DDD, or YYYY-MM-DD (default)) + 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 ba4b04ef3ae..6d6e971a404 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 0f69e6679c51826474477b7703015592a9f9b33b Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:37:29 -0700 Subject: [PATCH 12/48] 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 93c12ec5d5fd6db3bae6ae415270a28c592cadbc Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:43:47 -0700 Subject: [PATCH 13/48] Refactor: libcrmcommon: New pcmk__time_fmt_time To replace crm_time_log_timeofday. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 3 +++ 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, 24 insertions(+), 26 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index b239cd0bd1f..d30d9d370f6 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -36,6 +36,9 @@ extern "C" { enum pcmk__time_fmt_flags { //! Include date (as YYYY-WW-D, YYYY-DDD, or YYYY-MM-DD (default)) pcmk__time_fmt_date = (UINT32_C(1) << 0), + + //! Include time (as HH:MM:SS[.UUUUUU]('Z'| ('+'|'-')HH:MM)) + 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 6d6e971a404..63984a3792e 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 37dbf74e9e6abc92d3576cdcd817563c55f140df Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:44:38 -0700 Subject: [PATCH 14/48] 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 0906f95f2e9c867ee6137a9286d0185836a7be12 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:47:01 -0700 Subject: [PATCH 15/48] 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 | 11 +++++++++++ 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, 25 insertions(+), 16 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index d30d9d370f6..441c2588b3b 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -39,6 +39,17 @@ enum pcmk__time_fmt_flags { //! Include time (as HH:MM:SS[.UUUUUU]('Z'| ('+'|'-')HH:MM)) pcmk__time_fmt_time = (UINT32_C(1) << 1), + + /*! + * If \c pcmk__time_fmt_time is set: + * * If this flag is set and \c offset is not 0, include time zone as offset + * from UTC ( ('+'|'-')HH:MM). + * * Otherwise, include 'Z'. + * + * If \c pcmk__time_fmt_time is not set, this flag is ignored and neither + * the time zone nor 'Z' is included. + */ + 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 63984a3792e..0ac93ac398e 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 ece7691a54b78c9a4b5830b4cd15192927a90c77 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:47:29 -0700 Subject: [PATCH 16/48] 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 2ff3630e7cae4565b4751a5bec0ec52f4b8054b6 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 6 Jul 2026 23:24:24 -0700 Subject: [PATCH 17/48] Refactor: libcrmcommon: Some best practices in duration_as_string() Improve variable names and compare explicitly against zero where appropriate. Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 54 ++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 0ac93ac398e..79dbb42062a 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -899,23 +899,28 @@ sec_usec_as_string(long long sec, int usec, GString *buf) * \param[in] usec Microseconds to add to \p dt * \param[in] show_usec Whether to include microseconds in \p buf * \param[in,out] buf Result buffer + * + * \note This looks like it would produce incorrect output when \p dt has one or + * more negative fields. As a duration, however, it generally should not. */ static void duration_as_string(const crm_time_t *dt, int usec, bool show_usec, GString *buf) { pcmk__assert(valid_sec_usec(dt->seconds, usec)); - if (dt->years) { - g_string_append_printf(buf, "%4d year%s ", - dt->years, pcmk__plural_s(dt->years)); + if (dt->years != 0) { + g_string_append_printf(buf, "%4d year%s ", dt->years, + pcmk__plural_s(dt->years)); } - if (dt->months) { - g_string_append_printf(buf, "%2d month%s ", - dt->months, pcmk__plural_s(dt->months)); + + if (dt->months != 0) { + g_string_append_printf(buf, "%2d month%s ", dt->months, + pcmk__plural_s(dt->months)); } - if (dt->days) { - g_string_append_printf(buf, "%2d day%s ", - dt->days, pcmk__plural_s(dt->days)); + + if (dt->days != 0) { + g_string_append_printf(buf, "%2d day%s ", dt->days, + pcmk__plural_s(dt->days)); } // At least print seconds (and optionally usecs) @@ -925,34 +930,34 @@ duration_as_string(const crm_time_t *dt, int usec, bool show_usec, GString *buf) } else { g_string_append_printf(buf, "%d", dt->seconds); } + g_string_append_printf(buf, " second%s", pcmk__plural_s(dt->seconds)); } // More than one minute, so provide a more readable breakdown into units if (QB_ABS(dt->seconds) >= SECONDS_IN_MINUTE) { - uint32_t h = 0; - uint32_t m = 0; - uint32_t s = 0; - uint32_t u = QB_ABS(usec); + uint32_t hours = 0; + uint32_t minutes = 0; + uint32_t seconds = 0; bool print_sec_component = false; - seconds_to_hms(dt->seconds, &h, &m, &s); - print_sec_component = ((s != 0) || (show_usec && (u != 0))); + seconds_to_hms(dt->seconds, &hours, &minutes, &seconds); + print_sec_component = ((seconds != 0) || (show_usec && (usec != 0))); g_string_append(buf, " ("); - if (h) { - g_string_append_printf(buf, "%" PRIu32 " hour%s", - h, pcmk__plural_s(h)); + if (hours != 0) { + g_string_append_printf(buf, "%" PRIu32 " hour%s", hours, + pcmk__plural_s(hours)); - if ((m != 0) || print_sec_component) { + if ((minutes != 0) || print_sec_component) { g_string_append_c(buf, ' '); } } - if (m) { - g_string_append_printf(buf, "%" PRIu32 " minute%s", - m, pcmk__plural_s(m)); + if (minutes != 0) { + g_string_append_printf(buf, "%" PRIu32 " minute%s", minutes, + pcmk__plural_s(minutes)); if (print_sec_component) { g_string_append_c(buf, ' '); @@ -961,10 +966,11 @@ duration_as_string(const crm_time_t *dt, int usec, bool show_usec, GString *buf) if (print_sec_component) { if (show_usec) { - sec_usec_as_string(s, u, buf); + sec_usec_as_string(seconds, QB_ABS(usec), buf); } else { - g_string_append_printf(buf, "%" PRIu32, s); + g_string_append_printf(buf, "%" PRIu32, seconds); } + g_string_append_printf(buf, " second%s", pcmk__plural_s(dt->seconds)); } From 0f6ccd4df9c8d649019cf0005f9c3521615b6a5f Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 6 Jul 2026 23:25:25 -0700 Subject: [PATCH 18/48] Refactor: libcrmcommon: Drop QB_ABS() call in duration_as_string() This slightly changes behavior if seconds is zero and usec is negative (see sec_usec_as_string()). But as mentioned in the note within duration_as_string()'s Doxygen, the duration formatting is already incorrect when any fields are negative. sec_usec_as_string() calls QB_ABS(usec), so having this extra call was a bit confusing. Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 79dbb42062a..faf5fc874e4 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -966,7 +966,7 @@ duration_as_string(const crm_time_t *dt, int usec, bool show_usec, GString *buf) if (print_sec_component) { if (show_usec) { - sec_usec_as_string(seconds, QB_ABS(usec), buf); + sec_usec_as_string(seconds, usec, buf); } else { g_string_append_printf(buf, "%" PRIu32, seconds); } From b945641fa694efa7c2044aa0e9a852273312d304 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:49:53 -0700 Subject: [PATCH 19/48] Refactor: libcrmcommon: New pcmk__time_fmt_duration To replace crm_time_log_duration. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 28 +++++++++++++++++++++++++++ lib/common/iso8601.c | 2 +- tools/iso8601.c | 4 ++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 441c2588b3b..c0040bf4b74 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -50,6 +50,34 @@ enum pcmk__time_fmt_flags { * the time zone nor 'Z' is included. */ pcmk__time_fmt_timezone = (UINT32_C(1) << 2), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + /*! + * Format the \c crm_time_t object as a duration. The output contains the + * following fields: + * * YYYY year(s) + * * MM month(s) + * * DD day(s) + * * SECONDS[.UUUUUU] second(s) + * * If SECONDS >= 60, then the following fields in parentheses: + * * HOURS hour(s) + * * MINUTES minute(s) + * * SECONDS[.UUUUUU] second(s) + * + * \note This flag causes all other flags except \c crm_time_usecs to be + * ignored. + * \note Negative fields may be formatted incorrectly or confusingly. A + * duration should not really have negative fields, but they are + * allowed. + * \note The fields are separated by spaces. + * \note Years, months, and days are space-padded on the left. + * \note Fields with zero values are omitted, with the following exceptions: + * * If there are no nonzero date fields, the seconds field is + * formatted with a value of zero (plus usecs if requested). + * * Usecs are included if and only if the \c crm_time_usecs flag is + * set and either seconds will be formatted or usecs is nonzero. + */ + 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 faf5fc874e4..e142e89dd8e 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1010,7 +1010,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 2ca4d62745f97ea98deb48e71d9538e41f80922c Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:50:22 -0700 Subject: [PATCH 20/48] 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 6a5274e938962cda88bff26cb55bda4be42af29c Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:51:40 -0700 Subject: [PATCH 21/48] Refactor: libcrmcommon: New pcmk__time_fmt_ordinal To replace crm_time_ordinal. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 7 +++++++ lib/common/iso8601.c | 2 +- tools/iso8601.c | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index c0040bf4b74..9b8cc9c02dc 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -78,6 +78,13 @@ enum pcmk__time_fmt_flags { * set and either seconds will be formatted or usecs is nonzero. */ pcmk__time_fmt_duration = (UINT32_C(1) << 3), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + /*! + * If \c pcmk__time_fmt_date is set and \c crm_time_weeks is not set, format + * date as YYYY-DDD + */ + 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 e142e89dd8e..1dd62557148 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1053,7 +1053,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 1dd0851ce17d93cc466ddd4247f2a0d27232c261 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:52:11 -0700 Subject: [PATCH 22/48] 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 4616d858a5ac765577c423d7a436b7702c198d62 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:54:04 -0700 Subject: [PATCH 23/48] Refactor: libcrmcommon: New pcmk__time_fmt_weeks To replace crm_time_weeks. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 8 ++++++-- lib/common/iso8601.c | 2 +- tools/iso8601.c | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 9b8cc9c02dc..41c00633229 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -81,10 +81,14 @@ enum pcmk__time_fmt_flags { // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) /*! - * If \c pcmk__time_fmt_date is set and \c crm_time_weeks is not set, format - * date as YYYY-DDD + * If \c pcmk__time_fmt_date is set and \c pcmk__time_fmt_weeks is not set, + * format date as YYYY-DDD */ pcmk__time_fmt_ordinal = (UINT32_C(1) << 4), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + //! If \c pcmk__time_fmt_date is set, format date as YYYY-WW-D + 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 1dd62557148..796bf963c5c 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1041,7 +1041,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 63efc87714bc204cb51461cced8826f4a84d7ab2 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:54:26 -0700 Subject: [PATCH 24/48] 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 5b458ab497455586bfeaee441a6a3e4b1ddd13bc Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:56:33 -0700 Subject: [PATCH 25/48] Refactor: libcrmcommon: New pcmk__time_fmt_seconds To replace crm_time_seconds. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 14 ++++++++++++++ lib/common/iso8601.c | 4 ++-- tools/iso8601.c | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 41c00633229..f77be6148ce 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -89,6 +89,20 @@ enum pcmk__time_fmt_flags { // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) //! If \c pcmk__time_fmt_date is set, format date as YYYY-WW-D pcmk__time_fmt_weeks = (UINT32_C(1) << 5), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + /*! + * Format the \c crm_time_t object as the number of seconds since + * 0001-01-01T00:00:00. The output is in the format SECONDS[.UUUUUU], where + * usecs are included if and only if \c crm_time_usecs is set. + * + * \note This flag causes all other flags except \c pcmk__time_fmt_duration + * and \c crm_time_usecs to be ignored. + * \note If the \c crm_time_t object is a duration, then all years are + * treated as having 365 days and all months are treated as having 30 + * days, for the purpose of computing the number of seconds. + */ + 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 796bf963c5c..c7c209c1d8e 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1015,10 +1015,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 c43548db9948118cbd285ac90b6b706ccd279385 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:57:07 -0700 Subject: [PATCH 26/48] 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 58c4c611e8e77b2326ac1b7a60eebc08a30b6c89 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:58:17 -0700 Subject: [PATCH 27/48] Refactor: libcrmcommon: New pcmk__time_fmt_epoch To replace crm_time_epoch. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 15 +++++++++++++++ lib/common/iso8601.c | 3 ++- tools/iso8601.c | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index f77be6148ce..5e0fc5faeda 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -103,6 +103,21 @@ enum pcmk__time_fmt_flags { * days, for the purpose of computing the number of seconds. */ pcmk__time_fmt_seconds = (UINT32_C(1) << 8), + + // @COMPAT Nothing sets this internally except tools/iso8601.c (deprecated) + /*! + * Format the \c crm_time_t object as the number of seconds since + * 1970-01-01T00:00:00 (the Unix epoch). The output is in the format + * SECONDS[.UUUUUU], where usecs are included if and only if + * \c crm_time_usecs is set. + * + * \note This flag causes all other flags except \c pcmk__time_fmt_duration, + * \c pcmk__time_fmt_seconds, and \c crm_time_usecs to be ignored. + * \note If the \c crm_time_t object is a duration, then all years are + * treated as having 365 days and all months are treated as having 30 + * days, for the purpose of computing the number of seconds. + */ + 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 c7c209c1d8e..6acf35dc2a6 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1015,7 +1015,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 f9603173d5280519440bd6cd3762eaa25b87caa5 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 18:58:40 -0700 Subject: [PATCH 28/48] 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 59a68716e43099bd7141352f416a58bad4fc25d6 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:01:59 -0700 Subject: [PATCH 29/48] Refactor: libcrmcommon: New pcmk__time_fmt_usecs To replace crm_time_usecs. Signed-off-by: Reid Wahl --- include/crm/common/iso8601_internal.h | 24 ++++++++++++++++-------- lib/common/iso8601.c | 11 ++++++----- lib/fencing/st_output.c | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/include/crm/common/iso8601_internal.h b/include/crm/common/iso8601_internal.h index 5e0fc5faeda..0f8ef238d50 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -64,8 +64,8 @@ enum pcmk__time_fmt_flags { * * MINUTES minute(s) * * SECONDS[.UUUUUU] second(s) * - * \note This flag causes all other flags except \c crm_time_usecs to be - * ignored. + * \note This flag causes all other flags except \c pcmk__time_fmt_usecs to + * be ignored. * \note Negative fields may be formatted incorrectly or confusingly. A * duration should not really have negative fields, but they are * allowed. @@ -74,8 +74,9 @@ enum pcmk__time_fmt_flags { * \note Fields with zero values are omitted, with the following exceptions: * * If there are no nonzero date fields, the seconds field is * formatted with a value of zero (plus usecs if requested). - * * Usecs are included if and only if the \c crm_time_usecs flag is - * set and either seconds will be formatted or usecs is nonzero. + * * Usecs are included if and only if the \c pcmk__time_fmt_usecs + * flag is set and either seconds will be formatted or usecs is + * nonzero. */ pcmk__time_fmt_duration = (UINT32_C(1) << 3), @@ -94,10 +95,10 @@ enum pcmk__time_fmt_flags { /*! * Format the \c crm_time_t object as the number of seconds since * 0001-01-01T00:00:00. The output is in the format SECONDS[.UUUUUU], where - * usecs are included if and only if \c crm_time_usecs is set. + * usecs are included if and only if \c pcmk__time_fmt_usecs is set. * * \note This flag causes all other flags except \c pcmk__time_fmt_duration - * and \c crm_time_usecs to be ignored. + * and \c pcmk__time_fmt_usecs to be ignored. * \note If the \c crm_time_t object is a duration, then all years are * treated as having 365 days and all months are treated as having 30 * days, for the purpose of computing the number of seconds. @@ -109,15 +110,22 @@ enum pcmk__time_fmt_flags { * Format the \c crm_time_t object as the number of seconds since * 1970-01-01T00:00:00 (the Unix epoch). The output is in the format * SECONDS[.UUUUUU], where usecs are included if and only if - * \c crm_time_usecs is set. + * \c pcmk__time_fmt_usecs is set. * * \note This flag causes all other flags except \c pcmk__time_fmt_duration, - * \c pcmk__time_fmt_seconds, and \c crm_time_usecs to be ignored. + * \c pcmk__time_fmt_seconds, and \c pcmk__time_fmt_usecs to be + * ignored. * \note If the \c crm_time_t object is a duration, then all years are * treated as having 365 days and all months are treated as having 30 * days, for the purpose of computing the number of seconds. */ pcmk__time_fmt_epoch = (UINT32_C(1) << 9), + + /*! + * Format seconds as a floating-point value at microsecond resolution. If + * not set, seconds are truncated to an integer. + */ + 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 6acf35dc2a6..1a6453db364 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1011,7 +1011,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; } @@ -1025,7 +1026,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); @@ -1087,7 +1088,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)); } } @@ -2115,8 +2116,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 39853d9005f3d586d63b444aef98ef7f91727825 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:02:23 -0700 Subject: [PATCH 30/48] 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 cefe639e1bbcd03bd7077dd586538148217f7e50 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:06:37 -0700 Subject: [PATCH 31/48] 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 0f8ef238d50..4db48c8bb79 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -141,6 +141,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 1a6453db364..b1323d15648 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1372,7 +1372,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; } @@ -1656,7 +1656,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; @@ -1684,6 +1684,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 b9a802aae54ffb9676aeffdd4ff25283959b6400 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:07:17 -0700 Subject: [PATCH 32/48] 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 b1323d15648..3cbbea60aaa 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1684,12 +1684,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 * @@ -2444,5 +2438,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 c1c71164c0aeb2b20ed5dfd6daaba3830f4cb907 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 21:19:11 -0700 Subject: [PATCH 33/48] 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 3cbbea60aaa..dfe92b5c2ad 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1083,14 +1083,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 98eb7236672f21addff623cc587b2fb4a892bda2 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 19:15:22 -0700 Subject: [PATCH 34/48] 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 dfe92b5c2ad..ae7ce463b06 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; } @@ -1083,7 +1091,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 34695076b8efdec7e360cf03f58ed732e562d88f Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:09:33 -0700 Subject: [PATCH 35/48] 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 ae7ce463b06..85d2c366379 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) { @@ -2450,5 +2442,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 503395dca841073dc5e70ef3a8a5fb26a11d6513 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:13:36 -0700 Subject: [PATCH 36/48] 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 85d2c366379..d0a057adf76 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1068,11 +1068,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 97e3ce2e895a51ef7d5604bb5734b909e3b263a6 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:22:06 -0700 Subject: [PATCH 37/48] 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 d0a057adf76..b35384cdf5e 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; } @@ -1068,7 +1074,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); @@ -1758,7 +1764,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 831460141d40c746dcb5e742160289b46d7a2fee Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:22:51 -0700 Subject: [PATCH 38/48] 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 b35384cdf5e..e76db1c84f2 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) { @@ -2455,5 +2447,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 ea5eb1b35a2b65d565d25294bebbc8969c384313 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:29:18 -0700 Subject: [PATCH 39/48] 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 e76db1c84f2..1e34136ccee 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1054,12 +1054,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 3780939eba9f63777197c156fe9110b0234b64cb Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:30:20 -0700 Subject: [PATCH 40/48] 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 1e34136ccee..db72be2140a 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) { @@ -2450,5 +2440,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 dca830eadd8b2f41d4f749ec03113757cc533b06 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:34:48 -0700 Subject: [PATCH 41/48] 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 4db48c8bb79..d4e435d824e 100644 --- a/include/crm/common/iso8601_internal.h +++ b/include/crm/common/iso8601_internal.h @@ -130,6 +130,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 db72be2140a..45c15520999 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 @@ -1009,7 +1016,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 5aa9080cc4f0d3923b7d7827df57315cfa24fb75 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Thu, 30 Apr 2026 22:36:11 -0700 Subject: [PATCH 42/48] 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 45c15520999..6d2cd338f07 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) @@ -2457,5 +2451,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 From 717d36069b0a4b5f0fe915a3758b002926035556 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Mon, 6 Jul 2026 13:10:10 -0700 Subject: [PATCH 43/48] Refactor: various: Drop unneeded parens for address-of operator We used these in order to be explicit about operator precedence for clarity. However, I now believe these particular parentheses add more clutter than clarity. Signed-off-by: Reid Wahl --- daemons/attrd/attrd_cib.c | 2 +- daemons/controld/controld_control.c | 4 +-- daemons/controld/controld_execd.c | 10 +++--- daemons/controld/controld_remote_ra.c | 34 ++++++++++---------- daemons/controld/controld_timers.c | 10 +++--- daemons/controld/controld_utils.c | 6 ++-- daemons/controld/pacemaker-controld.c | 2 +- daemons/execd/execd_alerts.c | 2 +- daemons/execd/execd_commands.c | 46 +++++++++++++-------------- daemons/fenced/fenced_commands.c | 10 +++--- daemons/fenced/fenced_remote.c | 12 +++---- daemons/pacemakerd/pcmkd_subdaemons.c | 4 +-- lib/cib/cib_client.c | 2 +- lib/cib/cib_ops.c | 2 +- lib/cib/cib_remote.c | 10 +++--- lib/cluster/cpg.c | 24 +++++++------- lib/cluster/election.c | 6 ++-- lib/common/cmdline.c | 6 ++-- lib/common/ipc_client.c | 9 +++--- lib/common/ipc_controld.c | 4 +-- lib/common/iso8601.c | 4 +-- lib/common/messages.c | 2 +- lib/common/nvpair.c | 2 +- lib/common/patchset.c | 11 +++---- lib/common/remote.c | 4 +-- lib/common/rules.c | 12 +++---- lib/common/schemas.c | 10 +++--- lib/common/xml_element.c | 2 +- lib/fencing/st_actions.c | 28 ++++++++-------- lib/lrmd/lrmd_client.c | 4 +-- lib/pacemaker/pcmk_graph_consumer.c | 22 ++++++------- lib/pacemaker/pcmk_sched_colocation.c | 12 +++---- lib/pacemaker/pcmk_sched_promotable.c | 8 ++--- lib/pacemaker/pcmk_sched_recurring.c | 4 +-- lib/pacemaker/pcmk_scheduler.c | 2 +- lib/pacemaker/pcmk_status.c | 2 +- lib/pengine/complex.c | 13 ++++---- lib/pengine/failcounts.c | 8 ++--- lib/pengine/pe_output.c | 2 +- lib/pengine/rules_compat.c | 2 +- lib/pengine/unpack.c | 18 +++++------ lib/services/services.c | 2 +- lib/services/services_linux.c | 24 +++++++------- lib/services/services_ocf.c | 4 +-- lib/services/systemd.c | 2 +- tools/cibsecret.c | 2 +- tools/crm_attribute.c | 4 +-- tools/crm_mon.c | 4 +-- tools/crm_node.c | 4 +-- tools/crm_resource.c | 2 +- tools/crm_simulate.c | 2 +- tools/crm_verify.c | 2 +- tools/crmadmin.c | 2 +- tools/stonith_admin.c | 2 +- 54 files changed, 215 insertions(+), 218 deletions(-) diff --git a/daemons/attrd/attrd_cib.c b/daemons/attrd/attrd_cib.c index 324cd556a44..fb86f3a5151 100644 --- a/daemons/attrd/attrd_cib.c +++ b/daemons/attrd/attrd_cib.c @@ -640,7 +640,7 @@ write_attribute(attribute_t *a, bool ignore_delay) set_alert_attribute_value(alert_attribute_value, v); // Save this value so we can log it when write completes - pcmk__str_update(&(v->requested), v->current); + pcmk__str_update(&v->requested, v->current); } if (private_updates) { diff --git a/daemons/controld/controld_control.c b/daemons/controld/controld_control.c index fece662991c..f05401f88ab 100644 --- a/daemons/controld/controld_control.c +++ b/daemons/controld/controld_control.c @@ -65,7 +65,7 @@ do_ha_control(long long action, enum crmd_fsa_cause cause, controld_election_init(); - pcmk__str_update(&(controld_globals.our_uuid), + pcmk__str_update(&controld_globals.our_uuid, pcmk__cluster_get_xml_id(node)); if (controld_globals.our_uuid == NULL) { @@ -614,7 +614,7 @@ config_query_callback(xmlNode * msg, int call_id, int rc, xmlNode * output, void controld_globals.node_pending_timeout /= 1000; value = g_hash_table_lookup(config_hash, PCMK_OPT_CLUSTER_NAME); - pcmk__str_update(&(controld_globals.cluster_name), value); + pcmk__str_update(&controld_globals.cluster_name, value); // Let subcomponents initialize their own static variables controld_configure_election(config_hash); diff --git a/daemons/controld/controld_execd.c b/daemons/controld/controld_execd.c index 4c33460cac0..b7ad0cf699a 100644 --- a/daemons/controld/controld_execd.c +++ b/daemons/controld/controld_execd.c @@ -559,12 +559,12 @@ build_active_RAs(lrm_state_t * lrm_state, xmlNode * rsc_list) pcmk__xe_set(xml_rsc, PCMK__META_CONTAINER, container); } } - controld_add_resource_history_xml(xml_rsc, &(entry->rsc), entry->failed, + controld_add_resource_history_xml(xml_rsc, &entry->rsc, entry->failed, lrm_state->node_name); - controld_add_resource_history_xml(xml_rsc, &(entry->rsc), entry->last, + controld_add_resource_history_xml(xml_rsc, &entry->rsc, entry->last, lrm_state->node_name); for (gIter = entry->recurring_op_list; gIter != NULL; gIter = gIter->next) { - controld_add_resource_history_xml(xml_rsc, &(entry->rsc), gIter->data, + controld_add_resource_history_xml(xml_rsc, &entry->rsc, gIter->data, lrm_state->node_name); } } @@ -1627,7 +1627,7 @@ construct_op(const lrm_state_t *lrm_state, const xmlNode *rsc_op, pcmk__scan_min_int(op_timeout, &op->timeout, 0); if (pcmk__uint_from_hash(params, CRM_META "_" PCMK_META_INTERVAL, 0, - &(op->interval_ms)) != pcmk_rc_ok) { + &op->interval_ms) != pcmk_rc_ok) { op->interval_ms = 0; } @@ -2017,7 +2017,7 @@ do_lrm_rsc_op(lrm_state_t *lrm_state, lrmd_rsc_info_t *rsc, xmlNode *msg, pending->rsc_id = pcmk__str_copy(rsc->id); pending->start_time = time(NULL); pending->user_data = pcmk__str_copy(op->user_data); - pcmk__xe_get_time(msg, PCMK_OPT_SHUTDOWN_LOCK, &(pending->lock_time)); + pcmk__xe_get_time(msg, PCMK_OPT_SHUTDOWN_LOCK, &pending->lock_time); g_hash_table_replace(lrm_state->active_ops, call_id_s, pending); if ((op->interval_ms > 0) diff --git a/daemons/controld/controld_remote_ra.c b/daemons/controld/controld_remote_ra.c index 23a5512d3df..06d5b4e17e9 100644 --- a/daemons/controld/controld_remote_ra.c +++ b/daemons/controld/controld_remote_ra.c @@ -105,7 +105,7 @@ free_cmd(void *user_data) free(cmd->rsc_id); free(cmd->action); free(cmd->userdata); - pcmk__reset_result(&(cmd->result)); + pcmk__reset_result(&cmd->result); lrmd_key_value_freeall(cmd->params); free(cmd); } @@ -344,7 +344,7 @@ static void check_remote_node_state(const remote_ra_cmd_t *cmd) { /* Only successful actions can change node state */ - if (!pcmk__result_ok(&(cmd->result))) { + if (!pcmk__result_ok(&cmd->result)) { return; } @@ -416,7 +416,7 @@ report_remote_ra_result(remote_ra_cmd_t * cmd) cmd->result.exit_reason); if (pcmk__is_set(cmd->status, cmd_reported_success) - && !pcmk__result_ok(&(cmd->result))) { + && !pcmk__result_ok(&cmd->result)) { op.t_rcchange = time(NULL); /* This edge case will likely never ever occur, but if it does the @@ -486,7 +486,7 @@ retry_start_cmd_cb(void *data) if (remaining > 0) { rc = handle_remote_ra_start(lrm_state, cmd, remaining * 1000); } else { - pcmk__set_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, + pcmk__set_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_TIMEOUT, "Not enough time remains to retry remote connection"); } @@ -535,7 +535,7 @@ monitor_timeout_cb(void *data) pcmk__info("Timed out waiting for remote poke response from %s%s", cmd->rsc_id, ((lrm_state != NULL)? "" : " (no LRM state)")); cmd->monitor_timeout_id = 0; - pcmk__set_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_TIMEOUT, + pcmk__set_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_TIMEOUT, "Remote executor did not respond"); if (lrm_state && lrm_state->remote_ra_data) { @@ -676,7 +676,7 @@ remote_lrm_op_callback(lrmd_event_data_t * op) if ((op->connection_rc == -ENOKEY) || (op->connection_rc == -EKEYREJECTED)) { // Hard error, don't retry - pcmk__set_result(&(cmd->result), PCMK_OCF_INVALID_PARAM, + pcmk__set_result(&cmd->result, PCMK_OCF_INVALID_PARAM, PCMK_EXEC_ERROR, pcmk_strerror(op->connection_rc)); @@ -690,7 +690,7 @@ remote_lrm_op_callback(lrmd_event_data_t * op) pcmk__trace("Not enough time before timeout (%ds) to " "reschedule start", remaining); - pcmk__format_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, + pcmk__format_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_TIMEOUT, "%s without enough time to retry", pcmk_strerror(op->connection_rc)); @@ -698,7 +698,7 @@ remote_lrm_op_callback(lrmd_event_data_t * op) } else { lrm_state_reset_tables(lrm_state, TRUE); - pcmk__set_result(&(cmd->result), PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); + pcmk__set_result(&cmd->result, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); lrm_remote_set_flags(lrm_state, remote_active); } @@ -719,7 +719,7 @@ remote_lrm_op_callback(lrmd_event_data_t * op) * For this function, if we get the poke pack, it is always a success. Pokes * only fail if the send fails, or the response times out. */ if (!pcmk__is_set(cmd->status, cmd_reported_success)) { - pcmk__set_result(&(cmd->result), PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); + pcmk__set_result(&cmd->result, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); report_remote_ra_result(cmd); cmd_set_flags(cmd, cmd_reported_success); } @@ -741,7 +741,7 @@ remote_lrm_op_callback(lrmd_event_data_t * op) if (pcmk__is_set(ra_data->status, remote_active) && !pcmk__is_set(cmd->status, cmd_cancel)) { - pcmk__set_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, + pcmk__set_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_ERROR, "Remote connection unexpectedly dropped " "during monitor"); @@ -791,7 +791,7 @@ handle_remote_ra_stop(lrm_state_t * lrm_state, remote_ra_cmd_t * cmd) lrm_state->remote_ra_data->cur_cmd = NULL; if (cmd) { - pcmk__set_result(&(cmd->result), PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); + pcmk__set_result(&cmd->result, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); report_remote_ra_result(cmd); } } @@ -825,7 +825,7 @@ handle_remote_ra_start(lrm_state_t * lrm_state, remote_ra_cmd_t * cmd, int timeo rc = controld_connect_remote_executor(lrm_state, server, port, timeout_used); if (rc != pcmk_rc_ok) { - pcmk__format_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, + pcmk__format_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_ERROR, "Could not connect to Pacemaker Remote node %s: %s", lrm_state->node_name, pcmk_rc_str(rc)); @@ -877,12 +877,12 @@ handle_remote_ra_exec(void *user_data) if (lrm_state_is_connected(lrm_state) == TRUE) { rc = lrm_state_poke_connection(lrm_state); if (rc < 0) { - pcmk__set_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, + pcmk__set_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_ERROR, pcmk_strerror(rc)); } } else { rc = -1; - pcmk__set_result(&(cmd->result), PCMK_OCF_NOT_RUNNING, + pcmk__set_result(&cmd->result, PCMK_OCF_NOT_RUNNING, PCMK_EXEC_DONE, "Remote connection inactive"); } @@ -918,7 +918,7 @@ handle_remote_ra_exec(void *user_data) } else if (strcmp(cmd->action, PCMK_ACTION_MIGRATE_TO) == 0) { lrm_remote_clear_flags(lrm_state, takeover_complete); lrm_remote_set_flags(lrm_state, expect_takeover); - pcmk__set_result(&(cmd->result), PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); + pcmk__set_result(&cmd->result, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); report_remote_ra_result(cmd); } else if (pcmk__str_any_of(cmd->action, PCMK_ACTION_RELOAD, @@ -932,7 +932,7 @@ handle_remote_ra_exec(void *user_data) * of "reload-agent". An OCF 1.1 "reload" would be a no-op anyway, * so this would work for that purpose as well. */ - pcmk__set_result(&(cmd->result), PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); + pcmk__set_result(&cmd->result, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); report_remote_ra_result(cmd); } @@ -1031,7 +1031,7 @@ fail_all_monitor_cmds(GList * list) for (gIter = rm_list; gIter != NULL; gIter = gIter->next) { cmd = gIter->data; - pcmk__set_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, + pcmk__set_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_ERROR, "Lost connection to remote executor"); pcmk__trace("Pre-emptively failing %s %s (interval=%u, %s)", cmd->action, cmd->rsc_id, cmd->interval_ms, cmd->userdata); diff --git a/daemons/controld/controld_timers.c b/daemons/controld/controld_timers.c index 72410e4ffd3..90138ee716c 100644 --- a/daemons/controld/controld_timers.c +++ b/daemons/controld/controld_timers.c @@ -331,26 +331,26 @@ controld_configure_fsa_timers(GHashTable *options) // Election timer value = g_hash_table_lookup(options, PCMK_OPT_DC_DEADTIME); - pcmk_parse_interval_spec(value, &(election_timer->period_ms)); + pcmk_parse_interval_spec(value, &election_timer->period_ms); // Integration timer value = g_hash_table_lookup(options, PCMK_OPT_JOIN_INTEGRATION_TIMEOUT); - pcmk_parse_interval_spec(value, &(integration_timer->period_ms)); + pcmk_parse_interval_spec(value, &integration_timer->period_ms); // Finalization timer value = g_hash_table_lookup(options, PCMK_OPT_JOIN_FINALIZATION_TIMEOUT); - pcmk_parse_interval_spec(value, &(finalization_timer->period_ms)); + pcmk_parse_interval_spec(value, &finalization_timer->period_ms); // Shutdown escalation timer value = g_hash_table_lookup(options, PCMK_OPT_SHUTDOWN_ESCALATION); - pcmk_parse_interval_spec(value, &(shutdown_escalation_timer->period_ms)); + pcmk_parse_interval_spec(value, &shutdown_escalation_timer->period_ms); pcmk__debug("Shutdown escalation occurs if DC has not responded to request " "in %ums", shutdown_escalation_timer->period_ms); // Transition timer value = g_hash_table_lookup(options, PCMK_OPT_TRANSITION_DELAY); - pcmk_parse_interval_spec(value, &(transition_timer->period_ms)); + pcmk_parse_interval_spec(value, &transition_timer->period_ms); // Recheck interval value = g_hash_table_lookup(options, PCMK_OPT_CLUSTER_RECHECK_INTERVAL); diff --git a/daemons/controld/controld_utils.c b/daemons/controld/controld_utils.c index 7775ea40a9d..fa67e90dbb5 100644 --- a/daemons/controld/controld_utils.c +++ b/daemons/controld/controld_utils.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. * @@ -693,8 +693,8 @@ update_dc(xmlNode * msg) } controld_globals.dc_name = NULL; // freed as last_dc - pcmk__str_update(&(controld_globals.dc_name), welcome_from); - pcmk__str_update(&(controld_globals.dc_version), dc_version); + pcmk__str_update(&controld_globals.dc_name, welcome_from); + pcmk__str_update(&controld_globals.dc_version, dc_version); if (pcmk__str_eq(controld_globals.dc_name, last_dc, pcmk__str_casei)) { /* do nothing */ diff --git a/daemons/controld/pacemaker-controld.c b/daemons/controld/pacemaker-controld.c index 2e8564fb90f..58f17e004b1 100644 --- a/daemons/controld/pacemaker-controld.c +++ b/daemons/controld/pacemaker-controld.c @@ -162,7 +162,7 @@ main(int argc, char **argv) goto done; } - if (pcmk__log_output_new(&(controld_globals.logger_out)) != pcmk_rc_ok) { + if (pcmk__log_output_new(&controld_globals.logger_out) != pcmk_rc_ok) { exit_code = CRM_EX_FATAL; goto done; } diff --git a/daemons/execd/execd_alerts.c b/daemons/execd/execd_alerts.c index d4391c41498..5d1f9e3e7fa 100644 --- a/daemons/execd/execd_alerts.c +++ b/daemons/execd/execd_alerts.c @@ -135,7 +135,7 @@ execd_process_alert_exec(pcmk__client_t *client, xmlNode *request) cb_data->client_id = pcmk__str_copy(client->id); - pcmk__xe_get_int(request, PCMK__XA_LRMD_CALLID, &(cb_data->call_id)); + pcmk__xe_get_int(request, PCMK__XA_LRMD_CALLID, &cb_data->call_id); action = services_alert_create(alert_id, alert_path, alert_timeout, params, alert_sequence_no, cb_data); diff --git a/daemons/execd/execd_commands.c b/daemons/execd/execd_commands.c index ba1698ef6dd..bc086263d6c 100644 --- a/daemons/execd/execd_commands.c +++ b/daemons/execd/execd_commands.c @@ -369,7 +369,7 @@ free_lrmd_cmd(lrmd_cmd_t * cmd) g_clear_pointer(&cmd->params, g_hash_table_destroy); - pcmk__reset_result(&(cmd->result)); + pcmk__reset_result(&cmd->result); free(cmd->origin); free(cmd->action); free(cmd->real_action); @@ -399,7 +399,7 @@ stonith_recurring_op_helper(void *data) rsc->recurring_ops = g_list_remove(rsc->recurring_ops, cmd); rsc->pending_ops = g_list_append(rsc->pending_ops, cmd); #ifdef PCMK__TIME_USE_CGT - get_current_time(&(cmd->t_queue), &(cmd->t_first_queue)); + get_current_time(&cmd->t_queue, &cmd->t_first_queue); #endif mainloop_set_trigger(rsc->work); @@ -539,7 +539,7 @@ schedule_lrmd_cmd(lrmd_rsc_t * rsc, lrmd_cmd_t * cmd) rsc->pending_ops = g_list_append(rsc->pending_ops, cmd); #ifdef PCMK__TIME_USE_CGT - get_current_time(&(cmd->t_queue), &(cmd->t_first_queue)); + get_current_time(&cmd->t_queue, &cmd->t_first_queue); #endif mainloop_set_trigger(rsc->work); @@ -611,8 +611,8 @@ send_cmd_complete_notify(lrmd_cmd_t * cmd) int queue_time = 0; #ifdef PCMK__TIME_USE_CGT - exec_time = time_diff_ms(NULL, &(cmd->t_run)); - queue_time = time_diff_ms(&cmd->t_run, &(cmd->t_queue)); + exec_time = time_diff_ms(NULL, &cmd->t_run); + queue_time = time_diff_ms(&cmd->t_run, &cmd->t_queue); #endif log_finished(cmd, exec_time, queue_time); @@ -733,7 +733,7 @@ cmd_reset(lrmd_cmd_t * cmd) #endif cmd->epoch_last_run = 0; - pcmk__reset_result(&(cmd->result)); + pcmk__reset_result(&cmd->result); cmd->result.execution_status = PCMK_EXEC_DONE; } @@ -855,8 +855,8 @@ action_complete(svc_action_t * action) // Cast variable instead of function return to keep compilers happy code = services_result2ocf(action->standard, cmd->action, action->rc); - pcmk__set_result(&(cmd->result), (int) code, - action->status, services__exit_reason(action)); + pcmk__set_result(&cmd->result, (int) code, action->status, + services__exit_reason(action)); rsc = cmd->rsc_id ? g_hash_table_lookup(rsc_list, cmd->rsc_id) : NULL; @@ -875,7 +875,7 @@ action_complete(svc_action_t * action) goto finalize; } - if (pcmk__result_ok(&(cmd->result)) + if (pcmk__result_ok(&cmd->result) && pcmk__strcase_any_of(cmd->action, PCMK_ACTION_START, PCMK_ACTION_STOP, NULL)) { /* Getting results for when a start or stop action completes is now @@ -886,7 +886,7 @@ action_complete(svc_action_t * action) * @TODO When monitors are handled in the same way, this function * can either be drastically simplified or done away with entirely. */ - services__copy_result(action, &(cmd->result)); + services__copy_result(action, &cmd->result); goto finalize; } else if (cmd->result.execution_status == PCMK_EXEC_PENDING && @@ -902,13 +902,13 @@ action_complete(svc_action_t * action) if (cmd->result.execution_status == PCMK_EXEC_PENDING) { goagain = true; - } else if (pcmk__result_ok(&(cmd->result)) + } else if (pcmk__result_ok(&cmd->result) && pcmk__str_eq(cmd->real_action, PCMK_ACTION_STOP, pcmk__str_casei)) { goagain = true; } else { - int time_sum = time_diff_ms(NULL, &(cmd->t_first_run)); + int time_sum = time_diff_ms(NULL, &cmd->t_first_run); int timeout_left = cmd->timeout_orig - time_sum; pcmk__debug("%s systemd %s is now complete (elapsed=%dms, " @@ -948,7 +948,7 @@ action_complete(svc_action_t * action) cmd->rsc_id, cmd->action, cmd->result.exit_status, g_strchomp(ctime(&cmd->epoch_rcchange)), cmd->timeout_orig); - pcmk__set_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, + pcmk__set_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_TIMEOUT, "Investigate reason for timeout, and adjust " "configured operation timeout if necessary"); @@ -961,7 +961,7 @@ action_complete(svc_action_t * action) goto finalize; } - time_sum = time_diff_ms(NULL, &(cmd->t_first_run)); + time_sum = time_diff_ms(NULL, &cmd->t_first_run); timeout_left = cmd->timeout_orig - time_sum; delay = cmd->timeout_orig / 10; @@ -974,7 +974,7 @@ action_complete(svc_action_t * action) cmd->start_delay = delay; cmd->timeout = timeout_left; - if (pcmk__result_ok(&(cmd->result))) { + if (pcmk__result_ok(&cmd->result)) { pcmk__debug("%s %s may still be in progress: re-scheduling " "(elapsed=%dms, remaining=%dms, start_delay=%dms)", cmd->rsc_id, cmd->real_action, time_sum, timeout_left, @@ -1009,7 +1009,7 @@ action_complete(svc_action_t * action) "remaining=%dms)", cmd->rsc_id, pcmk__s(cmd->real_action, cmd->action), cmd->result.exit_status, time_sum, timeout_left); - pcmk__set_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, + pcmk__set_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_TIMEOUT, "Investigate reason for timeout, and adjust " "configured operation timeout if necessary"); @@ -1018,7 +1018,7 @@ action_complete(svc_action_t * action) #endif finalize: - pcmk__set_result_output(&(cmd->result), services__grab_stdout(action), + pcmk__set_result_output(&cmd->result, services__grab_stdout(action), services__grab_stderr(action)); cmd_finalize(cmd, rsc); } @@ -1092,7 +1092,7 @@ fencing_rsc_action_complete(lrmd_cmd_t *cmd, int exit_status, pcmk__set_result(&cmd->result, exit_status, execution_status, exit_reason); // Certain successful actions change the known state of the resource - if ((rsc != NULL) && pcmk__result_ok(&(cmd->result))) { + if ((rsc != NULL) && pcmk__result_ok(&cmd->result)) { if (pcmk__str_eq(cmd->action, PCMK_ACTION_START, pcmk__str_casei)) { pcmk__set_result(&rsc->fence_probe_result, CRM_EX_OK, @@ -1371,14 +1371,14 @@ execute_nonstonith_action(lrmd_rsc_t *rsc, lrmd_cmd_t *cmd) params_copy, cmd->service_flags); if (action == NULL) { - pcmk__set_result(&(cmd->result), PCMK_OCF_UNKNOWN_ERROR, - PCMK_EXEC_ERROR, strerror(ENOMEM)); + pcmk__set_result(&cmd->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_ERROR, + strerror(ENOMEM)); cmd_finalize(cmd, rsc); return; } if (action->rc != PCMK_OCF_UNKNOWN) { - services__copy_result(action, &(cmd->result)); + services__copy_result(action, &cmd->result); services_action_free(action); cmd_finalize(cmd, rsc); return; @@ -1403,7 +1403,7 @@ execute_nonstonith_action(lrmd_rsc_t *rsc, lrmd_cmd_t *cmd) * called cmd_finalize(), which in this case should only reset (not * free) cmd. */ - services__copy_result(action, &(cmd->result)); + services__copy_result(action, &cmd->result); services_action_free(action); } } @@ -1435,7 +1435,7 @@ execute_resource_action(void *user_data) g_list_free_1(first); #ifdef PCMK__TIME_USE_CGT - get_current_time(&(cmd->t_run), &(cmd->t_first_run)); + get_current_time(&cmd->t_run, &cmd->t_first_run); #endif cmd->epoch_last_run = time(NULL); } diff --git a/daemons/fenced/fenced_commands.c b/daemons/fenced/fenced_commands.c index 6d92c57507b..9c8f0667b36 100644 --- a/daemons/fenced/fenced_commands.c +++ b/daemons/fenced/fenced_commands.c @@ -541,12 +541,12 @@ create_async_command(xmlNode *msg) return NULL; } - pcmk__xe_get_int(msg, PCMK__XA_ST_CALLID, &(cmd->id)); - pcmk__xe_get_int(msg, PCMK__XA_ST_DELAY, &(cmd->start_delay)); - pcmk__xe_get_int(msg, PCMK__XA_ST_TIMEOUT, &(cmd->default_timeout)); + pcmk__xe_get_int(msg, PCMK__XA_ST_CALLID, &cmd->id); + pcmk__xe_get_int(msg, PCMK__XA_ST_DELAY, &cmd->start_delay); + pcmk__xe_get_int(msg, PCMK__XA_ST_TIMEOUT, &cmd->default_timeout); cmd->timeout = cmd->default_timeout; - rc = pcmk__xe_get_flags(msg, PCMK__XA_ST_CALLOPT, &(cmd->options), + rc = pcmk__xe_get_flags(msg, PCMK__XA_ST_CALLOPT, &cmd->options, st_opt_none); if (rc != pcmk_rc_ok) { pcmk__warn("Couldn't parse options from request: %s", pcmk_rc_str(rc)); @@ -1179,7 +1179,7 @@ build_device_from_xml(const xmlNode *dev) } value = g_hash_table_lookup(device->params, PCMK_FENCING_HOST_MAP); - device->aliases = build_port_aliases(value, &(device->targets)); + device->aliases = build_port_aliases(value, &device->targets); value = target_list_type(device); if (!pcmk__str_eq(value, PCMK_VALUE_STATIC_LIST, pcmk__str_casei) diff --git a/daemons/fenced/fenced_remote.c b/daemons/fenced/fenced_remote.c index 9e05e87fb07..9d59d054e81 100644 --- a/daemons/fenced/fenced_remote.c +++ b/daemons/fenced/fenced_remote.c @@ -1179,10 +1179,10 @@ create_remote_stonith_op(const char *client, xmlNode *request, gboolean peer) op = pcmk__assert_alloc(1, sizeof(remote_fencing_op_t)); - pcmk__xe_get_int(request, PCMK__XA_ST_TIMEOUT, &(op->base_timeout)); + pcmk__xe_get_int(request, PCMK__XA_ST_TIMEOUT, &op->base_timeout); // Value -1 means disable any static/random fencing delays - pcmk__xe_get_int(request, PCMK__XA_ST_DELAY, &(op->client_delay)); + pcmk__xe_get_int(request, PCMK__XA_ST_DELAY, &op->client_delay); if (peer) { op->id = pcmk__xe_get_copy(dev, PCMK__XA_ST_REMOTE_OP); @@ -1230,14 +1230,14 @@ create_remote_stonith_op(const char *client, xmlNode *request, gboolean peer) // @TODO Figure out how to avoid copying XML here op->request = pcmk__xml_copy(NULL, request); - rc = pcmk__xe_get_flags(request, PCMK__XA_ST_CALLOPT, &(op->call_options), + rc = pcmk__xe_get_flags(request, PCMK__XA_ST_CALLOPT, &op->call_options, 0U); if (rc != pcmk_rc_ok) { pcmk__warn("Couldn't parse options from request %s: %s", op->id, pcmk_rc_str(rc)); } - pcmk__xe_get_int(request, PCMK__XA_ST_CALLID, &(op->client_callid)); + pcmk__xe_get_int(request, PCMK__XA_ST_CALLID, &op->client_callid); pcmk__trace("%s new fencing op %s ('%s' targeting %s for client %s, base " "timeout %ds, %u %s expected)", @@ -1259,7 +1259,7 @@ create_remote_stonith_op(const char *client, xmlNode *request, gboolean peer) stonith__clear_call_options(op->call_options, op->id, st_opt_cs_nodeid); if ((node != NULL) && (node->name != NULL)) { - pcmk__str_update(&(op->target), node->name); + pcmk__str_update(&op->target, node->name); } else { pcmk__warn("Could not expand nodeid '%s' into a host name", @@ -2259,7 +2259,7 @@ add_device_properties(const xmlNode *xml, remote_fencing_op_t *op, // Nodes <2.1.5 won't set this, so assume unfencing in that case rc = pcmk__xe_get_flags(xml, PCMK__XA_ST_DEVICE_SUPPORT_FLAGS, - &(props->device_support_flags), + &props->device_support_flags, fenced_df_supports_on); if (rc != pcmk_rc_ok) { pcmk__warn("Couldn't determine device support for %s " diff --git a/daemons/pacemakerd/pcmkd_subdaemons.c b/daemons/pacemakerd/pcmkd_subdaemons.c index 6637d7de73a..63152d29df0 100644 --- a/daemons/pacemakerd/pcmkd_subdaemons.c +++ b/daemons/pacemakerd/pcmkd_subdaemons.c @@ -149,7 +149,7 @@ check_next_subdaemon(void *user_data) { static int next_child = 0; - pcmkd_child_t *child = &(pcmk_children[next_child]); + pcmkd_child_t *child = &pcmk_children[next_child]; const char *name = pcmk__server_name(child->server); const long long pid = PCMK__SPECIAL_PID_AS_0(child->pid); int rc = child_liveness(child); @@ -361,7 +361,7 @@ pcmk_shutdown_worker(void *user_data) } for (; phase >= 0; phase--) { - pcmkd_child_t *child = &(pcmk_children[phase]); + pcmkd_child_t *child = &pcmk_children[phase]; const char *name = pcmk__server_name(child->server); time_t now = 0; diff --git a/lib/cib/cib_client.c b/lib/cib/cib_client.c index 685613c403b..c598e704982 100644 --- a/lib/cib/cib_client.c +++ b/lib/cib/cib_client.c @@ -412,7 +412,7 @@ cib_client_fetch_schemas(cib_t *cib, xmlNode **output_data, const char *after_ve static void cib_client_set_user(cib_t *cib, const char *user) { - pcmk__str_update(&(cib->user), user); + pcmk__str_update(&cib->user, user); } static void diff --git a/lib/cib/cib_ops.c b/lib/cib/cib_ops.c index 2fb7d93ce12..41ead4081b2 100644 --- a/lib/cib/cib_ops.c +++ b/lib/cib/cib_ops.c @@ -148,7 +148,7 @@ cib__get_operation(const char *op, const cib__operation_t **operation) operation_table = pcmk__strkey_table(NULL, NULL); for (int lpc = 0; lpc < PCMK__NELEM(cib_ops); lpc++) { - const cib__operation_t *oper = &(cib_ops[lpc]); + const cib__operation_t *oper = &cib_ops[lpc]; g_hash_table_insert(operation_table, (void *) oper->name, (void *) oper); diff --git a/lib/cib/cib_remote.c b/lib/cib/cib_remote.c index 8ba9bb8909a..3ab13b2a283 100644 --- a/lib/cib/cib_remote.c +++ b/lib/cib/cib_remote.c @@ -472,7 +472,7 @@ cib_tls_signon(cib_t *cib, pcmk__remote_t *connection, gboolean event_channel) connection->tcp_socket = -1; connection->tls_session = NULL; rc = pcmk__connect_remote(private->server, private->port, 0, NULL, - &(connection->tcp_socket), NULL, NULL); + &connection->tcp_socket, NULL, NULL); if (rc != pcmk_rc_ok) { pcmk__info("Remote connection to %s:%d failed: %s " QB_XS " rc=%d", private->server, private->port, pcmk_rc_str(rc), rc); @@ -585,9 +585,9 @@ cib_remote_signon(cib_t *cib, const char *name, enum cib_conn_type type) /* If no pcmk__output_t is set, just assume that a text prompt * is good enough. */ - pcmk__text_prompt("Password", false, &(private->passwd)); + pcmk__text_prompt("Password", false, &private->passwd); } else { - private->out->prompt("Password", false, &(private->passwd)); + private->out->prompt("Password", false, &private->passwd); } } @@ -596,12 +596,12 @@ cib_remote_signon(cib_t *cib, const char *name, enum cib_conn_type type) goto done; } - rc = cib_tls_signon(cib, &(private->command), FALSE); + rc = cib_tls_signon(cib, &private->command, false); if (rc != pcmk_ok) { goto done; } - rc = cib_tls_signon(cib, &(private->callback), TRUE); + rc = cib_tls_signon(cib, &private->callback, true); done: if (rc == pcmk_ok) { diff --git a/lib/cluster/cpg.c b/lib/cluster/cpg.c index aa0a17076ff..c121a2f9d07 100644 --- a/lib/cluster/cpg.c +++ b/lib/cluster/cpg.c @@ -319,10 +319,10 @@ check_message_sanity(const pcmk__cpg_msg_t *msg) pcmk__err("%sCPG message %d from %s invalid: Claimed size of %d bytes " "is too small " QB_XS " from %s[%u] to %s@%s", (msg->is_compressed? "Compressed " : ""), - msg->id, ais_dest(&(msg->sender)), + msg->id, ais_dest(&msg->sender), (int) msg->header.size, msg_type2text(msg->sender.type), msg->sender.pid, - msg_type2text(msg->host.type), ais_dest(&(msg->host))); + msg_type2text(msg->host.type), ais_dest(&msg->host)); return false; } @@ -330,10 +330,10 @@ check_message_sanity(const pcmk__cpg_msg_t *msg) pcmk__err("%sCPG message %d from %s invalid: Sender indicated error %d " QB_XS " from %s[%u] to %s@%s", (msg->is_compressed? "Compressed " : ""), - msg->id, ais_dest(&(msg->sender)), + msg->id, ais_dest(&msg->sender), msg->header.error, msg_type2text(msg->sender.type), msg->sender.pid, - msg_type2text(msg->host.type), ais_dest(&(msg->host))); + msg_type2text(msg->host.type), ais_dest(&msg->host)); return false; } @@ -342,10 +342,10 @@ check_message_sanity(const pcmk__cpg_msg_t *msg) "inconsistent with payload size %d " QB_XS " from %s[%u] to %s@%s", (msg->is_compressed? "Compressed " : ""), - msg->id, ais_dest(&(msg->sender)), + msg->id, ais_dest(&msg->sender), (int) msg->header.size, (int) msg_data_len(msg), msg_type2text(msg->sender.type), msg->sender.pid, - msg_type2text(msg->host.type), ais_dest(&(msg->host))); + msg_type2text(msg->host.type), ais_dest(&msg->host)); return false; } @@ -357,9 +357,9 @@ check_message_sanity(const pcmk__cpg_msg_t *msg) || (msg->data[msg->size - 1] != '\0'))) { pcmk__err("CPG message %d from %s invalid: Payload does not end at " "byte %" PRIu32 " " QB_XS " from %s[%u] to %s@%s", - msg->id, ais_dest(&(msg->sender)), msg->size, + msg->id, ais_dest(&msg->sender), msg->size, msg_type2text(msg->sender.type), msg->sender.pid, - msg_type2text(msg->host.type), ais_dest(&(msg->host))); + msg_type2text(msg->host.type), ais_dest(&msg->host)); return false; } @@ -367,8 +367,8 @@ check_message_sanity(const pcmk__cpg_msg_t *msg) (int) msg->header.size, (msg->is_compressed? "compressed " : ""), msg->id, msg_type2text(msg->sender.type), msg->sender.pid, - ais_dest(&(msg->sender)), - msg_type2text(msg->host.type), ais_dest(&(msg->host))); + ais_dest(&msg->sender), + msg_type2text(msg->host.type), ais_dest(&msg->host)); return true; } @@ -477,7 +477,7 @@ pcmk__cpg_message_data(cpg_handle_t handle, uint32_t sender_id, uint32_t pid, free(uncompressed); pcmk__warn("Ignoring compressed CPG message %d from %s (ID %" PRIu32 " PID %" PRIu32 "): %s", - msg->id, ais_dest(&(msg->sender)), sender_id, pid, + msg->id, ais_dest(&msg->sender), sender_id, pid, pcmk_rc_str(rc)); return NULL; } @@ -490,7 +490,7 @@ pcmk__cpg_message_data(cpg_handle_t handle, uint32_t sender_id, uint32_t pid, pcmk__trace("Received %sCPG message %d from %s (ID %" PRIu32 " PID %" PRIu32 "): %.40s...", (msg->is_compressed? "compressed " : ""), - msg->id, ais_dest(&(msg->sender)), sender_id, pid, msg->data); + msg->id, ais_dest(&msg->sender), sender_id, pid, msg->data); return data; } diff --git a/lib/cluster/election.c b/lib/cluster/election.c index 1ca0d4597b1..db44bfdfccd 100644 --- a/lib/cluster/election.c +++ b/lib/cluster/election.c @@ -436,7 +436,7 @@ parse_election_message(const xmlNode *message, struct vote *vote) vote->version = pcmk__xe_get(message, PCMK_XA_VERSION); vote->election_owner = pcmk__xe_get(message, PCMK__XA_ELECTION_OWNER); - pcmk__xe_get_int(message, PCMK__XA_ELECTION_ID, &(vote->election_id)); + pcmk__xe_get_int(message, PCMK__XA_ELECTION_ID, &vote->election_id); if ((vote->op == NULL) || (vote->from == NULL) || (vote->version == NULL) || (vote->election_owner == NULL) || (vote->election_id < 0)) { @@ -455,7 +455,7 @@ parse_election_message(const xmlNode *message, struct vote *vote) */ if ((pcmk__xe_get_timeval(message, PCMK__XA_ELECTION_AGE_SEC, PCMK__XA_ELECTION_AGE_NANO_SEC, - &(vote->age)) != pcmk_rc_ok) + &vote->age) != pcmk_rc_ok) || (vote->age.tv_sec < 0) || (vote->age.tv_usec < 0)) { pcmk__warn("Cannot count election %s from %s because uptime is " @@ -705,7 +705,7 @@ election_count_vote(pcmk_cluster_t *cluster, const xmlNode *message, } else { char *loss_time = NULL; - loss_time = ctime(&(cluster->priv->election->last_election_loss)); + loss_time = ctime(&cluster->priv->election->last_election_loss); if (loss_time) { // Show only HH:MM:SS loss_time += 11; diff --git a/lib/common/cmdline.c b/lib/common/cmdline.c index 89e92ef560f..b3f29fb990b 100644 --- a/lib/common/cmdline.c +++ b/lib/common/cmdline.c @@ -70,7 +70,7 @@ pcmk__build_arg_context(pcmk__common_args_t *common_args, const char *fmts, GOptionGroup *main_group; GOptionEntry main_entries[3] = { - { "version", '$', 0, G_OPTION_ARG_NONE, &(common_args->version), + { "version", '$', 0, G_OPTION_ARG_NONE, &common_args->version, N_("Display software version and exit"), NULL }, { "verbose", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, bump_verbosity, @@ -91,10 +91,10 @@ pcmk__build_arg_context(pcmk__common_args_t *common_args, const char *fmts, if (fmts != NULL) { GOptionEntry output_entries[3] = { - { "output-as", 0, 0, G_OPTION_ARG_STRING, &(common_args->output_ty), + { "output-as", 0, 0, G_OPTION_ARG_STRING, &common_args->output_ty, NULL, N_("FORMAT") }, - { "output-to", 0, 0, G_OPTION_ARG_STRING, &(common_args->output_dest), + { "output-to", 0, 0, G_OPTION_ARG_STRING, &common_args->output_dest, N_( "Specify file name for output (or \"-\" for stdout)"), N_("DEST") }, { NULL } diff --git a/lib/common/ipc_client.c b/lib/common/ipc_client.c index b3c3309351a..63529d52dc5 100644 --- a/lib/common/ipc_client.c +++ b/lib/common/ipc_client.c @@ -384,7 +384,7 @@ pcmk_poll_ipc(const pcmk_ipc_api_t *api, int timeout_ms) return EINVAL; } - rc = pcmk__ipc_fd(api->ipc, &(pollfd.fd)); + rc = pcmk__ipc_fd(api->ipc, &pollfd.fd); if (rc != pcmk_rc_ok) { pcmk__debug("Could not obtain file descriptor for %s IPC: %s", pcmk_ipc_name(api, true), pcmk_rc_str(rc)); @@ -440,7 +440,7 @@ connect_with_main_loop(pcmk_ipc_api_t *api) }; rc = pcmk__add_mainloop_ipc(api->ipc, G_PRIORITY_DEFAULT, api, - &callbacks, &(api->mainloop_io)); + &callbacks, &api->mainloop_io); if (rc != pcmk_rc_ok) { return rc; } @@ -1078,7 +1078,7 @@ crm_ipc_ready(crm_ipc_t *client) } client->pfd.revents = 0; - rc = poll(&(client->pfd), 1, 0); + rc = poll(&client->pfd, 1, 0); return (rc < 0)? -errno : rc; } @@ -1679,8 +1679,7 @@ pcmk__ipc_is_authentic_process_active(const char *name, uid_t refuid, struct pollfd pollfd = { 0, }; int poll_rc; - c = qb_ipcc_connect_async(name, 0, - &(pollfd.fd)); + c = qb_ipcc_connect_async(name, 0, &pollfd.fd); #else c = qb_ipcc_connect(name, 0); #endif diff --git a/lib/common/ipc_controld.c b/lib/common/ipc_controld.c index 21bfdf0ea39..7a119df5927 100644 --- a/lib/common/ipc_controld.c +++ b/lib/common/ipc_controld.c @@ -1,5 +1,5 @@ /* - * Copyright 2020-2025 the Pacemaker project contributors + * Copyright 2020-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -138,7 +138,7 @@ set_node_info_data(pcmk_controld_api_reply_t *data, xmlNode *msg_data) * @TODO: Improve handling after pcmk__node_status_t is refactored to handle * layer-specific data better. */ - pcmk__xe_get_int(msg_data, PCMK_XA_ID, &(data->data.node_info.id)); + pcmk__xe_get_int(msg_data, PCMK_XA_ID, &data->data.node_info.id); data->data.node_info.uuid = pcmk__xe_get(msg_data, PCMK_XA_ID); data->data.node_info.uname = pcmk__xe_get(msg_data, PCMK_XA_UNAME); diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 6d2cd338f07..69e9fd3a4cb 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -376,7 +376,7 @@ parse_time(const char *time_str, crm_time_t *a_time) tzset(); - if (!parse_hms(time_str, &(a_time->seconds))) { + if (!parse_hms(time_str, &a_time->seconds)) { return false; } @@ -395,7 +395,7 @@ parse_time(const char *time_str, crm_time_t *a_time) } } - if (!parse_offset(offset_s, &(a_time->offset))) { + if (!parse_offset(offset_s, &a_time->offset)) { return false; } diff --git a/lib/common/messages.c b/lib/common/messages.c index e7072ce8696..370550e867f 100644 --- a/lib/common/messages.c +++ b/lib/common/messages.c @@ -242,5 +242,5 @@ void pcmk__reset_request(pcmk__request_t *request) { g_clear_pointer(&request->op, free); - pcmk__reset_result(&(request->result)); + pcmk__reset_result(&request->result); } diff --git a/lib/common/nvpair.c b/lib/common/nvpair.c index 3f1bed26e02..b855da334b5 100644 --- a/lib/common/nvpair.c +++ b/lib/common/nvpair.c @@ -446,7 +446,7 @@ pcmk__unpack_nvpair_block(void *data, void *user_data) rule_xml = pcmk__xe_first_child(pair, PCMK_XE_RULE, NULL, NULL); if ((rule_xml != NULL) - && (pcmk_evaluate_rule(rule_xml, &(unpack_data->rule_input), + && (pcmk_evaluate_rule(rule_xml, &unpack_data->rule_input, unpack_data->next_change) != pcmk_rc_ok)) { return; } diff --git a/lib/common/patchset.c b/lib/common/patchset.c index 778be7ff9bd..ad4ad33b2b4 100644 --- a/lib/common/patchset.c +++ b/lib/common/patchset.c @@ -512,7 +512,7 @@ pcmk__xml_patchset_versions(const xmlNode *patchset, int source[3], for (int i = 0; i < PCMK__NELEM(vfields); i++) { if (source_xml != NULL) { if (pcmk__xe_get_int(source_xml, vfields[i], - &(source[i])) != pcmk_rc_ok) { + &source[i]) != pcmk_rc_ok) { return EINVAL; } pcmk__trace("Got source[%s]=%d", vfields[i], source[i]); @@ -524,7 +524,7 @@ pcmk__xml_patchset_versions(const xmlNode *patchset, int source[3], if (target_xml != NULL) { if (pcmk__xe_get_int(target_xml, vfields[i], - &(target[i])) != pcmk_rc_ok) { + &target[i]) != pcmk_rc_ok) { return EINVAL; } pcmk__trace("Got target[%s]=%d", vfields[i], target[i]); @@ -561,8 +561,7 @@ check_patchset_versions(const xmlNode *cib_root, const xmlNode *patchset) * Preserve behavior for xml_apply_patchset(). Use new behavior in a * future replacement. */ - if (pcmk__xe_get_int(cib_root, vfields[i], - &(current[i])) == pcmk_rc_ok) { + if (pcmk__xe_get_int(cib_root, vfields[i], ¤t[i]) == pcmk_rc_ok) { pcmk__trace("Got %d for current[%s]%s", current[i], vfields[i], ((current[i] < 0)? ", using 0" : "")); } else { @@ -1133,14 +1132,14 @@ xml_patch_versions(const xmlNode *patchset, int add[3], int del[3]) if (source != NULL) { for (int i = 0; i < PCMK__NELEM(vfields); i++) { - pcmk__xe_get_int(source, vfields[i], &(del[i])); + pcmk__xe_get_int(source, vfields[i], &del[i]); pcmk__trace("Got %d for del[%s]", del[i], vfields[i]); } } if (target != NULL) { for (int i = 0; i < PCMK__NELEM(vfields); i++) { - pcmk__xe_get_int(target, vfields[i], &(add[i])); + pcmk__xe_get_int(target, vfields[i], &add[i]); pcmk__trace("Got %d for add[%s]", add[i], vfields[i]); } } diff --git a/lib/common/remote.c b/lib/common/remote.c index a9ce088f3f1..a445c059ab2 100644 --- a/lib/common/remote.c +++ b/lib/common/remote.c @@ -202,11 +202,11 @@ remote_send_iovs(pcmk__remote_t *remote, struct iovec *iov, int iovs) for (int lpc = 0; (lpc < iovs) && (rc == pcmk_rc_ok); lpc++) { if (remote->tls_session) { - rc = send_tls(remote->tls_session, &(iov[lpc])); + rc = send_tls(remote->tls_session, &iov[lpc]); continue; } if (remote->tcp_socket >= 0) { - rc = send_plaintext(remote->tcp_socket, &(iov[lpc])); + rc = send_plaintext(remote->tcp_socket, &iov[lpc]); } else { rc = ESOCKTNOSUPPORT; } diff --git a/lib/common/rules.c b/lib/common/rules.c index 847a11b60ce..97c14070d57 100644 --- a/lib/common/rules.c +++ b/lib/common/rules.c @@ -184,19 +184,19 @@ pcmk__evaluate_date_spec(const xmlNode *date_spec, const crm_time_t *now) } // Year, month, day - pcmk__time_get_ymd(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), - &(ranges[5].value)); + pcmk__time_get_timeofday(now, &ranges[3].value, &ranges[4].value, + &ranges[5].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), - &(ranges[9].value)); + pcmk__time_get_ywd(now, &ranges[7].value, &ranges[8].value, + &ranges[9].value); for (int i = 0; i < PCMK__NELEM(ranges); ++i) { int rc = check_range(date_spec, parent_id, ranges[i].attr, diff --git a/lib/common/schemas.c b/lib/common/schemas.c index 7f2c4b6c8bd..5c2dc92c569 100644 --- a/lib/common/schemas.c +++ b/lib/common/schemas.c @@ -164,9 +164,11 @@ version_from_filename(const char *filename, pcmk__schema_version_t *version) } if (g_str_has_suffix(filename, ".rng")) { - return sscanf(filename, "pacemaker-%hhu.%hhu.rng", &(version->v[0]), &(version->v[1])) == 2; + return sscanf(filename, "pacemaker-%hhu.%hhu.rng", &version->v[0], + &version->v[1]) == 2; } else { - return sscanf(filename, "pacemaker-%hhu.%hhu", &(version->v[0]), &(version->v[1])) == 2; + return sscanf(filename, "pacemaker-%hhu.%hhu", &version->v[0], + &version->v[1]) == 2; } } @@ -389,7 +391,7 @@ load_transforms_from_dir(const char *dir) unsigned char order = 0; // Placeholder only if (sscanf(namelist[i]->d_name, "upgrade-%hhu.%hhu-%hhu.xsl", - &(version.v[0]), &(version.v[1]), &order) == 3) { + &version.v[0], &version.v[1], &order) == 3) { char *version_s = pcmk__assert_asprintf("%hhu.%hhu", version.v[0], version.v[1]); @@ -771,7 +773,7 @@ validate_with(xmlDoc *doc, pcmk__schema_t *schema, schema->validator); switch (schema->validator) { case pcmk__schema_validator_rng: - cache = (relaxng_ctx_cache_t **) &(schema->cache); + cache = (relaxng_ctx_cache_t **) &schema->cache; valid = validate_with_relaxng(doc, error_handler, error_handler_context, file, cache); break; diff --git a/lib/common/xml_element.c b/lib/common/xml_element.c index 8782d79dbfc..bc6a349b1e4 100644 --- a/lib/common/xml_element.c +++ b/lib/common/xml_element.c @@ -1583,7 +1583,7 @@ pcmk__xe_get_timeval(const xmlNode *xml, const char *sec_attr, // No bounds checking; see comment in pcmk__xe_get_time() // Parse seconds - rc = pcmk__xe_get_time(xml, sec_attr, &(result.tv_sec)); + rc = pcmk__xe_get_time(xml, sec_attr, &result.tv_sec); if (rc != pcmk_rc_ok) { return rc; } diff --git a/lib/fencing/st_actions.c b/lib/fencing/st_actions.c index a4273919951..7f4cb6e17fe 100644 --- a/lib/fencing/st_actions.c +++ b/lib/fencing/st_actions.c @@ -65,8 +65,8 @@ static void log_action(stonith_action_t *action, pid_t pid); static void set_result_from_svc_action(stonith_action_t *action, svc_action_t *svc_action) { - services__copy_result(svc_action, &(action->result)); - pcmk__set_result_output(&(action->result), + services__copy_result(svc_action, &action->result); + pcmk__set_result_output(&action->result, services__grab_stdout(svc_action), services__grab_stderr(svc_action)); } @@ -212,7 +212,7 @@ stonith__destroy_action(stonith_action_t *action) free(action->action); g_clear_pointer(&action->args, g_hash_table_destroy); g_clear_pointer(&action->svc_action, services_action_free); - pcmk__reset_result(&(action->result)); + pcmk__reset_result(&action->result); free(action); } } @@ -228,7 +228,7 @@ stonith__destroy_action(stonith_action_t *action) pcmk__action_result_t * stonith__action_result(stonith_action_t *action) { - return (action == NULL)? NULL : &(action->result); + return (action == NULL)? NULL : &action->result; } #define FAILURE_MAX_RETRIES 2 @@ -265,7 +265,7 @@ stonith__action_create(const char *agent, const char *action_name, action->timeout = action->remaining_timeout = timeout_sec; action->max_retries = FAILURE_MAX_RETRIES; - pcmk__set_result(&(action->result), PCMK_OCF_UNKNOWN, PCMK_EXEC_UNKNOWN, + pcmk__set_result(&action->result, PCMK_OCF_UNKNOWN, PCMK_EXEC_UNKNOWN, "Initialization bug in fencing library"); if (device_args) { @@ -527,17 +527,15 @@ stonith_action_async_done(svc_action_t *svc_action) svc_action->params = NULL; log_action(action, action->pid); - if (!pcmk__result_ok(&(action->result)) - && update_remaining_timeout(action)) { + if (!pcmk__result_ok(&action->result) + && update_remaining_timeout(action) + && (internal_stonith_action_execute(action) == pcmk_ok)) { - int rc = internal_stonith_action_execute(action); - if (rc == pcmk_ok) { - return; - } + return; } if (action->done_cb) { - action->done_cb(action->pid, &(action->result), action->userdata); + action->done_cb(action->pid, &action->result, action->userdata); } action->svc_action = NULL; // don't remove our caller @@ -556,7 +554,7 @@ stonith_action_async_forked(svc_action_t *svc_action) (action->fork_cb) (svc_action->pid, action->userdata); } - pcmk__set_result(&(action->result), PCMK_OCF_UNKNOWN, PCMK_EXEC_PENDING, + pcmk__set_result(&action->result, PCMK_OCF_UNKNOWN, PCMK_EXEC_PENDING, NULL); pcmk__trace("Child process %d performing action '%s' successfully forked", @@ -616,7 +614,7 @@ internal_stonith_action_execute(stonith_action_t * action) if ((action->action == NULL) || (action->args == NULL) || (action->agent == NULL)) { - pcmk__set_result(&(action->result), PCMK_OCF_UNKNOWN_ERROR, + pcmk__set_result(&action->result, PCMK_OCF_UNKNOWN_ERROR, PCMK_EXEC_ERROR_FATAL, "Bug in fencing library"); return -EINVAL; } @@ -641,7 +639,7 @@ internal_stonith_action_execute(stonith_action_t * action) /* keep retries from executing out of control and free previous results */ if (is_retry) { - pcmk__reset_result(&(action->result)); + pcmk__reset_result(&action->result); // @TODO This should be nonblocking via timer if mainloop is used sleep(1); } diff --git a/lib/lrmd/lrmd_client.c b/lib/lrmd/lrmd_client.c index ecaac78903a..65b23df8edd 100644 --- a/lib/lrmd/lrmd_client.c +++ b/lib/lrmd/lrmd_client.c @@ -1272,7 +1272,7 @@ lrmd_tls_connect(lrmd_t * lrmd, int *fd) native->sock = -1; rc = pcmk__connect_remote(native->server, native->port, 0, NULL, - &(native->sock), NULL, NULL); + &native->sock, NULL, NULL); if (rc != pcmk_rc_ok) { pcmk__warn("Pacemaker Remote connection to %s:%d failed: %s " QB_XS " rc=%d", @@ -1546,7 +1546,7 @@ lrmd_tls_connect_async(lrmd_t *lrmd, int timeout) native->sock = -1; rc = pcmk__connect_remote(native->server, native->port, timeout, &timer_id, - &(native->sock), lrmd, lrmd_tcp_connect_cb); + &native->sock, lrmd, lrmd_tcp_connect_cb); if (rc != pcmk_rc_ok) { pcmk__warn("Pacemaker Remote connection to %s:%d failed: %s " QB_XS " rc=%d", diff --git a/lib/pacemaker/pcmk_graph_consumer.c b/lib/pacemaker/pcmk_graph_consumer.c index 079ea9c64bc..69eb7652fe0 100644 --- a/lib/pacemaker/pcmk_graph_consumer.c +++ b/lib/pacemaker/pcmk_graph_consumer.c @@ -575,7 +575,7 @@ unpack_action(pcmk__graph_synapse_t *parent, xmlNode *xml_action) return NULL; } - pcmk__scan_min_int(value, &(action->id), -1); + pcmk__scan_min_int(value, &action->id, -1); action->type = pcmk__rsc_graph_action; action->xml = pcmk__xml_copy(NULL, xml_action); action->synapse = parent; @@ -583,7 +583,7 @@ unpack_action(pcmk__graph_synapse_t *parent, xmlNode *xml_action) action->params = xml2list(action->xml); value = crm_meta_value(action->params, PCMK_META_TIMEOUT); - pcmk__scan_min_int(value, &(action->timeout), 0); + pcmk__scan_min_int(value, &action->timeout, 0); /* Take PCMK_META_START_DELAY into account for the timeout of the action * timer @@ -597,7 +597,7 @@ unpack_action(pcmk__graph_synapse_t *parent, xmlNode *xml_action) } if (pcmk__uint_from_hash(action->params, CRM_META "_" PCMK_META_INTERVAL, - 0, &(action->interval_ms)) != pcmk_rc_ok) { + 0, &action->interval_ms) != pcmk_rc_ok) { action->interval_ms = 0; } @@ -629,10 +629,10 @@ unpack_synapse(pcmk__graph_t *new_graph, const xmlNode *xml_synapse) return NULL; } - pcmk__scan_min_int(pcmk__xe_id(xml_synapse), &(new_synapse->id), 0); + pcmk__scan_min_int(pcmk__xe_id(xml_synapse), &new_synapse->id, 0); value = pcmk__xe_get(xml_synapse, PCMK__XA_PRIORITY); - pcmk__scan_min_int(value, &(new_synapse->priority), 0); + pcmk__scan_min_int(value, &new_synapse->priority, 0); CRM_CHECK(new_synapse->id >= 0, free_graph_synapse((void *) new_synapse); return NULL); @@ -749,37 +749,37 @@ pcmk__unpack_graph(const xmlNode *xml_graph, const char *reference) CRM_CHECK(buf != NULL, pcmk__free_graph(new_graph); return NULL); - pcmk__scan_min_int(buf, &(new_graph->id), 1); + pcmk__scan_min_int(buf, &new_graph->id, 1); buf = pcmk__xe_get(xml_graph, PCMK_OPT_CLUSTER_DELAY); CRM_CHECK(buf != NULL, pcmk__free_graph(new_graph); return NULL); - pcmk_parse_interval_spec(buf, &(new_graph->network_delay)); + pcmk_parse_interval_spec(buf, &new_graph->network_delay); buf = pcmk__xe_get(xml_graph, PCMK_OPT_FENCING_TIMEOUT); if (buf == NULL) { new_graph->fencing_timeout = new_graph->network_delay; } else { - pcmk_parse_interval_spec(buf, &(new_graph->fencing_timeout)); + pcmk_parse_interval_spec(buf, &new_graph->fencing_timeout); } // Use 0 (dynamic limit) as default/invalid, -1 (no limit) as minimum buf = pcmk__xe_get(xml_graph, PCMK_OPT_BATCH_LIMIT); if ((buf == NULL) - || (pcmk__scan_min_int(buf, &(new_graph->batch_limit), + || (pcmk__scan_min_int(buf, &new_graph->batch_limit, -1) != pcmk_rc_ok)) { new_graph->batch_limit = 0; } buf = pcmk__xe_get(xml_graph, PCMK_OPT_MIGRATION_LIMIT); - pcmk__scan_min_int(buf, &(new_graph->migration_limit), -1); + pcmk__scan_min_int(buf, &new_graph->migration_limit, -1); new_graph->failed_stop_offset = pcmk__xe_get_copy(xml_graph, PCMK__XA_FAILED_STOP_OFFSET); new_graph->failed_start_offset = pcmk__xe_get_copy(xml_graph, PCMK__XA_FAILED_START_OFFSET); - pcmk__xe_get_time(xml_graph, "recheck-by", &(new_graph->recheck_by)); + pcmk__xe_get_time(xml_graph, "recheck-by", &new_graph->recheck_by); } // Unpack each child element diff --git a/lib/pacemaker/pcmk_sched_colocation.c b/lib/pacemaker/pcmk_sched_colocation.c index f4a85eea2e9..1892f37b616 100644 --- a/lib/pacemaker/pcmk_sched_colocation.c +++ b/lib/pacemaker/pcmk_sched_colocation.c @@ -421,9 +421,9 @@ pcmk__new_colocation(const char *id, const char *node_attr, int score, new_con->node_attribute = pcmk__s(node_attr, CRM_ATTR_UNAME); new_con->flags = flags; - pcmk__add_this_with(&(dependent->priv->this_with_colocations), new_con, + pcmk__add_this_with(&dependent->priv->this_with_colocations, new_con, dependent); - pcmk__add_with_this(&(primary->priv->with_this_colocations), new_con, + pcmk__add_with_this(&primary->priv->with_this_colocations, new_con, primary); dependent->priv->scheduler->priv->colocation_constraints = @@ -1930,10 +1930,10 @@ pcmk__add_dependent_scores(void *data, void *user_data) "%s: Incorporating attenuated %s assignment scores due " "to colocation %s", primary->id, dependent->id, colocation->id); - dependent->priv->cmds->add_colocated_node_scores(dependent, primary, - dependent->id, - &(primary->priv->allowed_nodes), - colocation, factor, flags); + dependent->priv->cmds->add_colocated_node_scores( + dependent, primary, dependent->id, &primary->priv->allowed_nodes, + colocation, factor, flags + ); } /*! diff --git a/lib/pacemaker/pcmk_sched_promotable.c b/lib/pacemaker/pcmk_sched_promotable.c index d3fa33d7214..8c06d953ab3 100644 --- a/lib/pacemaker/pcmk_sched_promotable.c +++ b/lib/pacemaker/pcmk_sched_promotable.c @@ -380,10 +380,10 @@ apply_coloc_to_primary(void *data, void *user_data) colocation->id, colocation->dependent->id, colocation->primary->id, pcmk_readable_score(colocation->score)); - dependent->priv->cmds->add_colocated_node_scores(dependent, clone, - clone->id, - &(clone->priv->allowed_nodes), - colocation, factor, flags); + dependent->priv->cmds->add_colocated_node_scores( + dependent, clone, clone->id, &clone->priv->allowed_nodes, colocation, + factor, flags + ); } /*! diff --git a/lib/pacemaker/pcmk_sched_recurring.c b/lib/pacemaker/pcmk_sched_recurring.c index 956b0cdfe0c..327a040a154 100644 --- a/lib/pacemaker/pcmk_sched_recurring.c +++ b/lib/pacemaker/pcmk_sched_recurring.c @@ -669,8 +669,8 @@ pcmk__new_cancel_action(pcmk_resource_t *rsc, const char *task, cancel_op = custom_action(rsc, key, PCMK_ACTION_CANCEL, node, FALSE, rsc->priv->scheduler); - pcmk__str_update(&(cancel_op->task), PCMK_ACTION_CANCEL); - pcmk__str_update(&(cancel_op->cancel_task), task); + pcmk__str_update(&cancel_op->task, PCMK_ACTION_CANCEL); + pcmk__str_update(&cancel_op->cancel_task, task); interval_ms_s = pcmk__assert_asprintf("%u", interval_ms); pcmk__insert_meta(cancel_op, PCMK_XA_OPERATION, task); diff --git a/lib/pacemaker/pcmk_scheduler.c b/lib/pacemaker/pcmk_scheduler.c index c9cfb345faa..191a4fe2989 100644 --- a/lib/pacemaker/pcmk_scheduler.c +++ b/lib/pacemaker/pcmk_scheduler.c @@ -823,7 +823,7 @@ pcmk__init_scheduler(pcmk__output_t *out, xmlNodePtr input, const crm_time_t *da } } else { - int rc = cib__signon_query(out, NULL, &(new_scheduler->input)); + int rc = cib__signon_query(out, NULL, &new_scheduler->input); if (rc != pcmk_rc_ok) { pcmk_free_scheduler(new_scheduler); diff --git a/lib/pacemaker/pcmk_status.c b/lib/pacemaker/pcmk_status.c index aab4e9fe4d5..49f897b3498 100644 --- a/lib/pacemaker/pcmk_status.c +++ b/lib/pacemaker/pcmk_status.c @@ -275,7 +275,7 @@ pcmk__status(pcmk__output_t *out, cib_t *cib, if ((cib->variant == cib_native) && pcmk__is_set(show, pcmk_section_times)) { // Currently used only in the times section - pcmk__query_node_name(out, 0, &(scheduler->priv->local_node_name), 0); + pcmk__query_node_name(out, 0, &scheduler->priv->local_node_name, 0); } rc = pcmk__output_cluster_status(scheduler, stonith, cib, current_cib, diff --git a/lib/pengine/complex.c b/lib/pengine/complex.c index 9235facaa63..e2ce92c405c 100644 --- a/lib/pengine/complex.c +++ b/lib/pengine/complex.c @@ -609,7 +609,7 @@ unpack_priority(pcmk_resource_t *rsc) { const char *value = g_hash_table_lookup(rsc->priv->meta, PCMK_META_PRIORITY); - int rc = pcmk_parse_score(value, &(rsc->priv->priority), 0); + int rc = pcmk_parse_score(value, &rsc->priv->priority, 0); if (rc != pcmk_rc_ok) { pcmk__config_warn("Using default (0) for resource %s " @@ -639,7 +639,7 @@ unpack_stickiness(pcmk_resource_t *rsc) "' is deprecated and will be removed in a " "future release (just leave it unset)"); } else { - int rc = pcmk_parse_score(value, &(rsc->priv->stickiness), 0); + int rc = pcmk_parse_score(value, &rsc->priv->stickiness, 0); if (rc != pcmk_rc_ok) { pcmk__config_warn("Using default (0) for resource %s " @@ -671,7 +671,7 @@ unpack_migration_threshold(pcmk_resource_t *rsc) "future release (just leave it unset)"); rsc->priv->ban_after_failures = PCMK_SCORE_INFINITY; } else { - int rc = pcmk_parse_score(value, &(rsc->priv->ban_after_failures), + int rc = pcmk_parse_score(value, &rsc->priv->ban_after_failures, PCMK_SCORE_INFINITY); if ((rc != pcmk_rc_ok) || (rsc->priv->ban_after_failures < 0)) { @@ -910,7 +910,7 @@ pe__unpack_resource(xmlNode *xml_obj, pcmk_resource_t **rsc, value = g_hash_table_lookup(rsc_private->meta, PCMK_META_FAILURE_TIMEOUT); if (value != NULL) { - pcmk_parse_interval_spec(value, &(rsc_private->failure_expiration_ms)); + pcmk_parse_interval_spec(value, &rsc_private->failure_expiration_ms); } if (remote_node) { @@ -926,8 +926,7 @@ pe__unpack_resource(xmlNode *xml_obj, pcmk_resource_t **rsc, if (value) { /* reconnect delay works by setting failure_timeout and preventing the * connection from starting until the failure is cleared. */ - pcmk_parse_interval_spec(value, - &(rsc_private->remote_reconnect_ms)); + pcmk_parse_interval_spec(value, &rsc_private->remote_reconnect_ms); /* We want to override any default failure_timeout in use when remote * PCMK_REMOTE_RA_RECONNECT_INTERVAL is in use. @@ -937,7 +936,7 @@ pe__unpack_resource(xmlNode *xml_obj, pcmk_resource_t **rsc, } } - get_target_role(*rsc, &(rsc_private->next_role)); + get_target_role(*rsc, &rsc_private->next_role); pcmk__rsc_trace(*rsc, "%s desired next state: %s", (*rsc)->id, (rsc_private->next_role == pcmk_role_unknown)? "default" : pcmk_role_text(rsc_private->next_role)); diff --git a/lib/pengine/failcounts.c b/lib/pengine/failcounts.c index 0036f833898..780aae1b357 100644 --- a/lib/pengine/failcounts.c +++ b/lib/pengine/failcounts.c @@ -306,7 +306,7 @@ update_failcount_for_attr(void *key, void *value, void *user_data) struct failcount_data *fc_data = user_data; // If this is a matching fail count attribute, update fail count - if (regexec(&(fc_data->failcount_re), (const char *) key, 0, NULL, 0) == 0) { + if (regexec(&fc_data->failcount_re, (const char *) key, 0, NULL, 0) == 0) { int score = 0; int rc = pcmk_parse_score(value, &score, 0); @@ -326,7 +326,7 @@ update_failcount_for_attr(void *key, void *value, void *user_data) } // If this is a matching last failure attribute, update last failure - if (regexec(&(fc_data->lastfailure_re), (const char *) key, 0, NULL, + if (regexec(&fc_data->lastfailure_re, (const char *) key, 0, NULL, 0) == 0) { long long last_ll; int rc = pcmk__scan_ll(value, &last_ll, 0LL); @@ -399,8 +399,8 @@ pe_get_failcount(const pcmk_node_t *node, pcmk_resource_t *rsc, return 0); g_hash_table_foreach(node->priv->attrs, update_failcount_for_attr, &fc_data); - regfree(&(fc_data.failcount_re)); - regfree(&(fc_data.lastfailure_re)); + regfree(&fc_data.failcount_re); + regfree(&fc_data.lastfailure_re); // If failure blocks the resource, disregard any failure timeout if ((fc_data.failcount > 0) && (rsc->priv->failure_expiration_ms > 0) diff --git a/lib/pengine/pe_output.c b/lib/pengine/pe_output.c index 86135a40582..fe427e3e54d 100644 --- a/lib/pengine/pe_output.c +++ b/lib/pengine/pe_output.c @@ -3353,7 +3353,7 @@ ticket_default(pcmk__output_t *out, va_list args) { * crm_ticket or we were given details=true as an argument. */ if (detail_str == NULL) { - char *epoch_str = pcmk__epoch2str(&(ticket->last_granted), 0); + char *epoch_str = pcmk__epoch2str(&ticket->last_granted, 0); out->list_item(out, NULL, "%s\t%s%s last-granted=\"%s\"", ticket->id, ticket_status(ticket), diff --git a/lib/pengine/rules_compat.c b/lib/pengine/rules_compat.c index 43fce159391..434f78c1dde 100644 --- a/lib/pengine/rules_compat.c +++ b/lib/pengine/rules_compat.c @@ -96,7 +96,7 @@ pe_eval_nvpairs(xmlNode *top, const xmlNode *xml_obj, const char *set_name, } data.doc = xml_obj->doc; - map_rule_input(&(data.rule_input), rule_data); + map_rule_input(&data.rule_input, rule_data); pairs = g_list_sort_with_data(pairs, pcmk__cmp_nvpair_blocks, &data); g_list_foreach(pairs, pcmk__unpack_nvpair_block, &data); diff --git a/lib/pengine/unpack.c b/lib/pengine/unpack.c index 4ff84c0e634..41558371cda 100644 --- a/lib/pengine/unpack.c +++ b/lib/pengine/unpack.c @@ -278,7 +278,7 @@ unpack_config(xmlNode *config, pcmk_scheduler_t *scheduler) scheduler); value = pcmk__cluster_option(config_hash, PCMK_OPT_FENCING_TIMEOUT); - pcmk_parse_interval_spec(value, &(scheduler->priv->fence_timeout_ms)); + pcmk_parse_interval_spec(value, &scheduler->priv->fence_timeout_ms); pcmk__debug("Default fencing action timeout: %s", pcmk__readable_interval(scheduler->priv->fence_timeout_ms)); @@ -309,7 +309,7 @@ unpack_config(xmlNode *config, pcmk_scheduler_t *scheduler) value = pcmk__cluster_option(config_hash, PCMK_OPT_PRIORITY_FENCING_DELAY); if (value) { - unsigned int *delay_ms = &(scheduler->priv->priority_fencing_ms); + unsigned int *delay_ms = &scheduler->priv->priority_fencing_ms; pcmk_parse_interval_spec(value, delay_ms); pcmk__trace("Priority fencing delay is %s", @@ -442,7 +442,7 @@ unpack_config(xmlNode *config, pcmk_scheduler_t *scheduler) pcmk__sched_shutdown_lock); if (pcmk__is_set(scheduler->flags, pcmk__sched_shutdown_lock)) { value = pcmk__cluster_option(config_hash, PCMK_OPT_SHUTDOWN_LOCK_LIMIT); - pcmk_parse_interval_spec(value, &(scheduler->priv->shutdown_lock_ms)); + pcmk_parse_interval_spec(value, &scheduler->priv->shutdown_lock_ms); pcmk__trace("Resources will be locked to nodes that were cleanly " "shut down (locks expire after %s)", pcmk__readable_interval(scheduler->priv->shutdown_lock_ms)); @@ -452,7 +452,7 @@ unpack_config(xmlNode *config, pcmk_scheduler_t *scheduler) } value = pcmk__cluster_option(config_hash, PCMK_OPT_NODE_PENDING_TIMEOUT); - pcmk_parse_interval_spec(value, &(scheduler->priv->node_pending_ms)); + pcmk_parse_interval_spec(value, &scheduler->priv->node_pending_ms); if (scheduler->priv->node_pending_ms == 0U) { pcmk__trace("Do not fence pending nodes"); } else { @@ -2332,7 +2332,7 @@ unpack_find_resource(pcmk_scheduler_t *scheduler, const pcmk_node_t *node, const bool removed = pcmk__is_set(rsc->flags, pcmk__rsc_removed); - pcmk__str_update(&(rsc->priv->history_id), rsc_id); + pcmk__str_update(&rsc->priv->history_id, rsc_id); pcmk__rsc_debug(rsc, "Internally renamed %s on %s to %s%s", rsc_id, pcmk__node_name(node), rsc->id, (removed? " (removed)" : "")); @@ -4526,7 +4526,7 @@ static int unpack_action_result(struct action_history *history) { if ((pcmk__xe_get_int(history->xml, PCMK__XA_OP_STATUS, - &(history->execution_status)) != pcmk_rc_ok) + &history->execution_status) != pcmk_rc_ok) || (history->execution_status < PCMK_EXEC_PENDING) || (history->execution_status > PCMK_EXEC_MAX) || (history->execution_status == PCMK_EXEC_CANCELLED)) { @@ -4539,7 +4539,7 @@ unpack_action_result(struct action_history *history) return pcmk_rc_unpack_error; } if ((pcmk__xe_get_int(history->xml, PCMK__XA_RC_CODE, - &(history->exit_status)) != pcmk_rc_ok) + &history->exit_status) != pcmk_rc_ok) || (history->exit_status < 0) || (history->exit_status > CRM_EX_MAX)) { pcmk__config_err("Ignoring resource history entry %s for %s on %s " "with invalid " PCMK__XA_RC_CODE " '%s'", @@ -4799,7 +4799,7 @@ unpack_rsc_op(pcmk_resource_t *rsc, pcmk_node_t *node, xmlNode *xml_op, history.id, rsc->id, pcmk__node_name(node)); return; } - pcmk__xe_get_uint(xml_op, PCMK_META_INTERVAL, &(history.interval_ms)); + pcmk__xe_get_uint(xml_op, PCMK_META_INTERVAL, &history.interval_ms); if (!can_affect_state(&history)) { pcmk__rsc_trace(rsc, "Ignoring resource history entry %s for %s on %s " @@ -4815,7 +4815,7 @@ unpack_rsc_op(pcmk_resource_t *rsc, pcmk_node_t *node, xmlNode *xml_op, history.expected_exit_status = pe__target_rc_from_xml(xml_op); history.key = pcmk__xe_history_key(xml_op); - pcmk__xe_get_int(xml_op, PCMK__XA_CALL_ID, &(history.call_id)); + pcmk__xe_get_int(xml_op, PCMK__XA_CALL_ID, &history.call_id); pcmk__rsc_trace(rsc, "Unpacking %s (%s call %d on %s): %s (%s)", history.id, history.task, history.call_id, diff --git a/lib/services/services.c b/lib/services/services.c index 81bfd15f405..177830d6078 100644 --- a/lib/services/services.c +++ b/lib/services/services.c @@ -443,7 +443,7 @@ services_action_user(svc_action_t *op, const char *user) CRM_CHECK((op != NULL) && (user != NULL), return -EINVAL); - rc = pcmk__lookup_user(user, &(op->opaque->uid), &(op->opaque->gid)); + rc = pcmk__lookup_user(user, &op->opaque->uid, &op->opaque->gid); return pcmk_rc2legacy(rc); } diff --git a/lib/services/services_linux.c b/lib/services/services_linux.c index d09ea571d41..1a4c1fb10d8 100644 --- a/lib/services/services_linux.c +++ b/lib/services/services_linux.c @@ -57,13 +57,13 @@ struct sigchld_data_s { static bool sigchld_setup(struct sigchld_data_s *data) { - sigemptyset(&(data->mask)); - sigaddset(&(data->mask), SIGCHLD); + sigemptyset(&data->mask); + sigaddset(&data->mask, SIGCHLD); - sigemptyset(&(data->old_mask)); + sigemptyset(&data->old_mask); // Block SIGCHLD (saving previous set of blocked signals to restore later) - if (sigprocmask(SIG_BLOCK, &(data->mask), &(data->old_mask)) < 0) { + if (sigprocmask(SIG_BLOCK, &data->mask, &data->old_mask) < 0) { pcmk__info("Wait for child process completion failed: %s " QB_XS " source=sigprocmask", pcmk_rc_str(errno)); @@ -83,7 +83,7 @@ sigchld_open(struct sigchld_data_s *data) CRM_CHECK(data != NULL, return -1); - fd = signalfd(-1, &(data->mask), SFD_NONBLOCK); + fd = signalfd(-1, &data->mask, SFD_NONBLOCK); if (fd < 0) { pcmk__info("Wait for child process completion failed: %s " QB_XS " source=signalfd", @@ -139,8 +139,8 @@ static void sigchld_cleanup(struct sigchld_data_s *data) { // Restore the original set of blocked signals - if ((sigismember(&(data->old_mask), SIGCHLD) == 0) - && (sigprocmask(SIG_UNBLOCK, &(data->mask), NULL) < 0)) { + if ((sigismember(&data->old_mask, SIGCHLD) == 0) + && (sigprocmask(SIG_UNBLOCK, &data->mask, NULL) < 0)) { pcmk__warn("Could not clean up after child process completion: %s", pcmk_rc_str(errno)); } @@ -207,8 +207,8 @@ sigchld_setup(struct sigchld_data_s *data) // Set SIGCHLD handler data->sa.sa_handler = (sighandler_t) sigchld_handler; data->sa.sa_flags = 0; - sigemptyset(&(data->sa.sa_mask)); - if (sigaction(SIGCHLD, &(data->sa), &(data->old_sa)) < 0) { + sigemptyset(&data->sa.sa_mask); + if (sigaction(SIGCHLD, &data->sa, &data->old_sa) < 0) { pcmk__info("Wait for child process completion failed: %s " QB_XS " source=sigaction", pcmk_rc_str(errno)); @@ -252,7 +252,7 @@ static void sigchld_cleanup(struct sigchld_data_s *data) { // Restore the previous SIGCHLD handler - if (sigaction(SIGCHLD, &(data->old_sa), NULL) < 0) { + if (sigaction(SIGCHLD, &data->old_sa, NULL) < 0) { pcmk__warn("Could not clean up after child process completion: %s", pcmk_rc_str(errno)); } @@ -631,10 +631,10 @@ finish_op_output(svc_action_t *op, bool is_stderr) int fd; if (is_stderr) { - source = &(op->opaque->stderr_gsource); + source = &op->opaque->stderr_gsource; fd = op->opaque->stderr_fd; } else { - source = &(op->opaque->stdout_gsource); + source = &op->opaque->stdout_gsource; fd = op->opaque->stdout_fd; } diff --git a/lib/services/services_ocf.c b/lib/services/services_ocf.c index 85f7be9b279..fb4d4e90b09 100644 --- a/lib/services/services_ocf.c +++ b/lib/services/services_ocf.c @@ -1,5 +1,5 @@ /* - * Copyright 2012-2025 the Pacemaker project contributors + * Copyright 2012-2026 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -171,7 +171,7 @@ int services__ocf_prepare(svc_action_t *op) { if (!services__ocf_agent_exists(op->provider, op->agent, - &(op->opaque->exec))) { + &op->opaque->exec)) { return ENOENT; } diff --git a/lib/services/systemd.c b/lib/services/systemd.c index bf2d51db42e..01eeb31aad9 100644 --- a/lib/services/systemd.c +++ b/lib/services/systemd.c @@ -859,7 +859,7 @@ process_unit_method_reply(DBusMessage *reply, svc_action_t *op) if (!op->synchronous && start_stop) { // Should be set to unknown/pending already services__set_result(op, PCMK_OCF_UNKNOWN, PCMK_EXEC_PENDING, NULL); - pcmk__str_update(&(op->opaque->job_path), path); + pcmk__str_update(&op->opaque->job_path, path); } else { services__set_result(op, PCMK_OCF_OK, PCMK_EXEC_DONE, NULL); diff --git a/tools/cibsecret.c b/tools/cibsecret.c index 2a6dc783fdf..473c3563423 100644 --- a/tools/cibsecret.c +++ b/tools/cibsecret.c @@ -363,7 +363,7 @@ get_live_peers(pcmk__output_t *out) /* Get the local node name if possible. */ if (cib->variant != cib_file) { - rc = pcmk__query_node_name(out, 0, &(nd.local_node), 0); + rc = pcmk__query_node_name(out, 0, &nd.local_node, 0); if (rc != pcmk_rc_ok) { out->err(out, "Could not get local node name"); goto done; diff --git a/tools/crm_attribute.c b/tools/crm_attribute.c index 3c9b702c081..41730972e5a 100644 --- a/tools/crm_attribute.c +++ b/tools/crm_attribute.c @@ -707,12 +707,12 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { GOptionContext *context = NULL; GOptionEntry extra_prog_entries[] = { - { "quiet", 'q', 0, G_OPTION_ARG_NONE, &(args->quiet), + { "quiet", 'q', 0, G_OPTION_ARG_NONE, &args->quiet, "Print only the value on stdout", NULL }, // NOTE: resource-agents <4.2.0 (2018-10-24) uses -Q - { "quiet", 'Q', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &(args->quiet), + { "quiet", 'Q', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &args->quiet, NULL, NULL }, diff --git a/tools/crm_mon.c b/tools/crm_mon.c index e63c04df3e5..c45a4dfe2a4 100644 --- a/tools/crm_mon.c +++ b/tools/crm_mon.c @@ -1236,7 +1236,7 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { GOptionContext *context = NULL; GOptionEntry extra_prog_entries[] = { - { "quiet", 'Q', 0, G_OPTION_ARG_NONE, &(args->quiet), + { "quiet", 'Q', 0, G_OPTION_ARG_NONE, &args->quiet, "Be less descriptive in output.", NULL }, @@ -1656,7 +1656,7 @@ main(int argc, char **argv) && pcmk__is_set(show, pcmk_section_times)) { // Currently used only in the times section - pcmk__query_node_name(out, 0, &(scheduler->priv->local_node_name), 0); + pcmk__query_node_name(out, 0, &scheduler->priv->local_node_name, 0); } out->message(out, "crm-mon-disconnected", diff --git a/tools/crm_node.c b/tools/crm_node.c index 0d4cb92968a..497ee90eae8 100644 --- a/tools/crm_node.c +++ b/tools/crm_node.c @@ -130,7 +130,7 @@ gboolean name_cb(const char *option_name, const char *optarg, void *data, GError **error) { options.command = 'N'; - pcmk__scan_min_int(optarg, &(options.nodeid), 0); + pcmk__scan_min_int(optarg, &options.nodeid, 0); return TRUE; } @@ -764,7 +764,7 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { GOptionContext *context = NULL; GOptionEntry extra_prog_entries[] = { - { "quiet", 'Q', 0, G_OPTION_ARG_NONE, &(args->quiet), + { "quiet", 'Q', 0, G_OPTION_ARG_NONE, &args->quiet, "Be less descriptive in output.", NULL }, diff --git a/tools/crm_resource.c b/tools/crm_resource.c index c8cd7d474c4..b781fec3247 100644 --- a/tools/crm_resource.c +++ b/tools/crm_resource.c @@ -1980,7 +1980,7 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { GOptionContext *context = NULL; GOptionEntry extra_prog_entries[] = { - { "quiet", 'Q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &(args->quiet), + { "quiet", 'Q', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &args->quiet, "Be less descriptive in output.", NULL }, { "resource", 'r', G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &options.rsc_id, diff --git a/tools/crm_simulate.c b/tools/crm_simulate.c index 5c43d535173..f57af68831b 100644 --- a/tools/crm_simulate.c +++ b/tools/crm_simulate.c @@ -475,7 +475,7 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { GOptionContext *context = NULL; GOptionEntry extra_prog_entries[] = { - { "quiet", 'Q', 0, G_OPTION_ARG_NONE, &(args->quiet), + { "quiet", 'Q', 0, G_OPTION_ARG_NONE, &args->quiet, "Display only essential output", NULL }, diff --git a/tools/crm_verify.c b/tools/crm_verify.c index b11e67f4392..7828b7ec178 100644 --- a/tools/crm_verify.c +++ b/tools/crm_verify.c @@ -91,7 +91,7 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { "\tcrm_verify --xml-file file.xml --verbose\n\n"; GOptionEntry extra_prog_entries[] = { - { "quiet", 'q', 0, G_OPTION_ARG_NONE, &(args->quiet), + { "quiet", 'q', 0, G_OPTION_ARG_NONE, &args->quiet, "Don't print verify information", NULL }, { NULL } diff --git a/tools/crmadmin.c b/tools/crmadmin.c index b1040a29230..ff1e5802644 100644 --- a/tools/crmadmin.c +++ b/tools/crmadmin.c @@ -145,7 +145,7 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { GOptionContext *context = NULL; GOptionEntry extra_prog_entries[] = { - { "quiet", 'q', 0, G_OPTION_ARG_NONE, &(args->quiet), + { "quiet", 'q', 0, G_OPTION_ARG_NONE, &args->quiet, "Display only the essential query information", NULL }, diff --git a/tools/stonith_admin.c b/tools/stonith_admin.c index d4a60ad00eb..ef8face6f3d 100644 --- a/tools/stonith_admin.c +++ b/tools/stonith_admin.c @@ -338,7 +338,7 @@ build_arg_context(pcmk__common_args_t *args, GOptionGroup **group) { GOptionContext *context = NULL; GOptionEntry extra_prog_entries[] = { - { "quiet", 'q', 0, G_OPTION_ARG_NONE, &(args->quiet), + { "quiet", 'q', 0, G_OPTION_ARG_NONE, &args->quiet, "Be less descriptive in output.", NULL }, From d54bf5d1fbf703f0a873875df9e7d21e80d89334 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Tue, 7 Jul 2026 16:50:09 -0700 Subject: [PATCH 44/48] Refactor: libcrmcommon: Best practices in pcmk__time_compare() Make it more similar to pcmk__compare_versions(), pcmk__compare_node_capacities(), etc. Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 104 +++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 29 deletions(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 69e9fd3a4cb..b9fdb97edf8 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -1623,45 +1623,91 @@ crm_time_subtract(const crm_time_t *dt, const crm_time_t *value) return subtract_time(dt, value, false); } -#define do_cmp_field(l, r, field) \ - if(rc == 0) { \ - if(l->field > r->field) { \ - pcmk__trace("%s: %d > %d", \ - #field, l->field, r->field); \ - rc = 1; \ - } else if(l->field < r->field) { \ - pcmk__trace("%s: %d < %d", \ - #field, l->field, r->field); \ - rc = -1; \ - } \ - } - +/*! + * \internal + * \brief Compare two time objects + * + * Two time objects are equal if they're both \c NULL or if their corresponding + * \c years, \c days, and \c seconds fields are all equal. + * + * If only one time object is \c NULL, then it is considered to be the earlier + * time. + * + * Comparisons are performed after converting both time objects to UTC. + * + * \param[in] time1 First time object to compare + * \param[in] time2 Second time object to compare + * + * \retval -1 if \p time1 is earlier than \p time2 + * \retval 1 if \p time1 is later than \p time2 + * \retval 0 if \p time1 and \p time2 are equal + */ int -pcmk__time_compare(const crm_time_t *a, const crm_time_t *b) +pcmk__time_compare(const crm_time_t *time1, const crm_time_t *time2) { int rc = 0; - crm_time_t *t1 = NULL; - crm_time_t *t2 = NULL; + crm_time_t *utc1 = NULL; + crm_time_t *utc2 = NULL; - if ((a == NULL) && (b == NULL)) { - return 0; + if ((time1 == NULL) && (time2 == NULL)) { + goto done; } - if (a == NULL) { - return -1; + + if (time1 == NULL) { + rc = -1; + goto done; } - if (b == NULL) { - return 1; + + if (time2 == NULL) { + rc = 1; + goto done; } - t1 = copy_time_to_utc(a); - t2 = copy_time_to_utc(b); + utc1 = copy_time_to_utc(time1); + utc2 = copy_time_to_utc(time2); - do_cmp_field(t1, t2, years); - do_cmp_field(t1, t2, days); - do_cmp_field(t1, t2, seconds); + if (utc1->years < utc2->years) { + pcmk__trace("Years: %d < %d", utc1->years, utc2->years); + rc = -1; + goto done; + } - crm_time_free(t1); - crm_time_free(t2); + if (utc1->years > utc2->years) { + pcmk__trace("Years: %d > %d", utc1->years, utc2->years); + rc = 1; + goto done; + } + + if (utc1->days < utc2->days) { + pcmk__trace("Days: %d < %d", utc1->days, utc2->days); + rc = -1; + goto done; + } + + if (utc1->days > utc2->days) { + pcmk__trace("Days: %d > %d", utc1->days, utc2->days); + rc = 1; + goto done; + } + + if (utc1->seconds < utc2->seconds) { + pcmk__trace("Seconds: %d < %d", utc1->seconds, utc2->seconds); + rc = -1; + goto done; + } + + if (utc1->seconds > utc2->seconds) { + pcmk__trace("Seconds: %d > %d", utc1->seconds, utc2->seconds); + rc = 1; + goto done; + } + + pcmk__trace("Times equal: %d years, %d days, %d seconds", + utc1->years, utc1->days, utc1->seconds); + +done: + crm_time_free(utc1); + crm_time_free(utc2); return rc; } From 4bb339d93eb774c8b758f74f2f5d823912d56109 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Tue, 7 Jul 2026 17:05:19 -0700 Subject: [PATCH 45/48] Refactor: libcrmcommon: Best practices for pcmk__time_get_timeofday() Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index b9fdb97edf8..6cf06de0a0b 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -706,14 +706,25 @@ pcmk__time_log_as(const char *file, const char *function, int line, free(date_s); } +/*! + * \internal + * \brief Convert a time object's seconds field to hours, minutes, and seconds + * + * The resulting minutes and seconds are in the range [0, 59]. Accordingly, the + * number of hours is \p dt->seconds divided by \c SECONDS_IN_HOUR. See + * \c seconds_to_hms(). + * + * \param[in] dt Time object + * \param[out] hours Where to store hours + * \param[out] minutes Where to store minutes + * \param[out] seconds If not \c NULL, where to store seconds + */ void -pcmk__time_get_timeofday(const crm_time_t *dt, uint32_t *hour, - uint32_t *minute, uint32_t *second) +pcmk__time_get_timeofday(const crm_time_t *dt, uint32_t *hours, + uint32_t *minutes, uint32_t *seconds) { - pcmk__assert((dt != NULL) && (hour != NULL) && (minute != NULL) - && (second != NULL)); - - seconds_to_hms(dt->seconds, hour, minute, second); + pcmk__assert((dt != NULL) && (hours != NULL) && (minutes != NULL)); + seconds_to_hms(dt->seconds, hours, minutes, seconds); } // Time in seconds since 0000-01-01 00:00:00Z From 837832b331f500574e722443eff5cd5983f8c07e Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Sat, 11 Jul 2026 18:11:12 -0700 Subject: [PATCH 46/48] Refactor: libcrmcommon: Simplify duration case of pcmk__time_get_ymd() Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index 6cf06de0a0b..e99ef2064b7 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -799,12 +799,10 @@ pcmk__time_get_ymd(const crm_time_t *dt, uint32_t *year, uint32_t *month, } } - } else if (dt->months) { - /* This is a duration including months, don't convert the days field */ - months = dt->months; - } else { - /* This is a duration not including months, still don't convert the days field */ + // Don't convert the days field of a duration to months + CRM_LOG_ASSERT(dt->duration); + months = dt->months; } *year = dt->years; From 137c1c2e134859a9c7fa65aa32485711879d6ed4 Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Sat, 11 Jul 2026 22:29:43 -0700 Subject: [PATCH 47/48] Refactor: libcrmcommon: Set duration field in copy_time_to_utc() This avoids an assertion in a future commit I'm working on, and it seems like a good practice for sanity. Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index e99ef2064b7..bafbedb36a9 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -632,6 +632,12 @@ copy_time_to_utc(const crm_time_t *dt) utc->seconds = dt->seconds; utc->offset = 0; + /* It makes no sense to convert a duration to UTC, but at time of writing, + * there are places where we may do it (for example, via public API + * functions). + */ + utc->duration = dt->duration; + if (dt->offset != 0) { crm_time_add_seconds(utc, -dt->offset); From eb7ebf3846aa8314975ad1b0899ad5aa657033db Mon Sep 17 00:00:00 2001 From: Reid Wahl Date: Fri, 10 Jul 2026 01:39:40 -0700 Subject: [PATCH 48/48] Refactor: libcrmcommon: Unindent pcmk__time_get_ymd() and add Doxygen Also add a couple of FIXME comments for incorrect logic. Since public API functions call pcmk__time_get_ymd(), we'll need to preserve behavior for those functions. However, we can write a correct function body for internal use soon. Signed-off-by: Reid Wahl --- lib/common/iso8601.c | 58 +++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/lib/common/iso8601.c b/lib/common/iso8601.c index bafbedb36a9..1db7c49c950 100644 --- a/lib/common/iso8601.c +++ b/lib/common/iso8601.c @@ -784,36 +784,56 @@ crm_time_get_seconds_since_epoch(const crm_time_t *dt) return (dt == NULL)? 0 : (pcmk__time_get_seconds(dt) - EPOCH_SECONDS); } +/*! + * \internal + * \brief Convert a time object's years and seconds to year, month, and day + * + * \param[in] dt Time object + * \param[out] year Where to store year + * \param[out] month Where to store month + * \param[out] day Where to store day + * + * \note This has some incorrect behavior. See FIXME comments, and be mindful of + * public API when fixing these issues. + */ 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) && (year != NULL) && (month != NULL) && (day != NULL)); - if(dt->years != 0) { - for (months = 1; months <= 12 && days > 0; months++) { - int mdays = days_in_month_year(months, dt->years); - - if (mdays >= days) { - break; - } else { - days -= mdays; - } - } - - } else { - // Don't convert the days field of a duration to months + if (dt->years == 0) { + /* Assume this to be a duration and return the fields as they are. + * + * @FIXME This is a longstanding assumption. Nothing guarantees that + * this is actually a duration. However, it would be invalid as a date. + */ CRM_LOG_ASSERT(dt->duration); - months = dt->months; + + *year = dt->years; + *month = dt->months; + *day = dt->days; + return; } *year = dt->years; - *month = months; - *day = days; + *day = dt->days; + + /* @FIXME This could also be a duration. It's incorrect to convert days to + * months in that case. + * + * @FIXME This could end with *month set to 13. + */ + for (*month = 1; *month <= 12; (*month)++) { + int mdays = days_in_month_year(*month, dt->years); + + if (mdays >= *day) { + return; + } + + *day -= mdays; + } } void