X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fteamspeak2.c;h=a709e79dd21308f2d8c42551c9e0f619a9a1c1cd;hb=1aa4295ba6875ceb02a7383237bc2485ffab9c1e;hp=638109caac37b3af2f95c215a947c2bc0bec2c7f;hpb=ab11d1b4db61f750f51be6e41dbe8320d3c65404;p=collectd.git diff --git a/src/teamspeak2.c b/src/teamspeak2.c index 638109ca..a709e79d 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -22,6 +22,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -120,12 +121,9 @@ static void tss2_submit_gauge (const char *plugin_instance, /* * Submits a gauge value to the collectd daemon */ - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].gauge = value; - - vl.values = values; + vl.values = &(value_t) { .gauge = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "teamspeak2", sizeof (vl.plugin)); @@ -149,14 +147,14 @@ static void tss2_submit_io (const char *plugin_instance, const char *type, /* * Submits the io rx/tx tuple to the collectd daemon */ - value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - - values[0].derive = rx; - values[1].derive = tx; + value_t values[] = { + { .derive = rx }, + { .derive = tx }, + }; vl.values = values; - vl.values_len = 2; + vl.values_len = STATIC_ARRAY_SIZE (values); sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "teamspeak2", sizeof (vl.plugin)); @@ -198,9 +196,7 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) * Returns connected file objects or establishes the connection * if it's not already present */ - struct addrinfo ai_hints; struct addrinfo *ai_head; - struct addrinfo *ai_ptr; int sd = -1; int status; @@ -216,12 +212,11 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) } /* Get all addrs for this hostname */ - memset (&ai_hints, 0, sizeof (ai_hints)); -#ifdef AI_ADDRCONFIG - ai_hints.ai_flags |= AI_ADDRCONFIG; -#endif - ai_hints.ai_family = AF_UNSPEC; - ai_hints.ai_socktype = SOCK_STREAM; + struct addrinfo ai_hints = { + .ai_family = AF_UNSPEC, + .ai_flags = AI_ADDRCONFIG, + .ai_socktype = SOCK_STREAM + }; status = getaddrinfo ((config_host != NULL) ? config_host : DEFAULT_HOST, (config_port != NULL) ? config_port : DEFAULT_PORT, @@ -235,7 +230,7 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) } /* Try all given hosts until we can connect to one */ - for (ai_ptr = ai_head; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) + for (struct addrinfo *ai_ptr = ai_head; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) { /* Create socket */ sd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, @@ -511,7 +506,7 @@ static int tss2_read_vserver (vserver_list_t *vserver) gauge_t packet_loss = NAN; int valid = 0; - char plugin_instance[DATA_MAX_NAME_LEN]; + char plugin_instance[DATA_MAX_NAME_LEN] = { 0 }; FILE *read_fh; FILE *write_fh; @@ -527,8 +522,6 @@ static int tss2_read_vserver (vserver_list_t *vserver) if (vserver == NULL) { /* Request global information */ - memset (plugin_instance, 0, sizeof (plugin_instance)); - status = tss2_send_request (write_fh, "gi\r\n"); } else @@ -773,7 +766,6 @@ static int tss2_read (void) * Poll function which collects global and vserver information * and submits it to collectd */ - vserver_list_t *vserver; int success = 0; int status; @@ -789,7 +781,7 @@ static int tss2_read (void) } /* Handle vservers */ - for (vserver = server_list; vserver != NULL; vserver = vserver->next) + for (vserver_list_t *vserver = server_list; vserver != NULL; vserver = vserver->next) { status = tss2_read_vserver (vserver); if (status == 0)