# Adds support for hddtemp to conky. # HDD temperatures are provided by the hddtemp daemon. diff -Naurp conky-1.4.2-orig/AUTHORS conky-1.4.2-hddtemp/AUTHORS --- conky-1.4.2-orig/AUTHORS 2006-08-08 16:10:46.000000000 +0200 +++ conky-1.4.2-hddtemp/AUTHORS 2006-08-08 16:35:29.000000000 +0200 @@ -123,6 +123,9 @@ Lucas Brutschy + hddtemp support + Moncelier Camille METAR patch diff -Naurp conky-1.4.2-orig/configure.in conky-1.4.2-hddtemp/configure.in --- conky-1.4.2-orig/configure.in 2006-08-08 16:10:46.000000000 +0200 +++ conky-1.4.2-hddtemp/configure.in 2006-08-08 16:33:56.000000000 +0200 @@ -287,6 +287,20 @@ if test x$want_seti = xyes; then fi dnl +dnl Hddtemp +dnl + +want_hddtemp=yes +AC_ARG_ENABLE(hddtemp, +[ --enable-hddtemp enable if you want hddtemp support [[default=yes]]], + [want_hddtemp="$enableval"]) + +AM_CONDITIONAL(BUILD_HDDTEMP, test x$want_hddtemp = xyes) +if test x$want_hddtemp = xyes; then + AC_DEFINE(HDDTEMP, 1, [Define if you want hddtemp support]) +fi + +dnl dnl MPD dnl diff -Naurp conky-1.4.2-orig/doc/variables.xml conky-1.4.2-hddtemp/doc/variables.xml --- conky-1.4.2-orig/doc/variables.xml 2006-08-08 16:10:46.000000000 +0200 +++ conky-1.4.2-hddtemp/doc/variables.xml 2006-08-08 16:29:29.000000000 +0200 @@ -448,6 +448,16 @@ + + + + + Displays temperature of a selected hard disk drive as reported by the hddtemp daemon running on host:port. + + + + + diff -Naurp conky-1.4.2-orig/Makefile.in conky-1.4.2-hddtemp/Makefile.in --- conky-1.4.2-orig/Makefile.in 2006-08-08 16:10:46.000000000 +0200 +++ conky-1.4.2-hddtemp/Makefile.in 2006-08-08 16:34:56.000000000 +0200 @@ -95,6 +95,8 @@ BUILD_BMP_FALSE = @BUILD_BMP_FALSE@ BUILD_BMP_TRUE = @BUILD_BMP_TRUE@ BUILD_FREEBSD_FALSE = @BUILD_FREEBSD_FALSE@ BUILD_FREEBSD_TRUE = @BUILD_FREEBSD_TRUE@ +BUILD_HDDTEMP_FALSE = @BUILD_HDDTEMP_FALSE@ +BUILD_HDDTEMP_TRUE = @BUILD_HDDTEMP_TRUE@ BUILD_INFOPIPE_FALSE = @BUILD_INFOPIPE_FALSE@ BUILD_INFOPIPE_TRUE = @BUILD_INFOPIPE_TRUE@ BUILD_LINUX_FALSE = @BUILD_LINUX_FALSE@ diff -Naurp conky-1.4.2-orig/src/conky.c conky-1.4.2-hddtemp/src/conky.c --- conky-1.4.2-orig/src/conky.c 2006-08-08 16:10:46.000000000 +0200 +++ conky-1.4.2-hddtemp/src/conky.c 2006-08-08 18:16:22.000000000 +0200 @@ -1023,6 +1023,9 @@ enum text_object_type { OBJ_iconv_start, OBJ_iconv_stop, #endif +#ifdef HDDTEMP + OBJ_hddtemp, +#endif }; struct text_object { @@ -1097,6 +1100,11 @@ struct text_object { int connection_index; /* 0 to n-1 connections. */ } tcp_port_monitor; #endif + struct { + char *addr; + int port; + char *dev; + } hddtemp; /* 2 */ } data; }; @@ -1937,6 +1945,12 @@ static void free_text_objects(unsigned i info.first_process = NULL; } break; +#ifdef HDDTEMP + case OBJ_hddtemp: + free(objs[i].data.hddtemp.dev); + free(objs[i].data.hddtemp.addr); + break; +#endif } } free(objs); @@ -2768,6 +2782,17 @@ static struct text_object *construct_tex memset(&(info.bmpx), 0, sizeof(struct bmpx_s)); END #endif +#ifdef HDDTEMP + OBJ(hddtemp, 0) + if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev, + &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) { + ERR("hddtemp needs arguments"); + obj->type = OBJ_text; + obj->data.s = strdup("${hddtemp}"); + return NULL; + } + END +#endif #ifdef TCP_PORT_MONITOR OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR) int argc, port_begin, port_end, item, connection_index; @@ -3723,6 +3748,20 @@ static void generate_text_internal(char OBJ(hr) { new_hr(p, obj->data.i); } + OBJ(hddtemp) { + char *temp; + char unit; + + temp = get_hddtemp_info(obj->data.hddtemp.dev, + obj->data.hddtemp.addr, obj->data.hddtemp.port, &unit); + if (!temp) { + snprintf(p, p_max_size, "N/A"); + } else if (unit == '*') { + snprintf(p, p_max_size, "%s", temp); + } else { + snprintf(p, p_max_size, "%s°%c", temp, unit); + } + } OBJ(offset) { new_offset(p, obj->data.i); } diff -Naurp conky-1.4.2-orig/src/conky.h conky-1.4.2-hddtemp/src/conky.h --- conky-1.4.2-orig/src/conky.h 2006-08-08 16:10:46.000000000 +0200 +++ conky-1.4.2-hddtemp/src/conky.h 2006-08-08 18:15:38.000000000 +0200 @@ -597,6 +597,12 @@ extern mldonkey_config mlconfig; int get_mldonkey_status(mldonkey_config * config, mldonkey_info * info); #endif +/* in hddtemp.c */ +#ifdef HDDTEMP +int scan_hddtemp(const char *arg, char **dev, char **addr, int *port); +char *get_hddtemp_info(char *dev, char *addr, int port, char *unit); +#endif /* HDDTEMP */ + /* in linux.c */ /* nothing to see here */ @@ -605,3 +611,5 @@ int get_mldonkey_status(mldonkey_config extern int do_it(void); #endif + + diff -Naurp conky-1.4.2-orig/src/hddtemp.c conky-1.4.2-hddtemp/src/hddtemp.c --- conky-1.4.2-orig/src/hddtemp.c 1970-01-01 01:00:00.000000000 +0100 +++ conky-1.4.2-hddtemp/src/hddtemp.c 2006-08-08 16:14:09.000000000 +0200 @@ -0,0 +1,144 @@ +#include "conky.h" +#include +#include +#include +#include +#include +#include +#include +#include + +#define BUFLEN 512 +#define PORT 7634 + +char buf[BUFLEN]; + +int scan_hddtemp(const char *arg, char **dev, char **addr, int *port) +{ + char buf1[32], buf2[64]; + int n, ret; + + ret = sscanf(arg, "%31s %63s %d", buf1, buf2, &n); + + if (ret < 1) + return -1; + + *dev = strdup(buf1); + if (ret >= 2) + *addr = strdup(buf2); + else + *addr = strdup("127.0.0.1"); + + if (ret == 3) + *port = n; + else + *port = PORT; + + return 0; +} + +char *get_hddtemp_info(char *dev, char *hostaddr, int port, char *unit) +{ + int sockfd = 0; + struct hostent *he; + struct sockaddr_in addr; + struct timeval tv; + fd_set rfds; + int len, i, devlen = strlen(dev); + char sep; + char *p, *out, *r = NULL; + + if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { + perror("socket"); + return NULL; + } + + he = gethostbyname(hostaddr); + if (!he) { + perror("gethostbyname"); + goto out; + } + + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + addr.sin_addr = *((struct in_addr *)he->h_addr); + memset(&(addr.sin_zero), 0, 8); + + if (connect(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr)) == -1) { + perror("connect"); + goto out; + } + + FD_ZERO(&rfds); + FD_SET(sockfd, &rfds); + + /* We're going to wait up to a quarter a second to see whether + * there's any data available. Polling with timeout set to 0 + * doesn't seem to work with hddtemp. */ + tv.tv_sec = 0; + tv.tv_usec = 250000; + + i = select(sockfd+1, &rfds, NULL, NULL, &tv); + if (i == -1) + perror("select"); + + /* No data available */ + if (i <= 0) + goto out; + + p = buf; + len = 0; + do { + i = recv(sockfd, p, BUFLEN - (p-buf), 0); + if (i < 0) { + perror("recv"); + goto out; + } + len += i; + p += i; + } while (i > 0 && p < buf + BUFLEN - 1); + + if (len < 2) { + goto out; + } + + 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) + goto out; + p++; + out = p; + p = strchr(p, sep); + if (!p) + goto out; + *p = '\0'; + p++; + *unit = *p; + if (!strncmp(out, "NA", 2)) { + strcpy(buf, "N/A"); + r = buf; + } else { + r = out; + } + goto out; + } else { + for (i = 0; i < 5; i++) { + p = strchr(p, sep); + if (!p) + goto out; + p++; + } + } + } +out: close(sockfd); + return r; +} + diff -Naurp conky-1.4.2-orig/src/Makefile.am conky-1.4.2-hddtemp/src/Makefile.am --- conky-1.4.2-orig/src/Makefile.am 2006-08-08 16:10:46.000000000 +0200 +++ conky-1.4.2-hddtemp/src/Makefile.am 2006-08-08 16:17:07.000000000 +0200 @@ -62,9 +62,13 @@ if BUILD_X11 x11 = x11.c endif -conky_SOURCES = common.c fs.c $(linux) mail.c mixer.c $(seti) $(mpd) $(xmms2) $(solaris) $(freebsd) $(netbsd) $(port_monitors) conky.c conky.h $(x11) $(mldonkey) remoted.c remoted.h remotec.c remotec.h $(xmms) $(bmpx) +if BUILD_HDDTEMP +hddtemp = hddtemp.c +endif + +conky_SOURCES = common.c fs.c $(linux) mail.c mixer.c $(seti) $(mpd) $(xmms2) $(solaris) $(freebsd) $(netbsd) $(port_monitors) conky.c conky.h $(x11) $(mldonkey) remoted.c remoted.h remotec.c remotec.h $(xmms) $(bmpx) $(hddtemp) AM_LDFLAGS = $(X11_LIBS) $(XFT_LIBS) $(CAIRO_LIBS) $(PTHREAD_LIBS) -lm EXTRA_DIST = seti.c linux.c solaris.c freebsd.c netbsd.c mpd.c libmpdclient.c \ -libmpdclient.h xmms2.c top.h mldonkey.c ftp.c ftp.h x11.c +libmpdclient.h xmms2.c top.h mldonkey.c ftp.c ftp.h x11.c hddtemp.c