X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Femail.c;h=611da5601695bdb0a41d93e5a29a89fc2490f648;hb=80294418289129eb75c9f07e2043adcbd02941a4;hp=b406d48305e415e0bc45732357c5ba347036f760;hpb=2e632b0929fb957fd686231658bc2999fdfb4b20;p=collectd.git diff --git a/src/email.c b/src/email.c index b406d483..611da560 100644 --- a/src/email.c +++ b/src/email.c @@ -299,22 +299,21 @@ static void *collect(void *arg) { } if ('e' == line[0]) { /* e:: */ - char *ptr = NULL; - char *type = strtok_r(line + 2, ":", &ptr); - char *tmp = strtok_r(NULL, ":", &ptr); - int bytes = 0; - - if (NULL == tmp) { + 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); @@ -361,8 +360,6 @@ static void *collect(void *arg) { } /* static void *collect (void *) */ static void *open_connection(void __attribute__((unused)) * arg) { - struct sockaddr_un addr; - const char *path = (NULL == sock_file) ? SOCK_PATH : sock_file; const char *group = (NULL == sock_group) ? COLLECTD_GRP_NAME : sock_group; @@ -375,7 +372,9 @@ static void *open_connection(void __attribute__((unused)) * arg) { pthread_exit((void *)1); } - 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; @@ -403,15 +402,21 @@ static void *open_connection(void __attribute__((unused)) * arg) { { struct group sg; struct group *grp; - char grbuf[2048]; int status; + long int grbuf_size = sysconf(_SC_GETGR_R_SIZE_MAX); + if (grbuf_size <= 0) + grbuf_size = sysconf(_SC_PAGESIZE); + if (grbuf_size <= 0) + grbuf_size = 4096; + char grbuf[grbuf_size]; + grp = NULL; status = getgrnam_r(group, &sg, grbuf, sizeof(grbuf), &grp); if (status != 0) { char errbuf[1024]; log_warn("getgrnam_r (%s) failed: %s", group, - sstrerror(errno, errbuf, sizeof(errbuf))); + sstrerror(status, errbuf, sizeof(errbuf))); } else if (grp == NULL) { log_warn("No such group: `%s'", group); } else {