annotate src/master/service-anvil.c @ 23017:c1d36f2575c7 default tip

lib-imap: Fix "Don't accept strings with NULs" cherry-pick
author Timo Sirainen <timo.sirainen@open-xchange.com>
date Thu, 29 Aug 2019 09:55:25 +0300
parents cb108f786fb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21390
diff changeset
1 /* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
4 #include "ioloop.h"
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "fd-close-on-exec.h"
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "fd-set-nonblock.h"
10454
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
7 #include "fdpass.h"
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "service.h"
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "service-process.h"
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "service-process-notify.h"
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "service-anvil.h"
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include <unistd.h>
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14
9866
1d2d0aa8e313 anvil, config: Use the name in initial VERSION handshake.
Timo Sirainen <tss@iki.fi>
parents: 9235
diff changeset
15 #define ANVIL_HANDSHAKE "VERSION\tanvil\t1\t0\n"
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
17 struct service_anvil_global *service_anvil_global;
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
18
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
19 static void
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
20 service_list_anvil_discard_input_stop(struct service_anvil_global *anvil)
9955
907e781f7999 master: Fix to previous change, don't crash at service deinit.
Timo Sirainen <tss@iki.fi>
parents: 9954
diff changeset
21 {
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
22 if (anvil->io_blocking != NULL) {
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
23 io_remove(&anvil->io_blocking);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
24 io_remove(&anvil->io_nonblocking);
9955
907e781f7999 master: Fix to previous change, don't crash at service deinit.
Timo Sirainen <tss@iki.fi>
parents: 9954
diff changeset
25 }
907e781f7999 master: Fix to previous change, don't crash at service deinit.
Timo Sirainen <tss@iki.fi>
parents: 9954
diff changeset
26 }
907e781f7999 master: Fix to previous change, don't crash at service deinit.
Timo Sirainen <tss@iki.fi>
parents: 9954
diff changeset
27
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
28 static void anvil_input_fd_discard(struct service_anvil_global *anvil, int fd)
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
29 {
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
30 char buf[1024];
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
31 ssize_t ret;
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
32
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
33 ret = read(fd, buf, sizeof(buf));
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
34 if (ret <= 0) {
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
35 i_error("read(anvil fd) failed: %m");
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
36 service_list_anvil_discard_input_stop(anvil);
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
37 }
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
38 }
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
39
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
40 static void anvil_input_blocking_discard(struct service_anvil_global *anvil)
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
41 {
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
42 anvil_input_fd_discard(anvil, anvil->blocking_fd[0]);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
43 }
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
44
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
45 static void anvil_input_nonblocking_discard(struct service_anvil_global *anvil)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
46 {
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
47 anvil_input_fd_discard(anvil, anvil->nonblocking_fd[0]);
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
48 }
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
49
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
50 static void service_list_anvil_discard_input(struct service_anvil_global *anvil)
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
51 {
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
52 if (anvil->io_blocking != NULL)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
53 return;
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
54
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
55 anvil->io_blocking = io_add(anvil->blocking_fd[0], IO_READ,
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
56 anvil_input_blocking_discard, anvil);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
57 anvil->io_nonblocking = io_add(anvil->nonblocking_fd[0], IO_READ,
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
58 anvil_input_nonblocking_discard, anvil);
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
59 }
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
60
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 static int anvil_send_handshake(int fd, const char **error_r)
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 {
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 ssize_t ret;
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 ret = write(fd, ANVIL_HANDSHAKE, strlen(ANVIL_HANDSHAKE));
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 if (ret < 0) {
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 *error_r = t_strdup_printf("write(anvil) failed: %m");
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 return -1;
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 }
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 if (ret == 0) {
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 *error_r = t_strdup_printf("write(anvil) returned EOF");
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 return -1;
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 }
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 /* this is a pipe, it either wrote all of it or nothing */
10887
588892d877dc Compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents: 10582
diff changeset
75 i_assert((size_t)ret == strlen(ANVIL_HANDSHAKE));
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 return 0;
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 }
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 static int
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 service_process_write_anvil_kill(int fd, struct service_process *process)
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 {
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 const char *data;
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 data = t_strdup_printf("KILL\t%s\n", dec2str(process->pid));
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 if (write(fd, data, strlen(data)) < 0) {
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 if (errno != EAGAIN)
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 i_error("write(anvil process) failed: %m");
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 return -1;
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 }
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 return 0;
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 }
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
93 void service_anvil_monitor_start(struct service_list *service_list)
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 {
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
95 struct service *service;
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
96
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
97 if (service_anvil_global->process_count == 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
98 service_list_anvil_discard_input(service_anvil_global);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
99 else {
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
100 service = service_lookup_type(service_list, SERVICE_TYPE_ANVIL);
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
101 (void)service_process_create(service);
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 }
10069
5147503f4123 master: Add IO listeners to anvil after forking. Fixes kqueue.
Timo Sirainen <tss@iki.fi>
parents: 10021
diff changeset
103 }
5147503f4123 master: Add IO listeners to anvil after forking. Fixes kqueue.
Timo Sirainen <tss@iki.fi>
parents: 10021
diff changeset
104
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
105 void service_anvil_process_created(struct service_process *process)
10069
5147503f4123 master: Add IO listeners to anvil after forking. Fixes kqueue.
Timo Sirainen <tss@iki.fi>
parents: 10021
diff changeset
106 {
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
107 struct service_anvil_global *anvil = service_anvil_global;
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
108 const char *error;
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
109
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
110 service_anvil_global->pid = process->pid;
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
111 service_anvil_global->uid = process->uid;
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
112 service_anvil_global->process_count++;
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
113 service_list_anvil_discard_input_stop(anvil);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
114
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
115 if (anvil_send_handshake(anvil->blocking_fd[1], &error) < 0 ||
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
116 anvil_send_handshake(anvil->nonblocking_fd[1], &error) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
117 service_error(process->service, "%s", error);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
118 }
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
119
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
120 void service_anvil_process_destroyed(struct service_process *process)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
121 {
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
122 i_assert(service_anvil_global->process_count > 0);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
123 if (--service_anvil_global->process_count == 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
124 service_list_anvil_discard_input(service_anvil_global);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
125
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
126 if (service_anvil_global->pid == process->pid)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
127 service_anvil_global->pid = 0;
13648
926a7ceeaa10 anvil: Handle crash restarts without failing completely.
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
128 service_anvil_global->restarted = TRUE;
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 }
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130
10454
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
131 void service_anvil_send_log_fd(void)
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
132 {
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
133 ssize_t ret;
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
134 char b;
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
135
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
136 if (service_anvil_global->process_count == 0)
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
137 return;
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
138
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
139 ret = fd_send(service_anvil_global->log_fdpass_fd[1],
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
140 services->anvil->log_fd[1], &b, 1);
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
141 if (ret < 0)
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
142 i_error("fd_send(anvil log fd) failed: %m");
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
143 else if (ret == 0)
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
144 i_error("fd_send(anvil log fd) failed: disconnected");
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
145 }
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
146
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
147 void service_anvil_global_init(void)
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 {
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
149 struct service_anvil_global *anvil;
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
150
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
151 anvil = i_new(struct service_anvil_global, 1);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
152 if (pipe(anvil->status_fd) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
153 i_fatal("pipe() failed: %m");
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
154 if (pipe(anvil->blocking_fd) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
155 i_fatal("pipe() failed: %m");
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
156 if (pipe(anvil->nonblocking_fd) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
157 i_fatal("pipe() failed: %m");
10454
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
158 if (socketpair(AF_UNIX, SOCK_STREAM, 0, anvil->log_fdpass_fd) < 0)
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
159 i_fatal("socketpair() failed: %m");
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
160 fd_set_nonblock(anvil->status_fd[0], TRUE);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
161 fd_set_nonblock(anvil->status_fd[1], TRUE);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
162 fd_set_nonblock(anvil->nonblocking_fd[1], TRUE);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
163
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
164 fd_close_on_exec(anvil->status_fd[0], TRUE);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
165 fd_close_on_exec(anvil->status_fd[1], TRUE);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
166 fd_close_on_exec(anvil->blocking_fd[0], TRUE);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
167 fd_close_on_exec(anvil->blocking_fd[1], TRUE);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
168 fd_close_on_exec(anvil->nonblocking_fd[0], TRUE);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
169 fd_close_on_exec(anvil->nonblocking_fd[1], TRUE);
10454
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
170 fd_close_on_exec(anvil->log_fdpass_fd[0], TRUE);
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
171 fd_close_on_exec(anvil->log_fdpass_fd[1], TRUE);
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
172
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
173 anvil->kills =
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
174 service_process_notify_init(anvil->nonblocking_fd[1],
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
175 service_process_write_anvil_kill);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
176 service_anvil_global = anvil;
9235
2e2b957f1cca Implemented anvil service, which is used to implement mail_max_userip_connections.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177 }
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
178
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
179 void service_anvil_global_deinit(void)
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
180 {
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
181 struct service_anvil_global *anvil = service_anvil_global;
9992
fb16190aa088 master: Fixes to handling anvil service.
Timo Sirainen <tss@iki.fi>
parents: 9955
diff changeset
182
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
183 service_list_anvil_discard_input_stop(anvil);
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
184 service_process_notify_deinit(&anvil->kills);
10454
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
185 if (close(anvil->log_fdpass_fd[0]) < 0)
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
186 i_error("close(anvil) failed: %m");
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
187 if (close(anvil->log_fdpass_fd[1]) < 0)
802b9ebe79e6 anvil: After master gets a SIGHUP, start logging via new log process.
Timo Sirainen <tss@iki.fi>
parents: 10200
diff changeset
188 i_error("close(anvil) failed: %m");
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
189 if (close(anvil->blocking_fd[0]) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
190 i_error("close(anvil) failed: %m");
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
191 if (close(anvil->blocking_fd[1]) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
192 i_error("close(anvil) failed: %m");
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
193 if (close(anvil->nonblocking_fd[0]) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
194 i_error("close(anvil) failed: %m");
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
195 if (close(anvil->nonblocking_fd[1]) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
196 i_error("close(anvil) failed: %m");
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
197 if (close(anvil->status_fd[0]) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
198 i_error("close(anvil) failed: %m");
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
199 if (close(anvil->status_fd[1]) < 0)
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
200 i_error("close(anvil) failed: %m");
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
201 i_free(anvil);
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
202
10200
01676e67cf38 master: anvil process now stays alive across SIGHUPs.
Timo Sirainen <tss@iki.fi>
parents: 10069
diff changeset
203 service_anvil_global = NULL;
9954
c998a51b7be4 master: If anvil isn't used, read and discard all anvil input coming from mail processes.
Timo Sirainen <tss@iki.fi>
parents: 9866
diff changeset
204 }