summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Moody <moody@posixcafe.org>2022-05-28 02:34:43 +0000
committerJacob Moody <moody@posixcafe.org>2022-05-28 02:34:43 +0000
commit57fa781188eeab3f958f3c5cedab2bebc60f388e (patch)
tree8c9d931ef73880f0e5245e5b6d839cbf7e08458c
parent774529e440cfe570fbaf29e6e5c5c73345aa04a1 (diff)
aux/listen: Allow per service namespace files
-rw-r--r--rc/bin/service/!tcp80.namespace24
-rw-r--r--sys/man/8/listen8
-rw-r--r--sys/src/cmd/aux/listen.c20
3 files changed, 45 insertions, 7 deletions
diff --git a/rc/bin/service/!tcp80.namespace b/rc/bin/service/!tcp80.namespace
new file mode 100644
index 000000000..bb2f629df
--- /dev/null
+++ b/rc/bin/service/!tcp80.namespace
@@ -0,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
diff --git a/sys/man/8/listen b/sys/man/8/listen
index 6a597f614..2224c5b81 100644
--- a/sys/man/8/listen
+++ b/sys/man/8/listen
@@ -96,6 +96,14 @@ For example,
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
diff --git a/sys/src/cmd/aux/listen.c b/sys/src/cmd/aux/listen.c
index 36056dd69..c7834ff8b 100644
--- a/sys/src/cmd/aux/listen.c
+++ b/sys/src/cmd/aux/listen.c
@@ -136,6 +136,7 @@ listendir(char *srvdir, int trusted)
{
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 @@ listendir(char *srvdir, int trusted)
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 @@ listendir(char *srvdir, int trusted)
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 @@ scandir(char *dname)
continue;
if(strncmp(nm, proto, nlen) != 0)
continue;
+ if(strstr(nm + nlen, ".namespace") != nil)
+ continue;
addannounce(nm + nlen);
}
free(db);
@@ -329,15 +340,10 @@ becomenone(void)
}
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;