2012-02-05 11:35:58 -05:00
|
|
|
/****************************************************************
|
|
|
|
* *
|
2024-07-19 11:43:27 -04:00
|
|
|
* Copyright 2001, 2013 Fidelity Information Services, Inc *
|
2012-02-05 11:35:58 -05:00
|
|
|
* *
|
|
|
|
* This source code contains the intellectual property *
|
|
|
|
* of its copyright holder(s), and is made available *
|
|
|
|
* under a license. If you do not know the terms of *
|
|
|
|
* the license, please stop and do not read further. *
|
|
|
|
* *
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
#include "mdef.h"
|
|
|
|
|
|
|
|
#include "gtm_time.h"
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
#include "dollarh.h"
|
|
|
|
#include "gtmimagename.h"
|
2024-07-19 11:43:27 -04:00
|
|
|
#include "have_crit.h"
|
2012-02-05 11:35:58 -05:00
|
|
|
|
|
|
|
void dollarh(time_t intime, uint4 *days, time_t *seconds)
|
|
|
|
{
|
|
|
|
uint4 tdays;
|
|
|
|
int isdst;
|
|
|
|
struct tm *ttime;
|
2024-07-19 11:43:27 -04:00
|
|
|
time_t mktime_ret;
|
2012-02-05 11:35:58 -05:00
|
|
|
#ifdef DEBUG
|
|
|
|
static uint4 old_days = 0, old_seconds = 0;
|
|
|
|
static time_t old_intime = 0;
|
|
|
|
static int old_isdst;
|
|
|
|
#endif
|
2024-07-19 11:43:27 -04:00
|
|
|
/* The comment below is now obsolete as GTM-6802 took care of protecting time-related functions from nested
|
|
|
|
* invocations, making the presence of sigprocmasks unnecessary. If several years pass without more incidents
|
|
|
|
* of time-caused hangs, remove the comment. (SOPINI, 2013/02/20)
|
|
|
|
*
|
|
|
|
* When dollarh() is processing and a signal occurs, the signal processing can eventually lead to nested system time
|
2012-02-05 11:35:58 -05:00
|
|
|
* routine calls. If a signal arrives during a system time call (__tzset() in linux) we end up in a generic signal
|
|
|
|
* handler which invokes syslog which in turn tries to call the system time routine (__tz_convert() in linux) which
|
|
|
|
* seems to get suspended presumably waiting for the same interlock that __tzset() has already obtained. A work around
|
|
|
|
* is to block signals (SIGINT, SIGQUIT, SIGTERM, SIGTSTP, SIGCONT, SIGALRM) during the function and then restore them
|
|
|
|
* at the end. [C9D06-002271] [C9I03-002967].
|
|
|
|
*/
|
2024-07-19 11:43:27 -04:00
|
|
|
GTM_LOCALTIME(ttime, &intime); /* represent intime as local time in case of offsets from UCT other than hourly */
|
2012-02-05 11:35:58 -05:00
|
|
|
*seconds = (time_t)(ttime->tm_hour * HOUR) + (ttime->tm_min * MINUTE) + ttime->tm_sec;
|
|
|
|
isdst = ttime->tm_isdst;
|
2024-07-19 11:43:27 -04:00
|
|
|
GTM_GMTIME(ttime, &intime); /* represent intime as UCT */
|
|
|
|
ttime->tm_isdst = isdst; /* use GTM_LOCALTIME to tell mktime whether daylight savings needs to be applied */
|
|
|
|
GTM_MKTIME(mktime_ret, ttime);
|
|
|
|
assert((time_t)-1 != mktime_ret);
|
|
|
|
tdays = (uint4)((intime + (time_t)difftime(intime, mktime_ret)) / ONEDAY) + DAYS; /* adjust relative to UTC */
|
2012-02-05 11:35:58 -05:00
|
|
|
*days = tdays; /* use temp local in case the caller has overlapped arguments */
|
|
|
|
/* Assert that $H always moves forward. The only exception is a negative time adjustment due to DST change.
|
|
|
|
* Do asserts AFTER unblocking signals as otherwise assert failures could hang and/or result in no cores.
|
|
|
|
* DSE and MUPIP use this function to potentially display times in the past (e.g. in DSE DUMP -FILE,
|
|
|
|
* MUPIP JOURNAL EXTRACT) so restrict this assert to the runtime for now.
|
|
|
|
*/
|
|
|
|
assert(!IS_GTM_IMAGE || ((*days == old_days) && (*seconds >= old_seconds)) || (*days > old_days)
|
|
|
|
|| (0 < old_isdst) && (0 == isdst));
|
|
|
|
DEBUG_ONLY(old_seconds = (uint4)*seconds; old_days = *days; old_intime = intime; old_isdst = isdst;)
|
|
|
|
return;
|
|
|
|
}
|