okra pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=b6b143bf0cb54465867ee35af40ff8ad95eacb50

commit b6b143bf0cb54465867ee35af40ff8ad95eacb50
Author: Al netstar Poole <[email protected]>
Date:   Thu Feb 2 15:48:48 2017 -0600

    Make sysinfo gadgets work with BSD
---
 src/modules/cpufreq/e_mod_main.c               | 38 +++++++++++++--------
 src/modules/sysinfo/batman/batman.c            | 16 +++++----
 src/modules/sysinfo/cpuclock/cpuclock.c        | 19 ++++++-----
 src/modules/sysinfo/cpuclock/cpuclock_sysctl.c | 16 ++++-----
 src/modules/sysinfo/thermal/thermal.c          | 28 ++++++++--------
 src/modules/sysinfo/thermal/thermal_sysctl.c   | 46 ++++++++++++--------------
 6 files changed, 87 insertions(+), 76 deletions(-)

diff --git a/src/modules/cpufreq/e_mod_main.c b/src/modules/cpufreq/e_mod_main.c
index 24a9003..3c72636 100644
--- a/src/modules/cpufreq/e_mod_main.c
+++ b/src/modules/cpufreq/e_mod_main.c
@@ -6,7 +6,7 @@
  *       in s->frequencies instead of available frequencies.
  */
 
-#if defined (__FreeBSD__) || defined (__OpenBSD__)
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined (__OpenBSD__)
 # include <sys/sysctl.h>
 #endif
 
@@ -96,6 +96,7 @@ _gc_init(E_Gadcon *gc, const char *name, const char *id, 
const char *style)
                                   _button_cb_mouse_down, inst);
    cpufreq_config->instances =
      eina_list_append(cpufreq_config->instances, inst);
+
    _cpufreq_face_update_available(inst);
 
    cpufreq_config->handler =
@@ -488,6 +489,9 @@ _cpufreq_set_governor(const char *governor)
 {
    char buf[4096];
    int ret;
+   struct stat st;
+
+   if (stat(cpufreq_config->set_exe_path, &st) < 0) return;
 
    snprintf(buf, sizeof(buf),
             "%s %s %s", cpufreq_config->set_exe_path, "governor", governor);
@@ -515,7 +519,7 @@ _cpufreq_set_frequency(int frequency)
    char buf[4096];
    int ret;
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
    frequency /= 1000;
 #endif
    if (!cpufreq_config->status->can_set_frequency)
@@ -564,12 +568,14 @@ _cpufreq_set_frequency(int frequency)
 void
 _cpufreq_set_pstate(int min, int max)
 {
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
+   (void) min;
+   (void) max;
+#else
    char buf[4096];
-   int ret;
-
    snprintf(buf, sizeof(buf),
             "%s %s %i %i %i", cpufreq_config->set_exe_path, "pstate", min, 
max, cpufreq_config->status->pstate_turbo);
-   ret = system(buf);
+   int ret = system(buf);
    if (ret != 0)
      {
         E_Dialog *dia;
@@ -585,6 +591,7 @@ _cpufreq_set_pstate(int min, int max)
         elm_win_center(dia->win, 1, 1);
         e_dialog_show(dia);
      }
+#endif
 }
 
 static Cpu_Status *
@@ -631,9 +638,11 @@ _cpufreq_cb_sort(const void *item1, const void *item2)
 static void
 _cpufreq_status_check_available(Cpu_Status *s)
 {
+   // FIXME: this assumes all cores accept the same freqs/ might be wrong
+#if !defined(__OpenBSD__)
    char buf[4096];
    Eina_List *l;
-   // FIXME: this assumes all cores accept the same freqs/ might be wrong
+#endif
 
 #if defined (__OpenBSD__)
    int p;
@@ -646,14 +655,14 @@ _cpufreq_status_check_available(Cpu_Status *s)
 
    /* storing percents */
    p = 100;
-   s->frequencies = eina_list_append(s->frequencies, (void *)p);
+   s->frequencies = eina_list_append(s->frequencies, (void *)(long int)p);
    p = 75;
-   s->frequencies = eina_list_append(s->frequencies, (void *)p);
+   s->frequencies = eina_list_append(s->frequencies, (void *)(long int)p);
    p = 50;
-   s->frequencies = eina_list_append(s->frequencies, (void *)p);
+   s->frequencies = eina_list_append(s->frequencies, (void *)(long int)p);
    p = 25;
-   s->frequencies = eina_list_append(s->frequencies, (void *)p);
-#elif defined (__FreeBSD__)
+   s->frequencies = eina_list_append(s->frequencies, (void *)(long int)p);
+#elif defined (__FreeBSD__) || defined(__DragonFly__)
    int freq;
    size_t len = sizeof(buf);
    char *pos, *q;
@@ -847,7 +856,7 @@ _cpufreq_status_check_current(Cpu_Status *s)
    s->can_set_frequency = 1;
    s->cur_governor = NULL;
 
-#elif defined (__FreeBSD__)
+#elif defined (__FreeBSD__) || defined(__DragonFly__)
    size_t len = sizeof(frequency);
    s->active = 0;
 
@@ -1019,6 +1028,10 @@ _cpufreq_face_update_available(Instance *inst)
         edje_object_message_send(inst->o_cpu, EDJE_MESSAGE_STRING_SET, 2, 
governor_msg);
         free(governor_msg);
      }
+#if defined(__OpenBSD__)
+   _cpufreq_face_update_current(inst);
+#endif
+
 }
 
 static void
@@ -1465,7 +1478,6 @@ e_modapi_init(E_Module *m)
    cpufreq_config->module = m;
 
    e_gadcon_provider_register(&_gadcon_class);
-   
    snprintf(buf, sizeof(buf), "%s/e-module-cpufreq.edj", e_module_dir_get(m));
    e_configure_registry_category_add("advanced", 80, _("Advanced"), NULL,
                                      "preferences-advanced");
diff --git a/src/modules/sysinfo/batman/batman.c 
b/src/modules/sysinfo/batman/batman.c
index b194445..28c1096 100644
--- a/src/modules/sysinfo/batman/batman.c
+++ b/src/modules/sysinfo/batman/batman.c
@@ -266,9 +266,9 @@ _batman_config_updated(Instance *inst)
    if ((inst->cfg->batman.force_mode == UNKNOWN) ||
        (inst->cfg->batman.force_mode == SUBSYSTEM))
      {
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
         ok = _batman_udev_start(inst);
-#elif defined __OpenBSD__ || defined __DragonFly__ || defined __FreeBSD__ || 
defined __NetBSD__
+#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) 
|| defined(__NetBSD__)
         ok = _batman_sysctl_start(inst);
 #else
         ok = _batman_upower_start();
@@ -430,9 +430,9 @@ _batman_removed_cb(void *data, Evas_Object *obj 
EINA_UNUSED, void *event_data)
 
    if (inst->o_main != event_data) return;
 
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
    _batman_udev_stop(inst);
-#elif defined __OpenBSD__ || defined __DragonFly__ || defined __FreeBSD__ || 
defined __NetBSD__
+#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) 
|| defined(__NetBSD__)
    _batman_sysctl_stop();
 #elif defined(upower)
    _batman_upower_stop();
@@ -440,7 +440,7 @@ _batman_removed_cb(void *data, Evas_Object *obj 
EINA_UNUSED, void *event_data)
    _batman_fallback_stop();
 #endif
 
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
    eeze_shutdown();
 #endif
 
@@ -454,14 +454,16 @@ void
 sysinfo_batman_remove(void *data, Evas *e EINA_UNUSED, Evas_Object *obj 
EINA_UNUSED, void *event_data EINA_UNUSED)
 {
    Instance *inst = data;
-
 #ifdef HAVE_EEZE
    _batman_udev_stop(inst);
-#elif defined __OpenBSD__ || defined __DragonFly__ || defined __FreeBSD__ || 
defined __NetBSD__
+#elif defined(__OpenBSD__) || defined(__DragonFly__) || defined(__FreeBSD__) 
|| defined(__NetBSD__)
+   (void) inst;
    _batman_sysctl_stop();
 #elif defined(upower)
+   (void) inst;
    _batman_upower_stop();
 #else
+   (void) inst;
    _batman_fallback_stop();
 #endif
 
diff --git a/src/modules/sysinfo/cpuclock/cpuclock.c 
b/src/modules/sysinfo/cpuclock/cpuclock.c
index 8e6e1c3..2ef6a39 100644
--- a/src/modules/sysinfo/cpuclock/cpuclock.c
+++ b/src/modules/sysinfo/cpuclock/cpuclock.c
@@ -78,11 +78,12 @@ _cpuclock_set_thread_frequency(void *data, Ecore_Thread *th 
EINA_UNUSED)
 {
    const char *freq = data;
 
-#if defined __FreeBSD__ || defined __OpenBSD__
-   _cpuclock_sysctl_frequency(freq);
-   return;
-#endif
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined (__OpenBSD__)
+   int frequency = atoi(freq);
+   _cpuclock_sysctl_frequency(frequency);
+#else
    _cpuclock_sysfs_setall("scaling_setspeed", freq);
+#endif
 }
 
 static void
@@ -322,8 +323,10 @@ _cpuclock_face_update_current(Instance *inst)
 static void
 _cpuclock_status_check_available(Cpu_Status *s)
 {
+#if !defined(__OpenBSD__)
    char buf[4096];
    Eina_List *l;
+#endif 
    // FIXME: this assumes all cores accept the same freqs/ might be wrong
 
 #if defined (__OpenBSD__)
@@ -337,13 +340,13 @@ _cpuclock_status_check_available(Cpu_Status *s)
 
    /* storing percents */
    p = 100;
-   s->frequencies = eina_list_append(s->frequencies, (void *)p);
+   s->frequencies = eina_list_append(s->frequencies, (void *)(long int)p);
    p = 75;
-   s->frequencies = eina_list_append(s->frequencies, (void *)p);
+   s->frequencies = eina_list_append(s->frequencies, (void *)(long int)p);
    p = 50;
-   s->frequencies = eina_list_append(s->frequencies, (void *)p);
+   s->frequencies = eina_list_append(s->frequencies, (void *)(long int)p);
    p = 25;
-   s->frequencies = eina_list_append(s->frequencies, (void *)p);
+   s->frequencies = eina_list_append(s->frequencies, (void *)(long int)p);
 #elif defined (__FreeBSD__)
    int freq;
    size_t len = sizeof(buf);
diff --git a/src/modules/sysinfo/cpuclock/cpuclock_sysctl.c 
b/src/modules/sysinfo/cpuclock/cpuclock_sysctl.c
index ecf0ec4..5f96b7e 100644
--- a/src/modules/sysinfo/cpuclock/cpuclock_sysctl.c
+++ b/src/modules/sysinfo/cpuclock/cpuclock_sysctl.c
@@ -1,16 +1,16 @@
 #include "cpuclock.h"
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
 # include <sys/sysctl.h>
 #endif
 
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__)
 # include <sys/param.h>
 # include <sys/resource.h>
 # include <sys/sysctl.h>
 #endif
 
 
-#if defined __OpenBSD__
+#if defined(__OpenBSD__)
 int
 _cpuclock_sysctl_frequency(int new_perf)
 {
@@ -19,16 +19,16 @@ _cpuclock_sysctl_frequency(int new_perf)
 
    if (sysctl(mib, 2, NULL, 0, &new_perf, len) == -1)
      return 1;
-   else
-     return 0;
+     
+   return 0;
 }
-#elif defined __FreeBSD__
+#elif defined(__FreeBSD__) || defined(__DragonFly__)
 int
 _cpuclock_sysctl_frequency(int new_perf)
 {
    if (sysctlbyname("dev.cpu.0.freq", NULL, NULL, &new_perf, sizeof(new_perf)) 
== -1)
      return 1;
-   else
-     return 0;
+ 
+   return 0;
 }
 #endif
diff --git a/src/modules/sysinfo/thermal/thermal.c 
b/src/modules/sysinfo/thermal/thermal.c
index 142e4d6..53135d7 100644
--- a/src/modules/sysinfo/thermal/thermal.c
+++ b/src/modules/sysinfo/thermal/thermal.c
@@ -3,13 +3,14 @@
 static void
 _thermal_thread_free(Tempthread *tth)
 {
+#if defined(HAVE_EEZE)
    const char *s;
-
+#endif
    if (!tth) return;
 
    eina_stringshare_del(tth->sensor_name);
    eina_stringshare_del(tth->sensor_path);
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
    EINA_LIST_FREE(tth->tempdevs, s) eina_stringshare_del(s);
 #endif
    free(tth->extn);
@@ -67,7 +68,7 @@ _thermal_apply(Instance *inst, int temp)
      }
 }
 
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
 static Eina_Bool
 _thermal_udev_poll(void *data)
 {
@@ -79,7 +80,7 @@ _thermal_udev_poll(void *data)
 }
 #endif
 
-#if defined __FreeBSD__ || defined __OpenBSD__ || defined __DragonflyBSD__
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
 static void
 _thermal_check_sysctl(void *data, Ecore_Thread *th)
 {
@@ -98,13 +99,12 @@ _thermal_check_sysctl(void *data, Ecore_Thread *th)
 }
 #endif
 
-#if !defined HAVE_EEZE && !defined __FreeBSD__ && !defined __OpenBSD__ && 
!defined __DragonflyBSD__
+#if !defined(HAVE_EEZE) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && 
!defined(__DragonFly__)
 static void
 _thermal_check_fallback(void *data, Ecore_Thread *th)
 {
    Tempthread *tth = data;
    int ptemp = -500, temp;
-
    for (;;)
      {
         if (ecore_thread_check(th)) break;
@@ -117,14 +117,13 @@ _thermal_check_fallback(void *data, Ecore_Thread *th)
 }
 #endif
 
-#if !defined HAVE_EEZE
+#if !defined(HAVE_EEZE)
 static void
 _thermal_check_notify(void *data, Ecore_Thread *th, void *msg)
 {
    Tempthread *tth  = data;
    Instance *inst = tth->inst;
    int temp = (int)((long)msg);
-
    if (th != inst->cfg->thermal.th) return;
    _thermal_apply(inst, temp);
 }
@@ -150,12 +149,12 @@ _thermal_config_updated(Instance *inst)
    if (inst->cfg->thermal.sensor_name)
      tth->sensor_name = eina_stringshare_add(inst->cfg->thermal.sensor_name);
 
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
    _thermal_udev_poll(tth);
    inst->cfg->thermal.poller = ecore_poller_add(ECORE_POLLER_CORE, 
inst->cfg->thermal.poll_interval,
                                      _thermal_udev_poll, tth);
    inst->cfg->thermal.tth = tth;
-#elif defined __FreeBSD__ || defined __OpenBSD__ || defined __DragonflyBSD__
+#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
     inst->cfg->thermal.th = ecore_thread_feedback_run(_thermal_check_sysctl,
                                         _thermal_check_notify,
                                         _thermal_check_done,
@@ -175,7 +174,7 @@ _thermal_face_shutdown(Instance *inst)
 {
    if (inst->cfg->thermal.th) ecore_thread_cancel(inst->cfg->thermal.th);
    if (inst->cfg->thermal.sensor_name) 
eina_stringshare_del(inst->cfg->thermal.sensor_name);
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
    if (inst->cfg->thermal.poller)
      {
         E_FREE_FUNC(inst->cfg->thermal.poller, ecore_poller_del);
@@ -206,7 +205,7 @@ _thermal_removed_cb(void *data, Evas_Object *obj 
EINA_UNUSED, void *event_data)
 
    _thermal_face_shutdown(inst);
 
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
    eeze_shutdown();
 #endif
 
@@ -223,7 +222,7 @@ sysinfo_thermal_remove(void *data, Evas *e EINA_UNUSED, 
Evas_Object *obj EINA_UN
 
    _thermal_face_shutdown(inst);
 
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
    eeze_shutdown();
 #endif
 }
@@ -313,12 +312,11 @@ thermal_create(Evas_Object *parent, int *id, 
E_Gadget_Site_Orient orient EINA_UN
    evas_object_event_callback_add(inst->o_main, EVAS_CALLBACK_DEL, 
sysinfo_thermal_remove, inst);
    evas_object_show(inst->o_main);
 
-#ifdef HAVE_EEZE
+#if defined(HAVE_EEZE)
    eeze_init();
 #endif
 
    if (inst->cfg->id < 0) return inst->o_main;
-
    sysinfo_instances =
      eina_list_append(sysinfo_instances, inst);
 
diff --git a/src/modules/sysinfo/thermal/thermal_sysctl.c 
b/src/modules/sysinfo/thermal/thermal_sysctl.c
index 4c636f0..e17e2db 100644
--- a/src/modules/sysinfo/thermal/thermal_sysctl.c
+++ b/src/modules/sysinfo/thermal/thermal_sysctl.c
@@ -1,30 +1,30 @@
 #include "thermal.h"
 
-#if defined (__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__DragonFly__)
 # include <sys/types.h>
 # include <sys/sysctl.h>
 # include <errno.h>
 #endif
 
-#ifdef __OpenBSD__
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#include <sys/sensors.h>
-#include <errno.h>
-#include <err.h>
+#if defined(__OpenBSD__)
+# include <sys/param.h>
+# include <sys/sysctl.h>
+# include <sys/sensors.h>
+# include <errno.h>
+# include <err.h>
 #endif
 
-#if defined (__FreeBSD__) || defined(__DragonFly__) || defined (__OpenBSD__)
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
 typedef struct
 {
    int mib[CTL_MAXNAME];
-#if defined (__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__DragonFly__)
    unsigned int miblen;
 #endif
    int dummy;
 } Extn;
 
-#if defined (__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__DragonFly__)
 static const char *sources[] =
   {
      "hw.acpi.thermal.tz0.temperature",
@@ -35,7 +35,7 @@ static const char *sources[] =
   };
 #endif
 
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__)
 static struct sensor snsr;
 static size_t slen = sizeof(snsr);
 #endif
@@ -43,20 +43,19 @@ static size_t slen = sizeof(snsr);
 static void
 init(Tempthread *tth)
 {
-   Eina_List *therms;
-   char path[512];
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__)
    int dev, numt;
    struct sensordev snsrdev;
    size_t sdlen = sizeof(snsrdev);
 #endif
+
 #if defined (__FreeBSD__) || defined(__DragonFly__)
    unsigned i;
    size_t len;
    int rc;
 #endif
-   Extn *extn;
 
+   Extn *extn;
    if (tth->initted) return;
    tth->initted = EINA_TRUE;
 
@@ -71,6 +70,7 @@ init(Tempthread *tth)
         tth->sensor_name = NULL;
         eina_stringshare_del(tth->sensor_path);
         tth->sensor_path = NULL;
+
 #if defined (__FreeBSD__) || defined(__DragonFly__)
         for (i = 0; sources[i]; i++)
           {
@@ -82,6 +82,7 @@ init(Tempthread *tth)
                   break;
                }
           }
+
 #elif defined(__OpenBSD__)
         extn->mib[0] = CTL_HW;
         extn->mib[1] = HW_SENSORS;
@@ -99,13 +100,13 @@ init(Tempthread *tth)
              if (strcmp(snsrdev.xname, "cpu0") == 0)
                {
                   tth->sensor_type = SENSOR_TYPE_OPENBSD;
-                  tth->sensor_name = strdup("cpu0");
+                  tth->sensor_name = eina_stringshare_add("cpu0");
                   break;
                }
              else if (strcmp(snsrdev.xname, "km0") == 0)
                {
                   tth->sensor_type = SENSOR_TYPE_OPENBSD;
-                  tth->sensor_name = strdup("km0");
+                  tth->sensor_name = eina_stringshare_add("km0");
                   break;
                }
           }
@@ -113,11 +114,9 @@ init(Tempthread *tth)
      }
    if ((tth->sensor_type) && (tth->sensor_name) && (!tth->sensor_path))
      {
-        char *name;
-
         if (tth->sensor_type == SENSOR_TYPE_FREEBSD)
           {
-#if defined (__FreeBSD__) || defined(__DragonFly__)
+#if defined(__FreeBSD__) || defined(__DragonFly__)
              len = sizeof(extn->mib) / sizeof(extn->mib[0]);
              rc = sysctlnametomib(tth->sensor_name, extn->mib, &len);
              if (rc == 0)
@@ -129,7 +128,7 @@ init(Tempthread *tth)
           }
         else if (tth->sensor_type == SENSOR_TYPE_OPENBSD)
           {
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__)
              for (numt = 0; numt < snsrdev.maxnumt[SENSOR_TEMP]; numt++)
                {
                   extn->mib[4] = numt;
@@ -149,10 +148,8 @@ init(Tempthread *tth)
 static int
 check(Tempthread *tth)
 {
-   FILE *f = NULL;
    int ret = 0;
    int temp = 0;
-   char buf[512];
 #if defined (__FreeBSD__) || defined(__DragonFly__)
    size_t len;
    size_t ftemp = 0;
@@ -180,7 +177,7 @@ check(Tempthread *tth)
      }
    else if (tth->sensor_type == SENSOR_TYPE_OPENBSD)
      {
-#ifdef __OpenBSD_
+#if defined(__OpenBSD__)
         if (sysctl(extn->mib, 5, &snsr, &slen, NULL, 0) != -1)
           {
              temp = (snsr.value - 273150000) / 1000000.0;
@@ -194,7 +191,6 @@ if (ret) return temp;
 
    return -999;
 error:
-   if (f) fclose(f);
    tth->sensor_type = SENSOR_TYPE_NONE;
    eina_stringshare_del(tth->sensor_name);
    tth->sensor_name = NULL;

-- 


Reply via email to