summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLandry Breuil <landry@rhaalovely.net>2011-03-07 20:14:24 +0100
committerRichard Hughes <richard@hughsie.com>2011-03-21 18:40:07 +0000
commit5e69186399741889ec369bd05b1daa006888d60c (patch)
treee6d8a3d08bb25ad79afe6d310498c5e151fc197e /src
parent0580fed09a5cdc73e8b9f6839917a848a664435f (diff)
openbsd: add up_native_has_sensor() and use it in is_laptop()
Signed-off-by: Richard Hughes <richard@hughsie.com>
Diffstat (limited to 'src')
-rw-r--r--src/openbsd/up-apm-native.h1
-rw-r--r--src/openbsd/up-native.c33
2 files changed, 34 insertions, 0 deletions
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 <sys/param.h>
+#include <sys/sensors.h>
+#include <sys/sysctl.h>
+#include <errno.h>
/* 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;
+}