The error messages from reading nvram have little useful info. This change introduces a storage leak that leaves the nvram file name around for later error printing. The storage leak is trivial and hence worth the cost, given that we now have a usable nvram file name. Error checking is also a lot more useful. Reference: /n/sources/patch/applied/moreusefulnvramfailure Date: Sun Mar 28 19:50:22 CES 2010 Signed-off-by: rminnich@gmail.com --- /sys/src/libauthsrv/readnvram.c Sun Mar 28 19:49:04 2010 +++ /sys/src/libauthsrv/readnvram.c Sun Mar 28 19:49:00 2010 @@ -129,11 +129,12 @@ int safelen; } Nvrwhere; +static char *nvrfile = nil, *cputype = nil; /* returns with *locp filled in and locp->fd open, if possible */ static void findnvram(Nvrwhere *locp) { - char *cputype, *nvrfile, *nvrlen, *nvroff, *v[2]; + char *nvrlen, *nvroff, *v[2]; int fd, i, safeoff, safelen; nvrfile = getenv("nvram"); @@ -158,7 +159,7 @@ } fd = open(v[0], ORDWR); if (fd < 0) - fd = open(v[0], OREAD); + fd = open(v[0], OREAD); safelen = sizeof(Nvrsafe); if(strstr(v[0], "/9fat") == nil) safeoff = 0; @@ -199,8 +200,6 @@ } break; } - free(nvrfile); - free(cputype); locp->fd = fd; locp->safelen = safelen; locp->safeoff = safeoff; @@ -241,12 +240,14 @@ safe = safep; else { memset(safep, 0, sizeof(*safep)); - if(loc.fd < 0 - || seek(loc.fd, loc.safeoff, 0) < 0 - || read(loc.fd, buf, loc.safelen) != loc.safelen){ + if(loc.fd < 0) { + fprint(2, "Could not open %s: %r\n", nvrfile); + } else if (seek(loc.fd, loc.safeoff, 0) < 0) { + fprint(2, "Could not seek %s to %d\n", nvrfile, loc.safeoff); + } else if (read(loc.fd, buf, loc.safelen) != loc.safelen){ err = 1; if(flag&(NVwrite|NVwriteonerr)) - fprint(2, "can't read nvram: %r\n"); + fprint(2, "can't read %s for %d bytes: %r\n", nvrfile, loc.safelen); /* start from scratch */ memset(safep, 0, sizeof(*safep)); safe = safep;