Re: [hackers] [slstatus][patch] corrected calculation for swap on openbsd

2018-05-16 Thread Aaron Marcher

Tobias,

thanks again for your patch. Great to have you on board as a 
contributor.


Cheers!
Aaron

--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE



[hackers] [slstatus][patch] corrected calculation for swap on openbsd

2018-05-16 Thread Tobias Tschinkowitz
Hi again!

The swapctl(2) function fills the swapent struct with 512KB blocks.
As we want to display in GB, i just modified the calculation for this to
get the expected output.

Greetings,
Tobias

---
 components/swap.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git components/swap.c components/swap.c
index 031b713..caa4788 100644
--- components/swap.c
+++ components/swap.c
@@ -131,8 +131,6 @@
#include 
#include 
 
-   #define dbtoqb(b) dbtob((int64_t)(b))
-
static void
getstats(int *total, int *used)
{
@@ -162,8 +160,8 @@
*used = 0;
 
for (i = 0; i < rnswap; i++) {
-   *total += dbtoqb(sep->se_nblks);
-   *used += dbtoqb(sep->se_inuse);
+   *total += sep->se_nblks >> 1;
+   *used += sep->se_inuse >> 1;
}
 
free(fsep);
@@ -176,7 +174,7 @@
 
getstats(, );
 
-   return bprintf("%f", (float)(total - used) / 1024 / 1024 / 
1024);
+   return bprintf("%f", (float)(total - used) / 1024 / 1024);
}
 
const char *
@@ -196,7 +194,7 @@
 
getstats(, );
 
-   return bprintf("%f", (float)total / 1024 / 1024 / 1024);
+   return bprintf("%f", (float)total / 1024 / 1024);
}
 
const char *
@@ -206,6 +204,6 @@
 
getstats(, );
 
-   return bprintf("%f", (float)used / 1024 / 1024 / 1024);
+   return bprintf("%f", (float)used / 1024 / 1024);
}
 #endif
-- 
2.16.2