Re: [hackers] [slstatus][PATCH] Add FreeBSD support for netspeeds, entropy and ip components

2019-02-05 Thread Michael Buch
Hey,
Thanks for reviewing!

As far as I know, similar to OpenBSD, in FreeBSD entropy is not a stat
that's useful (or readily available) since both use prng schemes that
deal with low available entropy. [1] There is a way to inspect whether
the random device is properly seeded or will block. But that wouldn't
be the same as what slstatus does for Linux.

1: https://lists.freebsd.org/pipermail/freebsd-questions/2008-April/173086.html

Thanks,
Michael


Am Di., 5. Feb. 2019 um 08:36 Uhr schrieb Aaron Marcher :
>
> Hi Michael,
>
> the entropy function on OpenBSD is kind of a easter egg. Could you look
> into "really" porting it to FreeBSD?
> Thank you very much for your motivation of porting slstatus to FreeBSD.
> I merged the other patches already.
>
> 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
>



Re: [hackers] [slstatus][PATCH] Add FreeBSD support for netspeeds, entropy and ip components

2019-02-05 Thread Aaron Marcher

Hi Michael,

the entropy function on OpenBSD is kind of a easter egg. Could you look 
into "really" porting it to FreeBSD?
Thank you very much for your motivation of porting slstatus to FreeBSD.  
I merged the other patches already.


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] Update LICENSE || Aaron Marcher

2019-02-05 Thread git
commit b6d0bd2fe45283b24e3e69a61671bd3ac615a9b4
Author: Aaron Marcher 
AuthorDate: Tue Feb 5 09:32:47 2019 +0100
Commit: Aaron Marcher 
CommitDate: Tue Feb 5 09:32:47 2019 +0100

Update LICENSE

diff --git a/LICENSE b/LICENSE
index 6be9570..2ab31bf 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 ISC License
 
-Copyright 2016-2018 Aaron Marcher 
+Copyright 2016-2019 Aaron Marcher 
 
 Copyright 2016 Roy Freytag 
 Copyright 2016 Vincent Loupmon 
@@ -16,7 +16,7 @@ Copyright 2018 Darron Anderson 
 Copyright 2018 Josuah Demangeon 
 Copyright 2018 Tobias Tschinkowitz 
 Copyright 2018 David Demelier 
-Copyright 2018 Michael Buch 
+Copyright 2018-2019 Michael Buch 
 Copyright 2018 Ian Remmler 
 
 Permission to use, copy, modify, and/or distribute this software for any



[hackers] [slstatus] Add FreeBSD support for temperature and battery components || Michael Buch

2019-02-05 Thread git
commit ec306623df7321a4e6ec11f70b6152a2e614d1ed
Author: Michael Buch 
AuthorDate: Sun Jan 27 15:44:39 2019 +
Commit: Aaron Marcher 
CommitDate: Tue Feb 5 09:30:21 2019 +0100

Add FreeBSD support for temperature and battery components

diff --git a/components/battery.c b/components/battery.c
index 1178f20..07b6ac1 100644
--- a/components/battery.c
+++ b/components/battery.c
@@ -195,4 +195,57 @@
 
return NULL;
}
+#elif defined(__FreeBSD__)
+   #include 
+
+   const char *
+   battery_perc(const char *unused)
+   {
+   int cap;
+   size_t len;
+
+   len = sizeof(cap);
+   if (sysctlbyname("hw.acpi.battery.life", &cap, &len, NULL, 0) 
== -1
+   || !len)
+   return NULL;
+
+   return bprintf("%d", cap);
+   }
+
+   const char *
+   battery_state(const char *unused)
+   {
+   int state;
+   size_t len;
+
+   len = sizeof(state);
+   if (sysctlbyname("hw.acpi.battery.state", &state, &len, NULL, 
0) == -1
+   || !len)
+   return NULL;
+
+   switch(state) {
+   case 0:
+   case 2:
+   return "+";
+   case 1:
+   return "-";
+   default:
+   return "?";
+   }
+   }
+
+   const char *
+   battery_remaining(const char *unused)
+   {
+   int rem;
+   size_t len;
+
+   len = sizeof(rem);
+   if (sysctlbyname("hw.acpi.battery.time", &rem, &len, NULL, 0) 
== -1
+   || !len
+   || rem == -1)
+   return NULL;
+
+   return bprintf("%uh %02um", rem / 60, rem % 60);
+   }
 #endif
diff --git a/components/temperature.c b/components/temperature.c
index d56cc0e..8462d0f 100644
--- a/components/temperature.c
+++ b/components/temperature.c
@@ -3,6 +3,7 @@
 
 #include "../util.h"
 
+
 #if defined(__linux__)
#include 
 
@@ -46,4 +47,25 @@
/* kelvin to celsius */
return bprintf("%d", (temp.value - 27315) / 1E6);
}
+#elif defined(__FreeBSD__)
+   #include 
+   #include 
+   #include 
+
+   const char *
+   temp(const char *zone)
+   {
+   char buf[256];
+   int temp;
+   size_t len;
+
+   len = sizeof(temp);
+   snprintf(buf, sizeof(buf), "hw.acpi.thermal.%s.temperature", 
zone);
+   if (sysctlbyname(buf, &temp, &len, NULL, 0) == -1
+   || !len)
+   return NULL;
+
+   /* kelvin to decimal celcius */
+   return bprintf("%d.%d", (temp - 2731) / 10, abs((temp - 2731) % 
10));
+   }
 #endif
diff --git a/config.def.h b/config.def.h
index ccc2aee..e06be66 100644
--- a/config.def.h
+++ b/config.def.h
@@ -13,11 +13,11 @@ static const char unknown_str[] = "n/a";
  * functiondescription argument (example)
  *
  * battery_percbattery percentage  battery name (BAT0)
- * NULL on OpenBSD
+ * NULL on OpenBSD/FreeBSD
  * battery_state   battery charging state  battery name (BAT0)
- * NULL on OpenBSD
+ * NULL on OpenBSD/FreeBSD
  * battery_remaining   battery remaining HH:MM battery name (BAT0)
- * NULL on OpenBSD
+ * NULL on OpenBSD/FreeBSD
  * cpu_perccpu usage in percentNULL
  * cpu_freqcpu frequency in MHzNULL
  * datetimedate and time   format string (%F %T)
@@ -52,6 +52,8 @@ static const char unknown_str[] = "n/a";
  * temptemperature in degree celsius   sensor file
  * (/sys/class/thermal/...)
  * NULL on OpenBSD
+ * thermal zone on FreeBSD
+ * (tz0, tz1, etc.)
  * uid UID of current user NULL
  * uptime  system uptime   NULL
  * usernameusername of current userNULL



[hackers] [slstatus] Add support for cpu and uptime components on FreeBSD || Michael Buch

2019-02-05 Thread git
commit 120d15059425b522db464e6f3f857bee4a781cce
Author: Michael Buch 
AuthorDate: Tue Feb 5 02:44:37 2019 +
Commit: Aaron Marcher 
CommitDate: Tue Feb 5 09:31:06 2019 +0100

Add support for cpu and uptime components on FreeBSD

diff --git a/components/cpu.c b/components/cpu.c
index d4f8064..9a021d5 100644
--- a/components/cpu.c
+++ b/components/cpu.c
@@ -93,6 +93,56 @@
return NULL;
}
 
+   return bprintf("%d", 100 *
+  ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
+a[CP_INTR]) -
+   (b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
+b[CP_INTR])) /
+  ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
+a[CP_INTR] + a[CP_IDLE]) -
+   (b[CP_USER] + b[CP_NICE] + b[CP_SYS] +
+b[CP_INTR] + b[CP_IDLE])));
+   }
+#elif defined(__FreeBSD__)
+   #include 
+   #include 
+   #include 
+
+   const char *
+   cpu_freq(void)
+   {
+   int freq;
+   size_t size;
+
+   size = sizeof(freq);
+   /* in MHz */
+   if (sysctlbyname("hw.clockrate", &freq, &size, NULL, 0) == -1
+   || !size) {
+   warn("sysctlbyname 'hw.clockrate':");
+   return NULL;
+   }
+
+   return fmt_human(freq * 1E6, 1000);
+   }
+
+   const char *
+   cpu_perc(void)
+   {
+   size_t size;
+   static long a[CPUSTATES];
+   long b[CPUSTATES];
+
+   size = sizeof(a);
+   memcpy(b, a, sizeof(b));
+   if (sysctlbyname("kern.cp_time", &a, &size, NULL, 0) == -1
+   || !size) {
+   warn("sysctlbyname 'kern.cp_time':");
+   return NULL;
+   }
+   if (b[0] == 0) {
+   return NULL;
+   }
+
return bprintf("%d", 100 *
   ((a[CP_USER] + a[CP_NICE] + a[CP_SYS] +
 a[CP_INTR]) -
diff --git a/components/uptime.c b/components/uptime.c
index 978f88f..7c23c98 100644
--- a/components/uptime.c
+++ b/components/uptime.c
@@ -5,14 +5,24 @@
 
 #include "../util.h"
 
+#if defined(CLOCK_BOOTTIME)
+   #define UPTIME_FLAG CLOCK_BOOTTIME
+#elif defined(CLOCK_UPTIME)
+   #define UPTIME_FLAG CLOCK_UPTIME
+#else
+   #define UPTIME_FLAG CLOCK_MONOTONIC
+#endif
+
 const char *
 uptime(void)
 {
+   char warn_buf[256];
uintmax_t h, m;
struct timespec uptime;
 
-   if (clock_gettime(CLOCK_BOOTTIME, &uptime) < 0) {
-   warn("clock_gettime 'CLOCK_BOOTTIME'");
+   if (clock_gettime(UPTIME_FLAG, &uptime) < 0) {
+   snprintf(warn_buf, 256, "clock_gettime %d", UPTIME_FLAG);
+   warn(warn_buf);
return NULL;
}