Commit 296d0bc9 296d0bc958142cafe0e839cd43236c14c8310ee2 by Sergey Poznyakoff

Allow to configure the length of the backlog queue for TCP servers

New statement backlog is provided in the server block.

* include/mailutils/server.h (mu_m_server_cfg_init): Pass
mu_m_server_t as first argument.
* libmailutils/server/msrv.c (mu_m_server_cfg_init): Pass
mu_m_server_t as first argument. Customize available statements
depending on the type of server (tcp vs udp).
New statement "backlog" available for tcp servers.

* comsat/comsat.c: Update call to mu_m_server_cfg_init
* imap4d/imap4d.c: Likewise.
* pop3d/pop3d.c: Likewise.
* maidag/maidag.c: Likewise.
1 parent 37388665
...@@ -566,7 +566,6 @@ main (int argc, char **argv) ...@@ -566,7 +566,6 @@ main (int argc, char **argv)
566 mu_argp_init (NULL, NULL); 566 mu_argp_init (NULL, NULL);
567 comsat_init (); 567 comsat_init ();
568 mu_acl_cfg_init (); 568 mu_acl_cfg_init ();
569 mu_m_server_cfg_init (NULL);
570 mu_m_server_create (&server, program_version); 569 mu_m_server_create (&server, program_version);
571 mu_m_server_set_type (server, MU_IP_UDP); 570 mu_m_server_set_type (server, MU_IP_UDP);
572 mu_m_server_set_conn (server, comsat_connection); 571 mu_m_server_set_conn (server, comsat_connection);
...@@ -575,6 +574,8 @@ main (int argc, char **argv) ...@@ -575,6 +574,8 @@ main (int argc, char **argv)
575 mu_m_server_set_max_children (server, 20); 574 mu_m_server_set_max_children (server, 20);
576 /* FIXME mu_m_server_set_pidfile (); */ 575 /* FIXME mu_m_server_set_pidfile (); */
577 mu_m_server_set_default_port (server, 512); 576 mu_m_server_set_default_port (server, 512);
577 mu_m_server_cfg_init (server, NULL);
578
578 /* FIXME: timeout is not needed. How to disable it? */ 579 /* FIXME: timeout is not needed. How to disable it? */
579 mu_log_syslog = 1; 580 mu_log_syslog = 1;
580 581
......
...@@ -942,7 +942,6 @@ main (int argc, char **argv) ...@@ -942,7 +942,6 @@ main (int argc, char **argv)
942 mu_tcpwrapper_cfg_init (); 942 mu_tcpwrapper_cfg_init ();
943 manlock_cfg_init (); 943 manlock_cfg_init ();
944 mu_acl_cfg_init (); 944 mu_acl_cfg_init ();
945 mu_m_server_cfg_init (imap4d_srv_param);
946 945
947 mu_argp_init (NULL, NULL); 946 mu_argp_init (NULL, NULL);
948 947
...@@ -956,6 +955,7 @@ main (int argc, char **argv) ...@@ -956,6 +955,7 @@ main (int argc, char **argv)
956 mu_m_server_set_default_port (server, 143); 955 mu_m_server_set_default_port (server, 143);
957 mu_m_server_set_timeout (server, 1800); /* RFC2060: 30 minutes. */ 956 mu_m_server_set_timeout (server, 1800); /* RFC2060: 30 minutes. */
958 mu_m_server_set_strexit (server, mu_strexit); 957 mu_m_server_set_strexit (server, mu_strexit);
958 mu_m_server_cfg_init (server, imap4d_srv_param);
959 959
960 mu_alloc_die_hook = imap4d_alloc_die; 960 mu_alloc_die_hook = imap4d_alloc_die;
961 961
......
...@@ -142,7 +142,7 @@ void mu_m_server_stop (int code); ...@@ -142,7 +142,7 @@ void mu_m_server_stop (int code);
142 int mu_m_server_check_acl (mu_m_server_t msrv, struct sockaddr *s, int salen); 142 int mu_m_server_check_acl (mu_m_server_t msrv, struct sockaddr *s, int salen);
143 143
144 struct mu_cfg_param; 144 struct mu_cfg_param;
145 void mu_m_server_cfg_init (struct mu_cfg_param *app_param); 145 void mu_m_server_cfg_init (mu_m_server_t msrv, struct mu_cfg_param *app_param);
146 146
147 147
148 #endif 148 #endif
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
24 #endif 24 #endif
25 #include <sys/types.h> 25 #include <sys/types.h>
26 #include <sys/wait.h> 26 #include <sys/wait.h>
27 #include <stdio.h>
27 #include <stdlib.h> 28 #include <stdlib.h>
28 #include <string.h> 29 #include <string.h>
29 #include <unistd.h> 30 #include <unistd.h>
...@@ -932,8 +933,32 @@ static struct mu_cfg_param server_cfg_param[] = { ...@@ -932,8 +933,32 @@ static struct mu_cfg_param server_cfg_param[] = {
932 { NULL } 933 { NULL }
933 }; 934 };
934 935
936 static int
937 _cb_backlog (void *data, mu_config_value_t *val)
938 {
939 mu_ip_server_t *psrv = data;
940 int backlog;
941
942 if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
943 return 1;
944 if (sscanf (val->v.string, "%d", &backlog) != 1 || backlog <= 0
945 || mu_tcp_server_set_backlog (*psrv, backlog))
946 {
947 mu_error (_("invalid argument"));
948 return 1;
949 }
950 return 0;
951 }
952
953 static struct mu_cfg_param server_tcp_param[] = {
954 { "backlog", mu_cfg_callback,
955 NULL, mu_offsetof (struct mu_srv_config, tcpsrv), _cb_backlog,
956 N_("Size of the queue of pending connections") },
957 { NULL }
958 };
959
935 void 960 void
936 mu_m_server_cfg_init (struct mu_cfg_param *app_param) 961 mu_m_server_cfg_init (mu_m_server_t srv, struct mu_cfg_param *app_param)
937 { 962 {
938 struct mu_cfg_section *section; 963 struct mu_cfg_section *section;
939 if (mu_create_canned_section ("server", &section) == 0) 964 if (mu_create_canned_section ("server", &section) == 0)
...@@ -941,6 +966,8 @@ mu_m_server_cfg_init (struct mu_cfg_param *app_param) ...@@ -941,6 +966,8 @@ mu_m_server_cfg_init (struct mu_cfg_param *app_param)
941 section->parser = server_section_parser; 966 section->parser = server_section_parser;
942 section->label = N_("ipaddr[:port]"); 967 section->label = N_("ipaddr[:port]");
943 mu_cfg_section_add_params (section, server_cfg_param); 968 mu_cfg_section_add_params (section, server_cfg_param);
969 if (srv->deftype == MU_IP_TCP)
970 mu_cfg_section_add_params (section, server_tcp_param);
944 if (app_param) 971 if (app_param)
945 mu_cfg_section_add_params (section, app_param); 972 mu_cfg_section_add_params (section, app_param);
946 } 973 }
......
...@@ -522,7 +522,6 @@ main (int argc, char *argv[]) ...@@ -522,7 +522,6 @@ main (int argc, char *argv[])
522 522
523 mu_tcpwrapper_cfg_init (); 523 mu_tcpwrapper_cfg_init ();
524 mu_acl_cfg_init (); 524 mu_acl_cfg_init ();
525 mu_m_server_cfg_init (NULL);
526 maidag_cfg_init (); 525 maidag_cfg_init ();
527 526
528 /* Parse command line */ 527 /* Parse command line */
...@@ -537,6 +536,7 @@ main (int argc, char *argv[]) ...@@ -537,6 +536,7 @@ main (int argc, char *argv[])
537 mu_m_server_set_mode (server, MODE_INTERACTIVE); 536 mu_m_server_set_mode (server, MODE_INTERACTIVE);
538 mu_m_server_set_max_children (server, 20); 537 mu_m_server_set_max_children (server, 20);
539 mu_m_server_set_timeout (server, 600); 538 mu_m_server_set_timeout (server, 600);
539 mu_m_server_cfg_init (server, NULL);
540 540
541 mu_log_syslog = -1; 541 mu_log_syslog = -1;
542 mu_log_print_severity = 1; 542 mu_log_print_severity = 1;
......
...@@ -575,7 +575,6 @@ main (int argc, char **argv) ...@@ -575,7 +575,6 @@ main (int argc, char **argv)
575 mu_tcpwrapper_cfg_init (); 575 mu_tcpwrapper_cfg_init ();
576 manlock_cfg_init (); 576 manlock_cfg_init ();
577 mu_acl_cfg_init (); 577 mu_acl_cfg_init ();
578 mu_m_server_cfg_init (pop3d_srv_param);
579 578
580 mu_argp_init (NULL, NULL); 579 mu_argp_init (NULL, NULL);
581 580
...@@ -589,6 +588,7 @@ main (int argc, char **argv) ...@@ -589,6 +588,7 @@ main (int argc, char **argv)
589 mu_m_server_set_default_port (server, 110); 588 mu_m_server_set_default_port (server, 110);
590 mu_m_server_set_timeout (server, 600); 589 mu_m_server_set_timeout (server, 600);
591 mu_m_server_set_strexit (server, mu_strexit); 590 mu_m_server_set_strexit (server, mu_strexit);
591 mu_m_server_cfg_init (server, pop3d_srv_param);
592 592
593 mu_alloc_die_hook = pop3d_alloc_die; 593 mu_alloc_die_hook = pop3d_alloc_die;
594 594
......