Linux: LAD_client: Fix Race Condition with Command FIFO
[ipc/ipcdev.git] / linux / src / utils / LAD_client.c
index 390e9c5b0c94c4aef05bea8165e2af870a1b79fd..9c858c4b047d89c974f8fe32ec181e6a15775cd6 100644 (file)
@@ -403,7 +403,6 @@ static Bool openCommandFIFO(Void)
             /* open a file for writing to FIFO, non-blocking */
             commandFIFOFd = open(commandFIFOFileName, O_WRONLY | O_TRUNC | O_NONBLOCK);
             if (commandFIFOFd != -1) {
-                close(commandFIFOFd);
                 break;
             }
         }
@@ -421,6 +420,8 @@ static Bool openCommandFIFO(Void)
     /* open a file for writing to FIFO */
     commandFIFOFilePtr = fopen(commandFIFOFileName, "w");
 
+    close(commandFIFOFd);
+
     if (commandFIFOFilePtr == NULL) {
         PRINTVERBOSE2("\nERROR: failed to open %s, errno = %x\n",
             commandFIFOFileName, errno)