Bumped version to 4.2.7; Updated ChangeLog.
[collectd.git] / src / hddtemp.c
index c777465..09f6bbe 100644 (file)
 #include "plugin.h"
 #include "configfile.h"
 
-#if HAVE_NETDB_H && HAVE_SYS_SOCKET_H && HAVE_NETINET_IN_H \
-       && HAVE_NETINET_TCP_H && HAVE_LIBGEN_H
 # include <netdb.h>
 # include <sys/socket.h>
 # include <netinet/in.h>
 # include <netinet/tcp.h>
 # include <libgen.h> /* for basename */
-# define HDDTEMP_HAVE_READ 1
-#else
-# define HDDTEMP_HAVE_READ 0
-#endif
 
 #if HAVE_LINUX_MAJOR_H
 # include <linux/major.h>
@@ -50,7 +44,6 @@
 #define HDDTEMP_DEF_HOST "127.0.0.1"
 #define HDDTEMP_DEF_PORT "7634"
 
-#if HDDTEMP_HAVE_READ
 static const char *config_keys[] =
 {
        "Host",
@@ -127,7 +120,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size)
        if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
        {
                char errbuf[1024];
-               ERROR ("hddtemp: getaddrinfo (%s, %s): %s",
+               ERROR ("hddtemp plugin: getaddrinfo (%s, %s): %s",
                                host, port,
                                (ai_return == EAI_SYSTEM)
                                ? sstrerror (errno, errbuf, sizeof (errbuf))
@@ -139,19 +132,23 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size)
        for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
        {
                /* create our socket descriptor */
-               if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0)
+               fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
+                               ai_ptr->ai_protocol);
+               if (fd < 0)
                {
                        char errbuf[1024];
-                       ERROR ("hddtemp: socket: %s",
+                       ERROR ("hddtemp plugin: socket: %s",
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
                        continue;
                }
 
                /* connect to the hddtemp daemon */
-               if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr, ai_ptr->ai_addrlen))
+               if (connect (fd, (struct sockaddr *) ai_ptr->ai_addr,
+                                       ai_ptr->ai_addrlen))
                {
                        char errbuf[1024];
-                       DEBUG ("hddtemp: connect (%s, %s): %s", host, port,
+                       INFO ("hddtemp plugin: connect (%s, %s) failed: %s",
+                                       host, port,
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
                        close (fd);
                        fd = -1;
@@ -167,7 +164,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size)
 
        if (fd < 0)
        {
-               ERROR ("hddtemp: Could not connect to daemon.");
+               ERROR ("hddtemp plugin: Could not connect to daemon.");
                return (-1);
        }
 
@@ -184,7 +181,7 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size)
                        if ((errno == EAGAIN) || (errno == EINTR))
                                continue;
 
-                       ERROR ("hddtemp: Error reading from socket: %s",
+                       ERROR ("hddtemp plugin: Error reading from socket: %s",
                                        sstrerror (errno, errbuf, sizeof (errbuf)));
                        close (fd);
                        return (-1);
@@ -198,12 +195,13 @@ static int hddtemp_query_daemon (char *buffer, int buffer_size)
        if (buffer_fill >= buffer_size)
        {
                buffer[buffer_size - 1] = '\0';
-               WARNING ("hddtemp: Message from hddtemp has been truncated.");
+               WARNING ("hddtemp plugin: Message from hddtemp has been "
+                               "truncated.");
        }
        else if (buffer_fill == 0)
        {
-               WARNING ("hddtemp: Peer has unexpectedly shut down the socket. "
-                               "Buffer: `%s'", buffer);
+               WARNING ("hddtemp plugin: Peer has unexpectedly shut down "
+                               "the socket. Buffer: `%s'", buffer);
                close (fd);
                return (-1);
        }
@@ -270,7 +268,7 @@ static int hddtemp_init (void)
 
        if ((fh = fopen ("/proc/partitions", "r")) != NULL)
        {
-               DEBUG ("Looking at /proc/partitions...");
+               DEBUG ("hddtemp plugin: Looking at /proc/partitions...");
 
                while (fgets (buf, sizeof (buf), fh) != NULL)
                {
@@ -311,6 +309,7 @@ static int hddtemp_init (void)
                                case SCSI_DISK5_MAJOR:
                                case SCSI_DISK6_MAJOR:
                                case SCSI_DISK7_MAJOR:
+#ifdef SCSI_DISK8_MAJOR
                                case SCSI_DISK8_MAJOR:
                                case SCSI_DISK9_MAJOR:
                                case SCSI_DISK10_MAJOR:
@@ -319,6 +318,7 @@ static int hddtemp_init (void)
                                case SCSI_DISK13_MAJOR:
                                case SCSI_DISK14_MAJOR:
                                case SCSI_DISK15_MAJOR:
+#endif /* SCSI_DISK8_MAJOR */
                                        /* SCSI disks minors are multiples of 16.
                                         * Keep only those. */
                                        if (minor % 16)
@@ -344,25 +344,25 @@ static int hddtemp_init (void)
 
                                /* Skip all other majors. */
                                default:
-                                       DEBUG ("Skipping unknown major %i", major);
+                                       DEBUG ("hddtemp plugin: Skipping unknown major %i", major);
                                        continue;
                        } /* switch (major) */
 
                        if ((name = strdup (fields[3])) == NULL)
                        {
-                               ERROR ("hddtemp: strdup(%s) == NULL", fields[3]);
+                               ERROR ("hddtemp plugin: strdup(%s) == NULL", fields[3]);
                                continue;
                        }
 
                        if ((entry = (hddname_t *) malloc (sizeof (hddname_t))) == NULL)
                        {
-                               ERROR ("hddtemp: malloc (%u) == NULL",
+                               ERROR ("hddtemp plugin: malloc (%u) == NULL",
                                                (unsigned int) sizeof (hddname_t));
                                free (name);
                                continue;
                        }
 
-                       DEBUG ("Found disk: %s (%u:%u).", name, major, minor);
+                       DEBUG ("hddtemp plugin: Found disk: %s (%u:%u).", name, major, minor);
 
                        entry->major = major;
                        entry->minor = minor;
@@ -385,7 +385,7 @@ static int hddtemp_init (void)
        else
        {
                char errbuf[1024];
-               DEBUG ("Could not open /proc/partitions: %s",
+               DEBUG ("hddtemp plugin: Could not open /proc/partitions: %s",
                                sstrerror (errno, errbuf, sizeof (errbuf)));
        }
 #endif /* COLLECT_DEBUG */
@@ -413,7 +413,7 @@ static char *hddtemp_get_name (char *drive)
 
        if (list == NULL)
        {
-               DEBUG ("Don't know %s, keeping name as-is.", drive);
+               DEBUG ("hddtemp plugin: Don't know %s, keeping name as-is.", drive);
                return (strdup (drive));
        }
 
@@ -507,16 +507,13 @@ static int hddtemp_read (void)
        
        return (0);
 } /* int hddtemp_read */
-#endif /* HDDTEMP_HAVE_READ */
 
 /* module_register
    Register collectd plugin. */
 void module_register (void)
 {
-#if HDDTEMP_HAVE_READ
        plugin_register_config ("hddtemp", hddtemp_config,
                        config_keys, config_keys_num);
        plugin_register_init ("hddtemp", hddtemp_init);
        plugin_register_read ("hddtemp", hddtemp_read);
-#endif /* HDDTEMP_HAVE_READ */
 }