annotate src/master/dict-process.c @ 7561:1a58b18652a6 HEAD

Avoid using shadow variables. Unfortunately -Wshadow also complains about index variable conflicting with index(), which is used in way too many places to change.
author Timo Sirainen <tss@iki.fi>
date Tue, 27 May 2008 02:09:47 +0300
parents 768231eb84cf
children ec83f6dcb585
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7086
7ed926ed7aa4 Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents: 6869
diff changeset
1 /* Copyright (c) 2006-2008 Dovecot authors, see the included COPYING file */
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
4 #include "array.h"
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "ioloop.h"
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "network.h"
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "fd-close-on-exec.h"
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "env-util.h"
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 #include "log.h"
5843
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
10 #include "child-process.h"
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "dict-process.h"
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 #include <syslog.h>
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include <unistd.h>
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include <sys/stat.h>
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
3885
b624b687fe13 Create dict-server socket to base_dir.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
17 #define DICT_SERVER_SOCKET_NAME "dict-server"
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 struct dict_process {
5843
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
20 struct child_process process;
3885
b624b687fe13 Create dict-server socket to base_dir.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
21 char *path;
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 int fd;
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
23
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
24 struct log_io *log;
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 struct io *io;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 };
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
7561
1a58b18652a6 Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents: 7481
diff changeset
28 static struct dict_process *dict_process;
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 static void dict_process_unlisten(struct dict_process *process);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 static int dict_process_start(struct dict_process *process)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 struct log_io *log;
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
35 const char *executable, *const *dicts;
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
36 unsigned int i, count;
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
37 int log_fd;
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 pid_t pid;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 log_fd = log_create_pipe(&log, 0);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 if (log_fd < 0)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 pid = -1;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 else {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 pid = fork();
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 if (pid < 0)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 i_error("fork() failed: %m");
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 if (pid < 0) {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 (void)close(log_fd);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 return -1;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 if (pid != 0) {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 /* master */
5843
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
56 child_process_add(pid, &process->process);
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 log_set_prefix(log, "dict: ");
6542
402d14b5ef8b If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents: 6477
diff changeset
58 log_set_pid(log, pid);
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 (void)close(log_fd);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
61 process->log = log;
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
62 log_ref(process->log);
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 dict_process_unlisten(process);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 return 0;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 log_set_prefix(log, "master-dict: ");
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 /* set stdin and stdout to /dev/null, so anything written into it
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 gets ignored. */
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 if (dup2(null_fd, 0) < 0)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 i_fatal("dup2(stdin) failed: %m");
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 if (dup2(null_fd, 1) < 0)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 i_fatal("dup2(stdout) failed: %m");
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 /* stderr = log, 3 = listener */
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 if (dup2(log_fd, 2) < 0)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 i_fatal("dup2(stderr) failed: %m");
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 if (dup2(process->fd, 3) < 0)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 i_fatal("dup2(3) failed: %m");
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 for (i = 0; i <= 3; i++)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 fd_close_on_exec(i, FALSE);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
7109
e6823d781317 Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents: 7091
diff changeset
84 child_process_init_env();
e6823d781317 Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents: 7091
diff changeset
85 env_put(t_strconcat("DICT_LISTEN_FROM_FD=", process->path, NULL));
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86
7481
768231eb84cf Added dict_db_config setting to point to a Berkeley DB config file.
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
87 if (settings_root->defaults->dict_db_config != NULL) {
768231eb84cf Added dict_db_config setting to point to a Berkeley DB config file.
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
88 env_put(t_strconcat("DB_CONFIG=",
768231eb84cf Added dict_db_config setting to point to a Berkeley DB config file.
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
89 settings_root->defaults->dict_db_config,
768231eb84cf Added dict_db_config setting to point to a Berkeley DB config file.
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
90 NULL));
768231eb84cf Added dict_db_config setting to point to a Berkeley DB config file.
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
91 }
768231eb84cf Added dict_db_config setting to point to a Berkeley DB config file.
Timo Sirainen <tss@iki.fi>
parents: 7109
diff changeset
92
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
93 dicts = array_get(&settings_root->dicts, &count);
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
94 i_assert((count % 2) == 0);
7109
e6823d781317 Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents: 7091
diff changeset
95 for (i = 0; i < count; i += 2)
e6823d781317 Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents: 7091
diff changeset
96 env_put(t_strdup_printf("DICT_%s=%s", dicts[i], dicts[i+1]));
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
97
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 /* make sure we don't leak syslog fd, but do it last so that
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 any errors above will be logged */
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 closelog();
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 executable = PKG_LIBEXECDIR"/dict";
7109
e6823d781317 Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents: 7091
diff changeset
103 client_process_exec(executable, "");
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104 i_fatal_status(FATAL_EXEC, "execv(%s) failed: %m", executable);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 return -1;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107
4907
5b4c9b20eba0 Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents: 4393
diff changeset
108 static void dict_process_listen_input(struct dict_process *process)
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 {
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
110 i_assert(process->log == NULL);
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 dict_process_start(process);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 static int dict_process_listen(struct dict_process *process)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 mode_t old_umask;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 int fd, i = 0;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 for (;;) {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 old_umask = umask(0);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 process->fd = net_listen_unix(process->path, 64);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122 umask(old_umask);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 if (process->fd != -1)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 break;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 if (errno != EADDRINUSE || ++i == 2) {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 i_error("net_listen_unix(%s) failed: %m",
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 process->path);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 return -1;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 /* see if it really exists */
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 fd = net_connect_unix(process->path);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 if (fd != -1 || errno != ECONNREFUSED) {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136 if (fd != -1) (void)close(fd);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 i_error("Socket already exists: %s", process->path);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 return -1;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
140
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 /* delete and try again */
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 if (unlink(process->path) < 0 && errno != ENOENT) {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 i_error("unlink(%s) failed: %m", process->path);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 return -1;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 fd_close_on_exec(process->fd, TRUE);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 process->io = io_add(process->fd, IO_READ,
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 dict_process_listen_input, process);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 return process->fd != -1 ? 0 : -1;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 static void dict_process_unlisten(struct dict_process *process)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 {
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 if (process->fd == -1)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158 return;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159
3960
aeb424e64f24 Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents: 3892
diff changeset
160 io_remove(&process->io);
aeb424e64f24 Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents: 3892
diff changeset
161
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 if (close(process->fd) < 0)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 i_error("close(dict) failed: %m");
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 process->fd = -1;
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166
5843
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
167 static void
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
168 dict_process_destroyed(struct child_process *process,
6411
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 5846
diff changeset
169 pid_t pid ATTR_UNUSED,
6a64e64fa3a3 Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents: 5846
diff changeset
170 bool abnormal_exit ATTR_UNUSED)
5843
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
171 {
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
172 struct dict_process *p = (struct dict_process *)process;
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
173
6869
5f97bba6df15 Don't crash when dict process exists and we receive SIGHUP.
Timo Sirainen <tss@iki.fi>
parents: 6542
diff changeset
174 if (p->log != NULL) {
5f97bba6df15 Don't crash when dict process exists and we receive SIGHUP.
Timo Sirainen <tss@iki.fi>
parents: 6542
diff changeset
175 /* not killed by ourself */
5f97bba6df15 Don't crash when dict process exists and we receive SIGHUP.
Timo Sirainen <tss@iki.fi>
parents: 6542
diff changeset
176 log_unref(p->log);
5f97bba6df15 Don't crash when dict process exists and we receive SIGHUP.
Timo Sirainen <tss@iki.fi>
parents: 6542
diff changeset
177 p->log = NULL;
5f97bba6df15 Don't crash when dict process exists and we receive SIGHUP.
Timo Sirainen <tss@iki.fi>
parents: 6542
diff changeset
178 }
5843
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
179 (void)dict_process_listen(p);
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
180 }
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
181
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 void dict_process_init(void)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 {
7561
1a58b18652a6 Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents: 7481
diff changeset
184 struct dict_process *process;
1a58b18652a6 Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents: 7481
diff changeset
185
1a58b18652a6 Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents: 7481
diff changeset
186 process = dict_process = i_new(struct dict_process, 1);
5843
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
187 process->process.type = PROCESS_TYPE_DICT;
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 process->fd = -1;
3885
b624b687fe13 Create dict-server socket to base_dir.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
189 process->path = i_strconcat(settings_root->defaults->base_dir,
3975
9de8bce1077e Added plugin {} section to dovecot.conf for passing extra environment
Timo Sirainen <tss@iki.fi>
parents: 3960
diff changeset
190 "/"DICT_SERVER_SOCKET_NAME, NULL);
9de8bce1077e Added plugin {} section to dovecot.conf for passing extra environment
Timo Sirainen <tss@iki.fi>
parents: 3960
diff changeset
191 (void)dict_process_listen(process);
5843
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
192
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
193 child_process_set_destroy_callback(PROCESS_TYPE_DICT,
f655c4d4a419 Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents: 4907
diff changeset
194 dict_process_destroyed);
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 void dict_process_deinit(void)
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198 {
7561
1a58b18652a6 Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents: 7481
diff changeset
199 struct dict_process *process = dict_process;
1a58b18652a6 Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents: 7481
diff changeset
200
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 dict_process_unlisten(process);
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
202 if (process->log != NULL)
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
203 log_unref(process->log);
3885
b624b687fe13 Create dict-server socket to base_dir.
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
204 i_free(process->path);
3855
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 i_free(process);
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 }
8ce85fb481aa Forgot to add in last commit.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
208 void dict_process_kill(void)
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
209 {
7561
1a58b18652a6 Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents: 7481
diff changeset
210 struct dict_process *process = dict_process;
1a58b18652a6 Avoid using shadow variables. Unfortunately -Wshadow also complains about
Timo Sirainen <tss@iki.fi>
parents: 7481
diff changeset
211
4393
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
212 if (process->log != NULL) {
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
213 log_unref(process->log);
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
214 process->log = NULL;
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
215 }
9928ebb54719 Instead of passing URIs directly to dictionary server, it now accepts only
Timo Sirainen <tss@iki.fi>
parents: 3975
diff changeset
216 }