void dollarh(time_t intime, uint4 *days, time_t *seconds) { uint4 tdays; int isdst; struct tm *ttime; time_t mktime_ret; #ifdef DEBUG static uint4 old_days = 0, old_seconds = 0; static time_t old_intime = 0; static int old_isdst; #endif /* 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 * 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]. */ GTM_LOCALTIME(ttime, &intime); /* represent intime as local time in case of offsets from UCT other than hourly */ *seconds = (time_t)(ttime->tm_hour * HOUR) + (ttime->tm_min * MINUTE) + ttime->tm_sec; isdst = ttime->tm_isdst; 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 */ *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;
void gtcm_pktdmp(char *ptr, int length, char *msg) { char *end; char *chr; int buf[5]; int len; int j; int offset = 0; static int fileID = 0; char tbuf[16]; char fileName[256]; time_t ctim; struct tm *ltime; FILE *fp; char *gtm_dist; ctim = time(0); GTM_LOCALTIME(ltime, &ctim); SPRINTF(tbuf, "%02d%02d%02d%02d",ltime->tm_mon + 1,ltime->tm_mday, ltime->tm_hour,ltime->tm_min); if (gtm_dist=getenv("gtm_dist")) { char subdir[256]; struct stat buf; /* check for the subdirectory $gtm_dist/log/<omi_service> * If the subdirectory exists, place the log file there. * Otherwise...place the file in $gtm_dist/log. */ SPRINTF(subdir,"%s/log/%s", gtm_dist, omi_service); if (stat(subdir,&buf) == 0 && S_ISDIR(buf.st_mode)) { SPRINTF(fileName,"%s/%s_%s.%d", subdir, omi_service, tbuf, fileID++); } else { SPRINTF(fileName,"%s/log/%s_%s.%d", gtm_dist, omi_service, tbuf, fileID++); } } else SPRINTF(fileName,"/usr/tmp/%s_%s.%d", omi_service, tbuf, fileID++); #ifdef __MVS__ if (-1 == gtm_zos_create_tagged_file(fileName, TAG_EBCDIC)) { FPRINTF(stderr,"Could not create and tag new packet dump file (%s).\n", fileName); perror(fileName); } #endif fp = fopen(fileName, "w"); if (fp == NULL) { FPRINTF(stderr,"Could not open packet dump file (%s).\n", fileName); perror(fileName); return; } OMI_DBG((omi_debug, "%s\n", msg)); OMI_DBG((omi_debug, "Log dumped to %s.\n", fileName)); FPRINTF(fp,"%s\n", msg); buf[4] = '\0'; end = ptr + length; chr = (char *)buf; while (ptr < end) { fputc('\t', fp); if ((len = (int)(end - ptr)) > 16) len = 16; memcpy(chr, ptr, len); ptr += len; offset += len; for (j = len; j < 16; j++) chr[j] = '\0'; for (j = 0; j < 4; j++) FPRINTF(fp,"%08x ", buf[j]); for (j = 0; j < 16; j++) if (j >= len) chr[j] = ' '; else if (chr[j] < 32 || chr[j] > 126) chr[j] = '.'; FPRINTF(fp,"%16s %x\n", chr, offset); } FFLUSH(fp); fclose(fp); }