7 /* skeleton multi-threaded mail subsystem
9 /* #include <mail_server.h>
11 /* NORETURN multi_server_main(argc, argv, service, key, value, ...)
14 /* void (*service)(VSTREAM *stream, char *service_name, char **argv);
17 /* void multi_server_disconnect(stream)
20 /* void multi_server_drain()
22 /* This module implements a skeleton for multi-threaded
23 /* mail subsystems: mail subsystem programs that service multiple
24 /* clients at the same time. The resulting program expects to be run
25 /* from the \fBmaster\fR process.
27 /* multi_server_main() is the skeleton entry point. It should be
28 /* called from the application main program. The skeleton does all
29 /* the generic command-line processing, initialization of
30 /* configurable parameters, and connection management.
31 /* The skeleton never returns.
34 /* .IP "void (*service)(VSTREAM *stream, char *service_name, char **argv)"
35 /* A pointer to a function that is called by the skeleton each
36 /* time a client sends data to the program's service port. The
37 /* function is run after the program has optionally dropped its
38 /* privileges. This function should not attempt to preserve state
39 /* across calls. The stream initial state is non-blocking mode.
40 /* The service name argument corresponds to the service name in the
42 /* The argv argument specifies command-line arguments left over
43 /* after options processing.
45 /* Optional arguments are specified as a null-terminated (key, value)
46 /* list. Keys and expected values are:
47 /* .IP "MAIL_SERVER_INT_TABLE (CONFIG_INT_TABLE *)"
48 /* A table with configurable parameters, to be loaded from the
49 /* global Postfix configuration file. Tables are loaded in the
50 /* order as specified, and multiple instances of the same type
52 /* .IP "MAIL_SERVER_STR_TABLE (CONFIG_STR_TABLE *)"
53 /* A table with configurable parameters, to be loaded from the
54 /* global Postfix configuration file. Tables are loaded in the
55 /* order as specified, and multiple instances of the same type
57 /* .IP "MAIL_SERVER_BOOL_TABLE (CONFIG_BOOL_TABLE *)"
58 /* A table with configurable parameters, to be loaded from the
59 /* global Postfix configuration file. Tables are loaded in the
60 /* order as specified, and multiple instances of the same type
62 /* .IP "MAIL_SERVER_TIME_TABLE (CONFIG_TIME_TABLE *)"
63 /* A table with configurable parameters, to be loaded from the
64 /* global Postfix configuration file. Tables are loaded in the
65 /* order as specified, and multiple instances of the same type
67 /* .IP "MAIL_SERVER_RAW_TABLE (CONFIG_RAW_TABLE *)"
68 /* A table with configurable parameters, to be loaded from the
69 /* global Postfix configuration file. Tables are loaded in the
70 /* order as specified, and multiple instances of the same type
71 /* are allowed. Raw parameters are not subjected to $name
73 /* .IP "MAIL_SERVER_NINT_TABLE (CONFIG_NINT_TABLE *)"
74 /* A table with configurable parameters, to be loaded from the
75 /* global Postfix configuration file. Tables are loaded in the
76 /* order as specified, and multiple instances of the same type
78 /* .IP "MAIL_SERVER_PRE_INIT (void *(char *service_name, char **argv))"
79 /* A pointer to a function that is called once
80 /* by the skeleton after it has read the global configuration file
81 /* and after it has processed command-line arguments, but before
82 /* the skeleton has optionally relinquished the process privileges.
84 /* Only the last instance of this parameter type is remembered.
85 /* .IP "MAIL_SERVER_POST_INIT (void *(char *service_name, char **argv))"
86 /* A pointer to a function that is called once
87 /* by the skeleton after it has optionally relinquished the process
88 /* privileges, but before servicing client connection requests.
90 /* Only the last instance of this parameter type is remembered.
91 /* .IP "MAIL_SERVER_LOOP (int *(char *service_name, char **argv))"
92 /* A pointer to function that is executed from
93 /* within the event loop, whenever an I/O or timer event has happened,
94 /* or whenever nothing has happened for a specified amount of time.
95 /* The result value of the function specifies how long to wait until
96 /* the next event. Specify -1 to wait for "as long as it takes".
98 /* Only the last instance of this parameter type is remembered.
99 /* .IP "MAIL_SERVER_EXIT (void *(char *service_name, char **argv))"
100 /* A pointer to function that is executed immediately before normal
101 /* process termination.
102 /* .IP "MAIL_SERVER_PRE_ACCEPT (void *(char *service_name, char **argv))"
103 /* Function to be executed prior to accepting a new connection.
105 /* Only the last instance of this parameter type is remembered.
106 /* .IP "MAIL_SERVER_PRE_DISCONN (VSTREAM *, char *service_name, char **argv)"
107 /* A pointer to a function that is called
108 /* by the multi_server_disconnect() function (see below).
110 /* Only the last instance of this parameter type is remembered.
111 /* .IP "MAIL_SERVER_IN_FLOW_DELAY (none)"
112 /* Pause $in_flow_delay seconds when no "mail flow control token"
113 /* is available. A token is consumed for each connection request.
114 /* .IP MAIL_SERVER_SOLITARY
115 /* This service must be configured with process limit of 1.
116 /* .IP MAIL_SERVER_UNLIMITED
117 /* This service must be configured with process limit of 0.
118 /* .IP MAIL_SERVER_PRIVILEGED
119 /* This service must be configured as privileged.
121 /* multi_server_disconnect() should be called by the application
122 /* when a client disconnects.
124 /* multi_server_drain() should be called when the application
125 /* no longer wishes to accept new client connections. Existing
126 /* clients are handled in a background process. A non-zero
127 /* result means this call should be tried again later.
129 /* The var_use_limit variable limits the number of clients that
130 /* a server can service before it commits suicide.
131 /* This value is taken from the global \fBmain.cf\fR configuration
132 /* file. Setting \fBvar_use_limit\fR to zero disables the client limit.
134 /* The var_idle_limit variable limits the time that a service
135 /* receives no client connection requests before it commits suicide.
136 /* This value is taken from the global \fBmain.cf\fR configuration
137 /* file. Setting \fBvar_idle_limit\fR to zero disables the idle limit.
139 /* Problems and transactions are logged to \fBsyslogd\fR(8).
141 /* master(8), master process
142 /* syslogd(8) system logging
146 /* The Secure Mailer license must be distributed with this software.
149 /* IBM T.J. Watson Research
151 /* Yorktown Heights, NY 10598, USA
154 /* System library. */
156 #include <sys_defs.h>
157 #include <sys/socket.h>
158 #include <sys/time.h> /* select() */
168 #ifdef STRCASECMP_IN_STRINGS_H
173 #ifdef USE_SYS_SELECT_H
174 #include <sys/select.h> /* select() */
177 /* Utility library. */
180 #include <msg_syslog.h>
181 #include <msg_vstream.h>
182 #include <chroot_uid.h>
187 #include <msg_vstream.h>
188 #include <mymalloc.h>
190 #include <stringops.h>
191 #include <sane_accept.h>
193 #include <safe_open.h>
195 #include <watchdog.h>
196 #include <split_at.h>
198 /* Global library. */
200 #include <mail_task.h>
201 #include <debug_process.h>
202 #include <mail_params.h>
203 #include <mail_conf.h>
204 #include <mail_dict.h>
205 #include <timed_ipc.h>
206 #include <resolve_local.h>
207 #include <mail_flow.h>
209 /* Process manager. */
211 #include "master_proto.h"
213 /* Application-specific */
215 #include "mail_server.h"
220 static int client_count
;
221 static int use_count
;
222 static int socket_count
= 1;
224 static void (*multi_server_service
) (VSTREAM
*, char *, char **);
225 static char *multi_server_name
;
226 static char **multi_server_argv
;
227 static void (*multi_server_accept
) (int, char *);
228 static void (*multi_server_onexit
) (char *, char **);
229 static void (*multi_server_pre_accept
) (char *, char **);
230 static VSTREAM
*multi_server_lock
;
231 static int multi_server_in_flow_delay
;
232 static unsigned multi_server_generation
;
233 static void (*multi_server_pre_disconn
) (VSTREAM
*, char *, char **);
235 /* multi_server_exit - normal termination */
237 static NORETURN
multi_server_exit(void)
239 if (multi_server_onexit
)
240 multi_server_onexit(multi_server_name
, multi_server_argv
);
244 /* multi_server_abort - terminate after abnormal master exit */
246 static void multi_server_abort(int unused_event
, char *unused_context
)
249 msg_info("master disconnect -- exiting");
253 /* multi_server_timeout - idle time exceeded */
255 static void multi_server_timeout(int unused_event
, char *unused_context
)
258 msg_info("idle timeout -- exiting");
262 /* multi_server_drain - stop accepting new clients */
264 int multi_server_drain(void)
269 /* Try again later. */
272 /* Finish existing clients in the background, then terminate. */
274 (void) msg_cleanup((MSG_CLEANUP_FN
) 0);
275 for (fd
= MASTER_LISTEN_FD
; fd
< MASTER_LISTEN_FD
+ socket_count
; fd
++)
276 event_disable_readwrite(fd
);
279 /* Let the master start a new process. */
285 /* multi_server_disconnect - terminate client session */
287 void multi_server_disconnect(VSTREAM
*stream
)
290 msg_info("connection closed fd %d", vstream_fileno(stream
));
291 if (multi_server_pre_disconn
)
292 multi_server_pre_disconn(stream
, multi_server_name
, multi_server_argv
);
293 event_disable_readwrite(vstream_fileno(stream
));
294 (void) vstream_fclose(stream
);
299 /* multi_server_execute - in case (char *) != (struct *) */
301 static void multi_server_execute(int unused_event
, char *context
)
303 VSTREAM
*stream
= (VSTREAM
*) context
;
305 if (multi_server_lock
!= 0
306 && myflock(vstream_fileno(multi_server_lock
), INTERNAL_LOCK
,
307 MYFLOCK_OP_NONE
) < 0)
308 msg_fatal("select unlock: %m");
311 * Do not bother the application when the client disconnected. Don't drop
312 * the already accepted client request after "postfix reload"; that would
315 if (peekfd(vstream_fileno(stream
)) > 0) {
316 if (master_notify(var_pid
, multi_server_generation
, MASTER_STAT_TAKEN
) < 0)
318 multi_server_service(stream
, multi_server_name
, multi_server_argv
);
319 if (master_notify(var_pid
, multi_server_generation
, MASTER_STAT_AVAIL
) < 0)
320 multi_server_abort(EVENT_NULL_TYPE
, EVENT_NULL_CONTEXT
);
322 multi_server_disconnect(stream
);
324 if (client_count
== 0 && var_idle_limit
> 0)
325 event_request_timer(multi_server_timeout
, (char *) 0, var_idle_limit
);
328 /* multi_server_enable_read - enable read events */
330 static void multi_server_enable_read(int unused_event
, char *context
)
332 VSTREAM
*stream
= (VSTREAM
*) context
;
334 event_enable_read(vstream_fileno(stream
), multi_server_execute
, (char *) stream
);
337 /* multi_server_wakeup - wake up application */
339 static void multi_server_wakeup(int fd
)
344 #if defined(F_DUPFD) && (EVENTS_STYLE != EVENTS_STYLE_SELECT)
345 #ifndef THRESHOLD_FD_WORKAROUND
346 #define THRESHOLD_FD_WORKAROUND 128
351 * Leave some handles < FD_SETSIZE for DBMS libraries, in the unlikely
352 * case of a multi-server with a thousand clients.
354 if (fd
< THRESHOLD_FD_WORKAROUND
) {
355 if ((new_fd
= fcntl(fd
, F_DUPFD
, THRESHOLD_FD_WORKAROUND
)) < 0)
356 msg_fatal("fcntl F_DUPFD: %m");
362 msg_info("connection established fd %d", fd
);
363 non_blocking(fd
, BLOCKING
);
364 close_on_exec(fd
, CLOSE_ON_EXEC
);
366 stream
= vstream_fdopen(fd
, O_RDWR
);
367 tmp
= concatenate(multi_server_name
, " socket", (char *) 0);
368 vstream_control(stream
, VSTREAM_CTL_PATH
, tmp
, VSTREAM_CTL_END
);
370 timed_ipc_setup(stream
);
371 if (multi_server_in_flow_delay
&& mail_flow_get(1) < 0)
372 event_request_timer(multi_server_enable_read
, (char *) stream
,
375 multi_server_enable_read(0, (char *) stream
);
378 /* multi_server_accept_local - accept client connection request */
380 static void multi_server_accept_local(int unused_event
, char *context
)
382 int listen_fd
= CAST_CHAR_PTR_TO_INT(context
);
387 * Be prepared for accept() to fail because some other process already
388 * got the connection (the number of processes competing for clients is
389 * kept small, so this is not a "thundering herd" problem). If the
390 * accept() succeeds, be sure to disable non-blocking I/O, in order to
391 * minimize confusion.
393 if (client_count
== 0 && var_idle_limit
> 0)
394 time_left
= event_cancel_timer(multi_server_timeout
, (char *) 0);
396 if (multi_server_pre_accept
)
397 multi_server_pre_accept(multi_server_name
, multi_server_argv
);
398 fd
= LOCAL_ACCEPT(listen_fd
);
399 if (multi_server_lock
!= 0
400 && myflock(vstream_fileno(multi_server_lock
), INTERNAL_LOCK
,
401 MYFLOCK_OP_NONE
) < 0)
402 msg_fatal("select unlock: %m");
405 msg_error("accept connection: %m");
407 event_request_timer(multi_server_timeout
, (char *) 0, time_left
);
410 multi_server_wakeup(fd
);
413 #ifdef MASTER_XPORT_NAME_PASS
415 /* multi_server_accept_pass - accept descriptor */
417 static void multi_server_accept_pass(int unused_event
, char *context
)
419 int listen_fd
= CAST_CHAR_PTR_TO_INT(context
);
424 * Be prepared for accept() to fail because some other process already
425 * got the connection (the number of processes competing for clients is
426 * kept small, so this is not a "thundering herd" problem). If the
427 * accept() succeeds, be sure to disable non-blocking I/O, in order to
428 * minimize confusion.
430 if (client_count
== 0 && var_idle_limit
> 0)
431 time_left
= event_cancel_timer(multi_server_timeout
, (char *) 0);
433 if (multi_server_pre_accept
)
434 multi_server_pre_accept(multi_server_name
, multi_server_argv
);
435 fd
= PASS_ACCEPT(listen_fd
);
436 if (multi_server_lock
!= 0
437 && myflock(vstream_fileno(multi_server_lock
), INTERNAL_LOCK
,
438 MYFLOCK_OP_NONE
) < 0)
439 msg_fatal("select unlock: %m");
442 msg_error("accept connection: %m");
444 event_request_timer(multi_server_timeout
, (char *) 0, time_left
);
447 multi_server_wakeup(fd
);
452 /* multi_server_accept_inet - accept client connection request */
454 static void multi_server_accept_inet(int unused_event
, char *context
)
456 int listen_fd
= CAST_CHAR_PTR_TO_INT(context
);
461 * Be prepared for accept() to fail because some other process already
462 * got the connection (the number of processes competing for clients is
463 * kept small, so this is not a "thundering herd" problem). If the
464 * accept() succeeds, be sure to disable non-blocking I/O, in order to
465 * minimize confusion.
467 if (client_count
== 0 && var_idle_limit
> 0)
468 time_left
= event_cancel_timer(multi_server_timeout
, (char *) 0);
470 if (multi_server_pre_accept
)
471 multi_server_pre_accept(multi_server_name
, multi_server_argv
);
472 fd
= inet_accept(listen_fd
);
473 if (multi_server_lock
!= 0
474 && myflock(vstream_fileno(multi_server_lock
), INTERNAL_LOCK
,
475 MYFLOCK_OP_NONE
) < 0)
476 msg_fatal("select unlock: %m");
479 msg_error("accept connection: %m");
481 event_request_timer(multi_server_timeout
, (char *) 0, time_left
);
484 multi_server_wakeup(fd
);
487 /* multi_server_main - the real main program */
489 NORETURN
multi_server_main(int argc
, char **argv
, MULTI_SERVER_FN service
,...)
491 const char *myname
= "multi_server_main";
497 char *service_name
= basename(argv
[0]);
502 MAIL_SERVER_INIT_FN pre_init
= 0;
503 MAIL_SERVER_INIT_FN post_init
= 0;
504 MAIL_SERVER_LOOP_FN loop
= 0;
519 int msg_vstream_needed
= 0;
520 int redo_syslog_init
= 0;
523 * Process environment options as early as we can.
525 if (getenv(CONF_ENV_VERB
))
527 if (getenv(CONF_ENV_DEBUG
))
531 * Don't die when a process goes away unexpectedly.
533 signal(SIGPIPE
, SIG_IGN
);
536 * Don't die for frivolous reasons.
539 signal(SIGXFSZ
, SIG_IGN
);
543 * May need this every now and then.
545 var_procname
= mystrdup(basename(argv
[0]));
546 set_mail_conf_str(VAR_PROCNAME
, var_procname
);
549 * Initialize logging and exit handler. Do the syslog first, so that its
550 * initialization completes before we enter the optional chroot jail.
552 msg_syslog_init(mail_task(var_procname
), LOG_PID
, LOG_FACILITY
);
554 msg_info("daemon started");
557 * Initialize from the configuration file. Allow command-line options to
558 * override compiled-in defaults or configured parameter values.
563 * Register dictionaries that use higher-level interfaces and protocols.
568 * Pick up policy settings from master process. Shut up error messages to
569 * stderr, because no-one is going to see them.
572 while ((c
= GETOPT(argc
, argv
, "cdDi:lm:n:o:s:St:uvVz")) > 0) {
584 mail_conf_update(VAR_MAX_IDLE
, optarg
);
590 mail_conf_update(VAR_MAX_USE
, optarg
);
593 service_name
= optarg
;
596 /* XXX Use split_nameval() */
597 oname
= mystrdup(optarg
);
598 if ((oval
= split_at(oname
, '=')) == 0)
600 mail_conf_update(oname
, oval
);
601 if (strcmp(oname
, VAR_SYSLOG_NAME
) == 0)
602 redo_syslog_init
= 1;
605 if ((socket_count
= atoi(optarg
)) <= 0)
606 msg_fatal("invalid socket_count: %s", optarg
);
621 if (++msg_vstream_needed
== 1)
622 msg_vstream_init(mail_task(var_procname
), VSTREAM_ERR
);
628 msg_fatal("invalid option: %c", c
);
634 * Initialize generic parameters.
637 if (redo_syslog_init
)
638 msg_syslog_init(mail_task(var_procname
), LOG_PID
, LOG_FACILITY
);
641 * If not connected to stdin, stdin must not be a terminal.
643 if (daemon_mode
&& stream
== 0 && isatty(STDIN_FILENO
)) {
644 msg_vstream_init(var_procname
, VSTREAM_ERR
);
645 msg_fatal("do not run this command by hand");
649 * Application-specific initialization.
651 va_start(ap
, service
);
652 while ((key
= va_arg(ap
, int)) != 0) {
654 case MAIL_SERVER_INT_TABLE
:
655 get_mail_conf_int_table(va_arg(ap
, CONFIG_INT_TABLE
*));
657 case MAIL_SERVER_STR_TABLE
:
658 get_mail_conf_str_table(va_arg(ap
, CONFIG_STR_TABLE
*));
660 case MAIL_SERVER_BOOL_TABLE
:
661 get_mail_conf_bool_table(va_arg(ap
, CONFIG_BOOL_TABLE
*));
663 case MAIL_SERVER_TIME_TABLE
:
664 get_mail_conf_time_table(va_arg(ap
, CONFIG_TIME_TABLE
*));
666 case MAIL_SERVER_RAW_TABLE
:
667 get_mail_conf_raw_table(va_arg(ap
, CONFIG_RAW_TABLE
*));
669 case MAIL_SERVER_NINT_TABLE
:
670 get_mail_conf_nint_table(va_arg(ap
, CONFIG_NINT_TABLE
*));
672 case MAIL_SERVER_PRE_INIT
:
673 pre_init
= va_arg(ap
, MAIL_SERVER_INIT_FN
);
675 case MAIL_SERVER_POST_INIT
:
676 post_init
= va_arg(ap
, MAIL_SERVER_INIT_FN
);
678 case MAIL_SERVER_LOOP
:
679 loop
= va_arg(ap
, MAIL_SERVER_LOOP_FN
);
681 case MAIL_SERVER_EXIT
:
682 multi_server_onexit
= va_arg(ap
, MAIL_SERVER_EXIT_FN
);
684 case MAIL_SERVER_PRE_ACCEPT
:
685 multi_server_pre_accept
= va_arg(ap
, MAIL_SERVER_ACCEPT_FN
);
687 case MAIL_SERVER_PRE_DISCONN
:
688 multi_server_pre_disconn
= va_arg(ap
, MAIL_SERVER_DISCONN_FN
);
690 case MAIL_SERVER_IN_FLOW_DELAY
:
691 multi_server_in_flow_delay
= 1;
693 case MAIL_SERVER_SOLITARY
:
694 if (stream
== 0 && !alone
)
695 msg_fatal("service %s requires a process limit of 1",
698 case MAIL_SERVER_UNLIMITED
:
699 if (stream
== 0 && !zerolimit
)
700 msg_fatal("service %s requires a process limit of 0",
703 case MAIL_SERVER_PRIVILEGED
:
705 msg_fatal("service %s requires privileged operation",
709 msg_panic("%s: unknown argument type: %d", myname
, key
);
715 root_dir
= var_queue_dir
;
717 user_name
= var_mail_owner
;
720 * Can options be required?
724 msg_fatal("no transport type specified");
725 if (strcasecmp(transport
, MASTER_XPORT_NAME_INET
) == 0)
726 multi_server_accept
= multi_server_accept_inet
;
727 else if (strcasecmp(transport
, MASTER_XPORT_NAME_UNIX
) == 0)
728 multi_server_accept
= multi_server_accept_local
;
729 #ifdef MASTER_XPORT_NAME_PASS
730 else if (strcasecmp(transport
, MASTER_XPORT_NAME_PASS
) == 0)
731 multi_server_accept
= multi_server_accept_pass
;
734 msg_fatal("unsupported transport type: %s", transport
);
738 * Retrieve process generation from environment.
740 if ((generation
= getenv(MASTER_GEN_NAME
)) != 0) {
741 if (!alldig(generation
))
742 msg_fatal("bad generation: %s", generation
);
743 OCTAL_TO_UNSIGNED(multi_server_generation
, generation
);
745 msg_info("process generation: %s (%o)",
746 generation
, multi_server_generation
);
750 * Optionally start the debugger on ourself.
756 * Traditionally, BSD select() can't handle multiple processes selecting
757 * on the same socket, and wakes up every process in select(). See TCP/IP
758 * Illustrated volume 2 page 532. We avoid select() collisions with an
759 * external lock file.
763 * XXX Can't compete for exclusive access to the listen socket because we
764 * also have to monitor existing client connections for service requests.
767 if (stream
== 0 && !alone
) {
768 lock_path
= concatenate(DEF_PID_DIR
, "/", transport
,
769 ".", service_name
, (char *) 0);
770 why
= vstring_alloc(1);
771 if ((multi_server_lock
= safe_open(lock_path
, O_CREAT
| O_RDWR
, 0600,
772 (struct stat
*) 0, -1, -1, why
)) == 0)
773 msg_fatal("open lock file %s: %s", lock_path
, vstring_str(why
));
774 close_on_exec(vstream_fileno(multi_server_lock
), CLOSE_ON_EXEC
);
781 * Set up call-back info.
783 multi_server_service
= service
;
784 multi_server_name
= service_name
;
785 multi_server_argv
= argv
+ optind
;
788 * Run pre-jail initialization.
790 if (chdir(var_queue_dir
) < 0)
791 msg_fatal("chdir(\"%s\"): %m", var_queue_dir
);
793 pre_init(multi_server_name
, multi_server_argv
);
796 * Optionally, restrict the damage that this process can do.
798 resolve_local_init();
800 chroot_uid(root_dir
, user_name
);
803 * Run post-jail initialization.
806 post_init(multi_server_name
, multi_server_argv
);
809 * Are we running as a one-shot server with the client connection on
810 * standard input? If so, make sure the output is written to stdout so as
811 * to satisfy common expectation.
814 vstream_control(stream
,
816 VSTREAM_CTL_WRITE_FD
, STDOUT_FILENO
,
818 service(stream
, multi_server_name
, multi_server_argv
);
819 vstream_fflush(stream
);
824 * Running as a semi-resident server. Service connection requests.
825 * Terminate when we have serviced a sufficient number of clients, when
826 * no-one has been talking to us for a configurable amount of time, or
827 * when the master process terminated abnormally.
829 if (var_idle_limit
> 0)
830 event_request_timer(multi_server_timeout
, (char *) 0, var_idle_limit
);
831 for (fd
= MASTER_LISTEN_FD
; fd
< MASTER_LISTEN_FD
+ socket_count
; fd
++) {
832 event_enable_read(fd
, multi_server_accept
, CAST_INT_TO_CHAR_PTR(fd
));
833 close_on_exec(fd
, CLOSE_ON_EXEC
);
835 event_enable_read(MASTER_STATUS_FD
, multi_server_abort
, (char *) 0);
836 close_on_exec(MASTER_STATUS_FD
, CLOSE_ON_EXEC
);
837 close_on_exec(MASTER_FLOW_READ
, CLOSE_ON_EXEC
);
838 close_on_exec(MASTER_FLOW_WRITE
, CLOSE_ON_EXEC
);
839 watchdog
= watchdog_create(var_daemon_timeout
, (WATCHDOG_FN
) 0, (char *) 0);
842 * The event loop, at last.
844 while (var_use_limit
== 0 || use_count
< var_use_limit
|| client_count
> 0) {
845 if (multi_server_lock
!= 0) {
846 watchdog_stop(watchdog
);
847 if (myflock(vstream_fileno(multi_server_lock
), INTERNAL_LOCK
,
848 MYFLOCK_OP_EXCLUSIVE
) < 0)
849 msg_fatal("select lock: %m");
851 watchdog_start(watchdog
);
852 delay
= loop
? loop(multi_server_name
, multi_server_argv
) : -1;