ref: 57fa781188eeab3f958f3c5cedab2bebc60f388e
parent: 774529e440cfe570fbaf29e6e5c5c73345aa04a1
author: Jacob Moody <moody@posixcafe.org>
date: Fri May 27 22:34:43 EDT 2022
aux/listen: Allow per service namespace files
--- /dev/null
+++ b/rc/bin/service/!tcp80.namespace
@@ -1,0 +1,24 @@
+mount -aC #s/boot /root $rootspec
+
+# kernel devices
+bind #c /dev
+bind #d /fd
+bind -c #e /env
+bind #p /proc
+bind -a #l /net
+bind -a #I /net
+
+bind /root/$cputype/bin /bin
+bind /root/rc /rc
+bind -a /rc/bin /bin
+
+chdev Mcde|pslI/
+
+# grab just our webroot
+bind /root/usr/web /srv
+
+# or bind in the actual root
+# bind -a /root /
+
+unmount /root
+chdev -r Ms
--- a/sys/man/8/listen
+++ b/sys/man/8/listen
@@ -96,6 +96,14 @@
an inbound call on the TCP network for port 565 executes service
.BR tcp565 .
.PP
+Services may have individual
+.IR namespace (6)
+files specified within
+.IR srvdir .
+If provided, the namespace is used as the parent for each connection
+to the corresponding service. Namespace files are found by appending a .namespace
+suffix to the service name.
+.PP
At least the following services are available in
.BR /bin/service .
.TF \ tcp0000
--- a/sys/src/cmd/aux/listen.c
+++ b/sys/src/cmd/aux/listen.c
@@ -136,6 +136,7 @@
{
int ctl, pid, start;
char dir[40], err[128], ds[128];
+ char prog[Maxpath], serv[Maxserv], ns[Maxpath];
long childs;
Announce *a;
Waitmsg *wm;
@@ -178,6 +179,10 @@
sleep((pid*10)%200);
snprint(ds, sizeof ds, "%s!%s!%s", protodir, addr, a->a);
+ snprint(serv, sizeof serv, "%s%s", proto, a->a);
+ snprint(prog, sizeof prog, "%s/%s", srvdir, serv);
+ snprint(ns, sizeof ns, "%s.namespace", prog);
+
whined = a->whined;
/* a process per service */
@@ -201,7 +206,11 @@
else
exits("ctl");
}
- dolisten(dir, ctl, srvdir, a->a, &childs);
+ procsetname("%s %s", dir, ds);
+ if(!trusted)
+ if(newns("none", ns) < 0)
+ syslog(0, listenlog, "can't build namespace %s: %r\n", ns);
+ dolisten(dir, ctl, serv, prog, &childs);
close(ctl);
}
default:
@@ -299,6 +308,8 @@
continue;
if(strncmp(nm, proto, nlen) != 0)
continue;
+ if(strstr(nm + nlen, ".namespace") != nil)
+ continue;
addannounce(nm + nlen);
}
free(db);
@@ -329,15 +340,10 @@
}
void
-dolisten(char *dir, int ctl, char *srvdir, char *port, long *pchilds)
+dolisten(char *dir, int ctl, char *serv, char *prog, long *pchilds)
{
char ndir[40], wbuf[64];
- char prog[Maxpath], serv[Maxserv];
int nctl, data, wfd, nowait;
-
- procsetname("%s %s!%s!%s", dir, proto, addr, port);
- snprint(serv, sizeof serv, "%s%s", proto, port);
- snprint(prog, sizeof prog, "%s/%s", srvdir, serv);
wfd = -1;
nowait = RFNOWAIT;