Email gateway obeys 'Reply-To:' in header.
[egate.git] / util / gips.c
index 041be4a..90e1256 100644 (file)
  * Europagate, 1995
  *
  * $Log: gips.c,v $
- * Revision 1.6  1995/05/16 09:40:53  adam
+ * Revision 1.8  1995/05/22 11:43:01  adam
+ * Minor changes on dtbsun - include of errno.h.
+ *
+ * Revision 1.7  1995/05/22  09:03:41  adam
+ * New argument, block, to cs_open.
+ *
+ * Revision 1.6  1995/05/16  09:40:53  adam
  * LICENSE.
  *
  * Revision 1.5  1995/05/01  16:27:29  adam
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <errno.h>
 
 #include <gw-log.h>
 #include <gip.h>
 
+static char *module = "gips";
+
 GIP gips_initialize (const char *name)
 {
     return gip_initialize (name);
@@ -87,29 +96,44 @@ int gips_destroy (GIP gip)
     return gip_destroy (gip);
 }
 
-int gips_open (GIP gip, const char *client)
+int gips_open (GIP gip, const char *client, int block)
 {
-    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);
+    do
+    {
+        gw_log (GW_LOG_DEBUG, module, "open readonly of %s", gip->name);
+        gip->rfd = open (gip->name, block ? O_RDONLY : (O_RDONLY|O_NONBLOCK));
+        gw_log (GW_LOG_DEBUG, module, "got rfd %d", gip->rfd);
+    } while (gip->rfd == -1 && errno == EINTR);
+    do
+    {
+        gw_log (GW_LOG_DEBUG, module, "open writeonly of %s", client);
+        gip->wfd = open (client, block ? O_WRONLY : (O_WRONLY|O_NONBLOCK));
+        gw_log (GW_LOG_DEBUG, module, "got wfd %d", gip->wfd);
+    } while (gip->wfd == -1 && errno == EINTR);
     if (gip->rfd == -1)
     {
+        gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, 
+                "cannot open %s", gip->name);
         if (gip->wfd != -1)
         {
             close (gip->wfd);
             gip->wfd = -1;
         }
+        else
+            gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, 
+                    "cannot open %s", client);
         return -1;
     }
     if (gip->wfd == -1)
     {
+        gw_log (GW_LOG_DEBUG|GW_LOG_ERRNO, module, 
+                "cannot open %s", client);
         close (gip->rfd);
         gip->rfd = -1;
         return -1;
     }
+    fcntl (gip->wfd, F_SETFL, 0);
+    fcntl (gip->rfd, F_SETFL, 0);
     fcntl (gip->wfd, F_SETFD, FD_CLOEXEC);
     fcntl (gip->rfd, F_SETFD, FD_CLOEXEC);
     return 0;