9b48e9da83dfadb5ece1ef6d88bdc1c15a4d848d
[egate.git] / util / gips.c
1 /* Gateway kernel
2  * Europagate, 1995
3  *
4  * $Log: gips.c,v $
5  * Revision 1.5  1995/05/01 16:27:29  adam
6  * Various improvements. Close-on-exec and close on failure on either
7  * read or write FIFO.
8  *
9  * Revision 1.4  1995/04/21  16:38:08  adam
10  * Added more debugging logs.
11  *
12  * Revision 1.3  1995/04/20  15:12:46  adam
13  * Minor hacks really.
14  *
15  * Revision 1.2  1995/04/19  16:02:06  adam
16  * Some hacks to get the FIFO communication work!! Isn't reliable.
17  *
18  * Revision 1.1  1995/03/27  08:25:00  adam
19  * New module gip: Gateway IPc module.
20  * New module gw-db: Gateway hash-db module (user information table).
21  *
22  */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <assert.h>
27 #include <string.h>
28 #include <unistd.h>
29 #include <fcntl.h>
30
31 #include <gw-log.h>
32 #include <gip.h>
33
34 GIP gips_initialize (const char *name)
35 {
36     return gip_initialize (name);
37 }
38
39 int gips_destroy (GIP gip)
40 {
41     return gip_destroy (gip);
42 }
43
44 int gips_open (GIP gip, const char *client)
45 {
46     gw_log (GW_LOG_DEBUG, "gips", "open readonly of %s", gip->name);
47     gip->rfd = open (gip->name, O_RDONLY);
48     gw_log (GW_LOG_DEBUG, "gips", "got rfd %d", gip->rfd);
49     gw_log (GW_LOG_DEBUG, "gips", "open writeonly of %s", client);
50     gip->wfd = open (client, O_WRONLY);
51     gw_log (GW_LOG_DEBUG, "gips", "got wfd %d", gip->wfd);
52     if (gip->rfd == -1)
53     {
54         if (gip->wfd != -1)
55         {
56             close (gip->wfd);
57             gip->wfd = -1;
58         }
59         return -1;
60     }
61     if (gip->wfd == -1)
62     {
63         close (gip->rfd);
64         gip->rfd = -1;
65         return -1;
66     }
67     fcntl (gip->wfd, F_SETFD, FD_CLOEXEC);
68     fcntl (gip->rfd, F_SETFD, FD_CLOEXEC);
69     return 0;
70 }
71
72 int gips_close (GIP gip)
73 {
74     if (gip->rfd != -1)
75     {
76         close (gip->rfd);
77         gip->rfd = -1;
78     }
79     if (gip->wfd != -1)
80     {
81         close (gip->wfd);
82         gip->wfd = -1;
83     }
84     return 0;
85 }