unixsock: check return value of chmod
[collectd.git] / src / unixsock.c
index 0dc7d65..8b2f339 100644 (file)
@@ -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)
@@ -363,7 +372,8 @@ static void *us_server_thread (void __attribute__((unused)) *arg)
 
                DEBUG ("Spawning child to handle connection on fd #%i", *remote_fd);
 
-               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];
@@ -443,7 +453,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];