From 5e69186399741889ec369bd05b1daa006888d60c Mon Sep 17 00:00:00 2001 From: Landry Breuil Date: Mon, 7 Mar 2011 20:14:24 +0100 Subject: openbsd: add up_native_has_sensor() and use it in is_laptop() Signed-off-by: Richard Hughes --- src/openbsd/up-apm-native.h | 1 + src/openbsd/up-native.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) (limited to 'src/openbsd') diff --git a/src/openbsd/up-apm-native.h b/src/openbsd/up-apm-native.h index 961bd33..c2c3698 100644 --- a/src/openbsd/up-apm-native.h +++ b/src/openbsd/up-apm-native.h @@ -44,6 +44,7 @@ typedef struct UpApmNative* up_apm_native_new (const char*); const gchar * up_apm_native_get_path(UpApmNative*); gboolean up_native_is_laptop(); +gboolean up_native_has_sensor(const char*); G_END_DECLS #endif diff --git a/src/openbsd/up-native.c b/src/openbsd/up-native.c index 031b01a..678d840 100644 --- a/src/openbsd/up-native.c +++ b/src/openbsd/up-native.c @@ -1,6 +1,10 @@ #include "up-apm-native.h" #include "up-native.h" +#include +#include +#include +#include /* XXX why does this macro needs to be in the .c ? */ G_DEFINE_TYPE (UpApmNative, up_apm_native, G_TYPE_OBJECT) @@ -53,6 +57,10 @@ up_native_is_laptop() { int apm_fd; struct apm_power_info bstate; + + if (up_native_has_sensor("acpiac0")) + return TRUE; + if ((apm_fd = open("/dev/apm", O_RDONLY)) == -1) { if (errno != ENXIO && errno != ENOENT) g_error("cannot open device file"); @@ -62,3 +70,28 @@ up_native_is_laptop() close(apm_fd); return bstate.ac_state != APM_AC_UNKNOWN; } + +/** + * detect if a sensordev is present by its xname (acpibatX/acpiacX) + */ +gboolean +up_native_has_sensor(const char * id) +{ + int devn; + struct sensordev snsrdev; + size_t sdlen = sizeof(snsrdev); + int mib[] = {CTL_HW, HW_SENSORS, 0, 0 ,0}; + + for (devn = 0 ; ; devn++) { + mib[2] = devn; + if (sysctl(mib, 3, &snsrdev, &sdlen, NULL, 0) == -1) { + if (errno == ENXIO) + continue; + if (errno == ENOENT) + break; + } + if (!strcmp(snsrdev.xname, id)) + return TRUE; + } + return FALSE; +} -- cgit v1.2.1