nut plugin: Added a plugin to query the `upsd' from the `network ups tools'.
[collectd.git] / src / ntpd.c
index 668e302..7f4d62a 100644 (file)
@@ -389,12 +389,12 @@ static int ntpd_connect (void)
 
        if ((status = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
        {
-               DEBUG ("getaddrinfo (%s, %s): %s",
-                               host, port,
-                               status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status));
+               char errbuf[1024];
                ERROR ("ntpd plugin: getaddrinfo (%s, %s): %s",
                                host, port,
-                               status == EAI_SYSTEM ? strerror (errno) : gai_strerror (status));
+                               (status == EAI_SYSTEM)
+                               ? sstrerror (errno, errbuf, sizeof (errbuf))
+                               : gai_strerror (status));
                return (-1);
        }
 
@@ -470,8 +470,9 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size,
 
        if (gettimeofday (&time_end, NULL) < 0)
        {
+               char errbuf[1024];
                ERROR ("ntpd plugin: gettimeofday failed: %s",
-                               strerror (errno));
+                               sstrerror (errno, errbuf, sizeof (errbuf)));
                return (-1);
        }
        time_end.tv_sec++; /* wait for a most one second */
@@ -481,8 +482,9 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size,
        {
                if (gettimeofday (&time_now, NULL) < 0)
                {
+                       char errbuf[1024];
                        ERROR ("ntpd plugin: gettimeofday failed: %s",
-                                       strerror (errno));
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
                        return (-1);
                }
 
@@ -502,9 +504,9 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size,
 
                if (status < 0)
                {
-                       DEBUG ("poll failed: %s", strerror (errno));
+                       char errbuf[1024];
                        ERROR ("ntpd plugin: poll failed: %s",
-                                       strerror (errno));
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
                        return (-1);
                }
 
@@ -522,7 +524,9 @@ static int ntpd_receive_response (int req_code, int *res_items, int *res_size,
 
                if (status < 0)
                {
-                       DEBUG ("recv(2) failed: %s", strerror (errno));
+                       char errbuf[1024];
+                       DEBUG ("recv(2) failed: %s",
+                                       sstrerror (errno, errbuf, sizeof (errbuf)));
                        DEBUG ("Closing socket #%i", sd);
                        close (sd);
                        sock_descr = sd = -1;
@@ -874,9 +878,10 @@ static int ntpd_read (void)
                                        NULL, 0, 0 /* no flags */);
                        if (status != 0)
                        {
+                               char errbuf[1024];
                                ERROR ("ntpd plugin: getnameinfo failed: %s",
-                                               status == EAI_SYSTEM
-                                               ? strerror (errno)
+                                               (status == EAI_SYSTEM)
+                                               ? sstrerror (errno, errbuf, sizeof (errbuf))
                                                : gai_strerror (status));
                                continue;
                        }
@@ -955,15 +960,22 @@ static int ntpd_read (void)
 } /* int ntpd_read */
 #endif /* NTPD_HAVE_READ */
 
-void module_register (void)
+void module_register (modreg_e load)
 {
-       plugin_register_data_set (&time_offset_ds);
-       plugin_register_data_set (&time_dispersion_ds);
-       plugin_register_data_set (&delay_ds);
-       plugin_register_data_set (&frequency_offset_ds);
+       if (load & MR_DATASETS)
+       {
+               plugin_register_data_set (&time_offset_ds);
+               plugin_register_data_set (&time_dispersion_ds);
+               plugin_register_data_set (&delay_ds);
+               plugin_register_data_set (&frequency_offset_ds);
+       }
 
 #if NTPD_HAVE_READ
-       plugin_register_config ("ntpd", ntpd_config, config_keys, config_keys_num);
-       plugin_register_read ("ntpd", ntpd_read);
+       if (load & MR_READ)
+       {
+               plugin_register_config ("ntpd", ntpd_config,
+                               config_keys, config_keys_num);
+               plugin_register_read ("ntpd", ntpd_read);
+       }
 #endif /* NTPD_HAVE_READ */
-}
+} /* void module_register */