X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Funixsock.c;h=2c1665fc9fcbbdffc3c91935838a720e4fbf6d6f;hb=412a434094fb5ef130b026962945ca5168bb4036;hp=6de1395662161a66aaacafa389efa1e680583bf9;hpb=565c731a4353d1453b65dc9a4267e1f8e4740c06;p=collectd.git diff --git a/src/unixsock.c b/src/unixsock.c index 6de13956..2c1665fc 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -26,7 +26,6 @@ #include "utils_cmd_flush.h" #include "utils_cmd_getval.h" -#include "utils_cmd_getthreshold.h" #include "utils_cmd_listval.h" #include "utils_cmd_putval.h" #include "utils_cmd_putnotif.h" @@ -206,6 +205,7 @@ static void *us_handle_client (void *arg) close (fdin); close (fdout); pthread_exit ((void *) 1); + return ((void *) 1); } fhout = fdopen (fdout, "w"); @@ -217,6 +217,7 @@ static void *us_handle_client (void *arg) fclose (fhin); /* this closes fdin as well */ close (fdout); pthread_exit ((void *) 1); + return ((void *) 1); } /* change output buffer to line buffered mode */ @@ -228,6 +229,7 @@ static void *us_handle_client (void *arg) fclose (fhin); fclose (fhout); pthread_exit ((void *) 1); + return ((void *) 0); } while (42) @@ -241,6 +243,9 @@ static void *us_handle_client (void *arg) errno = 0; if (fgets (buffer, sizeof (buffer), fhin) == NULL) { + if ((errno == EINTR) || (errno == EAGAIN)) + continue; + if (errno != 0) { char errbuf[1024]; @@ -269,16 +274,13 @@ static void *us_handle_client (void *arg) fclose (fhin); fclose (fhout); pthread_exit ((void *) 1); + return ((void *) 1); } if (strcasecmp (fields[0], "getval") == 0) { 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); @@ -323,6 +325,9 @@ static void *us_server_thread (void __attribute__((unused)) *arg) pthread_t th; pthread_attr_t th_attr; + pthread_attr_init (&th_attr); + pthread_attr_setdetachstate (&th_attr, PTHREAD_CREATE_DETACHED); + if (us_open_socket () != 0) pthread_exit ((void *) 1); @@ -341,6 +346,7 @@ static void *us_server_thread (void __attribute__((unused)) *arg) sstrerror (errno, errbuf, sizeof (errbuf))); close (sock_fd); sock_fd = -1; + pthread_attr_destroy (&th_attr); pthread_exit ((void *) 1); } @@ -357,10 +363,8 @@ static void *us_server_thread (void __attribute__((unused)) *arg) DEBUG ("Spawning child to handle connection on fd #%i", *remote_fd); - pthread_attr_init (&th_attr); - pthread_attr_setdetachstate (&th_attr, PTHREAD_CREATE_DETACHED); - - status = pthread_create (&th, &th_attr, us_handle_client, (void *) remote_fd); + status = plugin_thread_create (&th, &th_attr, + us_handle_client, (void *) remote_fd); if (status != 0) { char errbuf[1024]; @@ -374,6 +378,7 @@ static void *us_server_thread (void __attribute__((unused)) *arg) close (sock_fd); sock_fd = -1; + pthread_attr_destroy (&th_attr); status = unlink ((sock_file != NULL) ? sock_file : US_DEFAULT_PATH); if (status != 0) @@ -439,7 +444,8 @@ static int us_init (void) loop = 1; - status = pthread_create (&listen_thread, NULL, us_server_thread, NULL); + status = plugin_thread_create (&listen_thread, NULL, + us_server_thread, NULL); if (status != 0) { char errbuf[1024];