Skip to content

Commit

Permalink
logging: improve E_CORE_LOG suppression mechanism
Browse files Browse the repository at this point in the history
Do not stop all logs, to any logging consumer, from being printed when
handling the E_CORE_LOG event in the event consumers. Only suppress the
triggering of the event itself.

This also fixes the blocking of OpenSIPS when xlog() is used from the
event_route.
  • Loading branch information
rvlad-patrascu committed Jun 6, 2023
1 parent 91e40b5 commit a4bf044
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 29 deletions.
25 changes: 17 additions & 8 deletions dprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,21 +559,22 @@ static void event_dprint(int log_level, int facility, char *module, const char *
evi_params_p list = NULL;
str s;
int n;
static char in_progress = 0;
int suppressed;

/* prevent reentry from the same process */
if (in_progress)
suppressed = pt[process_no].suppress_log_event;

if (suppressed)
return;

in_progress = 1;
pt[process_no].suppress_log_event = 1;

if (!evi_probe_event(evi_log_id)) {
in_progress = 0;
pt[process_no].suppress_log_event = suppressed;
return;
}

if (!(list = evi_get_params())) {
in_progress = 0;
pt[process_no].suppress_log_event = suppressed;
return;
}

Expand Down Expand Up @@ -641,12 +642,12 @@ static void event_dprint(int log_level, int facility, char *module, const char *
evi_log_name.len, evi_log_name.s);
}

in_progress = 0;
pt[process_no].suppress_log_event = suppressed;

return;
end_free:
evi_free_params(list);
in_progress = 0;
pt[process_no].suppress_log_event = suppressed;
}

/* generic consumer that registers to the log interface */
Expand Down Expand Up @@ -948,4 +949,12 @@ void set_proc_log_level(int level)
__set_proc_log_level(process_no, level);
}

void suppress_proc_log_event(void)
{
pt[process_no].suppress_log_event = 1;
}

void reset_proc_log_event(void)
{
pt[process_no].suppress_log_event = 0;
}
6 changes: 6 additions & 0 deletions dprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ void set_proc_log_level(int level);
/* changes the logging level to the default value for the current process */
void reset_proc_log_level(void);

/* suppress the E_CORE_LOG event for new logs (useful when handling the event
* itself in an event consumer) */
void suppress_proc_log_event(void);

void reset_proc_log_event(void);

static inline char* dp_time(void)
{
time_t ltime;
Expand Down
10 changes: 6 additions & 4 deletions ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,14 @@ void ipc_handle_job(int fd)
return;
}

/* we shouldn't print any logs, in case we are handling
* an event_route IPC job for the E_CORE_LOG event */
/*
/* suppress the E_CORE_LOG event for the below log while handling
* the event itself */
suppress_proc_log_event();

LM_DBG("received job type %d[%s] from process %d\n",
job.handler_type, ipc_handlers[job.handler_type].name, job.snd_proc);
*/

reset_proc_log_event();

/* custom handling for RPC type */
if (job.handler_type==ipc_rpc_type) {
Expand Down
9 changes: 5 additions & 4 deletions modules/event_kafka/kafka_producer.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,20 +637,21 @@ static int handle_io(struct fd_map *fm, int idx, int event_type)

switch (fm->type) {
case F_KAFKA_JOB:
/* supppress any logs, in case we are handling the E_CORE_LOG event */
set_proc_log_level(L_ALERT-1);
/* suppress the E_CORE_LOG event for new logs while handling
* the event itself */
suppress_proc_log_event();

job = kafka_receive_job();
if (!job) {
LM_ERR("Cannot receive job\n");
reset_proc_log_level();
reset_proc_log_event();
return 0;
}

if (kafka_handle_job(job) != 0)
shm_free(job);

reset_proc_log_level();
reset_proc_log_event();
break;
case F_KAFKA_EVENT:
prod = (kafka_producer_t *)fm->data;
Expand Down
7 changes: 4 additions & 3 deletions modules/event_rabbitmq/rabbitmq_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,9 @@ void rmq_process(int rank)
rmq_init_reader();
rmq_send_t * rmqs;

/* supppress any logs, in case we are handling the E_CORE_LOG event */
set_proc_log_level(L_ALERT-1);
/* suppress the E_CORE_LOG event for new logs while handling
* the event itself */
suppress_proc_log_event();

/* waiting for commands */
for (;;) {
Expand Down Expand Up @@ -580,5 +581,5 @@ void rmq_process(int rank)
shm_free(rmqs);
}

reset_proc_log_level();
reset_proc_log_event();
}
7 changes: 4 additions & 3 deletions modules/event_route/route_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ static void route_received(int sender, void *param)
struct sip_msg* req;
route_send_t *route_s = (route_send_t *)param;

/* supppress any logs, in case we are handling the E_CORE_LOG event */
set_proc_log_level(L_ALERT-1);
/* suppress the E_CORE_LOG event for new logs while handling
* the event itself */
suppress_proc_log_event();

if (!ref_script_route_check_and_update(route_s->ev_route)){
LM_ERR("event route [%.s] no longer available in script\n",
Expand All @@ -153,7 +154,7 @@ static void route_received(int sender, void *param)
shm_free(route_s->ev_route);
shm_free(route_s);

reset_proc_log_level();
reset_proc_log_event();
}


Expand Down
9 changes: 5 additions & 4 deletions modules/event_stream/stream_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,19 +661,20 @@ static int handle_io(struct fd_map *fm, int idx, int event_type)

switch (fm->type) {
case F_EV_JSONRPC_CMD:
/* supppress any logs, in case we are handling the E_CORE_LOG event */
set_proc_log_level(L_ALERT-1);
/* suppress the E_CORE_LOG event for new logs while handling
* the event itself */
suppress_proc_log_event();

jsonrpcs = stream_receive();
if (!jsonrpcs) {
LM_ERR("invalid receive jsonrpc command\n");
reset_proc_log_level();
reset_proc_log_event();
return -1;
}

handle_new_stream(jsonrpcs);

reset_proc_log_level();
reset_proc_log_event();
break;
case F_EV_JSONRPC_RPL:
con = (struct stream_con *)fm->data;
Expand Down
7 changes: 4 additions & 3 deletions modules/event_xmlrpc/xmlrpc_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,9 @@ void xmlrpc_process(int rank)
xmlrpc_init_send_buf();
xmlrpc_send_t * xmlrpcs;

/* supppress any logs, in case we are handling the E_CORE_LOG event */
set_proc_log_level(L_ALERT-1);
/* suppress the E_CORE_LOG event for new logs while handling
* the event itself */
suppress_proc_log_event();

/* waiting for commands */
for (;;) {
Expand All @@ -544,5 +545,5 @@ void xmlrpc_process(int rank)
shm_free(xmlrpcs);
}

reset_proc_log_level();
reset_proc_log_event();
}
3 changes: 3 additions & 0 deletions pt.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ struct process_table {
int log_level;
/* used when resetting the log level */
int default_log_level;
/* used for suppressing the E_CORE_LOG event for new logs while handling
* the event itself */
int suppress_log_event;

/* statistics of this process - they do not change during runtime,
* even when the proc is terminated or respawn - we just hide/unhide */
Expand Down

0 comments on commit a4bf044

Please sign in to comment.