X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fteamspeak2.c;h=0e683ce9fc42cb17a3f18802904f90df94bc4bfd;hb=6cf795578e3f29efbaeea974fdcd1049105dd7ff;hp=56e8d14e968642d4f632542ac8f9047a3562bf0d;hpb=06efe4f50bbdfbade922b8a3ee4576eb2cc4562c;p=collectd.git diff --git a/src/teamspeak2.c b/src/teamspeak2.c index 56e8d14e..638109ca 100644 --- a/src/teamspeak2.c +++ b/src/teamspeak2.c @@ -83,13 +83,12 @@ static int tss2_add_vserver (int vserver_port) } /* Allocate memory */ - entry = (vserver_list_t *) malloc (sizeof (vserver_list_t)); + entry = calloc (1, sizeof (*entry)); if (entry == NULL) { - ERROR ("teamspeak2 plugin: malloc failed."); + ERROR ("teamspeak2 plugin: calloc failed."); return (-1); } - memset (entry, 0, sizeof (vserver_list_t)); /* Save data */ entry->port = vserver_port; @@ -140,7 +139,7 @@ static void tss2_submit_gauge (const char *plugin_instance, if (type_instance != NULL) sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance)); - + plugin_dispatch_values (&vl); } /* void tss2_submit_gauge */ @@ -257,6 +256,7 @@ static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh) WARNING ("teamspeak2 plugin: connect failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); close (sd); + sd = -1; continue; } @@ -351,7 +351,7 @@ static int tss2_receive_line (FILE *fh, char *buffer, int buffer_size) * Receive a single line from the given file object */ char *temp; - + /* * fgets is blocking but much easier then doing anything else * TODO: Non-blocking Version would be safer @@ -434,7 +434,7 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh, char buffer[4096]; char *value; char *endptr = NULL; - + status = tss2_receive_line (read_fh, buffer, sizeof (buffer)); if (status != 0) { @@ -445,7 +445,7 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh, return (-1); } buffer[sizeof (buffer) - 1] = 0; - + if (strncmp ("average_packet_loss=", buffer, strlen ("average_packet_loss=")) == 0) { @@ -461,9 +461,9 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh, } value++; } - + value = &buffer[20]; - + packet_loss = strtod (value, &endptr); if (value == endptr) { @@ -488,7 +488,7 @@ static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh, buffer); } } - + *ret_value = packet_loss; return (0); } /* int tss2_vserver_gapl */ @@ -558,7 +558,7 @@ static int tss2_read_vserver (vserver_list_t *vserver) char *key; char *value; char *endptr = NULL; - + /* Read one line of the server's answer */ status = tss2_receive_line (read_fh, buffer, sizeof (buffer)); if (status != 0) @@ -723,7 +723,7 @@ static int tss2_config (const char *key, const char *value) /* * Interpret configuration values */ - if (strcasecmp ("Host", key) == 0) + if (strcasecmp ("Host", key) == 0) { char *temp; @@ -753,7 +753,7 @@ static int tss2_config (const char *key, const char *value) { /* Server variable found */ int status; - + status = tss2_add_vserver (atoi (value)); if (status != 0) return (1); @@ -803,10 +803,10 @@ static int tss2_read (void) continue; } } - + if (success == 0) return (-1); - return (0); + return (0); } /* int tss2_read */ static int tss2_shutdown(void) @@ -832,7 +832,7 @@ static int tss2_shutdown(void) /* Get rid of the configuration */ sfree (config_host); sfree (config_port); - + return (0); } /* int tss2_shutdown */