28 #include <libmilter/mfapi.h> 33 #define USE_SMFI_STOP 1 39 static void do_proc_save();
40 static void do_proc_log();
41 static void do_proc_reset();
42 static void do_proc_exit();
43 static void do_proc_conf();
46 static bool flag_save =
FALSE;
47 static bool flag_reset =
FALSE;
48 static bool flag_exit =
FALSE;
49 static bool flag_log =
FALSE;
50 static bool flag_conf =
FALSE;
52 static time_t time2exit = 0;
59 #define MAX_FAILS_T 16 72 memset(&
set, 0,
sizeof (
set));
75 sigaddset(&
set, SIGHUP);
76 sigaddset(&
set, SIGTERM);
77 sigaddset(&
set, SIGINT);
78 sigaddset(&
set, SIGQUIT);
79 sigaddset(&
set, SIGUSR1);
80 sigaddset(&
set, SIGUSR2);
85 sigaddset(&
set, SIGSYS);
86 sigaddset(&
set, SIGILL);
87 sigaddset(&
set, SIGBUS);
88 sigaddset(&
set, SIGFPE);
89 sigaddset(&
set, SIGSEGV);
96 if (sigwait(&
set, &sig) != 0) {
111 ZE_LogMsgInfo(10,
" *** Terminate command received : SIGHUP");
115 ZE_LogMsgInfo(10,
" *** Terminate command received : SIGTERM");
119 ZE_LogMsgInfo(10,
" *** Dump counters command received : SIGUSR1");
124 ZE_LogMsgInfo(10,
" *** Reset counters command received : SIGUSR2");
175 sigaddset(&
set, SIGHUP);
176 sigaddset(&
set, SIGTERM);
177 sigaddset(&
set, SIGINT);
178 sigaddset(&
set, SIGQUIT);
179 sigaddset(&
set, SIGUSR1);
180 sigaddset(&
set, SIGUSR2);
181 sigaddset(&
set, SIGALRM);
182 sigaddset(&
set, SIGABRT);
184 if ((r = pthread_sigmask(SIG_BLOCK, &
set, NULL)) != 0) {
230 #if (USE_SMFI_STOP == 1) && defined(HAVE_SMFI_STOP) 251 kill(getpid(), SIGHUP);
305 char *env = getenv(
"DUMP_MESSAGE_SCORE");
323 #define DT_LOOP DT_SIGALRM 329 #define DT_RATE_UPDATE 300 332 #define DT_GUPDATE 10 335 #define DT_HUPDATE 600 338 #define DT_COUNT_FD 10 341 #define DT_LOG_THROTTLE 60 346 #define DT_RESOURCE 10 347 #define DIM_LOAD_HISTORY 32 350 periodic_tasks_loop(data)
355 time_t t_now, t_last;
356 time_t t_loop, t_save, t_rate_updt, t_stats;
357 time_t t_h_updt, t_gt_updt, t_fd, t_conf;
358 time_t t_log_throttle, t_resource;
367 time_t t_init = time(NULL);
371 time_t t_restart = (time_t) 0;
373 tid = pthread_self();
374 (void) pthread_detach(tid);
376 t_loop = t_save = t_rate_updt = t_stats = 0;
377 t_gt_updt = t_h_updt = t_fd = t_conf = 0;
378 t_log_throttle = t_resource = 0;
380 t_last = t_now = time(NULL);
384 #ifdef _POSIX_PTHREAD_SEMANTICS 385 ctime_r(&t_now, sout);
387 ctime_r(&t_now, sout,
sizeof (sout));
400 server_idle[n] = 100;
409 if ((env = getenv(
"PERIODIC_AUTO_RESTART")) != NULL) {
423 #if defined(OS_LINUX) 432 if ((time2exit != 0) && ((t_now - time2exit) > 5)) {
434 "why system continues to run ? Surely one Linux box...");
441 if (t_now < (t_last +
DT_LOOP)) {
459 t_log_throttle += dt;
463 memset(sout, 0,
sizeof (sout));
464 #ifdef _POSIX_PTHREAD_SEMANTICS 465 ctime_r(&t_now, sout);
467 ctime_r(&t_now, sout,
sizeof (sout));
498 int msg = rand() % 32;
502 if (
TRUE || ((nb++ % 5) == 0)) {
503 ZE_MessageInfo(15,
"Will send %4d to the father on fd = %2d", msg,
524 if ((DT_RELOAD > 0) && (t_conf >= DT_RELOAD)) {
541 int idle, mean_idle = 0;
557 char *env = getenv(
"HIGH_LOAD_AUTO_RESTART");
565 if (max_load < 50 || max_load > 100)
568 min_idle = 100 - max_load;
579 mean_idle += server_idle[i];
580 if (server_idle[i] < min_idle)
588 if (min_idle > 0 && n == DIM_LOAD_HISTORY) {
596 if (t_restart > 1
HOURS && t_init + t_restart < t_now) {
598 (
long) (t_now - t_init));
645 #if (USE_SMFI_STOP == 1) && defined(HAVE_SMFI_STOP) 651 time2exit = time(NULL);
673 if (!flag_exit && ((msg_ok > 4) || (getppid() == 1))) {
679 #if (USE_SMFI_STOP == 1) && defined(HAVE_SMFI_STOP) 685 time2exit = time(NULL);
701 static void *periodic_tasks_debug(
void *);
713 if ((r = pthread_create(&tid, NULL, periodic_tasks_loop, (
void *) NULL)) != 0)
718 pthread_create(&tid, NULL, periodic_tasks_debug, (
void *) NULL)) != 0)
736 if ((sock_file == NULL) || (strlen(sock_file) == 0))
739 if (strncasecmp(sock_file,
"unix:", strlen(
"unix:")) == 0) {
740 sock_file += strlen(
"unix:");
742 if (strncasecmp(sock_file,
"local:", strlen(
"local:")) == 0)
743 sock_file += strlen(
"local:");
746 if ((sock_file != NULL) && strlen(sock_file) > 0 && *sock_file ==
'/') {
749 if (lstat(sock_file, &buf) == 0) {
765 periodic_tasks_debug(data)
770 char ip[32], name[64];
774 for (j = 0; j < (3 *
DT_DEBUG); j++) {
776 for (i = 0; i < 4; i++)
777 n[i] = 1 + (rand() % 64);
782 snprintf(ip,
sizeof (ip),
"%d.%d.%d.%d", n[0], n[1], n[2], n[3]);
783 snprintf(name,
sizeof (name),
"%d.%d.%d.%d.jose-marcio.org", n[0], n[1], n[2],
790 for (j = 0; j < (3 *
DT_DEBUG); j++) {
792 for (i = 0; i < 4; i++)
793 n[i] = 1 + (rand() % 64);
798 snprintf(ip,
sizeof (ip),
"%d.%d.%d.%d", n[0], n[1], n[2], n[3]);
799 snprintf(name,
sizeof (name),
"%d.%d.%d.%d.jose-marcio.org", n[0], n[1], n[2],
bool setup_filter_signal_handler()
int smtprate_add_entry(int, char *, char *, int, time_t)
bool log_counters_reopen()
void remove_milter_unix_sock(void)
void log_throttle_stats(void)
bool log_attached_files_reopen()
int recv_msg_channel(int[], int *, int)
bool log_grey_expire_reopen()
bool reopen_scores4stats_file()
bool res_history_update(History_T *, char *, time_t, time_t, bool)
#define ZE_LogMsgInfo(level,...)
bool smtprate_cleanup_table(time_t now, time_t win)
#define ZE_LogMsgError(level,...)
void log_counters(int, bool)
bool log_quarantine_reopen()
bool reopen_all_log_files()
long zeStr2long(char *s, int *error, long dval)
bool check_throttle_dos(void)
#define CF_AUTO_RELOAD_TABLES
#define ZE_LogMsgDebug(level,...)
#define ZE_MessageInfo(level,...)
#define ZE_MessageWarning(level,...)
#define ZE_LogSysError(...)
void remove_milter_sock()
void * filter_signal_handler(void *name)
void launch_periodic_tasks_thread()
#define ZE_LogMsgWarning(level,...)
int connopen_check_host(char *, char *, int)
bool send_message_pipe(int, int)
void update_throttle(time_t)
void smtprate_save_table(char *)
#define STRCASEEQUAL(a, b)
bool oracle_dump_counters(int, bool)
void smtprate_log_table()
void lifetime_set(uint32_t which)
unsigned int statistics_interval
time_t zeStr2time(char *s, int *error, time_t dval)