Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Factory
rmw
tests-fail-after-epochalypse.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File tests-fail-after-epochalypse.patch of Package rmw
From 00a97170277744c63fd5fba8b17c4d4198749acc Mon Sep 17 00:00:00 2001 From: andy5995 <arch_stanton5995@protonmail.com> Date: Mon, 25 Mar 2024 12:46:40 -0500 Subject: [PATCH] tests: Fix failing after year 2038 For #439 --- ChangeLog | 4 ++++ src/purging_rmw.c | 56 ++++++++++++++++++++++++++--------------------- src/time_rmw.c | 11 +++++++++- test/meson.build | 23 +++++++++++++++++++ 4 files changed, 68 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2a68ab8e..5f416eaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ === rmw ChangeLog === +2024-03-26 + + * Fix for tests failing after the Epochalypse (#439) + 2024-03-18 * Release v0.9.2 diff --git a/src/purging_rmw.c b/src/purging_rmw.c index 25e5a9c5..86b04f46 100644 --- a/src/purging_rmw.c +++ b/src/purging_rmw.c @@ -42,49 +42,55 @@ bool is_time_to_purge(st_time *st_time_var, const char *file) { const int BUF_TIME = 80; + char time_prev[BUF_TIME]; + bool purge_needed = true; + // Open the file for reading FILE *fp = fopen(file, "r"); - bool init = (fp); if (fp) { - char time_prev[BUF_TIME]; + // Read the previous time from the file + if (fgets(time_prev, sizeof(time_prev), fp) != NULL) + { + trim_whitespace(time_prev); + long prev_time = atol(time_prev); + // fprintf(stderr, "%ld\n", prev_time); - if (fgets(time_prev, sizeof time_prev, fp) == NULL) + // Check if the difference is less than a day + purge_needed = + ((st_time_var->now - prev_time) < SECONDS_IN_A_DAY) ? false : true; + } + else { print_msg_error(); printf("while getting line from %s\n", file); perror(__func__); - close_file(&fp, file, __func__); - exit(EXIT_FAILURE); } - - trim_whitespace(time_prev); - close_file(&fp, file, __func__); - - if ((st_time_var->now - atoi(time_prev)) < SECONDS_IN_A_DAY) - return false; + fclose(fp); // Close the file after reading } + else if (errno == ENOENT) + purge_needed = false; + // Open the file for writing to update the time fp = fopen(file, "w"); if (fp) { fprintf(fp, "%ld\n", st_time_var->now); - close_file(&fp, file, __func__); - /* - * if this is the first time the file got created, it's very likely - * indeed that purge does not need to run. Only return FALSE if the - * file didn't previously exist. - */ - return init; + // Check for errors when closing the file after writing + if (fclose(fp) != 0) + { + perror("Error closing file after write"); + exit(EXIT_FAILURE); + } + } + else + { + open_err(file, __func__); + exit(errno); // Exit if unable to write the file } - /* - * if we can't even write this file to the config directory, something - * is not right. Make it fatal. - */ - open_err(file, __func__); - exit(errno); + return purge_needed; } @@ -195,7 +201,7 @@ do_file_purge(char *purge_target, const rmw_options *cli_user_options, // sleep(1); } else - printf("-%s\n", pt_basename); + printf("-%s\n", pt_basename); } else msg_err_remove(trashinfo_entry_realpath, __func__); diff --git a/src/time_rmw.c b/src/time_rmw.c index 71055bd6..980ae9eb 100644 --- a/src/time_rmw.c +++ b/src/time_rmw.c @@ -32,9 +32,17 @@ set_time_string(char *tm_str, const size_t len, const char *format, time_t time_t_now) { struct tm result; - localtime_r(&time_t_now, &result); + if (localtime_r(&time_t_now, &result) == NULL) + { + fputs + ("Error: localtime_r() failed for time_t value beyond 32-bit limit.\n", + stderr); + exit(EXIT_FAILURE); + } strftime(tm_str, len, format, &result); trim_whitespace(tm_str); + + return; } /*! @@ -64,6 +72,7 @@ void init_time_vars(st_time *x) { x->now = time(NULL); + // x->now = 0x80000000; set_which_deletion_date(x->t_fmt); diff --git a/test/meson.build b/test/meson.build index b1022810..7b963074 100644 --- a/test/meson.build +++ b/test/meson.build @@ -3,6 +3,29 @@ add_test_setup( env: 'RMW_FAKE_MEDIA_ROOT=true' ) +# +# This does not work +# +#faketime_lib = cc.find_library( +# 'faketime', +# dirs: [ +# '/usr/lib/faketime', +# '/lib/x86_64-linux-gnu/faketime', +# '/lib/aarch64-linux-gnu/faketime' +# ], +# required: false +# ) + +# TODO: Detect whether ubsan is required or not, determine the path +add_test_setup( + 'epochalypse', + env: [ + #'LD_PRELOAD=' + faketime_lib.full_path(), + 'LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1', + 'FAKETIME=+14y' + ] +) + test_cases = [ 'strings_rmw', 'utils_rmw',
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor