Changeset: 2588a5ffc52c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2588a5ffc52c
Modified Files:
        monetdb5/misc/Makefile.ag
        monetdb5/misc/msabaoth.c
        monetdb5/misc/msabaoth.h
Branch: default
Log Message:

Merged from Dec2011


diffs (truncated from 606 to 300 lines):

diff --git a/NT/wincompile.py b/NT/wincompile.py
--- a/NT/wincompile.py
+++ b/NT/wincompile.py
@@ -76,4 +76,7 @@ p = subprocess.Popen(argv, shell = False
 out, err = p.communicate()
 sys.stdout.write(out.replace('\r\n', '\n'))
 sys.stderr.write(err.replace('\r\n', '\n'))
+if p.returncode and not verbose:
+    sys.stderr.write('failed invocation: %s\n' % ' '.join(argv))
+    sys.stderr.flush()
 sys.exit(p.returncode)
diff --git a/clients/ChangeLog.Dec2011 b/clients/ChangeLog.Dec2011
--- a/clients/ChangeLog.Dec2011
+++ b/clients/ChangeLog.Dec2011
@@ -1,6 +1,10 @@
 # ChangeLog file for clients
 # This file is updated with Maddlog
 
+* Wed Dec  7 2011 Fabian Groffen <[email protected]>
+- Fix making connections with stethoscope to hosts without monetdbd.
+  Bug #2944.
+
 * Tue Dec  6 2011 Fabian Groffen <[email protected]>
 - Fixed some bugs in the PHP interface affecting the mapi_ping(),
   monetdb_insert_id() and auto_commit() functions.  Bugs #2936, #2937,
diff --git a/clients/mapiclient/stethoscope.c b/clients/mapiclient/stethoscope.c
--- a/clients/mapiclient/stethoscope.c
+++ b/clients/mapiclient/stethoscope.c
@@ -238,6 +238,7 @@ doProfile(void *d)
        MapiHdl hdl = NULL;
 
        /* set up the profiler */
+       id[0] = '\0';
        dbh = mapi_mapiuri(wthr->uri, wthr->user, wthr->pass, "mal");
        if (dbh == NULL || mapi_error(dbh))
                die(dbh, hdl);
@@ -248,7 +249,6 @@ doProfile(void *d)
                snprintf(id, 10, "[%d] ", wthr->tid);
                printf("-- connection with server %s is %s\n", wthr->uri, id);
        } else {
-               id[0] = '\0';
                printf("-- connection with server %s\n", wthr->uri);
        }
 
@@ -437,7 +437,7 @@ main(int argc, char **argv)
                dbname = "";
        }
 
-       if (alts == NULL) {
+       if (alts == NULL || *alts == NULL) {
                /* nothing to redirect, so a single host to try */
                char uri[512];
                snprintf(uri, 512, "mapi:monetdb://%s:%d/%s", host, portnr, 
dbname);
@@ -465,31 +465,26 @@ main(int argc, char **argv)
        } else {
                /* fork runner threads for all alternatives */
                i = 1;
-               if (*alts != NULL) {
-                       walk = thds = malloc(sizeof(wthread));
-                       while (1) {
-                               walk->tid = i++;
-                               walk->uri = *alts;
-                               walk->user = user;
-                               walk->pass = password;
-                               walk->argc = argc - a;
-                               walk->argv = &argv[a];
-                               walk->s = NULL;
+               walk = thds = malloc(sizeof(wthread));
+               while (1) {
+                       walk->tid = i++;
+                       walk->uri = *alts;
+                       walk->user = user;
+                       walk->pass = password;
+                       walk->argc = argc - a;
+                       walk->argv = &argv[a];
+                       walk->s = NULL;
 #if !defined(HAVE_PTHREAD_H) && defined(_MSC_VER)
-                               walk->id = CreateThread(NULL, 0, doProfile, 
walk, 0, NULL);
+                       walk->id = CreateThread(NULL, 0, doProfile, walk, 0, 
NULL);
 #else
-                               pthread_create(&walk->id, NULL, &doProfile, 
walk);
+                       pthread_create(&walk->id, NULL, &doProfile, walk);
 #endif
-                               alts++;
-                               if (*alts == NULL)
-                                       break;
-                               walk = walk->next = malloc(sizeof(wthread));
-                       }
-                       walk->next = NULL;
-               } else {
-                       fprintf(stderr, "%s: no databases found for '%s'\n",
-                                       argv[0], dbname);
+                       alts++;
+                       if (*alts == NULL)
+                               break;
+                       walk = walk->next = malloc(sizeof(wthread));
                }
+               walk->next = NULL;
                free(oalts);
                for (walk = thds; walk != NULL; walk = walk->next) {
 #if !defined(HAVE_PTHREAD_H) && defined(_MSC_VER)
diff --git a/common/utils/Makefile.ag b/common/utils/Makefile.ag
--- a/common/utils/Makefile.ag
+++ b/common/utils/Makefile.ag
@@ -35,3 +35,8 @@ lib_muuid = {
        NOINST
        SOURCES = muuid.h muuid.c
 }
+
+lib_msabaoth = {
+       NOINST
+       SOURCES = msabaoth.h msabaoth.c
+}
diff --git a/monetdb5/misc/msabaoth.c b/common/utils/msabaoth.c
rename from monetdb5/misc/msabaoth.c
rename to common/utils/msabaoth.c
diff --git a/monetdb5/misc/msabaoth.h b/common/utils/msabaoth.h
rename from monetdb5/misc/msabaoth.h
rename to common/utils/msabaoth.h
diff --git a/java/src/nl/cwi/monetdb/merovingian/Control.java 
b/java/src/nl/cwi/monetdb/merovingian/Control.java
--- a/java/src/nl/cwi/monetdb/merovingian/Control.java
+++ b/java/src/nl/cwi/monetdb/merovingian/Control.java
@@ -19,9 +19,17 @@
 
 package nl.cwi.monetdb.merovingian;
 
-import java.io.*;
-import java.net.*;
-import java.util.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.net.Socket;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
 
 /**
  * A Control class to perform operations on a remote merovingian
@@ -31,7 +39,7 @@ import java.util.*;
  * possible actions against a merovingian server that has remote control
  * facilities enabled.
  * <br />
- * In the merovingian world, other merovingians in the vincinity are
+ * In the merovingian world, other merovingians in the vicinity are
  * known to each merovingian, allowing to perform cluster wide actions.
  * The implementation taken in this class is to require one known
  * merovingian to get insight in the entire network.  Note that
@@ -94,7 +102,7 @@ public class Control {
        
        final static private String RESPONSE_OK = "OK";
 
-       private String[] sendCommand(
+       private List<String> sendCommand(
                        String database, String command, boolean hasOutput)
                throws MerovingianException, IOException
        {
@@ -102,72 +110,65 @@ public class Control {
                PrintStream out = new PrintStream(s.getOutputStream());
                BufferedReader in = new BufferedReader(
                                new InputStreamReader(s.getInputStream()));
-               String response;
+               try {
+                       /* login ritual, step 1: get challenge from server */
+                       String response = in.readLine();
+                       if (response == null)
+                               throw new MerovingianException("server closed 
the connection");
+                       
+                       if (!response.startsWith("merovingian:1:") &&
+                                       !response.startsWith("merovingian:2:"))
+                               throw new MerovingianException("unsupported 
merovingian server");
+                       
+                       String[] tokens = response.split(":");
+                       if (tokens.length < 3)
+                               throw new MerovingianException("did not 
understand merovingian server");
+                       String version = tokens[1];
+                       String token = tokens[2];
 
-               /* login ritual, step 1: get challenge from server */
-               response = in.readLine();
-               if (!response.startsWith("merovingian:1:") &&
-                               !response.startsWith("merovingian:2:"))
-                       throw new MerovingianException("unsupported merovingian 
server");
-               String[] tokens = response.split(":");
-               String version = tokens[1];
-               String token = tokens[2];
+                       response = controlHash(passphrase, token);
+                       if (version.equals("1")) {
+                               out.print(response + "\n");
+                       } else if (version.equals("2")) {
+                               // we only support control mode for now
+                               out.print(response + ":control\n");
+                       }
+                       response = in.readLine();
+                       if (response == null) {
+                               throw new MerovingianException("server closed 
the connection");
+                       }
 
-               response = controlHash(passphrase, token);
-               if (version.equals("1")) {
-                       out.print(response + "\n");
-               } else if (version.equals("2")) {
-                       // we only support control mode for now
-                       out.print(response + ":control\n");
-               }
+                       if (!response.equals(RESPONSE_OK)) {
+                               throw new MerovingianException(response);
+                       }
 
-               response = in.readLine();
-               if (response == null) {
+                       /* send command, form is simple: "<db> <cmd>\n" */
+                       out.print(database + " " + command + "\n");
+
+                       /* Response has the first line either "OK\n" or an error
+                        * message.  In case of a command with output, the data 
will
+                        * follow the first line */
+                       response = in.readLine();
+                       if (response == null) {
+                               throw new MerovingianException("server closed 
the connection");
+                       }
+                       if (!response.equals(RESPONSE_OK)) {
+                               throw new MerovingianException(response);
+                       }
+
+                       if (!hasOutput)
+                               return null;
+
+                       ArrayList<String> l = new ArrayList<String>();
+                       while ((response = in.readLine()) != null) {
+                               l.add(response);
+                       }
+                       return l;
+               } finally {
                        in.close();
                        out.close();
                        s.close();
-                       throw new MerovingianException("server closed the 
connection");
                }
-               if (!response.equals(RESPONSE_OK)) {
-                       in.close();
-                       out.close();
-                       s.close();
-                       throw new MerovingianException(response);
-               }
-
-               /* send command, form is simple: "<db> <cmd>\n" */
-               out.print(database + " " + command + "\n");
-
-               /* Response has the first line either "OK\n" or an error
-                * message.  In case of a command with output, the data will
-                * follow the first line */
-               response = in.readLine();
-               if (response == null) {
-                       in.close();
-                       out.close();
-                       s.close();
-                       throw new MerovingianException("server closed the 
connection");
-               }
-               if (!response.equals(RESPONSE_OK)) {
-                       in.close();
-                       out.close();
-                       s.close();
-                       throw new MerovingianException(response);
-               }
-
-               String[] ret = null;
-               if (hasOutput) {
-                       ArrayList l = new ArrayList();
-                       while ((response = in.readLine()) != null) {
-                               l.add(response);
-                       }
-                       ret = (String[])(l.toArray(new String[l.size()]));
-               }
-
-               in.close();
-               out.close();
-               s.close();
-               return(ret);
        }
 
        public void start(String database)
@@ -253,18 +254,18 @@ public class Control {
                throws MerovingianException, IOException
        {
                Properties ret = new Properties();
-               String[] response = sendCommand(database, "get", true);
-               for (int i = 0; i < response.length; i++) {
-                       if (response[i].startsWith("#"))
+               List<String> response = sendCommand(database, "get", true);
+               for (String responseLine : response) {
+                       if (responseLine.startsWith("#"))
                                continue;
-                       int pos = response[i].indexOf("=");
+                       int pos = responseLine.indexOf("=");
                        if (pos > 0) {
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to