diff -r de663b03be21 sys/src/cmd/upas/q/runq.c --- a/sys/src/cmd/upas/q/runq.c Sat Jan 23 11:03:05 2021 -0800 +++ b/sys/src/cmd/upas/q/runq.c Sat Jan 23 12:18:33 2021 -0800 @@ -2,6 +2,13 @@ #include <ctype.h> typedef struct Job Job; +typedef struct Wdir Wdir; + +struct Wdir { + Dir *d; + int nd; + char *name; +}; struct Job { Job *next; @@ -10,6 +17,7 @@ int dfd; char **av; char *buf; /* backing for av */ + Wdir *wdir; /* work dir */ Dir *dp; /* not owned */ Mlock *l; Biobuf *b; @@ -17,15 +25,15 @@ void doalldirs(void); void dodir(char*); -Job* dofile(Dir*); +Job* dofile(Wdir*, Dir*); Job* donefile(Job*, Waitmsg*); void freejob(Job*); void rundir(char*); char* file(char*, char); void warning(char*, void*); void error(char*, void*); -int returnmail(char**, char*, char*); -void logit(char*, char*, char**); +int returnmail(char**, Wdir*, char*, char*); +void logit(char*, Wdir*, char*, char**); void doload(int); #define HUNK 32 @@ -35,12 +43,6 @@ int giveup = 2*24*60*60; int limit; -/* the current directory */ -Dir *dirbuf; -long ndirbuf = 0; -int nfiles; -char *curdir; - char *runqlog = "runq"; char **badsys; /* array of recalcitrant systems */ @@ -48,6 +50,7 @@ int njob = 1; /* number of concurrent jobs to invoke */ int Eflag; /* ignore E.xxxxxx dates */ int Rflag; /* no giving up, ever */ +int aflag; /* do all dirs */ void usage(void) @@ -82,27 +85,37 @@ case 'q': qdir = EARGF(usage()); break; + case 'a': + aflag++; + break; case 'n': njob = atoi(EARGF(usage())); if(njob == 0) usage(); break; + default: + usage(); + break; }ARGEND; if(argc != 2) usage(); - if(qdir == nil) + if(!aflag && qdir == nil){ qdir = getuser(); - if(qdir == nil) - error("unknown user", 0); + if(qdir == nil) + error("unknown user", 0); + } root = argv[0]; cmd = argv[1]; if(chdir(root) < 0) error("can't cd to %s", root); - dodir(qdir); + if(aflag) + doalldirs(); + else + dodir(qdir); exits(0); } @@ -129,12 +142,44 @@ } /* + * run all user directories, must be bootes (or root on unix) to do this + */ +void +doalldirs(void) +{ + Dir *db; + int fd; + long i, n; + + + fd = open(".", OREAD); + if(fd == -1){ + warning("reading %s", root); + return; + } + n = dirreadall(fd, &db); + if(n == 0){ + close(fd); + return; + } + for(i=0; i<n; i++){ + if((db[i].qid.type & QTDIR) == 0) + continue; + if(emptydir(db[i].name)) + continue; + dodir(db[i].name); + } + free(db); + close(fd); +} + +/* * cd to a user directory and run it */ void dodir(char *name) { - curdir = name; +// curdir = name; if(chdir(name) < 0){ warning("cd to %s", name); @@ -152,9 +197,10 @@ void rundir(char *name) { + int nlive, fidx, fd, found; Job *hd, *j, **p; - int nlive, fidx, fd, found; Waitmsg *w; + Wdir wd; fd = open(".", OREAD); if(fd == -1){ @@ -164,14 +210,15 @@ fidx= 0; hd = nil; nlive = 0; - nfiles = dirreadall(fd, &dirbuf); - while(nlive > 0 || fidx< nfiles){ - while(fidx< nfiles && nlive < njob){ - if(strncmp(dirbuf[fidx].name, "C.", 2) != 0){ + wd.name = name; + wd.nd = dirreadall(fd, &wd.d); + while(nlive > 0 || fidx< wd.nd){ + while(fidx< wd.nd && nlive < njob){ + if(strncmp(wd.d[fidx].name, "C.", 2) != 0){ fidx++; continue; } - if((j = dofile(&dirbuf[fidx])) != nil){ + if((j = dofile(&wd, &wd.d[fidx])) != nil){ nlive++; j->next = hd; hd = j; @@ -201,7 +248,7 @@ goto rescan; } assert(hd == nil); - free(dirbuf); + free(wd.d); close(fd); } @@ -209,15 +256,15 @@ * free files matching name in the current directory */ void -remmatch(char *name) +remmatch(Wdir *w, char *name) { long i; - syslog(0, runqlog, "removing %s/%s", curdir, name); + syslog(0, runqlog, "removing %s/%s", w->name, name); - for(i=0; i<nfiles; i++){ - if(strcmp(&dirbuf[i].name[1], &name[1]) == 0) - remove(dirbuf[i].name); + for(i=0; i<w->nd; i++){ + if(strcmp(&w->d[i].name[1], &name[1]) == 0) + remove(w->d[i].name); } /* error file (may have) appeared after we read the directory */ @@ -263,7 +310,7 @@ * tracks the running pid. */ Job* -dofile(Dir *dp) +dofile(Wdir *w, Dir *dp) { int dtime, efd, i, etime; Job *j; @@ -280,13 +327,13 @@ d = dirstat(file(dp->name, 'D')); if(d == nil){ syslog(0, runqlog, "no data file for %s", dp->name); - remmatch(dp->name); + remmatch(w, dp->name); return nil; } if(dp->length == 0){ if(time(0)-dp->mtime > 15*60){ syslog(0, runqlog, "empty ctl file for %s", dp->name); - remmatch(dp->name); + remmatch(w, dp->name); } return nil; } @@ -338,7 +385,7 @@ * - read args into (malloc'd) buffer * - malloc a vector and copy pointers to args into it */ - + j->wdir = w; j->buf = malloc(dp->length+1); if(j->buf == nil){ warning("buffer allocation", 0); @@ -381,9 +428,9 @@ j->av[j->ac] = 0; if(!Eflag &&time(0) - dtime > giveup){ - if(returnmail(j->av, dp->name, "Giveup") != 0) - logit("returnmail failed", dp->name, j->av); - remmatch(dp->name); + if(returnmail(j->av, w, dp->name, "Giveup") != 0) + logit("returnmail failed", w, dp->name, j->av); + remmatch(w, dp->name); goto done; } @@ -415,7 +462,7 @@ fprint(2, " %s", j->av[i]); fprint(2, "\n"); } - logit("execing", dp->name, j->av); + logit("execing", w, dp->name, j->av); close(0); dup(j->dfd, 0); close(j->dfd); @@ -461,9 +508,9 @@ fprint(2, "[%d] wm->msg == %s\n", getpid(), wm->msg); if(!Rflag && strstr(wm->msg, "Retry")==0){ /* return the message and remove it */ - if(returnmail(j->av, j->dp->name, wm->msg) != 0) - logit("returnmail failed", j->dp->name, j->av); - remmatch(j->dp->name); + if(returnmail(j->av, j->wdir, j->dp->name, wm->msg) != 0) + logit("returnmail failed", j->wdir, j->dp->name, j->av); + remmatch(j->wdir, j->dp->name); } else { /* add sys to bad list and try again later */ nbad++; @@ -472,7 +519,7 @@ } } else { /* it worked remove the message */ - remmatch(j->dp->name); + remmatch(j->wdir, j->dp->name); } n = j->next; freejob(j); @@ -520,7 +567,7 @@ * return 0 if successful */ int -returnmail(char **av, char *name, char *msg) +returnmail(char **av, Wdir *w, char *name, char *msg) { char buf[256], attachment[Pathlen], *sender; int i, fd, pfd[2]; @@ -529,7 +576,7 @@ String *s; if(av[1] == 0 || av[2] == 0){ - logit("runq - dumping bad file", name, av); + logit("runq - dumping bad file", w, name, av); return 0; } @@ -537,21 +584,21 @@ sender = s_to_c(s); if(!returnable(sender) || strcmp(sender, "postmaster") == 0) { - logit("runq - dumping p to p mail", name, av); + logit("runq - dumping p to p mail", w, name, av); return 0; } if(pipe(pfd) < 0){ - logit("runq - pipe failed", name, av); + logit("runq - pipe failed", w, name, av); return -1; } switch(rfork(RFFDG|RFPROC|RFENVG)){ case -1: - logit("runq - fork failed", name, av); + logit("runq - fork failed", w, name, av); return -1; case 0: - logit("returning", name, av); + logit("returning", w, name, av); close(pfd[1]); close(0); dup(pfd[0], 0); @@ -592,14 +639,14 @@ wm = wait(); if(wm == nil){ syslog(0, "runq", "wait: %r"); - logit("wait failed", name, av); + logit("wait failed", w, name, av); return -1; } i = 0; if(wm->msg[0]){ i = -1; syslog(0, "runq", "returnmail child: %s", wm->msg); - logit("returnmail child failed", name, av); + logit("returnmail child failed", w, name, av); } free(wm); return i; @@ -635,12 +682,12 @@ } void -logit(char *msg, char *file, char **av) +logit(char *msg, Wdir *w, char *file, char **av) { int n, m; char buf[256]; - n = snprint(buf, sizeof(buf), "%s/%s: %s", curdir, file, msg); + n = snprint(buf, sizeof(buf), "%s/%s: %s", w->name, file, msg); for(; *av; av++){ m = strlen(*av); if(n + m + 4 > sizeof(buf))
Sat Jan 23 14:27:11 EST 2021
diff -r de663b03be21 sys/src/cmd/upas/q/runq.c --- a/sys/src/cmd/upas/q/runq.c Sat Jan 23 11:03:05 2021 -0800 +++ b/sys/src/cmd/upas/q/runq.c Sat Jan 23 11:27:11 2021 -0800 @@ -48,6 +48,7 @@ int njob = 1; /* number of concurrent jobs to invoke */ int Eflag; /* ignore E.xxxxxx dates */ int Rflag; /* no giving up, ever */ +int aflag; /* do all dirs */ void usage(void) @@ -82,27 +83,37 @@ case 'q': qdir = EARGF(usage()); break; + case 'a': + aflag++; + break; case 'n': njob = atoi(EARGF(usage())); if(njob == 0) usage(); break; + default: + usage(); + break; }ARGEND; if(argc != 2) usage(); - if(qdir == nil) + if(!aflag && qdir == nil){ qdir = getuser(); - if(qdir == nil) - error("unknown user", 0); + if(qdir == nil) + error("unknown user", 0); + } root = argv[0]; cmd = argv[1]; if(chdir(root) < 0) error("can't cd to %s", root); - dodir(qdir); + if(aflag) + doalldirs(); + else + dodir(qdir); exits(0); } @@ -129,6 +140,38 @@ } /* + * run all user directories, must be bootes (or root on unix) to do this + */ +void +doalldirs(void) +{ + Dir *db; + int fd; + long i, n; + + + fd = open(".", OREAD); + if(fd == -1){ + warning("reading %s", root); + return; + } + n = dirreadall(fd, &db); + if(n == 0){ + close(fd); + return; + } + for(i=0; i<n; i++){ + if((db[i].qid.type & QTDIR) == 0) + continue; + if(emptydir(db[i].name)) + continue; + dodir(db[i].name); + } + free(db); + close(fd); +} + +/* * cd to a user directory and run it */ void
Sat Jan 23 14:15:19 EST 2021
/usr/bloody cpu% echo $user bloody cpu% /bin/upas/runq -n 20 -a /mail/queue /mail/lib/remotemail runq: cd to bloody: 'bloody' not found cpu%
Sat Jan 23 13:32:50 EST 2021
diff -r ab3f119403ba sys/man/8/qer --- a/sys/man/8/qer Sat Jan 23 18:42:46 2021 +0100 +++ b/sys/man/8/qer Sat Jan 23 10:32:49 2021 -0800 @@ -15,7 +15,7 @@ .br .B runq [ -.B -adsER +.B -dER ] [ .B -f @@ -26,10 +26,6 @@ .I subdir ] [ -.B -l -.I load -] -[ .B -t .I time ] @@ -39,7 +35,7 @@ ] [ .B -n -.I nprocs +.I njobs ] .I root cmd .SH DESCRIPTION @@ -84,10 +80,7 @@ .I Runq processes the files queued by .IR qer . -Without the -.B -a -option, -.I runq +.I Runq processes all requests in the directory .IR root / subdir , where @@ -96,9 +89,6 @@ .B -q if present, else the contents of .BR /dev/user . -With the -.B -a -it processes all requests. Each request is processed by executing the command .I cmd with the contents of the control file as its arguments, @@ -172,31 +162,12 @@ .I -q flag. .P -The -.BR -s , -.BR -n , -and -.B -l -flags are only meaningful with the -.B -a -flag. They control amount of parallelism that -is used when sweeping all of the queues. The argument following the +The argument following the .B -n -flag specifies the number of queues that are swept -in parallel; the default is 50. The argument following the -.B -l -flag specifies the total number of queues that are being swept. -By default, there is no limit. The number of active sweeps -is cumulative over all active executions of -.IR runq . -The -.B -s -flag forces each queue directory to be processed by exactly -one instance of -.IR runq . -This is useful on systems that connect to slow -external systems and prevents all the queue sweeps from -piling up trying to process a few slow systems. +flag specifies the number of queued jobs that are processed +in parallel from the queue; the default is 1. +This is useful for a large queue to be processed with a bounded +amount of parallelism. .PP .I Runq is often called from
Fri Jan 22 18:32:44 EST 2021
diff -r 077fe1dc73d0 sys/src/cmd/stats.c --- a/sys/src/cmd/stats.c Fri Jan 22 10:57:43 2021 +0100 +++ b/sys/src/cmd/stats.c Fri Jan 22 15:32:44 2021 -0800 @@ -86,6 +86,9 @@ char buf[8*1024]; char *bufp; char *ebufp; + + /* for new wifi stack */ + char *essid; }; enum @@ -471,6 +474,78 @@ } int +readessid(Machine *m) +{ + char *p, *ep; + int l; + + if(strncmp(m->bufp, "essid: ", 7) == 0){ + p = m->bufp + 7; + + for(ep=p; ep<m->ebufp; ep++) + if(*ep == '\n') + break; + + if (m->essid != nil) { + free(m->essid); + m->essid = nil; + } + + l = ep-p; + if (l == 0) + return 0; + + m->essid = malloc(l+3); + if (m->essid == nil) + return 0; + + m->essid[0] = ' '; /* essid can be a substring of another essid */ + m->essid[l+1] = '\n'; + m->essid[l+2] = '\0'; + memcpy(m->essid+1, p, l); + return 1; + } + + return 0; +} + +int +readrssi(Machine *m, uvlong *a) +{ + char *p, *e; + static uvlong last[5]; + int i; + + p = strstr(m->bufp, "status: "); + if (p == nil) + return 0; + p += 8; + if (strncmp(p, "associated", 10) != 0) { + a[0] = 0; + return 1; + } + + for(e = m->bufp; *e != '\n'; e++); + e = strstr(e, m->essid); + if (e == nil) + return 0; + + for(p = e; p>m->bufp && *p != '\n'; p--); + if (p == m->bufp) + return 0; + p += 25; + + memmove(&last[1], last, sizeof(uvlong) * 4); + last[0] = strtoull(p, &p, 12); + a[0] = 0; + for(i = 0; i < 5; i++) + a[0] += last[i]; + a[0] = -(a[0] / 60) - 45; /* scale for wavelan type */ + + return 1; +} + +int readswap(Machine *m, uvlong *a) { static int xxx = 0; @@ -615,7 +690,7 @@ m->ifstatsfd = open(buf, OREAD); if(loadbuf(m, &m->ifstatsfd)){ /* need to check that this is a wavelan interface */ - if(strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1)) + if((strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1)) || (readessid(m) && readrssi(m, a))) memmove(m->netetherifstats, a, sizeof m->netetherifstats); } @@ -752,7 +827,7 @@ memmove(m->prevetherstats, m->netetherstats, sizeof m->netetherstats); memmove(m->netetherstats, a, sizeof m->netetherstats); } - if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)){ + if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && (strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)) || (readessid(m) && readrssi(m, a))){ memmove(m->netetherifstats, a, sizeof m->netetherifstats); } if(needbattery(init)){
Fri Jan 22 18:03:52 EST 2021
diff -r 077fe1dc73d0 sys/src/cmd/stats.c --- a/sys/src/cmd/stats.c Fri Jan 22 10:57:43 2021 +0100 +++ b/sys/src/cmd/stats.c Fri Jan 22 15:03:51 2021 -0800 @@ -86,6 +86,9 @@ char buf[8*1024]; char *bufp; char *ebufp; + + /* for new wifi stack */ + char *essid; }; enum @@ -471,6 +474,76 @@ } int +readessid(Machine *m) +{ + char *p, *ep; + int l; + + if(strncmp(m->bufp, "essid: ", 7) == 0){ + p = m->bufp + 7; + + for(ep=p; ep<m->ebufp; ep++) + if(*ep == '\n') + break; + + if (m->essid != nil) { + free(m->essid); + m->essid = nil; + } + + l = ep-p; + if (l == 0) + return 0; + + m->essid = malloc(l+1); + if (m->essid == nil) + return 0; + + m->essid[l] = '\0'; + memcpy(m->essid, p, l); + return 1; + } + + return 0; +} + +int +readrssi(Machine *m, uvlong *a) +{ + char *p, *e; + static uvlong last[5]; + int i; + + p = strstr(m->bufp, "status: "); + if (p == nil) + return 0; + p += 8; + if (strncmp(p, "associated", 10) != 0) { + a[0] = 0; + return 1; + } + + for(e = m->bufp; *e != '\n'; e++); + e = strstr(e, m->essid); + if (e == nil) + return 0; + + for(p = e; p>m->bufp && *p != '\n'; p--); + if (p == m->bufp) + return 0; + p += 25; + + memmove(&last[1], last, sizeof(uvlong) * 4); + last[0] = strtoull(p, &p, 12); + a[0] = 0; + for(i = 0; i < 5; i++) + a[0] += last[i]; + a[0] = -(a[0] / 60) - 45; /* scale for wavelan type */ + + return 1; +} + +int readswap(Machine *m, uvlong *a) { static int xxx = 0; @@ -615,7 +688,7 @@ m->ifstatsfd = open(buf, OREAD); if(loadbuf(m, &m->ifstatsfd)){ /* need to check that this is a wavelan interface */ - if(strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1)) + if((strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1)) || (readessid(m) && readrssi(m, a))) memmove(m->netetherifstats, a, sizeof m->netetherifstats); } @@ -752,7 +825,7 @@ memmove(m->prevetherstats, m->netetherstats, sizeof m->netetherstats); memmove(m->netetherstats, a, sizeof m->netetherstats); } - if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)){ + if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && (strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)) || (readessid(m) && readrssi(m, a))){ memmove(m->netetherifstats, a, sizeof m->netetherifstats); } if(needbattery(init)){
Fri Jan 22 17:41:07 EST 2021
mss564535rtjuny AU3XRgm kQOK RGm9GF5
Fri Jan 22 15:47:03 EST 2021
. \" GLOBAL CONSTANTS " . .nr B 3v .nr T 2v \"page top margin .nr M 3n \"page horizontal margin .nr W 8.5i-\nMu-\nMu \"page content width .nr H (\n(.pu-\nTu-\nBu) \"max page height .nr G 2n \"inter-columns gap . . \" INTERNAL MACROS FOR LAYOUT " . \"record the content into a trap .de C{ . di C* \"save text content . ll \\n($Wu-\nGu \"line length column content .. . \"place the recorded content into columns, now that we have the height .de C} . br . di \"end C* diversion . . nr $H 0 1v . nr $P 0 1u . . mk . C? \"find optimal column height . rt . . C0 \"top of first column .\" tm Running with C=\\n($c/\\n($C P=\\n($p/\\n($P H=\\n($H h=\\n($h . C* \"print the formatted content . sp \\n(.tu \"consume space until the trap . . po \nMu \"back to page margin . ll \nWu \"back to full width . .. . \"Trap context: \" .----------------. .----------------. .----------------. \" | | | :::: :::: :::: | | :::: :::: :::: | \" | | | :::: :::: :::: | | :::: :::: :::: | \" | C0:: :::: :::: | | :::: :::: :::: | | :::: :::: :::: | \" | :::: :::: :::: | | :::: :::: :::: | | :::: :::: :::: | \" | :::: :::: :::: | | :::: :::: :::: | | ::C1 ::C1 ::C3 | \" | ::C1 ::C1 ::C2 | | ::C1 ::C1 ::C2 | | | \" '----------------' '----------------' '----------------' . \"test to print the content to check the height .de C? . C+ \"use more space . di _ \"catch output . C0 \"top of column .\" tm Trying with C=\\n($c/\\n($C P=\\n($p/\\n($P H=\\n($H h=\\n($h . C* \"try to fit the text in this setup . br . di . rm _ \"remove dummy content . . if \\n($o \{\ . rt \"back to top . C? \"need more room start over . \} . . ch C# \"remove real trap . dt \"remove diversion trap .. . \"set the minimal column width \" $C number of column per page width \" $W width of each column .de CW . nr $C \nW/\\$1 . nr $W (\nW+\nG)/\\n($C .. . \"increase the space used for extra pages and last columns height \" $P number of extra pages \" $H Height of the last serie of columns .de C+ . \"note: on first call, $H == $h == 0 . ie \\n($H>\\n($h \{ \"if rest of page is not enough . nr $P \\n($P+1 \"increase extra page count . nr $H 3v \"back to top of next page . \} . el \{ . nr $H \\n($H+1v . \} .. . \"column trap \" $t height of column for setting trap \" $o is there an overflow? (0=no 1=yes) \" $c current column within diversion/trap \" $p current number of extra pages spent within diversion/trap \" $h height of the page available for our content .de C# . \"pick apropriate trap context . ie \\n($p=\\n($P \{\ . ie \\n($c=\\n($C .C3 \"end of last column of last page . el .C1 \"end of some column of last page . \} . el\{\ . ie \\n($c=\\n($C .C2 \"end of last column of some page . el .C1 \"end of some column of some page . \} . . \"page offset . ie \\n($p=\\n($P \ . nr $t \\n($H \"height to last page height . el \ . nr $t \\n($h \"height to available height . . \"bump the trap . ch C# . wh \\n(.du+\\n($tu C# . dt \\n(.du+\\n($tu C# .. . \"top of article .de C0 . nr $o 0 \"no overflow yet . nr $c 0 1 \"will be increased by C#{...C+...} . nr $p 0 1 \"no extra page spent yet . nr $h \nT+\nH-\\n(nl \"rest of page available . mk \"mark top-of-column . C# \"initial trap setup . po \\nMu \"reset offset .. . \"bottom of some column of some page .de C1 . nr $c \\n($c+1 . rt \"back to top-of-column . po +\\n($Wu \"no effect in diversions .. . \"bottom of last column of some page .de C2 . nr $c 1 . nr $p \\n($p+1 \"bump this column's page count . bp \"new page . nr $h \\nH \"a whole empty page just for us . po \\nMu \"reset offset . mk .. . \"bottom of last column of last page .de C3 . nr $o 1 \"column overflow! must start over . po \\nMu .. . \"page header .de HE . ps 10p . vs 12p . po \nMu \"page margin . tl |#1 - 20\n(yr/\n(mo/\n(dy||PAGE \\n%| . po 0 \v'-1v'\l'101' . po \nMu \"page margin .. . \"open hook .de ?{ . if '\\*?'C{' .C{ \"if want a column layout, open it . ds ? C} \"next step: close column layout .. . \"close hook .de ?} . if '\\*?'C}' \{\ . C} \"if in a column layout, close it . F} \"if collected footnotes, print them . \} . ds ? C{ \"next step: open column layout .. . \"heading hook .de ?H . if '\\*?'HE' \{\ . br . HE . \} .. . .de F} . F* \"flush any footnote there was . rm F* \"then remove the associated macro . if \\n($F>0 .br . nr $F 0 1 .. . . \" MS-STYLE MACRO FRONTEND " . \"document name .de TL . ad c . ps 40p . vs 40p . ds ? HE . wh 0 HE \"set the trap for subsequent pages .. . \"section heading .de SH . ?H \"maybe show a heading separator . ?} \"maybe close previous column layout . ad l . ps 17p . vs 17p*3u/2u . ft 3 \"bold .. . \"paragraph .de PP . ?H \"maybe show a heading separator . br . ps 10p . vs 12p . sp 0.5v \"BUG: does not honor 0.5 . ft 1 . ad b . ?{ \"maybe open a new column layout .. . \"footnote start .de FN [\\n+($F] \"add this footnote's reference . da F* \"append this footnote . IP [\\n($F] \"as a numbered paragraph .. . \"footnote end .de FE . di .. . . \" SETUP LAYOUT " . .CW 30n .po \nMu .ll \nWu
Fri Jan 22 06:45:20 EST 2021
diff -r 077fe1dc73d0 sys/src/cmd/stats.c --- a/sys/src/cmd/stats.c Fri Jan 22 10:57:43 2021 +0100 +++ b/sys/src/cmd/stats.c Fri Jan 22 03:45:20 2021 -0800 @@ -86,6 +86,9 @@ char buf[8*1024]; char *bufp; char *ebufp; + + /* for new wifi stack */ + char *essid; }; enum @@ -471,6 +474,62 @@ } int +readessid(Machine *m) +{ + char *p, *ep; + int l; + + if(strncmp(m->bufp, "essid: ", 7) == 0){ + p = m->bufp + 7; + + for(ep=p; ep<m->ebufp; ep++) + if(*ep == '\n') + break; + + if (m->essid != nil) { + free(m->essid); + m->essid = nil; + } + + l = ep-p; + if (l == 0) + return 0; + + m->essid = malloc(l+1); + if (m->essid == nil) + return 0; + + m->essid[l] = '\0'; + memcpy(m->essid, p, l); + return 1; + } + + return 0; +} + +int +readrssi(Machine *m, uvlong *a) +{ + char *p, *e; + + for(e = m->bufp; *e != '\n'; e++); + e = strstr(e, m->essid); + if (e == nil) + return 0; + + for(p = e; p>m->bufp && *p != '\n'; p--); + if (p == m->bufp) + return 0; + p += 25; + + a[0] = strtoull(p, &p, 12); + a[0] /= 9000; /* TODO find low signal strength number, scale for wavelan type */ + a[0] -= 45; + + return 1; +} + +int readswap(Machine *m, uvlong *a) { static int xxx = 0; @@ -615,7 +674,7 @@ m->ifstatsfd = open(buf, OREAD); if(loadbuf(m, &m->ifstatsfd)){ /* need to check that this is a wavelan interface */ - if(strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1)) + if((strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1)) || (readessid(m) && readrssi(m, a))) memmove(m->netetherifstats, a, sizeof m->netetherifstats); } @@ -752,7 +811,7 @@ memmove(m->prevetherstats, m->netetherstats, sizeof m->netetherstats); memmove(m->netetherstats, a, sizeof m->netetherstats); } - if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)){ + if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && (strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)) || (readessid(m) && readrssi(m, a))){ memmove(m->netetherifstats, a, sizeof m->netetherifstats); } if(needbattery(init)){
Fri Jan 22 06:37:19 EST 2021
diff -r 4e0405b6fb7e sys/src/cmd/stats.c --- a/sys/src/cmd/stats.c Tue Jan 12 21:08:12 2021 +0100 +++ b/sys/src/cmd/stats.c Fri Jan 22 03:37:18 2021 -0800 @@ -86,6 +86,9 @@ char buf[8*1024]; char *bufp; char *ebufp; + + /* for new wifi stack */ + char *essid; }; enum @@ -469,6 +472,62 @@ } int +readessid(Machine *m) +{ + char *p, *ep; + int l; + + if(strncmp(m->bufp, "essid: ", 7) == 0){ + p = m->bufp + 7; + + for(ep=p; ep<m->ebufp; ep++) + if(*ep == '\n') + break; + + if (m->essid != nil) { + free(m->essid); + m->essid = nil; + } + + l = ep-p; + if (l == 0) + return 0; + + m->essid = malloc(l+1); + if (m->essid == nil) + return 0; + + m->essid[l] = '\0'; + memcpy(m->essid, p, l); + return 1; + } + + return 0; +} + +int +readrssi(Machine *m, uvlong *a) +{ + char *p, *e; + + for(e = m->bufp; *e != '\n'; e++); + e = strstr(e, m->essid); + if (e == nil) + return 0; + + for(p = e; p>m->bufp && *p != '\n'; p--); + if (p == m->bufp) + return 0; + p += 25; + + a[0] = strtoull(p, &p, 12); + a[0] /= 9000; /* TODO find low signal strength number, scale for wavelan type */ + a[0] -= 45; + + return 1; +} + +int readswap(Machine *m, uvlong *a) { static int xxx = 0; @@ -613,7 +672,7 @@ m->ifstatsfd = open(buf, OREAD); if(loadbuf(m, &m->ifstatsfd)){ /* need to check that this is a wavelan interface */ - if(strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1)) + if((strncmp(m->buf, "Signal: ", 8) == 0 && readnums(m, nelem(m->netetherifstats), a, 1)) || (readessid(m) && readrssi(m, a))) memmove(m->netetherifstats, a, sizeof m->netetherifstats); } @@ -734,7 +793,7 @@ memmove(m->prevetherstats, m->netetherstats, sizeof m->netetherstats); memmove(m->netetherstats, a, sizeof m->netetherstats); } - if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)){ + if(needsignal(init) && loadbuf(m, &m->ifstatsfd) && (strncmp(m->buf, "Signal: ", 8)==0 && readnums(m, nelem(m->netetherifstats), a, 1)) || (readessid(m) && readrssi(m, a))){ memmove(m->netetherifstats, a, sizeof m->netetherifstats); } if(needbattery(init) && loadbuf(m, &m->batteryfd) && readnums(m, nelem(m->batterystats), a, 0))
Thu Jan 21 20:43:48 EST 2021
/sys/src/9/port/chan.c:1321,1335