Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv21904
Modified Files:
Makefile.ag monetdb.c monetdb_merocom.c
Added Files:
control.c control.h
Log Message:
factor out control command sending into a separate file, needs to still
implement TCP stuff, also still needs to merge back monetdb_merocom.c into
monetdb.c
--- NEW FILE: control.h ---
/*
* The contents of this file are subject to the MonetDB Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is the MonetDB Database System.
*
* The Initial Developer of the Original Code is CWI.
* Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
* Copyright August 2008-2009 MonetDB B.V.
* All Rights Reserved.
*/
#ifndef _SEEN_CONTROL_H
#define _SEEN_CONTROL_H 1
char* control_send(
char** ret,
char* host,
int port,
char* database,
char* command);
#endif
U Makefile.ag
Index: Makefile.ag
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/Makefile.ag,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- Makefile.ag 20 Aug 2009 10:46:50 -0000 1.6
+++ Makefile.ag 27 Aug 2009 15:14:52 -0000 1.7
@@ -24,8 +24,11 @@
$(MONETDB_INCS)
EXTRA_DIST = $(man_MANS) \
- utils.h properties.h glob.h \
- database.h
+ utils.h \
+ properties.h \
+ glob.h \
+ database.h \
+ control.h
lib_meroutil = {
NOINST
@@ -33,7 +36,8 @@
utils.c \
properties.c \
glob.c \
- database.c
+ database.c \
+ control.c
}
bin_merovingian = {
--- NEW FILE: control.c ---
/*
* The contents of this file are subject to the MonetDB Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://monetdb.cwi.nl/Legal/MonetDBLicense-1.1.html
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is the MonetDB Database System.
*
* The Initial Developer of the Original Code is CWI.
* Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
* Copyright August 2008-2009 MonetDB B.V.
* All Rights Reserved.
*/
#include "sql_config.h"
#include <stdio.h>
#include <unistd.h> /* close */
#include <string.h> /* strerror */
#include <sys/socket.h> /* socket */
#ifdef HAVE_SYS_UN_H
#include <sys/un.h> /* sockaddr_un */
#endif
#include <errno.h>
#define SOCKPTR struct sockaddr *
/* Sends command for database to merovingian listening at host and port.
* If host is a path, and port is 0, a UNIX socket connection for host
* is opened. The response of merovingian is returned as a malloced
* string.
* TODO: implement TCP connect
*/
char* control_send(
char** ret,
char* host,
int port,
char* database,
char* command)
{
char buf[8096];
int sock = -1;
struct sockaddr_un server;
size_t len;
(void)port;
/* UNIX socket connect */
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
snprintf(buf, sizeof(buf), "cannot open connection: %s\n",
strerror(errno));
return(strdup(buf));
}
memset(&server, 0, sizeof(struct sockaddr_un));
server.sun_family = AF_UNIX;
strncpy(server.sun_path, host, sizeof(server.sun_path) - 1);
if (connect(sock, (SOCKPTR) &server, sizeof(struct sockaddr_un))) {
snprintf(buf, sizeof(buf), "cannot connect: %s\n",
strerror(errno));
return(strdup(buf));
}
len = snprintf(buf, sizeof(buf), "%s %s\n", database, command);
send(sock, buf, len, 0);
if ((len = recv(sock, buf, sizeof(buf), 0)) <= 0)
return(strdup("no response from merovingian\n"));
buf[len] = '\0';
close(sock);
*ret = strdup(buf);
return(NULL);
}
U monetdb.c
Index: monetdb.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/monetdb.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- monetdb.c 20 Aug 2009 16:12:02 -0000 1.33
+++ monetdb.c 27 Aug 2009 15:14:52 -0000 1.34
@@ -38,6 +38,7 @@
#include "properties.h"
#include "glob.h"
#include "database.h"
+#include "control.h"
#include <stdlib.h> /* exit, getenv */
#include <stdarg.h> /* variadic stuff */
#include <stdio.h> /* fprintf, rename */
U monetdb_merocom.c
Index: monetdb_merocom.c
===================================================================
RCS file:
/cvsroot/monetdb/sql/src/backends/monet5/merovingian/monetdb_merocom.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- monetdb_merocom.c 19 Aug 2009 13:41:08 -0000 1.1
+++ monetdb_merocom.c 27 Aug 2009 15:14:52 -0000 1.2
@@ -23,15 +23,15 @@
KILL,
SHARE
} merocom;
+/* CREATE,
+ DESTROY */
static void
command_merocom(int argc, char *argv[], merocom mode)
{
int doall = 0;
char path[8096];
- int sock = -1;
- struct sockaddr_un server;
- char buf[256];
+ char *res;
int i;
err e;
sabdb *orig;
@@ -102,20 +102,6 @@
exit(1);
}
- if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- fprintf(stderr, "%s: cannot open connection: %s\n",
- type, 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, "%s: cannot connect: %s\n",
- type, strerror(errno));
- exit(2);
- }
-
if (doall == 1) {
/* don't even look at the arguments, because we are instructed
* to list all known databases */
@@ -156,21 +142,14 @@
if (stats->state == SABdbRunning) {
printf("%s%sing database '%s'... ", type, mode
== STOP ? "p" : "", stats->dbname);
fflush(stdout);
- len = snprintf(buf, sizeof(buf),
- "%s %s\n", stats->dbname, type);
- send(sock, buf, len, 0);
- if ((len = recv(sock, buf, sizeof(buf), 0)) <=
0) {
- fprintf(stderr, "\n%s: no response from
merovingian\n",
- type);
- exit(2);
- }
- buf[len] = '\0';
- if (strcmp(buf, "OK\n") == 0) {
+ control_send(&res, path, 0, stats->dbname,
type);
+ if (strcmp(res, "OK\n") == 0) {
printf("done\n");
} else {
- printf("FAILED:\n%s", buf);
+ printf("FAILED:\n%s", res);
ret = 1;
}
+ free(res);
} else if (doall != 1) {
printf("%s: database is not running: %s\n",
type, stats->dbname);
}
@@ -178,48 +157,35 @@
if (stats->state != SABdbRunning) {
printf("starting database '%s'... ",
stats->dbname);
fflush(stdout);
- len = snprintf(buf, sizeof(buf),
- "%s %s\n", stats->dbname, type);
- send(sock, buf, len, 0);
- if ((len = recv(sock, buf, sizeof(buf), 0)) <=
0) {
- fprintf(stderr, "\n%s: no response from
merovingian\n",
- type);
- exit(2);
- }
- buf[len] = '\0';
- if (strcmp(buf, "OK\n") == 0) {
+ control_send(&res, path, 0, stats->dbname,
type);
+ if (strcmp(res, "OK\n") == 0) {
printf("done\n");
} else {
- printf("FAILED:\n%s", buf);
+ printf("FAILED:\n%s", res);
ret = 1;
}
+ free(res);
} else if (doall != 1 && stats->state == SABdbRunning) {
printf("%s: database is already running: %s\n",
type, stats->dbname);
}
} else if (mode == SHARE) {
char *value = argv[1];
+ char share[4069];
/* stay quiet, we're part of monetdb set property=value
*/
- len = snprintf(buf, sizeof(buf),
- "%s share=%s\n", stats->dbname, value);
- send(sock, buf, len, 0);
- if ((len = recv(sock, buf, sizeof(buf), 0)) <= 0) {
- fprintf(stderr, "\n%s: no response from
merovingian\n",
- type);
- exit(2);
- }
- buf[len] = '\0';
- if (strcmp(buf, "OK\n") != 0) {
- printf("FAILED:\n%s", buf);
+
+ len = snprintf(share, sizeof(share), "share=%s", value);
+ control_send(&res, path, 0, stats->dbname, share);
+ if (strcmp(res, "OK\n") != 0) {
+ printf("FAILED:\n%s", res);
ret = 1;
}
+ free(res);
}
stats = stats->next;
}
- close(sock);
-
if (orig != NULL)
SABAOTHfreeStatus(&orig);
------------------------------------------------------------------------------
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