X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Funixsock.c;h=8b2f33914eacc3307fbc7d1b28c9c5fe032b3c74;hb=8af74098eb65ff4c0c0cc65dfaa40973fe741a63;hp=337978df444e17ac5dbccdbf88ad7d71330024fd;hpb=76e6392863d130ceca048eb860e4db1c9e40fee7;p=collectd.git diff --git a/src/unixsock.c b/src/unixsock.c index 337978df..8b2f3391 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -122,7 +122,16 @@ static int us_open_socket (void) return (-1); } - chmod (sa.sun_path, sock_perms); + status = chmod (sa.sun_path, sock_perms); + if (status == -1) + { + char errbuf[1024]; + ERROR ("unixsock plugin: chmod failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + close (sock_fd); + sock_fd = -1; + return (-1); + } status = listen (sock_fd, 8); if (status != 0) @@ -205,6 +214,7 @@ static void *us_handle_client (void *arg) close (fdin); close (fdout); pthread_exit ((void *) 1); + return ((void *) 1); } fhout = fdopen (fdout, "w"); @@ -216,6 +226,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 */ @@ -227,6 +238,7 @@ static void *us_handle_client (void *arg) fclose (fhin); fclose (fhout); pthread_exit ((void *) 1); + return ((void *) 0); } while (42) @@ -240,6 +252,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]; @@ -268,6 +283,7 @@ static void *us_handle_client (void *arg) fclose (fhin); fclose (fhout); pthread_exit ((void *) 1); + return ((void *) 1); } if (strcasecmp (fields[0], "getval") == 0) @@ -318,6 +334,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); @@ -336,6 +355,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); } @@ -352,9 +372,6 @@ 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 = plugin_thread_create (&th, &th_attr, us_handle_client, (void *) remote_fd); if (status != 0) @@ -370,6 +387,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)