5 |
#include <string.h> |
#include <string.h> |
6 |
#include <errno.h> |
#include <errno.h> |
7 |
#include <limits.h> |
#include <limits.h> |
8 |
|
#include <fcntl.h> |
9 |
#include <setjmp.h> |
#include <setjmp.h> |
10 |
#include <locale.h> |
#include <locale.h> |
11 |
|
|
48 |
int |
int |
49 |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
50 |
{ |
{ |
51 |
int c, r, f; |
int c, r; |
|
pid_t pid; |
|
52 |
char *conffile; /* Configuration file. */ |
char *conffile; /* Configuration file. */ |
53 |
account_t *ca; /* Current account. */ |
account_t *ca; /* Current account. */ |
54 |
mbox_t *cm; /* Current mailbox. */ |
mbox_t *cm; /* Current mailbox. */ |
55 |
|
|
56 |
setlocale(LC_ALL, ""); |
setlocale(LC_ALL, ""); |
57 |
|
|
|
f = 0; |
|
58 |
home = getenv("HOME"); |
home = getenv("HOME"); |
59 |
options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE | OPTION_PEEK); |
options = (OPTION_DETAILS_NORMAL | OPTION_NAMESPACE | OPTION_PEEK); |
60 |
*charset = 0; |
*charset = 0; |
147 |
init_buffer(&obuf); |
init_buffer(&obuf); |
148 |
|
|
149 |
if (options & OPTION_DAEMON_MODE) { |
if (options & OPTION_DAEMON_MODE) { |
|
f = 1; |
|
150 |
options &= ~(OPTION_DETAILS_QUIET | |
options &= ~(OPTION_DETAILS_QUIET | |
151 |
OPTION_DETAILS_NORMAL | OPTION_DETAILS_VERBOSE); |
OPTION_DETAILS_NORMAL | OPTION_DETAILS_VERBOSE); |
152 |
options |= OPTION_DETAILS_QUIET; |
options |= OPTION_DETAILS_QUIET; |
216 |
} |
} |
217 |
|
|
218 |
/* Fork if in daemon mode. */ |
/* Fork if in daemon mode. */ |
219 |
if (f) { |
if (options & OPTION_DAEMON_MODE && |
220 |
f = 0; |
!(flags & FLAG_DAEMON_MODE)) { |
221 |
pid = fork(); |
|
222 |
switch (pid) { |
close_logfile(); |
223 |
|
|
224 |
|
switch (fork()) { |
225 |
|
case -1: |
226 |
|
fatal(ERROR_FORK, "forking; %s\n", |
227 |
|
strerror(errno)); |
228 |
|
break; |
229 |
|
case 0: |
230 |
|
break; |
231 |
|
default: |
232 |
|
secmem_clear(); |
233 |
|
exit(0); |
234 |
|
break; |
235 |
|
} |
236 |
|
|
237 |
|
if (setsid() == -1) |
238 |
|
fatal(ERROR_FORK, "creating session; %s\n", |
239 |
|
strerror(errno)); |
240 |
|
|
241 |
|
switch (fork()) { |
242 |
case -1: |
case -1: |
243 |
fatal(ERROR_FORK, "forking; %s\n", |
fatal(ERROR_FORK, "forking; %s\n", |
244 |
strerror(errno)); |
strerror(errno)); |
245 |
break; |
break; |
246 |
case 0: |
case 0: |
|
lockfile_create(); |
|
|
corefile_disable(); |
|
|
flags |= FLAG_DAEMON_MODE; |
|
247 |
break; |
break; |
248 |
default: |
default: |
249 |
secmem_clear(); |
secmem_clear(); |
|
close_logfile(); |
|
250 |
exit(0); |
exit(0); |
251 |
break; |
break; |
252 |
} |
} |
253 |
|
|
254 |
|
close(STDIN_FILENO); |
255 |
|
close(STDOUT_FILENO); |
256 |
|
close(STDERR_FILENO); |
257 |
|
if (open("/dev/null", O_RDWR) != -1) { |
258 |
|
dup(STDIN_FILENO); |
259 |
|
dup(STDIN_FILENO); |
260 |
|
} |
261 |
|
open_logfile(); |
262 |
|
lockfile_create(); |
263 |
|
corefile_disable(); |
264 |
|
|
265 |
|
flags |= FLAG_DAEMON_MODE; |
266 |
} |
} |
267 |
if (options & OPTION_DAEMON_MODE && |
if (options & OPTION_DAEMON_MODE && |
268 |
flags & FLAG_SIGUSR1_RECEIVED) { |
flags & FLAG_SIGUSR1_RECEIVED) { |