diff options
author | Philip Withnall <philip@tecnocode.co.uk> | 2012-01-13 19:37:29 +0000 |
---|---|---|
committer | Philip Withnall <philip@tecnocode.co.uk> | 2012-03-26 13:08:46 +0100 |
commit | 456575eb920abe5c132d22db0871b5a7fcdde74f (patch) | |
tree | 6d97153d18d95d63c15dd26a76e30639c4f0e28a /tools | |
parent | 75c7fb1803a27a608d75ffda41306ef9082aa01c (diff) |
Bug 660235 — Consistent signal handlers to a terminal would be cool
Fix folks-inspect’s handling of SIGINT, SIGTERM and EOF. In the former case,
we want to clear the current input buffer and display a new prompt. In
the case of SIGTERM we want to exit cleanly, and in the case of EOF we want
to exit if the input buffer is empty.
The combination of readline, Unix signals and threads in this was unfun.
Closes: https://bugzilla.gnome.org/show_bug.cgi?id=660235
Diffstat (limited to 'tools')
-rw-r--r-- | tools/inspect/Makefile.am | 1 | ||||
-rw-r--r-- | tools/inspect/inspect.vala | 30 |
2 files changed, 30 insertions, 1 deletions
diff --git a/tools/inspect/Makefile.am b/tools/inspect/Makefile.am index 3ceb370f..0bf0c9b3 100644 --- a/tools/inspect/Makefile.am +++ b/tools/inspect/Makefile.am @@ -1,6 +1,7 @@ VALAFLAGS = \ $(AM_VALAFLAGS) \ --vapidir=$(top_srcdir)/folks \ + --pkg=posix \ --pkg=readline \ --pkg=gobject-2.0 \ --pkg=gio-2.0 \ diff --git a/tools/inspect/inspect.vala b/tools/inspect/inspect.vala index f0c587fb..1f34103e 100644 --- a/tools/inspect/inspect.vala +++ b/tools/inspect/inspect.vala @@ -57,9 +57,19 @@ public class Folks.Inspect.Client : Object return 1; } - /* Create the client and run the command. */ + /* Create the client. */ main_client = new Client (); + /* Set up signal handling. */ + Unix.signal_add (Posix.SIGTERM, () => + { + /* Quit the client and let that exit the process. */ + main_client.quit (); + + return false; + }); + + /* Run the command. */ if (args.length == 1) { main_client.run_interactive (); @@ -209,6 +219,24 @@ public class Folks.Inspect.Client : Object assert_not_reached (); }); + /* Handle SIGINT. */ + Unix.signal_add (Posix.SIGINT, () => + { + /* Tidy up. */ + Readline.free_line_state (); + Readline.cleanup_after_signal (); + Readline.reset_after_signal (); + + /* Display a fresh prompt. */ + stdout.printf ("^C"); + Readline.crlf (); + Readline.reset_line_state (); + Readline.replace_line ("", 0); + Readline.redisplay (); + + return true; + }); + /* Allow things to be set for folks-inspect in ~/.inputrc, and install our * own completion function. */ Readline.readline_name = "folks-inspect"; |