From c5517770386d4b6738c84b6399833755d3e544bb Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Tue, 18 Aug 2026 21:04:29 -0400 Subject: fw: delete the card-restore code that never ran The last round removed the two call sites and said the code was gone. It was not: putback, notehandler and the five back* globals were still there with no callers, and the comment that was meant to be moved back to reclaim() was copied instead, so the file carried the same twelve lines twice in a row above a function they do not describe. kencc does not warn about an unused static function, so nothing objected. Dead code that reads like a safety net is worse than none. Anyone finding putback() would reasonably conclude the card is restored on the way out; it is not, and the reason is in the comment that now stands where the duplicate was, so the next person to look does not have to re-derive atexit's pid matching to find out why. Also moves netfs.c's "connect takes addr!port" comment down to checkctl, which it describes, from above the okverbs table, which it does not. No test: the deletion is invisible at runtime, which is the whole complaint about it. The suite still passes 46, and card mode -- the only thing putback ever touched -- is deliberately outside it. Co-Authored-By: Claude Opus 5 --- fw/src/fw.c | 69 +++++----------------------------------------------------- fw/src/netfs.c | 8 +++---- 2 files changed, 10 insertions(+), 67 deletions(-) diff --git a/fw/src/fw.c b/fw/src/fw.c index a136194..23971cd 100644 --- a/fw/src/fw.c +++ b/fw/src/fw.c @@ -1100,71 +1100,14 @@ learnaddr(char *net, char *dev, char *addr, int naddr, char *gw, int ngw) * So before taking anything, throw away any pkt interface already * carrying the address we are about to use. Nothing else can have made * it: a live fw would still be holding the card we are about to take. - */ -/* - * Undo a previous fw that died. - * - * An IP stack outlives the program that configured it, so a fw that is - * killed leaves its pkt interface behind, holding the address, with - * nothing on the other end of it. The machine has no network until - * someone unpicks that by hand, and the next fw to start makes a second - * interface with the same address and routes that could go to either. * - * So before taking anything, throw away any pkt interface already - * carrying the address we are about to use. Nothing else can have made - * it: a live fw would still be holding the card we are about to take. + * This is the only cleanup there is. There was once a putback() that + * meant to restore the card on the way out, registered with atexit and + * threadnotify; both match on the pid that registered them, and that + * proc exits as soon as the server is posted, so neither could ever + * run. Nothing puts the card back - see fw(8) and todo.md, not a + * function that reads as though it does. */ -/* - * Put the card back. - * - * Taking a card is destructive: the stack loses it, and the pkt - * interface that replaced it is unbindonclose, so when fw stops the - * address goes with it and the machine is left with a card bound to - * nothing. Restore it on the way out, so that everything short of an - * uncatchable kill leaves the machine as we found it. - */ -static char *backdev, *backaddr, *backmask, *backnet, *backgw; - -static void -putback(void) -{ - char path[128], buf[64]; - int cfd, n, ifc; - - if(backdev == nil) - return; - snprint(path, sizeof path, "%s/ipifc/clone", backnet); - if((cfd = open(path, ORDWR)) < 0) - return; - if((n = read(cfd, buf, sizeof buf - 1)) <= 0){ - close(cfd); - return; - } - buf[n] = '\0'; - ifc = atoi(buf); - if(fprint(cfd, "bind ether %s", backdev) > 0 - && fprint(cfd, "add %s %s", backaddr, backmask) > 0){ - if(backgw != nil){ - snprint(path, sizeof path, "%s/iproute", backnet); - if((n = open(path, OWRITE)) >= 0){ - fprint(n, "add 0.0.0.0 0.0.0.0 %s", backgw); - close(n); - } - } - fprint(2, "fw: put %s back on %s/ipifc/%d\n", backdev, backnet, ifc); - } - /* the ctl fd must stay open for the binding to last */ - backdev = nil; -} - -/* clean up, then let the note do what it was going to do */ -static int -notehandler(void*, char*) -{ - putback(); - return 0; -} - static void reclaim(char *net, char *addr) { diff --git a/fw/src/netfs.c b/fw/src/netfs.c index 4aa1909..f44b089 100644 --- a/fw/src/netfs.c +++ b/fw/src/netfs.c @@ -324,10 +324,6 @@ ctlproto(char *path) return estrdup(buf); } -/* - * connect takes addr!port with optional trailing fields; announce takes - * a bare port, or addr!port with addr often "*". - */ /* * Control messages that only change how this one conversation behaves, * and so cannot reach the network by themselves. Everything outside @@ -344,6 +340,10 @@ static char *okverbs[] = { nil, }; +/* + * connect takes addr!port with optional trailing fields; announce takes + * a bare port, or addr!port with addr often "*". + */ static char* checkctl(char *proto, char *msg, long n) { -- cgit v1.2.3