From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 27845 invoked from network); 7 Sep 2021 18:19:31 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 7 Sep 2021 18:19:31 -0000 Received: from wopr.sciops.net ([216.126.196.60]) by 4ess; Tue Sep 7 13:46:51 -0400 2021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sciops.net; s=20210706; t=1631036801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=QMGBhzkYhj/AMnsr7c023awsbB9GQO9h0unsI499SHo=; b=NMskYp0rBHmRLOUjerN/qhbud1iQjE51OaoM5d07A7pPo61MSstvHy0iW15Jw2H5lyvJI9 A3nid2Q3AHObLl84exs/FqT6SXGYbABtmTarx3g9jR7oln7tw6R09s6oZsSQk8V3q1nk2y 1UlZyoFFRS5ugvY86DjHAgHySPQGnk0= Received: by wopr.sciops.net (OpenSMTPD) with ESMTPSA id 960c6e79 (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO) for <9front@9front.org>; Tue, 7 Sep 2021 10:46:40 -0700 (PDT) Message-ID: Date: Tue, 07 Sep 2021 19:46:39 +0200 From: qwx@sciops.net To: 9front@9front.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: proven lifecycle proxy strategy Subject: [9front] plumber: remove $plumbsrv, add optional srvname, usage check Reply-To: 9front@9front.org Precedence: bulk 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;