X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Femail.c;h=e1ce21856d79e759759c80acc0888cf5b58d7d22;hb=0d9f395599348e735e6f461e1c328293bef0d060;hp=e5f015b2539b6d91e25d4f95e5c9b38bc2ef97cf;hpb=bbfa295a9f40e9966fff0afe29babd1f7834f5d3;p=collectd.git diff --git a/src/email.c b/src/email.c index e5f015b2..e1ce2185 100644 --- a/src/email.c +++ b/src/email.c @@ -299,22 +299,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); @@ -374,13 +373,14 @@ static void *open_connection(void __attribute__((unused)) * arg) { } struct sockaddr_un addr = { - .sun_family = AF_UNIX + .sun_family = AF_UNIX, }; sstrncpy(addr.sun_path, path, (size_t)(UNIX_PATH_MAX - 1)); errno = 0; if (bind(connector_socket, (struct sockaddr *)&addr, - offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) == -1) { + offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) == + -1) { char errbuf[1024]; disabled = 1; close(connector_socket); @@ -402,9 +402,15 @@ static void *open_connection(void __attribute__((unused)) * arg) { { struct group sg; struct group *grp; - char grbuf[4096]; 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) {