Changeset: 3fa6164e3adc for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=3fa6164e3adc
Modified Files:
        sql/src/backends/monet5/merovingian/merovingian.c
Branch: default
Log Message:

Merged from Jun2010


diffs (229 lines):

diff -r 19ba7a116100 -r 3fa6164e3adc MonetDB5/src/mal/mal_errors.mx
--- a/MonetDB5/src/mal/mal_errors.mx    Mon Jul 26 11:20:21 2010 +0200
+++ b/MonetDB5/src/mal/mal_errors.mx    Mon Jul 26 12:41:51 2010 +0200
@@ -98,7 +98,7 @@
 #define RUNTIME_OBJECT_UNDEFINED "Object not found"
 #define RUNTIME_UNKNOWN_INSTRUCTION "Instruction type not supported"
 #define RUNTIME_QRY_TIMEOUT "Query aborted due to timeout"
-#define OPERATION_FAILED "Operation failed"
+#define OPERATION_FAILED "operation failed"
 
 #define BOX_CLOSED "Box is not open"
 
diff -r 19ba7a116100 -r 3fa6164e3adc MonetDB5/src/modules/mal/mal_mapi.mx
--- a/MonetDB5/src/modules/mal/mal_mapi.mx      Mon Jul 26 11:20:21 2010 +0200
+++ b/MonetDB5/src/modules/mal/mal_mapi.mx      Mon Jul 26 12:41:51 2010 +0200
@@ -675,20 +675,20 @@
                usockfile = GDKstrdup(*Usockfile);
 #else
                usockfile = NULL;
-               throw(IO, "mal_mapi.listen", OPERATION_FAILED " Unix domain 
sockets are not supported");
+               throw(IO, "mal_mapi.listen", OPERATION_FAILED ": UNIX domain 
sockets are not supported");
 #endif
        }
        maxusers = *Maxusers;
        maxusers = (maxusers ? maxusers : SERVERMAXUSERS);
 
        if (port <= 0 && usockfile == NULL)
-               throw(IO, "mal_mapi.listen", OPERATION_FAILED " No port or 
socket file specified");
+               throw(IO, "mal_mapi.listen", OPERATION_FAILED ": no port or 
socket file specified");
 
        if (port > 0) {
                sock = socket(AF_INET, SOCK_STREAM, 0);
                if (sock == INVALID_SOCKET)
                        throw(IO, "mal_mapi.listen",
-                                       OPERATION_FAILED " Creation of stream 
socket failed: %s",
+                                       OPERATION_FAILED ": creation of stream 
socket failed: %s",
                                        strerror(errno));
 
                setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof 
on);
@@ -728,7 +728,7 @@
 
                if (getsockname(sock, (SOCKPTR) &server, &length) < 0)
                        throw(IO, "mal_mapi.listen",
-                                       OPERATION_FAILED " Failed getting 
socket name: %s",
+                                       OPERATION_FAILED ": failed getting 
socket name: %s",
                                        strerror(errno));
                listen(sock, maxusers);
        }
@@ -737,18 +737,26 @@
                usock = socket(AF_UNIX, SOCK_STREAM, 0);
                if (usock == INVALID_SOCKET ) {
                        throw(IO, "mal_mapi.listen",
-                                       OPERATION_FAILED " Creation of Unix 
socket failed: %s",
+                                       OPERATION_FAILED ": creation of UNIX 
socket failed: %s",
                                        strerror(errno));
                }
+
+               /* prevent silent truncation, sun_path is typically around 108
+                * chars long :/ */
+               if (strlen(usockfile) > sizeof(userver.sun_path))
+                       throw(MAL, "mal_mapi.listen",
+                                       OPERATION_FAILED ": UNIX socket path 
too long: %s",
+                                       usockfile);
+
                userver.sun_family = AF_UNIX;
                strncpy(userver.sun_path, usockfile, sizeof(userver.sun_path));
 
                length = (SOCKLEN) sizeof(userver);
                unlink(usockfile);
-               if (bind(usock, (SOCKPTR) & userver, length) < 0) {
+               if (bind(usock, (SOCKPTR) &userver, length) < 0) {
                        unlink(usockfile);
                        throw(IO, "mal_mapi.listen",
-                                       OPERATION_FAILED " Binding to Unix 
socket file %s failed: %s",
+                                       OPERATION_FAILED ": binding to UNIX 
socket file %s failed: %s",
                                        usockfile, strerror(errno));
                }
                listen(usock, maxusers);
@@ -771,7 +779,7 @@
        psock[2] = INVALID_SOCKET;
        if (MT_create_thread(pidp, (void (*)(void *)) SERVERlistenThread, 
psock) < 0) {
                GDKfree(psock);
-               throw(MAL, "mal_mapi.listen", OPERATION_FAILED " Starting 
thread failed");
+               throw(MAL, "mal_mapi.listen", OPERATION_FAILED ": starting 
thread failed");
        } 
 #ifdef DEBUG_SERVER
        gethostname(host, (int) 512);
@@ -936,7 +944,7 @@
                                l--;
                        }
                *f=0;
-               throw(MAL, "@1", OPERATION_FAILED " Remote error: %s", newerr);
+               throw(MAL, "@1", OPERATION_FAILED ": remote error: %s", newerr);
        }
 }
 @c
@@ -965,7 +973,7 @@
 
        if( i==MAXSESSIONS){
                mal_unset_lock(mal_contextLock,"SERVERconnect");
-               throw(IO, "mapi.connect", OPERATION_FAILED " Too many 
sessions");
+               throw(IO, "mapi.connect", OPERATION_FAILED ": too many 
sessions");
        }
        SERVERsessions[i].c= cntxt;
        SERVERsessions[i].key= ++sessionkey;
diff -r 19ba7a116100 -r 3fa6164e3adc 
sql/src/backends/monet5/merovingian/ChangeLog.Jun2010
--- a/sql/src/backends/monet5/merovingian/ChangeLog.Jun2010     Mon Jul 26 
11:20:21 2010 +0200
+++ b/sql/src/backends/monet5/merovingian/ChangeLog.Jun2010     Mon Jul 26 
12:41:51 2010 +0200
@@ -1,6 +1,10 @@
 # ChangeLog file for sql/src/backends/monet5/merovingian
 # This file is updated with mchangelog
 
+  26 Jul 2010; Fabian Groffen <fab...@cwi.nl> merovingian.c, monetdb.c:
+  On installs with (very) long prefixes, the UNIX domain sockets could get
+  truncated, causing merovingian to become unavailable to monetdb and mclient.
+
   21 Jul 2010; Fabian Groffen <fab...@cwi.nl> merovingian.c:
   Really shutdown when an argument to merovingian was given, instead of
   ending up in some inconsistent state.  This solves all weird behaviour
diff -r 19ba7a116100 -r 3fa6164e3adc 
sql/src/backends/monet5/merovingian/merovingian.c
--- a/sql/src/backends/monet5/merovingian/merovingian.c Mon Jul 26 11:20:21 
2010 +0200
+++ b/sql/src/backends/monet5/merovingian/merovingian.c Mon Jul 26 12:41:51 
2010 +0200
@@ -425,8 +425,9 @@
        str dbfarm, pidfilename;
        str p, prefix;
        FILE *cnf = NULL, *pidfile = NULL;
+       char *control_usock;
+       char *mapi_usock;
        char buf[1024];
-       char bufu[1024];
        dpair d = NULL;
        int pfd[2];
        int retfd = -1;
@@ -593,7 +594,7 @@
        }
 
        /* where is the mserver5 binary we fork on demand? */
-       snprintf(buf, 1023, "%s/bin/mserver5", prefix);
+       snprintf(buf, sizeof(buf), "%s/bin/mserver5", prefix);
        _mero_mserver = alloca(sizeof(char) * (strlen(buf) + 1));
        memcpy(_mero_mserver, buf, strlen(buf) + 1);
        /* exit early if this is not going to work well */
@@ -918,20 +919,20 @@
        Mfprintf(stdout, "monitoring dbfarm %s\n", dbfarm);
 
        SABAOTHinit(dbfarm, NULL);
+       GDKfree(dbfarm);
 
        /* set up control channel path */
-       snprintf(buf, 1024, "%s/.merovingian_control", dbfarm);
-       unlink(buf);
-       snprintf(bufu, 1024, "%s/mapi_socket", dbfarm);
-       unlink(bufu);
-       GDKfree(dbfarm);
+       control_usock = ".merovingian_control";
+       unlink(control_usock);
+       mapi_usock = "mapi_socket";
+       unlink(mapi_usock);
 
        /* open up connections */
        if (
                        (e = openConnectionTCP(&sock, _mero_port, stdout)) == 
NO_ERR &&
-                       (e = openConnectionUNIX(&socku, bufu, 0, stdout)) == 
NO_ERR &&
+                       (e = openConnectionUNIX(&socku, mapi_usock, 0, stdout)) 
== NO_ERR &&
                        (e = openConnectionUDP(&usock, discoveryport)) == 
NO_ERR &&
-                       (e = openConnectionUNIX(&unsock, buf, S_IRWXO, 
_mero_ctlout)) == NO_ERR &&
+                       (e = openConnectionUNIX(&unsock, control_usock, 
S_IRWXO, _mero_ctlout)) == NO_ERR &&
                        (_mero_controlport == 0 || (e = 
openConnectionTCP(&csock, _mero_controlport, _mero_ctlout)) == NO_ERR)
           )
        {
@@ -998,12 +999,12 @@
        }
 
        /* control channel is already closed at this point */
-       if (unlink(buf) == -1)
+       if (unlink(control_usock) == -1)
                Mfprintf(stderr, "unable to unlink control socket '%s': %s\n",
-                               buf, strerror(errno));
-       if (unlink(bufu) == -1)
+                               control_usock, strerror(errno));
+       if (unlink(mapi_usock) == -1)
                Mfprintf(stderr, "unable to unlink mapi socket '%s': %s\n",
-                               bufu, strerror(errno));
+                               mapi_usock, strerror(errno));
 
        if (e != NO_ERR) {
                /* console */
diff -r 19ba7a116100 -r 3fa6164e3adc 
sql/src/backends/monet5/merovingian/monetdb.c
--- a/sql/src/backends/monet5/merovingian/monetdb.c     Mon Jul 26 11:20:21 
2010 +0200
+++ b/sql/src/backends/monet5/merovingian/monetdb.c     Mon Jul 26 12:41:51 
2010 +0200
@@ -76,7 +76,6 @@
 
 static str dbfarm = NULL;
 static int mero_running = 0;
-static char mero_control[8096];
 static char *mero_host = NULL;
 static int mero_port = -1;
 static char *mero_pass = NULL;
@@ -1366,10 +1365,6 @@
                mero_running = 0;
        }
 
-       /* set path to control channel */
-       snprintf(mero_control, sizeof(mero_control),
-                       "%s/.merovingian_control", dbfarm);
-
        /* Start handling the arguments.
         * monetdb [monetdb_options] command [options] [database [...]]
         * this means we first scout for monetdb_options which stops as soon
@@ -1487,8 +1482,17 @@
        }
 
        /* use UNIX socket if no hostname given */
-       if (mero_host == NULL)
-               mero_host = mero_control;
+       if (mero_host == NULL) {
+               /* avoid overrunning the sun_path buffer by moving into the
+                * directory where the UNIX socket resides (sun_path is
+                * typically around 108 chars long) */
+               if (chdir(dbfarm) < 0) {
+                       fprintf(stderr, "monetdb: could not move to dbfarm 
'%s': %s\n",
+                                       dbfarm, strerror(errno));
+                       return(1);
+               }
+               mero_host = ".merovingian_control";
+       }
 
        /* handle regular commands */
        if (strcmp(argv[i], "create") == 0) {
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to