1 /* milter-callback - a sendmail milter to perform variuos sender verifications
2  Copyright (C) 2008  Eugene M. Zheganin, milter-callback@norma.perm.ru
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 3 of the License, or
7  (at your option) 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, see <http://www.gnu.org/licenses/>.
16 */
17 
18 
19 #include <milter-callback.h>
20 #include <cache.h>
21 #include <cpit.h>
22 #include <commonprocs.h>
23 
24 extern int logLevel;
25 extern int mcDebug;
26 extern pthread_mutex_t *mcCacheBusy;
27 extern pthread_mutex_t *mcPitBusy;
28 
29 void
getCaches(int sig)30 getCaches (int sig) {
31     char tmpLog[MAXLOGLINE];
32     int mtxErr;
33 
34     /* displaying cache */
35     logNow("Got SIGUSR1, displaying both caches.", 0, 0);
36 
37     /* displaying cache */
38     logNow("Trying to lock the cache.", 3, 0);
39     mtxErr = pthread_mutex_lock(mcCacheBusy);
40     if (mtxErr == 0) {
41 	logNow("Lock aquired.", 3, 0);
42 	getCache(0);
43 	snprintf(tmpLog, MAXLOGLINE, "Trying to unlock the cache.");
44         logNow(&tmpLog[0], 3, 0);
45         mtxErr = pthread_mutex_unlock(mcCacheBusy);
46         if (mtxErr == 0) {
47             logNow("Cache unlocked.", 3, 0);
48         } else {
49             snprintf(tmpLog, MAXLOGLINE, "Cache cannot be unlocked, pthread_mutex_unlock() signalled %d.", mtxErr);
50             logNow(&tmpLog[0], 0, 0);
51         }
52     } else {
53 	snprintf(tmpLog, MAXLOGLINE, "Lock cannot be aquired, pthread_mutex_lock() signalled %d.", mtxErr);
54 	logNow(&tmpLog[0], 0, 0);
55     }
56 
57     /* displaying pit */
58     snprintf(tmpLog, MAXLOGLINE, "Trying to lock the pit cache.");
59     logNow(&tmpLog[0], 3, 0);
60     mtxErr = pthread_mutex_lock(mcPitBusy);
61     if (mtxErr == 0) {
62         logNow("Lock aquired.", 3, 0);
63 	getPit(0, 0);
64 	/* unflag mutex */
65 	snprintf(tmpLog, MAXLOGLINE, "Trying to unlock the pit cache.");
66         logNow(&tmpLog[0], 3, 0);
67         mtxErr = pthread_mutex_unlock(mcPitBusy);
68         if (mtxErr == 0) {
69             logNow("Pit cache unlocked.", 3, 0);
70         } else {
71             snprintf(tmpLog, MAXLOGLINE, "Pit cache cannot be unlocked, pthread_mutex_unlock() signalled %d.", mtxErr);
72             logNow(&tmpLog[0], 0, 0);
73         }
74     } else {
75         snprintf(tmpLog, MAXLOGLINE, "Lock on the pit cannot be aquired, pthread_mutex_lock() signalled %d.", mtxErr);
76         logNow(&tmpLog[0], 0, 0);
77     };
78 };
79