Description of problem: The behavior of mktime has changed between Fedora 23 and RHEL. I need the behavior to be consistent for the audit utilities. On Fedora 23 QE is reporting that the search tools cannot find events and on RHEL7 it works fine. In trying to locate the cause, I did run across something odd. The program below demonstrates the issue. Which one is the correct behavior, Fedora 23 or RHEL7? #define _XOPEN_SOURCE #include <stdio.h> #include <time.h> #include <string.h> #include <locale.h> time_t start_time = 0; void init_time(const char *da, const char *ti) { struct tm d; strptime(da, "%x", &d); strptime(ti, "%X", &d); start_time = mktime(&d); } int main(void) { setlocale (LC_ALL, "en_US.utf8"); init_time("06/07/2016", "17:00:00"); printf("Time is: %s\n", ctime(&start_time)); return 0; } Version-Release number of selected component (if applicable): glibc-2.22-17.fc23.x86_64 How reproducible: always Steps to Reproduce: 1. run test program Actual results: Time is: Tue Jun 7 17:00:00 2016 Expected results: Time is: Tue Jun 7 18:00:00 2016
(In reply to Steve Grubb from comment #0) > void init_time(const char *da, const char *ti) > { > struct tm d; > strptime(da, "%x", &d); > strptime(ti, "%X", &d); > start_time = mktime(&d); > } Please test with an initializer: struct tm d = {}; I suspect you see essentially random differences due to uninitialized data.
Thanks. That seems to make them both consistent. But it leads to the actual problem of now the time is just wrong. If a user types 17:00:00 in as the time, why does mktime change it to 18:00:00? How to you get reliable time conversion in both December and June? (I understand this is not a bz topic and will close this as not a bug.)
This seems to be the recipe to get reliable time conversion: struct tm d; clear_tm(&d); strptime(da, "%x", &d); start_time = mktime(&d); strptime(ti, "%X", &d); start_time = mktime(&d); strptime is not setting the dst flag on the date conversion so you have to let mktime fix it, then you can do the time conversion and have correct time converted into time_t.