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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 9788 invoked from network); 13 Aug 2021 01:42:37 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 13 Aug 2021 01:42:37 -0000 Received: from mail-il1-f178.google.com ([209.85.166.178]) by 1ess; Thu Aug 12 21:12:24 -0400 2021 Received: by mail-il1-f178.google.com with SMTP id x7so9122837ilh.10 for <9front@9front.org>; Thu, 12 Aug 2021 18:12:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:organization:mime-version; bh=JMnEbEPimSph+ukUKhvnDvzR0Y0RVBxcvuf4M4xmdgA=; b=lDRVs9Tykmx2FvuCaJeWRsvaAani9LCUGbAjqpSf0N6KP+52M/rcL7YqFgztFfxOb9 iYLX0oYiU+oqvC17DMGVkD8nRayH4NqwTO+et7LVyY8wB82yde7U+0AZpAKZ2S1vOnH6 Ajsfv8Po7/q9JRc0lQJrqMEJJqMxn+Tvn9+GBhygptWjIgGR8uXQqGtlMVkkXseZTxyC mSvLuMPDW/2D2kzk0MU/bB9MvKEe2fJf0UCrZLLWCxRiTAdQWGhNKZ7zAQfCvhKcX+bi sWK9BSsjZXomxbopeEikbVmUhuq538uEJpReVNRK2AizbOx2DI/xW4yOJ6J+ow98mlOu MFng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:organization :mime-version; bh=JMnEbEPimSph+ukUKhvnDvzR0Y0RVBxcvuf4M4xmdgA=; b=f/a4BfkvMZSROW0si8neHMIyIOFjyTbjRZh22CHZIXHkmmEeeWLRH4ymb/RrSdK4MY F0pCUkOmSVchm1vypTVBjyDiL600hoMedoALR5K3I+0qprsueHZnhzTQ6wsZFm8TR8xh YUGThlCy2fiXuWV6nk3cgaK8Gb1uAhw+8YuPRA6HIhCzDrNqnb/g1CF/LXas6+x5QFxY GNjCwlUqhes6k2UNOQcjaRpgwPzJomw23rQ+wnFSU3j05gsF/sFEfR4IFwyzrjkmwfWo n/HOxYGNylX9Oz7TxSFZBO+CKSj8SQVPrHdwLP9BmuTdznPRqruOV3zSd70WrrRuA8Rk lBxw== X-Gm-Message-State: AOAM533vPoePP4QjGJJ55KTtZ+mD1c1VRUd93DRqUj6UjBoeyWDkjk1g BJJF8oZIwpuw2rLOoq/BP4Pjz0LWqGY= X-Google-Smtp-Source: ABdhPJwikTFamxYd2GRTFU+lPSqvir0A/NxL1/RnpyhYxraLlbN4ZnxP+yweOAqkLXsii8Hz8yEJtw== X-Received: by 2002:a92:d112:: with SMTP id a18mr925690ilb.34.1628817128750; Thu, 12 Aug 2021 18:12:08 -0700 (PDT) Return-Path: Received: from spruce.localdomain ([2601:246:4e03:dc20::575f]) by smtp.gmail.com with ESMTPSA id b15sm2511454ilq.27.2021.08.12.18.12.08 for <9front@9front.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Aug 2021 18:12:08 -0700 (PDT) Date: Thu, 12 Aug 2021 20:11:55 -0500 From: Amavect To: 9front@9front.org Message-ID: <20210812201155.4d837b73@spruce.localdomain> Organization: Amavect Industries X-Mailer: Claws Mail 4.0.0 (GTK+ 3.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/jYMl=wkeSPOGDEc2r.JWj3A" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: decentralized lifecycle template blockchain-scale table optimizer Subject: [9front] exportfs: fix debug logging Reply-To: 9front@9front.org Precedence: bulk --MP_/jYMl=wkeSPOGDEc2r.JWj3A Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline All, Exportfs -d might not be able to create the debug file without permission. Instead of letting execution continue, patch 1 makes it fail. Patch 2 replaces the DFD macro with an int dfd, simplifying code by 3 lines. Depends on patch 1. Thanks, Amavect --MP_/jYMl=wkeSPOGDEc2r.JWj3A Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=create.1.diff --- //.git/fs/object/bf6769d3f09d51ff1096afa664c10d3313341a75/tree/sys/src/cmd/exportfs/exportfs.c +++ sys/src/cmd/exportfs/exportfs.c @@ -19,12 +19,12 @@ main(int argc, char **argv) { char *dbfile, *srv, *srvfdfile; - int n; dbfile = "/tmp/exportdb"; srv = nil; srvfd = -1; srvfdfile = nil; + int n; ARGBEGIN{ case 'd': @@ -84,6 +84,8 @@ if(dbg) { n = create(dbfile, OWRITE|OTRUNC, 0666); + if(n < 0) + fatal("cannot create debug log: %r", dbfile); dup(n, DFD); close(n); } --MP_/jYMl=wkeSPOGDEc2r.JWj3A Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=nomacro.2.diff --- //.git/fs/object/633dcc8c1cbdc9191e50c3639d8c908fafa32470/tree/sys/src/cmd/exportfs/exportfs.c +++ sys/src/cmd/exportfs/exportfs.c @@ -24,7 +24,6 @@ srv = nil; srvfd = -1; srvfdfile = nil; - int n; ARGBEGIN{ case 'd': @@ -83,14 +82,12 @@ exclusions(); if(dbg) { - n = create(dbfile, OWRITE|OTRUNC, 0666); - if(n < 0) + dfd = create(dbfile, OWRITE|OTRUNC, 0666); + if(dfd < 0) fatal("cannot create debug log: %r", dbfile); - dup(n, DFD); - close(n); } - DEBUG(DFD, "exportfs: started\n"); + DEBUG(dfd, "exportfs: started\n"); rfork(RFNOTEG|RFREND); @@ -108,13 +105,13 @@ char ebuf[ERRMAX]; ebuf[0] = '\0'; errstr(ebuf, sizeof ebuf); - DEBUG(DFD, "chdir(\"%s\"): %s\n", srv, ebuf); + DEBUG(dfd, "chdir(\"%s\"): %s\n", srv, ebuf); mounterror(ebuf); } - DEBUG(DFD, "invoked as server for %s", srv); + DEBUG(dfd, "invoked as server for %s", srv); } - DEBUG(DFD, "\niniting root\n"); + DEBUG(dfd, "\niniting root\n"); initroot(); io(); } --- //.git/fs/object/633dcc8c1cbdc9191e50c3639d8c908fafa32470/tree/sys/src/cmd/exportfs/exportfs.h +++ sys/src/cmd/exportfs/exportfs.h @@ -3,7 +3,6 @@ */ #define DEBUG if(!dbg){}else fprint -#define DFD 9 #define fidhash(s) fhash[s%FHASHSIZE] typedef struct Fsrpc Fsrpc; @@ -86,6 +85,7 @@ char Enopsmt[]; Extern int dbg; +Extern int dfd; Extern File *root; Extern File *psmpt; Extern Fid **fhash; --- //.git/fs/object/633dcc8c1cbdc9191e50c3639d8c908fafa32470/tree/sys/src/cmd/exportfs/exportsrv.c +++ sys/src/cmd/exportfs/exportsrv.c @@ -65,7 +65,7 @@ w = m->busy; if(w != nil && w->work.tag == t->work.oldtag) { w->flushtag = t->work.tag; - DEBUG(DFD, "\tset flushtag %d\n", t->work.tag); + DEBUG(dfd, "\tset flushtag %d\n", t->work.tag); postnote(PNPROC, m->pid, "flush"); unlock(m); putsbuf(t); @@ -75,7 +75,7 @@ } reply(&t->work, &rhdr, 0); - DEBUG(DFD, "\tflush reply\n"); + DEBUG(dfd, "\tflush reply\n"); putsbuf(t); } @@ -359,7 +359,7 @@ } path = makepath(f->f, ""); - DEBUG(DFD, "\tremove: %s\n", path); + DEBUG(dfd, "\tremove: %s\n", path); if(remove(path) < 0) { free(path); errstr(err, sizeof err); @@ -518,7 +518,7 @@ if(p == nil) /* Swept */ break; - DEBUG(DFD, "\tslave: %d %F\n", m->pid, &p->work); + DEBUG(dfd, "\tslave: %d %F\n", m->pid, &p->work); if(p->flushtag != NOTAG) goto flushme; @@ -629,7 +629,7 @@ } path = makepath(f->f, ""); - DEBUG(DFD, "\topen: %s %d\n", path, work->mode); + DEBUG(dfd, "\topen: %s %d\n", path, work->mode); f->fid = open(path, work->mode); free(path); if(f->fid < 0 || (d = dirfstat(f->fid)) == nil) { @@ -646,7 +646,7 @@ goto Error; } - DEBUG(DFD, "\topen: fd %d\n", f->fid); + DEBUG(dfd, "\topen: fd %d\n", f->fid); f->mode = work->mode; f->offset = 0; rhdr.iounit = getiounit(f->fid); @@ -688,7 +688,7 @@ reply(work, &rhdr, err); return; } - DEBUG(DFD, "\tread: fd=%d %d bytes\n", f->fid, r); + DEBUG(dfd, "\tread: fd=%d %d bytes\n", f->fid, r); rhdr.data = data; rhdr.count = r; @@ -720,7 +720,7 @@ return; } - DEBUG(DFD, "\twrite: %d bytes fd=%d\n", n, f->fid); + DEBUG(dfd, "\twrite: %d bytes fd=%d\n", n, f->fid); rhdr.count = n; reply(work, &rhdr, 0); --- //.git/fs/object/633dcc8c1cbdc9191e50c3639d8c908fafa32470/tree/sys/src/cmd/exportfs/io.c +++ sys/src/cmd/exportfs/io.c @@ -49,7 +49,7 @@ if(convM2S(r->buf, n, &r->work) != n) fatal("convM2S format error"); - DEBUG(DFD, "%F\n", &r->work); + DEBUG(dfd, "%F\n", &r->work); (fcalls[r->work.type])(r); } } @@ -69,7 +69,7 @@ else t->type = r->type + 1; - DEBUG(DFD, "\t%F\n", t); + DEBUG(dfd, "\t%F\n", t); data = malloc(messagesize); /* not mallocz; no need to clear */ if(data == nil) @@ -224,7 +224,7 @@ while(--f->ref == 0){ freecnt++; - DEBUG(DFD, "free %s\n", f->name); + DEBUG(dfd, "free %s\n", f->name); /* delete from parent */ parent = f->parent; if(parent->child == f) @@ -250,7 +250,7 @@ char *path; File *f; - DEBUG(DFD, "\tfile: 0x%p %s name %s\n", parent, parent->name, name); + DEBUG(dfd, "\tfile: 0x%p %s name %s\n", parent, parent->name, name); path = makepath(parent, name); if(patternfile != nil && excludefile(path)){ @@ -429,17 +429,17 @@ } path = d->qid.path; while(qidexists(path)){ - DEBUG(DFD, "collision on %s\n", d->name); + DEBUG(dfd, "collision on %s\n", d->name); /* collision: find a new one */ ncollision++; path &= QIDPATH; ++newqid; if(newqid >= (1<<16)){ - DEBUG(DFD, "collision wraparound\n"); + DEBUG(dfd, "collision wraparound\n"); newqid = 1; } path |= newqid<<48; - DEBUG(DFD, "assign qid %.16llux\n", path); + DEBUG(dfd, "assign qid %.16llux\n", path); } qidcnt++; q = emallocz(sizeof(Qidtab)); @@ -472,7 +472,7 @@ postnote(PNPROC, m->pid, "kill"); if(s != nil) { - DEBUG(DFD, "%s\n", buf); + DEBUG(dfd, "%s\n", buf); sysfatal("%s", buf); /* caution: buf could contain '%' */ } else exits(nil); --- //.git/fs/object/633dcc8c1cbdc9191e50c3639d8c908fafa32470/tree/sys/src/cmd/exportfs/oexportfs.c +++ sys/src/cmd/exportfs/oexportfs.c @@ -59,7 +59,7 @@ strecpy(strrchr(addr, '!'), addr+sizeof(addr), s); } - DEBUG(DFD, "filter: %s\n", addr); + DEBUG(dfd, "filter: %s\n", addr); snprint(buf, sizeof(buf), "%s", cmd); argc = tokenize(buf, argv, nelem(argv)-3); @@ -256,7 +256,7 @@ if(dbg) { n = create(dbfile, OWRITE|OTRUNC, 0666); - dup(n, DFD); + dup(n, dfd); close(n); } @@ -265,7 +265,7 @@ usage(); } - DEBUG(DFD, "%s: started\n", argv0); + DEBUG(dfd, "%s: started\n", argv0); rfork(RFNOTEG|RFREND); @@ -289,10 +289,10 @@ if(chdir(srv) < 0) { ebuf[0] = '\0'; errstr(ebuf, sizeof ebuf); - DEBUG(DFD, "chdir(\"%s\"): %s\n", srv, ebuf); + DEBUG(dfd, "chdir(\"%s\"): %s\n", srv, ebuf); mounterror(ebuf); } - DEBUG(DFD, "invoked as server for %s", srv); + DEBUG(dfd, "invoked as server for %s", srv); strncpy(buf, srv, sizeof buf); } else { @@ -301,7 +301,7 @@ if(n < 0) { errstr(buf, sizeof buf); fprint(0, "read(0): %s\n", buf); - DEBUG(DFD, "read(0): %s\n", buf); + DEBUG(dfd, "read(0): %s\n", buf); exits(buf); } buf[n] = 0; @@ -308,15 +308,15 @@ if(chdir(buf) < 0) { errstr(ebuf, sizeof ebuf); fprint(0, "chdir(%d:\"%s\"): %s\n", n, buf, ebuf); - DEBUG(DFD, "chdir(%d:\"%s\"): %s\n", n, buf, ebuf); + DEBUG(dfd, "chdir(%d:\"%s\"): %s\n", n, buf, ebuf); exits(ebuf); } } - DEBUG(DFD, "\niniting root\n"); + DEBUG(dfd, "\niniting root\n"); initroot(); - DEBUG(DFD, "%s: %s\n", argv0, buf); + DEBUG(dfd, "%s: %s\n", argv0, buf); if(srv == nil && srvfd == -1 && write(0, "OK", 2) != 2) fatal("open ack write"); @@ -436,7 +436,7 @@ if(convM2S(r->buf, n, &r->work) != n) fatal("convM2S format error"); - DEBUG(DFD, "%F\n", &r->work); + DEBUG(dfd, "%F\n", &r->work); (fcalls[r->work.type])(r); } io(); --- //.git/fs/object/633dcc8c1cbdc9191e50c3639d8c908fafa32470/tree/sys/src/cmd/exportfs/pattern.c +++ sys/src/cmd/exportfs/pattern.c @@ -42,7 +42,7 @@ if(include == nil) fatal("out of memory"); } - DEBUG(DFD, "\tinclude %s\n", line+2); + DEBUG(dfd, "\tinclude %s\n", line+2); include[ni] = regcomp(line+2); include[++ni] = nil; break; @@ -53,12 +53,12 @@ if(exclude == nil) fatal("out of memory"); } - DEBUG(DFD, "\texclude %s\n", line+2); + DEBUG(dfd, "\texclude %s\n", line+2); exclude[ne] = regcomp(line+2); exclude[++ne] = nil; break; default: - DEBUG(DFD, "ignoring pattern %s\n", line); + DEBUG(dfd, "ignoring pattern %s\n", line); break; } } @@ -76,16 +76,16 @@ else p = path+1; - DEBUG(DFD, "checking %s\n", p); + DEBUG(dfd, "checking %s\n", p); for(re = include; *re != nil; re++){ if(regexec(*re, p, nil, 0) != 1){ - DEBUG(DFD, "excluded+ %s\n", p); + DEBUG(dfd, "excluded+ %s\n", p); return -1; } } for(re = exclude; *re != nil; re++){ if(regexec(*re, p, nil, 0) == 1){ - DEBUG(DFD, "excluded- %s\n", p); + DEBUG(dfd, "excluded- %s\n", p); return -1; } } @@ -98,7 +98,7 @@ int r = 0, m; Dir *d; - DEBUG(DFD, "\tpreaddir n=%d wo=%lld fo=%lld\n", n, offset, f->offset); + DEBUG(dfd, "\tpreaddir n=%d wo=%lld fo=%lld\n", n, offset, f->offset); if(offset == 0 && f->offset != 0){ if(seek(f->fid, 0, 0) != 0) return -1; @@ -128,9 +128,9 @@ free(p); } m = convD2M(d, data, n); - DEBUG(DFD, "\t\tconvD2M %d\n", m); + DEBUG(dfd, "\t\tconvD2M %d\n", m); if(m <= BIT16SZ){ - DEBUG(DFD, "\t\t\tneeded %d\n", GBIT16(data)); + DEBUG(dfd, "\t\t\tneeded %d\n", GBIT16(data)); /* not enough room for full entry; leave for next time */ f->cdir--; return r; --MP_/jYMl=wkeSPOGDEc2r.JWj3A--