diff options
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/auxstats/FreeBSD.c | 47 | ||||
-rw-r--r-- | src/cmd/draw/gview.c | 8 | ||||
-rw-r--r-- | src/cmd/rc/unixcrap.c | 13 |
3 files changed, 25 insertions, 43 deletions
diff --git a/src/cmd/auxstats/FreeBSD.c b/src/cmd/auxstats/FreeBSD.c index a6b7a8d6..2497fe35 100644 --- a/src/cmd/auxstats/FreeBSD.c +++ b/src/cmd/auxstats/FreeBSD.c @@ -18,10 +18,9 @@ #include <limits.h> #include <libc.h> #include <bio.h> +#include <ifaddrs.h> #include "dat.h" -/* XXX: #if __FreeBSD_version */ - void xapm(int); void xloadavg(int); void xcpu(int); @@ -45,7 +44,6 @@ void (*statfn[])(int) = static kvm_t *kvm; static struct nlist nl[] = { - { "_ifnet" }, { "_cp_time" }, { "" } }; @@ -86,45 +84,28 @@ kread(ulong addr, char *buf, int size) void xnet(int first) { + struct ifaddrs *ifap, *ifa; ulong out, in, outb, inb, err; - static ulong ifnetaddr; - ulong addr; - struct ifnet ifnet; - struct ifnethead ifnethead; - char name[16]; if(first) return; - if(ifnetaddr == 0){ - ifnetaddr = nl[0].n_value; - if(ifnetaddr == 0) - return; - } - - if(kread(ifnetaddr, (char*)&ifnethead, sizeof ifnethead) < 0) + if (getifaddrs(&ifap) != 0) return; out = in = outb = inb = err = 0; - addr = (ulong)TAILQ_FIRST(&ifnethead); - while(addr){ -#if __FreeBSD_version < 500000 - if(kread(addr, (char*)&ifnet, sizeof ifnet) < 0 - || kread((ulong)ifnet.if_name, name, 16) < 0) - return; -#else - if(kread(addr, (char*)&ifnet, sizeof ifnet) < 0 - || kread((ulong)ifnet.if_dname, name, 16) < 0) - return; -#endif - name[15] = 0; - addr = (ulong)TAILQ_NEXT(&ifnet, if_link); - out += ifnet.if_opackets; - in += ifnet.if_ipackets; - outb += ifnet.if_obytes; - inb += ifnet.if_ibytes; - err += ifnet.if_oerrors+ifnet.if_ierrors; +#define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s) + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (ifa->ifa_addr->sa_family != AF_LINK) + continue; + out += IFA_STAT(opackets); + in += IFA_STAT(ipackets); + outb += IFA_STAT(obytes); + inb += IFA_STAT(ibytes); + err += IFA_STAT(oerrors) + IFA_STAT(ierrors); } + freeifaddrs(ifap); + Bprint(&bout, "etherin %lud 1000\n", in); Bprint(&bout, "etherout %lud 1000\n", out); Bprint(&bout, "etherinb %lud 1000000\n", inb); diff --git a/src/cmd/draw/gview.c b/src/cmd/draw/gview.c index 68b6ad43..0794f100 100644 --- a/src/cmd/draw/gview.c +++ b/src/cmd/draw/gview.c @@ -209,16 +209,16 @@ int clrim_id(Image* clr) int i; for (i=0; clrtab[i].im!=clr; i++) if (clrtab[i].c==DNofill) - exits("bad image color"); + sysfatal("bad image color"); return i; } -int clr_id(int clr) +int clr_id(ulong clr) { int i; for (i=0; clrtab[i].c!=clr; i++) if (clrtab[i].c==DNofill) - exits("bad color"); + sysfatal("bad color %#x", clr); return i; } @@ -1995,7 +1995,7 @@ void main(int argc, char *argv[]) } ARGEND if(initdraw(0, 0, "gview") < 0) - exits("initdraw"); + sysfatal("initdraw"); einit(Emouse|Ekeyboard); e = doinput(*argv ? *argv : "-"); diff --git a/src/cmd/rc/unixcrap.c b/src/cmd/rc/unixcrap.c index 9393fb23..0b915635 100644 --- a/src/cmd/rc/unixcrap.c +++ b/src/cmd/rc/unixcrap.c @@ -58,7 +58,8 @@ eusage(void) void execulimit(void) { - int fd, n, argc, sethard, setsoft, limit; + rlim_t n; + int fd, argc, sethard, setsoft, limit; int flag[256]; char **argv, **oargv, *p; char *argv0; @@ -118,10 +119,10 @@ execulimit(void) for(p=eargs; *p; p++){ getrlimit(rlx[p-eargs], &rl); n = flag['H'] ? rl.rlim_max : rl.rlim_cur; - if(n == -1) + if(n == RLIM_INFINITY) fprint(fd, "ulimit -%c unlimited\n", *p); else - fprint(fd, "ulimit -%c %d\n", *p, n); + fprint(fd, "ulimit -%c %llud\n", *p, (uvlong)n); } goto out; } @@ -132,10 +133,10 @@ execulimit(void) switch(limit){ case Notset: n = flag['H'] ? rl.rlim_max : rl.rlim_cur; - if(n == -1) + if(n == RLIM_INFINITY) fprint(fd, "ulimit -%c unlimited\n", *p); else - fprint(fd, "ulimit -%c %d\n", *p, n); + fprint(fd, "ulimit -%c %llud\n", *p, (uvlong)n); break; case Hard: n = rl.rlim_max; @@ -144,7 +145,7 @@ execulimit(void) n = rl.rlim_cur; goto set; case Unlimited: - n = -1; + n = RLIM_INFINITY; goto set; default: n = limit; |