Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv28618
Modified Files:
ChangeLog merovingian.c merovingian_client.c
Log Message:
Implemented UNIX domain socket listening for Merovingian. This cannot be
disabled and is hardwired to be the mapi_socket file in the dbfarm
Index: merovingian_client.c
===================================================================
RCS file:
/cvsroot/monetdb/sql/src/backends/monet5/merovingian/merovingian_client.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- merovingian_client.c 16 Mar 2010 11:44:31 -0000 1.4
+++ merovingian_client.c 24 Mar 2010 12:51:18 -0000 1.5
@@ -18,7 +18,7 @@
*/
static err
-handleClient(int sock)
+handleClient(int sock, char isusock)
{
stream *fdin, *fout;
str buf = alloca(sizeof(char) * 8096);
@@ -222,7 +222,9 @@
return(e);
}
- if (getpeername(sock, (struct sockaddr *)&saddr, &saddrlen) == -1) {
+ if (isusock) {
+ host = "(local)";
+ } else if (getpeername(sock, (struct sockaddr *)&saddr, &saddrlen) ==
-1) {
Mfprintf(stderr, "couldn't get peername of client: %s\n",
strerror(errno));
host = "(unknown)";
@@ -298,7 +300,7 @@
stream_flush(fout);
/* wait for input, or disconnect in a proxy runner */
- if ((e = startProxy(fdin, fout,
+ if ((e = startProxy(sock, fdin, fout,
redirs[0].conns->val, host)) !=
NO_ERR)
{
/* we need to let the client login in order not to
violate
@@ -321,7 +323,7 @@
}
static str
-acceptConnections(int sock)
+acceptConnections(int sock, int usock)
{
str msg;
int retval;
@@ -333,8 +335,10 @@
/* handle socket connections */
FD_ZERO(&fds);
FD_SET(sock, &fds);
+ FD_SET(usock, &fds);
- retval = select(sock + 1, &fds, NULL, NULL, NULL);
+ retval = select((sock > usock ? sock : usock) + 1,
+ &fds, NULL, NULL, NULL);
if (retval == 0) {
/* nothing interesting has happened */
continue;
@@ -349,7 +353,7 @@
continue;
}
if (FD_ISSET(sock, &fds)) {
- if ((msgsock = accept(sock, (SOCKPTR) 0, (socklen_t *)
0)) < 0) {
+ if ((msgsock = accept(sock, (SOCKPTR)0, (socklen_t *)
0)) < 0) {
if (_mero_keep_listening == 0)
break;
if (errno != EINTR) {
@@ -358,9 +362,72 @@
}
continue;
}
+ } else if (FD_ISSET(usock, &fds)) {
+ struct msghdr msgh;
+ struct iovec iov;
+ char buf[1];
+ int rv;
+ char ccmsg[CMSG_SPACE(sizeof(int))];
+
+ if ((msgsock = accept(usock, (SOCKPTR)0, (socklen_t
*)0)) < 0) {
+ if (_mero_keep_listening == 0)
+ break;
+ if (errno != EINTR) {
+ msg = strerror(errno);
+ goto error;
+ }
+ continue;
+ }
+
+ /* BEWARE: unix domain sockets have a slightly different
+ * behaviour initialy than normal sockets, because we
can
+ * send filedescriptors or credentials with them. To
do so,
+ * we need to use sendmsg/recvmsg, which operates on a
bare
+ * socket. Unfortunately we *have* to send something,
so it
+ * is one byte that can optionally carry the ancillary
data.
+ * This byte is at this moment defined to contain a
character:
+ * '0' - there is no ancillary data
+ * '1' - ancillary data for passing a file descriptor
+ * The future may introduce a state for passing
credentials.
+ * Any unknown character must be interpreted as some
unknown
+ * action, and hence not supported by the server.
+ * Since there is no reason why one would like to pass
+ * descriptors to Merovingian, this is not implemented
here. */
+
+ iov.iov_base = buf;
+ iov.iov_len = 1;
+
+ msgh.msg_name = 0;
+ msgh.msg_namelen = 0;
+ msgh.msg_iov = &iov;
+ msgh.msg_iovlen = 1;
+ msgh.msg_control = ccmsg;
+ msgh.msg_controllen = sizeof(ccmsg);
+
+ rv = recvmsg(msgsock, &msgh, 0);
+ if (rv == -1) {
+ close(msgsock);
+ continue;
+ }
+
+ switch (*buf) {
+ case '0':
+ /* nothing special, nothing to do */
+ break;
+ case '1':
+ /* filedescriptor, no way */
+ close(msgsock);
+ Mfprintf(stderr, "client error: fd
passing not supported\n");
+ continue;
+ default:
+ /* some unknown state */
+ close(msgsock);
+ Mfprintf(stderr, "client error: unknown
initial byte\n");
+ continue;
+ }
} else
continue;
- e = handleClient(msgsock);
+ e = handleClient(msgsock, FD_ISSET(usock, &fds));
if (e != NO_ERR) {
Mfprintf(stderr, "client error: %s\n", getErrMsg(e));
freeErr(e);
Index: merovingian.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/merovingian.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- merovingian.c 16 Mar 2010 11:44:29 -0000 1.71
+++ merovingian.c 24 Mar 2010 12:51:17 -0000 1.72
@@ -426,6 +426,7 @@
str p, prefix;
FILE *cnf = NULL, *pidfile = NULL;
char buf[1024];
+ char bufu[1024];
sabdb* stats = NULL;
dpair d;
int pfd[2];
@@ -437,6 +438,7 @@
int usock = -1;
int unsock = -1;
int csock = -1;
+ int socku = -1;
char doproxy = 1;
unsigned short discoveryport;
struct stat sb;
@@ -896,6 +898,8 @@
/* 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);
/* open up connections */
@@ -903,6 +907,7 @@
(e = openConnectionTCP(&sock, _mero_port, stdout)) ==
NO_ERR &&
(e = openConnectionUDP(&usock, discoveryport)) ==
NO_ERR &&
(e = openConnectionUNIX(&unsock, buf)) == NO_ERR &&
+ (e = openConnectionUNIX(&socku, bufu)) == NO_ERR &&
(_mero_controlport == 0 || (e =
openConnectionTCP(&csock, _mero_controlport, _mero_ctlout)) == NO_ERR)
)
{
@@ -961,7 +966,7 @@
}
/* handle external connections main loop */
- e = acceptConnections(sock);
+ e = acceptConnections(sock, socku);
/* wait for the control runner and discovery thread to have
* finished announcing they're going down */
@@ -977,6 +982,7 @@
/* control channel is already closed at this point */
unlink(buf);
+ unlink(bufu);
if (e != NO_ERR) {
/* console */
Index: ChangeLog
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/ChangeLog,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- ChangeLog 17 Mar 2010 14:06:15 -0000 1.35
+++ ChangeLog 24 Mar 2010 12:51:17 -0000 1.36
@@ -1,6 +1,12 @@
# ChangeLog file for sql/src/backends/monet5
# This file is updated with mchangelog (Gentoo echangelog bastard script)
+ 24 Mar 2010; Fabian Groffen <[email protected]> merovingian.c,
+ merovingian_client.c:
+ Implemented UNIX domain socket listener for Merovingian, found as
+ mapi_socket in the dbfarm. Client connections can be made over it
+ like normal TCP connections.
+
17 Mar 2010; Fabian Groffen <[email protected]> merovingian_proxy.c:
When a proxy connection is made to a local UNIX domain socket, pass
on the filedescriptor instead of proxying.
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins