myadm

Simple MySQL client for the terminal
git clone git://git.bitsmanent.org/myadm
Log | Files | Refs | README | LICENSE

commit a1db8461c3fa3e1d946070c38f6c099e4e1c2e87
parent a52328ad69c2cec8fd6e5367b01f6c7c02b165d3
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Thu,  3 Mar 2016 17:24:28 +0100

Handle SIGINT with quit(.i = 1).

Diffstat:
Mcore.c | 15+++++++++++++++
1 file changed, 15 insertions(+), 0 deletions(-)

diff --git a/core.c b/core.c @@ -11,6 +11,7 @@ #include <stdarg.h> #include <string.h> #include <stdlib.h> +#include <signal.h> #include <mysql.h> #include <stfl.h> @@ -83,6 +84,7 @@ Item *getitem(void); void stfl_putitem(Item *item); char choose(const char *msg, char *opts); Item *cloneitem(Item *item); +void sigint_handler(int sig); void flagas(const Arg *arg); void apply(const Arg *arg); void quit(const Arg *arg); @@ -473,7 +475,15 @@ ecalloc(size_t nmemb, size_t size) { } void +sigint_handler(int sig) { + Arg arg = {.i = 1}; + quit(&arg); +} + +void setup(void) { + struct sigaction sa; + mysql = mysql_init(NULL); if(mysql_real_connect(mysql, dbhost, dbuser, dbpass, NULL, 0, NULL, 0) == NULL) die("Cannot connect to the database.\n"); @@ -481,6 +491,11 @@ setup(void) { ipool = stfl_ipool_create(nl_langinfo(CODESET)); setmode(NULL); stfl_setf("status", "Welcome to %s-%s", __FILE__, VERSION); + + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sa.sa_handler = sigint_handler; + sigaction(SIGINT, &sa, NULL); } void