Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib support HANDSHAKE_EXEC
details: https://anonhg.NetBSD.org/src/rev/3df660b8bf7d
branches: trunk
changeset: 762083:3df660b8bf7d
user: pooka <pooka%NetBSD.org@localhost>
date: Tue Feb 15 10:37:07 2011 +0000
description:
support HANDSHAKE_EXEC
diffstat:
lib/librumpclient/rumpclient.c | 56 +++++++++++++++++++++++++----------------
lib/librumpuser/rumpuser_sp.c | 51 ++++++++++++++++++++++++++++++--------
lib/librumpuser/sp_common.c | 4 +-
3 files changed, 76 insertions(+), 35 deletions(-)
diffs (300 lines):
diff -r 30dcd5e9fa72 -r 3df660b8bf7d lib/librumpclient/rumpclient.c
--- a/lib/librumpclient/rumpclient.c Tue Feb 15 10:35:39 2011 +0000
+++ b/lib/librumpclient/rumpclient.c Tue Feb 15 10:37:07 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpclient.c,v 1.28 2011/02/14 14:56:23 pooka Exp $ */
+/* $NetBSD: rumpclient.c,v 1.29 2011/02/15 10:37:07 pooka Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@@ -84,7 +84,7 @@
static sigset_t fullset;
static int doconnect(bool);
-static int handshake_req(struct spclient *, uint32_t *, int, bool);
+static int handshake_req(struct spclient *, int, void *, int, bool);
time_t retrytimo = RUMPCLIENT_RETRYCONN_ONCE;
@@ -146,7 +146,8 @@
if ((rv = doconnect(false)) != 0)
continue;
- if ((rv = handshake_req(&clispc, NULL, 0, true)) != 0)
+ if ((rv = handshake_req(&clispc, HANDSHAKE_GUEST,
+ NULL, 0, true)) != 0)
continue;
/*
@@ -305,7 +306,8 @@
}
static int
-handshake_req(struct spclient *spc, uint32_t *auth, int cancel, bool haslock)
+handshake_req(struct spclient *spc, int type, void *data,
+ int cancel, bool haslock)
{
struct handshake_fork rf;
struct rsp_hdr rhdr;
@@ -314,7 +316,7 @@
size_t bonus;
int rv;
- if (auth) {
+ if (type == HANDSHAKE_FORK) {
bonus = sizeof(rf);
} else {
bonus = strlen(getprogname())+1;
@@ -324,10 +326,7 @@
rhdr.rsp_len = sizeof(rhdr) + bonus;
rhdr.rsp_class = RUMPSP_REQ;
rhdr.rsp_type = RUMPSP_HANDSHAKE;
- if (auth)
- rhdr.rsp_handshake = HANDSHAKE_FORK;
- else
- rhdr.rsp_handshake = HANDSHAKE_GUEST;
+ rhdr.rsp_handshake = type;
pthread_sigmask(SIG_SETMASK, &fullset, &omask);
if (haslock)
@@ -335,8 +334,8 @@
else
putwait(spc, &rw, &rhdr);
rv = dosend(spc, &rhdr, sizeof(rhdr));
- if (auth) {
- memcpy(rf.rf_auth, auth, AUTHLEN*sizeof(*auth));
+ if (type == HANDSHAKE_FORK) {
+ memcpy(rf.rf_auth, data, sizeof(rf.rf_auth)); /* uh, why? */
rf.rf_cancel = cancel;
rv = send_with_recon(spc, &rf, sizeof(rf));
} else {
@@ -710,12 +709,19 @@
}
void *(*rumpclient_dlsym)(void *, const char *);
+static int init_done = 0;
int
rumpclient_init()
{
char *p;
int error;
+ int rv = -1;
+ int hstype;
+
+ if (init_done)
+ return 0;
+ init_done = 1;
sigfillset(&fullset);
@@ -753,38 +759,43 @@
if ((p = getenv("RUMP__PARSEDSERVER")) == NULL) {
if ((p = getenv("RUMP_SERVER")) == NULL) {
errno = ENOENT;
- return -1;
+ goto out;
}
}
if ((error = parseurl(p, &serv_sa, &ptab_idx, 0)) != 0) {
errno = error;
- return -1;
+ goto out;
}
if (doinit() == -1)
- return -1;
+ goto out;
if ((p = getenv("RUMPCLIENT__EXECFD")) != NULL) {
sscanf(p, "%d,%d", &clispc.spc_fd, &kq);
unsetenv("RUMPCLIENT__EXECFD");
- return 0;
+ hstype = HANDSHAKE_EXEC;
+ } else {
+ if (doconnect(true) == -1)
+ goto out;
+ hstype = HANDSHAKE_GUEST;
}
- if (doconnect(true) == -1)
- return -1;
-
- error = handshake_req(&clispc, NULL, 0, false);
+ error = handshake_req(&clispc, hstype, NULL, 0, false);
if (error) {
pthread_mutex_destroy(&clispc.spc_mtx);
pthread_cond_destroy(&clispc.spc_cv);
if (clispc.spc_fd != -1)
host_close(clispc.spc_fd);
errno = error;
- return -1;
+ goto out;
}
+ rv = 0;
- return 0;
+ out:
+ if (rv == -1)
+ init_done = 0;
+ return rv;
}
struct rumpclient_fork {
@@ -836,7 +847,8 @@
if (doconnect(false) == -1)
return -1;
- error = handshake_req(&clispc, rpf->fork_auth, 0, false);
+ error = handshake_req(&clispc, HANDSHAKE_FORK, rpf->fork_auth,
+ 0, false);
if (error) {
pthread_mutex_destroy(&clispc.spc_mtx);
pthread_cond_destroy(&clispc.spc_cv);
diff -r 30dcd5e9fa72 -r 3df660b8bf7d lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c Tue Feb 15 10:35:39 2011 +0000
+++ b/lib/librumpuser/rumpuser_sp.c Tue Feb 15 10:37:07 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_sp.c,v 1.40 2011/02/08 11:21:22 pooka Exp $ */
+/* $NetBSD: rumpuser_sp.c,v 1.41 2011/02/15 10:37:07 pooka Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: rumpuser_sp.c,v 1.40 2011/02/08 11:21:22 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.41 2011/02/15 10:37:07 pooka Exp $");
#include <sys/types.h>
#include <sys/atomic.h>
@@ -85,7 +85,7 @@
static char banner[MAXBANNER];
#define PROTOMAJOR 0
-#define PROTOMINOR 2
+#define PROTOMINOR 3
struct prefork {
uint32_t pf_auth[AUTHLEN];
@@ -195,6 +195,14 @@
return p;
}
+static void
+lwproc_execnotify(const char *comm)
+{
+
+ spops.spop_schedule();
+ spops.spop_execnotify(comm);
+ spops.spop_unschedule();
+}
static void
lwproc_procexit(void)
@@ -770,11 +778,13 @@
{
struct sysbouncearg *sba;
pthread_t pt;
+ uint64_t reqno;
int retries, error, i;
+ reqno = spc->spc_hdr.rsp_reqno;
if (__predict_false(spc->spc_state == SPCSTATE_NEW)) {
if (spc->spc_hdr.rsp_type != RUMPSP_HANDSHAKE) {
- send_error_resp(spc, spc->spc_hdr.rsp_reqno, EAUTH);
+ send_error_resp(spc, reqno, EAUTH);
shutdown(spc->spc_fd, SHUT_RDWR);
spcfreebuf(spc);
return;
@@ -799,15 +809,13 @@
spc->spc_mainlwp = lwproc_curlwp();
- send_handshake_resp(spc, spc->spc_hdr.rsp_reqno, 0);
+ send_handshake_resp(spc, reqno, 0);
} else if (spc->spc_hdr.rsp_handshake == HANDSHAKE_FORK) {
struct lwp *tmpmain;
struct prefork *pf;
struct handshake_fork *rfp;
- uint64_t reqno;
int cancel;
- reqno = spc->spc_hdr.rsp_reqno;
if (spc->spc_off-HDRSZ != sizeof(*rfp)) {
send_error_resp(spc, reqno, EINVAL);
shutdown(spc->spc_fd, SHUT_RDWR);
@@ -880,11 +888,9 @@
if (__predict_false(spc->spc_hdr.rsp_type == RUMPSP_PREFORK)) {
struct prefork *pf;
- uint64_t reqno;
uint32_t auth[AUTHLEN];
DPRINTF(("rump_sp: prefork handler executing for %p\n", spc));
- reqno = spc->spc_hdr.rsp_reqno;
spcfreebuf(spc);
pf = malloc(sizeof(*pf));
@@ -925,8 +931,31 @@
return;
}
+ if (__predict_false(spc->spc_hdr.rsp_type == RUMPSP_HANDSHAKE)) {
+ char *comm = (char *)spc->spc_buf;
+ size_t commlen = spc->spc_hdr.rsp_len - HDRSZ;
+
+ if (spc->spc_hdr.rsp_handshake != HANDSHAKE_EXEC) {
+ send_error_resp(spc, reqno, EINVAL);
+ spcfreebuf(spc);
+ return;
+ }
+
+ /* ensure it's 0-terminated */
+ /* XXX make sure it contains sensible chars? */
+ comm[commlen] = '\0';
+
+ lwproc_switch(spc->spc_mainlwp);
+ lwproc_execnotify(comm);
+ lwproc_switch(NULL);
+
+ send_handshake_resp(spc, reqno, 0);
+ spcfreebuf(spc);
+ return;
+ }
+
if (__predict_false(spc->spc_hdr.rsp_type != RUMPSP_SYSCALL)) {
- send_error_resp(spc, spc->spc_hdr.rsp_reqno, EINVAL);
+ send_error_resp(spc, reqno, EINVAL);
spcfreebuf(spc);
return;
}
@@ -934,7 +963,7 @@
retries = 0;
while ((sba = malloc(sizeof(*sba))) == NULL) {
if (nworker == 0 || retries > 10) {
- send_error_resp(spc, spc->spc_hdr.rsp_reqno, EAGAIN);
+ send_error_resp(spc, reqno, EAGAIN);
spcfreebuf(spc);
return;
}
diff -r 30dcd5e9fa72 -r 3df660b8bf7d lib/librumpuser/sp_common.c
--- a/lib/librumpuser/sp_common.c Tue Feb 15 10:35:39 2011 +0000
+++ b/lib/librumpuser/sp_common.c Tue Feb 15 10:37:07 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sp_common.c,v 1.27 2011/02/14 14:56:23 pooka Exp $ */
+/* $NetBSD: sp_common.c,v 1.28 2011/02/15 10:37:07 pooka Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@@ -91,7 +91,7 @@
RUMPSP_PREFORK,
RUMPSP_RAISE };
-enum { HANDSHAKE_GUEST, HANDSHAKE_AUTH, HANDSHAKE_FORK };
+enum { HANDSHAKE_GUEST, HANDSHAKE_AUTH, HANDSHAKE_FORK, HANDSHAKE_EXEC };
#define AUTHLEN 4 /* 128bit fork auth */
Home |
Main Index |
Thread Index |
Old Index