aux/listen: Allow per service namespace files

This commit is contained in:
Jacob Moody 2022-05-28 02:34:43 +00:00 committed by xfnw
parent 9fe925eaa5
commit 674fcda107
3 changed files with 45 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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;