Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/master/main.c @ 5824:5d0aa827f130 HEAD
Reordered initialization code. Capabilities are now dropped as soon as
possible.
author | root@hurina |
---|---|
date | Thu, 28 Jun 2007 02:13:07 +0300 |
parents | 4f22660ffd33 |
children | f655c4d4a419 |
rev | line source |
---|---|
0 | 1 /* Copyright (C) 2002 Timo Sirainen */ |
2 | |
3 #include "common.h" | |
4 #include "ioloop.h" | |
5 #include "lib-signals.h" | |
6 #include "network.h" | |
697
7814b29d0862
Created env_put() and env_clean() for a bit easier handling of environment
Timo Sirainen <tss@iki.fi>
parents:
635
diff
changeset
|
7 #include "env-util.h" |
727
8dd8ebe6bcac
We use close-on-exec flag now to make sure that master process closes the
Timo Sirainen <tss@iki.fi>
parents:
697
diff
changeset
|
8 #include "fd-close-on-exec.h" |
2524 | 9 #include "write-full.h" |
0 | 10 |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
11 #include "askpass.h" |
0 | 12 #include "auth-process.h" |
5789
4f22660ffd33
Move POSIX capabilities dropping into separate function.
Andrey Panin <pazke@donpac.ru>
parents:
5696
diff
changeset
|
13 #include "capabilities.h" |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
14 #include "dict-process.h" |
0 | 15 #include "login-process.h" |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
16 #include "mail-process.h" |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
17 #include "syslog-util.h" |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
18 #include "ssl-init.h" |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
19 #include "log.h" |
0 | 20 |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
21 #include <stdio.h> |
0 | 22 #include <stdlib.h> |
23 #include <unistd.h> | |
24 #include <fcntl.h> | |
25 #include <syslog.h> | |
26 #include <sys/stat.h> | |
27 #include <sys/wait.h> | |
28 | |
29 const char *process_names[PROCESS_TYPE_MAX] = { | |
30 "unknown", | |
31 "auth", | |
3166
e6a487d80288
Restructuring of auth code. Balancer auth processes were a bad idea. Usually
Timo Sirainen <tss@iki.fi>
parents:
3075
diff
changeset
|
32 "auth-worker", |
0 | 33 "login", |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
34 "imap", |
1358
70b60399c7d3
Separate PROCESS_TYPE_MAIL into IMAP and POP3.
Timo Sirainen <tss@iki.fi>
parents:
1273
diff
changeset
|
35 "pop3", |
3989
e93e39326ae1
Added ssl-build-param binary to build the ssl-parameters.dat. This way
Timo Sirainen <tss@iki.fi>
parents:
3966
diff
changeset
|
36 "ssl-build-param", |
3966
19dcfd289610
Added missing "dict" to process names
Timo Sirainen <tss@iki.fi>
parents:
3919
diff
changeset
|
37 "dict" |
0 | 38 }; |
39 | |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
40 static const char *configfile = SYSCONFDIR "/" PACKAGE ".conf"; |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
41 static const char *env_tz; |
0 | 42 |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
43 struct ioloop *ioloop; |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
867
diff
changeset
|
44 struct hash_table *pids; |
5432
2b4fa90860dd
Before unlinking auth sockets at startup, try connecting to them first to
Timo Sirainen <tss@iki.fi>
parents:
5333
diff
changeset
|
45 int null_fd = -1, inetd_login_fd; |
1617
cc3cef25662c
Replaced geteuid() calls with one in the beginning and saving it to
Timo Sirainen <tss@iki.fi>
parents:
1610
diff
changeset
|
46 uid_t master_uid; |
3989
e93e39326ae1
Added ssl-build-param binary to build the ssl-parameters.dat. This way
Timo Sirainen <tss@iki.fi>
parents:
3966
diff
changeset
|
47 char program_path[PATH_MAX]; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
48 char ssl_manual_key_password[100]; |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
49 #ifdef DEBUG |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
50 static bool gdb; |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
51 #endif |
0 | 52 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
53 static void listen_fds_open(bool retry); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
54 static void listen_fds_close(struct server_settings *server); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
55 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
56 bool validate_str(const char *str, size_t max_len) |
0 | 57 { |
810
30f6811f4952
Instead of just trusting randomness of authentication cookies between
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
58 size_t i; |
0 | 59 |
60 for (i = 0; i < max_len; i++) { | |
61 if (str[i] == '\0') | |
62 return TRUE; | |
63 } | |
64 | |
65 return FALSE; | |
66 } | |
67 | |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
68 void child_process_init_env(void) |
0 | 69 { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
70 int facility; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
71 |
0 | 72 /* remove all environment, we don't need them */ |
697
7814b29d0862
Created env_put() and env_clean() for a bit easier handling of environment
Timo Sirainen <tss@iki.fi>
parents:
635
diff
changeset
|
73 env_clean(); |
0 | 74 |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
75 /* we'll log through master process */ |
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
76 env_put("LOG_TO_MASTER=1"); |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
77 if (env_tz != NULL) |
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
78 env_put(t_strconcat("TZ=", env_tz, NULL)); |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
79 |
4197
c3ded5b815aa
If we have plugins set and imap_capability unset, figure out the IMAP
Timo Sirainen <tss@iki.fi>
parents:
4138
diff
changeset
|
80 if (settings_root == NULL || |
c3ded5b815aa
If we have plugins set and imap_capability unset, figure out the IMAP
Timo Sirainen <tss@iki.fi>
parents:
4138
diff
changeset
|
81 !syslog_facility_find(settings_root->defaults->syslog_facility, |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
82 &facility)) |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
83 facility = LOG_MAIL; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
84 env_put(t_strdup_printf("SYSLOG_FACILITY=%d", facility)); |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
85 |
4553
d1c0514754d5
Require that master's version number matches the child's, unless
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
86 if (settings_root != NULL && !settings_root->defaults->version_ignore) |
d1c0514754d5
Require that master's version number matches the child's, unless
Timo Sirainen <tss@iki.fi>
parents:
4538
diff
changeset
|
87 env_put("DOVECOT_VERSION="PACKAGE_VERSION); |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
88 #ifdef DEBUG |
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
89 if (gdb) env_put("GDB=1"); |
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
90 #endif |
0 | 91 } |
92 | |
2886
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
93 void client_process_exec(const char *cmd, const char *title) |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
94 { |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
95 const char *executable, *p, **argv; |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
96 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
97 /* very simple argument splitting. */ |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
98 if (*title == '\0') |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
99 argv = t_strsplit(cmd, " "); |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
100 else |
2898 | 101 argv = t_strsplit(t_strconcat(cmd, " ", title, NULL), " "); |
2886
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
102 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
103 executable = argv[0]; |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
104 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
105 /* hide the path, it's ugly */ |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
106 p = strrchr(argv[0], '/'); |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
107 if (p != NULL) argv[0] = p+1; |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
108 |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
109 execv(executable, (char **)argv); |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
110 } |
634cf6aa34d1
Allow running all executables with parameters.
Timo Sirainen <tss@iki.fi>
parents:
2881
diff
changeset
|
111 |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
112 static void set_logfile(struct settings *set) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
113 { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
114 int facility; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
115 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
116 if (*set->log_path == '\0') { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
117 if (!syslog_facility_find(set->syslog_facility, &facility)) |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
118 facility = LOG_MAIL; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
119 |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
120 i_set_failure_syslog("dovecot", LOG_NDELAY, facility); |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
121 } else { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
122 /* log to file or stderr */ |
5333
55260092b094
Fixes to handling log prefixes. imap/pop3 processes now log the
Timo Sirainen <tss@iki.fi>
parents:
5249
diff
changeset
|
123 i_set_failure_file(set->log_path, "dovecot: "); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
124 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
125 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
126 if (*set->info_log_path != '\0') |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
127 i_set_info_file(set->info_log_path); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
128 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
129 i_set_failure_timestamp_format(set->log_timestamp); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
130 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
131 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
132 static void settings_reload(void) |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
133 { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
134 struct server_settings *old_set = settings_root; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
135 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
136 i_warning("SIGHUP received - reloading configuration"); |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
137 |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
138 /* restart auth and login processes */ |
4670 | 139 login_processes_destroy_all(); |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
140 auth_processes_destroy_all(); |
4393
9928ebb54719
Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents:
4388
diff
changeset
|
141 dict_process_kill(); |
1223
52e0830ade13
Added setting mail_drop_priv_before_exec.
Timo Sirainen <tss@iki.fi>
parents:
1124
diff
changeset
|
142 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
143 if (!master_settings_read(configfile, FALSE, FALSE)) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
144 i_warning("Invalid configuration, keeping old one"); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
145 else { |
4355
3af32babd71b
If running from inetd, don't try to open/close listener sockets when
Timo Sirainen <tss@iki.fi>
parents:
4326
diff
changeset
|
146 if (!IS_INETD()) { |
3af32babd71b
If running from inetd, don't try to open/close listener sockets when
Timo Sirainen <tss@iki.fi>
parents:
4326
diff
changeset
|
147 listen_fds_close(old_set); |
3af32babd71b
If running from inetd, don't try to open/close listener sockets when
Timo Sirainen <tss@iki.fi>
parents:
4326
diff
changeset
|
148 listen_fds_open(TRUE); |
3af32babd71b
If running from inetd, don't try to open/close listener sockets when
Timo Sirainen <tss@iki.fi>
parents:
4326
diff
changeset
|
149 } |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
150 set_logfile(settings_root->defaults); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
151 } |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
152 } |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
153 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
154 static void sig_die(int signo, void *context __attr_unused__) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
155 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
156 /* warn about being killed because of some signal, except SIGINT (^C) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
157 which is too common at least while testing :) */ |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
158 if (signo != SIGINT) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
159 i_warning("Killed with signal %d", signo); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
160 io_loop_stop(ioloop); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
161 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
162 |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
163 static void sig_reload_settings(int signo __attr_unused__, |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
164 void *context __attr_unused__) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
165 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
166 settings_reload(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
167 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
168 |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
169 static void sig_reopen_logs(int signo __attr_unused__, |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
170 void *context __attr_unused__) |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
171 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
172 set_logfile(settings_root->defaults); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
173 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
174 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
867
diff
changeset
|
175 static const char *get_exit_status_message(enum fatal_exit_status status) |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
176 { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
177 switch (status) { |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
178 case FATAL_LOGOPEN: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
179 return "Can't open log file"; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
180 case FATAL_LOGWRITE: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
181 return "Can't write to log file"; |
867
e1656057b9a5
Forgot to handle FATAL_LOGERROR.
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
182 case FATAL_LOGERROR: |
e1656057b9a5
Forgot to handle FATAL_LOGERROR.
Timo Sirainen <tss@iki.fi>
parents:
811
diff
changeset
|
183 return "Internal logging error"; |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
184 case FATAL_OUTOFMEM: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
185 return "Out of memory"; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
186 case FATAL_EXEC: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
187 return "exec() failed"; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
188 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
189 case FATAL_DEFAULT: |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
190 return NULL; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
191 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
192 |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
193 return NULL; |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
194 } |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
195 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
196 static void sigchld_handler(int signo __attr_unused__, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
197 void *context __attr_unused__) |
0 | 198 { |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
199 const char *process_type_name, *msg; |
0 | 200 pid_t pid; |
201 int status, process_type; | |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
202 bool abnormal_exit; |
0 | 203 |
204 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { | |
205 /* get the type and remove from hash */ | |
206 process_type = PID_GET_PROCESS_TYPE(pid); | |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
207 if (process_type != PROCESS_TYPE_UNKNOWN) |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
208 PID_REMOVE_PROCESS_TYPE(pid); |
0 | 209 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
210 abnormal_exit = TRUE; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
211 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
212 /* write errors to syslog */ |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
213 process_type_name = process_names[process_type]; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
214 if (WIFEXITED(status)) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
215 status = WEXITSTATUS(status); |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
216 if (status == 0) { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
217 abnormal_exit = FALSE; |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
218 if (process_type == PROCESS_TYPE_UNKNOWN) { |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
219 i_error("unknown child %s exited " |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
220 "successfully", dec2str(pid)); |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
221 } |
5601
b02af502bcd6
When running multiple Dovecot instances, only one of them needs to
Timo Sirainen <tss@iki.fi>
parents:
5589
diff
changeset
|
222 } else if (status == 1 && |
b02af502bcd6
When running multiple Dovecot instances, only one of them needs to
Timo Sirainen <tss@iki.fi>
parents:
5589
diff
changeset
|
223 process_type == PROCESS_TYPE_SSL_PARAM) { |
b02af502bcd6
When running multiple Dovecot instances, only one of them needs to
Timo Sirainen <tss@iki.fi>
parents:
5589
diff
changeset
|
224 /* kludgy. hide this failure. */ |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
225 } else { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
226 msg = get_exit_status_message(status); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
227 msg = msg == NULL ? "" : |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
228 t_strconcat(" (", msg, ")", NULL); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
229 i_error("child %s (%s) returned error %d%s", |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
230 dec2str(pid), process_type_name, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
231 status, msg); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
232 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
233 } else if (WIFSIGNALED(status)) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
234 i_error("child %s (%s) killed with signal %d", |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
235 dec2str(pid), process_type_name, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
236 WTERMSIG(status)); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
237 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
238 |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
239 switch (process_type) { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
240 case PROCESS_TYPE_LOGIN: |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
241 login_process_destroyed(pid, abnormal_exit); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
242 break; |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
243 case PROCESS_TYPE_IMAP: |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
244 case PROCESS_TYPE_POP3: |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
245 mail_process_destroyed(pid); |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
246 break; |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
247 case PROCESS_TYPE_SSL_PARAM: |
5601
b02af502bcd6
When running multiple Dovecot instances, only one of them needs to
Timo Sirainen <tss@iki.fi>
parents:
5589
diff
changeset
|
248 ssl_parameter_process_destroyed(abnormal_exit); |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
249 break; |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
250 case PROCESS_TYPE_DICT: |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
251 dict_process_restart(); |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
252 break; |
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
253 } |
0 | 254 } |
255 | |
256 if (pid == -1 && errno != EINTR && errno != ECHILD) | |
257 i_warning("waitpid() failed: %m"); | |
258 } | |
259 | |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
260 static void resolve_ip(const char *set_name, const char *name, |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
261 struct ip_addr *ip, unsigned int *port) |
0 | 262 { |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
263 struct ip_addr *ip_list; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
264 const char *p; |
4745
7ee0bb1b2d97
Changed ips_count to unsigned int in net_gethostbyname(). Also removed
Timo Sirainen <tss@iki.fi>
parents:
4670
diff
changeset
|
265 unsigned int ips_count; |
7ee0bb1b2d97
Changed ips_count to unsigned int in net_gethostbyname(). Also removed
Timo Sirainen <tss@iki.fi>
parents:
4670
diff
changeset
|
266 int ret; |
0 | 267 |
4326
e228a9efd35d
If ssl_listen setting was empty in config file, startup failed with "Can't
Timo Sirainen <tss@iki.fi>
parents:
4253
diff
changeset
|
268 if (*name == '\0') { |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
269 /* defaults to "*" or "[::]" */ |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
270 ip->family = 0; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
271 return; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
272 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
273 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
274 if (name[0] == '[') { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
275 /* IPv6 address */ |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
276 p = strchr(name, ']'); |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
277 if (p == NULL) { |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
278 i_fatal("%s: Missing ']' in address %s", |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
279 set_name, name); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
280 } |
1100
95d2f3e60b82
[ipv6 address] didn't work in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1058
diff
changeset
|
281 name = t_strdup_until(name+1, p); |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
282 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
283 p++; |
1228
4e438a5c00d3
[ipv6 address] was still buggy in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1223
diff
changeset
|
284 if (*p == '\0') |
4e438a5c00d3
[ipv6 address] was still buggy in *_listen
Timo Sirainen <tss@iki.fi>
parents:
1223
diff
changeset
|
285 p = NULL; |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
286 else if (*p != ':') { |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
287 i_fatal("%s: Invalid data after ']' in address %s", |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
288 set_name, name); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
289 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
290 } else { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
291 p = strrchr(name, ':'); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
292 if (p != NULL) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
293 name = t_strdup_until(name, p); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
294 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
295 |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
296 if (p != NULL) { |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
297 if (!is_numeric(p+1, '\0')) { |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
298 i_fatal("%s: Invalid port in address %s", |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
299 set_name, name); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
300 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
301 *port = atoi(p+1); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
302 } |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
303 |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
304 if (strcmp(name, "*") == 0) { |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
305 /* IPv4 any */ |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
306 net_get_ip_any4(ip); |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
307 return; |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
308 } |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
309 |
1261
5373999355ed
[::] address wasn't treated exactly as "ipv6 any", but looks like
Timo Sirainen <tss@iki.fi>
parents:
1260
diff
changeset
|
310 if (strcmp(name, "::") == 0) { |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
311 /* IPv6 any */ |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
312 net_get_ip_any6(ip); |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
313 return; |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
740
diff
changeset
|
314 } |
0 | 315 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
316 /* Return the first IP if there happens to be multiple. */ |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
317 ret = net_gethostbyname(name, &ip_list, &ips_count); |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
318 if (ret != 0) { |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
319 i_fatal("%s: Can't resolve address %s: %s", |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
320 set_name, name, net_gethosterror(ret)); |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
321 } |
0 | 322 |
323 if (ips_count < 1) | |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
324 i_fatal("%s: No IPs for address: %s", set_name, name); |
0 | 325 |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
326 *ip = ip_list[0]; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
327 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
328 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
329 static void |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
330 check_conflicts_set(const struct settings *set, const struct ip_addr *ip, |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
331 unsigned int port, const char *name1, const char *name2) |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
332 { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
333 if (set->listen_port == port && net_ip_compare(ip, &set->listen_ip) && |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
334 set->listen_fd > 0) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
335 i_fatal("Protocols %s and %s are listening in same ip/port", |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
336 name1, name2); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
337 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
338 if (set->ssl_listen_port == port && |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
339 net_ip_compare(ip, &set->ssl_listen_ip) && set->ssl_listen_fd > 0) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
340 i_fatal("Protocols %ss and %s are listening in same ip/port", |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
341 name1, name2); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
342 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
343 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
344 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
345 static void check_conflicts(const struct ip_addr *ip, unsigned int port, |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
346 const char *proto) |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
347 { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
348 struct server_settings *server; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
349 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
350 for (server = settings_root; server != NULL; server = server->next) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
351 if (server->imap != NULL) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
352 check_conflicts_set(server->imap, ip, port, |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
353 "imap", proto); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
354 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
355 if (server->pop3 != NULL) { |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
356 check_conflicts_set(server->pop3, ip, port, |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
357 "pop3", proto); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
358 } |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
359 } |
0 | 360 } |
361 | |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
362 static void listen_protocols(struct settings *set, bool retry) |
0 | 363 { |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
364 struct ip_addr *ip; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
365 const char *const *proto; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
366 unsigned int port; |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
367 int *fd, i; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
368 |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
369 set->listen_port = set->protocol == MAIL_PROTOCOL_IMAP ? 143 : 110; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
370 #ifdef HAVE_SSL |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
371 set->ssl_listen_port = set->protocol == MAIL_PROTOCOL_IMAP ? 993 : 995; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
372 #else |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
373 set->ssl_listen_port = 0; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
374 #endif |
0 | 375 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
376 /* resolve */ |
4974
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
377 resolve_ip("listen", set->listen, &set->listen_ip, &set->listen_port); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
378 if (!set->ssl_disable) { |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
379 resolve_ip("ssl_listen", set->ssl_listen, &set->ssl_listen_ip, |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
380 &set->ssl_listen_port); |
4654603f24f6
If ssl_disable=yes, don't bother resolving ssl_listen. Also if listen or
Timo Sirainen <tss@iki.fi>
parents:
4965
diff
changeset
|
381 } |
0 | 382 |
4375
4fa4d1d299d3
We broke if ssl_listen wasn't explicitly set in config file. Patch by
Timo Sirainen <tss@iki.fi>
parents:
4355
diff
changeset
|
383 /* if ssl_listen wasn't explicitly set in the config file, |
4fa4d1d299d3
We broke if ssl_listen wasn't explicitly set in config file. Patch by
Timo Sirainen <tss@iki.fi>
parents:
4355
diff
changeset
|
384 use the non-ssl IP settings for the ssl listener, too. */ |
4fa4d1d299d3
We broke if ssl_listen wasn't explicitly set in config file. Patch by
Timo Sirainen <tss@iki.fi>
parents:
4355
diff
changeset
|
385 if (set->ssl_listen_ip.family == 0 && *set->ssl_listen == '\0') |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
386 set->ssl_listen_ip = set->listen_ip; |
0 | 387 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
388 /* register wanted protocols */ |
1820 | 389 proto = t_strsplit_spaces(set->protocols, " "); |
390 for (; *proto != NULL; proto++) { | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
391 fd = NULL; ip = NULL; port = 0; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
392 if (strcasecmp(*proto, "imap") == 0) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
393 if (set->protocol == MAIL_PROTOCOL_IMAP) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
394 fd = &set->listen_fd; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
395 port = set->listen_port; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
396 ip = &set->listen_ip; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
397 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
398 } else if (strcasecmp(*proto, "imaps") == 0) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
399 if (set->protocol == MAIL_PROTOCOL_IMAP && |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
400 !set->ssl_disable) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
401 fd = &set->ssl_listen_fd; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
402 port = set->ssl_listen_port; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
403 ip = &set->ssl_listen_ip; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
404 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
405 } else if (strcasecmp(*proto, "pop3") == 0) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
406 if (set->protocol == MAIL_PROTOCOL_POP3) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
407 fd = &set->listen_fd; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
408 port = set->listen_port; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
409 ip = &set->listen_ip; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
410 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
411 } else if (strcasecmp(*proto, "pop3s") == 0) { |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
412 if (set->protocol == MAIL_PROTOCOL_POP3 && |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
413 !set->ssl_disable) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
414 fd = &set->ssl_listen_fd; |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
415 port = set->ssl_listen_port; |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
416 ip = &set->ssl_listen_ip; |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
417 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
418 } else { |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
419 i_fatal("Unknown protocol %s", *proto); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
420 } |
0 | 421 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
422 if (fd == NULL) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
423 continue; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
424 |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
425 if (*fd != -1) |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
426 i_fatal("Protocol %s given more than once", *proto); |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
427 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
428 if (port == 0) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
429 *fd = null_fd; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
430 else { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
431 for (i = 0; i < 10; i++) { |
3075
9cb91ed5a110
Added backlog parameter for net_listen*().
Timo Sirainen <tss@iki.fi>
parents:
2898
diff
changeset
|
432 *fd = net_listen(ip, &port, 8); |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
433 if (*fd != -1) |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
434 break; |
5077
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
435 if (errno == EADDRINUSE) { |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
436 /* retry */ |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
437 } else if (errno == EINTR && |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
438 io_loop_is_running(ioloop)) { |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
439 /* SIGHUPing sometimes gets us here. |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
440 we don't want to die. */ |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
441 } else { |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
442 /* error */ |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
443 break; |
acafdee84537
If we see exit for unknown child process, log an error but don't crash. If
Timo Sirainen <tss@iki.fi>
parents:
4974
diff
changeset
|
444 } |
3181
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
445 |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
446 check_conflicts(ip, port, *proto); |
ef3a07e0a634
Give more understandable error message if imap/pop3 listen ports conflict.
Timo Sirainen <tss@iki.fi>
parents:
3166
diff
changeset
|
447 if (!retry) |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
448 break; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
449 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
450 /* wait a while and try again. we're SIGHUPing |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
451 so we most likely just closed it ourself.. */ |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
452 sleep(1); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
453 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
454 |
1423
3e73d02e5f71
Don't try to set /dev/null fd nonblocking, all systems don't like that.
Timo Sirainen <tss@iki.fi>
parents:
1367
diff
changeset
|
455 if (*fd == -1) |
3e73d02e5f71
Don't try to set /dev/null fd nonblocking, all systems don't like that.
Timo Sirainen <tss@iki.fi>
parents:
1367
diff
changeset
|
456 i_fatal("listen(%d) failed: %m", port); |
3e73d02e5f71
Don't try to set /dev/null fd nonblocking, all systems don't like that.
Timo Sirainen <tss@iki.fi>
parents:
1367
diff
changeset
|
457 net_set_nonblock(*fd, TRUE); |
4578
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
458 fd_close_on_exec(*fd, TRUE); |
1423
3e73d02e5f71
Don't try to set /dev/null fd nonblocking, all systems don't like that.
Timo Sirainen <tss@iki.fi>
parents:
1367
diff
changeset
|
459 } |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
460 } |
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
461 |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
462 if (set->listen_fd == -1) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
463 set->listen_fd = null_fd; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
464 if (set->ssl_listen_fd == -1) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
465 set->ssl_listen_fd = null_fd; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
466 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
467 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
468 static void listen_fds_open(bool retry) |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
469 { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
470 struct server_settings *server; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
471 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
472 for (server = settings_root; server != NULL; server = server->next) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
473 if (server->imap != NULL) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
474 listen_protocols(server->imap, retry); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
475 if (server->pop3 != NULL) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
476 listen_protocols(server->pop3, retry); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
477 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
478 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
479 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
480 static void listen_fds_close(struct server_settings *server) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
481 { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
482 for (; server != NULL; server = server->next) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
483 if (server->imap != NULL) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
484 if (server->imap->listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
485 close(server->imap->listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
486 i_error("close(imap.listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
487 if (server->imap->ssl_listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
488 close(server->imap->ssl_listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
489 i_error("close(imap.ssl_listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
490 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
491 if (server->pop3 != NULL) { |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
492 if (server->pop3->listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
493 close(server->pop3->listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
494 i_error("close(pop3.listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
495 if (server->pop3->ssl_listen_fd != null_fd && |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
496 close(server->pop3->ssl_listen_fd) < 0) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
497 i_error("close(pop3.ssl_listen_fd) failed: %m"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
498 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
499 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
500 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
501 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
502 static bool have_stderr_set(struct settings *set) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
503 { |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
504 if (*set->log_path != '\0' && |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
505 strcmp(set->log_path, "/dev/stderr") == 0) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
506 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
507 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
508 if (*set->info_log_path != '\0' && |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
509 strcmp(set->info_log_path, "/dev/stderr") == 0) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
510 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
511 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
512 return FALSE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
513 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
514 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3853
diff
changeset
|
515 static bool have_stderr(struct server_settings *server) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
516 { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
517 while (server != NULL) { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
518 if (server->imap != NULL && have_stderr_set(server->imap)) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
519 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
520 if (server->pop3 != NULL && have_stderr_set(server->pop3)) |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
521 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
522 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
523 server = server->next; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
524 } |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
525 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
526 return FALSE; |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
527 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
528 |
5437 | 529 static void open_null_fd(void) |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
530 { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
531 null_fd = open("/dev/null", O_RDONLY); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
532 if (null_fd == -1) |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
533 i_fatal("Can't open /dev/null: %m"); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
534 fd_close_on_exec(null_fd, TRUE); |
5437 | 535 } |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
536 |
5437 | 537 static void open_fds(void) |
538 { | |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
539 /* make sure all fds between 0..3 are used. */ |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
540 while (null_fd < 4) { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
541 null_fd = dup(null_fd); |
4578
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
542 if (null_fd == -1) |
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
543 i_fatal("dup(null_fd) failed: %m"); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
544 fd_close_on_exec(null_fd, TRUE); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
545 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
546 |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
547 if (!IS_INETD()) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
548 listen_fds_open(FALSE); |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
549 |
4477
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
550 /* close stdin and stdout. */ |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
551 if (dup2(null_fd, 0) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
552 i_fatal("dup2(0) failed: %m"); |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
553 if (dup2(null_fd, 1) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
554 i_fatal("dup2(1) failed: %m"); |
0 | 555 } |
556 | |
2524 | 557 static void create_pid_file(const char *path) |
558 { | |
559 const char *pid; | |
560 int fd; | |
561 | |
2534 | 562 pid = t_strconcat(dec2str(getpid()), "\n", NULL); |
2524 | 563 |
564 fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644); | |
565 if (fd == -1) | |
566 i_fatal("open(%s) failed: %m", path); | |
567 if (write_full(fd, pid, strlen(pid)) < 0) | |
568 i_fatal("write() failed in %s: %m", path); | |
569 (void)close(fd); | |
570 } | |
571 | |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
572 static void main_init(bool log_error) |
0 | 573 { |
5824
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
574 drop_capabilities(); |
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
575 |
0 | 576 /* deny file access from everyone else except owner */ |
577 (void)umask(0077); | |
578 | |
5824
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
579 set_logfile(settings_root->defaults); |
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
580 /* close stderr unless we're logging into /dev/stderr. */ |
4477
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
581 if (!have_stderr(settings_root)) { |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
582 if (dup2(null_fd, 2) < 0) |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
583 i_fatal("dup2(2) failed: %m"); |
e414beaf1473
If something in io_loop_create() failed, we logged the error to /dev/null.
Timo Sirainen <tss@iki.fi>
parents:
4475
diff
changeset
|
584 } |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
585 i_info("Dovecot v"VERSION" starting up"); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
586 |
5696
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
587 if (log_error) { |
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
588 i_warning("This is Dovecot's warning log"); |
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
589 i_error("This is Dovecot's error log"); |
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
590 i_fatal("This is Dovecot's fatal log"); |
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
591 } |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
592 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
593 lib_signals_init(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
594 lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
595 lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL); |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4745
diff
changeset
|
596 lib_signals_ignore(SIGPIPE, TRUE); |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4745
diff
changeset
|
597 lib_signals_ignore(SIGALRM, FALSE); |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
598 lib_signals_set_handler(SIGHUP, TRUE, sig_reload_settings, NULL); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
599 lib_signals_set_handler(SIGUSR1, TRUE, sig_reopen_logs, NULL); |
0 | 600 |
945
501f076f2e74
Rewrote hash table code, works with less memory now. Also some memory
Timo Sirainen <tss@iki.fi>
parents:
926
diff
changeset
|
601 pids = hash_create(default_pool, default_pool, 128, NULL, NULL); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
602 lib_signals_set_handler(SIGCHLD, TRUE, sigchld_handler, NULL); |
0 | 603 |
5824
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
604 log_init(); |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
605 ssl_init(); |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
606 dict_process_init(); |
0 | 607 auth_processes_init(); |
608 login_processes_init(); | |
2524 | 609 |
610 create_pid_file(t_strconcat(settings_root->defaults->base_dir, | |
611 "/master.pid", NULL)); | |
0 | 612 } |
613 | |
614 static void main_deinit(void) | |
615 { | |
2524 | 616 (void)unlink(t_strconcat(settings_root->defaults->base_dir, |
617 "/master.pid", NULL)); | |
618 | |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
619 /* make sure we log if child processes died unexpectedly */ |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
620 sigchld_handler(SIGCHLD, NULL); |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
621 |
0 | 622 login_processes_deinit(); |
623 auth_processes_deinit(); | |
3853
b3e18b51c205
Start dict server automatically when a client tries to connect to it.
Timo Sirainen <tss@iki.fi>
parents:
3724
diff
changeset
|
624 dict_process_deinit(); |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
625 ssl_deinit(); |
0 | 626 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4485
diff
changeset
|
627 lib_signals_unset_handler(SIGCHLD, sigchld_handler, NULL); |
0 | 628 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
629 if (close(null_fd) < 0) |
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
630 i_error("close(null_fd) failed: %m"); |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
631 |
0 | 632 hash_destroy(pids); |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
633 lib_signals_deinit(); |
2000
c7c19f5071c3
Write all logging through master process. Fixes problems with log rotation,
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
634 log_deinit(); |
0 | 635 closelog(); |
636 } | |
637 | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
638 static void daemonize(struct settings *set) |
0 | 639 { |
640 pid_t pid; | |
641 | |
642 pid = fork(); | |
643 if (pid < 0) | |
644 i_fatal("fork() failed: %m"); | |
645 | |
646 if (pid != 0) | |
647 _exit(0); | |
610 | 648 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
649 if (setsid() < 0) |
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
650 i_fatal("setsid() failed: %m"); |
1367
533bb936e674
chdir() to base_dir at startup. chdir() mail processes to home dir if it's
Timo Sirainen <tss@iki.fi>
parents:
1358
diff
changeset
|
651 |
533bb936e674
chdir() to base_dir at startup. chdir() mail processes to home dir if it's
Timo Sirainen <tss@iki.fi>
parents:
1358
diff
changeset
|
652 if (chdir(set->base_dir) < 0) |
533bb936e674
chdir() to base_dir at startup. chdir() mail processes to home dir if it's
Timo Sirainen <tss@iki.fi>
parents:
1358
diff
changeset
|
653 i_fatal("chdir(%s) failed: %m", set->base_dir); |
0 | 654 } |
655 | |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
656 static void print_help(void) |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
657 { |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
658 printf( |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
659 "Usage: dovecot [-F] [-c <config file>] [-p] [-n] [-a]\n" |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
660 " [--exec-mail <protocol>] [--version] [--build-options]\n"); |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
661 } |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
662 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
663 static void print_build_options(void) |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
664 { |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
665 printf("Build options:" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
666 #ifdef IOLOOP_EPOLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
667 " ioloop=epoll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
668 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
669 #ifdef IOLOOP_KQUEUE |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
670 " ioloop=kqueue" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
671 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
672 #ifdef IOLOOP_POLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
673 " ioloop=poll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
674 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
675 #ifdef IOLOOP_SELECT |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
676 " ioloop=select" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
677 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
678 #ifdef IOLOOP_NOTIFY_DNOTIFY |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
679 " notify=dnotify" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
680 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
681 #ifdef IOLOOP_NOTIFY_INOTIFY |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
682 " notify=inotify" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
683 #endif |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
684 #ifdef IOLOOP_NOTIFY_KQUEUE |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
685 " notify=kqueue" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
686 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
687 #ifdef HAVE_IPV6 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
688 " ipv6" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
689 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
690 #ifdef HAVE_GNUTLS |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
691 " gnutls" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
692 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
693 #ifdef HAVE_OPENSSL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
694 " openssl" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
695 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
696 "\nSQL drivers:" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
697 #ifdef BUILD_MYSQL |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
698 " mysql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
699 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
700 #ifdef BUILD_PGSQL |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
701 " postgresql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
702 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
703 #ifdef BUILD_SQLITE |
3919
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
704 " sqlite" |
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
705 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
706 "\nPassdb:" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
707 #ifdef PASSDB_BSDAUTH |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
708 " bsdauth" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
709 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
710 #ifdef PASSDB_CHECKPASSWORD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
711 " checkpassword" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
712 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
713 #ifdef PASSDB_LDAP |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
714 " ldap" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
715 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
716 #ifdef PASSDB_PAM |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
717 " pam" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
718 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
719 #ifdef PASSDB_PASSWD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
720 " passwd" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
721 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
722 #ifdef PASSDB_PASSWD_FILE |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
723 " passwd-file" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
724 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
725 #ifdef PASSDB_SHADOW |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
726 " shadow" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
727 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
728 #ifdef PASSDB_SQL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
729 " sql" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
730 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
731 #ifdef PASSDB_VPOPMAIL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
732 " vpopmail" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
733 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
734 "\nUserdb:" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
735 #ifdef USERDB_CHECKPASSWORD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
736 " checkpassword" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
737 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
738 #ifdef USERDB_LDAP |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
739 " ldap" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
740 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
741 #ifdef USERDB_PASSWD |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
742 " passwd" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
743 #endif |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
744 #ifdef USERDB_PREFETCH |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
745 " prefetch" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
746 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
747 #ifdef USERDB_PASSWD_FILE |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
748 " passwd-file" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
749 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
750 #ifdef USERDB_SQL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
751 " sql" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
752 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
753 #ifdef USERDB_STATIC |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
754 " static" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
755 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
756 #ifdef USERDB_VPOPMAIL |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
757 " vpopmail" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
758 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
759 "\n"); |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
760 } |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
761 |
0 | 762 int main(int argc, char *argv[]) |
763 { | |
764 /* parse arguments */ | |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
765 const char *exec_protocol = NULL, *exec_section = NULL, *user, *home; |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
766 bool foreground = FALSE, ask_key_pass = FALSE, log_error = FALSE; |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
767 bool dump_config = FALSE, dump_config_nondefaults = FALSE; |
0 | 768 int i; |
769 | |
2311
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
770 #ifdef DEBUG |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
771 gdb = getenv("GDB") != NULL; |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
772 #endif |
0 | 773 lib_init(); |
774 | |
1617
cc3cef25662c
Replaced geteuid() calls with one in the beginning and saving it to
Timo Sirainen <tss@iki.fi>
parents:
1610
diff
changeset
|
775 master_uid = geteuid(); |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
776 inetd_login_fd = -1; |
0 | 777 for (i = 1; i < argc; i++) { |
778 if (strcmp(argv[i], "-F") == 0) { | |
779 /* foreground */ | |
780 foreground = TRUE; | |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
781 } else if (strcmp(argv[i], "-a") == 0) { |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
782 dump_config = TRUE; |
0 | 783 } else if (strcmp(argv[i], "-c") == 0) { |
784 /* config file */ | |
785 i++; | |
786 if (i == argc) i_fatal("Missing config file argument"); | |
787 configfile = argv[i]; | |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
788 } else if (strcmp(argv[i], "-n") == 0) { |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
789 dump_config_nondefaults = dump_config = TRUE; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
790 } else if (strcmp(argv[i], "-p") == 0) { |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
791 /* Ask SSL private key password */ |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
792 ask_key_pass = TRUE; |
2311
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
793 } else if (strcmp(argv[i], "--exec-mail") == 0) { |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
794 /* <protocol> [<server section>] |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
795 read configuration and execute mail process */ |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
796 i++; |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
797 if (i == argc) i_fatal("Missing protocol argument"); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
798 exec_protocol = argv[i]; |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
799 if (i+1 != argc) |
2312
cc753e275197
And section fix for --exec-mail..
Timo Sirainen <tss@iki.fi>
parents:
2311
diff
changeset
|
800 exec_section = argv[++i]; |
1260 | 801 } else if (strcmp(argv[i], "--version") == 0) { |
802 printf("%s\n", VERSION); | |
803 return 0; | |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
804 } else if (strcmp(argv[i], "--build-options") == 0) { |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
805 print_build_options(); |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
806 return 0; |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
807 } else if (strcmp(argv[i], "--log-error") == 0) { |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
808 log_error = TRUE; |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
809 foreground = TRUE; |
0 | 810 } else { |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
811 print_help(); |
0 | 812 i_fatal("Unknown argument: %s", argv[1]); |
813 } | |
814 } | |
815 | |
5437 | 816 /* need to have this open before reading settings */ |
817 open_null_fd(); | |
818 | |
2311
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
819 if (getenv("DOVECOT_INETD") != NULL) { |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
820 /* starting through inetd. */ |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
821 inetd_login_fd = dup(0); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
822 if (inetd_login_fd == -1) |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
823 i_fatal("dup(0) failed: %m"); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
824 fd_close_on_exec(inetd_login_fd, TRUE); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
825 foreground = TRUE; |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
826 } |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
827 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
828 if (dump_config) { |
4485
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
829 /* print the config file path before parsing it, so in case |
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
830 of errors it's still shown */ |
5589
271c35971331
Print also Dovecot version with dovecot -n.
Timo Sirainen <tss@iki.fi>
parents:
5437
diff
changeset
|
831 printf("# "VERSION": %s\n", configfile); |
4485
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
832 } |
eb1e7932ade6
dovecot -n and -a: Print the config file path before parsing it so if there
Timo Sirainen <tss@iki.fi>
parents:
4477
diff
changeset
|
833 |
0 | 834 /* read and verify settings before forking */ |
3901
0ae5f5b468b7
Put ssl-parameters file into login directory so it still can be accessed
Timo Sirainen <tss@iki.fi>
parents:
3897
diff
changeset
|
835 t_push(); |
1058
3b8fb7bf7ecc
Moved settings parsing to lib-settings.
Timo Sirainen <tss@iki.fi>
parents:
1055
diff
changeset
|
836 master_settings_init(); |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
837 if (!master_settings_read(configfile, exec_protocol != NULL, |
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
838 dump_config)) |
5639
e1b3043c0d90
If startup fails because of configuration problems, print "Invalid
Timo Sirainen <tss@iki.fi>
parents:
5601
diff
changeset
|
839 i_fatal("Invalid configuration in %s", configfile); |
3901
0ae5f5b468b7
Put ssl-parameters file into login directory so it still can be accessed
Timo Sirainen <tss@iki.fi>
parents:
3897
diff
changeset
|
840 t_pop(); |
0 | 841 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
842 if (dump_config) { |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
843 master_settings_dump(settings_root, dump_config_nondefaults); |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
844 return 0; |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
845 } |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
846 |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
847 if (ask_key_pass) { |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
848 const char *prompt; |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
849 |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
850 t_push(); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
851 prompt = t_strdup_printf("Give the password for SSL key file " |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
852 "%s: ", |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
853 settings_root->defaults->ssl_key_file); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
854 askpass(prompt, ssl_manual_key_password, |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
855 sizeof(ssl_manual_key_password)); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
856 t_pop(); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
857 } |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
858 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
859 /* save TZ environment. AIX depends on it to get the timezone |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
860 correctly. */ |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
861 env_tz = getenv("TZ"); |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
862 user = getenv("USER"); |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
863 home = getenv("HOME"); |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
864 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
865 /* clean up the environment of everything */ |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
866 env_clean(); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
867 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
868 /* put back the TZ */ |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
869 if (env_tz != NULL) |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
870 env_put(t_strconcat("TZ=", env_tz, NULL)); |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
871 |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
872 if (exec_protocol != NULL) { |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
873 /* Put back user and home */ |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
874 env_put(t_strconcat("USER=", user, NULL)); |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
875 env_put(t_strconcat("HOME=", home, NULL)); |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
876 mail_process_exec(exec_protocol, exec_section); |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
877 } |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
878 |
2311
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
879 open_fds(); |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
880 |
0 | 881 if (!foreground) |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
882 daemonize(settings_root->defaults); |
0 | 883 |
5249
784dc7224718
Removed pool parameter from io_loop_create()
Timo Sirainen <tss@iki.fi>
parents:
5201
diff
changeset
|
884 ioloop = io_loop_create(); |
0 | 885 |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
886 main_init(log_error); |
0 | 887 io_loop_run(ioloop); |
888 main_deinit(); | |
889 | |
1058
3b8fb7bf7ecc
Moved settings parsing to lib-settings.
Timo Sirainen <tss@iki.fi>
parents:
1055
diff
changeset
|
890 master_settings_deinit(); |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
891 io_loop_destroy(&ioloop); |
0 | 892 lib_deinit(); |
893 | |
894 return 0; | |
895 } |