trace_processor_shell: don't quit on CTRL-C
The CTRL-C behavior is inconsistent: if pressed while running
a query it interrupts the query but leaves the shell open.
If pressed when no query is running it quits.
This causes a lot of frustration when hittiing CTRL-C just
after a query has finished, especially on large queries.
This change makes it so CTRL-C doesn't quit ever.
Test: manual
Change-Id: I4fc6b0ac72754475b4b167c26abec48b3ed9c7a7
diff --git a/src/trace_processor/trace_processor_shell.cc b/src/trace_processor/trace_processor_shell.cc
index 89fdc99..88c39af 100644
--- a/src/trace_processor/trace_processor_shell.cc
+++ b/src/trace_processor/trace_processor_shell.cc
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <stdio.h>
@@ -147,7 +148,17 @@
using ScopedLine = std::unique_ptr<char, LineDeleter>;
ScopedLine GetLine(const char* prompt) {
- return ScopedLine(linenoise(prompt));
+ errno = 0;
+ auto line = ScopedLine(linenoise(prompt));
+ // linenoise returns a nullptr both for CTRL-C and CTRL-D, however in the
+ // former case it sets errno to EAGAIN.
+ // If the user press CTRL-C return "" instead of nullptr. We don't want the
+ // main loop to quit in that case as that is inconsistent with the behavior
+ // "CTRL-C interrupts the current query" and frustrating when hitting that
+ // a split second after the query is done.
+ if (!line && errno == EAGAIN)
+ return ScopedLine(strdup(""));
+ return line;
}
#else
@@ -502,8 +513,10 @@
ScopedLine line = GetLine("> ");
if (!line)
break;
- if (strcmp(line.get(), "") == 0)
+ if (strcmp(line.get(), "") == 0) {
+ printf("If you want to quit either type .q or press CTRL-D (EOF)\n");
continue;
+ }
if (line.get()[0] == '.') {
char command[32] = {};
char arg[1024] = {};