Permalink
Browse files

devices/sensors: Added HDD temperature sensors from udisks2

  • Loading branch information...
ocerman authored and lpereira committed Jan 12, 2019
1 parent 1eb28cd commit 7c0151830c81540f1b91e91216e91b2fc0a97cd0
Showing with 77 additions and 0 deletions.
  1. +50 −0 hardinfo/udisks2_util.c
  2. +6 −0 includes/udisks2_util.h
  3. +21 −0 modules/devices/sensors.c
@@ -211,10 +211,21 @@ GDBusConnection* get_udisks2_connection(void) {
return conn;
}

udiskt* udiskt_new() {
return g_new0(udiskt, 1);
}

udiskd* udiskd_new() {
return g_new0(udiskd, 1);
}

void udiskt_free(udiskt *u) {
if (u) {
g_free(u->drive);
g_free(u);
}
}

void udiskd_free(udiskd *u) {
if (u) {
g_free(u->model);
@@ -229,6 +240,41 @@ void udiskd_free(udiskd *u) {
}
}

gpointer get_udisks2_temp(const char *blockdev, GDBusProxy *drive){
GVariant *v;
gboolean smart_enabled = FALSE;
udiskt* disk_temp = NULL;

v = get_dbus_property(drive, UDISKS2_DRIVE_ATA_INTERFACE, "SmartEnabled");
if (v) {
smart_enabled = g_variant_get_boolean(v);
g_variant_unref(v);
}

if (!smart_enabled) {
return NULL;
}

v = get_dbus_property(drive, UDISKS2_DRIVE_ATA_INTERFACE, "SmartTemperature");
if (v) {
disk_temp = udiskt_new();
disk_temp->temperature = (gint32) g_variant_get_double(v) - 273.15;
g_variant_unref(v);
}

if (!disk_temp) {
return NULL;
}

v = get_dbus_property(drive, UDISKS2_DRIVE_INTERFACE, "Model");
if (v) {
disk_temp->drive = g_variant_dup_string(v, NULL);
g_variant_unref(v);
}

return disk_temp;
}

gpointer get_udisks2_drive_info(const char *blockdev, GDBusProxy *drive) {
GVariant *v;
const gchar *str;
@@ -335,6 +381,10 @@ gpointer get_udisks2_drive_info(const char *blockdev, GDBusProxy *drive) {
return u;
}

GSList* get_udisks2_temps(void){
return udisks2_drives_func_caller(udisks2_conn, get_udisks2_temp);
}

GSList* get_udisks2_all_drives_info(void){
return udisks2_drives_func_caller(udisks2_conn, get_udisks2_drive_info);
}
@@ -18,6 +18,12 @@ typedef struct udiskd {
gint32 smart_temperature;
} udiskd;

typedef struct udiskt {
gchar *drive;
gint32 temperature;
} udiskt;

void udisks2_init();
void udisks2_shutdown();
GSList *get_udisks2_temps();
GSList *get_udisks2_all_drives_info();
@@ -22,6 +22,7 @@
#include "expr.h"
#include "hardinfo.h"
#include "socket.h"
#include "udisks2_util.h"

gchar *sensors = NULL;
GHashTable *sensor_compute = NULL;
@@ -510,6 +511,24 @@ static void read_sensors_hddtemp(void) {
}
}

void read_sensors_udisks2(void) {
GSList *node;
GSList *temps;
udiskt *disk;

temps = get_udisks2_temps();
for (node = temps; node != NULL; node = node->next) {
disk = (udiskt *)node->data;
add_sensor("Hard Drive",
disk->drive,
"udisks2",
disk->temperature,
"\302\260C");
udiskt_free(disk);
}
g_slist_free(temps);
}

void scan_sensors_do(void) {
g_free(sensors);
sensors = g_strdup("");
@@ -522,6 +541,8 @@ void scan_sensors_do(void) {
read_sensors_sys_thermal();
read_sensors_omnibook();
read_sensors_hddtemp();
read_sensors_udisks2();

/* FIXME: Add support for ibm acpi and more sensors */
}

0 comments on commit 7c01518

Please sign in to comment.