/*
* fn CMM_RET oal_sys_setTZ(TIME_OBJ *pNewObj,
const struct tm *pDstStart,
const struct tm *pDstEnd,
const char *pTimeZone)
* brief Set system timezone environment variable
*
* param[in] pNewObj - The time obj.
* param[in] pDstStart - DaylightSavings start time.
* param[in] pDstend - DaylightSavings end time.
* param[in] pTimeZone - The local time zone.
*
* return CMM_RET
*/
CMM_RET oal_sys_setTZ(DEV2_TIME_OBJ *pNewObj,
const struct tm *pDstStart,
const struct tm *pDstEnd,
const char *pTimeZone)
{
struct timeval tv;
struct timeval *setTv = NULL;
struct timezone tz;
int tzHour = 0, tzMin = 0;
#if (defined(__GLIBC__) && !defined(__UCLIBC__))
const char* mon_names[] = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
const char* week_counts[][2] = {
{"",">=1"}, /* 1st*/
{"",">=8"}, /* 2nd */
{"",">=15"}, /* 3rd */
{"",">=22"}, /* 4th */
{"last",""} /* last */
};
const char* wday_names[] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
int startWeekCount = 0, endWeekCount = 0;
char tzInfo[BUFLEN_512] = {0};
char *pTmp = tzInfo;
FILE *fp = NULL;
if (pNewObj->daylightSavingsUsed)
{
/* set the week count as the UI wants */
startWeekCount = pNewObj->X_TP_DaylightSavingsStartWeekCount;
endWeekCount = pNewObj->X_TP_DaylightSavingsEndWeekCount;
pTmp += sprintf(pTmp, "Rule MYR minimum maximum - %s %s%s%s %02d:0:0 1:00 D\n",
mon_names[pDstStart->tm_mon],
week_counts[startWeekCount-1][0],
wday_names[pDstStart->tm_wday],
week_counts[startWeekCount-1][1],
pDstStart->tm_hour);
pTmp += sprintf(pTmp, "Rule MYR minimum maximum - %s %s%s%s %02d:0:0 0 S\n",
mon_names[pDstEnd->tm_mon],
week_counts[endWeekCount-1][0],
wday_names[pDstEnd->tm_wday],
week_counts[endWeekCount-1][1],
pDstEnd->tm_hour);
pTmp += sprintf(pTmp, "Zone localtime %s MYR C%%sT\n", pTimeZone);
}
else
{
pTmp += sprintf(pTmp, "Zone localtime %s - CST\n", pTimeZone);
}
fp = fopen(__GLIBC_TZ_FILE_PATH__, "w+");
if (fp == NULL)
{
CMM_ERR("Open TZ file error!");
return CMM_ERROR;
}
if (fwrite(tzInfo, strlen(tzInfo), 1, fp) < 0)
{
CMM_ERR("Write TZ file error!");
fclose(fp);
return CMM_ERROR;
}
fclose(fp);
/* create /var/tmp/localtime */
util_execSystem(__FUNCTION__, "zic -d /var/tmp %s", __GLIBC_TZ_FILE_PATH__);
#else
int startWeekCount = 0, endWeekCount = 0;
char tzInfo[BUFLEN_128] = {0};
char tmpTimeZone[BUFLEN_128] = {0};
char *pTmp = tzInfo;
FILE *fp = NULL;
/* Get the entire timezone */
cstr_strncpy(tmpTimeZone, pTimeZone, BUFLEN_128);
tmpTimeZone[0] ^= 6; /* Change the leading symbol, '+' -> '-' or '-' -> '+' */
pTmp += sprintf(pTmp, "GMT%s", tmpTimeZone);
/* DaylightSavings is enable */
if (pNewObj->daylightSavingsUsed)
{
/* set the week count as the UI wants */
startWeekCount = pNewObj->X_TP_DaylightSavingsStartWeekCount;
endWeekCount = pNewObj->X_TP_DaylightSavingsEndWeekCount;
/* Get the dst info, like "DST,Mmon.cnt.wday/hh,Mmon.cnt.wday/hh */
pTmp += sprintf(pTmp, "DST,M%d.%d.%d/%d,M%d.%d.%d/%d", \
pDstStart->tm_mon + 1, startWeekCount, pDstStart->tm_wday, pDstStart->tm_hour,\
pDstEnd->tm_mon + 1, endWeekCount, pDstEnd->tm_wday, pDstEnd->tm_hour);
}
*pTmp++ = '\n';
*pTmp = '\0';
/* Write the tzInfo to the file: /etc/TZ */
fp = fopen(__UCLIBC_TZ_FILE_PATH__, "w+");
if (fp == NULL)
{
CMM_ERR("Open TZ file error!");
return CMM_ERROR;
}
if (fwrite(tzInfo, strlen(tzInfo), 1, fp) < 0)
{
CMM_ERR("Write TZ file error!");
fclose(fp);
return CMM_ERROR;
}
fclose(fp);
#endif
/* liuyuxuan add for parental control V2 */
memset(&tv, 0, sizeof(struct timeval));
memset(&tz, 0, sizeof(struct timezone));
gettimeofday(&tv, &tz);
sscanf(pTimeZone, "%d:%d", &tzHour, &tzMin);
if(tzMin > 0 && tzHour < 0)
{
tzMin = -tzMin;
}
tz.tz_minuteswest = -(MINUTES * tzHour + tzMin);
settimeofday(setTv, &tz);
/* liuyuxuan add end */
return CMM_OK;
}
是在哪里设定夏令时