From 90251761932a95bfa138cbba4963d435406c3c9d Mon Sep 17 00:00:00 2001 From: Sigrid Date: Fri, 22 Jan 2021 10:57:43 +0100 Subject: [PATCH] aux/acpi: do not expose empty files --- sys/src/cmd/aux/acpi.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sys/src/cmd/aux/acpi.c b/sys/src/cmd/aux/acpi.c index 9bd5e38fc..cca662ef3 100644 --- a/sys/src/cmd/aux/acpi.c +++ b/sys/src/cmd/aux/acpi.c @@ -62,6 +62,8 @@ enum { Qbattery, Qcputemp, Qctl, + + Qdisable = (uvlong)-1, }; static void rootread(Req*); @@ -354,7 +356,7 @@ fswalk1(Fid *fid, char *name, Qid *qid) } for(i = 1; i < nelem(dfile); i++){ /* i=1: 0 is root dir */ - if(strcmp(dfile[i].name, name) == 0){ + if(dfile[i].qid.path != Qdisable && strcmp(dfile[i].name, name) == 0){ *qid = dfile[i].qid; fid->qid = *qid; return nil; @@ -424,12 +426,14 @@ rootread(Req *r) if(offset == 0) /* skip root */ offset = 1; - for(; p+2 < ep; p += n){ + for(; p+2 < ep && offset < nelem(dfile); p += n){ if(fillstat(offset, &d, 0) < 0) - break; - n = convD2M(&d, (uchar*)p, ep-p); - if(n <= BIT16SZ) - break; + n = 0; + else{ + n = convD2M(&d, (uchar*)p, ep-p); + if(n <= BIT16SZ) + break; + } offset++; } r->fid->aux = (void*)offset; @@ -540,6 +544,11 @@ threadmain(int argc, char **argv) amlenum(amlroot, "_BIF", enumbat, nil); amlenum(amlroot, "_PSL", enumtmp, nil); + if(nbats < 1) + dfile[Qbattery].qid.path = Qdisable; + if(ntherms < 1) + dfile[Qcputemp].qid.path = Qdisable; + threadpostmountsrv(&fs, srv, mtpt, MREPL); threadexits(nil);