-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLICKHOUSE-1420 Clear query in client by Ctrl+C #2877
Conversation
This reverts commit df017f9.
dbms/programs/client/Client.cpp
Outdated
{ | ||
if(signo == SIGINT) | ||
{ | ||
if (strcmp(rl_line_buffer, "") == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check for first byte is enough
dbms/programs/client/Client.cpp
Outdated
@@ -658,6 +659,24 @@ class Client : public Poco::Util::Application | |||
return boost::replace_all_copy(prompt_by_server_display_name, "{database}", config().getString("database", "default")); | |||
} | |||
|
|||
static void signalHandler(int signo) | |||
{ | |||
if(signo == SIGINT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style
dbms/programs/client/Client.cpp
Outdated
@@ -658,6 +659,24 @@ class Client : public Poco::Util::Application | |||
return boost::replace_all_copy(prompt_by_server_display_name, "{database}", config().getString("database", "default")); | |||
} | |||
|
|||
static void signalHandler(int signo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing comment.
dbms/programs/client/Client.cpp
Outdated
@@ -571,7 +571,8 @@ class Client : public Poco::Util::Application | |||
Poco::File(history_file).createFile(); | |||
} | |||
|
|||
loop(); | |||
signal(SIGINT, signalHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error is not checked.
dbms/programs/client/Client.cpp
Outdated
if (strcmp(rl_line_buffer, "") == 0) | ||
{ | ||
std::cout << std::endl; | ||
exit(SIGINT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goodbye message is not printed.
{ | ||
std::cout << std::endl; | ||
rl_replace_line("", 0); | ||
rl_forced_update_display(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return value is ignored.
@@ -1099,6 +1118,8 @@ class Client : public Poco::Util::Application | |||
/// Also checks if query execution should be cancelled. | |||
void receiveResult() | |||
{ | |||
signal(SIGINT, SIG_DFL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really needed?
(We block signals in InterruptListener.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it exit by double press Ctrl+c doesn`t work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How it can be explained?
@@ -571,7 +571,9 @@ class Client : public Poco::Util::Application | |||
Poco::File(history_file).createFile(); | |||
} | |||
|
|||
loop(); | |||
if (signal(SIGINT, signalHandler) == SIG_ERR) | |||
throwFromErrno("Cannot handle signal.", ErrorCodes::CANNOT_WAIT_FOR_SIGNAL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong error code.
{ | ||
if (!rl_line_buffer[0]) | ||
{ | ||
std::cout << std::endl << "Bye." << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is duplicated.
if (!rl_line_buffer[0]) | ||
{ | ||
std::cout << std::endl << "Bye." << std::endl; | ||
exit(SIGINT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructor of Client class wont be invoked. ASan and Valgrind will report false positive memory leaks.
@@ -1129,6 +1153,8 @@ class Client : public Poco::Util::Application | |||
|
|||
if (cancelled && is_interactive) | |||
std::cout << "Query was cancelled." << std::endl; | |||
|
|||
signal(SIGINT, signalHandler); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return code is not checked.
/// or to exit if query is empty | ||
static void signalHandler(int signo) | ||
{ | ||
if (signo == SIGINT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless check.
{ | ||
if (!rl_line_buffer[0]) | ||
{ | ||
std::cout << std::endl << "Bye." << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not signal-safe.
I've edited your implementation. Now it's much more simple. |
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en