new file.
Showing
2 changed files
with
128 additions
and
0 deletions
imap4d/bye.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | |||
19 | #include "imap4d.h" | ||
20 | |||
21 | int | ||
22 | imap4d_bye (int reason) | ||
23 | { | ||
24 | struct passwd *pw = getpwuid (getuid ()); | ||
25 | const char *username; | ||
26 | int status = EXIT_FAILURE; | ||
27 | username = (pw) ? pw->pw_name : "Unknown"; | ||
28 | |||
29 | mailbox_close (mbox); | ||
30 | mailbox_destroy (&mbox); | ||
31 | |||
32 | switch (reason) | ||
33 | { | ||
34 | case ERR_NO_MEM: | ||
35 | util_out (RESP_BYE, "Server terminating no more ressources."); | ||
36 | syslog (LOG_ERR, "Out of memory"); | ||
37 | break; | ||
38 | |||
39 | case ERR_SIGNAL: | ||
40 | util_out (RESP_BYE, "Quitting on signal"); | ||
41 | syslog (LOG_ERR, "Quitting on signal"); | ||
42 | break; | ||
43 | |||
44 | case ERR_TIMEOUT: | ||
45 | util_out (RESP_BYE, "Session timed out"); | ||
46 | if (state == STATE_NONAUTH) | ||
47 | syslog (LOG_INFO, "Session timed out for no user"); | ||
48 | else | ||
49 | syslog (LOG_INFO, "Session timed out for user: %s", username); | ||
50 | break; | ||
51 | |||
52 | case ERR_NO_OFILE: | ||
53 | syslog (LOG_INFO, "No socket to send to"); | ||
54 | break; | ||
55 | |||
56 | case OK: | ||
57 | util_out (RESP_BYE, "Session terminating."); | ||
58 | if (state == STATE_NONAUTH) | ||
59 | syslog (LOG_INFO, "Session terminating"); | ||
60 | else | ||
61 | syslog (LOG_INFO, "Session terminating for user: %s", username); | ||
62 | status = EXIT_SUCCESS; | ||
63 | break; | ||
64 | |||
65 | default: | ||
66 | util_out (RESP_BYE, "Quitting (reason unknown)"); | ||
67 | syslog (LOG_ERR, "Unknown quit"); | ||
68 | break; | ||
69 | } | ||
70 | |||
71 | closelog (); | ||
72 | exit (status); | ||
73 | } |
imap4d/signal.c
0 → 100644
1 | /* GNU mailutils - a suite of utilities for electronic mail | ||
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | ||
17 | |||
18 | |||
19 | #define __USE_MISC | ||
20 | #include "imap4d.h" | ||
21 | |||
22 | RETSIGTYPE | ||
23 | imap4d_sigchld (int signo) | ||
24 | { | ||
25 | pid_t pid; | ||
26 | int status; | ||
27 | |||
28 | while ( (pid = waitpid(-1, &status, WNOHANG)) > 0) | ||
29 | --children; | ||
30 | #ifndef HAVE_SIGACTION | ||
31 | /* On some system, signal implements the unreliable semantic and | ||
32 | has to be rearm. */ | ||
33 | signal (signo, imap4d_sigchld); | ||
34 | #endif | ||
35 | } | ||
36 | |||
37 | /* Default signal handler to call the imap4d_bye() function */ | ||
38 | |||
39 | RETSIGTYPE | ||
40 | imap4d_signal (int signo) | ||
41 | { | ||
42 | extern const char *const sys_siglist[]; | ||
43 | /* syslog (LOG_CRIT, "got signal %d", signo); */ | ||
44 | syslog (LOG_CRIT, "got signal %s", sys_siglist[signo]); | ||
45 | /* Master process. */ | ||
46 | if (!ofile) | ||
47 | { | ||
48 | syslog (LOG_CRIT, "MASTER: exiting on signal"); | ||
49 | exit (1); /* abort(); */ | ||
50 | } | ||
51 | |||
52 | if (signo == SIGALRM) | ||
53 | imap4d_bye (ERR_TIMEOUT); | ||
54 | imap4d_bye (ERR_SIGNAL); | ||
55 | } |
-
Please register or sign in to post a comment