X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fping.c;h=88661e94ba5a5e60c99281a9fffc26d6c3265849;hb=d41585ea72b7e2768c4dd507016ffd0cc3a6e130;hp=cac8a3fde43540c08249877e54138cefdc6e590f;hpb=ef7cc595639328626c90f4b4bf984f101b389166;p=collectd.git diff --git a/src/ping.c b/src/ping.c index cac8a3fd..88661e94 100644 --- a/src/ping.c +++ b/src/ping.c @@ -244,7 +244,7 @@ static int ping_dispatch_all (pingobj_t *pingobj) /* {{{ */ static void *ping_thread (void *arg) /* {{{ */ { - static pingobj_t *pingobj = NULL; + pingobj_t *pingobj = NULL; struct timeval tv_begin; struct timeval tv_end; @@ -399,7 +399,7 @@ static int start_thread (void) /* {{{ */ pthread_mutex_unlock (&ping_lock); return (-1); } - + pthread_mutex_unlock (&ping_lock); return (0); } /* }}} int start_thread */ @@ -427,8 +427,10 @@ static int stop_thread (void) /* {{{ */ status = -1; } + pthread_mutex_lock (&ping_lock); memset (&ping_thread_id, 0, sizeof (ping_thread_id)); ping_thread_error = 0; + pthread_mutex_unlock (&ping_lock); return (status); } /* }}} int stop_thread */ @@ -481,7 +483,7 @@ static int ping_config (const char *key, const char *value) /* {{{ */ hostlist_t *hl; char *host; - hl = (hostlist_t *) malloc (sizeof (hostlist_t)); + hl = malloc (sizeof (*hl)); if (hl == NULL) { char errbuf[1024]; @@ -543,26 +545,21 @@ static int ping_config (const char *key, const char *value) /* {{{ */ tmp, value); } else if (strcasecmp (key, "Size") == 0) { - int size; + size_t size = (size_t) atoi (value); - if (ping_data != NULL) + /* Max IP packet size - (IPv6 + ICMP) = 65535 - (40 + 8) = 65487 */ + if (size <= 65487) { - free (ping_data); - ping_data = NULL; - } + size_t i; - size = atoi (value); - if ((size >= 0) && (size <= 65536)) - { - int i; - ping_data = (char *) malloc(size + 1); + sfree (ping_data); + ping_data = malloc (size + 1); if (ping_data == NULL) { - char errbuf[1024]; - ERROR ("ping plugin: malloc failed: %s", - sstrerror (errno, errbuf, sizeof (errbuf))); + ERROR ("ping plugin: malloc failed."); return (1); } + /* Note: By default oping is using constant string * "liboping -- ICMP ping library " * which is exactly 56 bytes. @@ -576,9 +573,9 @@ static int ping_config (const char *key, const char *value) /* {{{ */ * printable characters, and not NUL character. */ ping_data[i] = ('0' + i % 64); } /* }}} for (i = 0; i < size; i++) */ - ping_data[size] = '\0'; + ping_data[size] = 0; } else - WARNING ("ping plugin: Ignoring invalid Size %i.", size); + WARNING ("ping plugin: Ignoring invalid Size %zu.", size); } else if (strcasecmp (key, "Timeout") == 0) {