1*e89934bbSchristos /* $NetBSD: master_proto.c,v 1.2 2017/02/14 01:16:45 christos Exp $ */
241fbaed0Stron
341fbaed0Stron /*++
441fbaed0Stron /* NAME
541fbaed0Stron /* master_proto 3
641fbaed0Stron /* SUMMARY
741fbaed0Stron /* Postfix master - status notification protocol
841fbaed0Stron /* SYNOPSIS
941fbaed0Stron /* #include <master_proto.h>
1041fbaed0Stron /*
1141fbaed0Stron /* int master_notify(pid, generation, status)
1241fbaed0Stron /* int pid;
1341fbaed0Stron /* unsigned generation;
1441fbaed0Stron /* int status;
1541fbaed0Stron /* DESCRIPTION
1641fbaed0Stron /* The master process provides a standard environment for its
1741fbaed0Stron /* child processes. Part of this environment is a pair of file
1841fbaed0Stron /* descriptors that the master process shares with all child
1941fbaed0Stron /* processes that provide the same service.
2041fbaed0Stron /* .IP MASTER_LISTEN_FD
2141fbaed0Stron /* The shared file descriptor for accepting client connection
2241fbaed0Stron /* requests. The master process listens on this socket or FIFO
2341fbaed0Stron /* when all child processes are busy.
2441fbaed0Stron /* .IP MASTER_STATUS_FD
2541fbaed0Stron /* The shared file descriptor for sending child status updates to
2641fbaed0Stron /* the master process.
2741fbaed0Stron /* .PP
2841fbaed0Stron /* A child process uses master_notify() to send a status notification
2941fbaed0Stron /* message to the master process.
3041fbaed0Stron /* .IP MASTER_STAT_AVAIL
3141fbaed0Stron /* The child process is ready to accept client connections.
3241fbaed0Stron /* .IP MASTER_STAT_TAKEN
3341fbaed0Stron /* Until further notice, the child process is unavailable for
3441fbaed0Stron /* accepting client connections.
3541fbaed0Stron /* .PP
3641fbaed0Stron /* When a child process terminates without sending a status update,
3741fbaed0Stron /* the master process will figure out that the child is no longer
3841fbaed0Stron /* available.
3941fbaed0Stron /* DIAGNOSTICS
4041fbaed0Stron /* The result is -1 in case of problems. This usually means that
4141fbaed0Stron /* the parent disconnected after a reload request, in order to
4241fbaed0Stron /* force children to commit suicide.
4341fbaed0Stron /* LICENSE
4441fbaed0Stron /* .ad
4541fbaed0Stron /* .fi
4641fbaed0Stron /* The Secure Mailer license must be distributed with this software.
4741fbaed0Stron /* AUTHOR(S)
4841fbaed0Stron /* Wietse Venema
4941fbaed0Stron /* IBM T.J. Watson Research
5041fbaed0Stron /* P.O. Box 704
5141fbaed0Stron /* Yorktown Heights, NY 10598, USA
5241fbaed0Stron /*--*/
5341fbaed0Stron
5441fbaed0Stron /* System library. */
5541fbaed0Stron
5641fbaed0Stron #include <sys_defs.h>
5741fbaed0Stron #include <unistd.h>
5841fbaed0Stron
5941fbaed0Stron /* Utility library. */
6041fbaed0Stron
6141fbaed0Stron #include <msg.h>
6241fbaed0Stron
6341fbaed0Stron /* Global library. */
6441fbaed0Stron
6541fbaed0Stron #include "master_proto.h"
6641fbaed0Stron
master_notify(int pid,unsigned generation,int status)6741fbaed0Stron int master_notify(int pid, unsigned generation, int status)
6841fbaed0Stron {
6941fbaed0Stron const char *myname = "master_notify";
7041fbaed0Stron MASTER_STATUS stat;
7141fbaed0Stron
7241fbaed0Stron /*
7341fbaed0Stron * We use a simple binary protocol to minimize security risks. Since this
7441fbaed0Stron * is local IPC, there are no byte order or word length issues. The
7541fbaed0Stron * server treats this information as gossip, so sending a bad PID or a
7641fbaed0Stron * bad status code will only have amusement value.
7741fbaed0Stron */
7841fbaed0Stron stat.pid = pid;
7941fbaed0Stron stat.gen = generation;
8041fbaed0Stron stat.avail = status;
8141fbaed0Stron
82e262b48eSchristos if (write(MASTER_STATUS_FD, (void *) &stat, sizeof(stat)) != sizeof(stat)) {
8341fbaed0Stron if (msg_verbose)
8441fbaed0Stron msg_info("%s: status %d: %m", myname, status);
8541fbaed0Stron return (-1);
8641fbaed0Stron } else {
8741fbaed0Stron if (msg_verbose)
8841fbaed0Stron msg_info("%s: status %d", myname, status);
8941fbaed0Stron return (0);
9041fbaed0Stron }
9141fbaed0Stron }
92