ze-filter  (ze-filter-0.8.0-develop-180218)
ze-log-grey.c
Go to the documentation of this file.
1 
2 /*
3  *
4  * ze-filter - Mail Server Filter for sendmail
5  *
6  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
7  *
8  * Auteur : Jose Marcio Martins da Cruz
9  * jose.marcio.mc@gmail.org
10  *
11  * Historique :
12  * Creation : Thu Jan 19 16:45:15 CET 2006
13  *
14  * This program is free software, but with restricted license :
15  *
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  * More details about ze-filter license can be found at ze-filter
22  * web site : http://foss.jose-marcio.org
23  */
24 
25 
26 #include <ze-sys.h>
27 #include <ze-filter.h>
28 #include <ze-log-grey.h>
29 
30 /* ****************************************************************************
31  * *
32  * *
33  **************************************************************************** */
34 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
35 
36 
37 void log_grey_expire(char *);
39 
40 
41 /* ****************************************************************************
42  * *
43  * *
44  **************************************************************************** */
45 static LOG_T logt = LOG_INITIALIZER;
46 
47 bool
49 {
50  bool res = TRUE;
51 
52  MUTEX_LOCK(&mutex);
53 
54  if (!log_ready(&logt)) {
55  char path[1024];
56  char *wkdir = cf_get_str(CF_WORKDIR);
57  char *logname = cf_get_str(CF_GREY_LOG_FILE);
58 
59  ADJUST_LOG_NAME(path, logname, wkdir, "none:");
60 
61  res = log_open(&logt, path);
62  } else
63  res = log_reopen(&logt);
64 
66 
67  return res;
68 }
69 
70 /* ****************************************************************************
71  * *
72  * *
73  **************************************************************************** */
74 void
76  char *rec;
77 {
78  time_t t = time(NULL);
79  int r;
80 
81  if (!log_ready(&logt) && !log_grey_expire_reopen())
82  return;
83 
84  MUTEX_LOCK(&mutex);
85 
86  log_printf(&logt, "%10ld %s\n", (long) t, rec);
87 
88 fin:
90 }
#define LOG_INITIALIZER
Definition: ze-txtlog.h:96
bool log_ready(LOG_T *)
Definition: ze-txtlog.c:130
bool log_reopen(LOG_T *)
Definition: ze-txtlog.c:275
#define MUTEX_UNLOCK(mutex)
Definition: macros.h:101
bool log_grey_expire_reopen()
Definition: ze-log-grey.c:48
bool log_open(LOG_T *, char *)
Definition: ze-txtlog.c:146
#define MUTEX_LOCK(mutex)
Definition: macros.h:93
pthread_mutex_t mutex
Definition: ze-connopen.c:63
bool log_printf(LOG_T *, char *,...)
Definition: ze-txtlog.c:355
void log_grey_expire(char *)
Definition: ze-log-grey.c:75
#define TRUE
Definition: macros.h:157
char * cf_get_str(int id)
Definition: ze-cf.c:854
#define CF_GREY_LOG_FILE
Definition: cfh-defs.h:210
#define CF_WORKDIR
Definition: cfh-defs.h:67
#define ADJUST_LOG_NAME(path, fname, dir, defval)
Definition: ze-txtlog.h:133