shithub: fork

Download patch

ref: 4ee8c1580c81d927c2a87baccaf2c875ae89f751
parent: 1d517245a7bc67cd8e81249f8b45bb78926ead55
author: qwx <qwx@sciops.net>
date: Tue Aug 5 06:03:54 EDT 2025

stats: sync with upstream

--- a/sys/src/cmd/stats.c
+++ b/sys/src/cmd/stats.c
@@ -69,7 +69,6 @@
 	int		swapfd;
 	int		etherfd[10];
 	int		batteryfd;
-	int		bitsybatfd;
 	int		tempfd;
 	int		disable;
 
@@ -238,7 +237,7 @@
 int	logscale = 0;
 int	ylabels = 0;
 int	sleeptime = 1000;
-int	batteryperiod = 1000;
+int	batteryperiod = 10000;
 int	tempperiod = 1000;
 
 char	*procnames[NPROC] = {"main", "input"};
@@ -419,7 +418,7 @@
 uvlong
 roundvmax(uvlong v)
 {
-	int e, o;
+	vlong e, o;
 
 	e = ceil(log10(v)) - 2;
 	if(e <= 0)
@@ -681,6 +680,11 @@
 	uvlong a[MAXNUM];
 	char *p, mpt[256], buf[256];
 	Dir *d;
+	static char *archplaces[] = {
+		"/dev",
+		"/mnt/pm",
+		"/mnt/apm",	/* battery only */
+	};
 
 	p = strchr(name, '!');
 	if(p)
@@ -753,33 +757,25 @@
 	while(n < nelem(m->etherfd))
 		m->etherfd[n++] = -1;
 
-	snprint(buf, sizeof buf, "%s/mnt/apm/battery", mpt);
-	m->batteryfd = open(buf, OREAD);
-	if(m->batteryfd < 0){
-		snprint(buf, sizeof buf, "%s/mnt/pm/battery", mpt);
+	for(i=0; i < nelem(archplaces); i++){
+		snprint(buf, sizeof buf, "%s/%s/battery", mpt, archplaces[i]);
 		m->batteryfd = open(buf, OREAD);
-	}
-	m->bitsybatfd = -1;
-	if(m->batteryfd >= 0){
-		batteryperiod = 10000;
+		if(m->batteryfd < 0)
+			continue;
 		if(loadbuf(m, &m->batteryfd) && readnums(m, nelem(m->batterystats), a, 0))
 			memmove(m->batterystats, a, sizeof(m->batterystats));
-	}else{
-		snprint(buf, sizeof buf, "%s/dev/battery", mpt);
-		m->bitsybatfd = open(buf, OREAD);
-		if(loadbuf(m, &m->bitsybatfd) && readnums(m, 1, a, 0))
-			memmove(m->batterystats, a, sizeof(m->batterystats));
+		break;
 	}
-	snprint(buf, sizeof buf, "%s/dev/cputemp", mpt);
-	m->tempfd = open(buf, OREAD);
-	if(m->tempfd < 0){
-		tempperiod = 5000;
-		snprint(buf, sizeof buf, "%s/mnt/pm/cputemp", mpt);
+	for(i=0; i < nelem(archplaces); i++){
+		snprint(buf, sizeof buf, "%s/%s/cputemp", mpt, archplaces[i]);
 		m->tempfd = open(buf, OREAD);
+		if(m->tempfd < 0)
+			continue;
+		if(loadbuf(m, &m->tempfd))
+			for(n=0; n < nelem(m->temp) && readnums(m, 2, a, 0); n++)
+				m->temp[n] = a[0];
+		break;
 	}
-	if(loadbuf(m, &m->tempfd))
-		for(n=0; n < nelem(m->temp) && readnums(m, 2, a, 0); n++)
-			 m->temp[n] = a[0];
 	return 1;
 }
 
@@ -895,8 +891,6 @@
 	if(needbattery(init)){
 		if(loadbuf(m, &m->batteryfd) && readnums(m, nelem(m->batterystats), a, 0))
 			memmove(m->batterystats, a, sizeof(m->batterystats));
-		else if(loadbuf(m, &m->bitsybatfd) && readnums(m, 1, a, 0))
-			memmove(m->batterystats, a, sizeof(m->batterystats));
 	}
 	if(needtemp(init) && loadbuf(m, &m->tempfd))
 		for(n=0; n < nelem(m->temp) && readnums(m, 2, a, 0); n++)
@@ -1079,10 +1073,7 @@
 batteryval(Machine *m, uvlong *v, uvlong *vmax, int)
 {
 	*v = m->batterystats[0];
-	if(m->bitsybatfd >= 0)
-		*vmax = 184;		// at least on my bitsy...
-	else
-		*vmax = 100;
+	*vmax = 100;
 }
 
 void
--