7 /* wakeup UNIX-domain file descriptor listener
9 /* #include <trigger.h>
11 /* int upass_trigger(service, buf, len, timeout)
12 /* const char *service;
17 /* upass_trigger() wakes up the named UNIX-domain server by sending
18 /* a brief connection to it and writing the named buffer.
20 /* The connection is closed by a background thread. Some kernels
21 /* cannot handle client-side disconnect before the server has
22 /* received the message.
26 /* Name of the communication endpoint.
28 /* Address of data to be written.
30 /* Amount of data to be written.
32 /* Deadline in seconds. Specify a value <= 0 to disable
35 /* The result is zero in case of success, -1 in case of problems.
37 /* upass_connect(3), UNIX-domain client
41 /* The Secure Mailer license must be distributed with this software.
44 /* IBM T.J. Watson Research
46 /* Yorktown Heights, NY 10598, USA
52 #include <sys/socket.h>
56 /* Utility library. */
65 struct upass_trigger
{
70 /* upass_trigger_event - disconnect from peer */
72 static void upass_trigger_event(int event
, char *context
)
74 struct upass_trigger
*up
= (struct upass_trigger
*) context
;
75 static const char *myname
= "upass_trigger_event";
80 if (event
== EVENT_TIME
)
81 msg_warn("%s: read timeout for service %s", myname
, up
->service
);
82 event_disable_readwrite(up
->fd
);
83 event_cancel_timer(upass_trigger_event
, context
);
84 if (close(up
->fd
) < 0)
85 msg_warn("%s: close %s: %m", myname
, up
->service
);
90 /* upass_trigger - wakeup UNIX-domain server */
92 int upass_trigger(const char *service
, const char *buf
, ssize_t len
, int timeout
)
94 const char *myname
= "upass_trigger";
95 struct upass_trigger
*up
;
99 msg_info("%s: service %s", myname
, service
);
104 if ((fd
= upass_connect(service
, BLOCKING
, timeout
)) < 0) {
106 msg_warn("%s: connect to %s: %m", myname
, service
);
109 close_on_exec(fd
, CLOSE_ON_EXEC
);
112 * Stash away context.
114 up
= (struct upass_trigger
*) mymalloc(sizeof(*up
));
116 up
->service
= mystrdup(service
);
119 * Write the request...
121 if (write_buf(fd
, buf
, len
, timeout
) < 0
122 || write_buf(fd
, "", 1, timeout
) < 0)
124 msg_warn("%s: write to %s: %m", myname
, service
);
127 * Wakeup when the peer disconnects, or when we lose patience.
130 event_request_timer(upass_trigger_event
, (char *) up
, timeout
+ 100);
131 event_enable_read(fd
, upass_trigger_event
, (char *) up
);