Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv32291

Modified Files:
        monetdb_discover.c 
Log Message:
use control_send to retrieve discovery list


U monetdb_discover.c
Index: monetdb_discover.c
===================================================================
RCS file: 
/cvsroot/monetdb/sql/src/backends/monet5/merovingian/monetdb_discover.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- monetdb_discover.c  19 Aug 2009 13:41:08 -0000      1.1
+++ monetdb_discover.c  14 Sep 2009 18:18:31 -0000      1.2
@@ -21,12 +21,8 @@
 command_discover(int argc, char *argv[])
 {
        char path[8096];
-       int sock = -1;
-       struct sockaddr_un server;
-       char buf[256];
+       char *buf;
        char *p, *q;
-       int len;
-       int pos;
        size_t twidth = TERMWIDTH;
        char location[twidth + 1];
        char *match = NULL;
@@ -55,82 +51,43 @@
        snprintf(path, 8095, "%s/.merovingian_control", dbfarm);
        path[8095] = '\0';
 
-       if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
-               fprintf(stderr, "discover: cannot open connection: %s\n",
-                               strerror(errno));
-               exit(2);
-       }
-       memset(&server, 0, sizeof(struct sockaddr_un));
-       server.sun_family = AF_UNIX;
-       strncpy(server.sun_path, path, sizeof(server.sun_path) - 1);
-       if (connect(sock, (SOCKPTR) &server, sizeof(struct sockaddr_un))) {
-               fprintf(stderr, "discover: cannot connect: %s\n", 
strerror(errno));
-               exit(2);
-       }
-
        /* Send the pass phrase to unlock the information available in
         * merovingian.  Anelosimus eximius is a social species of spiders,
         * which help each other, just like merovingians do among each
         * other. */
-       len = snprintf(buf, sizeof(buf), "anelosimus eximius\n");
-       send(sock, buf, len, 0);
-       pos = 0;
-       len = 0;
-       buf[len] = '\0';
-       do {
-               if ((p = strchr(buf, '\n')) == NULL) {
-                       if (len == sizeof(buf) - 1) {
-                               /* no newline in this block, too large, warn 
and discard */
-                               printf("discover: WARNING: discarding (too 
long?) line: %s\n",
-                                               buf);
-                               pos = 0;
-                       } else {
-                               pos = len;
-                       }
-                       len = recv(sock, buf + pos, sizeof(buf) - 1 - pos, 0);
-                       /* if there is no more... */
-                       if (len == 0) {
-                               break;
-                       } else if (len < 0) {
-                               fprintf(stderr, "discover: error while reading "
-                                               "from merovingian\n");
-                               exit(2);
-                       }
-                       len += pos;
-                       buf[len] = '\0';
-                       continue;
-               }
-               *p++ = '\0';
-
-               if ((q = strchr(buf, '\t')) == NULL) {
-                       /* doesn't look correct */
-                       printf("discover: WARNING: discarding incorrect line: 
%s\n", buf);
-                       len -= p - buf;
-                       memmove(buf, p, len + 1 /* include \0 */);
-                       continue;
-               }
-               *q++ = '\0';
+       p = control_send(&buf, path, -1, "anelosimus", "eximius");
+       if (p != NULL) {
+               printf("FAILED:\n%s\n", p);
+               free(p);
+               return;
+       }
 
-               snprintf(path, sizeof(path), "%s%s", q, buf);
+       if ((p = strtok(buf, "\n")) != NULL) {
+               do {
+                       if ((q = strchr(p, '\t')) == NULL) {
+                               /* doesn't look correct */
+                               printf("discover: WARNING: discarding incorrect 
line: %s\n", p);
+                               continue;
+                       }
+                       *q++ = '\0';
 
-               if (match == NULL || glob(match, path)) {
-                       /* cut too long location name */
-                       abbreviateString(location, path, twidth);
-                       /* store what we found */
-                       if (posloc == numlocs)
-                               locations = realloc(locations,
-                                               sizeof(char) * (numlocs = 
numlocs * 2));
-                       locations[posloc++] = strdup(location);
-                       if (strlen(location) > loclen)
-                               loclen = strlen(location);
-               }
+                       snprintf(path, sizeof(path), "%s%s", q, p);
 
-               /* move it away */
-               len -= p - buf;
-               memmove(buf, p, len + 1 /* include \0 */);
-       } while (1);
+                       if (match == NULL || glob(match, path)) {
+                               /* cut too long location name */
+                               abbreviateString(location, path, twidth);
+                               /* store what we found */
+                               if (posloc == numlocs)
+                                       locations = realloc(locations,
+                                                       sizeof(char) * (numlocs 
= numlocs * 2));
+                               locations[posloc++] = strdup(location);
+                               if (strlen(location) > loclen)
+                                       loclen = strlen(location);
+                       }
+               } while ((p = strtok(NULL, "\n")) != NULL);
+       }
 
-       close(sock);
+       free(buf);
 
        if (posloc > 0) {
                printf("%*slocation\n",


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to