Various improvements. Close-on-exec and close on failure on either
[egate.git] / util / gips.c
index 79eee64..9b48e9d 100644 (file)
@@ -2,7 +2,11 @@
  * Europagate, 1995
  *
  * $Log: gips.c,v $
- * Revision 1.4  1995/04/21 16:38:08  adam
+ * Revision 1.5  1995/05/01 16:27:29  adam
+ * Various improvements. Close-on-exec and close on failure on either
+ * read or write FIFO.
+ *
+ * Revision 1.4  1995/04/21  16:38:08  adam
  * Added more debugging logs.
  *
  * Revision 1.3  1995/04/20  15:12:46  adam
@@ -41,12 +45,27 @@ int gips_open (GIP gip, const char *client)
 {
     gw_log (GW_LOG_DEBUG, "gips", "open readonly of %s", gip->name);
     gip->rfd = open (gip->name, O_RDONLY);
+    gw_log (GW_LOG_DEBUG, "gips", "got rfd %d", gip->rfd);
     gw_log (GW_LOG_DEBUG, "gips", "open writeonly of %s", client);
     gip->wfd = open (client, O_WRONLY);
+    gw_log (GW_LOG_DEBUG, "gips", "got wfd %d", gip->wfd);
     if (gip->rfd == -1)
+    {
+        if (gip->wfd != -1)
+        {
+            close (gip->wfd);
+            gip->wfd = -1;
+        }
         return -1;
+    }
     if (gip->wfd == -1)
+    {
+        close (gip->rfd);
+        gip->rfd = -1;
         return -1;
+    }
+    fcntl (gip->wfd, F_SETFD, FD_CLOEXEC);
+    fcntl (gip->rfd, F_SETFD, FD_CLOEXEC);
     return 0;
 }