Module Name: src
Committed By: pooka
Date: Fri May 23 11:04:03 UTC 2014
Modified Files:
src/lib/librumpuser: rumpuser_sp.c
Log Message:
Create remote clients with standard file descriptors open. Fixes at
least editing a new file with ed in rumpremote (because ed calls
isatty(0) in case a file does not exist).
To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/lib/librumpuser/rumpuser_sp.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/librumpuser/rumpuser_sp.c
diff -u src/lib/librumpuser/rumpuser_sp.c:1.63 src/lib/librumpuser/rumpuser_sp.c:1.64
--- src/lib/librumpuser/rumpuser_sp.c:1.63 Fri Feb 28 13:55:36 2014
+++ src/lib/librumpuser/rumpuser_sp.c Fri May 23 11:04:03 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_sp.c,v 1.63 2014/02/28 13:55:36 pooka Exp $ */
+/* $NetBSD: rumpuser_sp.c,v 1.64 2014/05/23 11:04:03 pooka Exp $ */
/*
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
@@ -37,7 +37,7 @@
#include "rumpuser_port.h"
#if !defined(lint)
-__RCSID("$NetBSD: rumpuser_sp.c,v 1.63 2014/02/28 13:55:36 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.64 2014/05/23 11:04:03 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@@ -957,6 +957,7 @@ schedulework(struct spclient *spc, enum
struct spservarg {
int sps_sock;
connecthook_fn sps_connhook;
+ struct lwp *sps_l;
};
static void
@@ -983,7 +984,7 @@ handlereq(struct spclient *spc)
comm[commlen] = '\0';
if ((error = lwproc_rfork(spc,
- RUMP_RFCFDG, comm)) != 0) {
+ RUMP_RFFDG, comm)) != 0) {
shutdown(spc->spc_fd, SHUT_RDWR);
}
@@ -1193,6 +1194,8 @@ spserver(void *arg)
int rv;
unsigned int nfds, maxidx;
+ rump_pub_lwproc_switch(sarg->sps_l);
+
for (idx = 0; idx < MAXCLI; idx++) {
pfdlist[idx].fd = -1;
pfdlist[idx].events = POLLIN;
@@ -1317,6 +1320,7 @@ rumpuser_sp_init(const char *url,
pthread_t pt;
struct spservarg *sarg;
struct sockaddr *sap;
+ struct lwp *calllwp;
char *p;
unsigned idx = 0; /* XXXgcc */
int error, s;
@@ -1361,13 +1365,28 @@ rumpuser_sp_init(const char *url,
fprintf(stderr, "rump_sp: server bind failed\n");
goto out;
}
-
if (listen(s, MAXCLI) == -1) {
error = errno;
fprintf(stderr, "rump_sp: server listen failed\n");
goto out;
}
+ /*
+ * Create a context that the client threads run off of.
+ * We fork a dedicated context so as to ensure that all
+ * client threads get the same set of fd's. We fork off
+ * of whatever context the caller is running in (most likely
+ * an implicit thread, i.e. proc 1) and do not
+ * close fd's. The assumption is that people who
+ * write servers (i.e. "kernels") know what they're doing.
+ */
+ calllwp = rump_pub_lwproc_curlwp();
+ if ((error = rump_pub_lwproc_rfork(RUMP_RFFDG)) != 0) {
+ fprintf(stderr, "rump_sp: rfork failed");
+ goto out;
+ }
+ sarg->sps_l = rump_pub_lwproc_curlwp();
+ rump_pub_lwproc_switch(calllwp);
if ((error = pthread_create(&pt, NULL, spserver, sarg)) != 0) {
fprintf(stderr, "rump_sp: cannot create wrkr thread\n");
goto out;
@@ -1389,8 +1408,8 @@ rumpuser_sp_fini(void *arg)
}
/*
- * stuff response into the socket, since this process is just
- * about to exit
+ * stuff response into the socket, since the rump kernel container
+ * is just about to exit
*/
if (spc && spc->spc_syscallreq)
send_syscall_resp(spc, spc->spc_syscallreq, 0, retval);
@@ -1399,4 +1418,9 @@ rumpuser_sp_fini(void *arg)
shutdown(spclist[0].spc_fd, SHUT_RDWR);
spfini = 1;
}
+
+ /*
+ * could release thread, but don't bother, since the container
+ * will be stone dead in a moment.
+ */
}