APC UPS fixes.
authorJaromir Smrcek <jaromir.smrcek@zoner.com>
Sun, 10 May 2009 19:37:04 +0000 (13:37 -0600)
committerBrenden Matthews <brenden@rty.ca>
Sun, 10 May 2009 19:37:04 +0000 (13:37 -0600)
src/apcupsd.c
src/conky.c

index 9d9a29d..3136dea 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "conky.h"
 #include "apcupsd.h"
+#include "logging.h"
 
 #include <errno.h>
 #include <sys/time.h>
@@ -159,6 +160,11 @@ void update_apcupsd(void) {
                struct hostent* he = 0;
                struct sockaddr_in addr;
                short sz = 0;
+#ifdef HAVE_GETHOSTBYNAME_R
+               struct hostent he_mem;
+               int he_errno;
+               char hostbuff[2048];
+#endif
                //
                // connect to apcupsd daemon
                //
@@ -167,11 +173,19 @@ void update_apcupsd(void) {
                        perror("socket");
                        break;
                }
+#ifdef HAVE_GETHOSTBYNAME_R
+               if (gethostbyname_r(info.apcupsd.host, &he_mem, hostbuff, sizeof(hostbuff), &he, &he_errno)) {
+                       ERR("APCUPSD gethostbyname_r: %s", hstrerror(h_errno));
+                       break;
+               }
+#else /* HAVE_GETHOSTBYNAME_R */
                he = gethostbyname(info.apcupsd.host);
                if (!he) {
                        herror("gethostbyname");
                        break;
                }
+#endif /* HAVE_GETHOSTBYNAME_R */
+               
                memset(&addr, 0, sizeof(addr));
                addr.sin_family = AF_INET;
                addr.sin_port = info.apcupsd.port;
index 3440e3b..e091cd5 100644 (file)
@@ -5120,7 +5120,7 @@ static void generate_text_internal(char *p, int p_max_size,
                        }
                        OBJ(apcupsd_loadgauge) {
                                double progress;
-                               progress =      atof(cur->apcupsd.items[APCUPSD_LOAD]);
+                               progress =      atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
                                new_gauge(p, obj->a, obj->b,
                                                  (int)progress);
                        }