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