Skip to content

Commit

Permalink
* fix, signals.c: slimming reload() signal handler. Thanks to @jaredm…
Browse files Browse the repository at this point in the history
…auch for bringing this up.
  • Loading branch information
paololucente committed Nov 22, 2019
1 parent 71e2fb1 commit 6b74dfd
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 22 deletions.
5 changes: 5 additions & 0 deletions src/bgp/bgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,11 @@ void skinny_bgp_daemon_online()
reload_log_bgp_thread = FALSE;
}

if (reload_log && !bgp_misc_db->is_thread) {
reload_logs();
reload_log = FALSE;
}

if (bgp_misc_db->msglog_backend_methods || bgp_misc_db->dump_backend_methods) {
gettimeofday(&bgp_misc_db->log_tstamp, NULL);
compose_timestamp(bgp_misc_db->log_tstamp_str, SRVBUFLEN, &bgp_misc_db->log_tstamp, TRUE,
Expand Down
5 changes: 5 additions & 0 deletions src/bmp/bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,11 @@ void skinny_bmp_daemon()
reload_log_bmp_thread = FALSE;
}

if (reload_log && !bmp_misc_db->is_thread) {
reload_logs();
reload_log = FALSE;
}

if (bmp_misc_db->msglog_backend_methods || bmp_misc_db->dump_backend_methods) {
gettimeofday(&bmp_misc_db->log_tstamp, NULL);
compose_timestamp(bmp_misc_db->log_tstamp_str, SRVBUFLEN, &bmp_misc_db->log_tstamp, TRUE,
Expand Down
5 changes: 5 additions & 0 deletions src/imt_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ void imt_plugin(int pipe_fd, struct configuration *cfgptr, void *ptr)
reload_map = FALSE;
}

if (reload_log) {
reload_logs();
reload_log = FALSE;
}

if (poll_fd[0].revents & POLLIN) {
#ifdef WITH_ZMQ
read_data:
Expand Down
5 changes: 5 additions & 0 deletions src/nfacctd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,11 @@ int main(int argc,char **argv, char **envp)
gettimeofday(&reload_map_tstamp, NULL);
}

if (reload_log) {
reload_logs();
reload_log = FALSE;
}

if (print_stats) {
time_t now = time(NULL);

Expand Down
5 changes: 5 additions & 0 deletions src/nfprobe_plugin/nfprobe_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,11 @@ void nfprobe_plugin(int pipe_fd, struct configuration *cfgptr, void *ptr)
reload_map = FALSE;
}

if (reload_log) {
reload_logs();
reload_log = FALSE;
}

recv_budget = 0;
if (poll_bypass) {
poll_bypass = FALSE;
Expand Down
5 changes: 5 additions & 0 deletions src/nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ void pcap_cb(u_char *user, const struct pcap_pkthdr *pkthdr, const u_char *buf)
gettimeofday(&reload_map_tstamp, NULL);
}

if (reload_log) {
reload_logs();
reload_log = FALSE;
}

if (cb_data->has_tun_prims && pptrs.tun_pptrs) {
struct packet_ptrs *tpptrs = (struct packet_ptrs *) pptrs.tun_pptrs;

Expand Down
5 changes: 5 additions & 0 deletions src/plugin_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ void P_cache_handle_flush_event(struct ports_table *pt)
load_ports(config.ports_file, pt);
reload_map = FALSE;
}

if (reload_log) {
reload_logs();
reload_log = FALSE;
}
}

void P_cache_mark_flush(struct chained_cache *queue[], int index, int exiting)
Expand Down
2 changes: 1 addition & 1 deletion src/pmacct-build.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define PMACCT_BUILD "20191120-00"
#define PMACCT_BUILD "20191122-00"
2 changes: 1 addition & 1 deletion src/pmacct-globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct utpl_field *(*get_ext_db_ie_by_type)(struct template_cache_entry *, u_int
char sll_mac[2][ETH_ADDR_LEN];
struct host_addr mcast_groups[MAX_MCAST_GROUPS];
int reload_map, reload_map_exec_plugins, reload_geoipv2_file;
int reload_map_bgp_thread, reload_log_bgp_thread;
int reload_map_bgp_thread, reload_log, reload_log_bgp_thread;
int reload_map_bmp_thread, reload_log_bmp_thread;
int reload_map_rpki_thread, reload_log_rpki_thread;
int reload_map_telemetry_thread, reload_log_telemetry_thread;
Expand Down
2 changes: 1 addition & 1 deletion src/pmacct.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ initsetproctitle(int, char**, char**);
extern char sll_mac[2][ETH_ADDR_LEN];
extern struct host_addr mcast_groups[MAX_MCAST_GROUPS];
extern int reload_map, reload_map_exec_plugins, reload_geoipv2_file;
extern int reload_map_bgp_thread, reload_log_bgp_thread;
extern int reload_map_bgp_thread, reload_log, reload_log_bgp_thread;
extern int reload_map_bmp_thread, reload_log_bmp_thread;
extern int reload_map_rpki_thread, reload_log_rpki_thread;
extern int reload_map_telemetry_thread, reload_log_telemetry_thread;
Expand Down
5 changes: 5 additions & 0 deletions src/sfacctd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,11 @@ int main(int argc,char **argv, char **envp)
gettimeofday(&reload_map_tstamp, NULL);
}

if (reload_log) {
reload_logs();
reload_log = FALSE;
}

if (reload_log_sf_cnt) {
int nodes_idx;

Expand Down
5 changes: 5 additions & 0 deletions src/sfprobe_plugin/sfprobe_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,11 @@ void sfprobe_plugin(int pipe_fd, struct configuration *cfgptr, void *ptr)
reload_map = FALSE;
}

if (reload_log) {
reload_logs();
reload_log = FALSE;
}

recv_budget = 0;
if (poll_bypass) {
poll_bypass = FALSE;
Expand Down
20 changes: 1 addition & 19 deletions src/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,29 +175,11 @@ void PM_sigint_handler(int signum)

void reload()
{
int logf;

if (config.syslog) {
closelog();
logf = parse_log_facility(config.syslog);
if (logf == ERR) {
config.syslog = NULL;
Log(LOG_WARNING, "WARN ( %s/%s ): specified syslog facility is not supported; logging to console.\n", config.name, config.type);
}
openlog(NULL, LOG_PID, logf);
Log(LOG_INFO, "INFO ( %s/%s ): Start logging ...\n", config.name, config.type);
}

if (config.logfile) {
fclose(config.logfile_fd);
config.logfile_fd = open_output_file(config.logfile, "a", FALSE);
}

reload_log = TRUE;
if (config.nfacctd_bgp_msglog_file) reload_log_bgp_thread = TRUE;
if (config.nfacctd_bmp_msglog_file) reload_log_bmp_thread = TRUE;
if (config.sfacctd_counter_file) reload_log_sf_cnt = TRUE;
if (config.telemetry_msglog_file) reload_log_telemetry_thread = TRUE;

}

void push_stats()
Expand Down
5 changes: 5 additions & 0 deletions src/sql_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,11 @@ void sql_cache_handle_flush_event(struct insert_data *idata, time_t *refresh_dea
load_ports(config.ports_file, pt);
reload_map = FALSE;
}

if (reload_log) {
reload_logs();
reload_log = FALSE;
}
}

struct db_cache *sql_cache_search(struct primitives_ptrs *prim_ptrs, time_t basetime)
Expand Down
5 changes: 5 additions & 0 deletions src/tee_plugin/tee_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ void tee_plugin(int pipe_fd, struct configuration *cfgptr, void *ptr)
reload_map = FALSE;
}

if (reload_log) {
reload_logs();
reload_log = FALSE;
}

recv_budget = 0;
if (poll_bypass) {
poll_bypass = FALSE;
Expand Down
5 changes: 5 additions & 0 deletions src/telemetry/telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ void telemetry_daemon(void *t_data_void)
reload_log_telemetry_thread = FALSE;
}

if (reload_log && !telemetry_misc_db->is_thread) {
reload_logs();
reload_log = FALSE;
}

if (telemetry_misc_db->msglog_backend_methods || telemetry_misc_db->dump_backend_methods) {
gettimeofday(&telemetry_misc_db->log_tstamp, NULL);
compose_timestamp(telemetry_misc_db->log_tstamp_str, SRVBUFLEN, &telemetry_misc_db->log_tstamp, TRUE,
Expand Down
21 changes: 21 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -3143,3 +3143,24 @@ char *null_terminate(char *str, int len)

return loc;
}

void reload_logs()
{
int logf;

if (config.syslog) {
closelog();
logf = parse_log_facility(config.syslog);
if (logf == ERR) {
config.syslog = NULL;
Log(LOG_WARNING, "WARN ( %s/%s ): specified syslog facility is not supported; logging to console.\n", config.name, config.type);
}
openlog(NULL, LOG_PID, logf);
Log(LOG_INFO, "INFO ( %s/%s ): Start logging ...\n", config.name, config.type);
}

if (config.logfile) {
fclose(config.logfile_fd);
config.logfile_fd = open_output_file(config.logfile, "a", FALSE);
}
}
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ extern void parse_hostport(const char *, struct sockaddr *, socklen_t *);
extern bool is_prime(u_int32_t);
extern u_int32_t next_prime(u_int32_t);
extern char *null_terminate(char *, int);
extern void reload_logs();

extern char *compose_json_str(void *);
extern void write_and_free_json(FILE *, void *);
Expand Down

0 comments on commit 6b74dfd

Please sign in to comment.