From: qwx@sciops.net
To: 9front@9front.org
Subject: [9front] plumber: remove $plumbsrv, add optional srvname, usage check
Date: Tue, 07 Sep 2021 19:46:39 +0200 [thread overview]
Message-ID: <AA80538B10AD48D91BEC0531F9C0FE64@wopr.sciops.net> (raw)
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. Thoughts?
Cheers,
qwx
diff 87a823332f9eaa4ff1e72f8524f6e59d1cc4f407 uncommitted
--- a//sys/man/4/plumber
+++ b//sys/man/4/plumber
@@ -6,6 +6,9 @@
[
.B -p
.I plumbing
+] [
+.B -s
+.I srvname
]
.SH DESCRIPTION
The
@@ -31,11 +34,17 @@
and a set of output
.I ports
for dispatching messages to applications.
+.PP
The service is also published as a
.IR srv (4)
-file, named in
-.BR $plumbsrv ,
+file,
+.IR srvname ,
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
Programs use
.B write
--- a//sys/src/cmd/plumb/fsys.c
+++ b//sys/src/cmd/plumb/fsys.c
@@ -218,9 +218,10 @@
clock = getclock();
if(cexecpipe(&mntfd, &srvfd) < 0)
error("can't create pipe: %r");
- sprint(srvfile, "/srv/plumb.%s.%d", user, getpid());
- if(putenv("plumbsrv", srvfile) < 0)
- error("can't write $plumbsrv: %r");
+ if(srvname == nil)
+ snprint(srvfile, sizeof(srvfile), "/srv/plumb.%s.%d", user, getpid());
+ else
+ snprint(srvfile, sizeof(srvfile), "/srv/%s", srvname);
fd = create(srvfile, OWRITE|OCEXEC|ORCLOSE, 0600);
if(fd < 0)
error("can't create /srv file: %r");
--- a//sys/src/cmd/plumb/plumber.c
+++ b//sys/src/cmd/plumb/plumber.c
@@ -15,6 +15,7 @@
int printerrors=1;
jmp_buf parsejmp;
char *lasterror;
+char *srvname;
void
makeports(Ruleset *rules[])
@@ -38,6 +39,13 @@
}
void
+usage(void)
+{
+ fprint(2, "usage: %s [-p plumbfile] [-s srvname]\n", argv0);
+ exits("usage");
+}
+
+void
threadmain(int argc, char *argv[])
{
char buf[512];
@@ -48,7 +56,13 @@
ARGBEGIN{
case 'p':
- plumbfile = ARGF();
+ plumbfile = EARGF(usage());
+ break;
+ case 's':
+ srvname = EARGF(usage());
+ break;
+ default:
+ usage();
break;
}ARGEND
--- a//sys/src/cmd/plumb/plumber.h
+++ b//sys/src/cmd/plumb/plumber.h
@@ -92,3 +92,4 @@
char *lasterror;
char **ports;
int nports;
+char *srvname;
next reply other threads:[~2021-09-07 18:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-07 17:46 qwx [this message]
2021-09-07 22:06 ` umbraticus
2021-09-08 8:51 ` sirjofri
2021-09-08 14:18 ` ori
2021-09-08 14:29 ` kvik
2021-09-08 17:35 ` qwx
2021-09-09 15:07 ` kvik
2021-09-09 15:21 ` kvik
2021-09-09 18:05 ` qwx
2021-09-09 18:16 ` qwx
2021-09-10 21:05 ` qwx
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AA80538B10AD48D91BEC0531F9C0FE64@wopr.sciops.net \
--to=qwx@sciops.net \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).