plumber: remove $plumbsrv, add optional srvname, usage check

Plumber both posts a service to /srv and sets a $plumbsrv environment
variable.  Our libplumb no longer uses $plumbsrv and nothing else
does.  It's a silly hack;  rc doesn't update /env immediately, and
scripts, which for instance set up subrios, cannot rely on it to
clean up the plumber at the end.

Instead, add the option to specify a srvname, actually check for some
common errors and print a usage string.

Thanks to Ori for input and a preliminary patch.
This commit is contained in:
qwx 2021-09-10 21:03:47 +00:00
parent d1986d8c0e
commit e279699344
4 changed files with 31 additions and 6 deletions

View file

@ -6,6 +6,9 @@ plumber \- file system for interprocess messaging
[ [
.B -p .B -p
.I plumbing .I plumbing
] [
.B -s
.I srvname
] ]
.SH DESCRIPTION .SH DESCRIPTION
The The
@ -31,11 +34,17 @@ and
and a set of output and a set of output
.I ports .I ports
for dispatching messages to applications. for dispatching messages to applications.
.PP
The service is also published as a The service is also published as a
.IR srv (4) .IR srv (4)
file, named in file,
.BR $plumbsrv , .IR srvname ,
for mounting elsewhere. for mounting elsewhere.
By default, its name is a dot-separated concatenation
of the program's name and a process id.
A different one can be specified via the
.B -s
option.
.PP .PP
Programs use Programs use
.B write .B write

View file

@ -218,9 +218,10 @@ startfsys(void)
clock = getclock(); clock = getclock();
if(cexecpipe(&mntfd, &srvfd) < 0) if(cexecpipe(&mntfd, &srvfd) < 0)
error("can't create pipe: %r"); error("can't create pipe: %r");
sprint(srvfile, "/srv/plumb.%s.%d", user, getpid()); if(srvname == nil)
if(putenv("plumbsrv", srvfile) < 0) snprint(srvfile, sizeof(srvfile), "/srv/plumb.%s.%d", user, getpid());
error("can't write $plumbsrv: %r"); else
snprint(srvfile, sizeof(srvfile), "/srv/%s", srvname);
fd = create(srvfile, OWRITE|OCEXEC|ORCLOSE, 0600); fd = create(srvfile, OWRITE|OCEXEC|ORCLOSE, 0600);
if(fd < 0) if(fd < 0)
error("can't create /srv file: %r"); error("can't create /srv file: %r");

View file

@ -15,6 +15,7 @@ Ruleset **rules;
int printerrors=1; int printerrors=1;
jmp_buf parsejmp; jmp_buf parsejmp;
char *lasterror; char *lasterror;
char *srvname;
void void
makeports(Ruleset *rules[]) makeports(Ruleset *rules[])
@ -37,6 +38,13 @@ mainproc(void *v)
sendp(c, nil); sendp(c, nil);
} }
void
usage(void)
{
fprint(2, "usage: %s [-p plumbfile] [-s srvname]\n", argv0);
exits("usage");
}
void void
threadmain(int argc, char *argv[]) threadmain(int argc, char *argv[])
{ {
@ -48,7 +56,13 @@ threadmain(int argc, char *argv[])
ARGBEGIN{ ARGBEGIN{
case 'p': case 'p':
plumbfile = ARGF(); plumbfile = EARGF(usage());
break;
case 's':
srvname = EARGF(usage());
break;
default:
usage();
break; break;
}ARGEND }ARGEND

View file

@ -92,3 +92,4 @@ jmp_buf parsejmp;
char *lasterror; char *lasterror;
char **ports; char **ports;
int nports; int nports;
char *srvname;