Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysutils/htop doesn't report an uptime in some cases #238

Open
daftaupe opened this issue Dec 10, 2022 · 2 comments
Open

sysutils/htop doesn't report an uptime in some cases #238

daftaupe opened this issue Dec 10, 2022 · 2 comments

Comments

@daftaupe
Copy link
Member

As reported by rubin on the irc channel, sometimes htop doesn't provide an uptime as it's shown in the following image (see Uptime: (unknown) in the upper right top) screenshot

@daftaupe
Copy link
Member Author

There might be an issue in htop in dragonflybsd/Platform.c

There's a line sysctl(mib, 2, &bootTime, &size, NULL, 0);
with
mib[2] = { CTL_KERN, KERN_BOOTTIME };
and bootTime being a struct timeval, but it seems that according to sysctl(3), at KERN_BOOTTIME A struct timespec structure is returned.

Maybe it could be fixed using that patch, but not sure. In anycase, the package containing that patch has been sent to rubin in case he could reproduce the issue and see if htop behaves better with that modification.

git diff HEAD~1 HEAD
diff --git a/ports/sysutils/htop/dragonfly/patch-dragonflybsd_Platform.c b/ports/sysutils/htop/dragonfly/patch-dragonflybsd_Platform.c
index 3e33ead45f2..cd73da4f479 100644
--- a/ports/sysutils/htop/dragonfly/patch-dragonflybsd_Platform.c
+++ b/ports/sysutils/htop/dragonfly/patch-dragonflybsd_Platform.c
@@ -1,7 +1,35 @@
---- dragonflybsd/Platform.c.orig       2020-12-22 06:39:42 UTC
-+++ dragonflybsd/Platform.c
-@@ -207,10 +207,26 @@ void Platform_setSwapValues(Meter* this)
-    this->values[0] = pl->usedSwap;
+--- dragonflybsd/Platform.c.orig       2022-11-29 15:04:07.229269000 +0100
++++ dragonflybsd/Platform.c    2022-11-29 15:25:39.553506000 +0100
+@@ -127,17 +127,22 @@
+ }
+
+ int Platform_getUptime() {
+-   struct timeval bootTime, currTime;
++   struct timespec bootTimeTs, currTimeTs;
++   struct timeval bootTimeTv, currTimeTv;
+    int mib[2] = { CTL_KERN, KERN_BOOTTIME };
+-   size_t size = sizeof(bootTime);
++   size_t size = sizeof(bootTimeTs);
+
+-   int err = sysctl(mib, 2, &bootTime, &size, NULL, 0);
++   int err = sysctl(mib, 2, &bootTimeTs, &size, NULL, 0);
+    if (err) {
+       return -1;
+    }
+-   gettimeofday(&currTime, NULL);
+
+-   return (int) difftime(currTime.tv_sec, bootTime.tv_sec);
++   TIMESPEC_TO_TIMEVAL(&currTimeTv, &currTimeTs);
++   gettimeofday(&currTimeTv, NULL);
++
++   TIMESPEC_TO_TIMEVAL(&bootTimeTv, &bootTimeTs);
++
++   return (int) difftime(currTimeTv.tv_sec, bootTimeTv.tv_sec);
+ }
+
+ void Platform_getLoadAverage(double* one, double* five, double* fifteen) {
+@@ -222,10 +227,26 @@
+    this->values[1] = NAN;
  }

@daftaupe
Copy link
Member Author

Could it be linked to https://bugs.dragonflybsd.org/issues/3299 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant