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.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4492 invoked from network); 31 Mar 2021 16:01:41 -0000 Received: from 1ess.inri.net (216.126.196.35) by inbox.vuxu.org with ESMTPUTF8; 31 Mar 2021 16:01:41 -0000 Received: from duke.felloff.net ([216.126.196.34]) by 1ess; Wed Mar 31 11:57:48 -0400 2021 Message-ID: <63F26840102C2C7E68A92CBB2FEAB082@felloff.net> Date: Wed, 31 Mar 2021 17:57:37 +0200 From: cinap_lenrek@felloff.net To: 9front@9front.org In-Reply-To: <21e1e4df-f661-4586-a7a7-b2a447ea3189@www.fastmail.com> 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: shared anonymous CSS dependency-based GPU DOM interface Subject: Re: [9front] devfs config file loading Reply-To: 9front@9front.org Precedence: bulk i pushed a fix to devfs, fixing some locking errors and removed the "devfs:\n" signature check. changeset: 8386:a62bc34fa4fa tag: tip parent: 8385:1e6f4a46ea24 parent: 8383:75ba75e18763 user: cinap_lenrek@felloff.net date: Wed Mar 31 17:50:25 2021 +0200 summary: merge diff -r 1e6f4a46ea24 -r a62bc34fa4fa sys/src/9/port/devfs.c --- a/sys/src/9/port/devfs.c Mon Mar 29 09:29:35 2021 -0700 +++ b/sys/src/9/port/devfs.c Wed Mar 31 17:50:25 2021 +0200 @@ -117,12 +117,10 @@ static char *disk; /* default tree name used */ static char *source; /* default inner device used */ static int sectorsz = Sectorsz; /* default sector size */ -static char confstr[Maxconf]; /* textual configuration */ +static char *confstr; /* textual configuration */ static int debug; -static char cfgstr[] = "fsdev:\n"; - static Qid tqid = {Qtop, 0, QTDIR}; static Qid cqid = {Qctl, 0, 0}; @@ -180,6 +178,36 @@ return s; } +static char* +seprintconf(char *s, char *e) +{ + int i, j; + Tree *t; + + *s = 0; + for(i = 0; i < ntrees; i++){ + t = trees[i]; + if(t != nil) + for(j = 0; j < t->nadevs; j++) + if(t->devs[j] != nil) + s = seprintdev(s, e, t->devs[j]); + } + return s; +} + +/* called with lck w */ +static void +setconfstr(void) +{ + char *s; + + s = confstr; + if(s == nil) + s = smalloc(Maxconf); + seprintconf(s, s+Maxconf); + confstr = s; +} + static vlong mkpath(int tree, int devno) { @@ -405,6 +433,8 @@ } } } + if(some) + setconfstr(); wunlock(&lck); if(some == 0 && alltrees == 0) error(Enonexist); @@ -560,7 +590,11 @@ Tree *t; /* ignore comments & empty lines */ - if (*a == '\0' || *a == '#' || *a == '\n') + if (n < 1 || *a == '\0' || *a == '#' || *a == '\n') + return; + + /* ignore historical config signature */ + if (n >= 6 && memcmp(a, "fsdev:", 6) == 0) return; dprint("mconfig\n"); @@ -722,8 +756,9 @@ } setdsize(mp, ilen); + setconfstr(); + wunlock(&lck); poperror(); - wunlock(&lck); free(idev); free(ilen); free(cb); @@ -732,21 +767,30 @@ static void rdconf(void) { - int mustrd; char *c, *e, *p, *s; Chan *cc; - static int configed; + int mustrd; /* only read config file once */ - if (configed) + if (confstr != nil) return; - configed = 1; + + wlock(&lck); + if (confstr != nil) { + wunlock(&lck); + return; /* already done */ + } + + /* add the std "fs" tree */ + if(ntrees == 0){ + fstree.name = "fs"; + trees[ntrees++] = &fstree; + } + + setconfstr(); + wunlock(&lck); dprint("rdconf\n"); - /* add the std "fs" tree */ - trees[0] = &fstree; - ntrees++; - fstree.name = "fs"; /* identify the config file */ s = getconf("fsconfig"); @@ -756,7 +800,9 @@ } else mustrd = 1; + c = smalloc(Maxconf+1); if(waserror()){ + free(c); if(!mustrd) return; nexterror(); @@ -768,23 +814,12 @@ cclose(cc); nexterror(); } - devtab[cc->type]->read(cc, confstr, sizeof confstr, 0); + devtab[cc->type]->read(cc, c, Maxconf, 0); + cclose(cc); poperror(); - cclose(cc); - /* validate, copy and erase config; mconfig will repopulate confstr */ - if (strncmp(confstr, cfgstr, sizeof cfgstr - 1) != 0) - error("bad #k config, first line must be: 'fsdev:\\n'"); - - c = nil; - kstrdup(&c, confstr + sizeof cfgstr - 1); - if(waserror()){ - free(c); - nexterror(); - } - memset(confstr, 0, sizeof confstr); /* process config copy one line at a time */ - for (p = c; p != nil && *p != '\0'; p = e){ + for (p = c; *p != '\0'; p = e){ e = strchr(p, '\n'); if (e == nil) e = p + strlen(p); @@ -792,10 +827,9 @@ e++; mconfig(p, e - p); } - poperror(); + free(c); - - poperror(); /* mustrd */ + poperror(); /* c */ } static int @@ -1138,23 +1172,6 @@ return res; } -static char* -seprintconf(char *s, char *e) -{ - int i, j; - Tree *t; - - *s = 0; - for(i = 0; i < ntrees; i++){ - t = trees[i]; - if(t != nil) - for(j = 0; j < t->nadevs; j++) - if(t->devs[j] != nil) - s = seprintdev(s, e, t->devs[j]); - } - return s; -} - static long mread(Chan *c, void *a, long n, vlong off) { @@ -1175,7 +1192,6 @@ goto Done; } if(c->qid.path == Qctl){ - seprintconf(confstr, confstr + sizeof(confstr)); res = readstr((long)off, a, n, confstr); goto Done; } -- cinap