Tree wide: Replace sstrerror() with STRERRNO.
[collectd.git] / src / unixsock.c
index 99e39ee..7cbb385 100644 (file)
@@ -75,9 +75,7 @@ static int us_open_socket(void) {
 
   sock_fd = socket(PF_UNIX, SOCK_STREAM, 0);
   if (sock_fd < 0) {
-    char errbuf[1024];
-    ERROR("unixsock plugin: socket failed: %s",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("unixsock plugin: socket failed: %s", STRERRNO);
     return -1;
   }
 
@@ -91,9 +89,8 @@ static int us_open_socket(void) {
     errno = 0;
     status = unlink(sa.sun_path);
     if ((status != 0) && (errno != ENOENT)) {
-      char errbuf[1024];
       WARNING("unixsock plugin: Deleting socket file \"%s\" failed: %s",
-              sa.sun_path, sstrerror(errno, errbuf, sizeof(errbuf)));
+              sa.sun_path, STRERRNO);
     } else if (status == 0) {
       INFO("unixsock plugin: Successfully deleted socket file \"%s\".",
            sa.sun_path);
@@ -102,9 +99,7 @@ static int us_open_socket(void) {
 
   status = bind(sock_fd, (struct sockaddr *)&sa, sizeof(sa));
   if (status != 0) {
-    char errbuf[1024];
-    sstrerror(errno, errbuf, sizeof(errbuf));
-    ERROR("unixsock plugin: bind failed: %s", errbuf);
+    ERROR("unixsock plugin: bind failed: %s", STRERRNO);
     close(sock_fd);
     sock_fd = -1;
     return -1;
@@ -112,9 +107,7 @@ static int us_open_socket(void) {
 
   status = chmod(sa.sun_path, sock_perms);
   if (status == -1) {
-    char errbuf[1024];
-    ERROR("unixsock plugin: chmod failed: %s",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("unixsock plugin: chmod failed: %s", STRERRNO);
     close(sock_fd);
     sock_fd = -1;
     return -1;
@@ -122,9 +115,7 @@ static int us_open_socket(void) {
 
   status = listen(sock_fd, 8);
   if (status != 0) {
-    char errbuf[1024];
-    ERROR("unixsock plugin: listen failed: %s",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("unixsock plugin: listen failed: %s", STRERRNO);
     close(sock_fd);
     sock_fd = -1;
     return -1;
@@ -159,10 +150,9 @@ static int us_open_socket(void) {
 
     if (chown((sock_file != NULL) ? sock_file : US_DEFAULT_PATH, (uid_t)-1,
               g->gr_gid) != 0) {
-      char errbuf[1024];
       WARNING("unixsock plugin: chown (%s, -1, %i) failed: %s",
               (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, (int)g->gr_gid,
-              sstrerror(errno, errbuf, sizeof(errbuf)));
+              STRERRNO);
     }
   } while (0);
 
@@ -182,18 +172,14 @@ static void *us_handle_client(void *arg) {
 
   fdout = dup(fdin);
   if (fdout < 0) {
-    char errbuf[1024];
-    ERROR("unixsock plugin: dup failed: %s",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("unixsock plugin: dup failed: %s", STRERRNO);
     close(fdin);
     pthread_exit((void *)1);
   }
 
   fhin = fdopen(fdin, "r");
   if (fhin == NULL) {
-    char errbuf[1024];
-    ERROR("unixsock plugin: fdopen failed: %s",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("unixsock plugin: fdopen failed: %s", STRERRNO);
     close(fdin);
     close(fdout);
     pthread_exit((void *)1);
@@ -202,9 +188,7 @@ static void *us_handle_client(void *arg) {
 
   fhout = fdopen(fdout, "w");
   if (fhout == NULL) {
-    char errbuf[1024];
-    ERROR("unixsock plugin: fdopen failed: %s",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("unixsock plugin: fdopen failed: %s", STRERRNO);
     fclose(fhin); /* this closes fdin as well */
     close(fdout);
     pthread_exit((void *)1);
@@ -213,9 +197,7 @@ static void *us_handle_client(void *arg) {
 
   /* change output buffer to line buffered mode */
   if (setvbuf(fhout, NULL, _IOLBF, 0) != 0) {
-    char errbuf[1024];
-    ERROR("unixsock plugin: setvbuf failed: %s",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("unixsock plugin: setvbuf failed: %s", STRERRNO);
     fclose(fhin);
     fclose(fhout);
     pthread_exit((void *)1);
@@ -235,9 +217,8 @@ static void *us_handle_client(void *arg) {
         continue;
 
       if (errno != 0) {
-        char errbuf[1024];
         WARNING("unixsock plugin: failed to read from socket #%i: %s",
-                fileno(fhin), sstrerror(errno, errbuf, sizeof(errbuf)));
+                fileno(fhin), STRERRNO);
       }
       break;
     }
@@ -276,9 +257,8 @@ static void *us_handle_client(void *arg) {
       cmd_handle_flush(fhout, buffer);
     } else {
       if (fprintf(fhout, "-1 Unknown command: %s\n", fields[0]) < 0) {
-        char errbuf[1024];
         WARNING("unixsock plugin: failed to write to socket #%i: %s",
-                fileno(fhout), sstrerror(errno, errbuf, sizeof(errbuf)));
+                fileno(fhout), STRERRNO);
         break;
       }
     }
@@ -308,13 +288,11 @@ static void *us_server_thread(void __attribute__((unused)) * arg) {
     DEBUG("unixsock plugin: Calling accept..");
     status = accept(sock_fd, NULL, NULL);
     if (status < 0) {
-      char errbuf[1024];
 
       if (errno == EINTR)
         continue;
 
-      ERROR("unixsock plugin: accept failed: %s",
-            sstrerror(errno, errbuf, sizeof(errbuf)));
+      ERROR("unixsock plugin: accept failed: %s", STRERRNO);
       close(sock_fd);
       sock_fd = -1;
       pthread_attr_destroy(&th_attr);
@@ -323,9 +301,7 @@ static void *us_server_thread(void __attribute__((unused)) * arg) {
 
     remote_fd = malloc(sizeof(*remote_fd));
     if (remote_fd == NULL) {
-      char errbuf[1024];
-      WARNING("unixsock plugin: malloc failed: %s",
-              sstrerror(errno, errbuf, sizeof(errbuf)));
+      WARNING("unixsock plugin: malloc failed: %s", STRERRNO);
       close(status);
       continue;
     }
@@ -336,9 +312,7 @@ static void *us_server_thread(void __attribute__((unused)) * arg) {
     status = plugin_thread_create(&th, &th_attr, us_handle_client,
                                   (void *)remote_fd, "unixsock conn");
     if (status != 0) {
-      char errbuf[1024];
-      WARNING("unixsock plugin: pthread_create failed: %s",
-              sstrerror(errno, errbuf, sizeof(errbuf)));
+      WARNING("unixsock plugin: pthread_create failed: %s", STRERRNO);
       close(*remote_fd);
       free(remote_fd);
       continue;
@@ -351,10 +325,8 @@ static void *us_server_thread(void __attribute__((unused)) * arg) {
 
   status = unlink((sock_file != NULL) ? sock_file : US_DEFAULT_PATH);
   if (status != 0) {
-    char errbuf[1024];
     NOTICE("unixsock plugin: unlink (%s) failed: %s",
-           (sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
-           sstrerror(errno, errbuf, sizeof(errbuf)));
+           (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, STRERRNO);
   }
 
   return (void *)0;
@@ -404,9 +376,7 @@ static int us_init(void) {
   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",
-          sstrerror(errno, errbuf, sizeof(errbuf)));
+    ERROR("unixsock plugin: pthread_create failed: %s", STRERRNO);
     return -1;
   }