Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a816e303
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a816e303
编写于
5月 11, 2022
作者:
wafwerar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(os): Ubuntu 18.04 timezone error.
上级
f21348a3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
92 addition
and
90 deletion
+92
-90
source/os/src/osTimezone.c
source/os/src/osTimezone.c
+92
-90
未找到文件。
source/os/src/osTimezone.c
浏览文件 @
a816e303
...
@@ -172,106 +172,108 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
...
@@ -172,106 +172,108 @@ void taosGetSystemTimezone(char *outTimezoneStr, enum TdTimezone *tsTimezone) {
-
timezone
/
3600
);
-
timezone
/
3600
);
#else
#else
if
(
taosCheckExistFile
(
"/etc/timezone"
))
{
char
buf
[
4096
]
=
{
0
};
/*
char
*
tz
=
NULL
;
* NOTE: do not remove it.
{
* Enforce set the correct daylight saving time(DST) flag according
int
n
=
readlink
(
"/etc/localtime"
,
buf
,
sizeof
(
buf
));
* to current time
if
(
n
<
0
)
{
*/
printf
(
"read /etc/localtime error, reason:%s"
,
strerror
(
errno
));
time_t
tx1
=
taosGetTimestampSec
();
struct
tm
tm1
;
if
(
taosCheckExistFile
(
"/etc/timezone"
))
{
taosLocalTime
(
&
tx1
,
&
tm1
);
/*
/* load time zone string from /etc/timezone */
* NOTE: do not remove it.
// FILE *f = fopen("/etc/timezone", "r");
* Enforce set the correct daylight saving time(DST) flag according
errno
=
0
;
* to current time
TdFilePtr
pFile
=
taosOpenFile
(
"/etc/timezone"
,
TD_FILE_READ
);
*/
char
buf
[
68
]
=
{
0
};
time_t
tx1
=
taosGetTimestampSec
();
if
(
pFile
!=
NULL
)
{
struct
tm
tm1
;
int
len
=
taosReadFile
(
pFile
,
buf
,
64
);
taosLocalTime
(
&
tx1
,
&
tm1
);
if
(
len
<
64
&&
taosGetErrorFile
(
pFile
))
{
/* load time zone string from /etc/timezone */
taosCloseFile
(
&
pFile
);
// FILE *f = fopen("/etc/timezone", "r");
printf
(
"read /etc/timezone error, reason:%s"
,
strerror
(
errno
));
errno
=
0
;
return
;
TdFilePtr
pFile
=
taosOpenFile
(
"/etc/timezone"
,
TD_FILE_READ
);
}
char
buf
[
68
]
=
{
0
};
if
(
pFile
!=
NULL
)
{
int
len
=
taosReadFile
(
pFile
,
buf
,
64
);
if
(
len
<
64
&&
taosGetErrorFile
(
pFile
))
{
taosCloseFile
(
&
pFile
);
printf
(
"read /etc/timezone error, reason:%s"
,
strerror
(
errno
));
return
;
}
taosCloseFile
(
&
pFile
);
taosCloseFile
(
&
pFile
);
buf
[
sizeof
(
buf
)
-
1
]
=
0
;
buf
[
sizeof
(
buf
)
-
1
]
=
0
;
char
*
lineEnd
=
strstr
(
buf
,
"
\n
"
);
char
*
lineEnd
=
strstr
(
buf
,
"
\n
"
);
if
(
lineEnd
!=
NULL
)
{
if
(
lineEnd
!=
NULL
)
{
*
lineEnd
=
0
;
*
lineEnd
=
0
;
}
}
// for CentOS system, /etc/timezone does not exist. Ignore the TZ environment variables
// for CentOS system, /etc/timezone does not exist. Ignore the TZ environment variables
if
(
strlen
(
buf
)
>
0
)
{
if
(
strlen
(
buf
)
>
0
)
{
setenv
(
"TZ"
,
buf
,
1
);
setenv
(
"TZ"
,
buf
,
1
);
}
}
}
}
// get and set default timezone
// get and set default timezone
tzset
();
tzset
();
/*
/*
* get CURRENT time zone.
* get CURRENT time zone.
* system current time zone is affected by daylight saving time(DST)
* system current time zone is affected by daylight saving time(DST)
*
*
* e.g., the local time zone of London in DST is GMT+01:00,
* e.g., the local time zone of London in DST is GMT+01:00,
* otherwise is GMT+00:00
* otherwise is GMT+00:00
*/
*/
int32_t
tz
=
(
-
timezone
*
MILLISECOND_PER_SECOND
)
/
MILLISECOND_PER_HOUR
;
int32_t
tz
=
(
-
timezone
*
MILLISECOND_PER_SECOND
)
/
MILLISECOND_PER_HOUR
;
*
tsTimezone
=
tz
;
*
tsTimezone
=
tz
;
tz
+=
daylight
;
tz
+=
daylight
;
/*
/*
* format example:
* format example:
*
*
* Asia/Shanghai (CST, +0800)
* Asia/Shanghai (CST, +0800)
* Europe/London (BST, +0100)
* Europe/London (BST, +0100)
*/
*/
snprintf
(
outTimezoneStr
,
TD_TIMEZONE_LEN
,
"%s (%s, %s%02d00)"
,
buf
,
tzname
[
daylight
],
tz
>=
0
?
"+"
:
"-"
,
abs
(
tz
));
snprintf
(
outTimezoneStr
,
TD_TIMEZONE_LEN
,
"%s (%s, %s%02d00)"
,
buf
,
tzname
[
daylight
],
tz
>=
0
?
"+"
:
"-"
,
abs
(
tz
));
}
else
{
}
else
{
char
buf
[
4096
]
=
{
0
};
printf
(
"There is not /etc/timezone.
\n
"
);
char
*
tz
=
NULL
;
{
int
n
=
readlink
(
"/etc/localtime"
,
buf
,
sizeof
(
buf
));
if
(
n
<
0
)
{
printf
(
"read /etc/localtime error, reason:%s"
,
strerror
(
errno
));
return
;
}
}
buf
[
n
]
=
'\0'
;
return
;
for
(
int
i
=
n
-
1
;
i
>=
0
;
--
i
)
{
}
if
(
buf
[
i
]
==
'/'
)
{
buf
[
n
]
=
'\0'
;
if
(
tz
)
{
for
(
int
i
=
n
-
1
;
i
>=
0
;
--
i
)
{
tz
=
buf
+
i
+
1
;
if
(
buf
[
i
]
==
'/'
)
{
break
;
if
(
tz
)
{
}
tz
=
buf
+
i
+
1
;
tz
=
buf
+
i
+
1
;
break
;
}
}
tz
=
buf
+
i
+
1
;
}
}
if
(
!
tz
||
0
==
strchr
(
tz
,
'/'
))
{
}
printf
(
"parsing /etc/localtime failed"
);
if
(
!
tz
||
0
==
strchr
(
tz
,
'/'
))
{
return
;
printf
(
"parsing /etc/localtime failed"
);
}
return
;
setenv
(
"TZ"
,
tz
,
1
);
tzset
();
}
}
/*
setenv
(
"TZ"
,
tz
,
1
);
* NOTE: do not remove it.
tzset
();
* Enforce set the correct daylight saving time(DST) flag according
* to current time
*/
time_t
tx1
=
taosGetTimestampSec
();
struct
tm
tm1
;
taosLocalTime
(
&
tx1
,
&
tm1
);
/*
* format example:
*
* Asia/Shanghai (CST, +0800)
* Europe/London (BST, +0100)
*/
snprintf
(
outTimezoneStr
,
TD_TIMEZONE_LEN
,
"%s (%s, %+03ld00)"
,
tz
,
tm1
.
tm_isdst
?
tzname
[
daylight
]
:
tzname
[
0
],
-
timezone
/
3600
);
}
}
/*
* NOTE: do not remove it.
* Enforce set the correct daylight saving time(DST) flag according
* to current time
*/
time_t
tx1
=
taosGetTimestampSec
();
struct
tm
tm1
;
taosLocalTime
(
&
tx1
,
&
tm1
);
/*
* format example:
*
* Asia/Shanghai (CST, +0800)
* Europe/London (BST, +0100)
*/
snprintf
(
outTimezoneStr
,
TD_TIMEZONE_LEN
,
"%s (%s, %+03ld00)"
,
tz
,
tm1
.
tm_isdst
?
tzname
[
daylight
]
:
tzname
[
0
],
-
timezone
/
3600
);
#endif
#endif
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录