- buf[len] = 0;
-
- /* The first character read is the separator. */
- sep = buf[0];
- p = buf + 1;
-
- while (*p) {
- if (!strncmp(p, dev, devlen)) {
- p += devlen + 1;
- p = strchr(p, sep);
- if (!p) {
- break;
- }
- p++;
- out = p;
- p = strchr(p, sep);
- if (!p) {
- break;
- }
- *p = '\0';
- p++;
- *unit = *p;
- if (!strncmp(out, "NA", 2)) {
- strcpy(buf, "N/A");
- r = buf;
- } else {
- r = out;
- }
- break;
- } else {
- for (i = 0; i < 5; i++) {
- p = strchr(p, sep);
- if (!p) {
- break;
- }
- p++;
- }
- }
- }
- } while (0);
- close(sockfd);
- return r;
+ return 0;
+out_fail:
+ free(*saveptr);
+ return 1;
+}
+
+void update_hddtemp(void) {
+ char *data, *dev, unit, *saveptr;
+ short val;
+ static double last_hddtemp_update = 0.0;
+
+ /* limit tcp connection overhead */
+ if (current_update_time - last_hddtemp_update < 5)
+ return;
+ last_hddtemp_update = current_update_time;
+
+ free_hddtemp_info();
+
+ if (!(data = fetch_hddtemp_output()))
+ return;
+
+ if (read_hdd_val(data, &dev, &val, &unit, &saveptr)) {
+ free(data);
+ return;
+ }
+ do {
+ add_hddtemp_info(dev, val, unit);
+ } while (!read_hdd_val(NULL, &dev, &val, &unit, &saveptr));
+ free(data);
+}
+
+void free_hddtemp(void)
+{
+ free_hddtemp_info();
+ if (hddtemp_host) {
+ free(hddtemp_host);
+ hddtemp_host = NULL;
+ }
+ if (hddtemp_port) {
+ free(hddtemp_port);
+ hddtemp_port = NULL;
+ }
+}
+
+int get_hddtemp_info(const char *dev, short *val, char *unit)
+{
+ struct hdd_info *hdi = hdd_info_head.next;
+
+ /* if no dev is given, just use hdd_info_head->next */
+ while(dev && hdi) {
+ if (!strcmp(dev, hdi->dev))
+ break;
+ hdi = hdi->next;
+ }
+ if (!hdi)
+ return 1;
+
+ *val = hdi->temp;
+ *unit = hdi->unit;
+ return 0;