annotate src/stats/main.c @ 22715:20415dd0b85a

dsync: Add per-mailbox sync lock that is always used. Both importing and exporting gets the lock before they even sync the mailbox. The lock is kept until the import/export finishes. This guarantees that no matter how dsync is run, two dsyncs can't be working on the same mailbox at the same time. This lock is in addition to the optional per-user lock enabled by the -l parameter. If the -l parameter is used, the same lock timeout is used for the per-mailbox lock. Otherwise 30s timeout is used. This should help to avoid email duplication when replication is enabled for public namespaces, and maybe in some other rare situations as well.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 28 Dec 2017 14:10:23 +0200
parents cb108f786fb4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21390
diff changeset
1 /* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
18292
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
4 #include "module-dir.h"
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "restrict-access.h"
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "master-service.h"
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "master-service-settings.h"
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "global-memory.h"
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "stats-settings.h"
19711
ce7e31d9ad08 stats: Renamed mail-server-connection to fifo-input-connection.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
10 #include "fifo-input-connection.h"
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "mail-command.h"
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "mail-session.h"
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include "mail-user.h"
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "mail-domain.h"
13350
f77ee6f0c42a stats: Fixed handling IP address stats.
Timo Sirainen <tss@iki.fi>
parents: 13294
diff changeset
15 #include "mail-ip.h"
18068
9c2bcafcf121 stats: Added support for "global" stats type.
Timo Sirainen <tss@iki.fi>
parents: 17414
diff changeset
16 #include "mail-stats.h"
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include "client.h"
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18
18292
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
19 static struct module *modules = NULL;
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 static void client_connected(struct master_service_connection *conn)
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 {
20085
509696de4c0e stats: Support multiple FIFO listeners.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19711
diff changeset
23 if (conn->fifo)
509696de4c0e stats: Support multiple FIFO listeners.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19711
diff changeset
24 (void)fifo_input_connection_create(conn->fd);
509696de4c0e stats: Support multiple FIFO listeners.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19711
diff changeset
25 else
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
26 (void)client_create(conn->fd);
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 master_service_client_connection_accept(conn);
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 }
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
18292
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
30 static void main_preinit(void)
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
31 {
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
32 struct module_dir_load_settings mod_set;
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
33
21389
59437f8764c6 global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 20085
diff changeset
34 i_zero(&mod_set);
18292
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
35 mod_set.abi_version = DOVECOT_ABI_VERSION;
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
36 mod_set.require_init_funcs = TRUE;
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
37
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
38 modules = module_dir_load(STATS_MODULE_DIR, NULL, &mod_set);
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
39 module_dir_init(modules);
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
40
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
41 restrict_access_by_env(NULL, FALSE);
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
42 restrict_access_allow_coredumps(TRUE);
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
43 }
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
44
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 int main(int argc, char *argv[])
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 {
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 const struct setting_parser_info *set_roots[] = {
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 &stats_setting_parser_info,
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 NULL
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 };
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 const enum master_service_flags service_flags =
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 MASTER_SERVICE_FLAG_NO_IDLE_DIE |
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 MASTER_SERVICE_FLAG_UPDATE_PROCTITLE;
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 const char *error;
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 void **sets;
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 master_service = master_service_init("stats", service_flags,
14629
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
58 &argc, &argv, "");
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 if (master_getopt(master_service) > 0)
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 return FATAL_DEFAULT;
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 if (master_service_settings_read_simple(master_service, set_roots,
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 &error) < 0)
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 i_fatal("Error reading configuration: %s", error);
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 master_service_init_log(master_service, "stats: ");
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
18292
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
66 main_preinit();
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 sets = master_service_settings_get_others(master_service);
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 stats_settings = sets[0];
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 mail_commands_init();
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 mail_sessions_init();
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 mail_users_init();
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 mail_domains_init();
13350
f77ee6f0c42a stats: Fixed handling IP address stats.
Timo Sirainen <tss@iki.fi>
parents: 13294
diff changeset
75 mail_ips_init();
18068
9c2bcafcf121 stats: Added support for "global" stats type.
Timo Sirainen <tss@iki.fi>
parents: 17414
diff changeset
76 mail_global_init();
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77
16508
754d244b8249 Call master_service_init_finish() only after all of the initialization is done.
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
78 master_service_init_finish(master_service);
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 master_service_run(master_service, client_connected);
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 clients_destroy_all();
20085
509696de4c0e stats: Support multiple FIFO listeners.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19711
diff changeset
82 fifo_input_connections_destroy_all();
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 mail_commands_deinit();
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 mail_sessions_deinit();
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 mail_users_deinit();
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 mail_domains_deinit();
13350
f77ee6f0c42a stats: Fixed handling IP address stats.
Timo Sirainen <tss@iki.fi>
parents: 13294
diff changeset
87 mail_ips_deinit();
18292
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
88 mail_global_deinit();
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89
18292
a9952ceeac61 stats process/plugin redesign to be more modular.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
90 module_dir_unload(&modules);
13294
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 i_assert(global_used_memory == 0);
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 master_service_deinit(&master_service);
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 return 0;
c51fbe64eae1 Initial implementation of statistics gathering daemon and plugins to feed it.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 }