X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Femail.c;h=f8a94fb6e4a64181968473f4486ebf5038c84407;hb=028736501ebf63ab9d70b8de8628f9b2fd25eb37;hp=c0f28d04379be54bc9c3e0fee08697d71ffc3cbb;hpb=22813e1a6a3d059efc67975893df985052661a7a;p=collectd.git diff --git a/src/email.c b/src/email.c index c0f28d04..f8a94fb6 100644 --- a/src/email.c +++ b/src/email.c @@ -111,13 +111,13 @@ static const char *config_keys[] = {"SocketFile", "SocketGroup", "SocketPerms", static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); /* socket configuration */ -static char *sock_file = NULL; -static char *sock_group = NULL; +static char *sock_file; +static char *sock_group; static int sock_perms = S_IRWXU | S_IRWXG; static int max_conns = MAX_CONNS; /* state of the plugin */ -static int disabled = 0; +static int disabled; /* thread managing "client" connections */ static pthread_t connector = (pthread_t)0; @@ -134,7 +134,7 @@ static conn_list_t conns; static pthread_cond_t collector_available = PTHREAD_COND_INITIALIZER; /* collector threads */ -static collector_t **collectors = NULL; +static collector_t **collectors; static pthread_mutex_t available_mutex = PTHREAD_MUTEX_INITIALIZER; static int available_collectors; @@ -260,7 +260,6 @@ static void *collect(void *arg) { while (42) { /* 256 bytes ought to be enough for anybody ;-) */ char line[256 + 1]; /* line + '\0' */ - int len = 0; errno = 0; if (fgets(line, sizeof(line), this->socket) == NULL) { @@ -272,9 +271,9 @@ static void *collect(void *arg) { break; } - len = strlen(line); + size_t len = strlen(line); if ((line[len - 1] != '\n') && (line[len - 1] != '\r')) { - log_warn("collect: line too long (> %zu characters): " + log_warn("collect: line too long (> %" PRIsz " characters): " "'%s' (truncated)", sizeof(line) - 1, line); @@ -287,7 +286,7 @@ static void *collect(void *arg) { continue; } - line[len - 1] = 0; + line[len - 1] = '\0'; log_debug("collect: line = '%s'", line); @@ -297,22 +296,21 @@ static void *collect(void *arg) { } if (line[0] == 'e') { /* e:: */ - char *ptr = NULL; - char *type = strtok_r(line + 2, ":", &ptr); - char *tmp = strtok_r(NULL, ":", &ptr); - int bytes = 0; - - if (tmp == NULL) { + char *type = line + 2; + char *bytes_str = strchr(type, ':'); + if (bytes_str == NULL) { log_err("collect: syntax error in line '%s'", line); continue; } - bytes = atoi(tmp); + *bytes_str = 0; + bytes_str++; pthread_mutex_lock(&count_mutex); type_list_incr(&list_count, type, /* increment = */ 1); pthread_mutex_unlock(&count_mutex); + int bytes = atoi(bytes_str); if (bytes > 0) { pthread_mutex_lock(&size_mutex); type_list_incr(&list_size, type, /* increment = */ bytes); @@ -370,7 +368,9 @@ static void *open_connection(void __attribute__((unused)) * arg) { pthread_exit((void *)1); } - struct sockaddr_un addr = {.sun_family = AF_UNIX}; + struct sockaddr_un addr = { + .sun_family = AF_UNIX, + }; sstrncpy(addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1)); errno = 0;