Merge remote-tracking branch 'octo/master'
authorSven Trenkel <collectd@semidefinite.de>
Sun, 16 Jul 2017 22:49:59 +0000 (22:49 +0000)
committerSven Trenkel <collectd@semidefinite.de>
Sun, 16 Jul 2017 22:49:59 +0000 (22:49 +0000)
132 files changed:
configure.ac
contrib/systemd.collectd.service
src/aggregation.c
src/amqp.c
src/apache.c
src/apcups.c
src/ascent.c
src/battery.c
src/bind.c
src/cgroups.c
src/chrony.c
src/collectd.conf.in
src/collectd.conf.pod
src/cpu.c
src/cpufreq.c
src/csv.c
src/curl.c
src/curl_json.c
src/curl_xml.c
src/daemon/common.c
src/daemon/common.h
src/daemon/common_test.c
src/daemon/configfile.c
src/daemon/filter_chain.c
src/daemon/meta_data.c
src/daemon/plugin.c
src/daemon/utils_time.c
src/dbi.c
src/disk.c
src/dpdkevents.c
src/dpdkstat.c
src/drbd.c
src/exec.c
src/filecount.c
src/gmond.c
src/hddtemp.c
src/hugepages.c
src/intel_rdt.c
src/interface.c
src/ipc.c
src/ipmi.c
src/iptables.c
src/ipvs.c
src/java.c
src/libcollectdclient/client.c
src/logfile.c
src/lpar.c
src/lua.c
src/lvm.c
src/madwifi.c
src/match_regex.c
src/mcelog.c
src/md.c
src/memcached.c
src/mic.c
src/modbus.c
src/mqtt.c
src/mysql.c
src/netapp.c
src/netlink.c
src/network.c
src/nfs.c
src/nginx.c
src/notify_desktop.c
src/notify_email.c
src/notify_nagios.c
src/ntpd.c
src/numa.c
src/nut.c
src/olsrd.c
src/onewire.c
src/openldap.c
src/oracle.c
src/ovs_events.c
src/ovs_stats.c
src/perl.c
src/postgresql.c
src/processes.c
src/protocols.c
src/python.c
src/redis.c
src/routeros.c
src/rrdcached.c
src/rrdtool.c
src/sensors.c
src/sigrok.c
src/smart.c
src/snmp.c
src/snmp_agent.c
src/statsd.c
src/swap.c
src/syslog.c
src/tail.c
src/tail_csv.c
src/target_notification.c
src/target_scale.c
src/target_set.c
src/target_v5upgrade.c
src/tcpconns.c
src/teamspeak2.c
src/thermal.c
src/threshold.c
src/turbostat.c
src/utils_cmd_putval.c
src/utils_cmds.c
src/utils_dns.c
src/utils_dpdk.c
src/utils_dpdk.h
src/utils_format_graphite.c
src/utils_format_json.c
src/utils_format_kairosdb.c
src/utils_latency_config.c
src/utils_lua.c
src/utils_mount.c
src/utils_ovs.c
src/utils_rrdcreate.c
src/utils_tail_match.c
src/varnish.c
src/virt.c
src/virt_test.c
src/vserver.c
src/write_graphite.c
src/write_http.c
src/write_kafka.c
src/write_mongodb.c
src/write_prometheus.c
src/write_redis.c
src/write_riemann.c
src/write_sensu.c
src/write_tsdb.c
src/xencpu.c
src/zfs_arc.c

index 3357375..35b139c 100644 (file)
@@ -5375,6 +5375,10 @@ if test "x$with_libupsclient" = "xyes"; then
     [AC_DEFINE([HAVE_UPSCLI_INIT], [1], [Define when upscli_init() (since version 2-7) is available.])]
   )
 
+  AC_CHECK_LIB([upsclient], [upscli_tryconnect],
+    [AC_DEFINE([HAVE_UPSCLI_TRYCONNECT], [1], [Define when upscli_tryconnect() (since version 2.6.2) is available.])]
+  )
+
   LDFLAGS="$SAVE_LDFLAGS"
 fi
 
index 853363d..6333d49 100644 (file)
@@ -30,8 +30,6 @@ ProtectHome=true
 # By default, drop all capabilities:
 CapabilityBoundingSet=
 
-NoNewPrivileges=true
-
 # Tell systemd it will receive a notification from collectd over its control
 # socket once the daemon is ready. See systemd.service(5) for more details.
 Type=notify
index ffee1cd..5fea279 100644 (file)
@@ -200,17 +200,15 @@ static int agg_instance_create_name(agg_instance_t *inst, /* {{{ */
       sstrncpy(inst->ident.plugin_instance, AGG_FUNC_PLACEHOLDER,
                sizeof(inst->ident.plugin_instance));
     else if (strcmp("", tmp_plugin) != 0)
-      ssnprintf(inst->ident.plugin_instance,
-                sizeof(inst->ident.plugin_instance), "%s-%s", tmp_plugin,
-                AGG_FUNC_PLACEHOLDER);
+      snprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance),
+               "%s-%s", tmp_plugin, AGG_FUNC_PLACEHOLDER);
     else if (strcmp("", tmp_plugin_instance) != 0)
-      ssnprintf(inst->ident.plugin_instance,
-                sizeof(inst->ident.plugin_instance), "%s-%s",
-                tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
+      snprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance),
+               "%s-%s", tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
     else
-      ssnprintf(inst->ident.plugin_instance,
-                sizeof(inst->ident.plugin_instance), "%s-%s-%s", tmp_plugin,
-                tmp_plugin_instance, AGG_FUNC_PLACEHOLDER);
+      snprintf(inst->ident.plugin_instance, sizeof(inst->ident.plugin_instance),
+               "%s-%s-%s", tmp_plugin, tmp_plugin_instance,
+               AGG_FUNC_PLACEHOLDER);
   }
 
   /* Type */
index 1adc627..467b7ff 100644 (file)
@@ -217,23 +217,23 @@ static char *camqp_strerror(camqp_config_t *conf, /* {{{ */
     if (r.reply.id == AMQP_CONNECTION_CLOSE_METHOD) {
       amqp_connection_close_t *m = r.reply.decoded;
       char *tmp = camqp_bytes_cstring(&m->reply_text);
-      ssnprintf(buffer, buffer_size, "Server connection error %d: %s",
-                m->reply_code, tmp);
+      snprintf(buffer, buffer_size, "Server connection error %d: %s",
+               m->reply_code, tmp);
       sfree(tmp);
     } else if (r.reply.id == AMQP_CHANNEL_CLOSE_METHOD) {
       amqp_channel_close_t *m = r.reply.decoded;
       char *tmp = camqp_bytes_cstring(&m->reply_text);
-      ssnprintf(buffer, buffer_size, "Server channel error %d: %s",
-                m->reply_code, tmp);
+      snprintf(buffer, buffer_size, "Server channel error %d: %s",
+               m->reply_code, tmp);
       sfree(tmp);
     } else {
-      ssnprintf(buffer, buffer_size, "Server error method %#" PRIx32,
-                r.reply.id);
+      snprintf(buffer, buffer_size, "Server error method %#" PRIx32,
+               r.reply.id);
     }
     break;
 
   default:
-    ssnprintf(buffer, buffer_size, "Unknown reply type %i", (int)r.reply_type);
+    snprintf(buffer, buffer_size, "Unknown reply type %i", (int)r.reply_type);
   }
 
   return buffer;
@@ -758,9 +758,9 @@ static int camqp_write(const data_set_t *ds, const value_list_t *vl, /* {{{ */
   if (conf->routing_key != NULL) {
     sstrncpy(routing_key, conf->routing_key, sizeof(routing_key));
   } else {
-    ssnprintf(routing_key, sizeof(routing_key), "collectd/%s/%s/%s/%s/%s",
-              vl->host, vl->plugin, vl->plugin_instance, vl->type,
-              vl->type_instance);
+    snprintf(routing_key, sizeof(routing_key), "collectd/%s/%s/%s/%s/%s",
+             vl->host, vl->plugin, vl->plugin_instance, vl->type,
+             vl->type_instance);
 
     /* Switch slashes (the only character forbidden by collectd) and dots
      * (the separation character used by AMQP). */
@@ -980,7 +980,7 @@ static int camqp_config_connection(oconfig_item_t *ci, /* {{{ */
 
   if (publish) {
     char cbname[128];
-    ssnprintf(cbname, sizeof(cbname), "amqp/%s", conf->name);
+    snprintf(cbname, sizeof(cbname), "amqp/%s", conf->name);
 
     status = plugin_register_write(
         cbname, camqp_write, &(user_data_t){
index e2f75c1..650760c 100644 (file)
@@ -219,17 +219,18 @@ static int config_add(oconfig_item_t *ci) {
   if (status == 0) {
     char callback_name[3 * DATA_MAX_NAME_LEN];
 
-    ssnprintf(callback_name, sizeof(callback_name), "apache/%s/%s",
-              (st->host != NULL) ? st->host : hostname_g,
-              (st->name != NULL) ? st->name : "default");
+    snprintf(callback_name, sizeof(callback_name), "apache/%s/%s",
+             (st->host != NULL) ? st->host : hostname_g,
+             (st->name != NULL) ? st->name : "default");
 
     status = plugin_register_complex_read(
         /* group = */ NULL,
         /* name      = */ callback_name,
         /* callback  = */ apache_read_host,
-        /* interval  = */ 0, &(user_data_t){
-                                 .data = st, .free_func = apache_free,
-                             });
+        /* interval  = */ 0,
+        &(user_data_t){
+            .data = st, .free_func = apache_free,
+        });
   }
 
   if (status != 0) {
@@ -313,8 +314,8 @@ static int init_host(apache_t *st) /* {{{ */
     static char credentials[1024];
     int status;
 
-    status = ssnprintf(credentials, sizeof(credentials), "%s:%s", st->user,
-                       (st->pass == NULL) ? "" : st->pass);
+    status = snprintf(credentials, sizeof(credentials), "%s:%s", st->user,
+                      (st->pass == NULL) ? "" : st->pass);
     if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
       ERROR("apache plugin: init_host: Returning an error "
             "because the credentials have been "
@@ -328,7 +329,6 @@ static int init_host(apache_t *st) /* {{{ */
 #endif
   }
 
-  curl_easy_setopt(st->curl, CURLOPT_URL, st->url);
   curl_easy_setopt(st->curl, CURLOPT_FOLLOWLOCATION, 1L);
   curl_easy_setopt(st->curl, CURLOPT_MAXREDIRS, 50L);
 
@@ -510,6 +510,9 @@ static int apache_read_host(user_data_t *user_data) /* {{{ */
   assert(st->curl != NULL);
 
   st->apache_buffer_fill = 0;
+
+  curl_easy_setopt(st->curl, CURLOPT_URL, st->url);
+
   if (curl_easy_perform(st->curl) != CURLE_OK) {
     ERROR("apache: curl_easy_perform failed: %s", st->apache_curl_error);
     return -1;
index 7c6a47c..406c164 100644 (file)
@@ -421,13 +421,11 @@ static int apcups_read(void) {
       .linefreq = NAN,
   };
 
-  int status =
-      apc_query_server(conf_node == NULL ? APCUPS_DEFAULT_NODE : conf_node,
-                       conf_service, &apcups_detail);
+  int status = apc_query_server(conf_node, conf_service, &apcups_detail);
+
   if (status != 0) {
     DEBUG("apcups plugin: apc_query_server (\"%s\", \"%s\") = %d",
-          conf_node == NULL ? APCUPS_DEFAULT_NODE : conf_node, conf_service,
-          status);
+          conf_node, conf_service, status);
     return status;
   }
 
@@ -436,8 +434,19 @@ static int apcups_read(void) {
   return 0;
 } /* apcups_read */
 
+static int apcups_init(void) {
+  if (conf_node == NULL)
+    conf_node = APCUPS_DEFAULT_NODE;
+
+  if (conf_service == NULL)
+    conf_service = APCUPS_DEFAULT_SERVICE;
+
+  return 0;
+} /* apcups_init */
+
 void module_register(void) {
   plugin_register_complex_config("apcups", apcups_config);
+  plugin_register_init("apcups", apcups_init);
   plugin_register_read("apcups", apcups_read);
   plugin_register_shutdown("apcups", apcups_shutdown);
 } /* void module_register */
index 16f9104..36694f6 100644 (file)
@@ -499,8 +499,8 @@ static int ascent_init(void) /* {{{ */
     static char credentials[1024];
     int status;
 
-    status = ssnprintf(credentials, sizeof(credentials), "%s:%s", user,
-                       (pass == NULL) ? "" : pass);
+    status = snprintf(credentials, sizeof(credentials), "%s:%s", user,
+                      (pass == NULL) ? "" : pass);
     if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
       ERROR("ascent plugin: ascent_init: Returning an error because the "
             "credentials have been truncated.");
@@ -511,7 +511,6 @@ static int ascent_init(void) /* {{{ */
 #endif
   }
 
-  curl_easy_setopt(curl, CURLOPT_URL, url);
   curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
   curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
 
@@ -554,6 +553,9 @@ static int ascent_read(void) /* {{{ */
   }
 
   ascent_buffer_fill = 0;
+
+  curl_easy_setopt(curl, CURLOPT_URL, url);
+
   if (curl_easy_perform(curl) != CURLE_OK) {
     ERROR("ascent plugin: curl_easy_perform failed: %s", ascent_curl_error);
     return -1;
index 5a0b089..b6dea0f 100644 (file)
@@ -347,8 +347,7 @@ static int sysfs_file_to_buffer(char const *dir, /* {{{ */
   char filename[PATH_MAX];
   int status;
 
-  ssnprintf(filename, sizeof(filename), "%s/%s/%s", dir, power_supply,
-            basename);
+  snprintf(filename, sizeof(filename), "%s/%s/%s", dir, power_supply, basename);
 
   status = (int)read_file_contents(filename, buffer, buffer_size - 1);
   if (status < 0)
@@ -479,7 +478,7 @@ static int read_acpi_full_capacity(char const *dir, /* {{{ */
 
   FILE *fh;
 
-  ssnprintf(filename, sizeof(filename), "%s/%s/info", dir, power_supply);
+  snprintf(filename, sizeof(filename), "%s/%s/info", dir, power_supply);
   fh = fopen(filename, "r");
   if (fh == NULL)
     return errno;
@@ -532,7 +531,7 @@ static int read_acpi_callback(char const *dir, /* {{{ */
 
   FILE *fh;
 
-  ssnprintf(filename, sizeof(filename), "%s/%s/state", dir, power_supply);
+  snprintf(filename, sizeof(filename), "%s/%s/state", dir, power_supply);
   fh = fopen(filename, "r");
   if (fh == NULL) {
     if ((errno == EAGAIN) || (errno == EINTR) || (errno == ENOENT))
@@ -641,11 +640,11 @@ static int read_pmu(void) /* {{{ */
     gauge_t voltage = NAN;
     gauge_t charge = NAN;
 
-    ssnprintf(filename, sizeof(filename), PROC_PMU_PATH_FORMAT, i);
+    snprintf(filename, sizeof(filename), PROC_PMU_PATH_FORMAT, i);
     if (access(filename, R_OK) != 0)
       break;
 
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "%i", i);
+    snprintf(plugin_instance, sizeof(plugin_instance), "%i", i);
 
     fh = fopen(filename, "r");
     if (fh == NULL) {
index b7308ad..990e2ca 100644 (file)
@@ -737,8 +737,8 @@ static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */
                                          nsstats_translation_table_length,
                                          plugin_instance};
 
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s",
-              view->name, zone_name);
+    snprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s", view->name,
+             zone_name);
 
     if (version == 3) {
       list_info_ptr_t list_info = {plugin_instance,
@@ -868,8 +868,7 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
     list_info_ptr_t list_info = {plugin_instance,
                                  /* type = */ "dns_qtype"};
 
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes",
-              view->name);
+    snprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes", view->name);
     if (version == 3) {
       bind_parse_generic_name_attr_value_list(
           /* xpath = */ "counters[@type='resqtype']",
@@ -891,8 +890,8 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
                                          resstats_translation_table_length,
                                          plugin_instance};
 
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats",
-              view->name);
+    snprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats",
+             view->name);
     if (version == 3) {
       bind_parse_generic_name_attr_value_list(
           "counters[@type='resstats']",
@@ -914,8 +913,8 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */
     list_info_ptr_t list_info = {plugin_instance,
                                  /* type = */ "dns_qtype_cached"};
 
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets",
-              view->name);
+    snprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets",
+             view->name);
 
     bind_parse_generic_name_value(/* xpath = */ "cache/rrset",
                                   /* callback = */ bind_xml_list_callback,
@@ -1598,7 +1597,6 @@ static int bind_init(void) /* {{{ */
   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, bind_curl_callback);
   curl_easy_setopt(curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, bind_curl_error);
-  curl_easy_setopt(curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
   curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
   curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
 #ifdef HAVE_CURLOPT_TIMEOUT_MS
@@ -1620,6 +1618,9 @@ static int bind_read(void) /* {{{ */
   }
 
   bind_buffer_fill = 0;
+
+  curl_easy_setopt(curl, CURLOPT_URL, (url != NULL) ? url : BIND_DEFAULT_URL);
+
   if (curl_easy_perform(curl) != CURLE_OK) {
     ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error);
     return -1;
index 9cb7cf9..18e489d 100644 (file)
@@ -63,7 +63,7 @@ static int read_cpuacct_procs(const char *dirname, char const *cgroup_name,
   if (ignorelist_match(il_cgroup, cgroup_name))
     return 0;
 
-  ssnprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, cgroup_name);
+  snprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, cgroup_name);
 
   status = lstat(abs_path, &statbuf);
   if (status != 0) {
@@ -75,8 +75,8 @@ static int read_cpuacct_procs(const char *dirname, char const *cgroup_name,
   if (!S_ISDIR(statbuf.st_mode))
     return 0;
 
-  ssnprintf(abs_path, sizeof(abs_path), "%s/%s/cpuacct.stat", dirname,
-            cgroup_name);
+  snprintf(abs_path, sizeof(abs_path), "%s/%s/cpuacct.stat", dirname,
+           cgroup_name);
   fh = fopen(abs_path, "r");
   if (fh == NULL) {
     char errbuf[1024];
@@ -138,7 +138,7 @@ static int read_cpuacct_root(const char *dirname, const char *filename,
   struct stat statbuf;
   int status;
 
-  ssnprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, filename);
+  snprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, filename);
 
   status = lstat(abs_path, &statbuf);
   if (status != 0) {
index a5e85a8..6fb369a 100644 (file)
@@ -348,10 +348,10 @@ static char *niptoha(const tChrony_IPAddr *addr, char *p_buf,
 }
 
 static void nreftostr(uint32_t nrefid, char *p_buf, size_t p_buf_size) {
-  int i, j, c;
+  size_t j = 0;
 
-  for (i = j = 0; i < 4; i++) {
-    c = ntohl(nrefid) << i * 8 >> 24;
+  for (int i = 0; i < 4; i++) {
+    int c = ntohl(nrefid) << i * 8 >> 24;
     if (!isalnum(c) || j + 1 >= p_buf_size)
       continue;
     p_buf[j++] = c;
index fb161af..6b59d4d 100644 (file)
 #  <EAL>
 #    Coremask "0x1"
 #    MemoryChannels "4"
-#    ProcessType "secondary"
 #    FilePrefix "rte"
 #  </EAL>
 #  <Event "link_status">
 #  <EAL>
 #    Coremask "0x2"
 #    MemoryChannels "4"
-#    ProcessType "secondary"
 #    FilePrefix "rte"
 #  </EAL>
 #  SharedMemObj "dpdk_collectd_stats_0"
 #      ForceSSL true
 #      VerifyPeer true
 #      CAPath "/path/to/folder"
+#      #ConnectTimeout 5000
 #</Plugin>
 
 #<Plugin olsrd>
index ceb6a13..67ee0a9 100644 (file)
@@ -2408,7 +2408,6 @@ B<Synopsis:>
    <EAL>
      Coremask "0x1"
      MemoryChannels "4"
-     ProcessType "secondary"
      FilePrefix "rte"
    </EAL>
    <Event "link_status">
@@ -2431,7 +2430,7 @@ B<Options:>
 
 =head3 The EAL block
 
-=over 5
+=over 4
 
 =item B<Coremask> I<Mask>
 
@@ -2439,10 +2438,6 @@ B<Options:>
 
 Number of memory channels per processor socket.
 
-=item B<ProcessType> I<type>
-
-The type of DPDK process instance.
-
 =item B<FilePrefix> I<File>
 
 The prefix text used for hugepage filenames. The filename will be set to
@@ -2457,7 +2452,7 @@ single argument which specifies the name of the event.
 
 =head4 Link Status event
 
-=over 5
+=over 4
 
 =item B<SendEventOnUpdate> I<true|false>
 
@@ -2490,7 +2485,7 @@ value is false.
 
 =head4 Keep Alive event
 
-=over 5
+=over 4
 
 =item B<SendEventOnUpdate> I<true|false>
 
@@ -2526,7 +2521,6 @@ B<Synopsis:>
    <EAL>
      Coremask "0x4"
      MemoryChannels "4"
-     ProcessType "secondary"
      FilePrefix "rte"
      SocketMemory "1024"
    </EAL>
@@ -2540,7 +2534,7 @@ B<Options:>
 
 =head3 The EAL block
 
-=over 5
+=over 4
 
 =item B<Coremask> I<Mask>
 
@@ -2551,10 +2545,6 @@ core numbering can change between platforms and should be determined beforehand.
 
 A string containing a number of memory channels per processor socket.
 
-=item B<ProcessType> I<type>
-
-A string containing the type of DPDK process instance.
-
 =item B<FilePrefix> I<File>
 
 The prefix text used for hugepage filenames. The filename will be set to
@@ -2570,6 +2560,7 @@ sockets in MB. This is an optional value.
 =over 3
 
 =item B<SharedMemObj> I<Mask>
+
 A string containing the name of the shared memory object that should be used to
 share stats from the DPDK secondary process to the collectd dpdkstat plugin.
 Defaults to dpdk_collectd_stats if no other value is configured.
@@ -5300,6 +5291,11 @@ generate links like the one described above for ALL certs in a given folder.
 Example usage:
 C<c_rehash /path/to/certs/folder>
 
+=item B<ConnectTimeout> I<Milliseconds>
+
+The B<ConnectTimeout> option sets the connect timeout, in milliseconds.
+By default, the configured B<Interval> is used to set the timeout.
+
 =back
 
 =head2 Plugin C<olsrd>
@@ -7198,6 +7194,7 @@ B<Synopsis:>
   <Plugin snmp_agent>
     <Data "memAvailReal">
       Plugin "memory"
+      #PluginInstance "some"
       Type "memory"
       TypeInstance "free"
       OIDs "1.3.6.1.4.1.2021.4.6.0"
@@ -7241,6 +7238,12 @@ scalar data type B<Instance> has no effect and can be omitted.
 
 Read plugin name whose collected data will be mapped to specified OIDs.
 
+=item B<PluginInstance> I<String>
+
+Read plugin instance whose collected data will be mapped to specified OIDs.
+The field is optional and by default there is no plugin instance check.
+Allowed only if B<Data> block defines scalar data type.
+
 =item B<Type> I<String>
 
 Collectd's type that is to be used for specified OID, e.E<nbsp>g. "if_octets"
@@ -7253,9 +7256,9 @@ Collectd's type-instance that is to be used for specified OID.
 =item B<OIDs> I<OID> [I<OID> ...]
 
 Configures the OIDs to be handled by I<snmp_agent> plugin. Values for these OIDs
-are taken from collectd data type specified by B<Plugin>, B<Type>,
-B<TypeInstance> fields of this B<Data> block. Number of the OIDs configured
-should correspond to number of values in specified B<Type>.
+are taken from collectd data type specified by B<Plugin>, B<PluginInstance>,
+B<Type>, B<TypeInstance> fields of this B<Data> block. Number of the OIDs
+configured should correspond to number of values in specified B<Type>.
 For example two OIDs "IF-MIB::ifInOctets" "IF-MIB::ifOutOctets" can be mapped to
 "rx" and "tx" values of "if_octets" type.
 
index a5a136e..307ae49 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -326,7 +326,7 @@ static void submit_value(int cpu_num, int cpu_state, const char *type,
            sizeof(vl.type_instance));
 
   if (cpu_num >= 0) {
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", cpu_num);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", cpu_num);
   }
   plugin_dispatch_values(&vl);
 }
index 608e60e..0139947 100644 (file)
@@ -34,10 +34,10 @@ static int cpufreq_init(void) {
   num_cpu = 0;
 
   while (1) {
-    status = ssnprintf(filename, sizeof(filename),
-                       "/sys/devices/system/cpu/cpu%d/cpufreq/"
-                       "scaling_cur_freq",
-                       num_cpu);
+    status = snprintf(filename, sizeof(filename),
+                      "/sys/devices/system/cpu/cpu%d/cpufreq/"
+                      "scaling_cur_freq",
+                      num_cpu);
     if ((status < 1) || ((unsigned int)status >= sizeof(filename)))
       break;
 
@@ -62,7 +62,7 @@ static void cpufreq_submit(int cpu_num, value_t value) {
   vl.values_len = 1;
   sstrncpy(vl.plugin, "cpufreq", sizeof(vl.plugin));
   sstrncpy(vl.type, "cpufreq", sizeof(vl.type));
-  ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%i", cpu_num);
+  snprintf(vl.type_instance, sizeof(vl.type_instance), "%i", cpu_num);
 
   plugin_dispatch_values(&vl);
 }
@@ -70,8 +70,8 @@ static void cpufreq_submit(int cpu_num, value_t value) {
 static int cpufreq_read(void) {
   for (int i = 0; i < num_cpu; i++) {
     char filename[PATH_MAX];
-    ssnprintf(filename, sizeof(filename),
-              "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i);
+    snprintf(filename, sizeof(filename),
+             "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", i);
 
     value_t v;
     if (parse_value_file(filename, &v, DS_TYPE_GAUGE) != 0) {
index e4c84f7..debe095 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
@@ -47,7 +47,7 @@ static int value_list_to_string(char *buffer, int buffer_len,
 
   memset(buffer, '\0', buffer_len);
 
-  status = ssnprintf(buffer, buffer_len, "%.3f", CDTIME_T_TO_DOUBLE(vl->time));
+  status = snprintf(buffer, buffer_len, "%.3f", CDTIME_T_TO_DOUBLE(vl->time));
   if ((status < 1) || (status >= buffer_len))
     return -1;
   offset = status;
@@ -62,8 +62,8 @@ static int value_list_to_string(char *buffer, int buffer_len,
     }
 
     if (ds->ds[i].type == DS_TYPE_GAUGE) {
-      status = ssnprintf(buffer + offset, buffer_len - offset, ",%lf",
-                         vl->values[i].gauge);
+      status = snprintf(buffer + offset, buffer_len - offset, ",%lf",
+                        vl->values[i].gauge);
     } else if (store_rates != 0) {
       if (rates == NULL)
         rates = uc_get_rate(ds, vl);
@@ -72,17 +72,16 @@ static int value_list_to_string(char *buffer, int buffer_len,
                 "uc_get_rate failed.");
         return -1;
       }
-      status =
-          ssnprintf(buffer + offset, buffer_len - offset, ",%lf", rates[i]);
+      status = snprintf(buffer + offset, buffer_len - offset, ",%lf", rates[i]);
     } else if (ds->ds[i].type == DS_TYPE_COUNTER) {
-      status = ssnprintf(buffer + offset, buffer_len - offset, ",%llu",
-                         vl->values[i].counter);
+      status = snprintf(buffer + offset, buffer_len - offset, ",%llu",
+                        vl->values[i].counter);
     } else if (ds->ds[i].type == DS_TYPE_DERIVE) {
-      status = ssnprintf(buffer + offset, buffer_len - offset, ",%" PRIi64,
-                         vl->values[i].derive);
+      status = snprintf(buffer + offset, buffer_len - offset, ",%" PRIi64,
+                        vl->values[i].derive);
     } else if (ds->ds[i].type == DS_TYPE_ABSOLUTE) {
-      status = ssnprintf(buffer + offset, buffer_len - offset, ",%" PRIu64,
-                         vl->values[i].absolute);
+      status = snprintf(buffer + offset, buffer_len - offset, ",%" PRIu64,
+                        vl->values[i].absolute);
     }
 
     if ((status < 1) || (status >= (buffer_len - offset))) {
index 808f242..cc48c77 100644 (file)
@@ -347,7 +347,6 @@ static int cc_page_init_curl(web_page_t *wp) /* {{{ */
   curl_easy_setopt(wp->curl, CURLOPT_WRITEDATA, wp);
   curl_easy_setopt(wp->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt(wp->curl, CURLOPT_ERRORBUFFER, wp->curl_errbuf);
-  curl_easy_setopt(wp->curl, CURLOPT_URL, wp->url);
   curl_easy_setopt(wp->curl, CURLOPT_FOLLOWLOCATION, 1L);
   curl_easy_setopt(wp->curl, CURLOPT_MAXREDIRS, 50L);
 
@@ -369,8 +368,8 @@ static int cc_page_init_curl(web_page_t *wp) /* {{{ */
       return -1;
     }
 
-    ssnprintf(wp->credentials, credentials_size, "%s:%s", wp->user,
-              (wp->pass == NULL) ? "" : wp->pass);
+    snprintf(wp->credentials, credentials_size, "%s:%s", wp->user,
+             (wp->pass == NULL) ? "" : wp->pass);
     curl_easy_setopt(wp->curl, CURLOPT_USERPWD, wp->credentials);
 #endif
 
@@ -611,6 +610,9 @@ static int cc_read_page(web_page_t *wp) /* {{{ */
     start = cdtime();
 
   wp->buffer_fill = 0;
+
+  curl_easy_setopt(wp->curl, CURLOPT_URL, wp->url);
+
   status = curl_easy_perform(wp->curl);
   if (status != CURLE_OK) {
     ERROR("curl plugin: curl_easy_perform failed with status %i: %s", status,
index 8037742..35b11c0 100644 (file)
@@ -217,7 +217,7 @@ static void cj_advance_array(cj_t *db) {
   db->state[db->depth].index++;
 
   char name[DATA_MAX_NAME_LEN];
-  ssnprintf(name, sizeof(name), "%d", db->state[db->depth].index);
+  snprintf(name, sizeof(name), "%d", db->state[db->depth].index);
   cj_load_key(db, name);
 }
 
@@ -578,7 +578,6 @@ static int cj_init_curl(cj_t *db) /* {{{ */
   curl_easy_setopt(db->curl, CURLOPT_WRITEDATA, db);
   curl_easy_setopt(db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt(db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
-  curl_easy_setopt(db->curl, CURLOPT_URL, db->url);
   curl_easy_setopt(db->curl, CURLOPT_FOLLOWLOCATION, 1L);
   curl_easy_setopt(db->curl, CURLOPT_MAXREDIRS, 50L);
 
@@ -600,8 +599,8 @@ static int cj_init_curl(cj_t *db) /* {{{ */
       return -1;
     }
 
-    ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
-              (db->pass == NULL) ? "" : db->pass);
+    snprintf(db->credentials, credentials_size, "%s:%s", db->user,
+             (db->pass == NULL) ? "" : db->pass);
     curl_easy_setopt(db->curl, CURLOPT_USERPWD, db->credentials);
 #endif
 
@@ -800,8 +799,8 @@ static void cj_submit_impl(cj_t *db, cj_key_t *key, value_t *value) /* {{{ */
   if (key->instance == NULL) {
     int len = 0;
     for (int i = 0; i < db->depth; i++)
-      len += ssnprintf(vl.type_instance + len, sizeof(vl.type_instance) - len,
-                       i ? "-%s" : "%s", db->state[i + 1].name);
+      len += snprintf(vl.type_instance + len, sizeof(vl.type_instance) - len,
+                      i ? "-%s" : "%s", db->state[i + 1].name);
   } else
     sstrncpy(vl.type_instance, key->instance, sizeof(vl.type_instance));
 
@@ -858,12 +857,13 @@ static int cj_curl_perform(cj_t *db) /* {{{ */
   int status;
   long rc;
   char *url;
-  url = db->url;
+
+  curl_easy_setopt(db->curl, CURLOPT_URL, db->url);
 
   status = curl_easy_perform(db->curl);
   if (status != CURLE_OK) {
     ERROR("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
-          status, db->curl_errbuf, url);
+          status, db->curl_errbuf, db->url);
     return -1;
   }
   if (db->stats != NULL)
index a0dca05..e83de73 100644 (file)
@@ -369,7 +369,7 @@ static int cx_handle_all_value_xpaths(xmlXPathContextPtr xpath_ctx, /* {{{ */
     status = cx_handle_single_value_xpath(xpath_ctx, xpath, ds, vl, i);
     if (status != 0)
       return -1; /* An error has been printed. */
-  }                /* for (i = 0; i < xpath->values_len; i++) */
+  }              /* for (i = 0; i < xpath->values_len; i++) */
 
   plugin_dispatch_values(vl);
   vl->values = NULL;
@@ -441,8 +441,8 @@ static int cx_handle_instance_xpath(xmlXPathContextPtr xpath_ctx, /* {{{ */
   if (xpath->instance_prefix != NULL) {
     if (instance_node != NULL) {
       char *node_value = (char *)xmlNodeGetContent(instance_node->nodeTab[0]);
-      ssnprintf(vl->type_instance, sizeof(vl->type_instance), "%s%s",
-                xpath->instance_prefix, node_value);
+      snprintf(vl->type_instance, sizeof(vl->type_instance), "%s%s",
+               xpath->instance_prefix, node_value);
       sfree(node_value);
     } else
       sstrncpy(vl->type_instance, xpath->instance_prefix,
@@ -602,13 +602,15 @@ static int cx_curl_perform(cx_t *db, CURL *curl) /* {{{ */
   long rc;
   char *ptr;
   char *url;
-  url = db->url;
 
   db->buffer_fill = 0;
+
+  curl_easy_setopt(db->curl, CURLOPT_URL, db->url);
+
   status = curl_easy_perform(curl);
   if (status != CURLE_OK) {
     ERROR("curl_xml plugin: curl_easy_perform failed with status %i: %s (%s)",
-          status, db->curl_errbuf, url);
+          status, db->curl_errbuf, db->url);
     return -1;
   }
   if (db->stats != NULL)
@@ -817,7 +819,6 @@ static int cx_init_curl(cx_t *db) /* {{{ */
   curl_easy_setopt(db->curl, CURLOPT_WRITEDATA, db);
   curl_easy_setopt(db->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
   curl_easy_setopt(db->curl, CURLOPT_ERRORBUFFER, db->curl_errbuf);
-  curl_easy_setopt(db->curl, CURLOPT_URL, db->url);
   curl_easy_setopt(db->curl, CURLOPT_FOLLOWLOCATION, 1L);
   curl_easy_setopt(db->curl, CURLOPT_MAXREDIRS, 50L);
 
@@ -839,8 +840,8 @@ static int cx_init_curl(cx_t *db) /* {{{ */
       return -1;
     }
 
-    ssnprintf(db->credentials, credentials_size, "%s:%s", db->user,
-              (db->pass == NULL) ? "" : db->pass);
+    snprintf(db->credentials, credentials_size, "%s:%s", db->user,
+             (db->pass == NULL) ? "" : db->pass);
     curl_easy_setopt(db->curl, CURLOPT_USERPWD, db->credentials);
 #endif
 
index d9c8348..3ae61d8 100644 (file)
@@ -84,18 +84,6 @@ char *sstrncpy(char *dest, const char *src, size_t n) {
   return dest;
 } /* char *sstrncpy */
 
-int ssnprintf(char *dest, size_t n, const char *format, ...) {
-  int ret = 0;
-  va_list ap;
-
-  va_start(ap, format);
-  ret = vsnprintf(dest, n, format, ap);
-  dest[n - 1] = '\0';
-  va_end(ap);
-
-  return ret;
-} /* int ssnprintf */
-
 char *ssnprintf_alloc(char const *format, ...) /* {{{ */
 {
   char static_buffer[1024] = "";
@@ -191,9 +179,9 @@ char *sstrerror(int errnum, char *buf, size_t buflen) {
 
 #else
   if (strerror_r(errnum, buf, buflen) != 0) {
-    ssnprintf(buf, buflen, "Error #%i; "
-                           "Additionally, strerror_r failed.",
-              errnum);
+    snprintf(buf, buflen, "Error #%i; "
+                          "Additionally, strerror_r failed.",
+             errnum);
   }
 #endif /* STRERROR_R_CHAR_P */
 
@@ -675,7 +663,7 @@ int get_kstat(kstat_t **ksp_ptr, char *module, int instance, char *name) {
   if (kc == NULL)
     return -1;
 
-  ssnprintf(ident, sizeof(ident), "%s,%i,%s", module, instance, name);
+  snprintf(ident, sizeof(ident), "%s,%i,%s", module, instance, name);
 
   *ksp_ptr = kstat_lookup(kc, module, instance, name);
   if (*ksp_ptr == NULL) {
@@ -882,7 +870,7 @@ int format_values(char *ret, size_t ret_len, /* {{{ */
 
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
-    status = ssnprintf(ret + offset, ret_len - offset, __VA_ARGS__);           \
+    status = snprintf(ret + offset, ret_len - offset, __VA_ARGS__);            \
     if (status < 1) {                                                          \
       sfree(rates);                                                            \
       return -1;                                                               \
index 8947c57..afd292a 100644 (file)
@@ -66,9 +66,6 @@ typedef struct value_to_rate_state_s value_to_rate_state_t;
 
 char *sstrncpy(char *dest, const char *src, size_t n);
 
-__attribute__((format(printf, 3, 4))) int ssnprintf(char *dest, size_t n,
-                                                    const char *format, ...);
-
 __attribute__((format(printf, 1, 2))) char *ssnprintf_alloc(char const *format,
                                                             ...);
 
index 5b577d4..67d800e 100644 (file)
@@ -58,27 +58,6 @@ DEF_TEST(sstrncpy) {
   return 0;
 }
 
-DEF_TEST(ssnprintf) {
-  char buffer[16] = "";
-  char *ptr = &buffer[4];
-  int status;
-
-  buffer[0] = buffer[1] = buffer[2] = buffer[3] = 0xff;
-  buffer[12] = buffer[13] = buffer[14] = buffer[15] = 0xff;
-
-  status = ssnprintf(ptr, 8, "%i", 1337);
-  OK(status == 4);
-  EXPECT_EQ_STR("1337", ptr);
-
-  status = ssnprintf(ptr, 8, "%s", "collectd");
-  OK(status == 8);
-  OK(ptr[7] == 0);
-  EXPECT_EQ_STR("collect", ptr);
-  OK(buffer[3] == buffer[12]);
-
-  return 0;
-}
-
 DEF_TEST(sstrdup) {
   char *ptr;
 
index 5594bb7..0d295c1 100644 (file)
@@ -196,7 +196,7 @@ static int dispatch_global_option(const oconfig_item_t *ci) {
     return global_option_set(ci->key, ci->values[0].value.string, 0);
   else if (ci->values[0].type == OCONFIG_TYPE_NUMBER) {
     char tmp[128];
-    ssnprintf(tmp, sizeof(tmp), "%lf", ci->values[0].value.number);
+    snprintf(tmp, sizeof(tmp), "%lf", ci->values[0].value.number);
     return global_option_set(ci->key, tmp, 0);
   } else if (ci->values[0].type == OCONFIG_TYPE_BOOLEAN) {
     if (ci->values[0].value.boolean)
@@ -305,13 +305,13 @@ static int dispatch_value_plugin(const char *plugin, oconfig_item_t *ci) {
 
     if (ci->values[i].type == OCONFIG_TYPE_STRING)
       status =
-          ssnprintf(buffer_ptr, buffer_free, " %s", ci->values[i].value.string);
+          snprintf(buffer_ptr, buffer_free, " %s", ci->values[i].value.string);
     else if (ci->values[i].type == OCONFIG_TYPE_NUMBER)
-      status = ssnprintf(buffer_ptr, buffer_free, " %lf",
-                         ci->values[i].value.number);
+      status =
+          snprintf(buffer_ptr, buffer_free, " %lf", ci->values[i].value.number);
     else if (ci->values[i].type == OCONFIG_TYPE_BOOLEAN)
-      status = ssnprintf(buffer_ptr, buffer_free, " %s",
-                         ci->values[i].value.boolean ? "true" : "false");
+      status = snprintf(buffer_ptr, buffer_free, " %s",
+                        ci->values[i].value.boolean ? "true" : "false");
 
     if ((status < 0) || (status >= buffer_free))
       return -1;
@@ -653,7 +653,7 @@ static oconfig_item_t *cf_read_dir(const char *dir, const char *pattern,
     if ((de->d_name[0] == '.') || (de->d_name[0] == 0))
       continue;
 
-    status = ssnprintf(name, sizeof(name), "%s/%s", dir, de->d_name);
+    status = snprintf(name, sizeof(name), "%s/%s", dir, de->d_name);
     if ((status < 0) || ((size_t)status >= sizeof(name))) {
       ERROR("configfile: Not including `%s/%s' because its"
             " name is too long.",
@@ -1246,7 +1246,7 @@ int cf_util_get_service(const oconfig_item_t *ci, char **ret_string) /* {{{ */
     ERROR("cf_util_get_service: Out of memory.");
     return -1;
   }
-  ssnprintf(service, 6, "%i", port);
+  snprintf(service, 6, "%i", port);
 
   sfree(*ret_string);
   *ret_string = service;
index 5a2d647..1352f5b 100644 (file)
@@ -343,8 +343,8 @@ static int fc_config_add_rule(fc_chain_t *chain, /* {{{ */
 
   if (ci->values_num == 1) {
     sstrncpy(rule->name, ci->values[0].value.string, sizeof(rule->name));
-    ssnprintf(rule_name, sizeof(rule_name), "Rule \"%s\"",
-              ci->values[0].value.string);
+    snprintf(rule_name, sizeof(rule_name), "Rule \"%s\"",
+             ci->values[0].value.string);
   }
 
   for (int i = 0; i < ci->children_num; i++) {
index 502ca10..ce3e102 100644 (file)
@@ -713,15 +713,15 @@ int meta_data_as_string(meta_data_t *md, /* {{{ */
     actual = e->value.mv_string;
     break;
   case MD_TYPE_SIGNED_INT:
-    ssnprintf(buffer, sizeof(buffer), "%" PRIi64, e->value.mv_signed_int);
+    snprintf(buffer, sizeof(buffer), "%" PRIi64, e->value.mv_signed_int);
     actual = buffer;
     break;
   case MD_TYPE_UNSIGNED_INT:
-    ssnprintf(buffer, sizeof(buffer), "%" PRIu64, e->value.mv_unsigned_int);
+    snprintf(buffer, sizeof(buffer), "%" PRIu64, e->value.mv_unsigned_int);
     actual = buffer;
     break;
   case MD_TYPE_DOUBLE:
-    ssnprintf(buffer, sizeof(buffer), GAUGE_FORMAT, e->value.mv_double);
+    snprintf(buffer, sizeof(buffer), GAUGE_FORMAT, e->value.mv_double);
     actual = buffer;
     break;
   case MD_TYPE_BOOLEAN:
index 3bf183d..0451e8a 100644 (file)
@@ -400,13 +400,13 @@ static int plugin_load_file(const char *file, _Bool global) {
   if (dlh == NULL) {
     char errbuf[1024] = "";
 
-    ssnprintf(errbuf, sizeof(errbuf),
-              "dlopen (\"%s\") failed: %s. "
-              "The most common cause for this problem is "
-              "missing dependencies. Use ldd(1) to check "
-              "the dependencies of the plugin "
-              "/ shared object.",
-              file, dlerror());
+    snprintf(errbuf, sizeof(errbuf),
+             "dlopen (\"%s\") failed: %s. "
+             "The most common cause for this problem is "
+             "missing dependencies. Use ldd(1) to check "
+             "the dependencies of the plugin "
+             "/ shared object.",
+             file, dlerror());
 
     ERROR("%s", errbuf);
     /* Make sure this is printed to STDERR in any case, but also
@@ -640,7 +640,7 @@ static void start_read_threads(size_t num) /* {{{ */
     }
 
     char name[THREAD_NAME_MAX];
-    ssnprintf(name, sizeof(name), "reader#%zu", read_threads_num);
+    snprintf(name, sizeof(name), "reader#%zu", read_threads_num);
     set_thread_name(read_threads[read_threads_num], name);
 
     read_threads_num++;
@@ -847,7 +847,7 @@ static void start_write_threads(size_t num) /* {{{ */
     }
 
     char name[THREAD_NAME_MAX];
-    ssnprintf(name, sizeof(name), "writer#%zu", write_threads_num);
+    snprintf(name, sizeof(name), "writer#%zu", write_threads_num);
     set_thread_name(write_threads[write_threads_num], name);
 
     write_threads_num++;
@@ -996,7 +996,7 @@ int plugin_load(char const *plugin_name, _Bool global) {
 
   /* `cpu' should not match `cpufreq'. To solve this we add `.so' to the
    * type when matching the filename */
-  status = ssnprintf(typename, sizeof(typename), "%s.so", plugin_name);
+  status = snprintf(typename, sizeof(typename), "%s.so", plugin_name);
   if ((status < 0) || ((size_t)status >= sizeof(typename))) {
     WARNING("plugin_load: Filename too long: \"%s.so\"", plugin_name);
     return -1;
@@ -1013,7 +1013,7 @@ int plugin_load(char const *plugin_name, _Bool global) {
     if (strcasecmp(de->d_name, typename))
       continue;
 
-    status = ssnprintf(filename, sizeof(filename), "%s/%s", dir, de->d_name);
+    status = snprintf(filename, sizeof(filename), "%s/%s", dir, de->d_name);
     if ((status < 0) || ((size_t)status >= sizeof(filename))) {
       WARNING("plugin_load: Filename too long: \"%s/%s\"", dir, de->d_name);
       continue;
index 815d969..ab440ed 100644 (file)
@@ -164,7 +164,7 @@ int format_rfc3339(char *buffer, size_t buffer_size, struct tm const *t_tm,
   size_left -= len;
 
   if (print_nano) {
-    if ((len = ssnprintf(pos, size_left, ".%09ld", nsec)) == 0)
+    if ((len = snprintf(pos, size_left, ".%09ld", nsec)) == 0)
       return ENOMEM;
     pos += len;
     size_left -= len;
index ac307ff..a577aef 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -107,10 +107,10 @@ static const char *cdbi_strerror(dbi_conn conn, /* {{{ */
   msg = NULL;
   status = dbi_conn_error(conn, &msg);
   if ((status >= 0) && (msg != NULL))
-    ssnprintf(buffer, buffer_size, "%s (status %i)", msg, status);
+    snprintf(buffer, buffer_size, "%s (status %i)", msg, status);
   else
-    ssnprintf(buffer, buffer_size, "dbi_conn_error failed with status %i",
-              status);
+    snprintf(buffer, buffer_size, "dbi_conn_error failed with status %i",
+             status);
 
   return buffer;
 } /* }}} const char *cdbi_conn_error */
@@ -131,12 +131,12 @@ static int cdbi_result_get_field(dbi_result res, /* {{{ */
     long long value;
 
     value = dbi_result_get_longlong_idx(res, index);
-    ssnprintf(buffer, buffer_size, "%lli", value);
+    snprintf(buffer, buffer_size, "%lli", value);
   } else if (src_type == DBI_TYPE_DECIMAL) {
     double value;
 
     value = dbi_result_get_double_idx(res, index);
-    ssnprintf(buffer, buffer_size, "%63.15g", value);
+    snprintf(buffer, buffer_size, "%63.15g", value);
   } else if (src_type == DBI_TYPE_STRING) {
     const char *value;
 
index 4a217c3..51a50fd 100644 (file)
@@ -405,8 +405,8 @@ static int disk_read(void) {
 
   /* Get the list of all disk objects. */
   if (IOServiceGetMatchingServices(
-                                   io_master_port, IOServiceMatching(kIOBlockStorageDriverClass),
-                                   &disk_list) != kIOReturnSuccess) {
+          io_master_port, IOServiceMatching(kIOBlockStorageDriverClass),
+          &disk_list) != kIOReturnSuccess) {
     ERROR("disk plugin: IOServiceGetMatchingServices failed.");
     return -1;
   }
@@ -490,11 +490,10 @@ static int disk_read(void) {
         sstrncpy(disk_name, props_disk_name_bsd, sizeof(disk_name));
       else {
         ERROR("disk plugin: can't find bsd disk name.");
-        ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major,
-                  disk_minor);
+        snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor);
       }
     } else
-      ssnprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor);
+      snprintf(disk_name, sizeof(disk_name), "%i-%i", disk_major, disk_minor);
 
     DEBUG("disk plugin: disk_name = \"%s\"", disk_name);
 
index 6be6bc0..efb7694 100644 (file)
@@ -66,19 +66,20 @@ typedef struct dpdk_ka_monitor_s {
 
 typedef struct dpdk_link_status_config_s {
   int enabled;
-  int send_updated;
+  _Bool send_updated;
   uint32_t enabled_port_mask;
   char port_name[RTE_MAX_ETHPORTS][DATA_MAX_NAME_LEN];
-  int notify;
+  _Bool notify;
 } dpdk_link_status_config_t;
 
 typedef struct dpdk_keep_alive_config_s {
   int enabled;
-  int send_updated;
+  _Bool send_updated;
   uint128_t lcore_mask;
   dpdk_keepalive_shm_t *shm;
   char shm_name[DATA_MAX_NAME_LEN];
-  int notify;
+  _Bool notify;
+  int fd;
 } dpdk_keep_alive_config_t;
 
 typedef struct dpdk_events_config_s {
@@ -100,14 +101,22 @@ typedef struct dpdk_events_ctx_s {
   dpdk_ka_monitor_t core_info[RTE_KEEPALIVE_MAXCORES];
 } dpdk_events_ctx_t;
 
+typedef enum {
+  DPDK_EVENTS_STATE_CFG_ERR = 1 << 0,
+  DPDK_EVENTS_STATE_KA_CFG_ERR = 1 << 1,
+  DPDK_EVENTS_STATE_LS_CFG_ERR = 1 << 2,
+
+} dpdk_events_cfg_status;
+
 #define DPDK_EVENTS_CTX_GET(a) ((dpdk_events_ctx_t *)dpdk_helper_priv_get(a))
 
 #define DPDK_EVENTS_TRACE()                                                    \
   DEBUG("%s:%s:%d pid=%u", DPDK_EVENTS_PLUGIN, __FUNCTION__, __LINE__, getpid())
 
 static dpdk_helper_ctx_t *g_hc;
+static dpdk_events_cfg_status g_state;
 
-static int dpdk_event_keep_alive_shm_create(void) {
+static int dpdk_event_keep_alive_shm_open(void) {
   dpdk_events_ctx_t *ec = DPDK_EVENTS_CTX_GET(g_hc);
   char *shm_name;
 
@@ -121,23 +130,48 @@ static int dpdk_event_keep_alive_shm_create(void) {
   }
 
   char errbuf[ERR_BUF_SIZE];
-  int fd = shm_open(shm_name, O_RDWR, 0);
+  int fd = shm_open(shm_name, O_RDONLY, 0);
   if (fd < 0) {
     ERROR(DPDK_EVENTS_PLUGIN ": Failed to open %s as SHM:%s. Is DPDK KA "
                              "primary application running?",
           shm_name, sstrerror(errno, errbuf, sizeof(errbuf)));
     return errno;
-  } else {
-    ec->config.keep_alive.shm =
-        (dpdk_keepalive_shm_t *)mmap(0, sizeof(*(ec->config.keep_alive.shm)),
-                                     PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-    close(fd);
-    if (ec->config.keep_alive.shm == MAP_FAILED) {
-      ERROR(DPDK_EVENTS_PLUGIN ": Failed to mmap KA SHM:%s",
-            sstrerror(errno, errbuf, sizeof(errbuf)));
-      return errno;
+  }
+
+  if (ec->config.keep_alive.fd != -1) {
+    struct stat stat_old, stat_new;
+
+    if (fstat(ec->config.keep_alive.fd, &stat_old) || fstat(fd, &stat_new)) {
+      ERROR(DPDK_EVENTS_PLUGIN ": failed to get information about a file");
+      close(fd);
+      return -1;
+    }
+
+    /* Check if inode number has changed. If yes, then create a new mapping */
+    if (stat_old.st_ino == stat_new.st_ino) {
+      close(fd);
+      return 0;
+    }
+
+    if (munmap(ec->config.keep_alive.shm, sizeof(dpdk_keepalive_shm_t)) != 0) {
+      ERROR(DPDK_EVENTS_PLUGIN ": munmap KA monitor failed");
+      close(fd);
+      return -1;
     }
+
+    close(ec->config.keep_alive.fd);
+    ec->config.keep_alive.fd = -1;
+  }
+
+  ec->config.keep_alive.shm = (dpdk_keepalive_shm_t *)mmap(
+      0, sizeof(*(ec->config.keep_alive.shm)), PROT_READ, MAP_SHARED, fd, 0);
+  if (ec->config.keep_alive.shm == MAP_FAILED) {
+    ERROR(DPDK_EVENTS_PLUGIN ": Failed to mmap KA SHM:%s",
+          sstrerror(errno, errbuf, sizeof(errbuf)));
+    close(fd);
+    return errno;
   }
+  ec->config.keep_alive.fd = fd;
 
   return 0;
 }
@@ -147,8 +181,11 @@ static void dpdk_events_default_config(void) {
 
   ec->config.interval = plugin_get_interval();
 
+  /* In configless mode when no <Plugin/> section is defined in config file
+   * both link_status and keep_alive should be enabled */
+
   /* Link Status */
-  ec->config.link_status.enabled = 0;
+  ec->config.link_status.enabled = 1;
   ec->config.link_status.enabled_port_mask = ~0;
   ec->config.link_status.send_updated = 1;
   ec->config.link_status.notify = 0;
@@ -158,13 +195,16 @@ static void dpdk_events_default_config(void) {
   }
 
   /* Keep Alive */
-  ec->config.keep_alive.enabled = 0;
+  ec->config.keep_alive.enabled = 1;
   ec->config.keep_alive.send_updated = 1;
   ec->config.keep_alive.notify = 0;
-  memset(&ec->config.keep_alive.lcore_mask, 0,
+  /* by default enable 128 cores */
+  memset(&ec->config.keep_alive.lcore_mask, 1,
          sizeof(ec->config.keep_alive.lcore_mask));
   memset(&ec->config.keep_alive.shm_name, 0,
          sizeof(ec->config.keep_alive.shm_name));
+  ec->config.keep_alive.shm = MAP_FAILED;
+  ec->config.keep_alive.fd = -1;
 }
 
 static int dpdk_events_preinit(void) {
@@ -208,18 +248,26 @@ static int dpdk_events_link_status_config(dpdk_events_ctx_t *ec,
     oconfig_item_t *child = ci->children + i;
 
     if (strcasecmp("EnabledPortMask", child->key) == 0) {
-      ec->config.link_status.enabled_port_mask =
-          (uint32_t)child->values[0].value.number;
+      if (cf_util_get_int(child,
+                          (int *)&ec->config.link_status.enabled_port_mask))
+        return -1;
       DEBUG(DPDK_EVENTS_PLUGIN ": LinkStatus:Enabled Port Mask 0x%X",
             ec->config.link_status.enabled_port_mask);
     } else if (strcasecmp("SendEventsOnUpdate", child->key) == 0) {
-      ec->config.link_status.send_updated = child->values[0].value.boolean;
+      if (cf_util_get_boolean(child, &ec->config.link_status.send_updated))
+        return -1;
       DEBUG(DPDK_EVENTS_PLUGIN ": LinkStatus:SendEventsOnUpdate %d",
-            (int)child->values[0].value.boolean);
+            ec->config.link_status.send_updated);
     } else if (strcasecmp("SendNotification", child->key) == 0) {
-      ec->config.link_status.notify = child->values[0].value.boolean;
+      if (cf_util_get_boolean(child, &ec->config.link_status.notify))
+        return -1;
+
       DEBUG(DPDK_EVENTS_PLUGIN ": LinkStatus:SendNotification %d",
-            (int)child->values[0].value.boolean);
+            ec->config.link_status.notify);
+    } else if (strcasecmp("PortName", child->key) != 0) {
+      ERROR(DPDK_EVENTS_PLUGIN ": unrecognized configuration option %s.",
+            child->key);
+      return -1;
     }
   }
 
@@ -231,8 +279,12 @@ static int dpdk_events_link_status_config(dpdk_events_ctx_t *ec,
     if (strcasecmp("PortName", child->key) == 0) {
       while (!(ec->config.link_status.enabled_port_mask & (1 << port_num)))
         port_num++;
-      ssnprintf(ec->config.link_status.port_name[port_num], DATA_MAX_NAME_LEN,
-                "%s", child->values[0].value.string);
+
+      if (cf_util_get_string_buffer(
+              child, ec->config.link_status.port_name[port_num],
+              sizeof(ec->config.link_status.port_name[port_num]))) {
+        return -1;
+      }
       DEBUG(DPDK_EVENTS_PLUGIN ": LinkStatus:Port %d Name: %s", port_num,
             ec->config.link_status.port_name[port_num]);
       port_num++;
@@ -251,28 +303,38 @@ static int dpdk_events_keep_alive_config(dpdk_events_ctx_t *ec,
     oconfig_item_t *child = ci->children + i;
 
     if (strcasecmp("SendEventsOnUpdate", child->key) == 0) {
-      ec->config.keep_alive.send_updated = child->values[0].value.boolean;
+      if (cf_util_get_boolean(child, &ec->config.keep_alive.send_updated))
+        return -1;
+
       DEBUG(DPDK_EVENTS_PLUGIN ": KeepAlive:SendEventsOnUpdate %d",
-            (int)child->values[0].value.boolean);
+            ec->config.keep_alive.send_updated);
     } else if (strcasecmp("LCoreMask", child->key) == 0) {
       char lcore_mask[DATA_MAX_NAME_LEN];
-      ssnprintf(lcore_mask, sizeof(lcore_mask), "%s",
-                child->values[0].value.string);
+
+      if (cf_util_get_string_buffer(child, lcore_mask, sizeof(lcore_mask)))
+        return -1;
       ec->config.keep_alive.lcore_mask =
           str_to_uint128(lcore_mask, strlen(lcore_mask));
       DEBUG(DPDK_EVENTS_PLUGIN ": KeepAlive:LCoreMask 0x%" PRIX64 "%" PRIX64 "",
             ec->config.keep_alive.lcore_mask.high,
             ec->config.keep_alive.lcore_mask.low);
     } else if (strcasecmp("KeepAliveShmName", child->key) == 0) {
-      ssnprintf(ec->config.keep_alive.shm_name,
-                sizeof(ec->config.keep_alive.shm_name), "%s",
-                child->values[0].value.string);
+      if (cf_util_get_string_buffer(child, ec->config.keep_alive.shm_name,
+                                    sizeof(ec->config.keep_alive.shm_name)))
+        return -1;
+
       DEBUG(DPDK_EVENTS_PLUGIN ": KeepAlive:KeepAliveShmName %s",
             ec->config.keep_alive.shm_name);
     } else if (strcasecmp("SendNotification", child->key) == 0) {
-      ec->config.keep_alive.notify = child->values[0].value.boolean;
+      if (cf_util_get_boolean(child, &ec->config.keep_alive.notify))
+        return -1;
+
       DEBUG(DPDK_EVENTS_PLUGIN ": KeepAlive:SendNotification %d",
-            (int)child->values[0].value.boolean);
+            ec->config.keep_alive.notify);
+    } else {
+      ERROR(DPDK_EVENTS_PLUGIN ": unrecognized configuration option %s.",
+            child->key);
+      return -1;
     }
   }
 
@@ -281,36 +343,79 @@ static int dpdk_events_keep_alive_config(dpdk_events_ctx_t *ec,
 
 static int dpdk_events_config(oconfig_item_t *ci) {
   DPDK_EVENTS_TRACE();
-
   int ret = dpdk_events_preinit();
-  if (ret)
-    return ret;
+  if (ret) {
+    g_state |= DPDK_EVENTS_STATE_CFG_ERR;
+    return 0;
+  }
 
   dpdk_events_ctx_t *ec = DPDK_EVENTS_CTX_GET(g_hc);
 
+  /* Disabling link_status and keep_alive since <Plugin/> config section
+   * specifies if those should be enabled */
+  ec->config.keep_alive.enabled = ec->config.link_status.enabled = 0;
+  memset(&ec->config.keep_alive.lcore_mask, 0,
+         sizeof(ec->config.keep_alive.lcore_mask));
+
   for (int i = 0; i < ci->children_num; i++) {
     oconfig_item_t *child = ci->children + i;
-    if (strcasecmp("EAL", child->key) == 0) {
-      dpdk_helper_eal_config_parse(g_hc, child);
-    } else if (strcasecmp("Event", child->key) == 0) {
-      if (strcasecmp(child->values[0].value.string, "link_status") == 0) {
-        dpdk_events_link_status_config(ec, child);
-      } else if (strcasecmp(child->values[0].value.string, "keep_alive") == 0) {
-        dpdk_events_keep_alive_config(ec, child);
+
+    if (strcasecmp("EAL", child->key) == 0)
+      ret = dpdk_helper_eal_config_parse(g_hc, child);
+    else if (strcasecmp("Event", child->key) == 0) {
+      char event_type[DATA_MAX_NAME_LEN];
+
+      if (cf_util_get_string_buffer(child, event_type, sizeof(event_type)))
+        ret = -1;
+      else if (strcasecmp(event_type, "link_status") == 0) {
+        ret = dpdk_events_link_status_config(ec, child);
+        if (ret) {
+          g_state |= DPDK_EVENTS_STATE_LS_CFG_ERR;
+          continue;
+        }
+      } else if (strcasecmp(event_type, "keep_alive") == 0) {
+        ret = dpdk_events_keep_alive_config(ec, child);
+        if (ret) {
+          g_state |= DPDK_EVENTS_STATE_KA_CFG_ERR;
+          continue;
+        }
       } else {
         ERROR(DPDK_EVENTS_PLUGIN ": The selected event \"%s\" is unknown.",
-              child->values[0].value.string);
+              event_type);
+        ret = -1;
       }
+    } else {
+      ERROR(DPDK_EVENTS_PLUGIN ": unrecognized configuration option %s.",
+            child->key);
+      ret = -1;
+    }
+
+    if (ret != 0) {
+      g_state |= DPDK_EVENTS_STATE_CFG_ERR;
+      return 0;
     }
   }
 
+  if (g_state & DPDK_EVENTS_STATE_KA_CFG_ERR) {
+    ERROR(DPDK_EVENTS_PLUGIN
+          ": Invalid keep alive configuration. Event disabled.");
+    ec->config.keep_alive.enabled = 0;
+  }
+
+  if (g_state & DPDK_EVENTS_STATE_LS_CFG_ERR) {
+    ERROR(DPDK_EVENTS_PLUGIN
+          ": Invalid link status configuration. Event disabled.");
+    ec->config.link_status.enabled = 0;
+  }
+
   if (!ec->config.keep_alive.enabled && !ec->config.link_status.enabled) {
     ERROR(DPDK_EVENTS_PLUGIN ": At least one type of events should be "
                              "configured for collecting. Plugin misconfigured");
-    return -1;
+    g_state |= DPDK_EVENTS_STATE_CFG_ERR;
+    return 0;
   }
 
-  return ret;
+  return 0;
 }
 
 static int dpdk_helper_link_status_get(dpdk_helper_ctx_t *phc) {
@@ -405,17 +510,17 @@ static int dpdk_events_link_status_dispatch(dpdk_helper_ctx_t *phc) {
 
         char dev_name[DATA_MAX_NAME_LEN];
         if (ec->config.link_status.port_name[i][0] != 0) {
-          ssnprintf(dev_name, sizeof(dev_name), "%s",
-                    ec->config.link_status.port_name[i]);
+          snprintf(dev_name, sizeof(dev_name), "%s",
+                   ec->config.link_status.port_name[i]);
         } else {
-          ssnprintf(dev_name, sizeof(dev_name), "port.%d", i);
+          snprintf(dev_name, sizeof(dev_name), "port.%d", i);
         }
 
         if (ec->config.link_status.notify) {
           int sev = ec->link_info[i].link_status ? NOTIF_OKAY : NOTIF_WARNING;
           char msg[DATA_MAX_NAME_LEN];
-          ssnprintf(msg, sizeof(msg), "Link Status: %s",
-                    ec->link_info[i].link_status ? "UP" : "DOWN");
+          snprintf(msg, sizeof(msg), "Link Status: %s",
+                   ec->link_info[i].link_status ? "UP" : "DOWN");
           dpdk_events_notification_dispatch(sev, dev_name,
                                             ec->link_info[i].read_time, msg);
         } else {
@@ -451,7 +556,7 @@ static void dpdk_events_keep_alive_dispatch(dpdk_helper_ctx_t *phc) {
     }
 
     char core_name[DATA_MAX_NAME_LEN];
-    ssnprintf(core_name, sizeof(core_name), "lcore%u", i);
+    snprintf(core_name, sizeof(core_name), "lcore%u", i);
 
     if (!ec->config.keep_alive.send_updated ||
         (ec->core_info[i].lcore_state !=
@@ -466,34 +571,34 @@ static void dpdk_events_keep_alive_dispatch(dpdk_helper_ctx_t *phc) {
         switch (ec->config.keep_alive.shm->core_state[i]) {
         case RTE_KA_STATE_ALIVE:
           sev = NOTIF_OKAY;
-          ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: ALIVE", i);
+          snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: ALIVE", i);
           break;
         case RTE_KA_STATE_MISSING:
-          ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: MISSING", i);
+          snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: MISSING", i);
           sev = NOTIF_WARNING;
           break;
         case RTE_KA_STATE_DEAD:
-          ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DEAD", i);
+          snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DEAD", i);
           sev = NOTIF_FAILURE;
           break;
         case RTE_KA_STATE_UNUSED:
-          ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNUSED", i);
+          snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNUSED", i);
           sev = NOTIF_OKAY;
           break;
         case RTE_KA_STATE_GONE:
-          ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: GONE", i);
+          snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: GONE", i);
           sev = NOTIF_FAILURE;
           break;
         case RTE_KA_STATE_DOZING:
-          ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DOZING", i);
+          snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: DOZING", i);
           sev = NOTIF_OKAY;
           break;
         case RTE_KA_STATE_SLEEP:
-          ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: SLEEP", i);
+          snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: SLEEP", i);
           sev = NOTIF_OKAY;
           break;
         default:
-          ssnprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNKNOWN", i);
+          snprintf(msg, sizeof(msg), "lcore %u Keep Alive Status: UNKNOWN", i);
           sev = NOTIF_FAILURE;
         }
 
@@ -517,62 +622,76 @@ static int dpdk_events_read(user_data_t *ud) {
   }
 
   dpdk_events_ctx_t *ec = DPDK_EVENTS_CTX_GET(g_hc);
+  int ls_ret = -1, ka_ret = -1;
 
+  int cmd_res = 0;
   if (ec->config.link_status.enabled) {
-    int cmd_res = 0;
-    int ret = dpdk_helper_command(g_hc, DPDK_CMD_GET_EVENTS, &cmd_res,
-                                  ec->config.interval);
-    if (cmd_res == 0 && ret == 0) {
+    ls_ret = dpdk_helper_command(g_hc, DPDK_CMD_GET_EVENTS, &cmd_res,
+                                 ec->config.interval);
+    if (cmd_res == 0 && ls_ret == 0) {
       dpdk_events_link_status_dispatch(g_hc);
     }
   }
 
   if (ec->config.keep_alive.enabled) {
-    dpdk_events_keep_alive_dispatch(g_hc);
+    ka_ret = dpdk_event_keep_alive_shm_open();
+    if (ka_ret) {
+      ERROR(DPDK_EVENTS_PLUGIN
+            ": %s : error %d in dpdk_event_keep_alive_shm_open()",
+            __FUNCTION__, ka_ret);
+    } else
+      dpdk_events_keep_alive_dispatch(g_hc);
+  }
+
+  if (!((cmd_res || ls_ret) == 0 || ka_ret == 0)) {
+    ERROR(DPDK_EVENTS_PLUGIN ": Read failure for all enabled event types");
+    return -1;
   }
 
   return 0;
 }
 
-static int dpdk_events_init(void) {
+static int dpdk_events_shutdown(void) {
   DPDK_EVENTS_TRACE();
 
-  int ret = dpdk_events_preinit();
-  if (ret)
-    return ret;
+  if (g_hc == NULL)
+    return 0;
 
   dpdk_events_ctx_t *ec = DPDK_EVENTS_CTX_GET(g_hc);
-
   if (ec->config.keep_alive.enabled) {
-    ret = dpdk_event_keep_alive_shm_create();
-    if (ret) {
-      ERROR(DPDK_EVENTS_PLUGIN ": %s : error %d in ka_shm_create()",
-            __FUNCTION__, ret);
-      return ret;
+    if (ec->config.keep_alive.fd != -1) {
+      close(ec->config.keep_alive.fd);
+      ec->config.keep_alive.fd = -1;
+    }
+
+    if (ec->config.keep_alive.shm != MAP_FAILED) {
+      if (munmap(ec->config.keep_alive.shm, sizeof(dpdk_keepalive_shm_t))) {
+        ERROR(DPDK_EVENTS_PLUGIN ": munmap KA monitor failed");
+        return -1;
+      }
+      ec->config.keep_alive.shm = MAP_FAILED;
     }
   }
+
+  dpdk_helper_shutdown(g_hc);
+  g_hc = NULL;
+
   return 0;
 }
 
-static int dpdk_events_shutdown(void) {
+static int dpdk_events_init(void) {
   DPDK_EVENTS_TRACE();
-  int ret;
 
-  dpdk_events_ctx_t *ec = DPDK_EVENTS_CTX_GET(g_hc);
-  if (ec->config.keep_alive.enabled) {
-    ret = munmap(ec->config.keep_alive.shm, sizeof(dpdk_keepalive_shm_t));
-    if (ret) {
-      ERROR(DPDK_EVENTS_PLUGIN ": munmap KA monitor returned %d", ret);
-      return ret;
-    }
+  if (g_state & DPDK_EVENTS_STATE_CFG_ERR) {
+    dpdk_events_shutdown();
+    return -1;
   }
 
-  ret = dpdk_helper_shutdown(g_hc);
-  g_hc = NULL;
+  int ret = dpdk_events_preinit();
   if (ret)
-    ERROR(DPDK_EVENTS_PLUGIN ": failed to cleanup %s helper", DPDK_EVENTS_NAME);
+    return ret;
 
-  return ret;
+  return 0;
 }
 
 void module_register(void) {
index cc525e8..d36cb8f 100644 (file)
@@ -91,10 +91,17 @@ struct dpdk_stats_ctx_s {
 };
 typedef struct dpdk_stats_ctx_s dpdk_stats_ctx_t;
 
+typedef enum {
+  DPDK_STAT_STATE_OKAY = 0,
+  DPDK_STAT_STATE_CFG_ERR,
+} dpdk_stat_cfg_status;
+
 #define DPDK_STATS_CTX_GET(a) ((dpdk_stats_ctx_t *)dpdk_helper_priv_get(a))
 
 dpdk_helper_ctx_t *g_hc = NULL;
 static char g_shm_name[DATA_MAX_NAME_LEN] = DPDK_STATS_NAME;
+static dpdk_stat_cfg_status g_state = DPDK_STAT_STATE_OKAY;
+
 static int dpdk_stats_reinit_helper();
 static void dpdk_stats_default_config(void) {
   dpdk_stats_ctx_t *ec = DPDK_STATS_CTX_GET(g_hc);
@@ -132,30 +139,40 @@ static int dpdk_stats_config(oconfig_item_t *ci) {
   DPDK_STATS_TRACE();
 
   int ret = dpdk_stats_preinit();
-  if (ret)
-    return ret;
+  if (ret) {
+    g_state = DPDK_STAT_STATE_CFG_ERR;
+    return 0;
+  }
 
   dpdk_stats_ctx_t *ctx = DPDK_STATS_CTX_GET(g_hc);
 
   for (int i = 0; i < ci->children_num; i++) {
     oconfig_item_t *child = ci->children + i;
 
-    if ((strcasecmp("EnabledPortMask", child->key) == 0) &&
-        (child->values[0].type == OCONFIG_TYPE_NUMBER)) {
-      ctx->config.enabled_port_mask = child->values[0].value.number;
-      DEBUG("%s: Enabled Port Mask 0x%X", DPDK_STATS_PLUGIN,
-            ctx->config.enabled_port_mask);
-    } else if (strcasecmp("SharedMemObj", child->key) == 0) {
-      cf_util_get_string_buffer(child, g_shm_name, sizeof(g_shm_name));
-      DEBUG("%s: Shared memory object %s", DPDK_STATS_PLUGIN, g_shm_name);
-      dpdk_stats_reinit_helper();
-    } else if (strcasecmp("EAL", child->key) == 0) {
+    if (strcasecmp("EnabledPortMask", child->key) == 0)
+      ret = cf_util_get_int(child, (int *)&ctx->config.enabled_port_mask);
+    else if (strcasecmp("SharedMemObj", child->key) == 0) {
+      ret = cf_util_get_string_buffer(child, g_shm_name, sizeof(g_shm_name));
+      if (ret == 0)
+        ret = dpdk_stats_reinit_helper();
+    } else if (strcasecmp("EAL", child->key) == 0)
       ret = dpdk_helper_eal_config_parse(g_hc, child);
-      if (ret)
-        return ret;
+    else if (strcasecmp("PortName", child->key) != 0) {
+      ERROR(DPDK_STATS_PLUGIN ": unrecognized configuration option %s",
+            child->key);
+      ret = -1;
+    }
+
+    if (ret != 0) {
+      g_state = DPDK_STAT_STATE_CFG_ERR;
+      return 0;
     }
   }
 
+  DEBUG(DPDK_STATS_PLUGIN ": Enabled Port Mask 0x%X",
+        ctx->config.enabled_port_mask);
+  DEBUG(DPDK_STATS_PLUGIN ": Shared memory object %s", g_shm_name);
+
   int port_num = 0;
 
   /* parse port names after EnabledPortMask was parsed */
@@ -167,16 +184,20 @@ static int dpdk_stats_config(oconfig_item_t *ci) {
       while (!(ctx->config.enabled_port_mask & (1 << port_num)))
         port_num++;
 
-      cf_util_get_string_buffer(child, ctx->config.port_name[port_num],
-                                sizeof(ctx->config.port_name[port_num]));
-      DEBUG("%s: Port %d Name: %s", DPDK_STATS_PLUGIN, port_num,
+      if (cf_util_get_string_buffer(child, ctx->config.port_name[port_num],
+                                    sizeof(ctx->config.port_name[port_num]))) {
+        g_state = DPDK_STAT_STATE_CFG_ERR;
+        return 0;
+      }
+
+      DEBUG(DPDK_STATS_PLUGIN ": Port %d Name: %s", port_num,
             ctx->config.port_name[port_num]);
 
       port_num++;
     }
   }
 
-  return ret;
+  return 0;
 }
 
 static int dpdk_helper_stats_get(dpdk_helper_ctx_t *phc) {
@@ -376,9 +397,9 @@ static int dpdk_stats_counters_dispatch(dpdk_helper_ctx_t *phc) {
 
     char dev_name[64];
     if (ctx->config.port_name[i][0] != 0) {
-      ssnprintf(dev_name, sizeof(dev_name), "%s", ctx->config.port_name[i]);
+      snprintf(dev_name, sizeof(dev_name), "%s", ctx->config.port_name[i]);
     } else {
-      ssnprintf(dev_name, sizeof(dev_name), "port.%d", i);
+      snprintf(dev_name, sizeof(dev_name), "port.%d", i);
     }
 
     DEBUG(" === Dispatch stats for port %d (name=%s; stats_count=%d)", i,
@@ -470,31 +491,30 @@ static int dpdk_stats_read(user_data_t *ud) {
   return 0;
 }
 
-static int dpdk_stats_init(void) {
+static int dpdk_stats_shutdown(void) {
   DPDK_STATS_TRACE();
-  int ret = 0;
 
-  ret = dpdk_stats_preinit();
-  if (ret != 0) {
-    return ret;
-  }
+  dpdk_helper_shutdown(g_hc);
+  g_hc = NULL;
 
   return 0;
 }
 
-static int dpdk_stats_shutdown(void) {
+static int dpdk_stats_init(void) {
   DPDK_STATS_TRACE();
-
   int ret = 0;
 
-  ret = dpdk_helper_shutdown(g_hc);
-  g_hc = NULL;
+  if (g_state != DPDK_STAT_STATE_OKAY) {
+    dpdk_stats_shutdown();
+    return -1;
+  }
+
+  ret = dpdk_stats_preinit();
   if (ret != 0) {
-    ERROR("%s: failed to cleanup %s helper", DPDK_STATS_PLUGIN, g_shm_name);
     return ret;
   }
 
-  return ret;
+  return 0;
 }
 
 void module_register(void) {
index 97a4f03..5a0eac3 100644 (file)
@@ -77,7 +77,7 @@ static int drbd_submit_fields(long int resource, char **fields,
     return EINVAL;
   }
 
-  ssnprintf(plugin_instance, sizeof(plugin_instance), "r%ld", resource);
+  snprintf(plugin_instance, sizeof(plugin_instance), "r%ld", resource);
 
   for (size_t i = 0; i < drbd_names_num; i++) {
     char *data;
index 3d12a2d..22da316 100644 (file)
@@ -187,8 +187,7 @@ static int exec_config_exec(oconfig_item_t *ci) /* {{{ */
       pl->argv[i] = strdup(ci->values[i + 1].value.string);
     } else {
       if (ci->values[i + 1].type == OCONFIG_TYPE_NUMBER) {
-        ssnprintf(buffer, sizeof(buffer), "%lf",
-                  ci->values[i + 1].value.number);
+        snprintf(buffer, sizeof(buffer), "%lf", ci->values[i + 1].value.number);
       } else {
         if (ci->values[i + 1].value.boolean)
           sstrncpy(buffer, "true", sizeof(buffer));
@@ -246,18 +245,18 @@ static void set_environment(void) /* {{{ */
   char buffer[1024];
 
 #ifdef HAVE_SETENV
-  ssnprintf(buffer, sizeof(buffer), "%.3f",
-            CDTIME_T_TO_DOUBLE(plugin_get_interval()));
+  snprintf(buffer, sizeof(buffer), "%.3f",
+           CDTIME_T_TO_DOUBLE(plugin_get_interval()));
   setenv("COLLECTD_INTERVAL", buffer, /* overwrite = */ 1);
 
   sstrncpy(buffer, hostname_g, sizeof(buffer));
   setenv("COLLECTD_HOSTNAME", buffer, /* overwrite = */ 1);
 #else
-  ssnprintf(buffer, sizeof(buffer), "COLLECTD_INTERVAL=%.3f",
-            CDTIME_T_TO_DOUBLE(plugin_get_interval()));
+  snprintf(buffer, sizeof(buffer), "COLLECTD_INTERVAL=%.3f",
+           CDTIME_T_TO_DOUBLE(plugin_get_interval()));
   putenv(buffer);
 
-  ssnprintf(buffer, sizeof(buffer), "COLLECTD_HOSTNAME=%s", hostname_g);
+  snprintf(buffer, sizeof(buffer), "COLLECTD_HOSTNAME=%s", hostname_g);
   putenv(buffer);
 #endif
 } /* }}} void set_environment */
index 7eb5104..a2ec8e8 100644 (file)
@@ -419,7 +419,7 @@ static int fc_read_dir_callback(const char *dirname, const char *filename,
   if (dir == NULL)
     return -1;
 
-  ssnprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, filename);
+  snprintf(abs_path, sizeof(abs_path), "%s/%s", dirname, filename);
 
   status = lstat(abs_path, &statbuf);
   if (status != 0) {
index c680427..50bd832 100644 (file)
@@ -417,8 +417,8 @@ static staging_entry_t *staging_entry_get(const char *host, /* {{{ */
   if (staging_tree == NULL)
     return NULL;
 
-  ssnprintf(key, sizeof(key), "%s/%s/%s", host, type,
-            (type_instance != NULL) ? type_instance : "");
+  snprintf(key, sizeof(key), "%s/%s/%s", host, type,
+           (type_instance != NULL) ? type_instance : "");
 
   se = NULL;
   status = c_avl_get(staging_tree, key, (void *)&se);
index 3af9c0f..a7eaf36 100644 (file)
@@ -214,7 +214,7 @@ static int hddtemp_config(const char *key, const char *value) {
   } else if (strcasecmp(key, "Port") == 0) {
     int port = (int)(atof(value));
     if ((port > 0) && (port <= 65535))
-      ssnprintf(hddtemp_port, sizeof(hddtemp_port), "%i", port);
+      snprintf(hddtemp_port, sizeof(hddtemp_port), "%i", port);
     else
       sstrncpy(hddtemp_port, value, sizeof(hddtemp_port));
   } else {
index 871e625..c5b0ecb 100644 (file)
@@ -87,11 +87,11 @@ static void submit_hp(const struct entry_info *info) {
 
   sstrncpy(vl.plugin, g_plugin_name, sizeof(vl.plugin));
   if (info->node) {
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%zuKb",
-              info->node, info->page_size_kb);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%zuKb",
+             info->node, info->page_size_kb);
   } else {
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%zuKb",
-              info->page_size_kb);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%zuKb",
+             info->page_size_kb);
   }
 
   /* ensure all metrics have the same timestamp */
@@ -125,7 +125,7 @@ static int read_hugepage_entry(const char *path, const char *entry,
   struct entry_info *info = e_info;
   double value;
 
-  ssnprintf(path2, sizeof(path2), "%s/%s", path, entry);
+  snprintf(path2, sizeof(path2), "%s/%s", path, entry);
 
   FILE *fh = fopen(path2, "rt");
   if (fh == NULL) {
@@ -193,7 +193,7 @@ static int read_syshugepages(const char *path, const char *node) {
     }
 
     /* /sys/devices/system/node/node?/hugepages/ */
-    ssnprintf(path2, sizeof(path2), "%s/%s", path, result->d_name);
+    snprintf(path2, sizeof(path2), "%s/%s", path, result->d_name);
 
     walk_directory(path2, read_hugepage_entry,
                    &(struct entry_info){
@@ -238,7 +238,7 @@ static int read_nodes(void) {
       continue;
     }
 
-    ssnprintf(path, sizeof(path), sys_node_hugepages, result->d_name);
+    snprintf(path, sizeof(path), sys_node_hugepages, result->d_name);
     read_syshugepages(path, result->d_name);
     errno = 0;
   }
index 7966daa..a3f77c9 100644 (file)
@@ -375,7 +375,7 @@ static int rdt_default_cgroups(void) {
     char desc[DATA_MAX_NAME_LEN];
     uint64_t core = i;
 
-    ssnprintf(desc, sizeof(desc), "%d", g_rdt->pqos_cpu->cores[i].lcore);
+    snprintf(desc, sizeof(desc), "%d", g_rdt->pqos_cpu->cores[i].lcore);
 
     /* set core group info */
     ret = cgroup_set(&g_rdt->cgroups[i], desc, &core, 1);
@@ -656,7 +656,7 @@ static int rdt_read(__attribute__((unused)) user_data_t *ud) {
 static int rdt_init(void) {
   int ret;
 
-  if(g_state == CONFIGURATION_ERROR)
+  if (g_state == CONFIGURATION_ERROR)
     return -1;
 
   ret = rdt_preinit();
index 78a0d69..deba186 100644 (file)
@@ -296,8 +296,8 @@ static int interface_read(void) {
       continue;
 
     if (unique_name)
-      ssnprintf(iname, sizeof(iname), "%s_%d_%s", ksp[i]->ks_module,
-                ksp[i]->ks_instance, ksp[i]->ks_name);
+      snprintf(iname, sizeof(iname), "%s_%d_%s", ksp[i]->ks_module,
+               ksp[i]->ks_instance, ksp[i]->ks_name);
     else
       sstrncpy(iname, ksp[i]->ks_name, sizeof(iname));
 
index 432c5e0..ed8a0c0 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -251,14 +251,14 @@ static int ipc_read_shm(void) /* {{{ */
   ipcinfo_shm_t *pshm;
   unsigned int shm_segments = 0;
   size64_t shm_bytes = 0;
-  int n;
+  int i, n;
 
   ipcinfo_shm = (ipcinfo_shm_t *)ipc_get_info(
       0, GET_IPCINFO_SHM_ALL, IPCINFO_SHM_VERSION, sizeof(ipcinfo_shm_t), &n);
   if (ipcinfo_shm == NULL)
     return -1;
 
-  for (int i = 0, pshm = ipcinfo_shm; i < n; i++, pshm++) {
+  for (i = 0, pshm = ipcinfo_shm; i < n; i++, pshm++) {
     shm_segments++;
     shm_bytes += pshm->shm_segsz;
   }
index 98e77bf..c8c8042 100644 (file)
@@ -83,7 +83,7 @@ static void c_ipmi_error(const char *func, int status) {
   }
 
   if (errbuf[0] == 0) {
-    ssnprintf(errbuf, sizeof(errbuf), "Unknown error %#x", status);
+    snprintf(errbuf, sizeof(errbuf), "Unknown error %#x", status);
   }
   errbuf[sizeof(errbuf) - 1] = 0;
 
@@ -123,8 +123,8 @@ static void sensor_read_handler(ipmi_sensor_t *sensor, int err,
           sstrncpy(n.type_instance, list_item->sensor_name,
                    sizeof(n.type_instance));
           sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
-          ssnprintf(n.message, sizeof(n.message), "sensor %s not present",
-                    list_item->sensor_name);
+          snprintf(n.message, sizeof(n.message), "sensor %s not present",
+                   list_item->sensor_name);
 
           plugin_dispatch_notification(&n);
         }
@@ -172,8 +172,8 @@ static void sensor_read_handler(ipmi_sensor_t *sensor, int err,
       sstrncpy(n.type_instance, list_item->sensor_name,
                sizeof(n.type_instance));
       sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
-      ssnprintf(n.message, sizeof(n.message), "sensor %s present",
-                list_item->sensor_name);
+      snprintf(n.message, sizeof(n.message), "sensor %s present",
+               list_item->sensor_name);
 
       plugin_dispatch_notification(&n);
     }
@@ -223,8 +223,8 @@ static int sensor_list_add(ipmi_sensor_t *sensor) {
   if (entity_id_string == NULL)
     sstrncpy(sensor_name, buffer, sizeof(sensor_name));
   else
-    ssnprintf(sensor_name, sizeof(sensor_name), "%s %s", buffer,
-              entity_id_string);
+    snprintf(sensor_name, sizeof(sensor_name), "%s %s", buffer,
+             entity_id_string);
 
   sstrncpy(buffer, sensor_name, sizeof(buffer));
   sensor_name_ptr = strstr(buffer, ").");
@@ -244,8 +244,8 @@ static int sensor_list_add(ipmi_sensor_t *sensor) {
     sensor_id_ptr = strstr(buffer, "(");
     if (sensor_id_ptr != NULL) {
       /* `sensor_id_ptr' now points to "(123)". */
-      ssnprintf(sensor_name, sizeof(sensor_name), "%s %s", sensor_name_ptr,
-                sensor_id_ptr);
+      snprintf(sensor_name, sizeof(sensor_name), "%s %s", sensor_name_ptr,
+               sensor_id_ptr);
     }
     /* else: don't touch sensor_name. */
   }
@@ -327,8 +327,8 @@ static int sensor_list_add(ipmi_sensor_t *sensor) {
     sstrncpy(n.host, hostname_g, sizeof(n.host));
     sstrncpy(n.type_instance, list_item->sensor_name, sizeof(n.type_instance));
     sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
-    ssnprintf(n.message, sizeof(n.message), "sensor %s added",
-              list_item->sensor_name);
+    snprintf(n.message, sizeof(n.message), "sensor %s added",
+             list_item->sensor_name);
 
     plugin_dispatch_notification(&n);
   }
@@ -375,8 +375,8 @@ static int sensor_list_remove(ipmi_sensor_t *sensor) {
     sstrncpy(n.host, hostname_g, sizeof(n.host));
     sstrncpy(n.type_instance, list_item->sensor_name, sizeof(n.type_instance));
     sstrncpy(n.type, list_item->sensor_type, sizeof(n.type));
-    ssnprintf(n.message, sizeof(n.message), "sensor %s removed",
-              list_item->sensor_name);
+    snprintf(n.message, sizeof(n.message), "sensor %s removed",
+             list_item->sensor_name);
 
     plugin_dispatch_notification(&n);
   }
index 1d127bf..286c6e9 100644 (file)
@@ -101,7 +101,7 @@ static int iptables_config(const char *key, const char *value) {
     return 1;
 
   ip_chain_t temp = {0};
-  ip_chain_t * final, **list;
+  ip_chain_t *final, **list;
   char *table;
   int table_len;
   char *chain;
@@ -189,7 +189,7 @@ static int iptables_config(const char *key, const char *value) {
   }
 
   chain_list = list;
-  final = malloc(sizeof(* final));
+  final = malloc(sizeof(*final));
   if (final == NULL) {
     char errbuf[1024];
     ERROR("malloc failed: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
@@ -226,8 +226,8 @@ static int submit6_match(const struct ip6t_entry_match *match,
 
   sstrncpy(vl.plugin, "ip6tables", sizeof(vl.plugin));
 
-  status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
-                     chain->table, chain->chain);
+  status = snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
+                    chain->table, chain->chain);
   if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance)))
     return 0;
 
@@ -235,8 +235,8 @@ static int submit6_match(const struct ip6t_entry_match *match,
     sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance));
   } else {
     if (chain->rule_type == RTYPE_NUM)
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%i",
-                chain->rule.num);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%i",
+               chain->rule.num);
     else
       sstrncpy(vl.type_instance, (char *)match->data, sizeof(vl.type_instance));
   }
@@ -274,8 +274,8 @@ static int submit_match(const struct ipt_entry_match *match,
 
   sstrncpy(vl.plugin, "iptables", sizeof(vl.plugin));
 
-  status = ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
-                     chain->table, chain->chain);
+  status = snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
+                    chain->table, chain->chain);
   if ((status < 1) || ((unsigned int)status >= sizeof(vl.plugin_instance)))
     return 0;
 
@@ -283,8 +283,8 @@ static int submit_match(const struct ipt_entry_match *match,
     sstrncpy(vl.type_instance, chain->name, sizeof(vl.type_instance));
   } else {
     if (chain->rule_type == RTYPE_NUM)
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%i",
-                chain->rule.num);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%i",
+               chain->rule.num);
     else
       sstrncpy(vl.type_instance, (char *)match->data, sizeof(vl.type_instance));
   }
index da67970..3d399bd 100644 (file)
@@ -172,8 +172,8 @@ static int get_pi(struct ip_vs_service_entry *se, char *pi, size_t size) {
   struct in_addr addr = {.s_addr = se->addr};
 
   int len =
-      ssnprintf(pi, size, "%s_%s%u", inet_ntoa(addr),
-                (se->protocol == IPPROTO_TCP) ? "TCP" : "UDP", ntohs(se->port));
+      snprintf(pi, size, "%s_%s%u", inet_ntoa(addr),
+               (se->protocol == IPPROTO_TCP) ? "TCP" : "UDP", ntohs(se->port));
 
   if ((len < 0) || (size <= ((size_t)len))) {
     log_err("plugin instance truncated: %s", pi);
@@ -189,7 +189,7 @@ static int get_ti(struct ip_vs_dest_entry *de, char *ti, size_t size) {
 
   struct in_addr addr = {.s_addr = de->addr};
 
-  int len = ssnprintf(ti, size, "%s_%u", inet_ntoa(addr), ntohs(de->port));
+  int len = snprintf(ti, size, "%s_%u", inet_ntoa(addr), ntohs(de->port));
 
   if ((len < 0) || (size <= ((size_t)len))) {
     log_err("type instance truncated: %s", ti);
index e3d3442..c7b0be3 100644 (file)
@@ -1213,9 +1213,9 @@ static int jtoc_notification(JNIEnv *jvm_env, notification_t *n, /* {{{ */
 
   return 0;
 } /* }}} int jtoc_notification */
-  /*
  * Functions accessible from Java
  */
+/*
+ * Functions accessible from Java
+ */
 static jint JNICALL cjni_api_dispatch_values(JNIEnv *jvm_env, /* {{{ */
                                              jobject this, jobject java_vl) {
   value_list_t vl = VALUE_LIST_INIT;
index c3cd414..3ae2e71 100644 (file)
@@ -92,7 +92,6 @@
 #define LCC_SET_ERRSTR(c, ...)                                                 \
   do {                                                                         \
     snprintf((c)->errbuf, sizeof((c)->errbuf), __VA_ARGS__);                   \
-    (c)->errbuf[sizeof((c)->errbuf) - 1] = 0;                                  \
   } while (0)
 
 /*
  */
 struct lcc_connection_s {
   FILE *fh;
-  char errbuf[1024];
+  char errbuf[2048];
 };
 
 struct lcc_response_s {
index e5807f1..de9b1f7 100644 (file)
@@ -163,7 +163,7 @@ static int logfile_notification(const notification_t *n,
   int buf_len = sizeof(buf);
   int status;
 
-  status = ssnprintf(
+  status = snprintf(
       buf_ptr, buf_len, "Notification: severity = %s",
       (n->severity == NOTIF_FAILURE)
           ? "FAILURE"
@@ -177,7 +177,7 @@ static int logfile_notification(const notification_t *n,
 
 #define APPEND(bufptr, buflen, key, value)                                     \
   if ((buflen > 0) && (strlen(value) > 0)) {                                   \
-    status = ssnprintf(bufptr, buflen, ", %s = %s", key, value);               \
+    status = snprintf(bufptr, buflen, ", %s = %s", key, value);                \
     if (status > 0) {                                                          \
       bufptr += status;                                                        \
       buflen -= status;                                                        \
index a0dde32..3ecf049 100644 (file)
@@ -226,10 +226,10 @@ static int lpar_read(void) {
     if (pool_busy_cpus < 0.0)
       pool_busy_cpus = 0.0;
 
-    ssnprintf(typinst, sizeof(typinst), "pool-%X-busy", lparstats.pool_id);
+    snprintf(typinst, sizeof(typinst), "pool-%X-busy", lparstats.pool_id);
     lpar_submit(typinst, pool_busy_cpus);
 
-    ssnprintf(typinst, sizeof(typinst), "pool-%X-idle", lparstats.pool_id);
+    snprintf(typinst, sizeof(typinst), "pool-%X-idle", lparstats.pool_id);
     lpar_submit(typinst, pool_idle_cpus);
   }
 
index aeaeff2..8cfb704 100644 (file)
--- a/src/lua.c
+++ b/src/lua.c
@@ -282,7 +282,7 @@ static int lua_cb_register_read(lua_State *L) /* {{{ */
   luaL_checktype(L, 1, LUA_TFUNCTION);
 
   char function_name[DATA_MAX_NAME_LEN];
-  ssnprintf(function_name, sizeof(function_name), "lua/%s", lua_tostring(L, 1));
+  snprintf(function_name, sizeof(function_name), "lua/%s", lua_tostring(L, 1));
 
   int callback_id = clua_store_callback(L, 1);
   if (callback_id < 0)
@@ -306,9 +306,10 @@ static int lua_cb_register_read(lua_State *L) /* {{{ */
   int status = plugin_register_complex_read(/* group = */ "lua",
                                             /* name      = */ function_name,
                                             /* callback  = */ clua_read,
-                                            /* interval  = */ 0, &(user_data_t){
-                                                                     .data = cb,
-                                                                 });
+                                            /* interval  = */ 0,
+                                            &(user_data_t){
+                                                .data = cb,
+                                            });
 
   if (status != 0)
     return luaL_error(L, "%s", "plugin_register_complex_read failed");
@@ -325,7 +326,7 @@ static int lua_cb_register_write(lua_State *L) /* {{{ */
   luaL_checktype(L, 1, LUA_TFUNCTION);
 
   char function_name[DATA_MAX_NAME_LEN] = "";
-  ssnprintf(function_name, sizeof(function_name), "lua/%s", lua_tostring(L, 1));
+  snprintf(function_name, sizeof(function_name), "lua/%s", lua_tostring(L, 1));
 
   int callback_id = clua_store_callback(L, 1);
   if (callback_id < 0)
@@ -346,11 +347,11 @@ static int lua_cb_register_write(lua_State *L) /* {{{ */
   cb->lua_function_name = strdup(function_name);
   pthread_mutex_init(&cb->lock, NULL);
 
-  int status =
-      plugin_register_write(/* name = */ function_name,
-                            /* callback  = */ clua_write, &(user_data_t){
-                                                              .data = cb,
-                                                          });
+  int status = plugin_register_write(/* name = */ function_name,
+                                     /* callback  = */ clua_write,
+                                     &(user_data_t){
+                                         .data = cb,
+                                     });
 
   if (status != 0)
     return luaL_error(L, "%s", "plugin_register_write failed");
@@ -533,7 +534,7 @@ static int lua_config_script(const oconfig_item_t *ci) /* {{{ */
   if (base_path[0] == '\0')
     sstrncpy(abs_path, rel_path, sizeof(abs_path));
   else
-    ssnprintf(abs_path, sizeof(abs_path), "%s/%s", base_path, rel_path);
+    snprintf(abs_path, sizeof(abs_path), "%s/%s", base_path, rel_path);
 
   DEBUG("Lua plugin: abs_path = \"%s\";", abs_path);
 
index c3214b0..6310727 100644 (file)
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -77,8 +77,7 @@ static void report_lv_utilization(lv_t lv, char const *vg_name,
     return;
   used_bytes = lv_size * (used_percent_unscaled * PERCENT_SCALE_FACTOR);
 
-  ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-%s", vg_name,
-            lv_name);
+  snprintf(plugin_instance, sizeof(plugin_instance), "%s-%s", vg_name, lv_name);
   lvm_submit(plugin_instance, "used", used_bytes);
   lvm_submit(plugin_instance, "free", lv_size - used_bytes);
 }
index 5a915b6..1a387b7 100644 (file)
@@ -519,7 +519,7 @@ static void submit(const char *dev, const char *type, const char *ti1,
   sstrncpy(vl.type, type, sizeof(vl.type));
 
   if ((ti1 != NULL) && (ti2 != NULL))
-    ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s", ti1, ti2);
+    snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s", ti1, ti2);
   else if ((ti1 != NULL) && (ti2 == NULL))
     sstrncpy(vl.type_instance, ti1, sizeof(vl.type_instance));
 
@@ -553,15 +553,15 @@ static void submit_antx(const char *dev, const char *name, u_int32_t *vals,
     if (vals[i] == 0)
       continue;
 
-    ssnprintf(ti2, sizeof(ti2), "%i", i);
+    snprintf(ti2, sizeof(ti2), "%i", i);
     submit_derive(dev, "ath_stat", name, ti2, (derive_t)vals[i]);
   }
 }
 
 static inline void macaddr_to_str(char *buf, size_t bufsize,
                                   const uint8_t mac[IEEE80211_ADDR_LEN]) {
-  ssnprintf(buf, bufsize, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1],
-            mac[2], mac[3], mac[4], mac[5]);
+  snprintf(buf, bufsize, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1],
+           mac[2], mac[3], mac[4], mac[5]);
 }
 
 static void process_stat_struct(int which, const void *ptr, const char *dev,
@@ -753,7 +753,7 @@ static int check_devname(const char *dev) {
   if (dev[0] == '.')
     return 0;
 
-  ssnprintf(buf, sizeof(buf), "/sys/class/net/%s/device/driver", dev);
+  snprintf(buf, sizeof(buf), "/sys/class/net/%s/device/driver", dev);
   buf[sizeof(buf) - 1] = '\0';
 
   i = readlink(buf, buf2, sizeof(buf2) - 1);
index 6b45f6c..dd4018b 100644 (file)
@@ -224,7 +224,7 @@ static int mr_config_add_meta_regex(llist_t **meta, /* {{{ */
     llist_append(*meta, entry);
   }
 
-  ssnprintf(buffer, sizeof(buffer), "%s `%s'", ci->key, meta_key);
+  snprintf(buffer, sizeof(buffer), "%s `%s'", ci->key, meta_key);
   /* Can't pass &entry->value into mr_add_regex, so copy in/out. */
   re_head = entry->value;
   status = mr_add_regex(&re_head, ci->values[1].value.string, buffer);
index fad18d5..b8731c7 100644 (file)
@@ -291,15 +291,15 @@ static int mcelog_submit(const mcelog_memory_rec_t *mr) {
       .type_instance = "corrected_memory_errors"};
 
   if (mr->dimm_name[0] != '\0')
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s_%s",
-              mr->location, mr->dimm_name);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s_%s",
+             mr->location, mr->dimm_name);
   else
     sstrncpy(vl.plugin_instance, mr->location, sizeof(vl.plugin_instance));
 
   plugin_dispatch_values(&vl);
 
-  ssnprintf(vl.type_instance, sizeof(vl.type_instance),
-            "corrected_memory_errors_in_%s", mr->corrected_err_timed_period);
+  snprintf(vl.type_instance, sizeof(vl.type_instance),
+           "corrected_memory_errors_in_%s", mr->corrected_err_timed_period);
   vl.values = &(value_t){.derive = (derive_t)mr->corrected_err_timed};
   plugin_dispatch_values(&vl);
 
@@ -308,9 +308,8 @@ static int mcelog_submit(const mcelog_memory_rec_t *mr) {
   vl.values = &(value_t){.derive = (derive_t)mr->uncorrected_err_total};
   plugin_dispatch_values(&vl);
 
-  ssnprintf(vl.type_instance, sizeof(vl.type_instance),
-            "uncorrected_memory_errors_in_%s",
-            mr->uncorrected_err_timed_period);
+  snprintf(vl.type_instance, sizeof(vl.type_instance),
+           "uncorrected_memory_errors_in_%s", mr->uncorrected_err_timed_period);
   vl.values = &(value_t){.derive = (derive_t)mr->uncorrected_err_timed};
   plugin_dispatch_values(&vl);
 
index 98cef1d..016e6b0 100644 (file)
--- a/src/md.c
+++ b/src/md.c
@@ -66,7 +66,7 @@ static void md_submit(const int minor, const char *type_instance,
   vl.values = &(value_t){.gauge = value};
   vl.values_len = 1;
   sstrncpy(vl.plugin, "md", sizeof(vl.plugin));
-  ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", minor);
+  snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", minor);
   sstrncpy(vl.type, "md_disks", sizeof(vl.type));
   sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
 
@@ -180,7 +180,7 @@ static int md_read(void) {
      * major/minor, but that again can be tricky if the filesystem
      * with the device file is mounted using the "nodev" option.
      */
-    ssnprintf(path, sizeof(path), "%s/%s", DEV_DIR, name);
+    snprintf(path, sizeof(path), "%s/%s", DEV_DIR, name);
 
     md_process(minor, path);
   }
index 5fc17df..e4ccbce 100644 (file)
@@ -477,8 +477,8 @@ static int memcached_add_read_callback(memcached_t *st) {
   char callback_name[3 * DATA_MAX_NAME_LEN];
   int status;
 
-  ssnprintf(callback_name, sizeof(callback_name), "memcached/%s",
-            (st->name != NULL) ? st->name : "__legacy__");
+  snprintf(callback_name, sizeof(callback_name), "memcached/%s",
+           (st->name != NULL) ? st->name : "__legacy__");
 
   /* If no <Address> used then:
    * - Connect to the destination specified by <Host>, if present.
@@ -520,9 +520,10 @@ static int memcached_add_read_callback(memcached_t *st) {
       /* group = */ "memcached",
       /* name      = */ callback_name,
       /* callback  = */ memcached_read,
-      /* interval  = */ 0, &(user_data_t){
-                               .data = st, .free_func = memcached_free,
-                           });
+      /* interval  = */ 0,
+      &(user_data_t){
+          .data = st, .free_func = memcached_free,
+      });
 
   return status;
 } /* int memcached_add_read_callback */
index 90a6178..a7ee433 100644 (file)
--- a/src/mic.c
+++ b/src/mic.c
@@ -132,7 +132,7 @@ static void mic_submit_memory_use(int micnumber, const char *type_instance,
   vl.values_len = 1;
 
   strncpy(vl.plugin, "mic", sizeof(vl.plugin));
-  ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber);
+  snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber);
   strncpy(vl.type, "memory", sizeof(vl.type));
   strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
 
@@ -165,7 +165,7 @@ static void mic_submit_temp(int micnumber, const char *type, gauge_t value) {
 
   strncpy(vl.host, hostname_g, sizeof(vl.host));
   strncpy(vl.plugin, "mic", sizeof(vl.plugin));
-  ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber);
+  snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber);
   strncpy(vl.type, "temperature", sizeof(vl.type));
   strncpy(vl.type_instance, type, sizeof(vl.type_instance));
 
@@ -208,10 +208,10 @@ static void mic_submit_cpu(int micnumber, const char *type_instance, int core,
   strncpy(vl.host, hostname_g, sizeof(vl.host));
   strncpy(vl.plugin, "mic", sizeof(vl.plugin));
   if (core < 0) /* global aggregation */
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber);
   else /* per-core statistics */
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i-cpu-%i",
-              micnumber, core);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i-cpu-%i",
+             micnumber, core);
   strncpy(vl.type, "cpu", sizeof(vl.type));
   strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
 
@@ -261,7 +261,7 @@ static void mic_submit_power(int micnumber, const char *type,
 
   strncpy(vl.host, hostname_g, sizeof(vl.host));
   strncpy(vl.plugin, "mic", sizeof(vl.plugin));
-  ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber);
+  snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", micnumber);
   strncpy(vl.type, type, sizeof(vl.type));
   strncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
 
index f45fe21..715724d 100644 (file)
@@ -248,7 +248,7 @@ static int mb_submit(mb_host_t *host, mb_slave_t *slave, /* {{{ */
     host->interval = plugin_get_interval();
 
   if (slave->instance[0] == 0)
-    ssnprintf(slave->instance, sizeof(slave->instance), "slave_%i", slave->id);
+    snprintf(slave->instance, sizeof(slave->instance), "slave_%i", slave->id);
 
   vl.values = &value;
   vl.values_len = 1;
@@ -934,7 +934,7 @@ static int mb_config_add_host(oconfig_item_t *ci) /* {{{ */
   if (status == 0) {
     char name[1024];
 
-    ssnprintf(name, sizeof(name), "modbus-%s", host->host);
+    snprintf(name, sizeof(name), "modbus-%s", host->host);
 
     plugin_register_complex_read(/* group = */ NULL, name,
                                  /* callback = */ mb_read,
index 36e6577..851866b 100644 (file)
@@ -471,12 +471,12 @@ static int format_topic(char *buf, size_t buf_len, data_set_t const *ds,
   if (status != 0)
     return status;
 
-  status = ssnprintf(buf, buf_len, "%s/%s", conf->topic_prefix, name);
+  status = snprintf(buf, buf_len, "%s/%s", conf->topic_prefix, name);
   if ((status < 0) || (((size_t)status) >= buf_len))
     return ENOMEM;
 
-  while((c = strchr(buf, '#')) || (c = strchr(buf, '+'))) {
-       *c = '_';
+  while ((c = strchr(buf, '#')) || (c = strchr(buf, '+'))) {
+    *c = '_';
   }
 
   return 0;
@@ -608,10 +608,11 @@ static int mqtt_config_publisher(oconfig_item_t *ci) {
       ERROR("mqtt plugin: Unknown config option: %s", child->key);
   }
 
-  ssnprintf(cb_name, sizeof(cb_name), "mqtt/%s", conf->name);
-  plugin_register_write(cb_name, mqtt_write, &(user_data_t){
-                                                 .data = conf,
-                                             });
+  snprintf(cb_name, sizeof(cb_name), "mqtt/%s", conf->name);
+  plugin_register_write(cb_name, mqtt_write,
+                        &(user_data_t){
+                            .data = conf,
+                        });
   return 0;
 } /* mqtt_config_publisher */
 
index b6edce0..7fe6d76 100644 (file)
@@ -218,7 +218,7 @@ static int mysql_config_database(oconfig_item_t *ci) /* {{{ */
           (db->database != NULL) ? db->database : "<default>");
 
     if (db->instance != NULL)
-      ssnprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance);
+      snprintf(cb_name, sizeof(cb_name), "mysql-%s", db->instance);
     else
       sstrncpy(cb_name, "mysql", sizeof(cb_name));
 
@@ -496,15 +496,15 @@ static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) {
     if (((io == NULL) || (strcasecmp(io, "yes") != 0)) &&
         (db->slave_io_running)) {
       n.severity = NOTIF_WARNING;
-      ssnprintf(n.message, sizeof(n.message),
-                "slave I/O thread not started or not connected to master");
+      snprintf(n.message, sizeof(n.message),
+               "slave I/O thread not started or not connected to master");
       plugin_dispatch_notification(&n);
       db->slave_io_running = 0;
     } else if (((io != NULL) && (strcasecmp(io, "yes") == 0)) &&
                (!db->slave_io_running)) {
       n.severity = NOTIF_OKAY;
-      ssnprintf(n.message, sizeof(n.message),
-                "slave I/O thread started and connected to master");
+      snprintf(n.message, sizeof(n.message),
+               "slave I/O thread started and connected to master");
       plugin_dispatch_notification(&n);
       db->slave_io_running = 1;
     }
@@ -512,13 +512,13 @@ static int mysql_read_slave_stats(mysql_database_t *db, MYSQL *con) {
     if (((sql == NULL) || (strcasecmp(sql, "yes") != 0)) &&
         (db->slave_sql_running)) {
       n.severity = NOTIF_WARNING;
-      ssnprintf(n.message, sizeof(n.message), "slave SQL thread not started");
+      snprintf(n.message, sizeof(n.message), "slave SQL thread not started");
       plugin_dispatch_notification(&n);
       db->slave_sql_running = 0;
     } else if (((sql != NULL) && (strcasecmp(sql, "yes") == 0)) &&
                (!db->slave_sql_running)) {
       n.severity = NOTIF_OKAY;
-      ssnprintf(n.message, sizeof(n.message), "slave SQL thread started");
+      snprintf(n.message, sizeof(n.message), "slave SQL thread started");
       plugin_dispatch_notification(&n);
       db->slave_sql_running = 1;
     }
index 701ac2f..44fb976 100644 (file)
@@ -654,9 +654,11 @@ static int submit_derive(const char *host, const char *plugin_inst, /* {{{ */
                          const char *type, const char *type_inst,
                          derive_t counter, cdtime_t timestamp,
                          cdtime_t interval) {
-  return submit_values(host, plugin_inst, type, type_inst, &(value_t){
-      .derive=counter,
-    }, 1, timestamp, interval);
+  return submit_values(host, plugin_inst, type, type_inst,
+                       &(value_t){
+                           .derive = counter,
+                       },
+                       1, timestamp, interval);
 } /* }}} int submit_derive */
 
 static int submit_two_gauge(const char *host, const char *plugin_inst, /* {{{ */
@@ -674,9 +676,11 @@ static int submit_two_gauge(const char *host, const char *plugin_inst, /* {{{ */
 static int submit_double(const char *host, const char *plugin_inst, /* {{{ */
                          const char *type, const char *type_inst, double d,
                          cdtime_t timestamp, cdtime_t interval) {
-  return submit_values(host, plugin_inst, type, type_inst, &(value_t){
-      .gauge=d,
-    }, 1, timestamp, interval);
+  return submit_values(host, plugin_inst, type, type_inst,
+                       &(value_t){
+                           .gauge = d,
+                       },
+                       1, timestamp, interval);
 } /* }}} int submit_uint64 */
 
 /* Calculate hit ratio from old and new counters and submit the resulting
@@ -769,13 +773,14 @@ static int submit_volume_perf_data(const char *hostname, /* {{{ */
   if ((hostname == NULL) || (old_data == NULL) || (new_data == NULL))
     return -1;
 
-  ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s",
-            old_data->name);
+  snprintf(plugin_instance, sizeof(plugin_instance), "volume-%s",
+           old_data->name);
 
   /* Check for and submit disk-octet values */
   if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_IO) &&
-      HAS_ALL_FLAGS(new_data->flags, HAVE_VOLUME_PERF_BYTES_READ |
-                                         HAVE_VOLUME_PERF_BYTES_WRITE)) {
+      HAS_ALL_FLAGS(new_data->flags,
+                    HAVE_VOLUME_PERF_BYTES_READ |
+                        HAVE_VOLUME_PERF_BYTES_WRITE)) {
     submit_two_derive(
         hostname, plugin_instance, "disk_octets", /* type instance = */ NULL,
         (derive_t)new_data->read_bytes, (derive_t)new_data->write_bytes,
@@ -793,15 +798,15 @@ static int submit_volume_perf_data(const char *hostname, /* {{{ */
   }
 
   /* Check for, calculate and submit disk-latency values */
-  if (HAS_ALL_FLAGS(old_data->flags, CFG_VOLUME_PERF_LATENCY |
-                                         HAVE_VOLUME_PERF_OPS_READ |
-                                         HAVE_VOLUME_PERF_OPS_WRITE |
-                                         HAVE_VOLUME_PERF_LATENCY_READ |
-                                         HAVE_VOLUME_PERF_LATENCY_WRITE) &&
-      HAS_ALL_FLAGS(new_data->flags, HAVE_VOLUME_PERF_OPS_READ |
-                                         HAVE_VOLUME_PERF_OPS_WRITE |
-                                         HAVE_VOLUME_PERF_LATENCY_READ |
-                                         HAVE_VOLUME_PERF_LATENCY_WRITE)) {
+  if (HAS_ALL_FLAGS(old_data->flags,
+                    CFG_VOLUME_PERF_LATENCY | HAVE_VOLUME_PERF_OPS_READ |
+                        HAVE_VOLUME_PERF_OPS_WRITE |
+                        HAVE_VOLUME_PERF_LATENCY_READ |
+                        HAVE_VOLUME_PERF_LATENCY_WRITE) &&
+      HAS_ALL_FLAGS(new_data->flags,
+                    HAVE_VOLUME_PERF_OPS_READ | HAVE_VOLUME_PERF_OPS_WRITE |
+                        HAVE_VOLUME_PERF_LATENCY_READ |
+                        HAVE_VOLUME_PERF_LATENCY_WRITE)) {
     gauge_t latency_per_op_read;
     gauge_t latency_per_op_write;
 
@@ -1399,10 +1404,11 @@ static int cna_submit_volume_usage_data(const char *hostname, /* {{{ */
     uint64_t snap_reserve_free = v->snap_reserved;
     uint64_t snap_norm_used = v->snap_used;
 
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "volume-%s", v->name);
+    snprintf(plugin_instance, sizeof(plugin_instance), "volume-%s", v->name);
 
-    if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_USED |
-                                    HAVE_VOLUME_USAGE_SNAP_RSVD)) {
+    if (HAS_ALL_FLAGS(v->flags,
+                      HAVE_VOLUME_USAGE_SNAP_USED |
+                          HAVE_VOLUME_USAGE_SNAP_RSVD)) {
       if (v->snap_reserved > v->snap_used) {
         snap_reserve_free = v->snap_reserved - v->snap_used;
         snap_reserve_used = v->snap_used;
@@ -1416,8 +1422,9 @@ static int cna_submit_volume_usage_data(const char *hostname, /* {{{ */
 
     /* The space used by snapshots but not reserved for them is included in
      * both, norm_used and snap_norm_used. If possible, subtract this here. */
-    if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_NORM_USED |
-                                    HAVE_VOLUME_USAGE_SNAP_USED)) {
+    if (HAS_ALL_FLAGS(v->flags,
+                      HAVE_VOLUME_USAGE_NORM_USED |
+                          HAVE_VOLUME_USAGE_SNAP_USED)) {
       if (norm_used >= snap_norm_used)
         norm_used -= snap_norm_used;
       else {
@@ -1459,8 +1466,9 @@ static int cna_submit_volume_usage_data(const char *hostname, /* {{{ */
                     "df_complex", "snap_reserved", (double)snap_reserve_free,
                     /* timestamp = */ 0, interval);
 
-    if (HAS_ALL_FLAGS(v->flags, HAVE_VOLUME_USAGE_SNAP_USED |
-                                    HAVE_VOLUME_USAGE_SNAP_RSVD))
+    if (HAS_ALL_FLAGS(v->flags,
+                      HAVE_VOLUME_USAGE_SNAP_USED |
+                          HAVE_VOLUME_USAGE_SNAP_RSVD))
       submit_double(hostname, /* plugin instance = */ plugin_instance,
                     "df_complex", "snap_reserve_used",
                     (double)snap_reserve_used, /* timestamp = */ 0, interval);
@@ -1490,13 +1498,12 @@ static int cna_change_volume_status(const char *hostname, /* {{{ */
 
   if ((v->flags & IS_VOLUME_USAGE_OFFLINE) != 0) {
     n.severity = NOTIF_OKAY;
-    ssnprintf(n.message, sizeof(n.message), "Volume %s is now online.",
-              v->name);
+    snprintf(n.message, sizeof(n.message), "Volume %s is now online.", v->name);
     v->flags &= ~IS_VOLUME_USAGE_OFFLINE;
   } else {
     n.severity = NOTIF_WARNING;
-    ssnprintf(n.message, sizeof(n.message), "Volume %s is now offline.",
-              v->name);
+    snprintf(n.message, sizeof(n.message), "Volume %s is now offline.",
+             v->name);
     v->flags |= IS_VOLUME_USAGE_OFFLINE;
   }
 
@@ -1723,8 +1730,8 @@ static int cna_handle_volume_usage_data(const host_config_t *host, /* {{{ */
     }
   } /* for (elem_volume) */
 
-  return cna_submit_volume_usage_data(host->name, cfg_volume,
-                                      host->cfg_volume_usage->interval.interval);
+  return cna_submit_volume_usage_data(
+      host->name, cfg_volume, host->cfg_volume_usage->interval.interval);
 } /* }}} int cna_handle_volume_usage_data */
 
 static int cna_setup_volume_usage(cfg_volume_usage_t *cvu) /* {{{ */
@@ -1825,8 +1832,8 @@ static int cna_handle_quota_data(const host_config_t *host, /* {{{ */
     if (volume_name == NULL)
       continue;
 
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "quota-%s-%s",
-              volume_name, tree_name);
+    snprintf(plugin_instance, sizeof(plugin_instance), "quota-%s-%s",
+             volume_name, tree_name);
 
     value = na_child_get_uint64(elem_quota, "disk-used", UINT64_MAX);
     if (value != UINT64_MAX) {
@@ -1938,8 +1945,8 @@ static int cna_handle_snapvault_data(const char *hostname, /* {{{ */
       continue;
 
     /* possible TODO: make plugin instance configurable */
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "snapvault-%s",
-              dest_path);
+    snprintf(plugin_instance, sizeof(plugin_instance), "snapvault-%s",
+             dest_path);
     submit_double(hostname, plugin_instance, /* type = */ "delay", NULL,
                   (double)value, /* timestamp = */ 0, interval);
 
@@ -2816,10 +2823,10 @@ static int cna_register_host(host_config_t *host) /* {{{ */
   char cb_name[256];
 
   if (host->vfiler)
-    ssnprintf(cb_name, sizeof(cb_name), "netapp-%s-%s", host->name,
-              host->vfiler);
+    snprintf(cb_name, sizeof(cb_name), "netapp-%s-%s", host->name,
+             host->vfiler);
   else
-    ssnprintf(cb_name, sizeof(cb_name), "netapp-%s", host->name);
+    snprintf(cb_name, sizeof(cb_name), "netapp-%s", host->name);
 
   plugin_register_complex_read(
       /* group = */ NULL, cb_name,
index 3cc1084..0bac3e7 100644 (file)
@@ -495,8 +495,8 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) {
     if (strcmp(tc_type, "filter") == 0)
       numberic_id = tm->tcm_parent;
 
-    ssnprintf(tc_inst, sizeof(tc_inst), "%s-%x:%x", kind, numberic_id >> 16,
-              numberic_id & 0x0000FFFF);
+    snprintf(tc_inst, sizeof(tc_inst), "%s-%x:%x", kind, numberic_id >> 16,
+             numberic_id & 0x0000FFFF);
   }
 
   DEBUG("netlink plugin: qos_filter_cb: got %s for %s (%i).", tc_type, dev,
@@ -527,8 +527,7 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) {
 
       stats_submitted = 1;
 
-      ssnprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type,
-                tc_inst);
+      snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst);
 
       if (q_stats.bs != NULL) {
         submit_one(dev, "ipt_bytes", type_instance, q_stats.bs->bytes);
@@ -560,8 +559,7 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) {
     if (!stats_submitted && ts != NULL) {
       char type_instance[DATA_MAX_NAME_LEN];
 
-      ssnprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type,
-                tc_inst);
+      snprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst);
 
       submit_one(dev, "ipt_bytes", type_instance, ts->bytes);
       submit_one(dev, "ipt_packets", type_instance, ts->packets);
index 00c6c75..375da84 100644 (file)
@@ -2652,10 +2652,10 @@ static int network_write(const data_set_t *ds, const value_list_t *vl,
 
   pthread_mutex_lock(&send_buffer_lock);
 
-  status =
-      add_to_buffer(send_buffer_ptr, network_config_packet_size -
-                                         (send_buffer_fill + BUFF_SIG_SIZE),
-                    &send_buffer_vl, ds, vl);
+  status = add_to_buffer(send_buffer_ptr,
+                         network_config_packet_size -
+                             (send_buffer_fill + BUFF_SIG_SIZE),
+                         &send_buffer_vl, ds, vl);
   if (status >= 0) {
     /* status == bytes added to the buffer */
     send_buffer_fill += status;
@@ -2666,10 +2666,10 @@ static int network_write(const data_set_t *ds, const value_list_t *vl,
   } else {
     flush_buffer();
 
-    status =
-        add_to_buffer(send_buffer_ptr, network_config_packet_size -
-                                           (send_buffer_fill + BUFF_SIG_SIZE),
-                      &send_buffer_vl, ds, vl);
+    status = add_to_buffer(send_buffer_ptr,
+                           network_config_packet_size -
+                               (send_buffer_fill + BUFF_SIG_SIZE),
+                           &send_buffer_vl, ds, vl);
 
     if (status >= 0) {
       send_buffer_fill += status;
index 6290613..bbe8438 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
@@ -357,8 +357,8 @@ static void nfs_submit_fields(int nfs_version, const char *instance,
   char plugin_instance[DATA_MAX_NAME_LEN];
   value_t values[fields_num];
 
-  ssnprintf(plugin_instance, sizeof(plugin_instance), "v%i%s", nfs_version,
-            instance);
+  snprintf(plugin_instance, sizeof(plugin_instance), "v%i%s", nfs_version,
+           instance);
 
   for (size_t i = 0; i < fields_num; i++)
     (void)parse_value(fields[i], &values[i], DS_TYPE_DERIVE);
@@ -523,8 +523,8 @@ static int nfs_read_kstat(kstat_t *ksp, int nfs_version, const char *inst,
   if (ksp == NULL)
     return EINVAL;
 
-  ssnprintf(plugin_instance, sizeof(plugin_instance), "v%i%s", nfs_version,
-            inst);
+  snprintf(plugin_instance, sizeof(plugin_instance), "v%i%s", nfs_version,
+           inst);
 
   kstat_read(kc, ksp, NULL);
   for (size_t i = 0; i < proc_names_num; i++) {
index 0f1da0a..88118b9 100644 (file)
@@ -122,8 +122,8 @@ static int init(void) {
     curl_easy_setopt(curl, CURLOPT_PASSWORD, (pass == NULL) ? "" : pass);
 #else
     static char credentials[1024];
-    int status = ssnprintf(credentials, sizeof(credentials), "%s:%s", user,
-                           pass == NULL ? "" : pass);
+    int status = snprintf(credentials, sizeof(credentials), "%s:%s", user,
+                          pass == NULL ? "" : pass);
     if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
       ERROR("nginx plugin: Credentials would have been truncated.");
       return -1;
@@ -133,10 +133,6 @@ static int init(void) {
 #endif
   }
 
-  if (url != NULL) {
-    curl_easy_setopt(curl, CURLOPT_URL, url);
-  }
-
   curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
   curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
 
@@ -207,6 +203,9 @@ static int nginx_read(void) {
     return -1;
 
   nginx_buffer_len = 0;
+
+  curl_easy_setopt(curl, CURLOPT_URL, url);
+
   if (curl_easy_perform(curl) != CURLE_OK) {
     WARNING("nginx plugin: curl_easy_perform failed: %s", nginx_curl_error);
     return -1;
index d167fbf..e391cf2 100644 (file)
@@ -93,12 +93,12 @@ static int c_notify(const notification_t *n,
     timeout = fail_timeout;
   }
 
-  ssnprintf(summary, sizeof(summary), "collectd %s notification",
-            (NOTIF_FAILURE == n->severity)
-                ? "FAILURE"
-                : (NOTIF_WARNING == n->severity)
-                      ? "WARNING"
-                      : (NOTIF_OKAY == n->severity) ? "OKAY" : "UNKNOWN");
+  snprintf(summary, sizeof(summary), "collectd %s notification",
+           (NOTIF_FAILURE == n->severity)
+               ? "FAILURE"
+               : (NOTIF_WARNING == n->severity)
+                     ? "WARNING"
+                     : (NOTIF_OKAY == n->severity) ? "OKAY" : "UNKNOWN");
 
   notification = notify_notification_new(summary, n->message, NULL
 #if NOTIFY_CHECK_VERSION(0, 7, 0)
index c1ce2f8..52cc838 100644 (file)
@@ -104,8 +104,8 @@ static void monitor_cb(const char *buf, int buflen, int writing,
 static int notify_email_init(void) {
   char server[MAXSTRING];
 
-  ssnprintf(server, sizeof(server), "%s:%i",
-            (smtp_host == NULL) ? DEFAULT_SMTP_HOST : smtp_host, smtp_port);
+  snprintf(server, sizeof(server), "%s:%i",
+           (smtp_host == NULL) ? DEFAULT_SMTP_HOST : smtp_host, smtp_port);
 
   pthread_mutex_lock(&session_lock);
 
@@ -214,16 +214,16 @@ static int notify_email_notification(const notification_t *n,
   int buf_len = sizeof(buf);
   int i;
 
-  ssnprintf(severity, sizeof(severity), "%s",
-            (n->severity == NOTIF_FAILURE)
-                ? "FAILURE"
-                : ((n->severity == NOTIF_WARNING)
-                       ? "WARNING"
-                       : ((n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN")));
+  snprintf(severity, sizeof(severity), "%s",
+           (n->severity == NOTIF_FAILURE)
+               ? "FAILURE"
+               : ((n->severity == NOTIF_WARNING)
+                      ? "WARNING"
+                      : ((n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN")));
 
-  ssnprintf(subject, sizeof(subject),
-            (email_subject == NULL) ? DEFAULT_SMTP_SUBJECT : email_subject,
-            severity, n->host);
+  snprintf(subject, sizeof(subject),
+           (email_subject == NULL) ? DEFAULT_SMTP_SUBJECT : email_subject,
+           severity, n->host);
 
   localtime_r(&CDTIME_T_TO_TIME_T(n->time), &timestamp_tm);
   strftime(timestamp_str, sizeof(timestamp_str), "%Y-%m-%d %H:%M:%S",
@@ -231,15 +231,15 @@ static int notify_email_notification(const notification_t *n,
   timestamp_str[sizeof(timestamp_str) - 1] = '\0';
 
   /* Let's make RFC822 message text with \r\n EOLs */
-  ssnprintf(buf, buf_len, "MIME-Version: 1.0\r\n"
-                          "Content-Type: text/plain; charset=\"US-ASCII\"\r\n"
-                          "Content-Transfer-Encoding: 8bit\r\n"
-                          "Subject: %s\r\n"
-                          "\r\n"
-                          "%s - %s@%s\r\n"
-                          "\r\n"
-                          "Message: %s",
-            subject, timestamp_str, severity, n->host, n->message);
+  snprintf(buf, buf_len, "MIME-Version: 1.0\r\n"
+                         "Content-Type: text/plain; charset=\"US-ASCII\"\r\n"
+                         "Content-Transfer-Encoding: 8bit\r\n"
+                         "Subject: %s\r\n"
+                         "\r\n"
+                         "%s - %s@%s\r\n"
+                         "\r\n"
+                         "Message: %s",
+           subject, timestamp_str, severity, n->host, n->message);
 
   pthread_mutex_lock(&session_lock);
 
index c95f7cb..f744d48 100644 (file)
@@ -141,10 +141,10 @@ static int nagios_notify(const notification_t *n, /* {{{ */
     break;
   }
 
-  ssnprintf(buffer, sizeof(buffer),
-            "[%.0f] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n",
-            CDTIME_T_TO_DOUBLE(n->time), n->host, &svc_description[1], code,
-            n->message);
+  snprintf(buffer, sizeof(buffer),
+           "[%.0f] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n",
+           CDTIME_T_TO_DOUBLE(n->time), n->host, &svc_description[1], code,
+           n->message);
 
   return nagios_print(buffer);
 } /* }}} int nagios_notify */
index 68ac3a7..a19d05c 100644 (file)
@@ -267,7 +267,7 @@ static int ntpd_config(const char *key, const char *value) {
   } else if (strcasecmp(key, "Port") == 0) {
     int port = (int)(atof(value));
     if ((port > 0) && (port <= 65535))
-      ssnprintf(ntpd_port, sizeof(ntpd_port), "%i", port);
+      snprintf(ntpd_port, sizeof(ntpd_port), "%i", port);
     else
       sstrncpy(ntpd_port, value, sizeof(ntpd_port));
   } else if (strcasecmp(key, "ReverseLookups") == 0) {
@@ -782,8 +782,8 @@ static int ntpd_get_name_refclock(char *buffer, size_t buffer_size,
     return ntpd_get_name_from_address(buffer, buffer_size, peer_info, 0);
 
   if (include_unit_id)
-    ssnprintf(buffer, buffer_size, "%s-%" PRIu32, refclock_names[refclock_id],
-              unit_id);
+    snprintf(buffer, buffer_size, "%s-%" PRIu32, refclock_names[refclock_id],
+             unit_id);
   else
     sstrncpy(buffer, refclock_names[refclock_id], buffer_size);
 
index 6ef3f09..56ea707 100644 (file)
@@ -47,7 +47,7 @@ static void numa_dispatch_value(int node, /* {{{ */
   vl.values_len = 1;
 
   sstrncpy(vl.plugin, "numa", sizeof(vl.plugin));
-  ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "node%i", node);
+  snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "node%i", node);
   sstrncpy(vl.type, "vmpage_action", sizeof(vl.type));
   sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
 
@@ -62,7 +62,7 @@ static int numa_read_node(int node) /* {{{ */
   int status;
   int success;
 
-  ssnprintf(path, sizeof(path), NUMA_ROOT_DIR "/node%i/numastat", node);
+  snprintf(path, sizeof(path), NUMA_ROOT_DIR "/node%i/numastat", node);
 
   fh = fopen(path, "r");
   if (fh == NULL) {
@@ -127,7 +127,7 @@ static int numa_init(void) /* {{{ */
     struct stat statbuf = {0};
     int status;
 
-    ssnprintf(path, sizeof(path), NUMA_ROOT_DIR "/node%i", max_node + 1);
+    snprintf(path, sizeof(path), NUMA_ROOT_DIR "/node%i", max_node + 1);
 
     status = stat(path, &statbuf);
     if (status == 0) {
index 2173af9..2bd4019 100644 (file)
--- a/src/nut.c
+++ b/src/nut.c
@@ -22,6 +22,7 @@
  *
  * Authors:
  *   Florian octo Forster <octo at collectd.org>
+ *   Pavel Rochnyak <pavel2000 ngs.ru>
  **/
 
 #include "collectd.h"
@@ -49,18 +50,20 @@ struct nut_ups_s {
   nut_ups_t *next;
 };
 
-static nut_ups_t *upslist_head = NULL;
-
-static pthread_mutex_t read_lock = PTHREAD_MUTEX_INITIALIZER;
-static int read_busy = 0;
-
-static const char *config_keys[] = {"UPS", "FORCESSL", "VERIFYPEER", "CAPATH"};
+static const char *config_keys[] = {"UPS", "FORCESSL", "VERIFYPEER", "CAPATH",
+                                    "CONNECTTIMEOUT"};
 static int config_keys_num = STATIC_ARRAY_SIZE(config_keys);
 static int force_ssl = 0;   // Initialized to default of 0 (false)
 static int verify_peer = 0; // Initialized to default of 0 (false)
+static int ssl_flags = UPSCLI_CONN_TRYSSL;
+static int connect_timeout = -1;
 static char *ca_path = NULL;
 
-static void free_nut_ups_t(nut_ups_t *ups) {
+static int nut_read(user_data_t *user_data);
+
+static void free_nut_ups_t(void *arg) {
+  nut_ups_t *ups = arg;
+
   if (ups->conn != NULL) {
     upscli_disconnect(ups->conn);
     sfree(ups->conn);
@@ -73,6 +76,7 @@ static void free_nut_ups_t(nut_ups_t *ups) {
 static int nut_add_ups(const char *name) {
   nut_ups_t *ups;
   int status;
+  char *cb_name;
 
   DEBUG("nut plugin: nut_add_ups (name = %s);", name);
 
@@ -89,13 +93,24 @@ static int nut_add_ups(const char *name) {
     return 1;
   }
 
-  if (upslist_head == NULL)
-    upslist_head = ups;
-  else {
-    nut_ups_t *last = upslist_head;
-    while (last->next != NULL)
-      last = last->next;
-    last->next = ups;
+  cb_name = ssnprintf_alloc("nut/%s", name);
+
+  status = plugin_register_complex_read(
+    /* group = */ "nut",
+    /* name      = */ cb_name,
+    /* callback  = */ nut_read,
+    /* interval  = */ 0,
+    /* user_data = */ &(user_data_t){
+                        .data = ups, .free_func = free_nut_ups_t,
+                      });
+
+  sfree(cb_name);
+
+  if (status == EINVAL) {
+    WARNING("nut plugin: UPS \"%s\" already added. "
+            "Please check your configuration.",
+            name);
+    return -1;
   }
 
   return 0;
@@ -137,6 +152,24 @@ static int nut_ca_path(const char *value) {
   return 0;
 } /* int nut_ca_path */
 
+static int nut_set_connect_timeout(const char *value) {
+#if HAVE_UPSCLI_TRYCONNECT
+  long ret;
+
+  errno = 0;
+  ret = strtol(value, /* endptr = */ NULL, /* base = */ 10);
+  if (errno == 0)
+    connect_timeout = ret;
+  else
+    WARNING("nut plugin: The ConnectTimeout option requires numeric argument. "
+            "Setting ignored.");
+#else /* #if HAVE_UPSCLI_TRYCONNECT */
+  WARNING("nut plugin: Dependency libupsclient version insufficient (<2.6.2) "
+          "for ConnectTimeout option support. Setting ignored.");
+#endif
+  return 0;
+} /* int nut_set_connect_timeout */
+
 static int nut_config(const char *key, const char *value) {
   if (strcasecmp(key, "UPS") == 0)
     return nut_add_ups(value);
@@ -146,6 +179,8 @@ static int nut_config(const char *key, const char *value) {
     return nut_verify_peer(value);
   else if (strcasecmp(key, "CAPATH") == 0)
     return nut_ca_path(value);
+  else if (strcasecmp(key, "CONNECTTIMEOUT") == 0)
+    return nut_set_connect_timeout(value);
   else
     return -1;
 } /* int nut_config */
@@ -169,48 +204,23 @@ static void nut_submit(nut_ups_t *ups, const char *type,
 } /* void nut_submit */
 
 static int nut_connect(nut_ups_t *ups) {
-#if HAVE_UPSCLI_INIT
-  int status;
-  int ssl_status;
-  int ssl_flags;
+  int status, ssl_status;
 
-  if (verify_peer == 1 && force_ssl == 0) {
-    WARNING("nut plugin: nut_connect: VerifyPeer true but ForceSSL "
-            "false. Setting ForceSSL to true.");
-    force_ssl = 1;
-  }
-
-  if (verify_peer == 1 && ca_path == NULL) {
-    ERROR("nut plugin: nut_connect: VerifyPeer true but missing "
-          "CAPath value.");
-    return -1;
-  }
-
-  if (verify_peer == 1) {
-    status = upscli_init(verify_peer, ca_path, NULL, NULL);
-
-    if (status != 1) {
-      ERROR("nut plugin: nut_connect: upscli_init (%i, %s) failed: %s",
-            verify_peer, ca_path, upscli_strerror(ups->conn));
-      upscli_cleanup();
-      return -1;
-    }
-  } /* if (verify_peer == 1) */
-
-  if (verify_peer == 1)
-    ssl_flags = (UPSCLI_CONN_REQSSL | UPSCLI_CONN_CERTVERIF);
-  else if (force_ssl == 1)
-    ssl_flags = UPSCLI_CONN_REQSSL;
-  else
-    ssl_flags = UPSCLI_CONN_TRYSSL;
+#if HAVE_UPSCLI_TRYCONNECT
+  struct timeval tv;
+  tv.tv_sec = connect_timeout / 1000;
+  tv.tv_usec = connect_timeout % 1000;
 
+  status = upscli_tryconnect(ups->conn, ups->hostname, ups->port, ssl_flags,
+                             &tv);
+#else /* #if HAVE_UPSCLI_TRYCONNECT */
   status = upscli_connect(ups->conn, ups->hostname, ups->port, ssl_flags);
+#endif
 
   if (status != 0) {
     ERROR("nut plugin: nut_connect: upscli_connect (%s, %i) failed: %s",
           ups->hostname, ups->port, upscli_strerror(ups->conn));
     sfree(ups->conn);
-    upscli_cleanup();
     return -1;
   } /* if (status != 0) */
 
@@ -231,57 +241,13 @@ static int nut_connect(nut_ups_t *ups) {
     ERROR("nut plugin: nut_connect: upscli_ssl failed: %s",
           upscli_strerror(ups->conn));
     sfree(ups->conn);
-    upscli_cleanup();
     return -1;
   } /* if (ssl_status == 1 && verify_peer == 1) */
   return 0;
-
-#else /* #if HAVE_UPSCLI_INIT */
-  int status;
-  int ssl_status;
-  int ssl_flags;
-
-  if (verify_peer == 1 || ca_path != NULL) {
-    WARNING("nut plugin: nut_connect: Dependency libupsclient version "
-            "insufficient (<2.7) for VerifyPeer support. Ignoring VerifyPeer "
-            "and CAPath.");
-  }
-
-  if (force_ssl == 1)
-    ssl_flags = UPSCLI_CONN_REQSSL;
-  else
-    ssl_flags = UPSCLI_CONN_TRYSSL;
-
-  status = upscli_connect(ups->conn, ups->hostname, ups->port, ssl_flags);
-
-  if (status != 0) {
-    ERROR("nut plugin: nut_connect: upscli_connect (%s, %i) failed: %s",
-          ups->hostname, ups->port, upscli_strerror(ups->conn));
-    sfree(ups->conn);
-    return -1;
-  } /* if (status != 0) */
-
-  INFO("nut plugin: Connection to (%s, %i) established.", ups->hostname,
-       ups->port);
-
-  // Output INFO or WARNING based on SSL
-  ssl_status = upscli_ssl(ups->conn); // 1 for SSL, 0 for not, -1 for error
-  if (ssl_status == 1) {
-    INFO("nut plugin: Connection is secured with SSL with no verification "
-         "of server SSL certificate.");
-  } else if (ssl_status == 0) {
-    WARNING("nut plugin: Connection is unsecured (no SSL).");
-  } else {
-    ERROR("nut plugin: nut_connect: upscli_ssl failed: %s",
-          upscli_strerror(ups->conn));
-    sfree(ups->conn);
-    return -1;
-  } /* if (ssl_status == 1 && verify_peer == 1) */
-  return 0;
-#endif
 }
 
-static int nut_read_one(nut_ups_t *ups) {
+static int nut_read(user_data_t *user_data) {
+  nut_ups_t *ups = user_data->data;
   const char *query[3] = {"VAR", ups->upsname, NULL};
   unsigned int query_num = 2;
   char **answer;
@@ -306,13 +272,10 @@ static int nut_read_one(nut_ups_t *ups) {
    * error */
   status = upscli_list_start(ups->conn, query_num, query);
   if (status != 0) {
-    ERROR("nut plugin: nut_read_one: upscli_list_start (%s) failed: %s",
+    ERROR("nut plugin: nut_read: upscli_list_start (%s) failed: %s",
           ups->upsname, upscli_strerror(ups->conn));
     upscli_disconnect(ups->conn);
     sfree(ups->conn);
-#if HAVE_UPSCLI_INIT
-    upscli_cleanup();
-#endif
     return -1;
   }
 
@@ -366,40 +329,58 @@ static int nut_read_one(nut_ups_t *ups) {
   } /* while (upscli_list_next) */
 
   return 0;
-} /* int nut_read_one */
+} /* int nut_read */
+
+static int nut_init(void) {
+#if HAVE_UPSCLI_INIT
+  if (verify_peer == 1 && force_ssl == 0) {
+    WARNING("nut plugin: nut_connect: VerifyPeer true but ForceSSL "
+            "false. Setting ForceSSL to true.");
+    force_ssl = 1;
+  }
+
+  if (verify_peer == 1 && ca_path == NULL) {
+    ERROR("nut plugin: nut_connect: VerifyPeer true but missing "
+          "CAPath value.");
+    plugin_unregister_read_group("nut");
+    return -1;
+  }
 
-static int nut_read(void) {
-  int success = 0;
+  if (verify_peer == 1 || force_ssl == 1) {
+    int status = upscli_init(verify_peer, ca_path, NULL, NULL);
 
-  pthread_mutex_lock(&read_lock);
-  success = read_busy;
-  read_busy = 1;
-  pthread_mutex_unlock(&read_lock);
+    if (status != 1) {
+      ERROR("nut plugin: upscli_init (%i, %s) failed", verify_peer, ca_path);
+      upscli_cleanup();
+      plugin_unregister_read_group("nut");
+      return -1;
+    }
+  } /* if (verify_peer == 1) */
+
+  if (verify_peer == 1)
+    ssl_flags = (UPSCLI_CONN_REQSSL | UPSCLI_CONN_CERTVERIF);
+  else if (force_ssl == 1)
+    ssl_flags = UPSCLI_CONN_REQSSL;
 
-  if (success != 0)
-    return 0;
+#else /* #if HAVE_UPSCLI_INIT */
+  if (verify_peer == 1 || ca_path != NULL) {
+    WARNING("nut plugin: nut_connect: Dependency libupsclient version "
+            "insufficient (<2.7) for VerifyPeer support. Ignoring VerifyPeer "
+            "and CAPath.");
+    verify_peer = 0;
+  }
 
-  for (nut_ups_t *ups = upslist_head; ups != NULL; ups = ups->next)
-    if (nut_read_one(ups) == 0)
-      success++;
+  if (force_ssl == 1)
+    ssl_flags = UPSCLI_CONN_REQSSL;
+#endif
 
-  pthread_mutex_lock(&read_lock);
-  read_busy = 0;
-  pthread_mutex_unlock(&read_lock);
+  if (connect_timeout <= 0)
+    connect_timeout = (long)CDTIME_T_TO_MS(plugin_get_interval());
 
-  return (success != 0) ? 0 : -1;
-} /* int nut_read */
+  return 0;
+} /* int nut_init */
 
 static int nut_shutdown(void) {
-  nut_ups_t *this;
-  nut_ups_t *next;
-
-  this = upslist_head;
-  while (this != NULL) {
-    next = this->next;
-    free_nut_ups_t(this);
-    this = next;
-  }
 #if HAVE_UPSCLI_INIT
   upscli_cleanup();
 #endif
@@ -409,6 +390,6 @@ static int nut_shutdown(void) {
 
 void module_register(void) {
   plugin_register_config("nut", nut_config, config_keys, config_keys_num);
-  plugin_register_read("nut", nut_read);
+  plugin_register_init("nut", nut_init);
   plugin_register_shutdown("nut", nut_shutdown);
 } /* void module_register */
index eccafae..1ac1d42 100644 (file)
@@ -294,8 +294,8 @@ static int olsrd_cb_links(int lineno, /* {{{ */
     if (config_want_links == OLSRD_WANT_DETAIL) {
       char type_instance[DATA_MAX_NAME_LEN];
 
-      ssnprintf(type_instance, sizeof(type_instance), "%s-%s-lq", fields[0],
-                fields[1]);
+      snprintf(type_instance, sizeof(type_instance), "%s-%s-lq", fields[0],
+               fields[1]);
 
       DEBUG("olsrd plugin: links: type_instance = %s;  lq = %g;", type_instance,
             lq);
@@ -318,8 +318,8 @@ static int olsrd_cb_links(int lineno, /* {{{ */
     if (config_want_links == OLSRD_WANT_DETAIL) {
       char type_instance[DATA_MAX_NAME_LEN];
 
-      ssnprintf(type_instance, sizeof(type_instance), "%s-%s-rx", fields[0],
-                fields[1]);
+      snprintf(type_instance, sizeof(type_instance), "%s-%s-rx", fields[0],
+               fields[1]);
 
       DEBUG("olsrd plugin: links: type_instance = %s; nlq = %g;", type_instance,
             lq);
@@ -496,8 +496,8 @@ static int olsrd_cb_topology(int lineno, /* {{{ */
     if (config_want_topology == OLSRD_WANT_DETAIL) {
       char type_instance[DATA_MAX_NAME_LEN] = {0};
 
-      ssnprintf(type_instance, sizeof(type_instance), "%s-%s-lq", fields[0],
-                fields[1]);
+      snprintf(type_instance, sizeof(type_instance), "%s-%s-lq", fields[0],
+               fields[1]);
       DEBUG("olsrd plugin: type_instance = %s; lq = %g;", type_instance, lq);
       olsrd_submit(/* p.-inst = */ "topology", /* type = */ "signal_quality",
                    type_instance, lq);
@@ -515,8 +515,8 @@ static int olsrd_cb_topology(int lineno, /* {{{ */
     } else {
       char type_instance[DATA_MAX_NAME_LEN] = {0};
 
-      ssnprintf(type_instance, sizeof(type_instance), "%s-%s-nlq", fields[0],
-                fields[1]);
+      snprintf(type_instance, sizeof(type_instance), "%s-%s-nlq", fields[0],
+               fields[1]);
       DEBUG("olsrd plugin: type_instance = %s; nlq = %g;", type_instance, nlq);
       olsrd_submit(/* p.-inst = */ "topology", /* type = */ "signal_quality",
                    type_instance, nlq);
index 2d594ec..5c5152d 100644 (file)
@@ -350,11 +350,11 @@ static int cow_read_ds2409(const char *path) {
   char subpath[4096];
   int status;
 
-  status = ssnprintf(subpath, sizeof(subpath), "%s/main", path);
+  status = snprintf(subpath, sizeof(subpath), "%s/main", path);
   if ((status > 0) && (status < (int)sizeof(subpath)))
     cow_read_bus(subpath);
 
-  status = ssnprintf(subpath, sizeof(subpath), "%s/aux", path);
+  status = snprintf(subpath, sizeof(subpath), "%s/aux", path);
   if ((status > 0) && (status < (int)sizeof(subpath)))
     cow_read_bus(subpath);
 
@@ -388,9 +388,9 @@ static int cow_read_bus(const char *path) {
     dummy = NULL;
 
     if (strcmp("/", path) == 0)
-      status = ssnprintf(subpath, sizeof(subpath), "/%s", buffer_ptr);
+      status = snprintf(subpath, sizeof(subpath), "/%s", buffer_ptr);
     else
-      status = ssnprintf(subpath, sizeof(subpath), "%s/%s", path, buffer_ptr);
+      status = snprintf(subpath, sizeof(subpath), "%s/%s", path, buffer_ptr);
     if ((status <= 0) || (status >= (int)sizeof(subpath)))
       continue;
 
index 8053929..b3fcb10 100644 (file)
@@ -314,8 +314,8 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */
         if ((olmbdb_list =
                  ldap_get_values_len(st->ld, e, "olmBDBEntryCache")) != NULL) {
           olmbdb_data = *olmbdb_list[0];
-          ssnprintf(typeinst, sizeof(typeinst), "bdbentrycache-%s",
-                    nc_data.bv_val);
+          snprintf(typeinst, sizeof(typeinst), "bdbentrycache-%s",
+                   nc_data.bv_val);
           cldap_submit_gauge("cache_size", typeinst, atoll(olmbdb_data.bv_val),
                              st);
           ldap_value_free_len(olmbdb_list);
@@ -324,8 +324,7 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */
         if ((olmbdb_list = ldap_get_values_len(st->ld, e, "olmBDBDNCache")) !=
             NULL) {
           olmbdb_data = *olmbdb_list[0];
-          ssnprintf(typeinst, sizeof(typeinst), "bdbdncache-%s",
-                    nc_data.bv_val);
+          snprintf(typeinst, sizeof(typeinst), "bdbdncache-%s", nc_data.bv_val);
           cldap_submit_gauge("cache_size", typeinst, atoll(olmbdb_data.bv_val),
                              st);
           ldap_value_free_len(olmbdb_list);
@@ -334,8 +333,8 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */
         if ((olmbdb_list = ldap_get_values_len(st->ld, e, "olmBDBIDLCache")) !=
             NULL) {
           olmbdb_data = *olmbdb_list[0];
-          ssnprintf(typeinst, sizeof(typeinst), "bdbidlcache-%s",
-                    nc_data.bv_val);
+          snprintf(typeinst, sizeof(typeinst), "bdbidlcache-%s",
+                   nc_data.bv_val);
           cldap_submit_gauge("cache_size", typeinst, atoll(olmbdb_data.bv_val),
                              st);
           ldap_value_free_len(olmbdb_list);
@@ -480,16 +479,17 @@ static int cldap_config_add(oconfig_item_t *ci) /* {{{ */
       databases[databases_num] = st;
       databases_num++;
 
-      ssnprintf(callback_name, sizeof(callback_name), "openldap/%s/%s",
-                (st->host != NULL) ? st->host : hostname_g,
-                (st->name != NULL) ? st->name : "default");
+      snprintf(callback_name, sizeof(callback_name), "openldap/%s/%s",
+               (st->host != NULL) ? st->host : hostname_g,
+               (st->name != NULL) ? st->name : "default");
 
       status = plugin_register_complex_read(/* group = */ NULL,
                                             /* name      = */ callback_name,
                                             /* callback  = */ cldap_read_host,
-                                            /* interval  = */ 0, &(user_data_t){
-                                                                     .data = st,
-                                                                 });
+                                            /* interval  = */ 0,
+                                            &(user_data_t){
+                                                .data = st,
+                                            });
     }
   }
 
index 2d98f0a..44bd564 100644 (file)
@@ -476,8 +476,7 @@ static int o_read_database_query(o_database_t *db, /* {{{ */
     column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN;
 
   ALLOC_OR_FAIL(column_values, column_num * sizeof(char *));
-  ALLOC_OR_FAIL(column_values[0],
-                column_num * DATA_MAX_NAME_LEN);
+  ALLOC_OR_FAIL(column_values[0], column_num * DATA_MAX_NAME_LEN);
   for (size_t i = 1; i < column_num; i++)
     column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN;
 
@@ -636,7 +635,7 @@ static int o_read_database(o_database_t *db) /* {{{ */
     if ((status != OCI_SUCCESS) && (status != OCI_SUCCESS_WITH_INFO)) {
       char errfunc[256];
 
-      ssnprintf(errfunc, sizeof(errfunc), "OCILogon(\"%s\")", db->connect_id);
+      snprintf(errfunc, sizeof(errfunc), "OCILogon(\"%s\")", db->connect_id);
 
       o_report_error("o_read_database", db->name, NULL, errfunc, oci_error);
       DEBUG("oracle plugin: OCILogon (%s): db->oci_service_context = %p;",
index 6504234..afa1199 100644 (file)
@@ -3,14 +3,17 @@
  *
  * Copyright(c) 2016 Intel Corporation. All rights reserved.
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ *of
  * this software and associated documentation files (the "Software"), to deal in
  * the Software without restriction, including without limitation the rights to
  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
+ * of the Software, and to permit persons to whom the Software is furnished to
+ *do
  * so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in all
+ * The above copyright notice and this permission notice shall be included in
+ *all
  * copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@@ -155,8 +158,8 @@ static char *ovs_events_get_select_params() {
       return NULL;
     }
     opt_buff = new_buff;
-    int ret = ssnprintf(opt_buff + buff_off, buff_size - buff_off, option_fmt,
-                        iface->name);
+    int ret = snprintf(opt_buff + buff_off, buff_size - buff_off, option_fmt,
+                       iface->name);
     if (ret < 0) {
       sfree(opt_buff);
       return NULL;
@@ -177,7 +180,7 @@ static char *ovs_events_get_select_params() {
   }
 
   /* create OVS DB select params */
-  if (ssnprintf(params_buff, params_size, params_fmt, opt_buff) < 0)
+  if (snprintf(params_buff, params_size, params_fmt, opt_buff) < 0)
     sfree(params_buff);
 
   sfree(opt_buff);
@@ -202,8 +205,8 @@ static int ovs_events_config_get_interfaces(const oconfig_item_t *ci) {
   for (int j = 0; j < ci->values_num; j++) {
     /* check interface name type */
     if (ci->values[j].type != OCONFIG_TYPE_STRING) {
-      ERROR(OVS_EVENTS_PLUGIN
-            ": given interface name is not a string [idx=%d]", j);
+      ERROR(OVS_EVENTS_PLUGIN ": given interface name is not a string [idx=%d]",
+            j);
       return -1;
     }
     /* allocate memory for configured interface */
@@ -278,9 +281,10 @@ static int ovs_events_plugin_config(oconfig_item_t *ci) {
   }
   /* Check and warn about invalid configuration */
   if (!ovs_events_ctx.config.send_notification && !dispatch_values) {
-      WARNING(OVS_EVENTS_PLUGIN ": send notification and dispatch values "
-              "options are disabled. No information will be dispatched by the "
-              "plugin. Please check your configuration");
+    WARNING(OVS_EVENTS_PLUGIN
+            ": send notification and dispatch values "
+            "options are disabled. No information will be dispatched by the "
+            "plugin. Please check your configuration");
   }
   /* Dispatch link status values if configured */
   if (dispatch_values)
@@ -291,7 +295,8 @@ static int ovs_events_plugin_config(oconfig_item_t *ci) {
 }
 
 /* Dispatch OVS interface link status event to collectd */
-static void ovs_events_dispatch_notification(const ovs_events_iface_info_t *ifinfo) {
+static void
+ovs_events_dispatch_notification(const ovs_events_iface_info_t *ifinfo) {
   const char *msg_link_status = NULL;
   notification_t n = {
       NOTIF_FAILURE, cdtime(), "", "", OVS_EVENTS_PLUGIN, "", "", "", NULL};
@@ -334,9 +339,9 @@ static void ovs_events_dispatch_notification(const ovs_events_iface_info_t *ifin
   }
 
   /* fill the notification data */
-  ssnprintf(n.message, sizeof(n.message),
-            "link state of \"%s\" interface has been changed to \"%s\"",
-            ifinfo->name, msg_link_status);
+  snprintf(n.message, sizeof(n.message),
+           "link state of \"%s\" interface has been changed to \"%s\"",
+           ifinfo->name, msg_link_status);
   sstrncpy(n.host, hostname_g, sizeof(n.host));
   sstrncpy(n.plugin_instance, ifinfo->name, sizeof(n.plugin_instance));
   sstrncpy(n.type, "gauge", sizeof(n.type));
@@ -345,7 +350,8 @@ static void ovs_events_dispatch_notification(const ovs_events_iface_info_t *ifin
 }
 
 /* Dispatch OVS interface link status value to collectd */
-static void ovs_events_link_status_submit(const ovs_events_iface_info_t *ifinfo) {
+static void
+ovs_events_link_status_submit(const ovs_events_iface_info_t *ifinfo) {
   value_list_t vl = VALUE_LIST_INIT;
   meta_data_t *meta = NULL;
 
index 31af77c..20b0dd1 100644 (file)
@@ -3,14 +3,17 @@
  *
  * Copyright(c) 2016 Intel Corporation. All rights reserved.
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of
  * this software and associated documentation files (the "Software"), to deal in
  * the Software without restriction, including without limitation the rights to
  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
+ * of the Software, and to permit persons to whom the Software is furnished to
+ * do
  * so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in all
+ * The above copyright notice and this permission notice shall be included in
+ * all
  * copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@@ -711,33 +714,30 @@ static void ovs_stats_initialize(ovs_db_t *pdb) {
                                      "external_ids", NULL};
 
   /* subscribe to a tables */
-  ovs_db_table_cb_register(pdb, "Bridge", bridge_columns,
-                           ovs_stats_bridge_table_change_cb,
+  ovs_db_table_cb_register(
+      pdb, "Bridge", bridge_columns, ovs_stats_bridge_table_change_cb,
       ovs_stats_bridge_table_result_cb,
-                           OVS_DB_TABLE_CB_FLAG_INITIAL |
-                           OVS_DB_TABLE_CB_FLAG_INSERT |
+      OVS_DB_TABLE_CB_FLAG_INITIAL | OVS_DB_TABLE_CB_FLAG_INSERT |
           OVS_DB_TABLE_CB_FLAG_MODIFY);
 
   ovs_db_table_cb_register(pdb, "Bridge", bridge_columns,
                            ovs_stats_bridge_table_delete_cb, NULL,
                            OVS_DB_TABLE_CB_FLAG_DELETE);
 
-  ovs_db_table_cb_register(pdb, "Port", port_columns,
-                           ovs_stats_port_table_change_cb,
+  ovs_db_table_cb_register(
+      pdb, "Port", port_columns, ovs_stats_port_table_change_cb,
       ovs_stats_port_table_result_cb,
-                           OVS_DB_TABLE_CB_FLAG_INITIAL |
-                           OVS_DB_TABLE_CB_FLAG_INSERT |
+      OVS_DB_TABLE_CB_FLAG_INITIAL | OVS_DB_TABLE_CB_FLAG_INSERT |
           OVS_DB_TABLE_CB_FLAG_MODIFY);
 
   ovs_db_table_cb_register(pdb, "Port", port_columns,
                            ovs_stats_port_table_delete_cb, NULL,
                            OVS_DB_TABLE_CB_FLAG_DELETE);
 
-  ovs_db_table_cb_register(pdb, "Interface", interface_columns,
-                           ovs_stats_interface_table_change_cb,
+  ovs_db_table_cb_register(
+      pdb, "Interface", interface_columns, ovs_stats_interface_table_change_cb,
       ovs_stats_interface_table_result_cb,
-                           OVS_DB_TABLE_CB_FLAG_INITIAL |
-                           OVS_DB_TABLE_CB_FLAG_INSERT |
+      OVS_DB_TABLE_CB_FLAG_INITIAL | OVS_DB_TABLE_CB_FLAG_INSERT |
           OVS_DB_TABLE_CB_FLAG_MODIFY);
 }
 
@@ -862,8 +862,8 @@ static int ovs_stats_plugin_init(void) {
        plugin_name, ovs_stats_cfg.ovs_db_node, ovs_stats_cfg.ovs_db_serv,
        ovs_stats_cfg.ovs_db_unix);
   /* connect to OvS DB */
-  if ((g_ovs_db = ovs_db_init (ovs_stats_cfg.ovs_db_node,
-                             ovs_stats_cfg.ovs_db_serv,
+  if ((g_ovs_db =
+           ovs_db_init(ovs_stats_cfg.ovs_db_node, ovs_stats_cfg.ovs_db_serv,
                        ovs_stats_cfg.ovs_db_unix, &cb)) == NULL) {
     ERROR("%s: plugin: failed to connect to OvS DB server", plugin_name);
     return -1;
index e922bad..7c8a615 100644 (file)
@@ -494,7 +494,8 @@ static int av2data_set(pTHX_ AV *array, char *name, data_set_t *ds) {
  *   meta     => [ { name => <name>, value => <value> }, ... ]
  * }
  */
-static int av2notification_meta(pTHX_ AV *array, notification_meta_t **ret_meta) {
+static int av2notification_meta(pTHX_ AV *array,
+                                notification_meta_t **ret_meta) {
   notification_meta_t *tail = NULL;
 
   int len = av_len(array);
@@ -881,9 +882,9 @@ static int oconfig_item2hv(pTHX_ oconfig_item_t *ci, HV *hash) {
 static char *get_module_name(char *buf, size_t buf_len, const char *module) {
   int status = 0;
   if (base_name[0] == '\0')
-    status = ssnprintf(buf, buf_len, "%s", module);
+    status = snprintf(buf, buf_len, "%s", module);
   else
-    status = ssnprintf(buf, buf_len, "%s::%s", base_name, module);
+    status = snprintf(buf, buf_len, "%s::%s", base_name, module);
   if ((status < 0) || ((unsigned int)status >= buf_len))
     return NULL;
   return buf;
@@ -2349,14 +2350,25 @@ static int g_interval_set(pTHX_ SV *var, MAGIC *mg) {
   return 0;
 } /* static int g_interval_set (pTHX_ SV *, MAGIC *) */
 
-static MGVTBL g_pv_vtbl = {g_pv_get, g_pv_set, NULL, NULL, NULL, NULL, NULL
+static MGVTBL g_pv_vtbl = {g_pv_get,
+                           g_pv_set,
+                           NULL,
+                           NULL,
+                           NULL,
+                           NULL,
+                           NULL
 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
                            ,
                            NULL
 #endif
 };
-static MGVTBL g_interval_vtbl = {g_interval_get, g_interval_set, NULL, NULL,
-                                 NULL, NULL, NULL
+static MGVTBL g_interval_vtbl = {g_interval_get,
+                                 g_interval_set,
+                                 NULL,
+                                 NULL,
+                                 NULL,
+                                 NULL,
+                                 NULL
 #if HAVE_PERL_STRUCT_MGVTBL_SVT_LOCAL
                                  ,
                                  NULL
index d0c0ae1..56730b4 100644 (file)
@@ -58,7 +58,7 @@
  * is ignored. */
 #define C_PSQL_PAR_APPEND(buf, buf_len, parameter, value)                      \
   if ((0 < (buf_len)) && (NULL != (value)) && ('\0' != *(value))) {            \
-    int s = ssnprintf(buf, buf_len, " %s = '%s'", parameter, value);           \
+    int s = snprintf(buf, buf_len, " %s = '%s'", parameter, value);            \
     if (0 < s) {                                                               \
       buf += s;                                                                \
       buf_len -= s;                                                            \
@@ -322,7 +322,7 @@ static int c_psql_connect(c_psql_database_t *db) {
   if ((!db) || (!db->database))
     return -1;
 
-  status = ssnprintf(buf, buf_len, "dbname = '%s'", db->database);
+  status = snprintf(buf, buf_len, "dbname = '%s'", db->database);
   if (0 < status) {
     buf += status;
     buf_len -= status;
@@ -424,9 +424,9 @@ static PGresult *c_psql_exec_query_params(c_psql_database_t *db, udb_query_t *q,
       params[i] = db->user;
       break;
     case C_PSQL_PARAM_INTERVAL:
-      ssnprintf(interval, sizeof(interval), "%.3f",
-                (db->interval > 0) ? CDTIME_T_TO_DOUBLE(db->interval)
-                                   : plugin_get_interval());
+      snprintf(interval, sizeof(interval), "%.3f",
+               (db->interval > 0) ? CDTIME_T_TO_DOUBLE(db->interval)
+                                  : plugin_get_interval());
       params[i] = interval;
       break;
     case C_PSQL_PARAM_INSTANCE:
@@ -438,7 +438,7 @@ static PGresult *c_psql_exec_query_params(c_psql_database_t *db, udb_query_t *q,
   }
 
   return PQexecParams(db->conn, udb_query_get_statement(q), data->params_num,
-                      NULL, (const char *const*)params, NULL, NULL, 0);
+                      NULL, (const char *const *)params, NULL, NULL, 0);
 } /* c_psql_exec_query_params */
 
 /* db->db_lock must be locked when calling this function */
@@ -629,7 +629,7 @@ static char *values_name_to_sqlarray(const data_set_t *ds, char *string,
   str_len = string_len;
 
   for (size_t i = 0; i < ds->ds_num; ++i) {
-    int status = ssnprintf(str_ptr, str_len, ",'%s'", ds->ds[i].name);
+    int status = snprintf(str_ptr, str_len, ",'%s'", ds->ds[i].name);
 
     if (status < 1)
       return NULL;
@@ -667,10 +667,10 @@ static char *values_type_to_sqlarray(const data_set_t *ds, char *string,
     int status;
 
     if (store_rates)
-      status = ssnprintf(str_ptr, str_len, ",'gauge'");
+      status = snprintf(str_ptr, str_len, ",'gauge'");
     else
-      status = ssnprintf(str_ptr, str_len, ",'%s'",
-                         DS_TYPE_TO_STRING(ds->ds[i].type));
+      status = snprintf(str_ptr, str_len, ",'%s'",
+                        DS_TYPE_TO_STRING(ds->ds[i].type));
 
     if (status < 1) {
       str_len = 0;
@@ -722,7 +722,7 @@ static char *values_to_sqlarray(const data_set_t *ds, const value_list_t *vl,
 
     if (ds->ds[i].type == DS_TYPE_GAUGE)
       status =
-          ssnprintf(str_ptr, str_len, "," GAUGE_FORMAT, vl->values[i].gauge);
+          snprintf(str_ptr, str_len, "," GAUGE_FORMAT, vl->values[i].gauge);
     else if (store_rates) {
       if (rates == NULL)
         rates = uc_get_rate(ds, vl);
@@ -732,13 +732,13 @@ static char *values_to_sqlarray(const data_set_t *ds, const value_list_t *vl,
         return NULL;
       }
 
-      status = ssnprintf(str_ptr, str_len, ",%lf", rates[i]);
+      status = snprintf(str_ptr, str_len, ",%lf", rates[i]);
     } else if (ds->ds[i].type == DS_TYPE_COUNTER)
-      status = ssnprintf(str_ptr, str_len, ",%llu", vl->values[i].counter);
+      status = snprintf(str_ptr, str_len, ",%llu", vl->values[i].counter);
     else if (ds->ds[i].type == DS_TYPE_DERIVE)
-      status = ssnprintf(str_ptr, str_len, ",%" PRIi64, vl->values[i].derive);
+      status = snprintf(str_ptr, str_len, ",%" PRIi64, vl->values[i].derive);
     else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
-      status = ssnprintf(str_ptr, str_len, ",%" PRIu64, vl->values[i].absolute);
+      status = snprintf(str_ptr, str_len, ",%" PRIu64, vl->values[i].absolute);
 
     if (status < 1) {
       str_len = 0;
@@ -936,7 +936,7 @@ static int c_psql_shutdown(void) {
 
     if (db->writers_num > 0) {
       char cb_name[DATA_MAX_NAME_LEN];
-      ssnprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->database);
+      snprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->database);
 
       if (!had_flush) {
         plugin_unregister_flush("postgresql");
@@ -1194,7 +1194,7 @@ static int c_psql_config_database(oconfig_item_t *ci) {
     }
   }
 
-  ssnprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->instance);
+  snprintf(cb_name, sizeof(cb_name), "postgresql-%s", db->instance);
 
   user_data_t ud = {.data = db, .free_func = c_psql_database_delete};
 
index 82a4859..4fec161 100644 (file)
@@ -805,7 +805,7 @@ static int ps_read_tasks_status(process_entry_t *ps) {
   char *fields[8];
   int numfields;
 
-  ssnprintf(dirname, sizeof(dirname), "/proc/%li/task", ps->id);
+  snprintf(dirname, sizeof(dirname), "/proc/%li/task", ps->id);
 
   if ((dh = opendir(dirname)) == NULL) {
     DEBUG("Failed to open directory `%s'", dirname);
@@ -820,8 +820,12 @@ static int ps_read_tasks_status(process_entry_t *ps) {
 
     tpid = ent->d_name;
 
-    ssnprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", ps->id,
-              tpid);
+    if (snprintf(filename, sizeof(filename), "/proc/%li/task/%s/status", ps->id,
+                 tpid) >= sizeof(filename)) {
+      DEBUG("Filename too long: `%s'", filename);
+      continue;
+    }
+
     if ((fh = fopen(filename, "r")) == NULL) {
       DEBUG("Failed to open file `%s'", filename);
       continue;
@@ -878,7 +882,7 @@ static int ps_read_status(long pid, process_entry_t *ps) {
   char *fields[8];
   int numfields;
 
-  ssnprintf(filename, sizeof(filename), "/proc/%li/status", pid);
+  snprintf(filename, sizeof(filename), "/proc/%li/status", pid);
   if ((fh = fopen(filename, "r")) == NULL)
     return -1;
 
@@ -931,7 +935,7 @@ static int ps_read_io(process_entry_t *ps) {
   char *fields[8];
   int numfields;
 
-  ssnprintf(filename, sizeof(filename), "/proc/%li/io", ps->id);
+  snprintf(filename, sizeof(filename), "/proc/%li/io", ps->id);
   if ((fh = fopen(filename, "r")) == NULL) {
     DEBUG("ps_read_io: Failed to open file `%s'", filename);
     return -1;
@@ -980,7 +984,7 @@ static int ps_count_fd(int pid) {
   struct dirent *ent;
   int count = 0;
 
-  ssnprintf(dirname, sizeof(dirname), "/proc/%i/fd", pid);
+  snprintf(dirname, sizeof(dirname), "/proc/%i/fd", pid);
 
   if ((dh = opendir(dirname)) == NULL) {
     DEBUG("Failed to open directory `%s'", dirname);
@@ -1041,7 +1045,7 @@ static int ps_read_process(long pid, process_entry_t *ps, char *state) {
 
   ssize_t status;
 
-  ssnprintf(filename, sizeof(filename), "/proc/%li/stat", pid);
+  snprintf(filename, sizeof(filename), "/proc/%li/stat", pid);
 
   status = read_file_contents(filename, buffer, sizeof(buffer) - 1);
   if (status <= 0)
@@ -1165,7 +1169,7 @@ static char *ps_get_cmdline(long pid, char *name, char *buf, size_t buf_len) {
   if ((pid < 1) || (NULL == buf) || (buf_len < 2))
     return NULL;
 
-  ssnprintf(file, sizeof(file), "/proc/%li/cmdline", pid);
+  snprintf(file, sizeof(file), "/proc/%li/cmdline", pid);
 
   errno = 0;
   fd = open(file, O_RDONLY);
@@ -1220,7 +1224,7 @@ static char *ps_get_cmdline(long pid, char *name, char *buf, size_t buf_len) {
     if (NULL == name)
       return NULL;
 
-    ssnprintf(buf, buf_len, "[%s]", name);
+    snprintf(buf, buf_len, "[%s]", name);
     return buf;
   }
 
index 32e9824..b63dee9 100644 (file)
@@ -156,8 +156,8 @@ static int read_file(const char *path) {
       if (values_list != NULL) {
         char match_name[2 * DATA_MAX_NAME_LEN];
 
-        ssnprintf(match_name, sizeof(match_name), "%s:%s", key_buffer,
-                  key_fields[i]);
+        snprintf(match_name, sizeof(match_name), "%s:%s", key_buffer,
+                 key_fields[i]);
 
         if (ignorelist_match(values_list, match_name))
           continue;
index 4807ba7..ac4b133 100644 (file)
@@ -801,8 +801,8 @@ static PyObject *cpy_register_write(PyObject *self, PyObject *args,
 static PyObject *cpy_register_notification(PyObject *self, PyObject *args,
                                            PyObject *kwds) {
   return cpy_register_generic_userdata((void *)plugin_register_notification,
-                                       (void *)cpy_notification_callback,
-                                       args, kwds);
+                                       (void *)cpy_notification_callback, args,
+                                       kwds);
 }
 
 static PyObject *cpy_register_flush(PyObject *self, PyObject *args,
@@ -971,8 +971,7 @@ static PyObject *cpy_unregister_read(PyObject *self, PyObject *arg) {
 }
 
 static PyObject *cpy_unregister_write(PyObject *self, PyObject *arg) {
-  return cpy_unregister_generic_userdata(plugin_unregister_write, arg,
-                                         "write");
+  return cpy_unregister_generic_userdata(plugin_unregister_write, arg, "write");
 }
 
 static PyObject *cpy_unregister_notification(PyObject *self, PyObject *arg) {
@@ -981,8 +980,7 @@ static PyObject *cpy_unregister_notification(PyObject *self, PyObject *arg) {
 }
 
 static PyObject *cpy_unregister_flush(PyObject *self, PyObject *arg) {
-  return cpy_unregister_generic_userdata(plugin_unregister_flush, arg,
-                                         "flush");
+  return cpy_unregister_generic_userdata(plugin_unregister_flush, arg, "flush");
 }
 
 static PyObject *cpy_unregister_shutdown(PyObject *self, PyObject *arg) {
index 05225b5..7c704ab 100644 (file)
@@ -370,7 +370,7 @@ static int redis_db_stats(char *node, char const *info_line) /* {{{ */
     char *str;
     int i;
 
-    ssnprintf(field_name, sizeof(field_name), "db%d:keys=", db);
+    snprintf(field_name, sizeof(field_name), "db%d:keys=", db);
 
     str = strstr(info_line, field_name);
     if (!str)
@@ -386,7 +386,7 @@ static int redis_db_stats(char *node, char const *info_line) /* {{{ */
       return -1;
     }
 
-    ssnprintf(db_id, sizeof(db_id), "%d", db);
+    snprintf(db_id, sizeof(db_id), "%d", db);
     redis_submit(node, "records", db_id, val);
   }
   return 0;
index ba92b0b..fa08b3b 100644 (file)
@@ -89,8 +89,7 @@ static void submit_interface(cr_data_t *rd, /* {{{ */
 
 static int handle_interface(__attribute__((unused))
                             ros_connection_t *c, /* {{{ */
-                            const ros_interface_t *i,
-                            void *user_data) {
+                            const ros_interface_t *i, void *user_data) {
   if ((i == NULL) || (user_data == NULL))
     return EINVAL;
 
@@ -142,8 +141,8 @@ static void submit_regtable(cr_data_t *rd, /* {{{ */
     return;
 
   /*** RX ***/
-  ssnprintf(type_instance, sizeof(type_instance), "%s-%s-rx", r->interface,
-            r->radio_name);
+  snprintf(type_instance, sizeof(type_instance), "%s-%s-rx", r->interface,
+           r->radio_name);
   cr_submit_gauge(rd, "bitrate", type_instance,
                   (gauge_t)(1000000.0 * r->rx_rate));
   cr_submit_gauge(rd, "signal_power", type_instance,
@@ -151,8 +150,8 @@ static void submit_regtable(cr_data_t *rd, /* {{{ */
   cr_submit_gauge(rd, "signal_quality", type_instance, (gauge_t)r->rx_ccq);
 
   /*** TX ***/
-  ssnprintf(type_instance, sizeof(type_instance), "%s-%s-tx", r->interface,
-            r->radio_name);
+  snprintf(type_instance, sizeof(type_instance), "%s-%s-tx", r->interface,
+           r->radio_name);
   cr_submit_gauge(rd, "bitrate", type_instance,
                   (gauge_t)(1000000.0 * r->tx_rate));
   cr_submit_gauge(rd, "signal_power", type_instance,
@@ -160,8 +159,8 @@ static void submit_regtable(cr_data_t *rd, /* {{{ */
   cr_submit_gauge(rd, "signal_quality", type_instance, (gauge_t)r->tx_ccq);
 
   /*** RX / TX ***/
-  ssnprintf(type_instance, sizeof(type_instance), "%s-%s", r->interface,
-            r->radio_name);
+  snprintf(type_instance, sizeof(type_instance), "%s-%s", r->interface,
+           r->radio_name);
   cr_submit_io(rd, "if_octets", type_instance, (derive_t)r->rx_bytes,
                (derive_t)r->tx_bytes);
   cr_submit_gauge(rd, "snr", type_instance, (gauge_t)r->signal_to_noise);
@@ -171,8 +170,7 @@ static void submit_regtable(cr_data_t *rd, /* {{{ */
 
 static int handle_regtable(__attribute__((unused))
                            ros_connection_t *c, /* {{{ */
-                           const ros_registration_table_t *r,
-                           void *user_data) {
+                           const ros_registration_table_t *r, void *user_data) {
   if ((r == NULL) || (user_data == NULL))
     return EINVAL;
 
@@ -378,7 +376,7 @@ static int cr_config_router(oconfig_item_t *ci) /* {{{ */
     }
   }
 
-  ssnprintf(read_name, sizeof(read_name), "routeros/%s", router_data->node);
+  snprintf(read_name, sizeof(read_name), "routeros/%s", router_data->node);
   if (status == 0)
     status = plugin_register_complex_read(
         /* group = */ NULL, read_name, cr_read, /* interval = */ 0,
index 4efb1f0..8287013 100644 (file)
@@ -75,7 +75,7 @@ static int value_list_to_string(char *buffer, int buffer_len,
   memset(buffer, '\0', buffer_len);
 
   t = CDTIME_T_TO_TIME_T(vl->time);
-  status = ssnprintf(buffer, buffer_len, "%lu", (unsigned long)t);
+  status = snprintf(buffer, buffer_len, "%lu", (unsigned long)t);
   if ((status < 1) || (status >= buffer_len))
     return -1;
   offset = status;
@@ -88,17 +88,17 @@ static int value_list_to_string(char *buffer, int buffer_len,
       return -1;
 
     if (ds->ds[i].type == DS_TYPE_COUNTER) {
-      status = ssnprintf(buffer + offset, buffer_len - offset, ":%llu",
-                         vl->values[i].counter);
+      status = snprintf(buffer + offset, buffer_len - offset, ":%llu",
+                        vl->values[i].counter);
     } else if (ds->ds[i].type == DS_TYPE_GAUGE) {
-      status = ssnprintf(buffer + offset, buffer_len - offset, ":%f",
-                         vl->values[i].gauge);
+      status = snprintf(buffer + offset, buffer_len - offset, ":%f",
+                        vl->values[i].gauge);
     } else if (ds->ds[i].type == DS_TYPE_DERIVE) {
-      status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIi64,
-                         vl->values[i].derive);
+      status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIi64,
+                        vl->values[i].derive);
     } else /* if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */ {
-      status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIu64,
-                         vl->values[i].absolute);
+      status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIu64,
+                        vl->values[i].absolute);
     }
 
     if ((status < 1) || (status >= (buffer_len - offset)))
@@ -482,9 +482,9 @@ static int rc_flush(__attribute__((unused)) cdtime_t timeout, /* {{{ */
     return EINVAL;
 
   if (datadir != NULL)
-    ssnprintf(filename, sizeof(filename), "%s/%s.rrd", datadir, identifier);
+    snprintf(filename, sizeof(filename), "%s/%s.rrd", datadir, identifier);
   else
-    ssnprintf(filename, sizeof(filename), "%s.rrd", identifier);
+    snprintf(filename, sizeof(filename), "%s.rrd", identifier);
 
   rrd_clear_error();
   status = rrdc_connect(daemon_address);
index 5a71ebe..4128905 100644 (file)
@@ -177,7 +177,7 @@ static int value_list_to_string_multiple(char *buffer, int buffer_len,
   memset(buffer, '\0', buffer_len);
 
   tt = CDTIME_T_TO_TIME_T(vl->time);
-  status = ssnprintf(buffer, buffer_len, "%u", (unsigned int)tt);
+  status = snprintf(buffer, buffer_len, "%u", (unsigned int)tt);
   if ((status < 1) || (status >= buffer_len))
     return -1;
   offset = status;
@@ -190,17 +190,17 @@ static int value_list_to_string_multiple(char *buffer, int buffer_len,
       return -1;
 
     if (ds->ds[i].type == DS_TYPE_COUNTER)
-      status = ssnprintf(buffer + offset, buffer_len - offset, ":%llu",
-                         vl->values[i].counter);
+      status = snprintf(buffer + offset, buffer_len - offset, ":%llu",
+                        vl->values[i].counter);
     else if (ds->ds[i].type == DS_TYPE_GAUGE)
-      status = ssnprintf(buffer + offset, buffer_len - offset, ":" GAUGE_FORMAT,
-                         vl->values[i].gauge);
+      status = snprintf(buffer + offset, buffer_len - offset, ":" GAUGE_FORMAT,
+                        vl->values[i].gauge);
     else if (ds->ds[i].type == DS_TYPE_DERIVE)
-      status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIi64,
-                         vl->values[i].derive);
+      status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIi64,
+                        vl->values[i].derive);
     else /*if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */
-      status = ssnprintf(buffer + offset, buffer_len - offset, ":%" PRIu64,
-                         vl->values[i].absolute);
+      status = snprintf(buffer + offset, buffer_len - offset, ":%" PRIu64,
+                        vl->values[i].absolute);
 
     if ((status < 1) || (status >= (buffer_len - offset)))
       return -1;
@@ -222,20 +222,20 @@ static int value_list_to_string(char *buffer, int buffer_len,
   tt = CDTIME_T_TO_TIME_T(vl->time);
   switch (ds->ds[0].type) {
   case DS_TYPE_DERIVE:
-    status = ssnprintf(buffer, buffer_len, "%u:%" PRIi64, (unsigned)tt,
-                       vl->values[0].derive);
+    status = snprintf(buffer, buffer_len, "%u:%" PRIi64, (unsigned)tt,
+                      vl->values[0].derive);
     break;
   case DS_TYPE_GAUGE:
-    status = ssnprintf(buffer, buffer_len, "%u:" GAUGE_FORMAT, (unsigned)tt,
-                       vl->values[0].gauge);
+    status = snprintf(buffer, buffer_len, "%u:" GAUGE_FORMAT, (unsigned)tt,
+                      vl->values[0].gauge);
     break;
   case DS_TYPE_COUNTER:
-    status = ssnprintf(buffer, buffer_len, "%u:%llu", (unsigned)tt,
-                       vl->values[0].counter);
+    status = snprintf(buffer, buffer_len, "%u:%llu", (unsigned)tt,
+                      vl->values[0].counter);
     break;
   case DS_TYPE_ABSOLUTE:
-    status = ssnprintf(buffer, buffer_len, "%u:%" PRIu64, (unsigned)tt,
-                       vl->values[0].absolute);
+    status = snprintf(buffer, buffer_len, "%u:%" PRIu64, (unsigned)tt,
+                      vl->values[0].absolute);
     break;
   default:
     return EINVAL;
index ed87c30..f4ecda5 100644 (file)
@@ -176,7 +176,7 @@ static int sensors_snprintf_chip_name(char *buf, size_t buf_size,
   int status = -1;
 
   if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA) {
-    status = ssnprintf(buf, buf_size, "%s-isa-%04x", chip->prefix, chip->addr);
+    status = snprintf(buf, buf_size, "%s-isa-%04x", chip->prefix, chip->addr);
   } else if (chip->bus == SENSORS_CHIP_NAME_BUS_DUMMY) {
     status = snprintf(buf, buf_size, "%s-%s-%04x", chip->prefix, chip->busname,
                       chip->addr);
@@ -436,8 +436,8 @@ static void sensors_submit(const char *plugin_instance, const char *type,
 
   value_list_t vl = VALUE_LIST_INIT;
 
-  status = ssnprintf(match_key, sizeof(match_key), "%s/%s-%s", plugin_instance,
-                     type, type_instance);
+  status = snprintf(match_key, sizeof(match_key), "%s/%s-%s", plugin_instance,
+                    type, type_instance);
   if (status < 1)
     return;
 
index 44920ad..8a325fe 100644 (file)
@@ -247,10 +247,10 @@ static int sigrok_init_driver(struct config_device *cfdev,
   }
   cfdev->sdi = devlist->data;
   g_slist_free(devlist);
-  ssnprintf(hwident, sizeof(hwident), "%s %s %s",
-            cfdev->sdi->vendor ? cfdev->sdi->vendor : "",
-            cfdev->sdi->model ? cfdev->sdi->model : "",
-            cfdev->sdi->version ? cfdev->sdi->version : "");
+  snprintf(hwident, sizeof(hwident), "%s %s %s",
+           cfdev->sdi->vendor ? cfdev->sdi->vendor : "",
+           cfdev->sdi->model ? cfdev->sdi->model : "",
+           cfdev->sdi->version ? cfdev->sdi->version : "");
   INFO("sigrok plugin: Device \"%s\" is a %s", cfdev->name, hwident);
 
   if (sr_dev_open(cfdev->sdi) != SR_OK)
index 0e4e192..30680be 100644 (file)
@@ -116,9 +116,9 @@ static void handle_attribute(SkDisk *d, const SkSmartAttributeParsedData *a,
     sstrncpy(notif.host, hostname_g, sizeof(notif.host));
     sstrncpy(notif.plugin_instance, name, sizeof(notif.plugin_instance));
     sstrncpy(notif.type_instance, a->name, sizeof(notif.type_instance));
-    ssnprintf(notif.message, sizeof(notif.message),
-              "attribute %s is below allowed threshold (%d < %d)", a->name,
-              a->current_value, a->threshold);
+    snprintf(notif.message, sizeof(notif.message),
+             "attribute %s is below allowed threshold (%d < %d)", a->name,
+             a->current_value, a->threshold);
     plugin_dispatch_notification(&notif);
   }
 }
index 77349f6..c299db9 100644 (file)
@@ -130,8 +130,7 @@ static void csnmp_oid_init(oid_t *dst, oid const *src, size_t n) {
 }
 
 static int csnmp_oid_compare(oid_t const *left, oid_t const *right) {
-  return snmp_oid_compare(left->oid, left->oid_len, right->oid,
-                          right->oid_len);
+  return snmp_oid_compare(left->oid, left->oid_len, right->oid, right->oid_len);
 }
 
 static int csnmp_oid_suffix(oid_t *dst, oid_t const *src, oid_t const *root) {
@@ -155,7 +154,7 @@ static int csnmp_oid_to_string(char *buffer, size_t buffer_size,
   char *oid_str_ptr[MAX_OID_LEN];
 
   for (size_t i = 0; i < o->oid_len; i++) {
-    ssnprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]);
+    snprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]);
     oid_str_ptr[i] = oid_str[i];
   }
 
@@ -703,7 +702,7 @@ static int csnmp_config_add_host(oconfig_item_t *ci) {
         "= %i }",
         hd->name, hd->address, hd->community, hd->version);
 
-  ssnprintf(cb_name, sizeof(cb_name), "snmp-%s", hd->name);
+  snprintf(cb_name, sizeof(cb_name), "snmp-%s", hd->name);
 
   status = plugin_register_complex_read(
       /* group = */ NULL, cb_name, csnmp_read_host, hd->interval,
@@ -997,10 +996,10 @@ static int csnmp_strvbcopy(char *dst, /* {{{ */
   else if (vb->type == ASN_BIT_STR)
     src = (char *)vb->val.bitstring;
   else if (vb->type == ASN_IPADDRESS) {
-    return ssnprintf(dst, dst_size,
-                     "%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "",
-                     (uint8_t)vb->val.string[0], (uint8_t)vb->val.string[1],
-                     (uint8_t)vb->val.string[2], (uint8_t)vb->val.string[3]);
+    return snprintf(dst, dst_size,
+                    "%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8 "",
+                    (uint8_t)vb->val.string[0], (uint8_t)vb->val.string[1],
+                    (uint8_t)vb->val.string[2], (uint8_t)vb->val.string[3]);
   } else {
     dst[0] = 0;
     return EINVAL;
@@ -1092,7 +1091,7 @@ static int csnmp_instance_list_add(csnmp_list_instances_t **head,
     value_t val = csnmp_value_list_to_value(
         vb, DS_TYPE_COUNTER,
         /* scale = */ 1.0, /* shift = */ 0.0, hd->name, dd->name);
-    ssnprintf(il->instance, sizeof(il->instance), "%llu", val.counter);
+    snprintf(il->instance, sizeof(il->instance), "%llu", val.counter);
   }
 
   /* TODO: Debugging output */
@@ -1222,8 +1221,8 @@ static int csnmp_dispatch_table(host_definition_t *host,
       if (data->instance_prefix == NULL)
         sstrncpy(vl.type_instance, temp, sizeof(vl.type_instance));
       else
-        ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s%s",
-                  data->instance_prefix, temp);
+        snprintf(vl.type_instance, sizeof(vl.type_instance), "%s%s",
+                 data->instance_prefix, temp);
     }
 
     vl.values_len = data->values_len;
index d7aea2d..497d157 100644 (file)
@@ -98,6 +98,7 @@ static snmp_agent_ctx_t *g_agent = NULL;
       (_dd->type ? !strcmp(_dd->type, _t) : 0) &&                              \
       (_dd->type_instance ? !strcmp(_dd->type_instance, _ti) : 1)
 
+static int snmp_agent_shutdown(void);
 static void *snmp_agent_thread_run(void *arg);
 static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler);
 static int snmp_agent_set_vardata(void *dst_buf, size_t *dst_buf_len,
@@ -123,7 +124,7 @@ static int snmp_agent_oid_to_string(char *buf, size_t buf_size,
   char *oid_str_ptr[MAX_OID_LEN];
 
   for (size_t i = 0; i < o->oid_len; i++) {
-    ssnprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]);
+    snprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]);
     oid_str_ptr[i] = oid_str[i];
   }
 
@@ -165,7 +166,7 @@ static void snmp_agent_dump_data(void) {
         DEBUG(PLUGIN_NAME ":     TypeInstance: %s", dd->type_instance);
       for (size_t i = 0; i < dd->oids_len; i++) {
         snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]);
-        DEBUG(PLUGIN_NAME ":     OID[%d]: %s", i, oid_str);
+        DEBUG(PLUGIN_NAME ":     OID[%zu]: %s", i, oid_str);
       }
       DEBUG(PLUGIN_NAME ":   Scale: %g", dd->scale);
       DEBUG(PLUGIN_NAME ":   Shift: %g", dd->shift);
@@ -189,7 +190,7 @@ static void snmp_agent_dump_data(void) {
       DEBUG(PLUGIN_NAME ":   TypeInstance: %s", dd->type_instance);
     for (size_t i = 0; i < dd->oids_len; i++) {
       snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]);
-      DEBUG(PLUGIN_NAME ":   OID[%d]: %s", i, oid_str);
+      DEBUG(PLUGIN_NAME ":   OID[%zu]: %s", i, oid_str);
     }
     DEBUG(PLUGIN_NAME ":   Scale: %g", dd->scale);
     DEBUG(PLUGIN_NAME ":   Shift: %g", dd->shift);
@@ -282,7 +283,8 @@ static int snmp_agent_validate_data(void) {
   return 0;
 }
 
-static void snmp_agent_generate_oid2string(oid_t *oid, size_t offset, char *key) {
+static void snmp_agent_generate_oid2string(oid_t *oid, size_t offset,
+                                           char *key) {
   int key_len = oid->oid[offset];
   int i;
 
@@ -368,9 +370,9 @@ static int snmp_agent_table_row_remove(table_definition_t *td,
       .severity = NOTIF_WARNING, .time = cdtime(), .plugin = PLUGIN_NAME};
   sstrncpy(n.host, hostname_g, sizeof(n.host));
   sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance));
-  ssnprintf(n.message, sizeof(n.message),
-            "Removed data row from table %s instance %s index %d", td->name,
-            ins, (index != NULL) ? *index : -1);
+  snprintf(n.message, sizeof(n.message),
+           "Removed data row from table %s instance %s index %d", td->name, ins,
+           (index != NULL) ? *index : -1);
   plugin_dispatch_notification(&n);
 
   if (td->index_oid.oid_len) {
@@ -420,28 +422,6 @@ static void snmp_agent_free_data(data_definition_t **dd) {
     for (size_t i = 0; i < (*dd)->oids_len; i++)
       unregister_mib((*dd)->oids[i].oid, (*dd)->oids[i].oid_len);
   }
-  if (!(*dd)->table->index_oid.oid_len) {
-    char *instance;
-
-    c_avl_iterator_t *iter = c_avl_get_iterator((*dd)->table->instance_index);
-    while (c_avl_iterator_next(iter, (void *)&instance, (void *)&instance) ==
-           0) {
-      for (size_t i = 0; i < (*dd)->oids_len; i++)
-        snmp_agent_unregister_oid_string(&(*dd)->oids[i], instance);
-    }
-    c_avl_iterator_destroy(iter);
-  } else {
-    /* unregister all table OIDs */
-    int *index;
-    char *value;
-
-    c_avl_iterator_t *iter = c_avl_get_iterator((*dd)->table->index_instance);
-    while (c_avl_iterator_next(iter, (void *)&index, (void *)&value) == 0) {
-      for (size_t i = 0; i < (*dd)->oids_len; i++)
-        snmp_agent_unregister_oid_index(&(*dd)->oids[i], *index);
-    }
-    c_avl_iterator_destroy(iter);
-  }
 
   sfree((*dd)->name);
   sfree((*dd)->plugin);
@@ -455,6 +435,43 @@ static void snmp_agent_free_data(data_definition_t **dd) {
   return;
 }
 
+static void snmp_agent_free_table_columns(table_definition_t *td) {
+  if (td->columns == NULL)
+    return;
+
+  for (llentry_t *de = llist_head(td->columns); de != NULL; de = de->next) {
+    data_definition_t *dd = de->value;
+
+    if (td->index_oid.oid_len) {
+      int *index;
+      char *instance;
+
+      c_avl_iterator_t *iter = c_avl_get_iterator(td->index_instance);
+      while (c_avl_iterator_next(iter, (void *)&index, (void *)&instance) ==
+             0) {
+        for (size_t i = 0; i < dd->oids_len; i++)
+          snmp_agent_unregister_oid_index(&dd->oids[i], *index);
+      }
+      c_avl_iterator_destroy(iter);
+    } else {
+      char *instance;
+
+      c_avl_iterator_t *iter = c_avl_get_iterator(dd->table->instance_index);
+      while (c_avl_iterator_next(iter, (void *)&instance, (void *)&instance) ==
+             0) {
+        for (size_t i = 0; i < dd->oids_len; i++)
+          snmp_agent_unregister_oid_string(&dd->oids[i], instance);
+      }
+      c_avl_iterator_destroy(iter);
+    }
+
+    snmp_agent_free_data(&dd);
+  }
+
+  llist_destroy(td->columns);
+  td->columns = NULL;
+} /* void snmp_agent_free_table_columns */
+
 static void snmp_agent_free_table(table_definition_t **td) {
 
   if (td == NULL || *td == NULL)
@@ -463,23 +480,20 @@ static void snmp_agent_free_table(table_definition_t **td) {
   if ((*td)->size_oid.oid_len)
     unregister_mib((*td)->size_oid.oid, (*td)->size_oid.oid_len);
 
+  /* Unregister Index OIDs */
   if ((*td)->index_oid.oid_len) {
     int *index;
-    char *value;
+    char *instance;
 
     c_avl_iterator_t *iter = c_avl_get_iterator((*td)->index_instance);
-    while (c_avl_iterator_next(iter, (void *)&index, (void *)&value) == 0)
+    while (c_avl_iterator_next(iter, (void *)&index, (void *)&instance) == 0)
       snmp_agent_unregister_oid_index(&(*td)->index_oid, *index);
 
     c_avl_iterator_destroy(iter);
   }
 
-  for (llentry_t *de = llist_head((*td)->columns); de != NULL; de = de->next) {
-    data_definition_t *dd = de->value;
-    snmp_agent_free_data(&dd);
-  }
-
-  llist_destroy((*td)->columns);
+  /* Unregister all table columns and their registered OIDs */
+  snmp_agent_free_table_columns(*td);
 
   void *key = NULL;
   void *value = NULL;
@@ -616,9 +630,9 @@ snmp_agent_table_oid_handler(struct netsnmp_mib_handler_s *handler,
 
         if (dd->is_instance) {
           requests->requestvb->type = ASN_OCTET_STR;
-          snmp_set_var_typed_value(requests->requestvb,
-                                   requests->requestvb->type, (const u_char *)instance,
-                                   strlen((instance)));
+          snmp_set_var_typed_value(
+              requests->requestvb, requests->requestvb->type,
+              (const u_char *)instance, strlen((instance)));
 
           pthread_mutex_unlock(&g_agent->lock);
 
@@ -1305,9 +1319,9 @@ static int snmp_agent_update_index(table_definition_t *td,
       .severity = NOTIF_OKAY, .time = cdtime(), .plugin = PLUGIN_NAME};
   sstrncpy(n.host, hostname_g, sizeof(n.host));
   sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance));
-  ssnprintf(n.message, sizeof(n.message),
-            "Data row added to table %s instance %s index %d", td->name, ins,
-            (index != NULL) ? *index : -1);
+  snprintf(n.message, sizeof(n.message),
+           "Data row added to table %s instance %s index %d", td->name, ins,
+           (index != NULL) ? *index : -1);
   plugin_dispatch_notification(&n);
 
   return 0;
@@ -1364,12 +1378,21 @@ static int snmp_agent_preinit(void) {
   g_agent->tables = llist_create();
   g_agent->scalars = llist_create();
 
+  if (g_agent->tables == NULL || g_agent->scalars == NULL) {
+    ERROR(PLUGIN_NAME ": llist_create() failed");
+    llist_destroy(g_agent->scalars);
+    llist_destroy(g_agent->tables);
+    return -ENOMEM;
+  }
+
   int err;
   /* make us a agentx client. */
   err = netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE,
                                1);
   if (err != 0) {
     ERROR(PLUGIN_NAME ": Failed to set agent role (%d)", err);
+    llist_destroy(g_agent->scalars);
+    llist_destroy(g_agent->tables);
     return -1;
   }
 
@@ -1381,6 +1404,8 @@ static int snmp_agent_preinit(void) {
   err = init_agent(PLUGIN_NAME);
   if (err != 0) {
     ERROR(PLUGIN_NAME ": Failed to initialize the agent library (%d)", err);
+    llist_destroy(g_agent->scalars);
+    llist_destroy(g_agent->tables);
     return -1;
   }
 
@@ -1394,9 +1419,13 @@ static int snmp_agent_preinit(void) {
 static int snmp_agent_init(void) {
   int ret;
 
-  ret = snmp_agent_preinit();
-  if (ret != 0)
-    return ret;
+  if (g_agent == NULL || ((llist_head(g_agent->scalars) == NULL) &&
+                          (llist_head(g_agent->tables) == NULL))) {
+    ERROR(PLUGIN_NAME ": snmp_agent_init: plugin not configured");
+    return -EINVAL;
+  }
+
+  plugin_register_shutdown(PLUGIN_NAME, snmp_agent_shutdown);
 
   ret = snmp_agent_register_scalar_oids();
   if (ret != 0)
@@ -1406,13 +1435,6 @@ static int snmp_agent_init(void) {
   if (ret != 0)
     return ret;
 
-  /* create a second thread to listen for requests from AgentX*/
-  ret = pthread_create(&g_agent->thread, NULL, &snmp_agent_thread_run, NULL);
-  if (ret != 0) {
-    ERROR(PLUGIN_NAME ": Failed to create a separate thread, err %u", ret);
-    return ret;
-  }
-
   ret = pthread_mutex_init(&g_agent->lock, NULL);
   if (ret != 0) {
     ERROR(PLUGIN_NAME ": Failed to initialize mutex, err %u", ret);
@@ -1425,6 +1447,18 @@ static int snmp_agent_init(void) {
     return ret;
   }
 
+  /* create a second thread to listen for requests from AgentX*/
+  ret = pthread_create(&g_agent->thread, NULL, &snmp_agent_thread_run, NULL);
+  if (ret != 0) {
+    ERROR(PLUGIN_NAME ": Failed to create a separate thread, err %u", ret);
+    return ret;
+  }
+
+  if (llist_head(g_agent->tables) != NULL) {
+    plugin_register_write(PLUGIN_NAME, snmp_agent_collect, NULL);
+    plugin_register_missing(PLUGIN_NAME, snmp_agent_clear_missing, NULL);
+  }
+
   return 0;
 }
 
@@ -1570,7 +1604,4 @@ static int snmp_agent_config(oconfig_item_t *ci) {
 void module_register(void) {
   plugin_register_init(PLUGIN_NAME, snmp_agent_init);
   plugin_register_complex_config(PLUGIN_NAME, snmp_agent_config);
-  plugin_register_write(PLUGIN_NAME, snmp_agent_collect, NULL);
-  plugin_register_missing(PLUGIN_NAME, snmp_agent_clear_missing, NULL);
-  plugin_register_shutdown(PLUGIN_NAME, snmp_agent_shutdown);
 }
index e1b52cb..5142613 100644 (file)
@@ -605,8 +605,9 @@ static int statsd_config_timer_percentile(oconfig_item_t *ci) /* {{{ */
     return ERANGE;
   }
 
-  tmp = realloc(conf_timer_percentile, sizeof(*conf_timer_percentile) *
-                                           (conf_timer_percentile_num + 1));
+  tmp =
+      realloc(conf_timer_percentile,
+              sizeof(*conf_timer_percentile) * (conf_timer_percentile_num + 1));
   if (tmp == NULL) {
     ERROR("statsd plugin: realloc failed.");
     return ENOMEM;
@@ -731,7 +732,7 @@ static int statsd_metric_submit_unsafe(char const *name,
     /* Make sure all timer metrics share the *same* timestamp. */
     vl.time = cdtime();
 
-    ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-average", name);
+    snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-average", name);
     vl.values[0].gauge =
         have_events
             ? CDTIME_T_TO_DOUBLE(latency_counter_get_average(metric->latency))
@@ -739,7 +740,7 @@ static int statsd_metric_submit_unsafe(char const *name,
     plugin_dispatch_values(&vl);
 
     if (conf_timer_lower) {
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-lower", name);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-lower", name);
       vl.values[0].gauge =
           have_events
               ? CDTIME_T_TO_DOUBLE(latency_counter_get_min(metric->latency))
@@ -748,7 +749,7 @@ static int statsd_metric_submit_unsafe(char const *name,
     }
 
     if (conf_timer_upper) {
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-upper", name);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-upper", name);
       vl.values[0].gauge =
           have_events
               ? CDTIME_T_TO_DOUBLE(latency_counter_get_max(metric->latency))
@@ -757,7 +758,7 @@ static int statsd_metric_submit_unsafe(char const *name,
     }
 
     if (conf_timer_sum) {
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-sum", name);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-sum", name);
       vl.values[0].gauge =
           have_events
               ? CDTIME_T_TO_DOUBLE(latency_counter_get_sum(metric->latency))
@@ -766,8 +767,8 @@ static int statsd_metric_submit_unsafe(char const *name,
     }
 
     for (size_t i = 0; i < conf_timer_percentile_num; i++) {
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance),
-                "%s-percentile-%.0f", name, conf_timer_percentile[i]);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-percentile-%.0f",
+               name, conf_timer_percentile[i]);
       vl.values[0].gauge =
           have_events ? CDTIME_T_TO_DOUBLE(latency_counter_get_percentile(
                             metric->latency, conf_timer_percentile[i]))
@@ -779,7 +780,7 @@ static int statsd_metric_submit_unsafe(char const *name,
      * vl.type's above are implicitly set to "latency". */
     if (conf_timer_count) {
       sstrncpy(vl.type, "gauge", sizeof(vl.type));
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-count", name);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-count", name);
       vl.values[0].gauge = latency_counter_get_num(metric->latency);
       plugin_dispatch_values(&vl);
     }
index 746ba51..a5531c2 100644 (file)
@@ -410,7 +410,7 @@ static int swap_read(void) /* {{{ */
 
   return 0;
 } /* }}} int swap_read */
-  /* #endif KERNEL_LINUX */
+/* #endif KERNEL_LINUX */
 
 /*
  * Under Solaris, two mechanisms can be used to read swap statistics, swapctl
index 8192d6a..90a97fb 100644 (file)
@@ -107,7 +107,7 @@ static int sl_notification(const notification_t *n,
 
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
-    status = ssnprintf(&buf[offset], sizeof(buf) - offset, __VA_ARGS__);       \
+    status = snprintf(&buf[offset], sizeof(buf) - offset, __VA_ARGS__);        \
     if (status < 1)                                                            \
       return -1;                                                               \
     else if (((size_t)status) >= (sizeof(buf) - offset))                       \
index 1b720b8..407970a 100644 (file)
@@ -309,7 +309,7 @@ static int ctail_init(void) {
   }
 
   for (size_t i = 0; i < tail_match_list_num; i++) {
-    ssnprintf(str, sizeof(str), "tail-%zu", i);
+    snprintf(str, sizeof(str), "tail-%zu", i);
 
     plugin_register_complex_read(NULL, str, ctail_read,
                                  tail_match_list_intervals[i],
index d512a52..9d0a15b 100644 (file)
@@ -475,7 +475,7 @@ static int tcsv_config_add_file(oconfig_item_t *ci) {
     return -1;
   }
 
-  ssnprintf(cb_name, sizeof(cb_name), "tail_csv/%s", id->path);
+  snprintf(cb_name, sizeof(cb_name), "tail_csv/%s", id->path);
 
   status = plugin_register_complex_read(
       NULL, cb_name, tcsv_read, id->interval,
index 2041510..429e256 100644 (file)
@@ -221,7 +221,7 @@ static int tn_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
     char template[DATA_MAX_NAME_LEN];
     char value_str[DATA_MAX_NAME_LEN];
 
-    ssnprintf(template, sizeof(template), "%%{ds:%s}", ds->ds[i].name);
+    snprintf(template, sizeof(template), "%%{ds:%s}", ds->ds[i].name);
 
     if (ds->ds[i].type != DS_TYPE_GAUGE) {
       if ((rates == NULL) && (rates_failed == 0)) {
@@ -233,12 +233,12 @@ static int tn_invoke(const data_set_t *ds, value_list_t *vl, /* {{{ */
 
     /* If this is a gauge value, use the current value. */
     if (ds->ds[i].type == DS_TYPE_GAUGE)
-      ssnprintf(value_str, sizeof(value_str), GAUGE_FORMAT,
-                (double)vl->values[i].gauge);
+      snprintf(value_str, sizeof(value_str), GAUGE_FORMAT,
+               (double)vl->values[i].gauge);
     /* If it's a counter, try to use the current rate. This may fail, if the
      * value has been renamed. */
     else if (rates != NULL)
-      ssnprintf(value_str, sizeof(value_str), GAUGE_FORMAT, (double)rates[i]);
+      snprintf(value_str, sizeof(value_str), GAUGE_FORMAT, (double)rates[i]);
     /* Since we don't know any better, use the string `unknown'. */
     else
       sstrncpy(value_str, "unknown", sizeof(value_str));
index 8ec53d4..1cc5d79 100644 (file)
@@ -56,12 +56,12 @@ static int ts_invoke_counter(const data_set_t *ds, value_list_t *vl, /* {{{ */
 
   curr_counter = (uint64_t)vl->values[dsrc_index].counter;
 
-  ssnprintf(key_prev_counter, sizeof(key_prev_counter),
-            "target_scale[%p,%i]:prev_counter", (void *)data, dsrc_index);
-  ssnprintf(key_int_counter, sizeof(key_int_counter),
-            "target_scale[%p,%i]:int_counter", (void *)data, dsrc_index);
-  ssnprintf(key_int_fraction, sizeof(key_int_fraction),
-            "target_scale[%p,%i]:int_fraction", (void *)data, dsrc_index);
+  snprintf(key_prev_counter, sizeof(key_prev_counter),
+           "target_scale[%p,%i]:prev_counter", (void *)data, dsrc_index);
+  snprintf(key_int_counter, sizeof(key_int_counter),
+           "target_scale[%p,%i]:int_counter", (void *)data, dsrc_index);
+  snprintf(key_int_fraction, sizeof(key_int_fraction),
+           "target_scale[%p,%i]:int_fraction", (void *)data, dsrc_index);
 
   prev_counter = curr_counter;
   int_counter = 0;
@@ -149,12 +149,12 @@ static int ts_invoke_derive(const data_set_t *ds, value_list_t *vl, /* {{{ */
 
   curr_derive = (int64_t)vl->values[dsrc_index].derive;
 
-  ssnprintf(key_prev_derive, sizeof(key_prev_derive),
-            "target_scale[%p,%i]:prev_derive", (void *)data, dsrc_index);
-  ssnprintf(key_int_derive, sizeof(key_int_derive),
-            "target_scale[%p,%i]:int_derive", (void *)data, dsrc_index);
-  ssnprintf(key_int_fraction, sizeof(key_int_fraction),
-            "target_scale[%p,%i]:int_fraction", (void *)data, dsrc_index);
+  snprintf(key_prev_derive, sizeof(key_prev_derive),
+           "target_scale[%p,%i]:prev_derive", (void *)data, dsrc_index);
+  snprintf(key_int_derive, sizeof(key_int_derive),
+           "target_scale[%p,%i]:int_derive", (void *)data, dsrc_index);
+  snprintf(key_int_fraction, sizeof(key_int_fraction),
+           "target_scale[%p,%i]:int_fraction", (void *)data, dsrc_index);
 
   prev_derive = curr_derive;
   int_derive = 0;
@@ -232,8 +232,8 @@ static int ts_invoke_absolute(const data_set_t *ds, value_list_t *vl, /* {{{ */
 
   curr_absolute = (uint64_t)vl->values[dsrc_index].absolute;
 
-  ssnprintf(key_int_fraction, sizeof(key_int_fraction),
-            "target_scale[%p,%i]:int_fraction", (void *)data, dsrc_index);
+  snprintf(key_int_fraction, sizeof(key_int_fraction),
+           "target_scale[%p,%i]:int_fraction", (void *)data, dsrc_index);
 
   int_fraction = 0.0;
 
index e3ec269..33ab96c 100644 (file)
@@ -193,7 +193,7 @@ static void ts_subst(char *dest, size_t size, const char *string, /* {{{ */
       char *value_str;
       const char *key = meta_toc[i];
 
-      ssnprintf(meta_name, sizeof(meta_name), "%%{meta:%s}", key);
+      snprintf(meta_name, sizeof(meta_name), "%%{meta:%s}", key);
       if (meta_data_as_string(vl->meta, key, &value_str) != 0)
         continue;
 
index 90f8e00..49f09f0 100644 (file)
@@ -238,23 +238,23 @@ static int v5_zfs_arc_counts(const data_set_t *ds, value_list_t *vl) /* {{{ */
 
   /* Dispatch new value lists instead of this one */
   new_vl.values[0].derive = (derive_t)vl->values[0].counter;
-  ssnprintf(new_vl.type_instance, sizeof(new_vl.type_instance),
-            "demand_data-%s", is_hits ? "hit" : "miss");
+  snprintf(new_vl.type_instance, sizeof(new_vl.type_instance), "demand_data-%s",
+           is_hits ? "hit" : "miss");
   plugin_dispatch_values(&new_vl);
 
   new_vl.values[0].derive = (derive_t)vl->values[1].counter;
-  ssnprintf(new_vl.type_instance, sizeof(new_vl.type_instance),
-            "demand_metadata-%s", is_hits ? "hit" : "miss");
+  snprintf(new_vl.type_instance, sizeof(new_vl.type_instance),
+           "demand_metadata-%s", is_hits ? "hit" : "miss");
   plugin_dispatch_values(&new_vl);
 
   new_vl.values[0].derive = (derive_t)vl->values[2].counter;
-  ssnprintf(new_vl.type_instance, sizeof(new_vl.type_instance),
-            "prefetch_data-%s", is_hits ? "hit" : "miss");
+  snprintf(new_vl.type_instance, sizeof(new_vl.type_instance),
+           "prefetch_data-%s", is_hits ? "hit" : "miss");
   plugin_dispatch_values(&new_vl);
 
   new_vl.values[0].derive = (derive_t)vl->values[3].counter;
-  ssnprintf(new_vl.type_instance, sizeof(new_vl.type_instance),
-            "prefetch_metadata-%s", is_hits ? "hit" : "miss");
+  snprintf(new_vl.type_instance, sizeof(new_vl.type_instance),
+           "prefetch_metadata-%s", is_hits ? "hit" : "miss");
   plugin_dispatch_values(&new_vl);
 
   /* Abort processing */
index f12ce5c..9fdd16e 100644 (file)
@@ -70,7 +70,8 @@
 #undef HAVE_SYSCTLBYNAME /* force HAVE_LIBKVM_NLIST path */
 #endif
 
-#if !KERNEL_LINUX && !HAVE_SYSCTLBYNAME && !HAVE_KVM_GETFILES && !HAVE_LIBKVM_NLIST && !KERNEL_AIX
+#if !KERNEL_LINUX && !HAVE_SYSCTLBYNAME && !HAVE_KVM_GETFILES &&               \
+    !HAVE_LIBKVM_NLIST && !KERNEL_AIX
 #error "No applicable input method."
 #endif
 
 /* #endif HAVE_SYSCTLBYNAME */
 
 #elif HAVE_KVM_GETFILES
-#include <sys/types.h>
 #include <sys/sysctl.h>
+#include <sys/types.h>
 #define _KERNEL /* for DTYPE_SOCKET */
 #include <sys/file.h>
 #undef _KERNEL
 #include <net/route.h>
 #include <netdb.h>
 #include <netinet/in.h>
-#include <netinet/ip.h>
 #include <netinet/in_pcb.h>
 #include <netinet/in_systm.h>
+#include <netinet/ip.h>
 #include <netinet/ip_var.h>
 #include <netinet/tcp.h>
 #include <netinet/tcp_timer.h>
@@ -292,8 +293,8 @@ static void conn_submit_port_entry(port_entry_t *pe) {
 
   if (((port_collect_listening != 0) && (pe->flags & PORT_IS_LISTENING)) ||
       (pe->flags & PORT_COLLECT_LOCAL)) {
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance),
-              "%" PRIu16 "-local", pe->port);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance),
+             "%" PRIu16 "-local", pe->port);
 
     for (int i = 1; i <= TCP_STATE_MAX; i++) {
       vl.values[0].gauge = pe->count_local[i];
@@ -305,8 +306,8 @@ static void conn_submit_port_entry(port_entry_t *pe) {
   }
 
   if (pe->flags & PORT_COLLECT_REMOTE) {
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance),
-              "%" PRIu16 "-remote", pe->port);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance),
+             "%" PRIu16 "-remote", pe->port);
 
     for (int i = 1; i <= TCP_STATE_MAX; i++) {
       vl.values[0].gauge = pe->count_remote[i];
@@ -830,8 +831,7 @@ static int conn_read(void) {
 
   conn_reset_port_entry();
 
-  kf = kvm_getfiles(kvmd, KERN_FILE_BYFILE, DTYPE_SOCKET,
-                   sizeof(*kf), &fcnt);
+  kf = kvm_getfiles(kvmd, KERN_FILE_BYFILE, DTYPE_SOCKET, sizeof(*kf), &fcnt);
   if (kf == NULL) {
     ERROR("tcpconns plugin: kvm_getfiles failed.");
     return -1;
index a26d16e..4d68f61 100644 (file)
@@ -333,7 +333,7 @@ static int tss2_select_vserver(FILE *read_fh, FILE *write_fh,
   int status;
 
   /* Send request */
-  ssnprintf(command, sizeof(command), "sel %i\r\n", vserver->port);
+  snprintf(command, sizeof(command), "sel %i\r\n", vserver->port);
 
   status = tss2_send_request(write_fh, command);
   if (status != 0) {
@@ -463,8 +463,8 @@ static int tss2_read_vserver(vserver_list_t *vserver) {
     status = tss2_send_request(write_fh, "gi\r\n");
   } else {
     /* Request server information */
-    ssnprintf(plugin_instance, sizeof(plugin_instance), "vserver%i",
-              vserver->port);
+    snprintf(plugin_instance, sizeof(plugin_instance), "vserver%i",
+             vserver->port);
 
     /* Select the server */
     status = tss2_select_vserver(read_fh, write_fh, vserver);
index 4815755..9da8fa5 100644 (file)
@@ -65,14 +65,14 @@ static int thermal_sysfs_device_read(const char __attribute__((unused)) * dir,
   if (device_list && ignorelist_match(device_list, name))
     return -1;
 
-  ssnprintf(filename, sizeof(filename), "%s/%s/temp", dirname_sysfs, name);
+  snprintf(filename, sizeof(filename), "%s/%s/temp", dirname_sysfs, name);
   if (parse_value_file(filename, &value, DS_TYPE_GAUGE) == 0) {
     value.gauge /= 1000.0;
     thermal_submit(name, TEMP, value);
     success = 1;
   }
 
-  ssnprintf(filename, sizeof(filename), "%s/%s/cur_state", dirname_sysfs, name);
+  snprintf(filename, sizeof(filename), "%s/%s/cur_state", dirname_sysfs, name);
   if (parse_value_file(filename, &value, DS_TYPE_GAUGE) == 0) {
     thermal_submit(name, COOLING_DEV, value);
     success = 1;
@@ -98,8 +98,8 @@ static int thermal_procfs_device_read(const char __attribute__((unused)) * dir,
    * temperature:             55 C
    */
 
-  len = ssnprintf(filename, sizeof(filename), "%s/%s/temperature",
-                  dirname_procfs, name);
+  len = snprintf(filename, sizeof(filename), "%s/%s/temperature",
+                 dirname_procfs, name);
   if ((len < 0) || ((size_t)len >= sizeof(filename)))
     return -1;
 
index 72e922e..7900133 100644 (file)
@@ -356,9 +356,9 @@ static int ut_config_host(const threshold_t *th_orig, oconfig_item_t *ci) {
 
   return status;
 } /* int ut_config_host */
-  /*
  * End of the functions used to configure threshold values.
  */
+/*
+ * End of the functions used to configure threshold values.
+ */
 /* }}} */
 
 /*
@@ -424,22 +424,22 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl,
 
   n.time = vl->time;
 
-  status = ssnprintf(buf, bufsize, "Host %s, plugin %s", vl->host, vl->plugin);
+  status = snprintf(buf, bufsize, "Host %s, plugin %s", vl->host, vl->plugin);
   buf += status;
   bufsize -= status;
 
   if (vl->plugin_instance[0] != '\0') {
-    status = ssnprintf(buf, bufsize, " (instance %s)", vl->plugin_instance);
+    status = snprintf(buf, bufsize, " (instance %s)", vl->plugin_instance);
     buf += status;
     bufsize -= status;
   }
 
-  status = ssnprintf(buf, bufsize, " type %s", vl->type);
+  status = snprintf(buf, bufsize, " type %s", vl->type);
   buf += status;
   bufsize -= status;
 
   if (vl->type_instance[0] != '\0') {
-    status = ssnprintf(buf, bufsize, " (instance %s)", vl->type_instance);
+    status = snprintf(buf, bufsize, " (instance %s)", vl->type_instance);
     buf += status;
     bufsize -= status;
   }
@@ -454,11 +454,11 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl,
   /* Send an okay notification */
   if (state == STATE_OKAY) {
     if (state_old == STATE_MISSING)
-      ssnprintf(buf, bufsize, ": Value is no longer missing.");
+      snprintf(buf, bufsize, ": Value is no longer missing.");
     else
-      ssnprintf(buf, bufsize, ": All data sources are within range again. "
-                              "Current value of \"%s\" is %f.",
-                ds->ds[ds_index].name, values[ds_index]);
+      snprintf(buf, bufsize, ": All data sources are within range again. "
+                             "Current value of \"%s\" is %f.",
+               ds->ds[ds_index].name, values[ds_index]);
   } else {
     double min;
     double max;
@@ -468,21 +468,21 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl,
 
     if (th->flags & UT_FLAG_INVERT) {
       if (!isnan(min) && !isnan(max)) {
-        ssnprintf(buf, bufsize,
-                  ": Data source \"%s\" is currently "
-                  "%f. That is within the %s region of %f%s and %f%s.",
-                  ds->ds[ds_index].name, values[ds_index],
-                  (state == STATE_ERROR) ? "failure" : "warning", min,
-                  ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "", max,
-                  ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
+        snprintf(buf, bufsize,
+                 ": Data source \"%s\" is currently "
+                 "%f. That is within the %s region of %f%s and %f%s.",
+                 ds->ds[ds_index].name, values[ds_index],
+                 (state == STATE_ERROR) ? "failure" : "warning", min,
+                 ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "", max,
+                 ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
       } else {
-        ssnprintf(buf, bufsize, ": Data source \"%s\" is currently "
-                                "%f. That is %s the %s threshold of %f%s.",
-                  ds->ds[ds_index].name, values[ds_index],
-                  isnan(min) ? "below" : "above",
-                  (state == STATE_ERROR) ? "failure" : "warning",
-                  isnan(min) ? max : min,
-                  ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
+        snprintf(buf, bufsize, ": Data source \"%s\" is currently "
+                               "%f. That is %s the %s threshold of %f%s.",
+                 ds->ds[ds_index].name, values[ds_index],
+                 isnan(min) ? "below" : "above",
+                 (state == STATE_ERROR) ? "failure" : "warning",
+                 isnan(min) ? max : min,
+                 ((th->flags & UT_FLAG_PERCENTAGE) != 0) ? "%" : "");
       }
     } else if (th->flags & UT_FLAG_PERCENTAGE) {
       gauge_t value;
@@ -501,21 +501,21 @@ static int ut_report_state(const data_set_t *ds, const value_list_t *vl,
       else
         value = 100.0 * values[ds_index] / sum;
 
-      ssnprintf(buf, bufsize,
-                ": Data source \"%s\" is currently "
-                "%g (%.2f%%). That is %s the %s threshold of %.2f%%.",
-                ds->ds[ds_index].name, values[ds_index], value,
-                (value < min) ? "below" : "above",
-                (state == STATE_ERROR) ? "failure" : "warning",
-                (value < min) ? min : max);
+      snprintf(buf, bufsize,
+               ": Data source \"%s\" is currently "
+               "%g (%.2f%%). That is %s the %s threshold of %.2f%%.",
+               ds->ds[ds_index].name, values[ds_index], value,
+               (value < min) ? "below" : "above",
+               (state == STATE_ERROR) ? "failure" : "warning",
+               (value < min) ? min : max);
     } else /* is not inverted */
     {
-      ssnprintf(buf, bufsize, ": Data source \"%s\" is currently "
-                              "%f. That is %s the %s threshold of %f.",
-                ds->ds[ds_index].name, values[ds_index],
-                (values[ds_index] < min) ? "below" : "above",
-                (state == STATE_ERROR) ? "failure" : "warning",
-                (values[ds_index] < min) ? min : max);
+      snprintf(buf, bufsize, ": Data source \"%s\" is currently "
+                             "%f. That is %s the %s threshold of %f.",
+               ds->ds[ds_index].name, values[ds_index],
+               (values[ds_index] < min) ? "below" : "above",
+               (state == STATE_ERROR) ? "failure" : "warning",
+               (values[ds_index] < min) ? min : max);
     }
   }
 
@@ -772,9 +772,9 @@ static int ut_missing(const value_list_t *vl,
   FORMAT_VL(identifier, sizeof(identifier), vl);
 
   NOTIFICATION_INIT_VL(&n, vl);
-  ssnprintf(n.message, sizeof(n.message),
-            "%s has not been updated for %.3f seconds.", identifier,
-            CDTIME_T_TO_DOUBLE(missing_time));
+  snprintf(n.message, sizeof(n.message),
+           "%s has not been updated for %.3f seconds.", identifier,
+           CDTIME_T_TO_DOUBLE(missing_time));
   n.time = now;
 
   plugin_dispatch_notification(&n);
index 45c8bd7..1049fb2 100644 (file)
@@ -266,7 +266,7 @@ open_msr(unsigned int cpu, _Bool multiple_read) {
     }
   }
 
-  ssnprintf(pathname, sizeof(pathname), "/dev/cpu/%d/msr", cpu);
+  snprintf(pathname, sizeof(pathname), "/dev/cpu/%d/msr", cpu);
   fd = open(pathname, O_RDONLY);
   if (fd < 0) {
     ERROR("turbostat plugin: failed to open %s", pathname);
@@ -556,7 +556,7 @@ static int submit_counters(struct thread_data *t, struct core_data *c,
   DEBUG("turbostat plugin: submit stats for cpu: %d, core: %d, pkg: %d",
         t->cpu_id, c->core_id, p->package_id);
 
-  ssnprintf(name, sizeof(name), "cpu%02d", t->cpu_id);
+  snprintf(name, sizeof(name), "cpu%02d", t->cpu_id);
 
   if (!aperf_mperf_unstable)
     turbostat_submit(name, "percent", "c0", 100.0 * t->mperf / t->tsc);
@@ -567,9 +567,9 @@ static int submit_counters(struct thread_data *t, struct core_data *c,
                    1.0 / 1000000 * t->aperf / interval_float);
 
   if ((!aperf_mperf_unstable) || (!(t->aperf > t->tsc || t->mperf > t->tsc)))
-    turbostat_submit(name, "frequency", "busy", 1.0 * t->tsc / 1000000 *
-                                                    t->aperf / t->mperf /
-                                                    interval_float);
+    turbostat_submit(name, "frequency", "busy",
+                     1.0 * t->tsc / 1000000 * t->aperf / t->mperf /
+                         interval_float);
 
   /* Sanity check (should stay stable) */
   turbostat_submit(name, "gauge", "TSC",
@@ -585,7 +585,7 @@ static int submit_counters(struct thread_data *t, struct core_data *c,
 
   /* If not using logical core numbering, set core id */
   if (!config_lcn) {
-    ssnprintf(name, sizeof(name), "core%02d", c->core_id);
+    snprintf(name, sizeof(name), "core%02d", c->core_id);
   }
 
   if (do_core_cstate & (1 << 3))
@@ -602,7 +602,7 @@ static int submit_counters(struct thread_data *t, struct core_data *c,
   if (!(t->flags & CPU_IS_FIRST_CORE_IN_PACKAGE))
     goto done;
 
-  ssnprintf(name, sizeof(name), "pkg%02d", p->package_id);
+  snprintf(name, sizeof(name), "pkg%02d", p->package_id);
 
   if (do_ptm)
     turbostat_submit(name, "temperature", NULL, p->pkg_temp_c);
@@ -1064,8 +1064,8 @@ static int get_threads_on_core(unsigned int cpu) {
   int matches;
   char character;
 
-  ssnprintf(path, sizeof(path),
-            "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
+  snprintf(path, sizeof(path),
+           "/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", cpu);
   filep = fopen(path, "r");
   if (!filep) {
     ERROR("turbostat plugin: Failed to open '%s'", path);
index 718425b..6f1bc39 100644 (file)
@@ -276,10 +276,10 @@ int cmd_create_putval(char *ret, size_t ret_len, /* {{{ */
     return status;
   escape_string(buffer_values, sizeof(buffer_values));
 
-  ssnprintf(ret, ret_len, "PUTVAL %s interval=%.3f %s", buffer_ident,
-            (vl->interval > 0) ? CDTIME_T_TO_DOUBLE(vl->interval)
-                               : CDTIME_T_TO_DOUBLE(plugin_get_interval()),
-            buffer_values);
+  snprintf(ret, ret_len, "PUTVAL %s interval=%.3f %s", buffer_ident,
+           (vl->interval > 0) ? CDTIME_T_TO_DOUBLE(vl->interval)
+                              : CDTIME_T_TO_DOUBLE(plugin_get_interval()),
+           buffer_values);
 
   return 0;
 } /* }}} int cmd_create_putval */
index 9770225..055c987 100644 (file)
  *   Sebastian 'tokkee' Harl <sh at tokkee.org>
  **/
 
+#include "utils_cmds.h"
 #include "daemon/common.h"
 #include "utils_cmd_flush.h"
 #include "utils_cmd_getval.h"
 #include "utils_cmd_listval.h"
 #include "utils_cmd_putval.h"
-#include "utils_cmds.h"
 #include "utils_parse_option.h"
 
 #include <stdbool.h>
index 37fa930..e7e04f7 100644 (file)
@@ -912,7 +912,7 @@ const char *qtype_str(int t) {
     return "ANY"; /* ... 255 */
 #endif /* __BIND >= 19950621 */
   default:
-    ssnprintf(buf, sizeof(buf), "#%i", t);
+    snprintf(buf, sizeof(buf), "#%i", t);
     return buf;
   } /* switch (t) */
 }
@@ -931,7 +931,7 @@ const char *opcode_str(int o) {
   case 5:
     return "Update";
   default:
-    ssnprintf(buf, sizeof(buf), "Opcode%d", o);
+    snprintf(buf, sizeof(buf), "Opcode%d", o);
     return buf;
   }
 }
@@ -998,7 +998,7 @@ const char *rcode_str(int rcode) {
 #endif /* RFC2136 rcodes */
 #endif /* __BIND >= 19950621 */
   default:
-    ssnprintf(buf, sizeof(buf), "RCode%i", rcode);
+    snprintf(buf, sizeof(buf), "RCode%i", rcode);
     return buf;
   }
 } /* const char *rcode_str (int rcode) */
index 3a30438..77f596e 100644 (file)
@@ -66,7 +66,7 @@ struct dpdk_helper_ctx_s {
   int eal_initialized;
 
   size_t shm_size;
-  const char *shm_name;
+  char shm_name[DATA_MAX_NAME_LEN];
 
   sem_t sema_cmd_start;
   sem_t sema_cmd_complete;
@@ -103,11 +103,10 @@ static void dpdk_helper_config_default(dpdk_helper_ctx_t *phc) {
 
   DPDK_HELPER_TRACE(phc->shm_name);
 
-  ssnprintf(phc->eal_config.coremask, DATA_MAX_NAME_LEN, "%s", "0xf");
-  ssnprintf(phc->eal_config.memory_channels, DATA_MAX_NAME_LEN, "%s", "1");
-  ssnprintf(phc->eal_config.process_type, DATA_MAX_NAME_LEN, "%s", "secondary");
-  ssnprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "%s",
-            DPDK_DEFAULT_RTE_CONFIG);
+  snprintf(phc->eal_config.coremask, DATA_MAX_NAME_LEN, "%s", "0xf");
+  snprintf(phc->eal_config.memory_channels, DATA_MAX_NAME_LEN, "%s", "1");
+  snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN, "%s",
+           DPDK_DEFAULT_RTE_CONFIG);
 }
 
 int dpdk_helper_eal_config_set(dpdk_helper_ctx_t *phc, dpdk_eal_config_t *ec) {
@@ -162,6 +161,7 @@ int dpdk_helper_eal_config_parse(dpdk_helper_ctx_t *phc, oconfig_item_t *ci) {
   int status = 0;
   for (int i = 0; i < ci->children_num; i++) {
     oconfig_item_t *child = ci->children + i;
+
     if (strcasecmp("Coremask", child->key) == 0) {
       status = cf_util_get_string_buffer(child, phc->eal_config.coremask,
                                          sizeof(phc->eal_config.coremask));
@@ -176,15 +176,15 @@ int dpdk_helper_eal_config_parse(dpdk_helper_ctx_t *phc, oconfig_item_t *ci) {
       status = cf_util_get_string_buffer(child, phc->eal_config.socket_memory,
                                          sizeof(phc->eal_config.socket_memory));
       DEBUG("dpdk_common: EAL:Socket memory %s", phc->eal_config.socket_memory);
-    } else if (strcasecmp("ProcessType", child->key) == 0) {
-      status = cf_util_get_string_buffer(child, phc->eal_config.process_type,
-                                         sizeof(phc->eal_config.process_type));
-      DEBUG("dpdk_common: EAL:Process type %s", phc->eal_config.process_type);
-    } else if ((strcasecmp("FilePrefix", child->key) == 0) &&
-               (child->values[0].type == OCONFIG_TYPE_STRING)) {
-      ssnprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN,
-                "/var/run/.%s_config", child->values[0].value.string);
-      DEBUG("dpdk_common: EAL:File prefix %s", phc->eal_config.file_prefix);
+    } else if (strcasecmp("FilePrefix", child->key) == 0) {
+      char prefix[DATA_MAX_NAME_LEN];
+
+      status = cf_util_get_string_buffer(child, prefix, sizeof(prefix));
+      if (status == 0) {
+        snprintf(phc->eal_config.file_prefix, DATA_MAX_NAME_LEN,
+                  "/var/run/.%s_config", prefix);
+        DEBUG("dpdk_common: EAL:File prefix %s", phc->eal_config.file_prefix);
+      }
     } else {
       ERROR("dpdk_common: Invalid '%s' configuration option", child->key);
       status = -EINVAL;
@@ -242,13 +242,16 @@ static void dpdk_shm_cleanup(const char *name, size_t size, void *map) {
   DPDK_HELPER_TRACE(name);
   char errbuf[ERR_BUF_SIZE];
 
+  /*
+   * Call shm_unlink first, as 'name' might be no longer accessible after munmap
+   */
+  if (shm_unlink(name))
+    ERROR("shm_unlink failure %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+
   if (map != NULL) {
     if (munmap(map, size))
       ERROR("munmap failure %s", sstrerror(errno, errbuf, sizeof(errbuf)));
   }
-
-  if (shm_unlink(name))
-    ERROR("shm_unlink failure %s", sstrerror(errno, errbuf, sizeof(errbuf)));
 }
 
 void *dpdk_helper_priv_get(dpdk_helper_ctx_t *phc) {
@@ -313,7 +316,7 @@ int dpdk_helper_init(const char *name, size_t data_size,
   }
 
   phc->shm_size = shm_size;
-  phc->shm_name = name;
+  sstrncpy(phc->shm_name, name, sizeof(phc->shm_name));
 
   dpdk_helper_config_default(phc);
 
@@ -322,11 +325,9 @@ int dpdk_helper_init(const char *name, size_t data_size,
   return 0;
 }
 
-int dpdk_helper_shutdown(dpdk_helper_ctx_t *phc) {
-  if (phc == NULL) {
-    ERROR("%s:Invalid argument(phc)", __FUNCTION__);
-    return -EINVAL;
-  }
+void dpdk_helper_shutdown(dpdk_helper_ctx_t *phc) {
+  if (phc == NULL)
+    return;
 
   DPDK_HELPER_TRACE(phc->shm_name);
 
@@ -339,8 +340,6 @@ int dpdk_helper_shutdown(dpdk_helper_ctx_t *phc) {
   sem_destroy(&phc->sema_cmd_start);
   sem_destroy(&phc->sema_cmd_complete);
   dpdk_shm_cleanup(phc->shm_name, phc->shm_size, (void *)phc);
-
-  return 0;
 }
 
 static int dpdk_helper_spawn(dpdk_helper_ctx_t *phc) {
@@ -471,7 +470,6 @@ static int dpdk_helper_eal_init(dpdk_helper_ctx_t *phc) {
   /* EAL config must be initialized */
   assert(phc->eal_config.coremask[0] != 0);
   assert(phc->eal_config.memory_channels[0] != 0);
-  assert(phc->eal_config.process_type[0] != 0);
   assert(phc->eal_config.file_prefix[0] != 0);
 
   argp[argc++] = "collectd-dpdk";
@@ -493,7 +491,7 @@ static int dpdk_helper_eal_init(dpdk_helper_ctx_t *phc) {
   }
 
   argp[argc++] = "--proc-type";
-  argp[argc++] = phc->eal_config.process_type;
+  argp[argc++] = "secondary";
 
   assert(argc <= (DPDK_EAL_ARGC * 2 + 1));
 
index f97a6b5..23941df 100644 (file)
@@ -50,7 +50,6 @@ struct dpdk_eal_config_s {
   char coremask[DATA_MAX_NAME_LEN];
   char memory_channels[DATA_MAX_NAME_LEN];
   char socket_memory[DATA_MAX_NAME_LEN];
-  char process_type[DATA_MAX_NAME_LEN];
   char file_prefix[DATA_MAX_NAME_LEN];
 };
 typedef struct dpdk_eal_config_s dpdk_eal_config_t;
@@ -65,7 +64,7 @@ typedef struct dpdk_helper_ctx_s dpdk_helper_ctx_t;
 
 int dpdk_helper_init(const char *name, size_t data_size,
                      dpdk_helper_ctx_t **pphc);
-int dpdk_helper_shutdown(dpdk_helper_ctx_t *phc);
+void dpdk_helper_shutdown(dpdk_helper_ctx_t *phc);
 int dpdk_helper_eal_config_parse(dpdk_helper_ctx_t *phc, oconfig_item_t *ci);
 int dpdk_helper_eal_config_set(dpdk_helper_ctx_t *phc, dpdk_eal_config_t *ec);
 int dpdk_helper_eal_config_get(dpdk_helper_ctx_t *phc, dpdk_eal_config_t *ec);
index f124ba1..87cead1 100644 (file)
@@ -46,7 +46,7 @@ static int gr_format_values(char *ret, size_t ret_len, int ds_num,
 
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
-    status = ssnprintf(ret + offset, ret_len - offset, __VA_ARGS__);           \
+    status = snprintf(ret + offset, ret_len - offset, __VA_ARGS__);            \
     if (status < 1) {                                                          \
       return -1;                                                               \
     } else if (((size_t)status) >= (ret_len - offset)) {                       \
@@ -131,9 +131,9 @@ static int gr_format_name(char *ret, int ret_len, value_list_t const *vl,
                       sizeof(n_type_instance), escape_char, preserve_separator);
 
   if (n_plugin_instance[0] != '\0')
-    ssnprintf(tmp_plugin, sizeof(tmp_plugin), "%s%c%s", n_plugin,
-              (flags & GRAPHITE_SEPARATE_INSTANCES) ? '.' : '-',
-              n_plugin_instance);
+    snprintf(tmp_plugin, sizeof(tmp_plugin), "%s%c%s", n_plugin,
+             (flags & GRAPHITE_SEPARATE_INSTANCES) ? '.' : '-',
+             n_plugin_instance);
   else
     sstrncpy(tmp_plugin, n_plugin, sizeof(tmp_plugin));
 
@@ -141,9 +141,9 @@ static int gr_format_name(char *ret, int ret_len, value_list_t const *vl,
     if ((flags & GRAPHITE_DROP_DUPE_FIELDS) && strcmp(n_plugin, n_type) == 0)
       sstrncpy(tmp_type, n_type_instance, sizeof(tmp_type));
     else
-      ssnprintf(tmp_type, sizeof(tmp_type), "%s%c%s", n_type,
-                (flags & GRAPHITE_SEPARATE_INSTANCES) ? '.' : '-',
-                n_type_instance);
+      snprintf(tmp_type, sizeof(tmp_type), "%s%c%s", n_type,
+               (flags & GRAPHITE_SEPARATE_INSTANCES) ? '.' : '-',
+               n_type_instance);
   } else
     sstrncpy(tmp_type, n_type, sizeof(tmp_type));
 
@@ -152,14 +152,14 @@ static int gr_format_name(char *ret, int ret_len, value_list_t const *vl,
   if (ds_name != NULL) {
     if ((flags & GRAPHITE_DROP_DUPE_FIELDS) &&
         strcmp(tmp_plugin, tmp_type) == 0)
-      ssnprintf(ret, ret_len, "%s%s%s.%s.%s", prefix, n_host, postfix,
-                tmp_plugin, ds_name);
+      snprintf(ret, ret_len, "%s%s%s.%s.%s", prefix, n_host, postfix,
+               tmp_plugin, ds_name);
     else
-      ssnprintf(ret, ret_len, "%s%s%s.%s.%s.%s", prefix, n_host, postfix,
-                tmp_plugin, tmp_type, ds_name);
+      snprintf(ret, ret_len, "%s%s%s.%s.%s.%s", prefix, n_host, postfix,
+               tmp_plugin, tmp_type, ds_name);
   } else
-    ssnprintf(ret, ret_len, "%s%s%s.%s.%s", prefix, n_host, postfix, tmp_plugin,
-              tmp_type);
+    snprintf(ret, ret_len, "%s%s%s.%s.%s", prefix, n_host, postfix, tmp_plugin,
+             tmp_type);
 
   return 0;
 }
@@ -219,8 +219,8 @@ int format_graphite(char *buffer, size_t buffer_size, data_set_t const *ds,
 
     /* Compute the graphite command */
     message_len =
-        (size_t)ssnprintf(message, sizeof(message), "%s %s %u\r\n", key, values,
-                          (unsigned int)CDTIME_T_TO_TIME_T(vl->time));
+        (size_t)snprintf(message, sizeof(message), "%s %s %u\r\n", key, values,
+                         (unsigned int)CDTIME_T_TO_TIME_T(vl->time));
     if (message_len >= sizeof(message)) {
       ERROR("format_graphite: message buffer too small: "
             "Need %zu bytes.",
index 67aebba..53a38b8 100644 (file)
@@ -95,7 +95,7 @@ static int values_to_json(char *buffer, size_t buffer_size, /* {{{ */
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
     int status;                                                                \
-    status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);    \
+    status = snprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);     \
     if (status < 1) {                                                          \
       sfree(rates);                                                            \
       return -1;                                                               \
@@ -159,7 +159,7 @@ static int dstypes_to_json(char *buffer, size_t buffer_size, /* {{{ */
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
     int status;                                                                \
-    status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);    \
+    status = snprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);     \
     if (status < 1)                                                            \
       return -1;                                                               \
     else if (((size_t)status) >= (buffer_size - offset))                       \
@@ -193,7 +193,7 @@ static int dsnames_to_json(char *buffer, size_t buffer_size, /* {{{ */
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
     int status;                                                                \
-    status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);    \
+    status = snprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);     \
     if (status < 1)                                                            \
       return -1;                                                               \
     else if (((size_t)status) >= (buffer_size - offset))                       \
@@ -228,7 +228,7 @@ static int meta_data_keys_to_json(char *buffer, size_t buffer_size, /* {{{ */
 
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
-    status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);    \
+    status = snprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);     \
     if (status < 1)                                                            \
       return -1;                                                               \
     else if (((size_t)status) >= (buffer_size - offset))                       \
@@ -318,7 +318,7 @@ static int value_list_to_json(char *buffer, size_t buffer_size, /* {{{ */
 
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
-    status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);    \
+    status = snprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);     \
     if (status < 1)                                                            \
       return -1;                                                               \
     else if (((size_t)status) >= (buffer_size - offset))                       \
@@ -577,11 +577,12 @@ static int format_alert(yajl_gen g, notification_t const *n) /* {{{ */
   }
 
   JSON_ADD(g, "severity");
-  JSON_ADD(g, (n->severity == NOTIF_FAILURE)
-                  ? "FAILURE"
-                  : (n->severity == NOTIF_WARNING)
-                        ? "WARNING"
-                        : (n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN");
+  JSON_ADD(g,
+           (n->severity == NOTIF_FAILURE)
+               ? "FAILURE"
+               : (n->severity == NOTIF_WARNING)
+                     ? "WARNING"
+                     : (n->severity == NOTIF_OKAY) ? "OKAY" : "UNKNOWN");
 
   JSON_ADD(g, "service");
   JSON_ADD(g, "collectd");
index 4378d7f..0128c57 100644 (file)
@@ -103,7 +103,7 @@ static int values_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
     int status;                                                                \
-    status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);    \
+    status = snprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);     \
     if (status < 1) {                                                          \
       sfree(rates);                                                            \
       return -1;                                                               \
@@ -192,7 +192,7 @@ static int value_list_to_kairosdb(char *buffer, size_t buffer_size, /* {{{ */
 
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
-    status = ssnprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);    \
+    status = snprintf(buffer + offset, buffer_size - offset, __VA_ARGS__);     \
     if (status < 1)                                                            \
       return -1;                                                               \
     else if (((size_t)status) >= (buffer_size - offset))                       \
@@ -345,12 +345,9 @@ int format_kairosdb_value_list(char *buffer, /* {{{ */
   if (*ret_buffer_free < 3)
     return -ENOMEM;
 
-  return format_kairosdb_value_list_nocheck(buffer, ret_buffer_fill,
-                                            ret_buffer_free, ds, vl,
-                                            store_rates,
-                                            (*ret_buffer_free) - 2,
-                                            http_attrs, http_attrs_num,
-                                            data_ttl);
+  return format_kairosdb_value_list_nocheck(
+      buffer, ret_buffer_fill, ret_buffer_free, ds, vl, store_rates,
+      (*ret_buffer_free) - 2, http_attrs, http_attrs_num, data_ttl);
 } /* }}} int format_kairosdb_value_list */
 
 /* vim: set sw=2 sts=2 et fdm=marker : */
index d0832cb..0f8c2a2 100644 (file)
@@ -25,8 +25,8 @@
  *   Pavel Rochnyack <pavel2000 at ngs.ru>
  */
 
-#include "common.h"
 #include "utils_latency_config.h"
+#include "common.h"
 #include "collectd.h"
 
 static int latency_config_add_percentile(latency_config_t *conf,
index 4e570ff..0990472 100644 (file)
@@ -28,8 +28,8 @@
  * GCC will complain about the macro definition. */
 #define DONT_POISON_SPRINTF_YET
 
-#include "common.h"
 #include "utils_lua.h"
+#include "common.h"
 
 static int ltoc_values(lua_State *L, /* {{{ */
                        const data_set_t *ds, value_t *ret_values) {
index bbc4c20..3d57ca6 100644 (file)
@@ -258,7 +258,7 @@ static void uuidcache_init(void) {
         * (This is useful, if the cdrom on /dev/hdc must not
         * be accessed.)
         */
-        ssnprintf(device, sizeof(device), "%s/%s", DEVLABELDIR, ptname);
+        snprintf(device, sizeof(device), "%s/%s", DEVLABELDIR, ptname);
         if (!get_label_uuid(device, &label, uuid)) {
           uuidcache_addentry(sstrdup(device), label, uuid);
         }
@@ -527,7 +527,7 @@ static cu_mount_t *cu_mount_gen_getmntent(void) {
 
   return first;
 } /* static cu_mount_t *cu_mount_gen_getmntent (void) */
-/* #endif HAVE_TWO_GETMNTENT || HAVE_GEN_GETMNTENT || HAVE_SUN_GETMNTENT */
+  /* #endif HAVE_TWO_GETMNTENT || HAVE_GEN_GETMNTENT || HAVE_SUN_GETMNTENT */
 
 #elif HAVE_SEQ_GETMNTENT
 #warn "This version of `getmntent' hat not yet been implemented!"
index 2f7baea..2087324 100644 (file)
@@ -3,14 +3,17 @@
  *
  * Copyright(c) 2016 Intel Corporation. All rights reserved.
  *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ *of
  * this software and associated documentation files (the "Software"), to deal in
  * the Software without restriction, including without limitation the rights to
  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
- * of the Software, and to permit persons to whom the Software is furnished to do
+ * of the Software, and to permit persons to whom the Software is furnished to
+ *do
  * so, subject to the following conditions:
  *
- * The above copyright notice and this permission notice shall be included in all
+ * The above copyright notice and this permission notice shall be included in
+ *all
  * copies or substantial portions of the Software.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@@ -314,8 +317,7 @@ static int ovs_db_data_send(const ovs_db_t *pdb, const char *data, size_t len) {
  */
 static yajl_gen_status ovs_yajl_gen_tstring(yajl_gen hander,
                                             const char *string) {
-  return yajl_gen_string(hander, (const unsigned char *)string,
-                         strlen(string));
+  return yajl_gen_string(hander, (const unsigned char *)string, strlen(string));
 }
 
 /* Add YAJL value into YAJL generator handle (JSON object)
@@ -1091,7 +1093,7 @@ int ovs_db_send_request(ovs_db_t *pdb, const char *method, const char *params,
   /* generate id field */
   OVS_YAJL_CALL(ovs_yajl_gen_tstring, jgen, "id");
   uid = ovs_uid_generate();
-  ssnprintf(uid_buff, sizeof(uid_buff), "%" PRIX64, uid);
+  snprintf(uid_buff, sizeof(uid_buff), "%" PRIX64, uid);
   OVS_YAJL_CALL(ovs_yajl_gen_tstring, jgen, uid_buff);
 
   OVS_YAJL_CALL(yajl_gen_map_close, jgen);
@@ -1177,7 +1179,7 @@ int ovs_db_table_cb_register(ovs_db_t *pdb, const char *tb_name,
     OVS_YAJL_CALL(ovs_yajl_gen_tstring, jgen, OVS_DB_DEFAULT_DB_NAME);
 
     /* uid string <json-value> */
-    ssnprintf(uid_str, sizeof(uid_str), "%" PRIX64, new_cb->uid);
+    snprintf(uid_str, sizeof(uid_str), "%" PRIX64, new_cb->uid);
     OVS_YAJL_CALL(ovs_yajl_gen_tstring, jgen, uid_str);
 
     /* <monitor-requests> */
index 86f7f3f..6cb5446 100644 (file)
@@ -208,8 +208,8 @@ static int rra_get(char ***ret, const value_list_t *vl, /* {{{ */
       if (rra_num >= rra_max)
         break;
 
-      status = ssnprintf(buffer, sizeof(buffer), "RRA:%s:%.10f:%u:%u",
-                         rra_types[j], cfg->xff, cdp_len, cdp_num);
+      status = snprintf(buffer, sizeof(buffer), "RRA:%s:%.10f:%u:%u",
+                        rra_types[j], cfg->xff, cdp_len, cdp_num);
 
       if ((status < 0) || ((size_t)status >= sizeof(buffer))) {
         ERROR("rra_get: Buffer would have been truncated.");
@@ -280,18 +280,18 @@ static int ds_get(char ***ret, /* {{{ */
     if (isnan(d->min)) {
       sstrncpy(min, "U", sizeof(min));
     } else
-      ssnprintf(min, sizeof(min), "%f", d->min);
+      snprintf(min, sizeof(min), "%f", d->min);
 
     if (isnan(d->max)) {
       sstrncpy(max, "U", sizeof(max));
     } else
-      ssnprintf(max, sizeof(max), "%f", d->max);
+      snprintf(max, sizeof(max), "%f", d->max);
 
-    status = ssnprintf(buffer, sizeof(buffer), "DS:%s:%s:%i:%s:%s", d->name,
-                       type, (cfg->heartbeat > 0)
-                                 ? cfg->heartbeat
-                                 : (int)CDTIME_T_TO_TIME_T(2 * vl->interval),
-                       min, max);
+    status = snprintf(
+        buffer, sizeof(buffer), "DS:%s:%s:%i:%s:%s", d->name, type,
+        (cfg->heartbeat > 0) ? cfg->heartbeat
+                             : (int)CDTIME_T_TO_TIME_T(2 * vl->interval),
+        min, max);
     if ((status < 1) || ((size_t)status >= sizeof(buffer)))
       break;
 
@@ -369,8 +369,8 @@ static int srrd_create(const char *filename, /* {{{ */
   if (last_up == 0)
     last_up = time(NULL) - 10;
 
-  ssnprintf(pdp_step_str, sizeof(pdp_step_str), "%lu", pdp_step);
-  ssnprintf(last_up_str, sizeof(last_up_str), "%lu", (unsigned long)last_up);
+  snprintf(pdp_step_str, sizeof(pdp_step_str), "%lu", pdp_step);
+  snprintf(last_up_str, sizeof(last_up_str), "%lu", (unsigned long)last_up);
 
   new_argv[0] = "create";
   new_argv[1] = (void *)filename;
@@ -497,7 +497,7 @@ static void *srrd_create_thread(void *targs) /* {{{ */
     return 0;
   }
 
-  ssnprintf(tmpfile, sizeof(tmpfile), "%s.async", args->filename);
+  snprintf(tmpfile, sizeof(tmpfile), "%s.async", args->filename);
 
   status = srrd_create(tmpfile, args->pdp_step, args->last_up, args->argc,
                        (void *)args->argv);
index f046f6b..af8bbe7 100644 (file)
@@ -119,11 +119,11 @@ static int latency_submit_match(cu_match_t *match, void *user_data) {
   sstrncpy(vl.type, data->type, sizeof(vl.type));
   for (size_t i = 0; i < data->latency_config.percentile_num; i++) {
     if (strlen(data->type_instance) != 0)
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%.0f",
-                data->type_instance, data->latency_config.percentile[i]);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%.0f",
+               data->type_instance, data->latency_config.percentile[i]);
     else
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%.0f",
-                data->latency_config.percentile[i]);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%.0f",
+               data->latency_config.percentile[i]);
 
     vl.values = &(value_t){
         .gauge =
@@ -147,11 +147,11 @@ static int latency_submit_match(cu_match_t *match, void *user_data) {
         bucket.upper_bound ? CDTIME_T_TO_DOUBLE(bucket.upper_bound) : INFINITY;
 
     if (strlen(data->type_instance) != 0)
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s-%g_%g",
-                data->type, data->type_instance, lower_bound, upper_bound);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%s-%g_%g",
+               data->type, data->type_instance, lower_bound, upper_bound);
     else
-      ssnprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%g_%g",
-                data->type, lower_bound, upper_bound);
+      snprintf(vl.type_instance, sizeof(vl.type_instance), "%s-%g_%g",
+               data->type, lower_bound, upper_bound);
 
     vl.values = &(value_t){
         .gauge =
index 1a71d8c..7c5a9ef 100644 (file)
@@ -98,8 +98,8 @@ static int varnish_submit(const char *plugin_instance, /* {{{ */
 
   if (plugin_instance == NULL)
     plugin_instance = "default";
-  ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
-            plugin_instance, category);
+  snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s-%s",
+           plugin_instance, category);
 
   sstrncpy(vl.type, type, sizeof(vl.type));
 
@@ -113,18 +113,20 @@ static int varnish_submit_gauge(const char *plugin_instance, /* {{{ */
                                 const char *category, const char *type,
                                 const char *type_instance,
                                 uint64_t gauge_value) {
-  return varnish_submit(plugin_instance, category, type, type_instance, (value_t){
-      .gauge=(gauge_t)gauge_value,
-    });
+  return varnish_submit(plugin_instance, category, type, type_instance,
+                        (value_t){
+                            .gauge = (gauge_t)gauge_value,
+                        });
 } /* }}} int varnish_submit_gauge */
 
 static int varnish_submit_derive(const char *plugin_instance, /* {{{ */
                                  const char *category, const char *type,
                                  const char *type_instance,
                                  uint64_t derive_value) {
-  return varnish_submit(plugin_instance, category, type, type_instance, (value_t){
-      .derive=(derive_t)derive_value,
-    });
+  return varnish_submit(plugin_instance, category, type, type_instance,
+                        (value_t){
+                            .derive = (derive_t)derive_value,
+                        });
 } /* }}} int varnish_submit_derive */
 
 #if HAVE_VARNISH_V3 || HAVE_VARNISH_V4
@@ -172,21 +174,21 @@ static int varnish_monitor(void *priv,
 
   if (conf->collect_connections) {
     if (strcmp(name, "client_conn") == 0)
-      return varnish_submit_derive(conf->instance, "connections",
-                                   "connections", "accepted", val);
+      return varnish_submit_derive(conf->instance, "connections", "connections",
+                                   "accepted", val);
     else if (strcmp(name, "client_drop") == 0)
-      return varnish_submit_derive(conf->instance, "connections",
-                                   "connections", "dropped", val);
+      return varnish_submit_derive(conf->instance, "connections", "connections",
+                                   "dropped", val);
     else if (strcmp(name, "client_req") == 0)
-      return varnish_submit_derive(conf->instance, "connections",
-                                   "connections", "received", val);
+      return varnish_submit_derive(conf->instance, "connections", "connections",
+                                   "received", val);
   }
 
 #ifdef HAVE_VARNISH_V3
   if (conf->collect_dirdns) {
     if (strcmp(name, "dir_dns_lookups") == 0)
-      return varnish_submit_derive(conf->instance, "dirdns",
-                                   "cache_operation", "lookups", val);
+      return varnish_submit_derive(conf->instance, "dirdns", "cache_operation",
+                                   "lookups", val);
     else if (strcmp(name, "dir_dns_failed") == 0)
       return varnish_submit_derive(conf->instance, "dirdns", "cache_result",
                                    "failed", val);
@@ -441,26 +443,26 @@ static int varnish_monitor(void *priv,
       return varnish_submit_gauge(conf->instance, "sms", "requests",
                                   "outstanding", val);
     else if (strcmp(name, "sms_nbytes") == 0)
-      return varnish_submit_gauge(conf->instance, "sms", "bytes",
-                                  "outstanding", val);
+      return varnish_submit_gauge(conf->instance, "sms", "bytes", "outstanding",
+                                  val);
     else if (strcmp(name, "sms_balloc") == 0)
       return varnish_submit_derive(conf->instance, "sms", "total_bytes",
                                    "allocated", val);
     else if (strcmp(name, "sms_bfree") == 0)
-      return varnish_submit_derive(conf->instance, "sms", "total_bytes",
-                                   "free", val);
+      return varnish_submit_derive(conf->instance, "sms", "total_bytes", "free",
+                                   val);
   }
 
   if (conf->collect_struct) {
     if (strcmp(name, "n_sess_mem") == 0)
-      return varnish_submit_gauge(conf->instance, "struct",
-                                  "current_sessions", "sess_mem", val);
+      return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
+                                  "sess_mem", val);
     else if (strcmp(name, "n_sess") == 0)
-      return varnish_submit_gauge(conf->instance, "struct",
-                                  "current_sessions", "sess", val);
+      return varnish_submit_gauge(conf->instance, "struct", "current_sessions",
+                                  "sess", val);
     else if (strcmp(name, "n_object") == 0)
-      return varnish_submit_gauge(conf->instance, "struct", "objects",
-                                  "object", val);
+      return varnish_submit_gauge(conf->instance, "struct", "objects", "object",
+                                  val);
     else if (strcmp(name, "n_vampireobject") == 0)
       return varnish_submit_gauge(conf->instance, "struct", "objects",
                                   "vampireobject", val);
@@ -495,14 +497,14 @@ static int varnish_monitor(void *priv,
       return varnish_submit_derive(conf->instance, "totals", "total_requests",
                                    "requests", val);
     else if (strcmp(name, "s_pipe") == 0)
-      return varnish_submit_derive(conf->instance, "totals",
-                                   "total_operations", "pipe", val);
+      return varnish_submit_derive(conf->instance, "totals", "total_operations",
+                                   "pipe", val);
     else if (strcmp(name, "s_pass") == 0)
-      return varnish_submit_derive(conf->instance, "totals",
-                                   "total_operations", "pass", val);
+      return varnish_submit_derive(conf->instance, "totals", "total_operations",
+                                   "pass", val);
     else if (strcmp(name, "s_fetch") == 0)
-      return varnish_submit_derive(conf->instance, "totals",
-                                   "total_operations", "fetches", val);
+      return varnish_submit_derive(conf->instance, "totals", "total_operations",
+                                   "fetches", val);
     else if (strcmp(name, "s_synth") == 0)
       return varnish_submit_derive(conf->instance, "totals", "total_bytes",
                                    "synth", val);
@@ -528,8 +530,8 @@ static int varnish_monitor(void *priv,
       return varnish_submit_derive(conf->instance, "totals", "total_bytes",
                                    "pipe_out", val);
     else if (strcmp(name, "n_purges") == 0)
-      return varnish_submit_derive(conf->instance, "totals",
-                                   "total_operations", "purges", val);
+      return varnish_submit_derive(conf->instance, "totals", "total_operations",
+                                   "purges", val);
     else if (strcmp(name, "s_hdrbytes") == 0)
       return varnish_submit_derive(conf->instance, "totals", "total_bytes",
                                    "header-bytes", val);
@@ -537,11 +539,11 @@ static int varnish_monitor(void *priv,
       return varnish_submit_derive(conf->instance, "totals", "total_bytes",
                                    "body-bytes", val);
     else if (strcmp(name, "n_gzip") == 0)
-      return varnish_submit_derive(conf->instance, "totals",
-                                   "total_operations", "gzip", val);
+      return varnish_submit_derive(conf->instance, "totals", "total_operations",
+                                   "gzip", val);
     else if (strcmp(name, "n_gunzip") == 0)
-      return varnish_submit_derive(conf->instance, "totals",
-                                   "total_operations", "gunzip", val);
+      return varnish_submit_derive(conf->instance, "totals", "total_operations",
+                                   "gunzip", val);
   }
 
   if (conf->collect_uptime) {
@@ -558,8 +560,8 @@ static int varnish_monitor(void *priv,
       return varnish_submit_gauge(conf->instance, "vcl", "vcl", "avail_vcl",
                                   val);
     else if (strcmp(name, "n_vcl_discard") == 0)
-      return varnish_submit_gauge(conf->instance, "vcl", "vcl",
-                                  "discarded_vcl", val);
+      return varnish_submit_gauge(conf->instance, "vcl", "vcl", "discarded_vcl",
+                                  val);
     else if (strcmp(name, "vmods") == 0)
       return varnish_submit_gauge(conf->instance, "vcl", "objects", "vmod",
                                   val);
@@ -600,17 +602,17 @@ static int varnish_monitor(void *priv,
       return varnish_submit_derive(conf->instance, "workers", "total_threads",
                                    "dropped", val);
     else if (strcmp(name, "n_wrk_queue") == 0)
-      return varnish_submit_derive(conf->instance, "workers",
-                                   "total_requests", "queued", val);
+      return varnish_submit_derive(conf->instance, "workers", "total_requests",
+                                   "queued", val);
     else if (strcmp(name, "n_wrk_overflow") == 0)
-      return varnish_submit_derive(conf->instance, "workers",
-                                   "total_requests", "overflowed", val);
+      return varnish_submit_derive(conf->instance, "workers", "total_requests",
+                                   "overflowed", val);
     else if (strcmp(name, "n_wrk_queued") == 0)
-      return varnish_submit_derive(conf->instance, "workers",
-                                   "total_requests", "queued", val);
+      return varnish_submit_derive(conf->instance, "workers", "total_requests",
+                                   "queued", val);
     else if (strcmp(name, "n_wrk_lqueue") == 0)
-      return varnish_submit_derive(conf->instance, "workers",
-                                   "total_requests", "queue_length", val);
+      return varnish_submit_derive(conf->instance, "workers", "total_requests",
+                                   "queue_length", val);
   }
 
 #if HAVE_VARNISH_V4
@@ -1135,9 +1137,10 @@ static int varnish_init(void) /* {{{ */
       /* group = */ "varnish",
       /* name      = */ "varnish/localhost",
       /* callback  = */ varnish_read,
-      /* interval  = */ 0, &(user_data_t){
-                               .data = conf, .free_func = varnish_config_free,
-                           });
+      /* interval  = */ 0,
+      &(user_data_t){
+          .data = conf, .free_func = varnish_config_free,
+      });
 
   return 0;
 } /* }}} int varnish_init */
@@ -1295,16 +1298,17 @@ static int varnish_config_instance(const oconfig_item_t *ci) /* {{{ */
     return EINVAL;
   }
 
-  ssnprintf(callback_name, sizeof(callback_name), "varnish/%s",
-            (conf->instance == NULL) ? "localhost" : conf->instance);
+  snprintf(callback_name, sizeof(callback_name), "varnish/%s",
+           (conf->instance == NULL) ? "localhost" : conf->instance);
 
   plugin_register_complex_read(
       /* group = */ "varnish",
       /* name      = */ callback_name,
       /* callback  = */ varnish_read,
-      /* interval  = */ 0, &(user_data_t){
-                               .data = conf, .free_func = varnish_config_free,
-                           });
+      /* interval  = */ 0,
+      &(user_data_t){
+          .data = conf, .free_func = varnish_config_free,
+      });
 
   have_instance = 1;
 
index 14095df..ca6e831 100644 (file)
@@ -731,7 +731,7 @@ static void vcpu_submit(derive_t value, virDomainPtr dom, int vcpu_nr,
                         const char *type) {
   char type_instance[DATA_MAX_NAME_LEN];
 
-  ssnprintf(type_instance, sizeof(type_instance), "%d", vcpu_nr);
+  snprintf(type_instance, sizeof(type_instance), "%d", vcpu_nr);
   submit(dom, type, type_instance, &(value_t){.derive = value}, 1);
 }
 
@@ -752,8 +752,8 @@ static void disk_submit(struct lv_block_info *binfo, virDomainPtr dom,
   }
 
   char flush_type_instance[DATA_MAX_NAME_LEN];
-  ssnprintf(flush_type_instance, sizeof(flush_type_instance), "flush-%s",
-            type_instance);
+  snprintf(flush_type_instance, sizeof(flush_type_instance), "flush-%s",
+           type_instance);
 
   if ((binfo->bi.rd_req != -1) && (binfo->bi.wr_req != -1))
     submit_derive2("disk_ops", (derive_t)binfo->bi.rd_req,
@@ -828,8 +828,8 @@ static void domain_state_submit(virDomainPtr dom, int state, int reason) {
   const char *reason_str = "N/A";
 #endif
 
-  ssnprintf(msg, sizeof(msg), "Domain state: %s. Reason: %s", state_str,
-            reason_str);
+  snprintf(msg, sizeof(msg), "Domain state: %s. Reason: %s", state_str,
+           reason_str);
 
   int severity;
   switch (state) {
@@ -1180,8 +1180,7 @@ static void vcpu_pin_submit(virDomainPtr dom, int max_cpus, int vcpu,
     char type_instance[DATA_MAX_NAME_LEN];
     _Bool is_set = VIR_CPU_USABLE(cpu_maps, cpu_map_len, vcpu, cpu) ? 1 : 0;
 
-    ssnprintf(type_instance, sizeof(type_instance), "vcpu_%d-cpu_%d", vcpu,
-              cpu);
+    snprintf(type_instance, sizeof(type_instance), "vcpu_%d-cpu_%d", vcpu, cpu);
     submit(dom, "cpu_affinity", type_instance, &(value_t){.gauge = is_set}, 1);
   }
 }
@@ -1661,7 +1660,7 @@ static int lv_init_instance(size_t i, plugin_read_cb callback) {
 
   memset(lv_ud, 0, sizeof(*lv_ud));
 
-  ssnprintf(inst->tag, sizeof(inst->tag), "%s-%zu", PLUGIN_NAME, i);
+  snprintf(inst->tag, sizeof(inst->tag), "%s-%zu", PLUGIN_NAME, i);
   inst->id = i;
 
   user_data_t *ud = &(lv_ud->ud);
@@ -1721,8 +1720,8 @@ static int lv_domain_get_tag(xmlXPathContextPtr xpath_ctx, const char *dom_name,
     goto done;
   }
 
-  ssnprintf(xpath_str, sizeof(xpath_str), "/domain/metadata/%s:%s/text()",
-            METADATA_VM_PARTITION_PREFIX, METADATA_VM_PARTITION_ELEMENT);
+  snprintf(xpath_str, sizeof(xpath_str), "/domain/metadata/%s:%s/text()",
+           METADATA_VM_PARTITION_PREFIX, METADATA_VM_PARTITION_ELEMENT);
   xpath_obj = xmlXPathEvalExpression((xmlChar *)xpath_str, xpath_ctx);
   if (xpath_obj == NULL) {
     ERROR(PLUGIN_NAME " plugin: xmlXPathEval(%s) failed on domain %s",
@@ -2157,7 +2156,7 @@ static int ignore_device_match(ignorelist_t *il, const char *domname,
     ERROR(PLUGIN_NAME " plugin: malloc failed.");
     return 0;
   }
-  ssnprintf(name, n, "%s:%s", domname, devpath);
+  snprintf(name, n, "%s:%s", domname, devpath);
   r = ignorelist_match(il, name);
   sfree(name);
   return r;
index cb3cc25..489a367 100644 (file)
@@ -22,8 +22,8 @@
  *   Florian octo Forster <octo at collectd.org>
  **/
 
-#include "virt.c" /* sic */
 #include "testing.h"
+#include "virt.c" /* sic */
 
 #include <unistd.h>
 
index a2ca0de..6f9d46b 100644 (file)
@@ -160,7 +160,7 @@ static int vserver_read(void) {
     if (dent->d_name[0] == '.')
       continue;
 
-    len = ssnprintf(file, sizeof(file), PROCDIR "/%s", dent->d_name);
+    len = snprintf(file, sizeof(file), PROCDIR "/%s", dent->d_name);
     if ((len < 0) || (len >= BUFSIZE))
       continue;
 
@@ -176,7 +176,7 @@ static int vserver_read(void) {
       continue;
 
     /* socket message accounting */
-    len = ssnprintf(file, sizeof(file), PROCDIR "/%s/cacct", dent->d_name);
+    len = snprintf(file, sizeof(file), PROCDIR "/%s/cacct", dent->d_name);
     if ((len < 0) || ((size_t)len >= sizeof(file)))
       continue;
 
@@ -220,7 +220,7 @@ static int vserver_read(void) {
     }
 
     /* thread information and load */
-    len = ssnprintf(file, sizeof(file), PROCDIR "/%s/cvirt", dent->d_name);
+    len = snprintf(file, sizeof(file), PROCDIR "/%s/cvirt", dent->d_name);
     if ((len < 0) || ((size_t)len >= sizeof(file)))
       continue;
 
@@ -266,7 +266,7 @@ static int vserver_read(void) {
     }
 
     /* processes and memory usage */
-    len = ssnprintf(file, sizeof(file), PROCDIR "/%s/limit", dent->d_name);
+    len = snprintf(file, sizeof(file), PROCDIR "/%s/limit", dent->d_name);
     if ((len < 0) || ((size_t)len >= sizeof(file)))
       continue;
 
index 206cdc2..a8d1320 100644 (file)
@@ -545,11 +545,11 @@ static int wg_config_node(oconfig_item_t *ci) {
 
   /* FIXME: Legacy configuration syntax. */
   if (cb->name == NULL)
-    ssnprintf(callback_name, sizeof(callback_name), "write_graphite/%s/%s/%s",
-              cb->node, cb->service, cb->protocol);
+    snprintf(callback_name, sizeof(callback_name), "write_graphite/%s/%s/%s",
+             cb->node, cb->service, cb->protocol);
   else
-    ssnprintf(callback_name, sizeof(callback_name), "write_graphite/%s",
-              cb->name);
+    snprintf(callback_name, sizeof(callback_name), "write_graphite/%s",
+             cb->name);
 
   plugin_register_write(callback_name, wg_write,
                         &(user_data_t){
index d5c91d9..06327ed 100644 (file)
@@ -119,6 +119,7 @@ static int wh_post_nolock(wh_callback_t *cb, char const *data) /* {{{ */
 {
   int status = 0;
 
+  curl_easy_setopt(cb->curl, CURLOPT_URL, cb->location);
   curl_easy_setopt(cb->curl, CURLOPT_POSTFIELDS, data);
   status = curl_easy_perform(cb->curl);
 
@@ -168,7 +169,6 @@ static int wh_callback_init(wh_callback_t *cb) /* {{{ */
   curl_easy_setopt(cb->curl, CURLOPT_HTTPHEADER, cb->headers);
 
   curl_easy_setopt(cb->curl, CURLOPT_ERRORBUFFER, cb->curl_errbuf);
-  curl_easy_setopt(cb->curl, CURLOPT_URL, cb->location);
   curl_easy_setopt(cb->curl, CURLOPT_FOLLOWLOCATION, 1L);
   curl_easy_setopt(cb->curl, CURLOPT_MAXREDIRS, 50L);
 
@@ -190,8 +190,8 @@ static int wh_callback_init(wh_callback_t *cb) /* {{{ */
       return -1;
     }
 
-    ssnprintf(cb->credentials, credentials_size, "%s:%s", cb->user,
-              (cb->pass == NULL) ? "" : cb->pass);
+    snprintf(cb->credentials, credentials_size, "%s:%s", cb->user,
+             (cb->pass == NULL) ? "" : cb->pass);
     curl_easy_setopt(cb->curl, CURLOPT_USERPWD, cb->credentials);
 #endif
     curl_easy_setopt(cb->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
@@ -369,9 +369,9 @@ static int wh_write_command(const data_set_t *ds,
     return status;
   }
 
-  command_len = (size_t)ssnprintf(command, sizeof(command),
-                                  "PUTVAL %s interval=%.3f %s\r\n", key,
-                                  CDTIME_T_TO_DOUBLE(vl->interval), values);
+  command_len = (size_t)snprintf(command, sizeof(command),
+                                 "PUTVAL %s interval=%.3f %s\r\n", key,
+                                 CDTIME_T_TO_DOUBLE(vl->interval), values);
   if (command_len >= sizeof(command)) {
     ERROR("write_http plugin: Command buffer too small: "
           "Need %zu bytes.",
@@ -791,7 +791,7 @@ static int wh_config_node(oconfig_item_t *ci) /* {{{ */
   /* Nulls the buffer and sets ..._free and ..._fill. */
   wh_reset_buffer(cb);
 
-  ssnprintf(callback_name, sizeof(callback_name), "write_http/%s", cb->name);
+  snprintf(callback_name, sizeof(callback_name), "write_http/%s", cb->name);
   DEBUG("write_http: Registering write callback '%s' with URL '%s'",
         callback_name, cb->location);
 
index ca400ac..3c57380 100644 (file)
@@ -89,7 +89,7 @@ static uint32_t kafka_hash(const char *keydata, size_t keylen) {
 #define KAFKA_RANDOM_KEY_BUFFER                                                \
   (char[KAFKA_RANDOM_KEY_SIZE]) { "" }
 static char *kafka_random_key(char buffer[static KAFKA_RANDOM_KEY_SIZE]) {
-  ssnprintf(buffer, KAFKA_RANDOM_KEY_SIZE, "%08" PRIX32, cdrand_u());
+  snprintf(buffer, KAFKA_RANDOM_KEY_SIZE, "%08" PRIX32, cdrand_u());
   return buffer;
 }
 
@@ -398,8 +398,8 @@ static void kafka_config_topic(rd_kafka_conf_t *conf,
   rd_kafka_topic_conf_set_partitioner_cb(tctx->conf, kafka_partition);
   rd_kafka_topic_conf_set_opaque(tctx->conf, tctx);
 
-  ssnprintf(callback_name, sizeof(callback_name), "write_kafka/%s",
-            tctx->topic_name);
+  snprintf(callback_name, sizeof(callback_name), "write_kafka/%s",
+           tctx->topic_name);
 
   status = plugin_register_write(
       callback_name, kafka_write,
index e90900e..46b6d86 100644 (file)
@@ -93,10 +93,10 @@ static bson_t *wm_create_bson(const data_set_t *ds, /* {{{ */
   BSON_APPEND_UTF8(ret, "type_instance", vl->type_instance);
 
   BSON_APPEND_ARRAY_BEGIN(ret, "values", &subarray); /* {{{ */
-  for (int i = 0; i < ds->ds_num; i++) {
+  for (size_t i = 0; i < ds->ds_num; i++) {
     char key[16];
 
-    ssnprintf(key, sizeof(key), "%i", i);
+    snprintf(key, sizeof(key), "%zu", i);
 
     if (ds->ds[i].type == DS_TYPE_GAUGE)
       BSON_APPEND_DOUBLE(&subarray, key, vl->values[i].gauge);
@@ -109,7 +109,7 @@ static bson_t *wm_create_bson(const data_set_t *ds, /* {{{ */
     else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
       BSON_APPEND_INT64(&subarray, key, vl->values[i].absolute);
     else {
-      ERROR("write_mongodb plugin: Unknown ds_type %d for index %d",
+      ERROR("write_mongodb plugin: Unknown ds_type %d for index %zu",
             ds->ds[i].type, i);
       bson_destroy(ret);
       return NULL;
@@ -118,10 +118,10 @@ static bson_t *wm_create_bson(const data_set_t *ds, /* {{{ */
   bson_append_array_end(ret, &subarray); /* }}} values */
 
   BSON_APPEND_ARRAY_BEGIN(ret, "dstypes", &subarray); /* {{{ */
-  for (int i = 0; i < ds->ds_num; i++) {
+  for (size_t i = 0; i < ds->ds_num; i++) {
     char key[16];
 
-    ssnprintf(key, sizeof(key), "%i", i);
+    snprintf(key, sizeof(key), "%zu", i);
 
     if (store_rates)
       BSON_APPEND_UTF8(&subarray, key, "gauge");
@@ -131,10 +131,10 @@ static bson_t *wm_create_bson(const data_set_t *ds, /* {{{ */
   bson_append_array_end(ret, &subarray); /* }}} dstypes */
 
   BSON_APPEND_ARRAY_BEGIN(ret, "dsnames", &subarray); /* {{{ */
-  for (int i = 0; i < ds->ds_num; i++) {
+  for (size_t i = 0; i < ds->ds_num; i++) {
     char key[16];
 
-    ssnprintf(key, sizeof(key), "%i", i);
+    snprintf(key, sizeof(key), "%zu", i);
     BSON_APPEND_UTF8(&subarray, key, ds->ds[i].name);
   }
   bson_append_array_end(ret, &subarray); /* }}} dsnames */
@@ -366,9 +366,9 @@ static int wm_config_node(oconfig_item_t *ci) /* {{{ */
   }
 
   if (status == 0) {
-    char cb_name[DATA_MAX_NAME_LEN];
+    char cb_name[sizeof("write_mongodb/") + DATA_MAX_NAME_LEN];
 
-    ssnprintf(cb_name, sizeof(cb_name), "write_mongodb/%s", node->name);
+    snprintf(cb_name, sizeof(cb_name), "write_mongodb/%s", node->name);
 
     status =
         plugin_register_write(cb_name, wm_write,
index 5264998..eac0d68 100644 (file)
@@ -159,8 +159,8 @@ static char *format_labels(char *buffer, size_t buffer_size,
    * know that they are sane. */
   for (size_t i = 0; i < m->n_label; i++) {
     char value[LABEL_VALUE_SIZE];
-    ssnprintf(labels[i], LABEL_BUFFER_SIZE, "%s=\"%s\"", m->label[i]->name,
-              escape_label_value(value, sizeof(value), m->label[i]->value));
+    snprintf(labels[i], LABEL_BUFFER_SIZE, "%s=\"%s\"", m->label[i]->name,
+             escape_label_value(value, sizeof(value), m->label[i]->value));
   }
 
   strjoin(buffer, buffer_size, labels, m->n_label, ",");
@@ -178,13 +178,13 @@ static void format_text(ProtobufCBuffer *buffer) {
   while (c_avl_iterator_next(iter, (void *)&unused_name, (void *)&fam) == 0) {
     char line[1024]; /* 4x DATA_MAX_NAME_LEN? */
 
-    ssnprintf(line, sizeof(line), "# HELP %s %s\n", fam->name, fam->help);
+    snprintf(line, sizeof(line), "# HELP %s %s\n", fam->name, fam->help);
     buffer->append(buffer, strlen(line), (uint8_t *)line);
 
-    ssnprintf(line, sizeof(line), "# TYPE %s %s\n", fam->name,
-              (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__GAUGE)
-                  ? "gauge"
-                  : "counter");
+    snprintf(line, sizeof(line), "# TYPE %s %s\n", fam->name,
+             (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__GAUGE)
+                 ? "gauge"
+                 : "counter");
     buffer->append(buffer, strlen(line), (uint8_t *)line);
 
     for (size_t i = 0; i < fam->n_metric; i++) {
@@ -194,17 +194,17 @@ static void format_text(ProtobufCBuffer *buffer) {
 
       char timestamp_ms[24] = "";
       if (m->has_timestamp_ms)
-        ssnprintf(timestamp_ms, sizeof(timestamp_ms), " %" PRIi64,
-                  m->timestamp_ms);
+        snprintf(timestamp_ms, sizeof(timestamp_ms), " %" PRIi64,
+                 m->timestamp_ms);
 
       if (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__GAUGE)
-        ssnprintf(line, sizeof(line), "%s{%s} " GAUGE_FORMAT "%s\n", fam->name,
-                  format_labels(labels, sizeof(labels), m), m->gauge->value,
-                  timestamp_ms);
+        snprintf(line, sizeof(line), "%s{%s} " GAUGE_FORMAT "%s\n", fam->name,
+                 format_labels(labels, sizeof(labels), m), m->gauge->value,
+                 timestamp_ms);
       else /* if (fam->type == IO__PROMETHEUS__CLIENT__METRIC_TYPE__COUNTER) */
-        ssnprintf(line, sizeof(line), "%s{%s} %.0f%s\n", fam->name,
-                  format_labels(labels, sizeof(labels), m), m->counter->value,
-                  timestamp_ms);
+        snprintf(line, sizeof(line), "%s{%s} %.0f%s\n", fam->name,
+                 format_labels(labels, sizeof(labels), m), m->counter->value,
+                 timestamp_ms);
 
       buffer->append(buffer, strlen(line), (uint8_t *)line);
     }
@@ -212,8 +212,8 @@ static void format_text(ProtobufCBuffer *buffer) {
   c_avl_iterator_destroy(iter);
 
   char server[1024];
-  ssnprintf(server, sizeof(server), "\n# collectd/write_prometheus %s at %s\n",
-            PACKAGE_VERSION, hostname_g);
+  snprintf(server, sizeof(server), "\n# collectd/write_prometheus %s at %s\n",
+           PACKAGE_VERSION, hostname_g);
   buffer->append(buffer, strlen(server), (uint8_t *)server);
 
   pthread_mutex_unlock(&metrics_lock);
@@ -599,8 +599,8 @@ static int metric_family_update(Io__Prometheus__Client__MetricFamily *fam,
   if (m == NULL)
     return -1;
 
-  return metric_update(m, vl->values[ds_index], ds->ds[ds_index].type,
-                       vl->time, vl->interval);
+  return metric_update(m, vl->values[ds_index], ds->ds[ds_index].type, vl->time,
+                       vl->interval);
 }
 
 /* metric_family_destroy frees the memory used by a metric family. */
@@ -631,7 +631,7 @@ metric_family_create(char *name, data_set_t const *ds, value_list_t const *vl,
   msg->name = name;
 
   char help[1024];
-  ssnprintf(
+  snprintf(
       help, sizeof(help),
       "write_prometheus plugin: '%s' Type: '%s', Dstype: '%s', Dsname: '%s'",
       vl->plugin, vl->type, DS_TYPE_TO_STRING(ds->ds[ds_index].type),
index f7215b5..5a029de 100644 (file)
@@ -70,10 +70,9 @@ static int wr_write(const data_set_t *ds, /* {{{ */
   status = FORMAT_VL(ident, sizeof(ident), vl);
   if (status != 0)
     return status;
-  ssnprintf(key, sizeof(key), "%s%s",
-            (node->prefix != NULL) ? node->prefix : REDIS_DEFAULT_PREFIX,
-            ident);
-  ssnprintf(time, sizeof(time), "%.9f", CDTIME_T_TO_DOUBLE(vl->time));
+  snprintf(key, sizeof(key), "%s%s",
+           (node->prefix != NULL) ? node->prefix : REDIS_DEFAULT_PREFIX, ident);
+  snprintf(time, sizeof(time), "%.9f", CDTIME_T_TO_DOUBLE(vl->time));
 
   value_size = sizeof(value);
   value_ptr = &value[0];
@@ -217,14 +216,15 @@ static int wr_config_node(oconfig_item_t *ci) /* {{{ */
   } /* for (i = 0; i < ci->children_num; i++) */
 
   if (status == 0) {
-    char cb_name[DATA_MAX_NAME_LEN];
+    char cb_name[sizeof("write_redis/") + DATA_MAX_NAME_LEN];
 
-    ssnprintf(cb_name, sizeof(cb_name), "write_redis/%s", node->name);
+    snprintf(cb_name, sizeof(cb_name), "write_redis/%s", node->name);
 
-    status = plugin_register_write(
-        cb_name, wr_write, &(user_data_t){
-                               .data = node, .free_func = wr_config_free,
-                           });
+    status =
+        plugin_register_write(cb_name, wr_write,
+                              &(user_data_t){
+                                  .data = node, .free_func = wr_config_free,
+                              });
   }
 
   if (status != 0)
index 5bd0cf4..6db3ef5 100644 (file)
@@ -293,18 +293,17 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */
               vl->type_instance);
   if (host->always_append_ds || (ds->ds_num > 1)) {
     if (host->event_service_prefix == NULL)
-      ssnprintf(service_buffer, sizeof(service_buffer), "%s/%s",
-                &name_buffer[1], ds->ds[index].name);
+      snprintf(service_buffer, sizeof(service_buffer), "%s/%s", &name_buffer[1],
+               ds->ds[index].name);
     else
-      ssnprintf(service_buffer, sizeof(service_buffer), "%s%s/%s",
-                host->event_service_prefix, &name_buffer[1],
-                ds->ds[index].name);
+      snprintf(service_buffer, sizeof(service_buffer), "%s%s/%s",
+               host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
   } else {
     if (host->event_service_prefix == NULL)
       sstrncpy(service_buffer, &name_buffer[1], sizeof(service_buffer));
     else
-      ssnprintf(service_buffer, sizeof(service_buffer), "%s%s",
-                host->event_service_prefix, &name_buffer[1]);
+      snprintf(service_buffer, sizeof(service_buffer), "%s%s",
+               host->event_service_prefix, &name_buffer[1]);
   }
 
   riemann_event_set(
@@ -352,8 +351,8 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */
   if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL)) {
     char ds_type[DATA_MAX_NAME_LEN];
 
-    ssnprintf(ds_type, sizeof(ds_type), "%s:rate",
-              DS_TYPE_TO_STRING(ds->ds[index].type));
+    snprintf(ds_type, sizeof(ds_type), "%s:rate",
+             DS_TYPE_TO_STRING(ds->ds[index].type));
     riemann_event_string_attribute_add(event, "ds_type", ds_type);
   } else {
     riemann_event_string_attribute_add(event, "ds_type",
@@ -363,7 +362,7 @@ wrr_value_to_event(struct riemann_host const *host, /* {{{ */
   {
     char ds_index[DATA_MAX_NAME_LEN];
 
-    ssnprintf(ds_index, sizeof(ds_index), "%zu", index);
+    snprintf(ds_index, sizeof(ds_index), "%zu", index);
     riemann_event_string_attribute_add(event, "ds_index", ds_index);
   }
 
@@ -802,8 +801,8 @@ static int wrr_config_node(oconfig_item_t *ci) /* {{{ */
     return status;
   }
 
-  ssnprintf(callback_name, sizeof(callback_name), "write_riemann/%s",
-            host->name);
+  snprintf(callback_name, sizeof(callback_name), "write_riemann/%s",
+           host->name);
 
   user_data_t ud = {.data = host, .free_func = wrr_free};
 
index 56acb63..ce23e65 100644 (file)
@@ -420,8 +420,8 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */
   // incorporate the data source type
   if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL)) {
     char ds_type[DATA_MAX_NAME_LEN];
-    ssnprintf(ds_type, sizeof(ds_type), "%s:rate",
-              DS_TYPE_TO_STRING(ds->ds[index].type));
+    snprintf(ds_type, sizeof(ds_type), "%s:rate",
+             DS_TYPE_TO_STRING(ds->ds[index].type));
     res = my_asprintf(&temp_str, "%s, \"collectd_data_source_type\": \"%s\"",
                       ret_str, ds_type);
     free(ret_str);
@@ -454,7 +454,7 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */
   // incorporate the data source index
   {
     char ds_index[DATA_MAX_NAME_LEN];
-    ssnprintf(ds_index, sizeof(ds_index), "%zu", index);
+    snprintf(ds_index, sizeof(ds_index), "%zu", index);
     res = my_asprintf(&temp_str, "%s, \"collectd_data_source_index\": %s",
                       ret_str, ds_index);
     free(ret_str);
@@ -534,17 +534,17 @@ static char *sensu_value_to_json(struct sensu_host const *host, /* {{{ */
                      host->separator);
   if (host->always_append_ds || (ds->ds_num > 1)) {
     if (host->event_service_prefix == NULL)
-      ssnprintf(service_buffer, sizeof(service_buffer), "%s.%s", name_buffer,
-                ds->ds[index].name);
+      snprintf(service_buffer, sizeof(service_buffer), "%s.%s", name_buffer,
+               ds->ds[index].name);
     else
-      ssnprintf(service_buffer, sizeof(service_buffer), "%s%s.%s",
-                host->event_service_prefix, name_buffer, ds->ds[index].name);
+      snprintf(service_buffer, sizeof(service_buffer), "%s%s.%s",
+               host->event_service_prefix, name_buffer, ds->ds[index].name);
   } else {
     if (host->event_service_prefix == NULL)
       sstrncpy(service_buffer, name_buffer, sizeof(service_buffer));
     else
-      ssnprintf(service_buffer, sizeof(service_buffer), "%s%s",
-                host->event_service_prefix, name_buffer);
+      snprintf(service_buffer, sizeof(service_buffer), "%s%s",
+               host->event_service_prefix, name_buffer);
   }
 
   // Replace collectd sensor name reserved characters so that time series DB is
@@ -1141,7 +1141,7 @@ static int sensu_config_node(oconfig_item_t *ci) /* {{{ */
     return -1;
   }
 
-  ssnprintf(callback_name, sizeof(callback_name), "write_sensu/%s", host->name);
+  snprintf(callback_name, sizeof(callback_name), "write_sensu/%s", host->name);
 
   user_data_t ud = {.data = host, .free_func = sensu_free};
 
index 1a1cd64..10f636c 100644 (file)
@@ -325,7 +325,7 @@ static int wt_format_values(char *ret, size_t ret_len, int ds_num,
 
 #define BUFFER_ADD(...)                                                        \
   do {                                                                         \
-    status = ssnprintf(ret + offset, ret_len - offset, __VA_ARGS__);           \
+    status = snprintf(ret + offset, ret_len - offset, __VA_ARGS__);            \
     if (status < 1) {                                                          \
       sfree(rates);                                                            \
       return -1;                                                               \
@@ -388,36 +388,36 @@ static int wt_format_name(char *ret, int ret_len, const value_list_t *vl,
   if (ds_name != NULL) {
     if (vl->plugin_instance[0] == '\0') {
       if (vl->type_instance[0] == '\0') {
-        ssnprintf(ret, ret_len, "%s%s.%s.%s", prefix, vl->plugin, vl->type,
-                  ds_name);
+        snprintf(ret, ret_len, "%s%s.%s.%s", prefix, vl->plugin, vl->type,
+                 ds_name);
       } else {
-        ssnprintf(ret, ret_len, "%s%s.%s.%s.%s", prefix, vl->plugin, vl->type,
-                  vl->type_instance, ds_name);
+        snprintf(ret, ret_len, "%s%s.%s.%s.%s", prefix, vl->plugin, vl->type,
+                 vl->type_instance, ds_name);
       }
     } else { /* vl->plugin_instance != "" */
       if (vl->type_instance[0] == '\0') {
-        ssnprintf(ret, ret_len, "%s%s.%s.%s.%s", prefix, vl->plugin,
-                  vl->plugin_instance, vl->type, ds_name);
+        snprintf(ret, ret_len, "%s%s.%s.%s.%s", prefix, vl->plugin,
+                 vl->plugin_instance, vl->type, ds_name);
       } else {
-        ssnprintf(ret, ret_len, "%s%s.%s.%s.%s.%s", prefix, vl->plugin,
-                  vl->plugin_instance, vl->type, vl->type_instance, ds_name);
+        snprintf(ret, ret_len, "%s%s.%s.%s.%s.%s", prefix, vl->plugin,
+                 vl->plugin_instance, vl->type, vl->type_instance, ds_name);
       }
     }
   } else { /* ds_name == NULL */
     if (vl->plugin_instance[0] == '\0') {
       if (vl->type_instance[0] == '\0') {
-        ssnprintf(ret, ret_len, "%s%s.%s", prefix, vl->plugin, vl->type);
+        snprintf(ret, ret_len, "%s%s.%s", prefix, vl->plugin, vl->type);
       } else {
-        ssnprintf(ret, ret_len, "%s%s.%s.%s", prefix, vl->plugin,
-                  vl->type_instance, vl->type);
+        snprintf(ret, ret_len, "%s%s.%s.%s", prefix, vl->plugin,
+                 vl->type_instance, vl->type);
       }
     } else { /* vl->plugin_instance != "" */
       if (vl->type_instance[0] == '\0') {
-        ssnprintf(ret, ret_len, "%s%s.%s.%s", prefix, vl->plugin,
-                  vl->plugin_instance, vl->type);
+        snprintf(ret, ret_len, "%s%s.%s.%s", prefix, vl->plugin,
+                 vl->plugin_instance, vl->type);
       } else {
-        ssnprintf(ret, ret_len, "%s%s.%s.%s.%s", prefix, vl->plugin,
-                  vl->plugin_instance, vl->type, vl->type_instance);
+        snprintf(ret, ret_len, "%s%s.%s.%s.%s", prefix, vl->plugin,
+                 vl->plugin_instance, vl->type, vl->type_instance);
       }
     }
   }
@@ -456,8 +456,8 @@ static int wt_send_message(const char *key, const char *value, cdtime_t time,
   }
 
   status =
-      ssnprintf(message, sizeof(message), "put %s %.0f %s fqdn=%s %s %s\r\n",
-                key, CDTIME_T_TO_DOUBLE(time), value, host, tags, host_tags);
+      snprintf(message, sizeof(message), "put %s %.0f %s fqdn=%s %s %s\r\n",
+               key, CDTIME_T_TO_DOUBLE(time), value, host, tags, host_tags);
   sfree(temp);
   if (status < 0)
     return -1;
@@ -607,9 +607,9 @@ static int wt_config_tsd(oconfig_item_t *ci) {
     }
   }
 
-  ssnprintf(callback_name, sizeof(callback_name), "write_tsdb/%s/%s",
-            cb->node != NULL ? cb->node : WT_DEFAULT_NODE,
-            cb->service != NULL ? cb->service : WT_DEFAULT_SERVICE);
+  snprintf(callback_name, sizeof(callback_name), "write_tsdb/%s/%s",
+           cb->node != NULL ? cb->node : WT_DEFAULT_NODE,
+           cb->service != NULL ? cb->service : WT_DEFAULT_SERVICE);
 
   user_data_t user_data = {.data = cb, .free_func = wt_callback_free};
 
index bf17864..8cba476 100644 (file)
@@ -112,7 +112,7 @@ static void submit_value(int cpu_num, gauge_t value) {
   sstrncpy(vl.type_instance, "load", sizeof(vl.type_instance));
 
   if (cpu_num >= 0) {
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", cpu_num);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", cpu_num);
   }
   plugin_dispatch_values(&vl);
 } /* static void submit_value */
index cf858f8..730d304 100644 (file)
@@ -118,7 +118,7 @@ static long long get_zfs_value(kstat_t *dummy __attribute__((unused)),
   size_t valuelen = sizeof(value);
   int rv;
 
-  ssnprintf(buffer, sizeof(buffer), "%s%s", zfs_arcstat, name);
+  snprintf(buffer, sizeof(buffer), "%s%s", zfs_arcstat, name);
   rv = sysctlbyname(buffer, (void *)&value, &valuelen,
                     /* new value = */ NULL, /* new length = */ (size_t)0);
   if (rv == 0)
@@ -216,12 +216,14 @@ static int za_read(void) {
   // See kstat_seq_show_headers module/spl/spl-kstat.c of the spl kernel
   // module.
   if (fgets(buffer, sizeof(buffer), fh) == NULL) {
-    ERROR("zfs_arc plugin: \"%s\" does not contain a single line.", ZOL_ARCSTATS_FILE);
+    ERROR("zfs_arc plugin: \"%s\" does not contain a single line.",
+          ZOL_ARCSTATS_FILE);
     fclose(fh);
     return -1;
   }
   if (fgets(buffer, sizeof(buffer), fh) == NULL) {
-    ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.", ZOL_ARCSTATS_FILE);
+    ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.",
+          ZOL_ARCSTATS_FILE);
     fclose(fh);
     return -1;
   }