No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / global / mail_trigger.c
blob4f4d0c158b4dfc82ece900ae783d7cf8e0e8ac54
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* mail_trigger 3
6 /* SUMMARY
7 /* trigger a mail service
8 /* SYNOPSIS
9 /* #include <mail_proto.h>
11 /* int mail_trigger(class, service, request, length)
12 /* const char *class;
13 /* const char *service;
14 /* const char *request;
15 /* ssize_t length;
16 /* DESCRIPTION
17 /* mail_trigger() wakes up the specified mail subsystem, by
18 /* sending it the specified request.
20 /* Arguments:
21 /* .IP class
22 /* Name of a class of local transport channel endpoints,
23 /* either \fIpublic\fR (accessible by any local user) or
24 /* \fIprivate\fR (administrative access only).
25 /* .IP service
26 /* The name of a local transport endpoint within the named class.
27 /* .IP request
28 /* A string. The list of valid requests is service specific.
29 /* .IP length
30 /* The length of the request string.
31 /* DIAGNOSTICS
32 /* The result is -1 in case of problems, 0 otherwise.
33 /* Warnings are logged.
34 /* BUGS
35 /* Works with FIFO or UNIX-domain services only.
37 /* Should use master.cf to find out what transport to use.
38 /* SEE ALSO
39 /* fifo_trigger(3) trigger a FIFO-based service
40 /* unix_trigger(3) trigger a UNIX_domain service
41 /* LICENSE
42 /* .ad
43 /* .fi
44 /* The Secure Mailer license must be distributed with this software.
45 /* AUTHOR(S)
46 /* Wietse Venema
47 /* IBM T.J. Watson Research
48 /* P.O. Box 704
49 /* Yorktown Heights, NY 10598, USA
50 /*--*/
52 /* System library. */
54 #include <sys_defs.h>
55 #include <sys/stat.h>
57 /* Utility library. */
59 #include <msg.h>
60 #include <mymalloc.h>
61 #include <iostuff.h>
62 #include <trigger.h>
64 /* Global library. */
66 #include "mail_params.h"
67 #include "mail_proto.h"
69 /* mail_trigger - trigger a service */
71 int mail_trigger(const char *class, const char *service,
72 const char *req_buf, ssize_t req_len)
74 struct stat st;
75 char *path;
76 int status;
79 * XXX Some systems cannot tell the difference between a named pipe
80 * (fifo) or a UNIX-domain socket. So we may have to try both.
82 path = mail_pathname(class, service);
83 if ((status = stat(path, &st)) < 0) {
84 msg_warn("unable to look up %s: %m", path);
85 } else if (S_ISFIFO(st.st_mode)) {
86 status = fifo_trigger(path, req_buf, req_len, var_trigger_timeout);
87 if (status < 0 && S_ISSOCK(st.st_mode))
88 status = LOCAL_TRIGGER(path, req_buf, req_len, var_trigger_timeout);
89 } else if (S_ISSOCK(st.st_mode)) {
90 status = LOCAL_TRIGGER(path, req_buf, req_len, var_trigger_timeout);
91 } else {
92 msg_warn("%s is not a socket or a fifo", path);
93 status = -1;
95 myfree(path);
96 return (status);