avoid to fetch hddtemp daemon if no hddtemp sensors
[psensor.git] / src / lib / hdd_hddtemp.c
index 1ce4884..91ef103 100644 (file)
@@ -59,7 +59,7 @@ static char *fetch()
 
        sockfd = socket(AF_INET, SOCK_STREAM, 0);
        if (sockfd == -1) {
-               log_err(_("hddtemp: failed to open socket."));
+               log_err(_("%s: failed to open socket."), PROVIDER_NAME);
                return NULL;
        }
 
@@ -72,7 +72,7 @@ static char *fetch()
        if (connect(sockfd,
                    (struct sockaddr *)&address,
                    (socklen_t) sizeof(address)) == -1) {
-               log_err(_("hddtemp: failed to open connection."));
+               log_err(_("%s: failed to open connection."), PROVIDER_NAME);
        } else {
                buffer = malloc(HDDTEMP_OUTPUT_BUFFER_LENGTH);
 
@@ -186,7 +186,9 @@ hddtemp_psensor_list_append(struct psensor ***sensors, int values_max_length)
                return;
 
        if (hddtemp_output[0] != '|') {
-               log_err(_("hddtemp: wrong string: %s."), hddtemp_output);
+               log_err(_("%s: wrong string: %s."),
+                       PROVIDER_NAME,
+                       hddtemp_output);
 
                free(hddtemp_output);
 
@@ -212,23 +214,42 @@ hddtemp_psensor_list_append(struct psensor ***sensors, int values_max_length)
 
 static void update(struct psensor **sensors, struct hdd_info *info)
 {
-       struct psensor **sensor_cur = sensors;
-
-       while (*sensor_cur) {
-               if (!((*sensor_cur)->type & SENSOR_TYPE_REMOTE)
-                   && (*sensor_cur)->type & SENSOR_TYPE_HDDTEMP
-                   && !strcmp((*sensor_cur)->id + 8, info->name))
-                       psensor_set_current_value(*sensor_cur,
+       while (*sensors) {
+               if (!((*sensors)->type & SENSOR_TYPE_REMOTE)
+                   && (*sensors)->type & SENSOR_TYPE_HDDTEMP
+                   && !strcmp((*sensors)->id + 8, info->name))
+                       psensor_set_current_value(*sensors,
                                                  (double)info->temp);
 
-               sensor_cur++;
+               sensors++;
+       }
+}
+
+static bool contains_hddtemp_sensor(struct psensor **sensors)
+{
+       struct psensor *s;
+
+       if (!sensors)
+               return false;
+
+       while (*sensors) {
+               s = *sensors;
+               if (!(s->type & SENSOR_TYPE_REMOTE)
+                    && (s->type & SENSOR_TYPE_HDDTEMP))
+                       return true;
+               sensors++;
        }
+
+       return false;
 }
 
 void hddtemp_psensor_list_update(struct psensor **sensors)
 {
        char *hddtemp_output;
 
+       if (!contains_hddtemp_sensor(sensors))
+               return;
+
        hddtemp_output = fetch();
 
        if (!hddtemp_output)
@@ -248,7 +269,9 @@ void hddtemp_psensor_list_update(struct psensor **sensors)
                        free(info.name);
                }
        } else {
-               log_err(_("hddtemp: wrong string: %s."), hddtemp_output);
+               log_err(_("%s: wrong string: %s."),
+                       PROVIDER_NAME,
+                       hddtemp_output);
        }
 
        free(hddtemp_output);