Change stats to let if run even if some of the machines is down. And also to tolerate temporary outages without keeping remote machines as permanently down Notes: Mon Mar 15 12:50:08 EST 2004 rsc It's not clear I got to this patch in time. It looks like there is code looking in ether0/0/ifstats that has gone away and I can't tell if that's on purpose or not. Reference: /n/sources/patch/sorry/stats Date: Mon Apr 5 23:23:14 CES 2004 Reviewed-by: rsc --- /sys/src/cmd/stats.c Mon Apr 5 23:23:15 2004 +++ /sys/src/cmd/stats.c Mon Apr 5 23:23:15 2004 @@ -575,7 +575,7 @@ return fd; } -void +int initmach(Machine *m, char *name) { int n, fd; @@ -583,10 +583,9 @@ char *p, mpt[256], buf[256]; p = strchr(name, '!'); - if(p){ + if(p) p++; - m->name = estrdup(p+1); - }else + else p = name; m->name = estrdup(p); m->remote = (strcmp(p, mysysname) != 0); @@ -597,7 +596,7 @@ fd = connectexportfs(name); if(fd < 0){ fprint(2, "can't connect to %s: %r\n", name); - killall("connect"); + return 0; } /* BUG? need to use amount() now? */ if(mount(fd, -1, mpt, MREPL, "") < 0){ @@ -605,7 +604,7 @@ strcpy(mpt, "/n/sid"); if(mount(fd, -1, mpt, MREPL, "") < 0){ fprint(2, "stats: mount %s on %s failed: %r\n", name, mpt); - killall("mount"); + return 0; } } } @@ -638,11 +637,6 @@ snprint(buf, sizeof buf, "%s/net/ether0/ifstats", mpt); m->ifstatsfd = open(buf, OREAD); - if(m->ifstatsfd < 0){ - /* try the old place - this code will disappear on Nov 18th - presotto */ - snprint(buf, sizeof buf, "%s/net/ether0/0/ifstats", mpt); - 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)) @@ -661,6 +655,7 @@ if(loadbuf(m, &m->bitsybatfd) && readnums(m, 1, a, 0)) memmove(m->batterystats, a, sizeof(m->batterystats)); } + return 1; } jmp_buf catchalarm; @@ -720,11 +715,19 @@ if(display != nil) /* else we're still initializing */ eresized(0); } - m->disable = 1; + if (m->disable++ >= 5) + m->disable = 0; /* give it another chance */ memmove(m->devsysstat, m->prevsysstat, sizeof m->devsysstat); memmove(m->netetherstats, m->prevetherstats, sizeof m->netetherstats); return; } + snprint(buf, sizeof buf, "%s", m->name); + if (strcmp(m->name, buf) != 0){ + free(m->name); + m->name = estrdup(buf); + if(display != nil) /* else we're still initializing */ + eresized(0); + } if(m->remote){ notify(alarmed); alarm(5000); @@ -987,7 +990,7 @@ present[which] = 0; } -void +int addmachine(char *name) { if(ngraph > 0){ @@ -998,8 +1001,11 @@ nmach = 0; /* a little dance to get us started with local machine by default */ mach = erealloc(mach, (nmach+1)*sizeof(Machine)); memset(mach+nmach, 0, sizeof(Machine)); - initmach(mach+nmach, name); - nmach++; + if (initmach(mach+nmach, name)){ + nmach++; + return 1; + } else + return 0; } void @@ -1259,9 +1265,9 @@ initmach(&mach[0], mysysname); readmach(&mach[0], 1); }else{ - for(i=0; i