7 /* kick a Postfix service
10 /* \fBpostkick\fR [\fB-c \fIconfig_dir\fR] [\fB-v\fR]
11 /* \fIclass service request\fR
13 /* The \fBpostkick\fR(1) command sends \fIrequest\fR to the
14 /* specified \fIservice\fR over a local transport channel.
15 /* This command makes Postfix private IPC accessible
16 /* for use in, for example, shell scripts.
19 /* .IP "\fB-c\fR \fIconfig_dir\fR"
20 /* Read the \fBmain.cf\fR configuration file in the named directory
21 /* instead of the default configuration directory.
23 /* Enable verbose logging for debugging purposes. Multiple \fB-v\fR
24 /* options make the software increasingly verbose.
28 /* Name of a class of local transport channel endpoints,
29 /* either \fBpublic\fR (accessible by any local user) or
30 /* \fBprivate\fR (administrative access only).
32 /* The name of a local transport endpoint within the named class.
34 /* A string. The list of valid requests is service-specific.
36 /* Problems and transactions are logged to the standard error
41 /* .IP \fBMAIL_CONFIG\fR
42 /* Directory with Postfix configuration files.
43 /* .IP \fBMAIL_VERBOSE\fR
44 /* Enable verbose logging for debugging purposes.
45 /* CONFIGURATION PARAMETERS
48 /* The following \fBmain.cf\fR parameters are especially relevant to
50 /* The text below provides only a parameter summary. See
51 /* \fBpostconf\fR(5) for more details including examples.
52 /* .IP "\fBconfig_directory (see 'postconf -d' output)\fR"
53 /* The default location of the Postfix main.cf and master.cf
54 /* configuration files.
55 /* .IP "\fBapplication_event_drain_time (100s)\fR"
56 /* How long the \fBpostkick\fR(1) command waits for a request to enter the
57 /* server's input buffer before giving up.
58 /* .IP "\fBqueue_directory (see 'postconf -d' output)\fR"
59 /* The location of the Postfix top-level queue directory.
61 /* /var/spool/postfix/private, private class endpoints
62 /* /var/spool/postfix/public, public class endpoints
64 /* qmgr(8), queue manager trigger protocol
65 /* pickup(8), local pickup daemon
66 /* postconf(5), configuration parameters
70 /* The Secure Mailer license must be distributed with this software.
73 /* IBM T.J. Watson Research
75 /* Yorktown Heights, NY 10598, USA
88 /* Utility library. */
93 #include <msg_vstream.h>
99 #include <mail_proto.h>
100 #include <mail_params.h>
101 #include <mail_version.h>
102 #include <mail_conf.h>
104 static NORETURN
usage(char *myname
)
106 msg_fatal("usage: %s [-c config_dir] [-v] class service request", myname
);
109 MAIL_VERSION_STAMP_DECLARE
;
111 int main(int argc
, char **argv
)
122 * Fingerprint executables and core dumps.
124 MAIL_VERSION_STAMP_ALLOCATE
;
127 * To minimize confusion, make sure that the standard file descriptors
128 * are open before opening anything else. XXX Work around for 44BSD where
129 * fstat can return EBADF on an open file descriptor.
131 for (fd
= 0; fd
< 3; fd
++)
132 if (fstat(fd
, &st
) == -1
133 && (close(fd
), open("/dev/null", O_RDWR
, 0)) != fd
)
134 msg_fatal("open /dev/null: %m");
137 * Process environment options as early as we can.
139 if (safe_getenv(CONF_ENV_VERB
))
143 * Initialize. Set up logging, read the global configuration file and
144 * extract configuration information.
146 if ((slash
= strrchr(argv
[0], '/')) != 0 && slash
[1])
148 msg_vstream_init(argv
[0], VSTREAM_ERR
);
149 set_mail_conf_str(VAR_PROCNAME
, var_procname
= mystrdup(argv
[0]));
154 while ((c
= GETOPT(argc
, argv
, "c:v")) > 0) {
159 if (setenv(CONF_ENV_PATH
, optarg
, 1) < 0)
160 msg_fatal("out of memory");
167 if (argc
!= optind
+ 3)
169 class = argv
[optind
];
170 service
= argv
[optind
+ 1];
171 request
= argv
[optind
+ 2];
174 * Finish initializations.
177 if (chdir(var_queue_dir
))
178 msg_fatal("chdir %s: %m", var_queue_dir
);
183 if (mail_trigger(class, service
, request
, strlen(request
)) < 0) {
184 msg_warn("Cannot contact class %s service %s - perhaps the mail system is down",
190 * Problem: With triggers over full duplex (i.e. non-FIFO) channels, we
191 * must avoid closing the channel before the server has received the
192 * request. Otherwise some hostile kernel may throw away the request.
194 * Solution: The trigger routine registers a read event handler that runs
195 * when the server closes the channel. The event_drain() routine waits
196 * for the event handler to run, but gives up when it takes too long.
199 event_drain(var_event_drain
);