X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Funixsock.c;h=a42456896ef0142765a8f44ef0a30dd5679cfb71;hb=45492ba3d0119874e2f2878d68089fc8f62268a4;hp=aa3451e9bc6cf7419bb23ab1feb2ce4b4bf64fbd;hpb=79963d13c1884d1d92667cc502ad20758b084a12;p=collectd.git diff --git a/src/unixsock.c b/src/unixsock.c index aa3451e9..a4245689 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -134,7 +134,13 @@ static int us_open_socket(void) { const char *grpname; struct group *g; struct group sg; - char grbuf[2048]; + + 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]; grpname = (sock_group != NULL) ? sock_group : COLLECTD_GRP_NAME; g = NULL; @@ -143,7 +149,7 @@ static int us_open_socket(void) { if (status != 0) { char errbuf[1024]; WARNING("unixsock plugin: getgrnam_r (%s) failed: %s", grpname, - sstrerror(errno, errbuf, sizeof(errbuf))); + sstrerror(status, errbuf, sizeof(errbuf))); break; } if (g == NULL) { @@ -257,17 +263,17 @@ static void *us_handle_client(void *arg) { } if (strcasecmp(fields[0], "getval") == 0) { - handle_getval(fhout, buffer); + cmd_handle_getval(fhout, buffer); } else if (strcasecmp(fields[0], "getthreshold") == 0) { handle_getthreshold(fhout, buffer); } else if (strcasecmp(fields[0], "putval") == 0) { - handle_putval(fhout, buffer); + cmd_handle_putval(fhout, buffer); } else if (strcasecmp(fields[0], "listval") == 0) { - handle_listval(fhout, buffer); + cmd_handle_listval(fhout, buffer); } else if (strcasecmp(fields[0], "putnotif") == 0) { handle_putnotif(fhout, buffer); } else if (strcasecmp(fields[0], "flush") == 0) { - handle_flush(fhout, buffer); + cmd_handle_flush(fhout, buffer); } else { if (fprintf(fhout, "-1 Unknown command: %s\n", fields[0]) < 0) { char errbuf[1024]; @@ -328,7 +334,7 @@ static void *us_server_thread(void __attribute__((unused)) * arg) { DEBUG("Spawning child to handle connection on fd #%i", *remote_fd); status = plugin_thread_create(&th, &th_attr, us_handle_client, - (void *)remote_fd); + (void *)remote_fd, "unixsock conn"); if (status != 0) { char errbuf[1024]; WARNING("unixsock plugin: pthread_create failed: %s", @@ -395,7 +401,8 @@ static int us_init(void) { loop = 1; - status = plugin_thread_create(&listen_thread, NULL, us_server_thread, NULL); + status = plugin_thread_create(&listen_thread, NULL, us_server_thread, NULL, + "unixsock listen"); if (status != 0) { char errbuf[1024]; ERROR("unixsock plugin: pthread_create failed: %s",