Changeset: 97501075b200 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=97501075b200
Modified Files:
        clients/Tests/exports.stable.out
        monetdb5/mal/mal.c
        monetdb5/mal/mal_client.c
        monetdb5/mal/mal_client.h
        monetdb5/mal/mal_debugger.c
        monetdb5/mal/mal_exception.c
        monetdb5/mal/mal_private.h
        monetdb5/mal/mal_session.c
        tools/mserver/mserver5.c
Branch: default
Log Message:

Don't call mal_exit() all over the place, and certainly not from interrupt 
handler.


diffs (truncated from 311 to 300 lines):

diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -1424,7 +1424,7 @@ void MCcloseClient(Client c);
 int MCdefault;
 Client MCforkClient(Client father);
 Client MCgetClient(int id);
-void MCinit(void);
+bool MCinit(void);
 Client MCinitClient(oid user, bstream *fin, stream *fout);
 int MCinitClientThread(Client c);
 int MCpushClientInput(Client c, bstream *new_input, int listing, char *prompt);
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -57,8 +57,12 @@ int mal_init(void){
 /* Any error encountered here terminates the process
  * with a message sent to stderr
  */
-       MCinit();
-       mdbInit();
+       if (!MCinit())
+               return -1;
+       if (!mdbInit()) {
+               mal_client_reset();
+               return -1;
+       }
        monet_memory = MT_npages() * MT_pagesize();
        initNamespace();
        initParser();
@@ -66,7 +70,14 @@ int mal_init(void){
        initHeartbeat();
 #endif
        initResource();
-       malBootstrap();
+       str err = malBootstrap();
+       if (err != MAL_SUCCEED) {
+               mal_client_reset();
+               mdbExit();
+               dumpExceptionsToStream(NULL, err);
+               freeException(err);
+               return -1;
+       }
        initProfiler();
        return 0;
 }
diff --git a/monetdb5/mal/mal_client.c b/monetdb5/mal/mal_client.c
--- a/monetdb5/mal/mal_client.c
+++ b/monetdb5/mal/mal_client.c
@@ -61,7 +61,7 @@ mal_client_reset(void)
                GDKfree(mal_clients);
 }
 
-void
+bool
 MCinit(void)
 {
        const char *max_clients = GDKgetenv("max_clients");
@@ -73,7 +73,7 @@ MCinit(void)
                maxclients = 64;
                if (GDKsetenv("max_clients", "64") != GDK_SUCCEED) {
                        fprintf(stderr,"#MCinit: GDKsetenv failed");
-                       mal_exit(1);
+                       return false;
                }
        }
 
@@ -83,10 +83,11 @@ MCinit(void)
        mal_clients = GDKzalloc(sizeof(ClientRec) * MAL_MAXCLIENTS);
        if( mal_clients == NULL){
                fprintf(stderr,"#MCinit:" MAL_MALLOC_FAIL);
-               mal_exit(1);
+               return false;
        }
        for (int i = 0; i < MAL_MAXCLIENTS; i++)
                ATOMIC_INIT(&mal_clients[i].lastprint, 0);
+       return true;
 }
 
 /* stack the files from which you read */
@@ -385,8 +386,8 @@ MCforkClient(Client father)
  * effects of sharing IO descriptors, also its children. Conversely, a
  * child can not close a parent.
  */
-static void
-freeClient(Client c)
+void
+MCfreeClient(Client c)
 {
        c->mode = FINISHCLIENT;
 
@@ -507,7 +508,7 @@ MCcloseClient(Client c)
 #endif
        /* free resources of a single thread */
        if (!isAdministrator(c)) {
-               freeClient(c);
+               MCfreeClient(c);
                return;
        }
 
diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h
--- a/monetdb5/mal/mal_client.h
+++ b/monetdb5/mal/mal_client.h
@@ -195,7 +195,7 @@ typedef struct CLIENT {
        char *query;                    /* string, identify whatever we're 
working on */
 } *Client, ClientRec;
 
-mal_export void    MCinit(void);
+mal_export bool    MCinit(void);
 
 mal_export int MAL_MAXCLIENTS;
 mal_export ClientRec *mal_clients;
diff --git a/monetdb5/mal/mal_debugger.c b/monetdb5/mal/mal_debugger.c
--- a/monetdb5/mal/mal_debugger.c
+++ b/monetdb5/mal/mal_debugger.c
@@ -60,7 +60,7 @@ static mdbStateRecord *mdbTable;
  * The debugger flags overview
  */
 
-void
+bool
 mdbInit(void)
 {
        /*
@@ -72,8 +72,9 @@ mdbInit(void)
        mdbTable = GDKzalloc(sizeof(mdbStateRecord) * MAL_MAXCLIENTS);
        if (mdbTable == NULL) {
                fprintf(stderr,"#mdbInit:" MAL_MALLOC_FAIL);
-               mal_exit(1);
+               return false;
        }
+       return true;
 }
 
 void
diff --git a/monetdb5/mal/mal_exception.c b/monetdb5/mal/mal_exception.c
--- a/monetdb5/mal/mal_exception.c
+++ b/monetdb5/mal/mal_exception.c
@@ -161,14 +161,21 @@ dumpExceptionsToStream(stream *out, str 
                        if (i - last > 0) { /* skip empty lines */
                                if (whatever[last] == '!') /* no need for 
double ! */
                                        last++;
-                               mnstr_printf(out, "!%s\n", whatever + last);
+                               if (out)
+                                       mnstr_printf(out, "!%s\n", whatever + 
last);
+                               else
+                                       fprintf(stderr, "!%s\n", whatever + 
last);
                        }
                        last = i + 1;
                }
        }
        /* flush last part */
-       if (i - last > 0) /* skip if empty */
-               mnstr_printf(out, "!%s\n", whatever + last);
+       if (i - last > 0) { /* skip if empty */
+               if (out)
+                       mnstr_printf(out, "!%s\n", whatever + last);
+               else
+                       fprintf(stderr, "!%s\n", whatever + last);
+       }
 }
 
 /**
diff --git a/monetdb5/mal/mal_private.h b/monetdb5/mal/mal_private.h
--- a/monetdb5/mal/mal_private.h
+++ b/monetdb5/mal/mal_private.h
@@ -16,6 +16,8 @@
 /* _MAL_CLIENT_H_ is defined in the same file as Client */
 __hidden void MCexitClient(Client c)
        __attribute__((__visibility__("hidden")));
+__hidden void MCfreeClient(Client c)
+       __attribute__((__visibility__("hidden")));
 __hidden int MCreadClient(Client c)
        __attribute__((__visibility__("hidden")));
 __hidden void MCpopClientInput(Client c)
@@ -51,7 +53,7 @@
 __hidden void setqptimeout(lng usecs)
        __attribute__((__visibility__("hidden")));
 
-__hidden void mdbInit(void)
+__hidden bool mdbInit(void)
        __attribute__((__visibility__("hidden")));
 __hidden void mdbExit(void)
        __attribute__((__visibility__("hidden")));
diff --git a/monetdb5/mal/mal_session.c b/monetdb5/mal/mal_session.c
--- a/monetdb5/mal/mal_session.c
+++ b/monetdb5/mal/mal_session.c
@@ -37,59 +37,43 @@ malBootstrap(void)
 {
        Client c;
        str msg = MAL_SUCCEED;
-       str bootfile = "mal_init", s = NULL;
+       str bootfile = "mal_init";
 
-       c = MCinitClient((oid) 0, 0, 0);
+       c = MCinitClient((oid) 0, NULL, NULL);
        if(c == NULL) {
-               fprintf(stderr,"#malBootstrap:Failed to initialise client");
-               mal_exit(1);
+               throw(MAL, "malBootstrap", "Failed to initialize client");
        }
        assert(c != NULL);
        c->curmodule = c->usermodule = userModule();
        if(c->usermodule == NULL) {
-               fprintf(stderr,"#malBootstrap:Failed to initialise client MAL 
module");
-               mal_exit(1);
+               MCfreeClient(c);
+               throw(MAL, "malBootstrap", "Failed to initialize client MAL 
module");
        }
        if ( (msg = defaultScenario(c)) ) {
-               fprintf(stderr,"#malBootstrap:Failed to initialise default 
scenario: %s", msg);
-               freeException(msg);
-               mal_exit(1);
+               MCfreeClient(c);
+               return msg;
        }
        if((msg = MSinitClientPrg(c, "user", "main")) != MAL_SUCCEED) {
-               fprintf(stderr,"#malBootstrap:Failed to initialise client: %s", 
msg);
-               freeException(msg);
-               mal_exit(1);
+               MCfreeClient(c);
+               return msg;
        }
        if( MCinitClientThread(c) < 0){
-               fprintf(stderr,"#malBootstrap:Failed to create client thread");
-               mal_exit(1);
+               MCfreeClient(c);
+               throw(MAL, "malBootstrap", "Failed to create client thread");
        }
-       s = malInclude(c, bootfile, 0);
-       if (s != NULL) {
-               fprintf(stderr, "!%s\n", s);
-               GDKfree(s);
-               mal_exit(1);
+       if ((msg = malInclude(c, bootfile, 0)) != MAL_SUCCEED) {
+               MCfreeClient(c);
+               return msg;
        }
        pushEndInstruction(c->curprg->def);
        chkProgram(c->usermodule, c->curprg->def);
        if ( (msg= c->curprg->def->errors) != MAL_SUCCEED ) {
-               mnstr_printf(c->fdout,"!%s%s",msg, (msg[strlen(msg)-1] == '\n'? 
"":"\n"));
-               mnstr_flush(c->fdout);
-               if( GDKerrbuf && GDKerrbuf[0]){
-                       mnstr_printf(c->fdout,"!GDKerror: %s\n",GDKerrbuf);
-                       mnstr_flush(c->fdout);
-               }
-#ifdef HAVE_EMBEDDED
+               MCfreeClient(c);
                return msg;
-#endif
        }
-       s = MALengine(c);
-       if (s != MAL_SUCCEED) {
-               GDKfree(s);
-#ifdef HAVE_EMBEDDED
-               return msg;
-#endif
-       }
+       msg = MALengine(c);
+       if (msg != MAL_SUCCEED)
+               MCfreeClient(c);
        return msg;
 }
 
diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c
--- a/tools/mserver/mserver5.c
+++ b/tools/mserver/mserver5.c
@@ -236,11 +236,18 @@ static void emergencyBreakpoint(void)
        /* just a handle to break after system initialization for GDB */
 }
 
+static volatile sig_atomic_t interrupted = 0;
+
 static void
 handler(int sig)
 {
        (void) sig;
-       mal_exit(-1);
+#ifdef HAVE_CONSOLE
+       if (!monet_daemon)
+               _Exit(-1);
+       else
+#endif
+               interrupted = 1;
 }
 
 int
@@ -713,6 +720,7 @@ main(int argc, char **av)
                GDKfree(monet_script[i]);
                monet_script[i] = 0;
        }
+       free(monet_script);
 
        if ((err = msab_registerStarted()) != NULL) {
                /* throw the error at the user, but don't die */
@@ -720,13 +728,12 @@ main(int argc, char **av)
                free(err);
        }
 
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to