annotate src/lmtp/main.c @ 10120:b584904d3bc7 HEAD

Moved process title init to lib-master. With Linux-hack enabled it now preserves command args.
author Timo Sirainen <tss@iki.fi>
date Tue, 20 Oct 2009 20:19:05 -0400
parents 1e63221f5c83
children 9c640a1eb8b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "array.h"
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "ioloop.h"
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "restrict-access.h"
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "fd-close-on-exec.h"
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "master-service.h"
10039
ddcc3391adf9 lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents: 9832
diff changeset
9 #include "master-service-settings.h"
9350
7df8fddbc7a5 Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents: 9348
diff changeset
10 #include "master-interface.h"
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "mail-storage-service.h"
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include "lda-settings.h"
10039
ddcc3391adf9 lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents: 9832
diff changeset
13 #include "lmtp-settings.h"
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "client.h"
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include "main.h"
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include <stdlib.h>
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include <unistd.h>
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #define LMTP_MASTER_FIRST_LISTEN_FD 3
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 #define IS_STANDALONE() \
9350
7df8fddbc7a5 Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents: 9348
diff changeset
23 (getenv(MASTER_UID_ENV) == NULL)
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 struct mail_storage_service_multi_ctx *multi_service;
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26
9159
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9121
diff changeset
27 static void client_connected(const struct master_service_connection *conn)
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 {
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 struct client *client;
10039
ddcc3391adf9 lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents: 9832
diff changeset
30 void **sets;
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
9350
7df8fddbc7a5 Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents: 9348
diff changeset
32 client = client_create(conn->fd, conn->fd);
7df8fddbc7a5 Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents: 9348
diff changeset
33 client->remote_ip = conn->remote_ip;
7df8fddbc7a5 Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents: 9348
diff changeset
34 client->remote_port = conn->remote_port;
10039
ddcc3391adf9 lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents: 9832
diff changeset
35
ddcc3391adf9 lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents: 9832
diff changeset
36 sets = master_service_settings_get_others(master_service);
ddcc3391adf9 lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents: 9832
diff changeset
37 client->set = sets[1];
ddcc3391adf9 lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents: 9832
diff changeset
38 client->lmtp_set = sets[2];
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39
9350
7df8fddbc7a5 Fixed LMTP server to actualy work.
Timo Sirainen <tss@iki.fi>
parents: 9348
diff changeset
40 (void)net_getsockname(conn->fd, &client->local_ip, &client->local_port);
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 }
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 static void main_init(void)
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 {
9159
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9121
diff changeset
45 if (IS_STANDALONE())
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 (void)client_create(STDIN_FILENO, STDOUT_FILENO);
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 }
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 static void main_deinit(void)
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 {
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 clients_destroy();
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 }
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53
10120
b584904d3bc7 Moved process title init to lib-master. With Linux-hack enabled it now preserves command args.
Timo Sirainen <tss@iki.fi>
parents: 10119
diff changeset
54 int main(int argc, char *argv[])
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 {
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 const struct setting_parser_info *set_roots[] = {
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 &lda_setting_parser_info,
10039
ddcc3391adf9 lmtp: Added lmtp_proxy setting (it's no longer hardcoded to yes).
Timo Sirainen <tss@iki.fi>
parents: 9832
diff changeset
58 &lmtp_setting_parser_info,
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 NULL
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 };
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 enum master_service_flags service_flags = 0;
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 enum mail_storage_service_flags storage_service_flags =
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 MAIL_STORAGE_SERVICE_FLAG_DISALLOW_ROOT |
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP;
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65
9159
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9121
diff changeset
66 if (IS_STANDALONE()) {
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9121
diff changeset
67 service_flags |= MASTER_SERVICE_FLAG_STANDALONE |
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9121
diff changeset
68 MASTER_SERVICE_FLAG_STD_CLIENT;
6324a79d3ee1 Initial commit for v2.0 master rewrite. Several features are still missing.
Timo Sirainen <tss@iki.fi>
parents: 9121
diff changeset
69 }
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70
10119
1e63221f5c83 Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents: 10039
diff changeset
71 master_service = master_service_init("lmtp", service_flags,
10120
b584904d3bc7 Moved process title init to lib-master. With Linux-hack enabled it now preserves command args.
Timo Sirainen <tss@iki.fi>
parents: 10119
diff changeset
72 &argc, &argv, NULL);
10119
1e63221f5c83 Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents: 10039
diff changeset
73 if (master_getopt(master_service) > 0)
1e63221f5c83 Moved most of getopt() handling to lib-master.
Timo Sirainen <tss@iki.fi>
parents: 10039
diff changeset
74 return FATAL_DEFAULT;
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75
9348
0c587f108916 lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents: 9159
diff changeset
76 multi_service = mail_storage_service_multi_init(master_service,
0c587f108916 lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents: 9159
diff changeset
77 set_roots,
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 storage_service_flags);
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 restrict_access_allow_coredumps(TRUE);
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 main_init();
9348
0c587f108916 lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents: 9159
diff changeset
82 master_service_run(master_service, client_connected);
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 main_deinit();
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 mail_storage_service_multi_deinit(&multi_service);
9348
0c587f108916 lib-master has now a global master_service variable that all binaries use.
Timo Sirainen <tss@iki.fi>
parents: 9159
diff changeset
86 master_service_deinit(&master_service);
9121
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 return 0;
a957a6be4af5 Initial implementation of LMTP server. Master process doesn't yet execute it though.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 }