Postfix3.3.1
master_proto.c
[詳解]
1 /*++
2 /* NAME
3 /* master_proto 3
4 /* SUMMARY
5 /* Postfix master - status notification protocol
6 /* SYNOPSIS
7 /* #include <master_proto.h>
8 /*
9 /* int master_notify(pid, generation, status)
10 /* int pid;
11 /* unsigned generation;
12 /* int status;
13 /* DESCRIPTION
14 /* The master process provides a standard environment for its
15 /* child processes. Part of this environment is a pair of file
16 /* descriptors that the master process shares with all child
17 /* processes that provide the same service.
18 /* .IP MASTER_LISTEN_FD
19 /* The shared file descriptor for accepting client connection
20 /* requests. The master process listens on this socket or FIFO
21 /* when all child processes are busy.
22 /* .IP MASTER_STATUS_FD
23 /* The shared file descriptor for sending child status updates to
24 /* the master process.
25 /* .PP
26 /* A child process uses master_notify() to send a status notification
27 /* message to the master process.
28 /* .IP MASTER_STAT_AVAIL
29 /* The child process is ready to accept client connections.
30 /* .IP MASTER_STAT_TAKEN
31 /* Until further notice, the child process is unavailable for
32 /* accepting client connections.
33 /* .PP
34 /* When a child process terminates without sending a status update,
35 /* the master process will figure out that the child is no longer
36 /* available.
37 /* DIAGNOSTICS
38 /* The result is -1 in case of problems. This usually means that
39 /* the parent disconnected after a reload request, in order to
40 /* force children to commit suicide.
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 /*--*/
51 
52 /* System library. */
53 
54 #include <sys_defs.h>
55 #include <unistd.h>
56 
57 /* Utility library. */
58 
59 #include <msg.h>
60 
61 /* Global library. */
62 
63 #include "master_proto.h"
64 
65 int master_notify(int pid, unsigned generation, int status)
66 {
67  const char *myname = "master_notify";
69 
70  /*
71  * We use a simple binary protocol to minimize security risks. Since this
72  * is local IPC, there are no byte order or word length issues. The
73  * server treats this information as gossip, so sending a bad PID or a
74  * bad status code will only have amusement value.
75  */
76  stat.pid = pid;
77  stat.gen = generation;
78  stat.avail = status;
79 
80  if (write(MASTER_STATUS_FD, (void *) &stat, sizeof(stat)) != sizeof(stat)) {
81  if (msg_verbose)
82  msg_info("%s: status %d: %m", myname, status);
83  return (-1);
84  } else {
85  if (msg_verbose)
86  msg_info("%s: status %d", myname, status);
87  return (0);
88  }
89 }
int msg_verbose
Definition: msg.c:177
unsigned gen
Definition: master_proto.h:27
int master_notify(int pid, unsigned generation, int status)
Definition: master_proto.c:65
#define stat(p, s)
Definition: warn_stat.h:18
#define MASTER_STATUS_FD
Definition: master_proto.h:56
void msg_info(const char *fmt,...)
Definition: msg.c:199