7 /* intra-mail system connection management
9 /* #include <mail_proto.h>
11 /* VSTREAM *mail_connect(class, name, block_mode)
16 /* VSTREAM *mail_connect_wait(class, name)
20 /* This module does low-level connection management for intra-mail
21 /* communication. All reads and writes are subject to a time limit
22 /* (controlled by the global variable \fIvar_ipc_timeout\fR). This
23 /* protects against deadlock conditions that should never happen.
25 /* mail_connect() attempts to connect to the UNIX-domain socket of
26 /* the named subsystem. The result is a null pointer in case of failure.
28 /* mail_connect_wait() is like mail_connect(), but keeps trying until
29 /* the connection succeeds. However, mail_connect_wait() terminates
30 /* with a fatal error when the service is down. This is to ensure that
31 /* processes terminate when the mail system shuts down.
35 /* Name of a class of local transport channel endpoints,
36 /* either \fIpublic\fR (accessible by any local user) or
37 /* \fIprivate\fR (administrative access only).
39 /* The name of a local transport endpoint within the named class.
41 /* NON_BLOCKING for a non-blocking connection, or BLOCKING.
43 /* timed_ipc(3), enforce IPC timeouts.
47 /* The Secure Mailer license must be distributed with this software.
50 /* IBM T.J. Watson Research
52 /* Yorktown Heights, NY 10598, USA
64 /* Utility library. */
71 #include <stringops.h>
75 #include "timed_ipc.h"
76 #include "mail_proto.h"
78 /* mail_connect - connect to mail subsystem */
80 VSTREAM
*mail_connect(const char *class, const char *name
, int block_mode
)
87 path
= mail_pathname(class, name
);
88 if ((fd
= LOCAL_CONNECT(path
, block_mode
, 0)) < 0) {
90 msg_info("connect to subsystem %s: %m", path
);
94 msg_info("connect to subsystem %s", path
);
95 stream
= vstream_fdopen(fd
, O_RDWR
);
96 timed_ipc_setup(stream
);
97 sock_name
= concatenate(path
, " socket", (char *) 0);
98 vstream_control(stream
,
99 VSTREAM_CTL_PATH
, sock_name
,
107 /* mail_connect_wait - connect to mail service until it succeeds */
109 VSTREAM
*mail_connect_wait(const char *class, const char *name
)
115 * XXX Solaris workaround for ECONNREFUSED on a busy socket.
117 while ((stream
= mail_connect(class, name
, BLOCKING
)) == 0) {
119 msg_fatal("connect #%d to subsystem %s/%s: %m",
122 msg_warn("connect #%d to subsystem %s/%s: %m",
125 sleep(10); /* XXX make configurable */