Changeset: d8b67dbe398a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/d8b67dbe398a
Modified Files:
        clients/mapiclient/mclient.c
        clients/mapilib/mapi.c
Branch: client_interrupts
Log Message:

Ignore SIGINT during computation


diffs (133 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1444,7 +1444,8 @@ SQLrenderer(MapiHdl hdl)
        stopped = false;
        prev_handler = signal(SIGINT, renderer_sigint_handler);
        if (prev_handler == SIG_ERR) {
-               perror("SQLrenderer: Could not install handler");
+               perror("SQLrenderer: Could not install signal handler");
+               prev_handler = NULL;
        }
 
        total = 0;
@@ -1666,7 +1667,7 @@ SQLrenderer(MapiHdl hdl)
        }
        mnstr_printf(toConsole, "\n");
 
-       if (signal(SIGINT, prev_handler) == SIG_ERR) {
+       if (prev_handler && signal(SIGINT, prev_handler) == SIG_ERR) {
                perror("SQLrenderer: Could not restore previous handler.");
        }
        free(len);
@@ -2406,8 +2407,8 @@ doFile(Mapi mid, stream *fp, bool useins
                        if (mode != MAL)
                                while (length > 0 &&
                                       (*line == '\f' ||
-                                       *line == '\n' ||
-                                       *line == ' ')) {
+                                               *line == '\n' ||
+                                               *line == ' ')) {
                                        line++;
                                        length--;
                                }
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -4329,6 +4329,15 @@ read_file(MapiHdl hdl, uint64_t off, cha
        (void) read_line(mid);
 }
 
+
+static void
+compute_sigint_handler(int signum)
+{
+       if (signum == SIGINT) {
+               printf("Caught sigint while computing. Ignoring\n");
+       }
+}
+
 /* Read ahead and cache data read.  Depending on the second argument,
    reading may stop at the first non-header and non-error line, or at
    a prompt.
@@ -4348,6 +4357,7 @@ read_into_cache(MapiHdl hdl, int lookahe
        char *line;
        Mapi mid;
        struct MapiResultSet *result;
+       void (*prev_handler)(int);
 
        mid = hdl->mid;
        assert(mid->active == hdl);
@@ -4357,16 +4367,32 @@ read_into_cache(MapiHdl hdl, int lookahe
                check_stream(mid, mid->to, "write error on stream", mid->error);
        }
        if ((result = hdl->active) == NULL)
+
+       prev_handler = signal(SIGINT, compute_sigint_handler);
+       if (prev_handler == SIG_ERR) {
+               perror("mapi_execute_internal: could not install signal 
handler");
+               prev_handler = NULL;
+       }
                result = hdl->result;   /* may also be NULL */
+
        for (;;) {
                line = read_line(mid);
                if (line == NULL) {
                        if (mid->from && mnstr_eof(mid->from)) {
                                mapi_log_record(mid, "unexpected end of file");
                                mapi_log_record(mid, __func__);
+
+                               if (prev_handler && signal(SIGINT, 
prev_handler) == SIG_ERR) {
+                                       perror("mapi_execute_internal: Could 
not restore previous handler.");
+                               }
                                close_connection(mid);
+
                                return mapi_setError(mid, "unexpected end of 
file", __func__, MERROR);
                        }
+                       if (prev_handler && signal(SIGINT, prev_handler) == 
SIG_ERR) {
+                               perror("mapi_execute_internal: Could not 
restore previous handler.");
+                       }
+
                        return mid->error;
                }
                switch (*line) {
@@ -4417,6 +4443,10 @@ read_into_cache(MapiHdl hdl, int lookahe
                                }
                                continue;
                        }
+                       if (prev_handler && signal(SIGINT, prev_handler) == 
SIG_ERR) {
+                               perror("mapi_execute_internal: Could not 
restore previous handler.");
+                       }
+
                        return mid->error;
                case '!':
                        /* start a new result set if we don't have one
@@ -4452,11 +4482,19 @@ read_into_cache(MapiHdl hdl, int lookahe
                        if (lookahead > 0 &&
                            (result->querytype == -1 /* unknown (not SQL) */ ||
                             result->querytype == Q_TABLE ||
-                            result->querytype == Q_UPDATE))
+                            result->querytype == Q_UPDATE)) {
+                               if (prev_handler && signal(SIGINT, 
prev_handler) == SIG_ERR) {
+                                       perror("mapi_execute_internal: Could 
not restore previous handler.");
+                               }
+
                                return mid->error;
+                       }
                        break;
                }
        }
+       if (prev_handler && signal(SIGINT, prev_handler) == SIG_ERR) {
+               perror("mapi_execute_internal: Could not restore previous 
handler.");
+       }
 }
 
 static MapiMsg
@@ -4514,6 +4552,7 @@ mapi_execute_internal(MapiHdl hdl)
        mnstr_flush(mid->to, MNSTR_FLUSH_DATA);
        check_stream(mid, mid->to, "write error on stream", mid->error);
        mid->active = hdl;
+
        return MOK;
 }
 
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to