Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/master/child-process.c @ 9348:3eacb6bbd227 HEAD
Added pop3_save_uidl setting.
When UIDLs are sent to client, save them to dovecot-uidlist. This allows
changing pop3_uidl_format without messages getting re-downloaded. It's also
useful with virtual POP3 INBOX when UIDLs are based on IMAP UIDs that may
not be as stable as in non-virtual INBOX.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 31 Aug 2009 18:53:17 -0400 |
parents | 366a327b028b |
children | 00cd9aacd03c |
rev | line source |
---|---|
8590
b9faf4db2a9f
Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents:
8573
diff
changeset
|
1 /* Copyright (c) 2002-2009 Dovecot authors, see the included COPYING file */ |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "common.h" |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
4 #include "lib-signals.h" |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "hash.h" |
8628
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
6 #include "str.h" |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "env-util.h" |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "syslog-util.h" |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
9 #include "child-process.h" |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include <unistd.h> |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #include <syslog.h> |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
13 #include <sys/wait.h> |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 const char *process_names[PROCESS_TYPE_MAX] = { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 "unknown", |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 "auth", |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 "auth-worker", |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 "login", |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 "imap", |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 "pop3", |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 "ssl-build-param", |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 "dict" |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 }; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
25 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
26 struct hash_table *processes; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 static child_process_destroy_callback_t *destroy_callbacks[PROCESS_TYPE_MAX]; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 struct child_process *child_process_lookup(pid_t pid) |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
30 { |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
8223
diff
changeset
|
31 return hash_table_lookup(processes, POINTER_CAST(pid)); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
32 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
33 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 void child_process_add(pid_t pid, struct child_process *process) |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 { |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
8223
diff
changeset
|
36 hash_table_insert(processes, POINTER_CAST(pid), process); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
38 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 void child_process_remove(pid_t pid) |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 { |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
8223
diff
changeset
|
41 hash_table_remove(processes, POINTER_CAST(pid)); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7095
diff
changeset
|
44 void child_process_init_env(void) |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
46 int facility; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
47 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7095
diff
changeset
|
48 /* remove all environment, we don't need them */ |
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7095
diff
changeset
|
49 env_clean(); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
51 /* we'll log through master process */ |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7095
diff
changeset
|
52 env_put("LOG_TO_MASTER=1"); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
53 if (env_tz != NULL) |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7095
diff
changeset
|
54 env_put(t_strconcat("TZ=", env_tz, NULL)); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
55 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 if (settings_root == NULL || |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 !syslog_facility_find(settings_root->defaults->syslog_facility, |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 &facility)) |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
59 facility = LOG_MAIL; |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7095
diff
changeset
|
60 env_put(t_strdup_printf("SYSLOG_FACILITY=%d", facility)); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 if (settings_root != NULL && !settings_root->defaults->version_ignore) |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7095
diff
changeset
|
63 env_put("DOVECOT_VERSION="PACKAGE_VERSION); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 #ifdef DEBUG |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7095
diff
changeset
|
65 if (gdb) env_put("GDB=1"); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 #endif |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 |
7109
e6823d781317
Reverted "environment array" changes. It broke overriding imap/pop3 settings
Timo Sirainen <tss@iki.fi>
parents:
7095
diff
changeset
|
69 void client_process_exec(const char *cmd, const char *title) |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 { |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
71 const char **argv; |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 /* very simple argument splitting. */ |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 if (*title == '\0') |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
75 argv = t_strsplit(cmd, " "); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
76 else |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
77 argv = t_strsplit(t_strconcat(cmd, " ", title, NULL), " "); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
78 |
7334
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
79 client_process_exec_argv(argv[0], argv); |
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
80 } |
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
81 |
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
82 void client_process_exec_argv(const char *executable, const char **argv) |
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
83 { |
ae8180a4febd
Allow dovecot --exec-mail ext program arguments.
Timo Sirainen <tss@iki.fi>
parents:
7109
diff
changeset
|
84 const char *p; |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
85 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
86 /* hide the path, it's ugly */ |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
87 p = strrchr(argv[0], '/'); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
88 if (p != NULL) argv[0] = p+1; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
89 |
9336
366a327b028b
master: If execv() fails with ENOMEM, mention the *_process_size setting.
Timo Sirainen <tss@iki.fi>
parents:
8889
diff
changeset
|
90 (void)execv(executable, (char **)argv); |
366a327b028b
master: If execv() fails with ENOMEM, mention the *_process_size setting.
Timo Sirainen <tss@iki.fi>
parents:
8889
diff
changeset
|
91 i_fatal_status(errno == ENOMEM ? FATAL_OUTOFMEM : FATAL_EXEC, |
366a327b028b
master: If execv() fails with ENOMEM, mention the *_process_size setting.
Timo Sirainen <tss@iki.fi>
parents:
8889
diff
changeset
|
92 "execv(%s) failed: %m", executable); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
93 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
94 |
8223
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
95 static const char *get_exit_status_message(enum fatal_exit_status status, |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
96 enum process_type process_type) |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
97 { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
98 switch (status) { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
99 case FATAL_LOGOPEN: |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
100 return "Can't open log file"; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
101 case FATAL_LOGWRITE: |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
102 return "Can't write to log file"; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
103 case FATAL_LOGERROR: |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 return "Internal logging error"; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
105 case FATAL_OUTOFMEM: |
8223
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
106 switch (process_type) { |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
107 case PROCESS_TYPE_AUTH: |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
108 case PROCESS_TYPE_AUTH_WORKER: |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
109 return "Out of memory - see auth_process_size setting"; |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
110 case PROCESS_TYPE_LOGIN: |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
111 return "Out of memory - see login_process_size setting"; |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
112 case PROCESS_TYPE_IMAP: |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
113 case PROCESS_TYPE_POP3: |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
114 return "Out of memory - see mail_process_size setting"; |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
115 case PROCESS_TYPE_UNKNOWN: |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
116 case PROCESS_TYPE_SSL_PARAM: |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
117 case PROCESS_TYPE_DICT: |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
118 case PROCESS_TYPE_MAX: |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
119 break; |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
120 } |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 return "Out of memory"; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 case FATAL_EXEC: |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
123 return "exec() failed"; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
124 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
125 case FATAL_DEFAULT: |
6542
402d14b5ef8b
If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
126 return "Fatal failure"; |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
127 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
128 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
129 return NULL; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
130 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
131 |
8798
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
132 static void |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
133 log_coredump(string_t *str, enum process_type process_type, int status) |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
134 { |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
135 #ifdef WCOREDUMP |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
136 int signum = WTERMSIG(status); |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
137 |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
138 if (WCOREDUMP(status)) { |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
139 str_append(str, " (core dumped)"); |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
140 return; |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
141 } |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
142 |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
143 if (signum != SIGABRT && signum != SIGSEGV && signum != SIGBUS) |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
144 return; |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
145 |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
146 /* let's try to figure out why we didn't get a core dump */ |
8823
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
147 if (core_dumps_disabled) { |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
148 str_printfa(str, " (core dumps disabled)"); |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
149 return; |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
150 } |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
151 |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
152 switch (process_type) { |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
153 case PROCESS_TYPE_LOGIN: |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
154 #ifdef HAVE_PR_SET_DUMPABLE |
8822
978010934c02
If login process core dumps, suggest using -D parameter.
Timo Sirainen <tss@iki.fi>
parents:
8798
diff
changeset
|
155 str_append(str, " (core not dumped - add -D to login_executable)"); |
8823
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
156 return; |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
157 #else |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
158 break; |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
159 #endif |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
160 case PROCESS_TYPE_IMAP: |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
161 case PROCESS_TYPE_POP3: |
8798
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
162 #ifndef HAVE_PR_SET_DUMPABLE |
8823
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
163 if (!settings_root->defaults->mail_drop_priv_before_exec) { |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
164 str_append(str, " (core not dumped - set mail_drop_priv_before_exec=yes)"); |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
165 return; |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
166 } |
8861
9d00503821d6
mail_privileged_group setting prevents core dumps - mention it in logging.
Timo Sirainen <tss@iki.fi>
parents:
8823
diff
changeset
|
167 if (*settings_root->defaults->mail_privileged_group != '\0') { |
9d00503821d6
mail_privileged_group setting prevents core dumps - mention it in logging.
Timo Sirainen <tss@iki.fi>
parents:
8823
diff
changeset
|
168 str_append(str, " (core not dumped - mail_privileged_group prevented it)"); |
9d00503821d6
mail_privileged_group setting prevents core dumps - mention it in logging.
Timo Sirainen <tss@iki.fi>
parents:
8823
diff
changeset
|
169 return; |
9d00503821d6
mail_privileged_group setting prevents core dumps - mention it in logging.
Timo Sirainen <tss@iki.fi>
parents:
8823
diff
changeset
|
170 } |
8798
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
171 #endif |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
172 str_append(str, " (core not dumped - is home dir set?)"); |
8823
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
173 return; |
8889
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
174 case PROCESS_TYPE_AUTH: |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
175 case PROCESS_TYPE_AUTH_WORKER: |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
176 if (settings_root->auths->uid == 0) |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
177 break; |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
178 #ifdef HAVE_PR_SET_DUMPABLE |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
179 str_printfa(str, " (core not dumped - " |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
180 "no permissions for auth user %s in %s?)", |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
181 settings_root->auths->user, |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
182 settings_root->defaults->base_dir); |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
183 #else |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
184 str_append(str, " (core not dumped - auth user is not root)"); |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
185 #endif |
c5cb1f27caea
Try to make sure auth process can dump core, and if it can't try to find why.
Timo Sirainen <tss@iki.fi>
parents:
8882
diff
changeset
|
186 return; |
8823
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
187 default: |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
188 break; |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
189 } |
fa0775526cf4
master: Fixes to core dump log message writing.
Timo Sirainen <tss@iki.fi>
parents:
8822
diff
changeset
|
190 str_append(str, " (core not dumped)"); |
8798
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
191 #endif |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
192 } |
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
193 |
8882
9f3968f49ceb
lib-signals: Changed callback API to return siginfo_t.
Timo Sirainen <tss@iki.fi>
parents:
8861
diff
changeset
|
194 static void sigchld_handler(const siginfo_t *si ATTR_UNUSED, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
5846
diff
changeset
|
195 void *context ATTR_UNUSED) |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
197 struct child_process *process; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
198 const char *process_type_name, *msg; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 enum process_type process_type; |
8628
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
200 string_t *str; |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 pid_t pid; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 int status; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 bool abnormal_exit; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
204 |
8628
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
205 str = t_str_new(128); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
207 /* get the type and remove from hash */ |
8628
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
208 str_truncate(str, 0); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 process = child_process_lookup(pid); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
210 if (process == NULL) |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
211 process_type = PROCESS_TYPE_UNKNOWN; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 else { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
213 process_type = process->type; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
214 child_process_remove(pid); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
215 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 abnormal_exit = TRUE; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
217 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 /* write errors to syslog */ |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 process_type_name = process_names[process_type]; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 if (WIFEXITED(status)) { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
221 status = WEXITSTATUS(status); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 if (status == 0) { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
223 abnormal_exit = FALSE; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
224 if (process_type == PROCESS_TYPE_UNKNOWN) { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
225 i_error("unknown child %s exited " |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
226 "successfully", dec2str(pid)); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
227 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 } else if (status == 1 && |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
229 process_type == PROCESS_TYPE_SSL_PARAM) { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
230 /* kludgy. hide this failure. */ |
6542
402d14b5ef8b
If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
231 } else if (status == FATAL_DEFAULT && |
402d14b5ef8b
If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
232 process->seen_fatal) { |
402d14b5ef8b
If child process logged a fatal failure, don't show "returned error 89"
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
233 /* the error was already logged. */ |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
234 } else { |
8223
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
235 msg = get_exit_status_message(status, |
66ecd60b7ea2
If a process dies because it's out of memory, mention *_process_size setting in the error message.
Timo Sirainen <tss@iki.fi>
parents:
7334
diff
changeset
|
236 process_type); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
237 msg = msg == NULL ? "" : |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
238 t_strconcat(" (", msg, ")", NULL); |
8628
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
239 str_printfa(str, |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
240 "child %s (%s) returned error %d%s", |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
241 dec2str(pid), process_type_name, |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
242 status, msg); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
243 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
244 } else if (WIFSIGNALED(status)) { |
8628
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
245 str_printfa(str, "child %s (%s) killed with signal %d", |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
246 dec2str(pid), process_type_name, |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
247 WTERMSIG(status)); |
8798
c9381a0fdc5e
Improved logging for core dumping. With Linux use PR_SET_DUMPABLE for imap/pop3.
Timo Sirainen <tss@iki.fi>
parents:
8735
diff
changeset
|
248 log_coredump(str, process_type, status); |
8628
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
249 } |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
250 |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
251 if (str_len(str) > 0) { |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
252 if (process != NULL && process->ip.family != 0) { |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
253 if (!process->ip_changed) |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
254 str_append(str, " (ip="); |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
255 else |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
256 str_append(str, " (latest ip="); |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
257 str_printfa(str, "%s)", |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
258 net_ip2addr(&process->ip)); |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
259 } |
e85c7cb22ad7
If login process crashes, log the IP address that (maybe) caused it.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
260 i_error("%s", str_c(str)); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
262 |
5846
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5843
diff
changeset
|
263 if (destroy_callbacks[process_type] != NULL) { |
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5843
diff
changeset
|
264 destroy_callbacks[process_type](process, pid, |
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5843
diff
changeset
|
265 abnormal_exit); |
21e529b8a701
Initial implementation for mail_max_user_connections setting.
Timo Sirainen <tss@iki.fi>
parents:
5843
diff
changeset
|
266 } |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 if (pid == -1 && errno != EINTR && errno != ECHILD) |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
270 i_warning("waitpid() failed: %m"); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
271 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
272 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
273 void child_process_set_destroy_callback(enum process_type type, |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
274 child_process_destroy_callback_t *cb) |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
275 { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
276 i_assert(type < PROCESS_TYPE_MAX); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
277 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
278 destroy_callbacks[type] = cb; |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
279 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
280 |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 void child_processes_init(void) |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 { |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
8223
diff
changeset
|
283 processes = hash_table_create(default_pool, default_pool, 128, NULL, NULL); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
284 lib_signals_set_handler(SIGCHLD, TRUE, sigchld_handler, NULL); |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 } |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
286 |
8735
f8fdabb30c0a
master: Don't crash if auth process dies too early.
Timo Sirainen <tss@iki.fi>
parents:
8628
diff
changeset
|
287 void child_processes_flush(void) |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 { |
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 /* make sure we log if child processes died unexpectedly */ |
8882
9f3968f49ceb
lib-signals: Changed callback API to return siginfo_t.
Timo Sirainen <tss@iki.fi>
parents:
8861
diff
changeset
|
290 sigchld_handler(NULL, NULL); |
8735
f8fdabb30c0a
master: Don't crash if auth process dies too early.
Timo Sirainen <tss@iki.fi>
parents:
8628
diff
changeset
|
291 } |
f8fdabb30c0a
master: Don't crash if auth process dies too early.
Timo Sirainen <tss@iki.fi>
parents:
8628
diff
changeset
|
292 |
f8fdabb30c0a
master: Don't crash if auth process dies too early.
Timo Sirainen <tss@iki.fi>
parents:
8628
diff
changeset
|
293 void child_processes_deinit(void) |
f8fdabb30c0a
master: Don't crash if auth process dies too early.
Timo Sirainen <tss@iki.fi>
parents:
8628
diff
changeset
|
294 { |
f8fdabb30c0a
master: Don't crash if auth process dies too early.
Timo Sirainen <tss@iki.fi>
parents:
8628
diff
changeset
|
295 child_processes_flush(); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
296 lib_signals_unset_handler(SIGCHLD, sigchld_handler, NULL); |
8573
f9166a09423a
Renamed hash_*() to hash_table_*() to avoid conflicts with OSX's strhash.h
Timo Sirainen <tss@iki.fi>
parents:
8223
diff
changeset
|
297 hash_table_destroy(&processes); |
5843
f655c4d4a419
Moved child process handling to child-process.[ch]. The hash table now uses
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 } |