Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8ca0cdfa
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看板
未验证
提交
8ca0cdfa
编写于
12月 29, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
12月 29, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19232 from taosdata/FIX/xsren/winSort
Fix/xsren/win sort & mac fqdn
上级
52cd40ea
1876d6d7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
66 addition
and
22 deletion
+66
-22
include/os/osSysinfo.h
include/os/osSysinfo.h
+1
-0
source/os/CMakeLists.txt
source/os/CMakeLists.txt
+4
-0
source/os/src/osMath.c
source/os/src/osMath.c
+1
-11
source/os/src/osSocket.c
source/os/src/osSocket.c
+9
-11
source/os/src/osSysinfo.c
source/os/src/osSysinfo.c
+51
-0
未找到文件。
include/os/osSysinfo.h
浏览文件 @
8ca0cdfa
...
...
@@ -70,6 +70,7 @@ typedef struct {
SysNameInfo
taosGetSysNameInfo
();
bool
taosCheckCurrentInDll
();
int
taosGetlocalhostname
(
char
*
hostname
,
size_t
maxLen
);
#ifdef __cplusplus
}
...
...
source/os/CMakeLists.txt
浏览文件 @
8ca0cdfa
...
...
@@ -44,6 +44,10 @@ if(TD_WINDOWS)
os PUBLIC ws2_32 iconv msvcregex wcwidth winmm crashdump
)
elseif
(
TD_DARWIN_64
)
find_library
(
CORE_FOUNDATION_FRAMEWORK CoreFoundation
)
target_link_libraries
(
os PUBLIC
${
CORE_FOUNDATION_FRAMEWORK
}
)
find_library
(
SYSTEM_CONFIGURATION_FRAMEWORK SystemConfiguration
)
target_link_libraries
(
os PUBLIC
${
SYSTEM_CONFIGURATION_FRAMEWORK
}
)
target_link_libraries
(
os PUBLIC dl m iconv
)
...
...
source/os/src/osMath.c
浏览文件 @
8ca0cdfa
...
...
@@ -16,6 +16,7 @@
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include "os.h"
#include <stdlib.h>
#ifdef WINDOWS
void
swapStr
(
char
*
j
,
char
*
J
,
int
width
)
{
...
...
@@ -33,16 +34,5 @@ void swapStr(char* j, char* J, int width) {
// todo refactor: 1) move away; 2) use merge sort instead; 3) qsort is not a stable sort actually.
void
taosSort
(
void
*
arr
,
int64_t
sz
,
int64_t
width
,
__compar_fn_t
compar
)
{
#ifdef WINDOWS
int64_t
i
,
j
;
for
(
i
=
0
;
i
<
sz
-
1
;
i
++
)
{
for
(
j
=
0
;
j
<
sz
-
1
-
i
;
j
++
)
{
if
(
compar
((
char
*
)
arr
+
j
*
width
,
(
char
*
)
arr
+
(
j
+
1
)
*
width
)
>
0
.
00
)
{
swapStr
((
char
*
)
arr
+
j
*
width
,
(
char
*
)
arr
+
(
j
+
1
)
*
width
,
width
);
}
}
}
#else
qsort
(
arr
,
sz
,
width
,
compar
);
#endif
}
source/os/src/osSocket.c
浏览文件 @
8ca0cdfa
...
...
@@ -988,7 +988,7 @@ int32_t taosGetFqdn(char *fqdn) {
#endif
char
hostname
[
1024
];
hostname
[
1023
]
=
'\0'
;
if
(
get
hostname
(
hostname
,
1023
)
==
-
1
)
{
if
(
taosGetlocal
hostname
(
hostname
,
1023
)
==
-
1
)
{
#ifdef WINDOWS
printf
(
"failed to get hostname, reason:%s
\n
"
,
strerror
(
WSAGetLastError
()));
#else
...
...
@@ -998,30 +998,28 @@ int32_t taosGetFqdn(char *fqdn) {
return
-
1
;
}
struct
addrinfo
hints
=
{
0
};
struct
addrinfo
*
result
=
NULL
;
#ifdef __APPLE__
// on macosx, hostname -f has the form of xxx.local
// which will block getaddrinfo for a few seconds if AI_CANONNAME is set
// thus, we choose AF_INET (ipv4 for the moment) to make getaddrinfo return
// immediately
hints
.
ai_family
=
AF_INET
;
// hints.ai_family = AF_INET;
strcpy
(
fqdn
,
hostname
);
strcpy
(
fqdn
+
strlen
(
hostname
),
".local"
);
#else // __APPLE__
struct
addrinfo
hints
=
{
0
};
struct
addrinfo
*
result
=
NULL
;
hints
.
ai_flags
=
AI_CANONNAME
;
#endif // __APPLE__
int32_t
ret
=
getaddrinfo
(
hostname
,
NULL
,
&
hints
,
&
result
);
if
(
!
result
)
{
fprintf
(
stderr
,
"failed to get fqdn, code:%d, reason:%s
\n
"
,
ret
,
gai_strerror
(
ret
));
return
-
1
;
}
#ifdef __APPLE__
// refer to comments above
strcpy
(
fqdn
,
hostname
);
#else // __APPLE__
strcpy
(
fqdn
,
result
->
ai_canonname
);
#endif // __APPLE__
freeaddrinfo
(
result
);
#endif // __APPLE__
return
0
;
}
...
...
source/os/src/osSysinfo.c
浏览文件 @
8ca0cdfa
...
...
@@ -98,6 +98,9 @@ LONG WINAPI exceptionHandler(LPEXCEPTION_POINTERS exception);
#include <errno.h>
#include <libproc.h>
#include <sys/sysctl.h>
#include <SystemConfiguration/SCDynamicStoreCopySpecific.h>
#include <CoreFoundation/CFString.h>
#include <stdio.h>
#else
...
...
@@ -1003,6 +1006,11 @@ SysNameInfo taosGetSysNameInfo() {
tstrncpy
(
info
.
machine
,
uts
.
machine
,
sizeof
(
info
.
machine
));
}
char
localHostName
[
512
];
taosGetlocalhostname
(
localHostName
,
512
);
TdCmdPtr
pCmd
=
taosOpenCmd
(
"scutil --get LocalHostName"
);
tstrncpy
(
info
.
nodename
,
localHostName
,
sizeof
(
info
.
nodename
));
return
info
;
#else
SysNameInfo
info
=
{
0
};
...
...
@@ -1038,3 +1046,46 @@ bool taosCheckCurrentInDll() {
return
false
;
#endif
}
#ifdef _TD_DARWIN_64
int
taosGetMaclocalhostnameByCommand
(
char
*
hostname
,
size_t
maxLen
)
{
TdCmdPtr
pCmd
=
taosOpenCmd
(
"scutil --get LocalHostName"
);
if
(
pCmd
!=
NULL
)
{
if
(
taosGetsCmd
(
pCmd
,
maxLen
-
1
,
hostname
)
>
0
)
{
int
len
=
strlen
(
hostname
);
if
(
hostname
[
len
-
1
]
==
'\n'
)
{
hostname
[
len
-
1
]
=
'\0'
;
}
return
0
;
}
taosCloseCmd
(
&
pCmd
);
}
return
-
1
;
}
int
getMacLocalHostNameBySCD
(
char
*
hostname
,
size_t
maxLen
)
{
SCDynamicStoreRef
store
=
SCDynamicStoreCreate
(
NULL
,
CFSTR
(
""
),
NULL
,
NULL
);
CFStringRef
hostname_cfstr
=
SCDynamicStoreCopyLocalHostName
(
store
);
if
(
hostname_cfstr
!=
NULL
)
{
CFStringGetCString
(
hostname_cfstr
,
hostname
,
maxLen
-
1
,
kCFStringEncodingMacRoman
);
CFRelease
(
hostname_cfstr
);
}
else
{
return
-
1
;
}
CFRelease
(
store
);
return
0
;
}
#endif
int
taosGetlocalhostname
(
char
*
hostname
,
size_t
maxLen
)
{
#ifdef _TD_DARWIN_64
int
res
=
getMacLocalHostNameBySCD
(
hostname
,
maxLen
);
if
(
res
!=
0
)
{
return
taosGetMaclocalhostnameByCommand
(
hostname
,
maxLen
);
}
else
{
return
0
;
}
#else
return
gethostname
(
hostname
,
maxLen
);
#endif
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录