Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/master/main.c @ 9528:142c935e44d6 HEAD
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 22 Jan 2010 18:58:51 +0200 |
parents | 0f04c7da33f1 |
children | 3237519b73f4 |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8354
diff
changeset
|
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "common.h" | |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
4 #include "array.h" |
0 | 5 #include "ioloop.h" |
6 #include "lib-signals.h" | |
7 #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
|
8 #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
|
9 #include "fd-close-on-exec.h" |
2524 | 10 #include "write-full.h" |
6313
0e08960275f8
Grow file descriptors to 64k at startup, and drop them for login and imap
Timo Sirainen <tss@iki.fi>
parents:
6303
diff
changeset
|
11 #include "restrict-process-size.h" |
0 | 12 |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
13 #include "askpass.h" |
0 | 14 #include "auth-process.h" |
5789
4f22660ffd33
Move POSIX capabilities dropping into separate function.
Andrey Panin <pazke@donpac.ru>
parents:
5696
diff
changeset
|
15 #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
|
16 #include "dict-process.h" |
0 | 17 #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
|
18 #include "mail-process.h" |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
19 #include "syslog-util.h" |
5936 | 20 #include "listener.h" |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
21 #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
|
22 #include "log.h" |
8354
5339d2ebeb56
dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
8323
diff
changeset
|
23 #include "sysinfo-get.h" |
8595
829b6555392b
master: When receiving SIGHUP, get the hostname again in case it changed.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
24 #include "hostpid.h" |
0 | 25 |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
26 #include <stdio.h> |
0 | 27 #include <stdlib.h> |
28 #include <unistd.h> | |
29 #include <fcntl.h> | |
30 #include <syslog.h> | |
31 #include <sys/stat.h> | |
32 | |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
33 #define FATAL_FILENAME "master-fatal.lastlog" |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
34 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
35 static const char *configfile = SYSCONFDIR "/" PACKAGE ".conf"; |
8323
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
36 static pid_t master_original_pid; |
0 | 37 |
1000
0fbafade2d85
If auth/login process died unexpectedly, the exit status or killing signal
Timo Sirainen <tss@iki.fi>
parents:
945
diff
changeset
|
38 struct ioloop *ioloop; |
5432
2b4fa90860dd
Before unlinking auth sockets at startup, try connecting to them first to
Timo Sirainen <tss@iki.fi>
parents:
5333
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 char ssl_manual_key_password[100]; |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5824
diff
changeset
|
43 const char *env_tz; |
8301
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
44 bool auth_success_written; |
8798
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8782
diff
changeset
|
45 bool core_dumps_disabled; |
2235
dcff4c088f1a
DEBUG: If GDB environment is set, don't do fd leak checks.
Timo Sirainen <tss@iki.fi>
parents:
2047
diff
changeset
|
46 #ifdef DEBUG |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5824
diff
changeset
|
47 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
|
48 #endif |
0 | 49 |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
50 static void ATTR_NORETURN ATTR_FORMAT(3, 0) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
51 master_fatal_callback(enum log_type type, int status, |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
52 const char *format, va_list args) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
53 { |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
54 const struct settings *set = settings_root->defaults; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
55 const char *path, *str; |
7351
6115fe69094c
Fatals/panics logged by master weren't logged properly.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
56 va_list args2; |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
57 int fd; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
58 |
8323
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
59 /* if we already forked a child process, this isn't fatal for the |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
60 main process and there's no need to write the fatal file. */ |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
61 if (getpid() == master_original_pid) { |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
62 /* write the error message to a file */ |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
63 path = t_strconcat(set->base_dir, "/"FATAL_FILENAME, NULL); |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
64 fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600); |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
65 if (fd != -1) { |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
66 VA_COPY(args2, args); |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
67 str = t_strdup_vprintf(format, args2); |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
68 write_full(fd, str, strlen(str)); |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
69 (void)close(fd); |
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
70 } |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
71 } |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
72 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
73 /* write it to log as well */ |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
74 if (*set->log_path == '\0') |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
75 i_syslog_fatal_handler(type, status, format, args); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
76 else |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
77 default_fatal_handler(type, status, format, args); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
78 } |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
79 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
80 static void fatal_log_check(void) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
81 { |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
82 const struct settings *set = settings_root->defaults; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
83 const char *path; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
84 char buf[1024]; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
85 ssize_t ret; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
86 int fd; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
87 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
88 path = t_strconcat(set->base_dir, "/"FATAL_FILENAME, NULL); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
89 fd = open(path, O_RDONLY); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
90 if (fd == -1) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
91 return; |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
92 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
93 ret = read(fd, buf, sizeof(buf)); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
94 if (ret < 0) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
95 i_error("read(%s) failed: %m", path); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
96 else { |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
97 buf[ret] = '\0'; |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
98 fprintf(stderr, "Last died with error (see error log for more " |
9379
a493ceb26615
master: Startup warnings written to stderr should end with LF.
Timo Sirainen <tss@iki.fi>
parents:
9370
diff
changeset
|
99 "information): %s\n", buf); |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
100 } |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
101 |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
102 close(fd); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
103 if (unlink(path) < 0) |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
104 i_error("unlink(%s) failed: %m", path); |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
105 } |
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
106 |
8305
e4d0ce4d3420
Don't show the WhyDoesItNotWork link if auth_debug=yes already.
Timo Sirainen <tss@iki.fi>
parents:
8301
diff
changeset
|
107 static void auth_warning_print(const struct server_settings *set) |
8301
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
108 { |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
109 struct stat st; |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
110 |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
111 auth_success_written = stat(AUTH_SUCCESS_PATH, &st) == 0; |
8305
e4d0ce4d3420
Don't show the WhyDoesItNotWork link if auth_debug=yes already.
Timo Sirainen <tss@iki.fi>
parents:
8301
diff
changeset
|
112 if (!auth_success_written && !set->auths->debug && |
e4d0ce4d3420
Don't show the WhyDoesItNotWork link if auth_debug=yes already.
Timo Sirainen <tss@iki.fi>
parents:
8301
diff
changeset
|
113 strcmp(set->defaults->protocols, "none") != 0) { |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
114 fprintf(stderr, |
9356
7639914c5cde
master: Changed the WhyDoesItNotWork info message.
Timo Sirainen <tss@iki.fi>
parents:
9064
diff
changeset
|
115 "If you have trouble with authentication failures,\n" |
7639914c5cde
master: Changed the WhyDoesItNotWork info message.
Timo Sirainen <tss@iki.fi>
parents:
9064
diff
changeset
|
116 "enable auth_debug setting. See http://wiki.dovecot.org/WhyDoesItNotWork\n" |
9379
a493ceb26615
master: Startup warnings written to stderr should end with LF.
Timo Sirainen <tss@iki.fi>
parents:
9370
diff
changeset
|
117 "This message goes away after the first successful login.\n"); |
8301
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
118 } |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
119 } |
d46579bb7a3c
Print a help message about authentication at startup until the first successful authentication.
Timo Sirainen <tss@iki.fi>
parents:
8062
diff
changeset
|
120 |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
121 static void set_logfile(struct settings *set) |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
122 { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
123 int facility; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
124 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
125 if (*set->log_path == '\0') { |
3724
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
126 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
|
127 facility = LOG_MAIL; |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
128 |
d22c883021da
Added syslog_facility setting to config file.
Timo Sirainen <tss@iki.fi>
parents:
3620
diff
changeset
|
129 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
|
130 } else { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
131 /* 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
|
132 i_set_failure_file(set->log_path, "dovecot: "); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
133 } |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
134 i_set_fatal_handler(master_fatal_callback); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
135 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
136 if (*set->info_log_path != '\0') |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
137 i_set_info_file(set->info_log_path); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
138 |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
139 i_set_failure_timestamp_format(set->log_timestamp); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
140 } |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
141 |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
142 static void ATTR_NORETURN |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
143 tee_fatal_handler(enum log_type type, int status, const char *fmt, va_list args) |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
144 { |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
145 const struct settings *set = settings_root->defaults; |
9370
5f9782109fcf
master: Startup errors crashed on some systems.
Timo Sirainen <tss@iki.fi>
parents:
9369
diff
changeset
|
146 va_list args2; |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
147 |
9370
5f9782109fcf
master: Startup errors crashed on some systems.
Timo Sirainen <tss@iki.fi>
parents:
9369
diff
changeset
|
148 VA_COPY(args2, args); |
5f9782109fcf
master: Startup errors crashed on some systems.
Timo Sirainen <tss@iki.fi>
parents:
9369
diff
changeset
|
149 fprintf(stderr, "Fatal: %s\n", t_strdup_vprintf(fmt, args2)); |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
150 |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
151 if (*set->log_path == '\0') { |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
152 i_syslog_fatal_handler(type, status, fmt, args); |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
153 } else { |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
154 default_fatal_handler(type, status, fmt, args); |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
155 } |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
156 } |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
157 |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
158 static void |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
159 tee_error_handler(enum log_type type, const char *fmt, va_list args) |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
160 { |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
161 const struct settings *set = settings_root->defaults; |
9370
5f9782109fcf
master: Startup errors crashed on some systems.
Timo Sirainen <tss@iki.fi>
parents:
9369
diff
changeset
|
162 va_list args2; |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
163 |
9370
5f9782109fcf
master: Startup errors crashed on some systems.
Timo Sirainen <tss@iki.fi>
parents:
9369
diff
changeset
|
164 VA_COPY(args2, args); |
5f9782109fcf
master: Startup errors crashed on some systems.
Timo Sirainen <tss@iki.fi>
parents:
9369
diff
changeset
|
165 fprintf(stderr, "Error: %s\n", t_strdup_vprintf(fmt, args2)); |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
166 |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
167 if (*set->log_path == '\0') { |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
168 i_syslog_error_handler(type, fmt, args); |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
169 } else { |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
170 default_error_handler(type, fmt, args); |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
171 } |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
172 } |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
173 |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
174 static void set_tee_logfile(struct settings *set) |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
175 { |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
176 set_logfile(set); |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
177 |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
178 i_set_fatal_handler(tee_fatal_handler); |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
179 i_set_error_handler(tee_error_handler); |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
180 } |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
181 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
182 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
|
183 { |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
184 struct server_settings *old_set = settings_root; |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
185 |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
186 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
|
187 |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
188 /* restart auth and login processes */ |
4670 | 189 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
|
190 auth_processes_destroy_all(); |
8649
67c08c386702
Added dict_process_count setting for creating multiple dict processes.
Timo Sirainen <tss@iki.fi>
parents:
8595
diff
changeset
|
191 dict_processes_kill(); |
1223
52e0830ade13
Added setting mail_drop_priv_before_exec.
Timo Sirainen <tss@iki.fi>
parents:
1124
diff
changeset
|
192 |
8595
829b6555392b
master: When receiving SIGHUP, get the hostname again in case it changed.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
193 /* see if hostname changed */ |
829b6555392b
master: When receiving SIGHUP, get the hostname again in case it changed.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
194 hostpid_init(); |
829b6555392b
master: When receiving SIGHUP, get the hostname again in case it changed.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
195 |
9528
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
196 if (!master_settings_read(configfile, FALSE, 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
|
197 i_warning("Invalid configuration, keeping old one"); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
198 else { |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
199 if (!IS_INETD()) |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
200 listeners_open_fds(old_set, TRUE); |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
201 set_logfile(settings_root->defaults); |
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
202 } |
635
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
203 } |
90a65c017bf0
SIGHUP reloads now settings. Logged in clients are left untouched, but
Timo Sirainen <tss@iki.fi>
parents:
615
diff
changeset
|
204 |
8882
9f3968f49ceb
lib-signals: Changed callback API to return siginfo_t.
Timo Sirainen <tss@iki.fi>
parents:
8798
diff
changeset
|
205 static void sig_die(const siginfo_t *si, void *context ATTR_UNUSED) |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
206 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
207 /* 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
|
208 which is too common at least while testing :) */ |
8883
5361cb6afe9e
When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
209 if (si->si_signo != SIGINT) { |
5361cb6afe9e
When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
210 i_warning("Killed with signal %d (by pid=%s uid=%s code=%s)", |
5361cb6afe9e
When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
211 si->si_signo, dec2str(si->si_pid), |
5361cb6afe9e
When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
212 dec2str(si->si_uid), |
5361cb6afe9e
When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
213 lib_signal_code_to_str(si->si_signo, si->si_code)); |
5361cb6afe9e
When a process is killed, show the signal code and the sending process's pid and uid.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
214 } |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
215 io_loop_stop(ioloop); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
216 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
217 |
8882
9f3968f49ceb
lib-signals: Changed callback API to return siginfo_t.
Timo Sirainen <tss@iki.fi>
parents:
8798
diff
changeset
|
218 static void sig_reload_settings(const siginfo_t *si ATTR_UNUSED, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6397
diff
changeset
|
219 void *context ATTR_UNUSED) |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
220 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
221 settings_reload(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
222 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
223 |
8882
9f3968f49ceb
lib-signals: Changed callback API to return siginfo_t.
Timo Sirainen <tss@iki.fi>
parents:
8798
diff
changeset
|
224 static void sig_reopen_logs(const siginfo_t *si ATTR_UNUSED, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6397
diff
changeset
|
225 void *context ATTR_UNUSED) |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
226 { |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
227 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
|
228 } |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
229 |
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
|
230 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
|
231 { |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
232 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
|
233 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
|
234 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
235 |
4388
af61031c746f
Settings parser nowadays returns "" instead of NULL when it reads an empty
Timo Sirainen <tss@iki.fi>
parents:
4375
diff
changeset
|
236 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
|
237 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
|
238 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
239 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
240 return FALSE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
241 } |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
242 |
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
|
243 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
|
244 { |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
245 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
|
246 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
|
247 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
248 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
|
249 return TRUE; |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
250 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
251 server = server->next; |
1055
a72bba3f8a55
Rewrote setting handling. Changed some existing settings also since POP3
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
252 } |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
253 |
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
254 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
|
255 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
256 |
5437 | 257 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
|
258 { |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 fd_close_on_exec(null_fd, TRUE); |
5437 | 263 } |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
264 |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
265 static void open_std_fds(void) |
5437 | 266 { |
1273
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
267 /* 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
|
268 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
|
269 null_fd = dup(null_fd); |
4578
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
270 if (null_fd == -1) |
3bb3d5ad254f
Cleanup + handle dup() failure.
Timo Sirainen <tss@iki.fi>
parents:
4553
diff
changeset
|
271 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
|
272 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
|
273 } |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
274 |
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
|
275 /* close stdin and stdout. */ |
1124
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
276 if (dup2(null_fd, 0) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
277 i_fatal("dup2(0) failed: %m"); |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
278 if (dup2(null_fd, 1) < 0) |
5e9430a39611
/dev/stderr works now in log paths.
Timo Sirainen <tss@iki.fi>
parents:
1100
diff
changeset
|
279 i_fatal("dup2(1) failed: %m"); |
0 | 280 } |
281 | |
2524 | 282 static void create_pid_file(const char *path) |
283 { | |
284 const char *pid; | |
285 int fd; | |
286 | |
2534 | 287 pid = t_strconcat(dec2str(getpid()), "\n", NULL); |
2524 | 288 |
289 fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0644); | |
290 if (fd == -1) | |
291 i_fatal("open(%s) failed: %m", path); | |
292 if (write_full(fd, pid, strlen(pid)) < 0) | |
293 i_fatal("write() failed in %s: %m", path); | |
294 (void)close(fd); | |
295 } | |
296 | |
7946
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
297 static void main_log_startup(void) |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
298 { |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
299 #define STARTUP_STRING PACKAGE_NAME" v"VERSION" starting up" |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
300 rlim_t core_limit; |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
301 |
8798
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8782
diff
changeset
|
302 core_dumps_disabled = restrict_get_core_limit(&core_limit) == 0 && |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8782
diff
changeset
|
303 core_limit == 0; |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8782
diff
changeset
|
304 if (core_dumps_disabled) |
7946
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
305 i_info(STARTUP_STRING" (core dumps disabled)"); |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
306 else |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
307 i_info(STARTUP_STRING); |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
308 } |
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
309 |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
310 static void main_init(bool log_error) |
0 | 311 { |
9528
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
312 const char *base_config_path; |
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
313 |
5824
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
314 drop_capabilities(); |
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
315 |
0 | 316 /* deny file access from everyone else except owner */ |
317 (void)umask(0077); | |
318 | |
5824
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
319 set_logfile(settings_root->defaults); |
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
320 /* 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
|
321 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
|
322 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
|
323 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
|
324 } |
2306
6aa77fdf152e
SIGHUP correctly reloads configuration now
Timo Sirainen <tss@iki.fi>
parents:
2235
diff
changeset
|
325 |
5696
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
326 if (log_error) { |
6303 | 327 printf("Writing to error logs and killing myself..\n"); |
328 i_info("This is Dovecot's info log"); | |
5696
b929827ddbe9
When using --log-error, log also a warning and an error.
Timo Sirainen <tss@iki.fi>
parents:
5639
diff
changeset
|
329 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
|
330 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
|
331 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
|
332 } |
7946
aad49536db41
If core dump limit is 0, add "core dumps disabled" to startup log line.
Timo Sirainen <tss@iki.fi>
parents:
7914
diff
changeset
|
333 main_log_startup(); |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
334 |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
335 lib_signals_init(); |
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 lib_signals_set_handler(SIGUSR1, TRUE, sig_reopen_logs, NULL); |
0 | 342 |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5824
diff
changeset
|
343 child_processes_init(); |
5824
5d0aa827f130
Reordered initialization code. Capabilities are now dropped as soon as
root@hurina
parents:
5789
diff
changeset
|
344 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
|
345 ssl_init(); |
8649
67c08c386702
Added dict_process_count setting for creating multiple dict processes.
Timo Sirainen <tss@iki.fi>
parents:
8595
diff
changeset
|
346 dict_processes_init(); |
0 | 347 auth_processes_init(); |
348 login_processes_init(); | |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
5824
diff
changeset
|
349 mail_processes_init(); |
2524 | 350 |
351 create_pid_file(t_strconcat(settings_root->defaults->base_dir, | |
352 "/master.pid", NULL)); | |
9528
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
353 base_config_path = t_strconcat(settings_root->defaults->base_dir, |
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
354 "/"PACKAGE".conf", NULL); |
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
355 (void)unlink(base_config_path); |
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
356 if (symlink(configfile, base_config_path) < 0) { |
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
357 i_error("symlink(%s, %s) failed: %m", |
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
358 configfile, base_config_path); |
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
359 } |
0 | 360 } |
361 | |
362 static void main_deinit(void) | |
363 { | |
2524 | 364 (void)unlink(t_strconcat(settings_root->defaults->base_dir, |
365 "/master.pid", NULL)); | |
366 | |
5846
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5844
diff
changeset
|
367 login_processes_destroy_all(); |
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5844
diff
changeset
|
368 |
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5844
diff
changeset
|
369 mail_processes_deinit(); |
0 | 370 login_processes_deinit(); |
371 auth_processes_deinit(); | |
8649
67c08c386702
Added dict_process_count setting for creating multiple dict processes.
Timo Sirainen <tss@iki.fi>
parents:
8595
diff
changeset
|
372 dict_processes_deinit(); |
615
0d852af6842e
Master process generates DH/RSA parameters now and stores them into file
Timo Sirainen <tss@iki.fi>
parents:
610
diff
changeset
|
373 ssl_deinit(); |
0 | 374 |
5887
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
375 listeners_close_fds(); |
3f2eb1b9c555
Support listening multiple sockets. SIGHUP also doesn't anymore recreate
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
376 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
801
diff
changeset
|
377 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
|
378 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
|
379 |
8699
035037f388fa
master: Don't crash at quit if there is some unwritten data in logs.
Timo Sirainen <tss@iki.fi>
parents:
8649
diff
changeset
|
380 log_deinit(); |
035037f388fa
master: Don't crash at quit if there is some unwritten data in logs.
Timo Sirainen <tss@iki.fi>
parents:
8649
diff
changeset
|
381 /* log_deinit() may still want to look up child processes */ |
035037f388fa
master: Don't crash at quit if there is some unwritten data in logs.
Timo Sirainen <tss@iki.fi>
parents:
8649
diff
changeset
|
382 child_processes_deinit(); |
3620
3360cc019737
Implemented new signal handling framework, which makes handling signals much
Timo Sirainen <tss@iki.fi>
parents:
3589
diff
changeset
|
383 lib_signals_deinit(); |
0 | 384 closelog(); |
385 } | |
386 | |
1610
6850142c4e25
New configuration file code. Some syntax changes, but tries to be somewhat
Timo Sirainen <tss@iki.fi>
parents:
1423
diff
changeset
|
387 static void daemonize(struct settings *set) |
0 | 388 { |
389 pid_t pid; | |
390 | |
391 pid = fork(); | |
392 if (pid < 0) | |
393 i_fatal("fork() failed: %m"); | |
394 | |
395 if (pid != 0) | |
396 _exit(0); | |
610 | 397 |
801
86224ff16bf6
Drop root privileges earlier. Close syslog more later in imap-master when
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
398 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
|
399 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
|
400 |
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
|
401 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
|
402 i_fatal("chdir(%s) failed: %m", set->base_dir); |
0 | 403 } |
404 | |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
405 static void print_help(void) |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
406 { |
3917
ae292bd41926
Added --build-ssl-parameters option to build them.
Timo Sirainen <tss@iki.fi>
parents:
3901
diff
changeset
|
407 printf( |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
408 "Usage: dovecot [-F] [-c <config file>] [-p] [-n] [-a]\n" |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
409 " [--version] [--build-options] [--exec-mail <protocol> [<args>]]\n"); |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
410 } |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
411 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
412 static void print_build_options(void) |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
413 { |
8782
e5cc81734221
Compile fix for systems where printf() is a macro.
Timo Sirainen <tss@iki.fi>
parents:
8699
diff
changeset
|
414 static const char *build_options = |
e5cc81734221
Compile fix for systems where printf() is a macro.
Timo Sirainen <tss@iki.fi>
parents:
8699
diff
changeset
|
415 "Build options:" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
416 #ifdef IOLOOP_EPOLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
417 " ioloop=epoll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
418 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
419 #ifdef IOLOOP_KQUEUE |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
420 " ioloop=kqueue" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
421 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
422 #ifdef IOLOOP_POLL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
423 " ioloop=poll" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
424 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
425 #ifdef IOLOOP_SELECT |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
426 " ioloop=select" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
427 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
428 #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
|
429 " notify=dnotify" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
430 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
431 #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
|
432 " notify=inotify" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
433 #endif |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
434 #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
|
435 " notify=kqueue" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
436 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
437 #ifdef HAVE_IPV6 |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
438 " ipv6" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
439 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
440 #ifdef HAVE_GNUTLS |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
441 " gnutls" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
442 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
443 #ifdef HAVE_OPENSSL |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
444 " openssl" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
445 #endif |
6635
e4f9e2b94a90
Show mail storages in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
446 "\nMail storages: "MAIL_STORAGES"\n" |
9064
d936c8e243dd
dovecot --build-options: If SQL or LDAP was built as plugins, say it.
Timo Sirainen <tss@iki.fi>
parents:
8977
diff
changeset
|
447 #ifdef SQL_DRIVER_PLUGINS |
d936c8e243dd
dovecot --build-options: If SQL or LDAP was built as plugins, say it.
Timo Sirainen <tss@iki.fi>
parents:
8977
diff
changeset
|
448 "SQL driver plugins:" |
d936c8e243dd
dovecot --build-options: If SQL or LDAP was built as plugins, say it.
Timo Sirainen <tss@iki.fi>
parents:
8977
diff
changeset
|
449 #else |
6635
e4f9e2b94a90
Show mail storages in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
450 "SQL drivers:" |
9064
d936c8e243dd
dovecot --build-options: If SQL or LDAP was built as plugins, say it.
Timo Sirainen <tss@iki.fi>
parents:
8977
diff
changeset
|
451 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
452 #ifdef BUILD_MYSQL |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
453 " mysql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
454 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
455 #ifdef BUILD_PGSQL |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
456 " postgresql" |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
457 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
458 #ifdef BUILD_SQLITE |
3919
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
459 " sqlite" |
b967ffb7e3a6
SQLite support. Patch by Jakob Hirsch.
Timo Sirainen <tss@iki.fi>
parents:
3917
diff
changeset
|
460 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
461 "\nPassdb:" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
462 #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
|
463 " bsdauth" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
464 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
465 #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
|
466 " checkpassword" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
467 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
468 #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
|
469 " ldap" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
470 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
471 #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
|
472 " pam" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
473 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
474 #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
|
475 " passwd" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
476 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
477 #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
|
478 " passwd-file" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
479 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
480 #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
|
481 " shadow" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
482 #endif |
6893
a9daec3c00b5
--build-options didn't list "sia" in passdbs.
Timo Sirainen <tss@iki.fi>
parents:
6635
diff
changeset
|
483 #ifdef PASSDB_SIA |
a9daec3c00b5
--build-options didn't list "sia" in passdbs.
Timo Sirainen <tss@iki.fi>
parents:
6635
diff
changeset
|
484 " sia" |
a9daec3c00b5
--build-options didn't list "sia" in passdbs.
Timo Sirainen <tss@iki.fi>
parents:
6635
diff
changeset
|
485 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
486 #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
|
487 " sql" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
488 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
489 #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
|
490 " vpopmail" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
491 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
492 "\nUserdb:" |
7947
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
493 #ifdef USERDB_NSS |
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
494 " nss" |
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
495 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
496 #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
|
497 " ldap" |
9064
d936c8e243dd
dovecot --build-options: If SQL or LDAP was built as plugins, say it.
Timo Sirainen <tss@iki.fi>
parents:
8977
diff
changeset
|
498 #ifndef BUILTIN_LDAP |
d936c8e243dd
dovecot --build-options: If SQL or LDAP was built as plugins, say it.
Timo Sirainen <tss@iki.fi>
parents:
8977
diff
changeset
|
499 "(plugin)" |
d936c8e243dd
dovecot --build-options: If SQL or LDAP was built as plugins, say it.
Timo Sirainen <tss@iki.fi>
parents:
8977
diff
changeset
|
500 #endif |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
501 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
502 #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
|
503 " passwd" |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
504 #endif |
7947
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
505 #ifdef USERDB_PASSWD_FILE |
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
506 " passwd-file" |
cd2789afcb09
Include "nss" in dovecot --build-options.
Timo Sirainen <tss@iki.fi>
parents:
7946
diff
changeset
|
507 #endif |
4475
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
508 #ifdef USERDB_PREFETCH |
3a3ef25c62ab
List -n and -a in short help. Fixes to --build-options.
Timo Sirainen <tss@iki.fi>
parents:
4464
diff
changeset
|
509 " prefetch" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
510 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
511 #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
|
512 " sql" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
513 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
514 #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
|
515 " static" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
516 #endif |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
517 #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
|
518 " vpopmail" |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
519 #endif |
8782
e5cc81734221
Compile fix for systems where printf() is a macro.
Timo Sirainen <tss@iki.fi>
parents:
8699
diff
changeset
|
520 "\n"; |
e5cc81734221
Compile fix for systems where printf() is a macro.
Timo Sirainen <tss@iki.fi>
parents:
8699
diff
changeset
|
521 puts(build_options); |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
522 } |
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
523 |
0 | 524 int main(int argc, char *argv[]) |
525 { | |
526 /* parse arguments */ | |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
527 const char *exec_protocol = NULL, **exec_args = NULL, *user, *home; |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
528 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
|
529 bool dump_config = FALSE, dump_config_nondefaults = FALSE; |
9528
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
530 bool config_path_given = FALSE; |
0 | 531 int i; |
532 | |
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
|
533 #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
|
534 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
|
535 #endif |
0 | 536 lib_init(); |
537 | |
1617
cc3cef25662c
Replaced geteuid() calls with one in the beginning and saving it to
Timo Sirainen <tss@iki.fi>
parents:
1610
diff
changeset
|
538 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
|
539 inetd_login_fd = -1; |
0 | 540 for (i = 1; i < argc; i++) { |
541 if (strcmp(argv[i], "-F") == 0) { | |
542 /* foreground */ | |
543 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
|
544 } 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
|
545 dump_config = TRUE; |
0 | 546 } else if (strcmp(argv[i], "-c") == 0) { |
547 /* config file */ | |
548 i++; | |
549 if (i == argc) i_fatal("Missing config file argument"); | |
550 configfile = argv[i]; | |
9528
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
551 config_path_given = 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
|
552 } 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
|
553 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
|
554 } 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
|
555 /* 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
|
556 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
|
557 } else if (strcmp(argv[i], "--exec-mail") == 0) { |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
558 /* <protocol> [<args>] |
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
|
559 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
|
560 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
|
561 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
|
562 exec_protocol = argv[i]; |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
563 exec_args = (const char **)&argv[i+1]; |
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
564 break; |
1260 | 565 } else if (strcmp(argv[i], "--version") == 0) { |
566 printf("%s\n", VERSION); | |
567 return 0; | |
3589
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
568 } 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
|
569 print_build_options(); |
fead84acb13c
Added --build-options parameter. Patch by Andrey Panin
Timo Sirainen <tss@iki.fi>
parents:
3535
diff
changeset
|
570 return 0; |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
571 } else if (strcmp(argv[i], "--log-error") == 0) { |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
572 log_error = TRUE; |
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
573 foreground = TRUE; |
0 | 574 } else { |
279
49f4b0be0d87
Print usage with invalid parameters.
Timo Sirainen <tss@iki.fi>
parents:
50
diff
changeset
|
575 print_help(); |
8977
59a3130bd4ed
master: "Unknown argument" error printed always the first argument instead of the unknown one.
Timo Sirainen <tss@iki.fi>
parents:
8965
diff
changeset
|
576 i_fatal("Unknown argument: %s", argv[i]); |
0 | 577 } |
578 } | |
579 | |
5437 | 580 /* need to have this open before reading settings */ |
581 open_null_fd(); | |
582 | |
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
|
583 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
|
584 /* 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
|
585 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
|
586 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
|
587 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
|
588 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
|
589 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
|
590 } |
4558d1b196fd
Added --exec-mail option to master. It can be used to parse Dovecot config
Timo Sirainen <tss@iki.fi>
parents:
2306
diff
changeset
|
591 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
592 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
|
593 /* 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
|
594 of errors it's still shown */ |
5589
271c35971331
Print also Dovecot version with dovecot -n.
Timo Sirainen <tss@iki.fi>
parents:
5437
diff
changeset
|
595 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
|
596 } |
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
|
597 |
0 | 598 /* read and verify settings before forking */ |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
599 T_BEGIN { |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
600 master_settings_init(); |
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
601 if (!master_settings_read(configfile, exec_protocol != NULL, |
9528
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
602 dump_config || log_error, |
142c935e44d6
dovecot -a|-n: Log a warning if Dovecot was last started using a different config file.
Timo Sirainen <tss@iki.fi>
parents:
9386
diff
changeset
|
603 !config_path_given)) |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6893
diff
changeset
|
604 i_fatal("Invalid configuration in %s", configfile); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
605 } T_END; |
0 | 606 |
4965
9246d9308caa
-n and -a parameters shouldn't be deleting auth sockets.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
607 if (dump_config) { |
8354
5339d2ebeb56
dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
8323
diff
changeset
|
608 const char *info; |
5339d2ebeb56
dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
8323
diff
changeset
|
609 |
5339d2ebeb56
dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
8323
diff
changeset
|
610 info = sysinfo_get(settings_root->defaults->mail_location); |
5339d2ebeb56
dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
8323
diff
changeset
|
611 if (*info != '\0') |
5339d2ebeb56
dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
8323
diff
changeset
|
612 printf("# %s\n", info); |
5339d2ebeb56
dovecot -n/-a: Print some information about the system.
Timo Sirainen <tss@iki.fi>
parents:
8323
diff
changeset
|
613 |
4138
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
614 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
|
615 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
|
616 } |
f9a6381adbe3
Added -a and -n parameters to dovecot to dump all/nondefault settings. A
Timo Sirainen <tss@iki.fi>
parents:
3989
diff
changeset
|
617 |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
618 if (ask_key_pass) T_BEGIN { |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
619 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
|
620 |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
621 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
|
622 "%s: ", |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
623 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
|
624 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
|
625 sizeof(ssl_manual_key_password)); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
626 } T_END; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
627 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
628 /* 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
|
629 correctly. */ |
3516
71b0ccba8cf3
Preserve TZ environment to child processes so timezones aren't lost with
Timo Sirainen <tss@iki.fi>
parents:
3181
diff
changeset
|
630 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
|
631 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
|
632 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
|
633 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
634 /* 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
|
635 env_clean(); |
2cf2e08a6ee9
Somewhat working code to support loading Dovecot from inetd and such. It
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
636 |
3535
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
637 /* put back the TZ */ |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
638 if (env_tz != NULL) |
08b3e3fd0bc5
The master process itself also needs the TZ environment
Timo Sirainen <tss@iki.fi>
parents:
3516
diff
changeset
|
639 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
|
640 |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
641 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
|
642 /* 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
|
643 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
|
644 env_put(t_strconcat("HOME=", home, NULL)); |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7229
diff
changeset
|
645 mail_process_exec(exec_protocol, exec_args); |
3897
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
646 } |
9dc2f8f0eb59
When starting with --exec-mail, keep USER and HOME environments and clear
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
647 |
9386
0f04c7da33f1
dovecot --exec-mail was broken.
Timo Sirainen <tss@iki.fi>
parents:
9379
diff
changeset
|
648 /* closes stdin/stdout, must be after --exec-mail handling */ |
0f04c7da33f1
dovecot --exec-mail was broken.
Timo Sirainen <tss@iki.fi>
parents:
9379
diff
changeset
|
649 open_std_fds(); |
0f04c7da33f1
dovecot --exec-mail was broken.
Timo Sirainen <tss@iki.fi>
parents:
9379
diff
changeset
|
650 |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
651 /* log all errors to both stderr and log file until we've finished |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
652 startup. */ |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
653 set_tee_logfile(settings_root->defaults); |
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
|
654 |
7229
586abf9b561c
If Dovecot master dies with a fatal failure, log the error message to a file
Timo Sirainen <tss@iki.fi>
parents:
7226
diff
changeset
|
655 fatal_log_check(); |
8305
e4d0ce4d3420
Don't show the WhyDoesItNotWork link if auth_debug=yes already.
Timo Sirainen <tss@iki.fi>
parents:
8301
diff
changeset
|
656 auth_warning_print(settings_root); |
9367
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
657 |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
658 if (!log_error && !IS_INETD()) T_BEGIN { |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
659 listeners_open_fds(NULL, FALSE); |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
660 } T_END; |
eb4ea59e4657
master: Log startup errors as well as writing them to stderr.
Timo Sirainen <tss@iki.fi>
parents:
9356
diff
changeset
|
661 |
0 | 662 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
|
663 daemonize(settings_root->defaults); |
8323
60c48789841b
master: Don't print "last died with error .." for fatals that were from forked child processes.
Timo Sirainen <tss@iki.fi>
parents:
8305
diff
changeset
|
664 master_original_pid = getpid(); |
0 | 665 |
5249
784dc7224718
Removed pool parameter from io_loop_create()
Timo Sirainen <tss@iki.fi>
parents:
5201
diff
changeset
|
666 ioloop = io_loop_create(); |
0 | 667 |
5090
04b467f23400
Added --log-error command line option.
Timo Sirainen <tss@iki.fi>
parents:
5077
diff
changeset
|
668 main_init(log_error); |
0 | 669 io_loop_run(ioloop); |
670 main_deinit(); | |
671 | |
1058
3b8fb7bf7ecc
Moved settings parsing to lib-settings.
Timo Sirainen <tss@iki.fi>
parents:
1055
diff
changeset
|
672 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
|
673 io_loop_destroy(&ioloop); |
0 | 674 lib_deinit(); |
675 | |
676 return 0; | |
677 } |