No longer create a special process context to fork remote clients off

of, simply always rfork off of proc1 closing all descriptors, and have
the rump kernel open 0/1/2 if the parent process is "1".

Fixes tests/rump/rumpkernel/t_sp, which was failing since the
abovementioned special process change due to attempting to deliver a
signal to the special process and the special process was not equipped
to handle one.
This commit is contained in:
pooka 2014-08-25 14:58:48 +00:00
parent 386021af1d
commit b124cf15b4
3 changed files with 37 additions and 36 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpuser_sp.c,v 1.66 2014/06/14 11:52:42 pooka Exp $ */
/* $NetBSD: rumpuser_sp.c,v 1.67 2014/08/25 14:58:48 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.66 2014/06/14 11:52:42 pooka Exp $");
__RCSID("$NetBSD: rumpuser_sp.c,v 1.67 2014/08/25 14:58:48 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@ -957,7 +957,6 @@ schedulework(struct spclient *spc, enum sbatype sba_type)
struct spservarg {
int sps_sock;
connecthook_fn sps_connhook;
struct lwp *sps_l;
};
static void
@ -983,8 +982,11 @@ handlereq(struct spclient *spc)
/* XXX make sure it contains sensible chars? */
comm[commlen] = '\0';
/* make sure we fork off of proc1 */
_DIAGASSERT(lwproc_curlwp() == NULL);
if ((error = lwproc_rfork(spc,
RUMP_RFFDG, comm)) != 0) {
RUMP_RFFD_CLEAR, comm)) != 0) {
shutdown(spc->spc_fd, SHUT_RDWR);
}
@ -1049,7 +1051,8 @@ handlereq(struct spclient *spc)
* the wrong spc pointer. (yea, optimize
* interfaces some day if anyone cares)
*/
if ((error = lwproc_rfork(spc, 0, NULL)) != 0) {
if ((error = lwproc_rfork(spc,
RUMP_RFFD_SHARE, NULL)) != 0) {
send_error_resp(spc, reqno,
RUMPSP_ERR_RFORK_FAILED);
shutdown(spc->spc_fd, SHUT_RDWR);
@ -1109,7 +1112,7 @@ handlereq(struct spclient *spc)
* above) so we can safely use it here.
*/
lwproc_switch(spc->spc_mainlwp);
if ((error = lwproc_rfork(spc, RUMP_RFFDG, NULL)) != 0) {
if ((error = lwproc_rfork(spc, RUMP_RFFD_COPY, NULL)) != 0) {
DPRINTF(("rump_sp: fork failed: %d (%p)\n",error, spc));
send_error_resp(spc, reqno, RUMPSP_ERR_RFORK_FAILED);
lwproc_switch(NULL);
@ -1194,8 +1197,6 @@ spserver(void *arg)
int rv;
unsigned int nfds, maxidx;
lwproc_switch(sarg->sps_l);
for (idx = 0; idx < MAXCLI; idx++) {
pfdlist[idx].fd = -1;
pfdlist[idx].events = POLLIN;
@ -1320,7 +1321,6 @@ 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;
@ -1371,22 +1371,6 @@ rumpuser_sp_init(const char *url,
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 = lwproc_curlwp();
if ((error = lwproc_rfork(NULL, RUMP_RFFDG, "spserver")) != 0) {
fprintf(stderr, "rump_sp: rfork failed");
goto out;
}
sarg->sps_l = lwproc_curlwp();
lwproc_switch(calllwp);
if ((error = pthread_create(&pt, NULL, spserver, sarg)) != 0) {
fprintf(stderr, "rump_sp: cannot create wrkr thread\n");
goto out;

View File

@ -1,4 +1,4 @@
/* $NetBSD: cons.c,v 1.3 2013/09/08 04:37:17 pooka Exp $ */
/* $NetBSD: cons.c,v 1.4 2014/08/25 14:58:48 pooka Exp $ */
/*
* Copyright (c) 2013 Antti Kantee. All Rights Reserved.
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.3 2013/09/08 04:37:17 pooka Exp $");
__KERNEL_RCSID(0, "$NetBSD: cons.c,v 1.4 2014/08/25 14:58:48 pooka Exp $");
#include <sys/param.h>
#include <sys/file.h>
@ -75,13 +75,10 @@ rump_consdev_init(void)
struct file *fp;
int fd, error;
/*
* We want to open the descriptors for the implicit proc
* so that they get inherited by default to all processes.
*/
KASSERT(curproc->p_pid == 1);
KASSERT(fd_getfile(0) == NULL);
KASSERT(fd_getfile(1) == NULL);
KASSERT(fd_getfile(2) == NULL);
/* then, map a file descriptor to the device */
if ((error = fd_allocfile(&fp, &fd)) != 0)
panic("cons fd_allocfile failed: %d", error);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rump.c,v 1.310 2014/08/14 16:28:49 riastradh Exp $ */
/* $NetBSD: rump.c,v 1.311 2014/08/25 14:58:48 pooka Exp $ */
/*
* Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.310 2014/08/14 16:28:49 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.311 2014/08/25 14:58:48 pooka Exp $");
#include <sys/systm.h>
#define ELFSIZE ARCH_ELFSIZE
@ -656,16 +656,34 @@ rump_hyp_rfork(void *priv, int flags, const char *comm)
{
struct vmspace *newspace;
struct proc *p;
struct lwp *l;
int error;
bool initfds;
/*
* If we are forking off of pid 1, initialize file descriptors.
*/
l = curlwp;
if (l->l_proc->p_pid == 1) {
KASSERT(flags == RUMP_RFFD_CLEAR);
initfds = true;
} else {
initfds = false;
}
if ((error = rump_lwproc_rfork(flags)) != 0)
return error;
/*
* We forked in this routine, so cannot use curlwp (const)
*/
l = rump_lwproc_curlwp();
p = l->l_proc;
/*
* Since it's a proxy proc, adjust the vmspace.
* Refcount will eternally be 1.
*/
p = curproc;
newspace = kmem_zalloc(sizeof(*newspace), KM_SLEEP);
newspace->vm_refcnt = 1;
newspace->vm_map.pmap = priv;
@ -673,6 +691,8 @@ rump_hyp_rfork(void *priv, int flags, const char *comm)
p->p_vmspace = newspace;
if (comm)
strlcpy(p->p_comm, comm, sizeof(p->p_comm));
if (initfds)
rump_consdev_init();
return 0;
}