Skip to content
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

Closed
wants to merge 4 commits into from
Closed

CLICKHOUSE-1420 Clear query in client by Ctrl+C #2877

wants to merge 4 commits into from

Conversation

CurtizJ
Copy link
Member

@CurtizJ CurtizJ commented Aug 15, 2018

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

@CurtizJ CurtizJ changed the title CLICKHOUSE-1420 Clear query by Ctrl+C CLICKHOUSE-1420 Clear query in client by Ctrl+C Aug 15, 2018
{
if(signo == SIGINT)
{
if (strcmp(rl_line_buffer, "") == 0)
Copy link
Member

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

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comment.

@@ -571,7 +571,8 @@ class Client : public Poco::Util::Application
Poco::File(history_file).createFile();
}

loop();
signal(SIGINT, signalHandler);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error is not checked.

if (strcmp(rl_line_buffer, "") == 0)
{
std::cout << std::endl;
exit(SIGINT);
Copy link
Member

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();
Copy link
Member

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);
Copy link
Member

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.)

Copy link
Member Author

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.

Copy link
Member

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);
Copy link
Member

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;
Copy link
Member

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);
Copy link
Member

@alexey-milovidov alexey-milovidov Aug 16, 2018

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);
Copy link
Member

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)
Copy link
Member

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;
Copy link
Member

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.

alexey-milovidov added a commit that referenced this pull request Aug 20, 2018
@alexey-milovidov
Copy link
Member

alexey-milovidov commented Aug 20, 2018

I've edited your implementation. Now it's much more simple.
I don't understand why resetting the signal handler was required.

alexey-milovidov added a commit that referenced this pull request Aug 20, 2018
alexey-milovidov added a commit that referenced this pull request Aug 20, 2018
alexey-milovidov added a commit that referenced this pull request Aug 20, 2018
alexey-milovidov added a commit that referenced this pull request Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants