Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6b6c4364
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6b6c4364
编写于
3月 10, 2022
作者:
wafwerar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-13770]<fix>: redefine system api.
上级
94bc3a6e
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
239 addition
and
215 deletion
+239
-215
include/os/osSysinfo.h
include/os/osSysinfo.h
+0
-1
include/os/osSystem.h
include/os/osSystem.h
+12
-0
source/os/src/osSysinfo.c
source/os/src/osSysinfo.c
+0
-35
source/os/src/osSystem.c
source/os/src/osSystem.c
+209
-54
tools/shell/inc/shell.h
tools/shell/inc/shell.h
+0
-4
tools/shell/src/backup/shellDarwin.c
tools/shell/src/backup/shellDarwin.c
+5
-55
tools/shell/src/backup/shellImport.c
tools/shell/src/backup/shellImport.c
+6
-9
tools/shell/src/shellLinux.c
tools/shell/src/shellLinux.c
+5
-55
tools/shell/src/shellMain.c
tools/shell/src/shellMain.c
+2
-2
未找到文件。
include/os/osSysinfo.h
浏览文件 @
6b6c4364
...
...
@@ -47,7 +47,6 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize);
int32_t
taosGetProcIO
(
int64_t
*
rchars
,
int64_t
*
wchars
,
int64_t
*
read_bytes
,
int64_t
*
write_bytes
);
int32_t
taosGetCardInfo
(
int64_t
*
receive_bytes
,
int64_t
*
transmit_bytes
);
int32_t
taosSystem
(
const
char
*
cmd
);
void
taosKillSystem
();
int32_t
taosGetSystemUUID
(
char
*
uid
,
int32_t
uidlen
);
char
*
taosGetCmdlineByPID
(
int32_t
pid
);
...
...
include/os/osSystem.h
浏览文件 @
6b6c4364
...
...
@@ -20,11 +20,23 @@
extern
"C"
{
#endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define popen POPEN_FUNC_TAOS_FORBID
#define pclose PCLOSE_FUNC_TAOS_FORBID
#define tcsetattr TCSETATTR_FUNC_TAOS_FORBID
#define tcgetattr TCGETATTR_FUNC_TAOS_FORBID
#endif
int32_t
taosSystem
(
const
char
*
cmd
,
char
*
buf
,
int32_t
bufSize
);
void
*
taosLoadDll
(
const
char
*
filename
);
void
*
taosLoadSym
(
void
*
handle
,
char
*
name
);
void
taosCloseDll
(
void
*
handle
);
int32_t
taosSetConsoleEcho
(
bool
on
);
void
setTerminalMode
();
int32_t
getOldTerminalMode
();
void
resetTerminalMode
();
#ifdef __cplusplus
}
...
...
source/os/src/osSysinfo.c
浏览文件 @
6b6c4364
...
...
@@ -671,41 +671,6 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
#endif
}
int
taosSystem
(
const
char
*
cmd
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
printf
(
"taosSystem not support"
);
return
-
1
;
#elif defined(_TD_DARWIN_64)
printf
(
"no support funtion"
);
return
-
1
;
#else
FILE
*
fp
;
int
res
;
char
buf
[
1024
];
if
(
cmd
==
NULL
)
{
// printf("taosSystem cmd is NULL!");
return
-
1
;
}
if
((
fp
=
popen
(
cmd
,
"r"
))
==
NULL
)
{
// printf("popen cmd:%s error: %s", cmd, strerror(errno));
return
-
1
;
}
else
{
while
(
fgets
(
buf
,
sizeof
(
buf
),
fp
))
{
// printf("popen result:%s", buf);
}
if
((
res
=
pclose
(
fp
))
==
-
1
)
{
// printf("close popen file pointer fp error!");
}
else
{
// printf("popen res is :%d", res);
}
return
res
;
}
#endif
}
void
taosKillSystem
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
printf
(
"function taosKillSystem, exit!"
);
...
...
source/os/src/osSystem.c
浏览文件 @
6b6c4364
...
...
@@ -13,78 +13,80 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE
#include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#elif defined(_TD_DARWIN_64)
#else
#include <dlfcn.h>
#include <termios.h>
#include <unistd.h>
#endif
/*
* windows implementation
*/
struct
termios
oldtio
;
void
*
taosLoadDll
(
const
char
*
filename
)
{
return
NULL
;
}
void
*
taosLoadSym
(
void
*
handle
,
char
*
name
)
{
return
NULL
;
}
void
taosCloseDll
(
void
*
handle
)
{}
int32_t
taosSystem
(
const
char
*
cmd
,
char
*
buf
,
int32_t
bufSize
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
FILE
*
fp
;
if
(
cmd
==
NULL
)
{
// printf("taosSystem cmd is NULL!");
return
-
1
;
}
int
taosSetConsoleEcho
(
bool
on
)
{
HANDLE
hStdin
=
GetStdHandle
(
STD_INPUT_HANDLE
);
DWORD
mode
=
0
;
GetConsoleMode
(
hStdin
,
&
mode
);
if
(
on
)
{
mode
|=
ENABLE_ECHO_INPUT
;
if
((
fp
=
_popen
(
cmd
,
"r"
))
==
NULL
)
{
// printf("popen cmd:%s error: %s", cmd, strerror(errno));
return
-
1
;
}
else
{
mode
&=
~
ENABLE_ECHO_INPUT
;
}
SetConsoleMode
(
hStdin
,
mode
);
while
(
fgets
(
buf
,
bufSize
,
fp
))
{
// printf("popen result:%s", buf);
}
return
0
;
}
if
(
!
_pclose
(
fp
))
{
// printf("close popen file pointer fp error!");
return
-
1
;
}
else
{
// printf("popen res is :%d", res);
}
return
0
;
#elif defined(_TD_DARWIN_64)
/*
* darwin implementation
*/
void
*
taosLoadDll
(
const
char
*
filename
)
{
return
NULL
;
}
void
*
taosLoadSym
(
void
*
handle
,
char
*
name
)
{
return
NULL
;
}
void
taosCloseDll
(
void
*
handle
)
{}
int
taosSetConsoleEcho
(
bool
on
)
{
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
int
err
;
struct
termios
term
;
if
(
tcgetattr
(
STDIN_FILENO
,
&
term
)
==
-
1
)
{
perror
(
"Cannot get the attribution of the terminal"
);
printf
(
"no support funtion"
);
return
-
1
;
#else
FILE
*
fp
;
int32_t
res
;
if
(
cmd
==
NULL
)
{
// printf("taosSystem cmd is NULL!");
return
-
1
;
}
if
(
on
)
term
.
c_lflag
|=
ECHOFLAGS
;
else
term
.
c_lflag
&=
~
ECHOFLAGS
;
err
=
tcsetattr
(
STDIN_FILENO
,
TCSAFLUSH
,
&
term
);
if
(
err
==
-
1
&&
err
==
EINTR
)
{
perror
(
"Cannot set the attribution of the terminal"
);
if
((
fp
=
popen
(
cmd
,
"r"
))
==
NULL
)
{
// printf("popen cmd:%s error: %s", cmd, strerror(errno));
return
-
1
;
}
return
0
;
}
#else
}
else
{
while
(
fgets
(
buf
,
bufSize
,
fp
))
{
// printf("popen result:%s", buf);
}
/*
* linux implementation
*/
if
((
res
=
pclose
(
fp
))
==
-
1
)
{
// printf("close popen file pointer fp error!");
}
else
{
// printf("popen res is :%d", res);
}
#include <dlfcn.h>
#include <termios.h>
#include <unistd.h>
return
res
;
}
#endif
}
void
*
taosLoadDll
(
const
char
*
filename
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
NULL
;
#elif defined(_TD_DARWIN_64)
return
NULL
;
#else
void
*
handle
=
dlopen
(
filename
,
RTLD_LAZY
);
if
(
!
handle
)
{
//printf("load dll:%s failed, error:%s", filename, dlerror());
...
...
@@ -94,9 +96,15 @@ void* taosLoadDll(const char* filename) {
//printf("dll %s loaded", filename);
return
handle
;
#endif
}
void
*
taosLoadSym
(
void
*
handle
,
char
*
name
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
NULL
;
#elif defined(_TD_DARWIN_64)
return
NULL
;
#else
void
*
sym
=
dlsym
(
handle
,
name
);
char
*
error
=
NULL
;
...
...
@@ -108,15 +116,57 @@ void* taosLoadSym(void* handle, char* name) {
//printf("sym %s loaded", name);
return
sym
;
#endif
}
void
taosCloseDll
(
void
*
handle
)
{
void
taosCloseDll
(
void
*
handle
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
return
;
#elif defined(_TD_DARWIN_64)
return
;
#else
if
(
handle
)
{
dlclose
(
handle
);
}
#endif
}
int
taosSetConsoleEcho
(
bool
on
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
HANDLE
hStdin
=
GetStdHandle
(
STD_INPUT_HANDLE
);
DWORD
mode
=
0
;
GetConsoleMode
(
hStdin
,
&
mode
);
if
(
on
)
{
mode
|=
ENABLE_ECHO_INPUT
;
}
else
{
mode
&=
~
ENABLE_ECHO_INPUT
;
}
SetConsoleMode
(
hStdin
,
mode
);
return
0
;
#elif defined(_TD_DARWIN_64)
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
int
err
;
struct
termios
term
;
if
(
tcgetattr
(
STDIN_FILENO
,
&
term
)
==
-
1
)
{
perror
(
"Cannot get the attribution of the terminal"
);
return
-
1
;
}
if
(
on
)
term
.
c_lflag
|=
ECHOFLAGS
;
else
term
.
c_lflag
&=
~
ECHOFLAGS
;
err
=
tcsetattr
(
STDIN_FILENO
,
TCSAFLUSH
,
&
term
);
if
(
err
==
-
1
&&
err
==
EINTR
)
{
perror
(
"Cannot set the attribution of the terminal"
);
return
-
1
;
}
return
0
;
#else
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
int
err
;
struct
termios
term
;
...
...
@@ -138,6 +188,111 @@ int taosSetConsoleEcho(bool on) {
}
return
0
;
#endif
}
void
setTerminalMode
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#elif defined(_TD_DARWIN_64)
struct
termios
newtio
;
/* if (atexit() != 0) { */
/* fprintf(stderr, "Error register exit function!\n"); */
/* exit(EXIT_FAILURE); */
/* } */
memcpy
(
&
newtio
,
&
oldtio
,
sizeof
(
oldtio
));
// Set new terminal attributes.
newtio
.
c_iflag
&=
~
(
IXON
|
IXOFF
|
ICRNL
|
INLCR
|
IGNCR
|
IMAXBEL
|
ISTRIP
);
newtio
.
c_iflag
|=
IGNBRK
;
// newtio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET);
newtio
.
c_oflag
|=
OPOST
;
newtio
.
c_oflag
|=
ONLCR
;
newtio
.
c_oflag
&=
~
(
OCRNL
|
ONLRET
);
newtio
.
c_lflag
&=
~
(
IEXTEN
|
ICANON
|
ECHO
|
ECHOE
|
ECHONL
|
ECHOCTL
|
ECHOPRT
|
ECHOKE
|
ISIG
);
newtio
.
c_cc
[
VMIN
]
=
1
;
newtio
.
c_cc
[
VTIME
]
=
0
;
if
(
tcsetattr
(
0
,
TCSANOW
,
&
newtio
)
!=
0
)
{
fprintf
(
stderr
,
"Fail to set terminal properties!
\n
"
);
exit
(
EXIT_FAILURE
);
}
#else
struct
termios
newtio
;
/* if (atexit() != 0) { */
/* fprintf(stderr, "Error register exit function!\n"); */
/* exit(EXIT_FAILURE); */
/* } */
memcpy
(
&
newtio
,
&
oldtio
,
sizeof
(
oldtio
));
// Set new terminal attributes.
newtio
.
c_iflag
&=
~
(
IXON
|
IXOFF
|
ICRNL
|
INLCR
|
IGNCR
|
IMAXBEL
|
ISTRIP
);
newtio
.
c_iflag
|=
IGNBRK
;
// newtio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET);
newtio
.
c_oflag
|=
OPOST
;
newtio
.
c_oflag
|=
ONLCR
;
newtio
.
c_oflag
&=
~
(
OCRNL
|
ONLRET
);
newtio
.
c_lflag
&=
~
(
IEXTEN
|
ICANON
|
ECHO
|
ECHOE
|
ECHONL
|
ECHOCTL
|
ECHOPRT
|
ECHOKE
|
ISIG
);
newtio
.
c_cc
[
VMIN
]
=
1
;
newtio
.
c_cc
[
VTIME
]
=
0
;
if
(
tcsetattr
(
0
,
TCSANOW
,
&
newtio
)
!=
0
)
{
fprintf
(
stderr
,
"Fail to set terminal properties!
\n
"
);
exit
(
EXIT_FAILURE
);
}
#endif
}
int32_t
getOldTerminalMode
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#elif defined(_TD_DARWIN_64)
/* Make sure stdin is a terminal. */
if
(
!
isatty
(
STDIN_FILENO
))
{
return
-
1
;
}
// Get the parameter of current terminal
if
(
tcgetattr
(
0
,
&
oldtio
)
!=
0
)
{
return
-
1
;
}
return
1
;
#else
/* Make sure stdin is a terminal. */
if
(
!
isatty
(
STDIN_FILENO
))
{
return
-
1
;
}
// Get the parameter of current terminal
if
(
tcgetattr
(
0
,
&
oldtio
)
!=
0
)
{
return
-
1
;
}
return
1
;
#endif
}
void
resetTerminalMode
()
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#elif defined(_TD_DARWIN_64)
if
(
tcsetattr
(
0
,
TCSANOW
,
&
oldtio
)
!=
0
)
{
fprintf
(
stderr
,
"Fail to reset the terminal properties!
\n
"
);
exit
(
EXIT_FAILURE
);
}
#else
if
(
tcsetattr
(
0
,
TCSANOW
,
&
oldtio
)
!=
0
)
{
fprintf
(
stderr
,
"Fail to reset the terminal properties!
\n
"
);
exit
(
EXIT_FAILURE
);
}
#endif
}
\ No newline at end of file
tools/shell/inc/shell.h
浏览文件 @
6b6c4364
...
...
@@ -86,10 +86,6 @@ extern char PROMPT_HEADER[];
extern
char
CONTINUE_PROMPT
[];
extern
int
prompt_size
;
extern
SShellHistory
history
;
extern
struct
termios
oldtio
;
extern
void
set_terminal_mode
();
extern
int
get_old_terminal_mode
(
struct
termios
*
tio
);
extern
void
reset_terminal_mode
();
extern
SShellArguments
args
;
extern
int64_t
result
;
...
...
tools/shell/src/backup/shellDarwin.c
浏览文件 @
6b6c4364
...
...
@@ -358,7 +358,7 @@ int32_t shellReadCommand(TAOS *con, char *command) {
void
*
shellLoopQuery
(
void
*
arg
)
{
if
(
indicator
)
{
get
_old_terminal_mode
(
&
oldtio
);
get
OldTerminalMode
(
);
indicator
=
0
;
}
...
...
@@ -379,12 +379,12 @@ void *shellLoopQuery(void *arg) {
do
{
// Read command from shell.
memset
(
command
,
0
,
MAX_COMMAND_SIZE
);
set
_terminal_m
ode
();
set
TerminalM
ode
();
err
=
shellReadCommand
(
con
,
command
);
if
(
err
)
{
break
;
}
reset
_terminal_m
ode
();
reset
TerminalM
ode
();
}
while
(
shellRunCommand
(
con
,
command
)
==
0
);
tfree
(
command
);
...
...
@@ -395,56 +395,6 @@ void *shellLoopQuery(void *arg) {
return
NULL
;
}
int
get_old_terminal_mode
(
struct
termios
*
tio
)
{
/* Make sure stdin is a terminal. */
if
(
!
isatty
(
STDIN_FILENO
))
{
return
-
1
;
}
// Get the parameter of current terminal
if
(
tcgetattr
(
0
,
&
oldtio
)
!=
0
)
{
return
-
1
;
}
return
1
;
}
void
reset_terminal_mode
()
{
if
(
tcsetattr
(
0
,
TCSANOW
,
&
oldtio
)
!=
0
)
{
fprintf
(
stderr
,
"Fail to reset the terminal properties!
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
void
set_terminal_mode
()
{
struct
termios
newtio
;
/* if (atexit(reset_terminal_mode) != 0) { */
/* fprintf(stderr, "Error register exit function!\n"); */
/* exit(EXIT_FAILURE); */
/* } */
memcpy
(
&
newtio
,
&
oldtio
,
sizeof
(
oldtio
));
// Set new terminal attributes.
newtio
.
c_iflag
&=
~
(
IXON
|
IXOFF
|
ICRNL
|
INLCR
|
IGNCR
|
IMAXBEL
|
ISTRIP
);
newtio
.
c_iflag
|=
IGNBRK
;
// newtio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET);
newtio
.
c_oflag
|=
OPOST
;
newtio
.
c_oflag
|=
ONLCR
;
newtio
.
c_oflag
&=
~
(
OCRNL
|
ONLRET
);
newtio
.
c_lflag
&=
~
(
IEXTEN
|
ICANON
|
ECHO
|
ECHOE
|
ECHONL
|
ECHOCTL
|
ECHOPRT
|
ECHOKE
|
ISIG
);
newtio
.
c_cc
[
VMIN
]
=
1
;
newtio
.
c_cc
[
VTIME
]
=
0
;
if
(
tcsetattr
(
0
,
TCSANOW
,
&
newtio
)
!=
0
)
{
fprintf
(
stderr
,
"Fail to set terminal properties!
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
void
get_history_path
(
char
*
history
)
{
sprintf
(
history
,
"%s/%s"
,
getpwuid
(
getuid
())
->
pw_dir
,
HISTORY_FILE
);
}
void
clearScreen
(
int
ecmd_pos
,
int
cursor_pos
)
{
...
...
@@ -541,9 +491,9 @@ void showOnScreen(Command *cmd) {
fflush
(
stdout
);
}
void
cleanup_handler
(
void
*
arg
)
{
tcsetattr
(
0
,
TCSANOW
,
&
oldtio
);
}
void
cleanup_handler
(
void
*
arg
)
{
resetTerminalMode
(
);
}
void
exitShell
()
{
tcsetattr
(
0
,
TCSANOW
,
&
oldtio
);
resetTerminalMode
(
);
exit
(
EXIT_SUCCESS
);
}
tools/shell/src/backup/shellImport.c
浏览文件 @
6b6c4364
...
...
@@ -39,14 +39,14 @@ static int shellGetFilesNum(const char *directoryName, const char *prefix)
char
cmd
[
1024
]
=
{
0
};
sprintf
(
cmd
,
"ls %s/*.%s | wc -l "
,
directoryName
,
prefix
);
FILE
*
fp
=
popen
(
cmd
,
"r"
)
;
if
(
fp
==
NULL
)
{
char
buf
[
1024
]
=
{
0
}
;
if
(
taosSystem
(
cmd
,
buf
,
sizeof
(
buf
))
<
0
)
{
fprintf
(
stderr
,
"ERROR: failed to execute:%s, error:%s
\n
"
,
cmd
,
strerror
(
errno
));
exit
(
0
);
}
int
fileNum
=
0
;
if
(
fscanf
(
fp
,
"%d"
,
&
fileNum
)
!=
1
)
{
if
(
sscanf
(
buf
,
"%d"
,
&
fileNum
)
!=
1
)
{
fprintf
(
stderr
,
"ERROR: failed to execute:%s, parse result error
\n
"
,
cmd
);
exit
(
0
);
}
...
...
@@ -56,7 +56,6 @@ static int shellGetFilesNum(const char *directoryName, const char *prefix)
exit
(
0
);
}
pclose
(
fp
);
return
fileNum
;
}
...
...
@@ -65,14 +64,14 @@ static void shellParseDirectory(const char *directoryName, const char *prefix, c
char
cmd
[
1024
]
=
{
0
};
sprintf
(
cmd
,
"ls %s/*.%s | sort"
,
directoryName
,
prefix
);
FILE
*
fp
=
popen
(
cmd
,
"r"
)
;
if
(
fp
==
NULL
)
{
char
buf
[
1024
]
=
{
0
}
;
if
(
taosSystem
(
cmd
,
buf
,
sizeof
(
buf
))
<
0
)
{
fprintf
(
stderr
,
"ERROR: failed to execute:%s, error:%s
\n
"
,
cmd
,
strerror
(
errno
));
exit
(
0
);
}
int
fileNum
=
0
;
while
(
fscanf
(
fp
,
"%128s"
,
fileArray
[
fileNum
++
]))
{
while
(
sscanf
(
buf
,
"%128s"
,
fileArray
[
fileNum
++
]))
{
if
(
strcmp
(
fileArray
[
fileNum
-
1
],
shellTablesSQLFile
)
==
0
)
{
fileNum
--
;
}
...
...
@@ -85,8 +84,6 @@ static void shellParseDirectory(const char *directoryName, const char *prefix, c
fprintf
(
stderr
,
"ERROR: directory:%s changed while read
\n
"
,
directoryName
);
exit
(
0
);
}
pclose
(
fp
);
}
static
void
shellCheckTablesSQLFile
(
const
char
*
directoryName
)
...
...
tools/shell/src/shellLinux.c
浏览文件 @
6b6c4364
...
...
@@ -388,7 +388,7 @@ int32_t shellReadCommand(TAOS *con, char *command) {
void
*
shellLoopQuery
(
void
*
arg
)
{
if
(
indicator
)
{
get
_old_terminal_mode
(
&
oldtio
);
get
OldTerminalMode
(
);
indicator
=
0
;
}
...
...
@@ -409,12 +409,12 @@ void *shellLoopQuery(void *arg) {
do
{
// Read command from shell.
memset
(
command
,
0
,
MAX_COMMAND_SIZE
);
set
_terminal_m
ode
();
set
TerminalM
ode
();
err
=
shellReadCommand
(
con
,
command
);
if
(
err
)
{
break
;
}
reset
_terminal_m
ode
();
reset
TerminalM
ode
();
}
while
(
shellRunCommand
(
con
,
command
)
==
0
);
tfree
(
command
);
...
...
@@ -425,56 +425,6 @@ void *shellLoopQuery(void *arg) {
return
NULL
;
}
int
get_old_terminal_mode
(
struct
termios
*
tio
)
{
/* Make sure stdin is a terminal. */
if
(
!
isatty
(
STDIN_FILENO
))
{
return
-
1
;
}
// Get the parameter of current terminal
if
(
tcgetattr
(
0
,
&
oldtio
)
!=
0
)
{
return
-
1
;
}
return
1
;
}
void
reset_terminal_mode
()
{
if
(
tcsetattr
(
0
,
TCSANOW
,
&
oldtio
)
!=
0
)
{
fprintf
(
stderr
,
"Fail to reset the terminal properties!
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
void
set_terminal_mode
()
{
struct
termios
newtio
;
/* if (atexit(reset_terminal_mode) != 0) { */
/* fprintf(stderr, "Error register exit function!\n"); */
/* exit(EXIT_FAILURE); */
/* } */
memcpy
(
&
newtio
,
&
oldtio
,
sizeof
(
oldtio
));
// Set new terminal attributes.
newtio
.
c_iflag
&=
~
(
IXON
|
IXOFF
|
ICRNL
|
INLCR
|
IGNCR
|
IMAXBEL
|
ISTRIP
);
newtio
.
c_iflag
|=
IGNBRK
;
// newtio.c_oflag &= ~(OPOST|ONLCR|OCRNL|ONLRET);
newtio
.
c_oflag
|=
OPOST
;
newtio
.
c_oflag
|=
ONLCR
;
newtio
.
c_oflag
&=
~
(
OCRNL
|
ONLRET
);
newtio
.
c_lflag
&=
~
(
IEXTEN
|
ICANON
|
ECHO
|
ECHOE
|
ECHONL
|
ECHOCTL
|
ECHOPRT
|
ECHOKE
|
ISIG
);
newtio
.
c_cc
[
VMIN
]
=
1
;
newtio
.
c_cc
[
VTIME
]
=
0
;
if
(
tcsetattr
(
0
,
TCSANOW
,
&
newtio
)
!=
0
)
{
fprintf
(
stderr
,
"Fail to set terminal properties!
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
void
get_history_path
(
char
*
_history
)
{
snprintf
(
_history
,
TSDB_FILENAME_LEN
,
"%s/%s"
,
getenv
(
"HOME"
),
HISTORY_FILE
);
}
void
clearScreen
(
int
ecmd_pos
,
int
cursor_pos
)
{
...
...
@@ -571,10 +521,10 @@ void showOnScreen(Command *cmd) {
fflush
(
stdout
);
}
void
cleanup_handler
(
void
*
arg
)
{
tcsetattr
(
0
,
TCSANOW
,
&
oldtio
);
}
void
cleanup_handler
(
void
*
arg
)
{
resetTerminalMode
(
);
}
void
exitShell
()
{
/*int32_t ret =*/
tcsetattr
(
STDIN_FILENO
,
TCSANOW
,
&
oldtio
);
/*int32_t ret =*/
resetTerminalMode
(
);
taos_cleanup
();
exit
(
EXIT_SUCCESS
);
}
tools/shell/src/shellMain.c
浏览文件 @
6b6c4364
...
...
@@ -41,11 +41,11 @@ void *cancelHandler(void *arg) {
taosReleaseRef(tscObjRef, rid);
#endif
#else
reset
_terminal_m
ode
();
reset
TerminalM
ode
();
printf
(
"
\n
Receive ctrl+c or other signal, quit shell.
\n
"
);
exit
(
0
);
#endif
reset
_terminal_m
ode
();
reset
TerminalM
ode
();
printf
(
"
\n
Receive ctrl+c or other signal, quit shell.
\n
"
);
exit
(
0
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录