nameservice: check return value of fcntl
authorFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 23 Oct 2012 10:40:45 +0000 (12:40 +0200)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Tue, 23 Oct 2012 11:45:14 +0000 (13:45 +0200)
Coverity:
CID 739618 (#1 of 1): Unchecked return value (CHECKED_RETURN)
At (4): Calling function "fcntl(fd, 4, 1)" without checking return value.
        This library function may fail and return an error code.
At (5): No check of the return value of "fcntl(fd, 4, 1)".

Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/nameservice/src/mapwrite.c

index 76b66fc..76b1e36 100644 (file)
@@ -209,17 +209,20 @@ mapwrite_poll(void *context __attribute__ ((unused)))
     int fd = open(the_fifoname, O_WRONLY | O_NONBLOCK);
     if (0 <= fd) {
       /*
-       * Change to blocking, otherwhise expect fprintf errors
+       * Change to blocking, otherwise expect fprintf errors
        */
-      fcntl(fd, F_SETFL, O_WRONLY);
-      fout = fdopen(fd, "w");
-      if (0 != fout) {
-        mapwrite_work(fout);
-        fclose(fout);
-        /* Give pipe reader cpu slot to detect EOF */
-        usleep(1);
-      } else {
+      if (fcntl(fd, F_SETFL, O_WRONLY) == -1) {
         close(fd);
+      } else {
+        fout = fdopen(fd, "w");
+        if (0 != fout) {
+          mapwrite_work(fout);
+          fclose(fout);
+          /* Give pipe reader cpu slot to detect EOF */
+          usleep(1);
+        } else {
+          close(fd);
+        }
       }
     }
   }