From: Philip K. <kov...@co...> - 2006-08-10 16:59:18
|
spock, i checked them in to svn, rev 679. our testers will let us know how they work. thanks for the submission. phil Michal Januszewski wrote: > Hello, > > As requested, I'm resubmitting my patch, rediffed against conky1 svn > trunk. > > Best regards. > > ------------------------------------------------------------------------ > > diff -Naurp conky1-orig/AUTHORS conky1-hddtemp/AUTHORS > --- conky1-orig/AUTHORS 2006-08-10 12:33:42.000000000 +0200 > +++ conky1-hddtemp/AUTHORS 2006-08-10 12:34:02.000000000 +0200 > @@ -126,6 +126,9 @@ Lucas Brutschy <lbrutschy at users dot s > MLDonkey patch > if constructs patch > > +Michal Januszewski <spock at gentoo dot org> > + hddtemp support > + > Moncelier Camille <pixdamix at users dot sourceforge dot net> > METAR patch > > diff -Naurp conky1-orig/configure.in conky1-hddtemp/configure.in > --- conky1-orig/configure.in 2006-08-10 12:33:42.000000000 +0200 > +++ conky1-hddtemp/configure.in 2006-08-10 12:34:02.000000000 +0200 > @@ -292,6 +292,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 conky1-orig/doc/variables.xml conky1-hddtemp/doc/variables.xml > --- conky1-orig/doc/variables.xml 2006-08-10 12:33:41.000000000 +0200 > +++ conky1-hddtemp/doc/variables.xml 2006-08-10 12:38:22.000000000 +0200 > @@ -454,6 +454,17 @@ > > <varlistentry> > <term> > + <command><option>hddtemp</option></command> > + <option>dev, (host,(port))</option> > + </term> > + <listitem> > + Displays temperature of a selected hard disk drive as reported by the hddtemp daemon running on host:port. > + Default host is 127.0.0.1, default port is 7634. > + <para></para></listitem> > +</varlistentry> > + > +<varlistentry> > + <term> > <command><option>head</option></command> > <option>logfile lines (interval)</option> > </term> > diff -Naurp conky1-orig/src/conky.c conky1-hddtemp/src/conky.c > --- conky1-orig/src/conky.c 2006-08-10 12:33:42.000000000 +0200 > +++ conky1-hddtemp/src/conky.c 2006-08-10 12:34:11.000000000 +0200 > @@ -1032,6 +1032,9 @@ enum text_object_type { > OBJ_iconv_start, > OBJ_iconv_stop, > #endif > +#ifdef HDDTEMP > + OBJ_hddtemp, > +#endif > }; > > struct text_object { > @@ -1112,6 +1115,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; > }; > > @@ -1961,6 +1969,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); > @@ -2876,6 +2890,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; > @@ -3874,6 +3899,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 conky1-orig/src/conky.h conky1-hddtemp/src/conky.h > --- conky1-orig/src/conky.h 2006-08-10 12:33:42.000000000 +0200 > +++ conky1-hddtemp/src/conky.h 2006-08-10 12:34:11.000000000 +0200 > @@ -599,6 +599,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 */ > @@ -607,3 +613,5 @@ int get_mldonkey_status(mldonkey_config > extern int do_it(void); > > #endif > + > + > diff -Naurp conky1-orig/src/hddtemp.c conky1-hddtemp/src/hddtemp.c > --- conky1-orig/src/hddtemp.c 1970-01-01 01:00:00.000000000 +0100 > +++ conky1-hddtemp/src/hddtemp.c 2006-08-10 12:34:11.000000000 +0200 > @@ -0,0 +1,144 @@ > +#include "conky.h" > +#include <stdio.h> > +#include <string.h> > +#include <stdlib.h> > +#include <unistd.h> > +#include <fcntl.h> > +#include <netdb.h> > +#include <sys/select.h> > +#include <sys/socket.h> > + > +#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 conky1-orig/src/Makefile.am conky1-hddtemp/src/Makefile.am > --- conky1-orig/src/Makefile.am 2006-08-10 12:33:42.000000000 +0200 > +++ conky1-hddtemp/src/Makefile.am 2006-08-10 12:34:11.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 > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > ------------------------------------------------------------------------ > > _______________________________________________ > Conky-development mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/conky-development > |