Kannel: Open Source WAP and SMS gateway  svn-r5335
log.c File Reference
#include "gwlib.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>

Go to the source code of this file.

Macros

#define MAX_LOGFILES   4096
 
#define THREADTABLE_SIZE   1024
 
#define thread_slot()   (gwthread_self() % THREADTABLE_SIZE)
 
#define MAX_LOGGABLE_PLACES   (10*1000)
 
#define FORMAT_SIZE   (1024)
 
#define FUNCTION_GUTS(level, place)
 
#define FUNCTION_GUTS_EXCL(level, place)
 

Enumerations

enum  {
  LOG_PID, LOG_DAEMON, LOG_DEBUG, LOG_INFO,
  LOG_WARNING, LOG_ERR, LOG_ALERT
}
 

Functions

static int decode (char *name)
 
static void openlog (const char *ident, int option, int facility)
 
static void syslog (int translog, const char *msg,...)
 
static void closelog (void)
 
static void add_stderr (void)
 
void log_init (void)
 
void log_shutdown (void)
 
void log_set_output_level (enum output_level level)
 
void log_set_log_level (enum output_level level)
 
void log_set_syslog_facility (char *facility)
 
void log_set_syslog (const char *ident, int syslog_level)
 
void log_reopen (void)
 
void log_close_all (void)
 
int log_open (char *filename, int level, enum excl_state excl)
 
static void format (char *buf, int level, const char *place, int e, const char *fmt, int with_timestamp_and_pid)
 
static void PRINTFLIKE (2, 0)
 
static void PRINTFLIKE (1, 0)
 
void gw_backtrace (void **stack_frames, size_t size, int lock)
 
void gw_panic (int err, const char *fmt,...)
 
void error (int err, const char *fmt,...)
 
void warning (int err, const char *fmt,...)
 
void info (int err, const char *fmt,...)
 
static int place_matches (const char *place, const char *pat)
 
static int place_should_be_logged (const char *place)
 
static int place_is_not_logged (const char *place)
 
void debug (const char *place, int err, const char *fmt,...)
 
void log_set_debug_places (const char *places)
 
void log_thread_to (int idx)
 

Variables

struct {
   FILE *   file
 
   int   minimum_output_level
 
   char   filename [FILENAME_MAX+1]
 
   enum excl_state   exclusive
 
logfiles [MAX_LOGFILES]
 
static int num_logfiles = 0
 
static unsigned int thread_to [(long) THREADTABLE_SIZE]
 
static char * loggable_places [MAX_LOGGABLE_PLACES]
 
static int num_places = 0
 
static RWLock rwlock
 
static int sysloglevel
 
static int syslogfacility = LOG_DAEMON
 
static int dosyslog = 0
 

Macro Definition Documentation

◆ FORMAT_SIZE

#define FORMAT_SIZE   (1024)

Definition at line 429 of file log.c.

Referenced by format().

◆ FUNCTION_GUTS

#define FUNCTION_GUTS (   level,
  place 
)
Value:
do { \
int i; \
int formatted = 0; \
char buf[FORMAT_SIZE]; \
va_list args; \
for (i = 0; i < num_logfiles; ++i) { \
level >= logfiles[i].minimum_output_level && \
logfiles[i].file != NULL) { \
if (!formatted) { \
format(buf, level, place, err, fmt, 1); \
formatted = 1; \
} \
va_start(args, fmt); \
output(logfiles[i].file, buf, args); \
va_end(args); \
} \
} \
gw_rwlock_unlock(&rwlock); \
if (dosyslog) { \
format(buf, level, place, err, fmt, 0); \
va_start(args, fmt); \
kannel_syslog(buf,args,level); \
va_end(args); \
} \
} while (0)
static struct @66 logfiles[MAX_LOGFILES]
static int dosyslog
Definition: log.c:211
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
int minimum_output_level
Definition: log.c:170
FILE * file
Definition: log.c:169
static RWLock rwlock
Definition: log.c:204
static int num_logfiles
Definition: log.c:174
#define FORMAT_SIZE
Definition: log.c:429
enum excl_state exclusive
Definition: log.c:172

Definition at line 544 of file log.c.

Referenced by debug(), error(), gw_panic(), info(), and warning().

◆ FUNCTION_GUTS_EXCL

#define FUNCTION_GUTS_EXCL (   level,
  place 
)
Value:
do { \
char buf[FORMAT_SIZE]; \
va_list args; \
if (logfiles[e].exclusive == GW_EXCL && \
level >= logfiles[e].minimum_output_level && \
logfiles[e].file != NULL) { \
format(buf, level, place, err, fmt, 1); \
va_start(args, fmt); \
output(logfiles[e].file, buf, args); \
va_end(args); \
} \
gw_rwlock_unlock(&rwlock); \
} while (0)
static struct @66 logfiles[MAX_LOGFILES]
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
int minimum_output_level
Definition: log.c:170
Definition: log.h:74
FILE * file
Definition: log.c:169
static RWLock rwlock
Definition: log.c:204
#define FORMAT_SIZE
Definition: log.c:429
enum excl_state exclusive
Definition: log.c:172

Definition at line 574 of file log.c.

Referenced by debug(), error(), info(), and warning().

◆ MAX_LOGFILES

#define MAX_LOGFILES   4096

Definition at line 167 of file log.c.

Referenced by log_open().

◆ MAX_LOGGABLE_PLACES

#define MAX_LOGGABLE_PLACES   (10*1000)

Definition at line 196 of file log.c.

Referenced by log_set_debug_places().

◆ thread_slot

#define thread_slot ( )    (gwthread_self() % THREADTABLE_SIZE)

Definition at line 189 of file log.c.

Referenced by debug(), error(), info(), log_thread_to(), and warning().

◆ THREADTABLE_SIZE

#define THREADTABLE_SIZE   1024

Definition at line 181 of file log.c.

Referenced by log_init().

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
LOG_PID 
LOG_DAEMON 
LOG_DEBUG 
LOG_INFO 
LOG_WARNING 
LOG_ERR 
LOG_ALERT 

Definition at line 141 of file log.c.

141  {
143 };
Definition: log.c:142
Definition: log.c:142
Definition: log.c:142
Definition: log.c:142
Definition: log.c:142

Function Documentation

◆ add_stderr()

static void add_stderr ( void  )
static

Definition at line 216 of file log.c.

References file, GW_DEBUG, GW_NON_EXCL, logfiles, and num_logfiles.

Referenced by log_init().

217 {
218  int i;
219 
220  for (i = 0; i < num_logfiles; ++i)
221  if (logfiles[i].file == stderr)
222  return;
223  logfiles[num_logfiles].file = stderr;
224  logfiles[num_logfiles].minimum_output_level = GW_DEBUG;
225  logfiles[num_logfiles].exclusive = GW_NON_EXCL;
226  ++num_logfiles;
227 }
static struct @66 logfiles[MAX_LOGFILES]
FILE * file
Definition: log.c:169
static int num_logfiles
Definition: log.c:174
Definition: log.h:69

◆ closelog()

static void closelog ( void  )
static

Definition at line 158 of file log.c.

Referenced by log_close_all().

159 {
160 }

◆ debug()

void debug ( const char *  place,
int  err,
const char *  fmt,
  ... 
)

Definition at line 726 of file log.c.

References FUNCTION_GUTS, FUNCTION_GUTS_EXCL, GW_DEBUG, place_is_not_logged(), place_should_be_logged(), thread_slot, and thread_to.

Referenced by abort_elapsed(), accept_thread(), acknowledge_from_rawmessage(), add_push_flag(), add_sar_transaction(), assembly_sar_event(), at2_check_sms_memory(), at2_detect_modem_type(), at2_detect_speed(), at2_extract_line(), at2_open_device(), at2_open_device1(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_encode(), at2_pdu_extract(), at2_read_delete_message(), at2_read_modems(), at2_read_sms_memory(), at2_send_messages(), at2_send_one_message(), at2_shutdown_cb(), at2_start_cb(), at2_wait_modem_command(), at2_write(), at2_write_ctrlz(), at2_write_line(), at_dial(), bb_reload_smsc_groups(), bb_shutdown(), bearerbox_to_smpp(), bearerbox_to_smsbox(), bearerbox_to_sql(), begin_sar_result(), boxc_receiver(), boxc_route_msg_to_smsc(), boxc_sender(), brunet_receive_sms(), brunet_send_sms(), cant_handle_event(), catenate_msg(), cfg_dump(), cfg_read(), cgw_sender(), cgw_shutdown_cb(), cgw_start_cb(), charset_convert(), check_application_headers(), check_login(), check_multipart(), cimd2_accept_message(), cimd2_get_packet(), cimd2_receive_msg(), cimd2_request(), cimd2_send_response(), cimd2_shutdown_cb(), cimd2_start_cb(), cimd2_stop_cb(), cimd2_submit_msg(), cimd_close(), cimd_open_connection(), cimd_pending_smsmessage(), cimd_receive_msg(), cimd_submit_msg(), clear_sent(), clickatell_receive_sms(), clickatell_send_sms(), client_create(), client_destroy(), client_read_status(), client_reset(), client_session(), client_thread(), concat_handling_check_and_handle(), concat_handling_cleanup(), concat_handling_clear_old_parts(), concat_handling_init(), config_reload(), confirm_push(), conn_pool_get(), connect_tcpip(), continue_sar_result(), convert_content(), cookie_destroy(), create_dlr_from_msg(), data_sm_to_msg(), decode_bearer_indication(), deconvert_content(), delayed_http_reply(), delivery_time_constraints(), dispatch_datagram(), dlr_add(), dlr_find(), dump_area(), dump_pdu(), dump_tpis(), elapse_timer(), emi2_handle_smscreq(), emi2_receiver(), emi2_sender(), emi_open_session(), emi_submit_msg(), emimsg_send(), empty_msg_lists(), event_semantically_valid(), expect_acknowledge(), expire_cookies(), fake_listener(), generic_destroy(), generic_init(), generic_parse_reply(), generic_receive_sms(), generic_send_sms(), get_cookies(), get_data(), get_fields(), get_header_value(), get_matching_translations(), get_ton_npi_value(), get_x_kannel_from_xml(), grp_dump(), gw_accept(), gw_check_check_leaks(), gw_dlopen_get_symbol(), gwthread_cancel(), gwthread_dumpsigmask(), gwthread_join_every(), gwthread_shutdown(), handle_dlr(), handle_erroneous_field_in(), handle_init_event(), handle_internal_event(), handle_method_event(), handle_ota_event(), handle_pdu(), handle_push_event(), handle_reply(), handle_session_event(), handle_split(), handle_submit_sm(), handle_transaction(), have_cookie(), http_accept_request(), http_cgivar_dump(), http_header_dump(), http_queue_thread(), http_use_proxy(), httpsmsc_receiver(), httpsmsc_send_cb(), httpsmsc_shutdown(), indicate_push_abort(), indicate_push_connection(), init_machine_create(), init_machine_destroy(), init_reroute(), init_smppbox(), init_smsbox_routes(), init_smsc_routes(), init_wapbox(), io_thread(), ip_allowed_by_ppg(), kannel_receive_sms(), kannel_send_sms(), log_set_syslog(), machine_create(), machine_destroy(), main(), main_connection_loop(), main_thread(), make_confirmed_push_request(), make_session_request(), make_unit_push_request(), memorybuffer_has_rawmessage(), meta_data_unpack(), method_machine_destroy(), mime_decompile(), mime_entity_body(), mime_entity_dump(), mime_entity_dump_real(), mime_something_to_entity(), msg_dump(), msg_to_bb(), msg_to_pdu(), my_dump(), n_messages_benchmark(), new_thread(), new_thread_cleanup(), normalize_charset(), numhash_create(), obey_request(), octstr_dump_debug(), octstr_dump_short(), octstr_shutdown(), ois_check_incoming(), ois_check_input(), ois_open_receiver(), ois_open_sender(), ois_read_into_buffer(), oisd_accept_message(), oisd_get_packet(), oisd_receive_msg(), oisd_request(), oisd_send_response(), oisd_shutdown_cb(), oisd_start_cb(), oisd_stop_cb(), oisd_submit_msg(), oneuser_dump(), OTAbitmap_create_stream(), pack_into_push_datagram(), pack_known_header(), packet_encode_message(), pap_request_thread(), parachute_start(), parse_address_value(), parse_attr_value(), parse_attribute(), parse_bad_message_response_value(), parse_cimd_to_iso88591(), parse_client_specifier(), parse_constant(), parse_document(), parse_dump(), parse_element(), parse_ext_qualifiers(), parse_global_phone_number(), parse_http_date(), parse_ipv4(), parse_ipv4_fragment(), parse_ipv6(), parse_iso88591_to_emi(), parse_msg_to_rawmessage(), parse_pap_value(), parse_progress_note_value(), parse_push_message_value(), parse_push_response_value(), parse_quality_of_service_value(), parse_response_result_value(), parse_url(), pdu_to_msg(), poller(), post_content_create(), proxy_thread(), push_client_event_handle(), push_client_machine_create(), push_client_machine_destroy(), push_client_machine_find_or_create(), push_machine_create(), push_machine_destroy(), radius_pdu_dump(), radius_pdu_unpack(), read_messages_from_bearerbox(), read_pdu(), receive_push_reply(), receive_reply(), receive_smpp_thread(), reconnect(), report_versions(), request_confirmed_push(), request_push(), request_unit_push(), resend_sar_result(), resp_event_handle(), resp_machine_create(), resp_machine_destroy(), resp_machine_find_or_create(), response(), response_push_connection(), retry_consumer_thread(), return_reply(), route_msg(), run_batch(), run_wapbox(), sema_msg_session_mt(), sema_open(), sema_pending_smsmessage(), sema_reopen(), sema_submit_msg(), send_acknowledge(), send_bad_message_response(), send_message(), send_messages(), send_msg(), send_pdu(), send_post(), send_push_response(), send_request(), send_smpp_thread(), sendsms_thread(), server(), server_thread(), session_machine_create(), session_machine_destroy(), set_any_value(), set_cookies(), shutdown_cb(), sigterm(), smasi_pdu_dump(), smpp_pdu_dump(), smpp_pdu_dump_line(), smpp_pdu_init(), sms_router(), sms_send(), sms_to_client(), smsbox_req_sendota(), smsbox_start(), smsbox_thread(), smsbox_to_bearerbox(), smsc2_cleanup(), smsc2_rout(), smsc_cimd2_create(), smsc_oisd_create(), smsc_soap_create(), smscconn_send(), soap_add_msg_cb(), soap_client_init_query(), soap_create_map(), soap_fetch_xml_data(), soap_listener(), soap_map_xml_data(), soap_msgdata_attribute(), soap_msgdata_deps(), soap_o2o_msgdata_attribute(), soap_parse_dlr(), soap_parse_mo(), soap_read_date(), soap_read_response(), soap_send_loop(), soap_server(), soap_server_start(), soap_server_stop(), soap_shutdown_cb(), soap_start_cb(), soap_stop_cb(), spawn_thread(), start_cb(), start_push(), start_request(), start_wap(), stop_initiator_timer(), store_file_dump(), store_push_data(), store_uuid(), string_to_versioned_number(), sustained_level_benchmark(), tcpip_connect_nb_to_server_with_port(), tcpip_connect_to_server_with_port(), tell_fatal_error(), thread1(), thread2(), tid_in_window(), timer_consumer_thread(), timestamp_to_minutes(), transform_message(), truncated_datagram(), udp_die(), udp_receiver(), udp_sender(), udp_shutdown(), udp_start(), udpc_create(), unpack_datagram(), unpack_wdp_datagram_real(), wait_for_ack(), wap_addr_tuple_dump(), wap_dispatch_datagram(), wap_event_assert(), wap_event_dump(), wap_map_url(), wap_msg_recv(), wap_msg_send(), wap_push_ppg_shutdown(), wapbox_start(), wbmp_create_stream(), wdp_to_wapboxes(), wina_bearer_identifier(), wml_compile(), wrapper_receiver(), wrapper_sender(), wrapper_shutdown(), wrapper_start(), wrapper_stop(), write_request_thread(), wsp_cap_dump(), wsp_cap_dump_list(), wsp_headers_pack(), wsp_headers_unpack(), wsp_pack_integer_string(), wsp_pack_version_value(), wsp_pdu_dump(), wsp_push_client_shutdown(), wsp_session_shutdown(), wtp_event_dump(), wtp_initiator_shutdown(), wtp_pdu_dump(), wtp_resp_shutdown(), wtp_tid_cache_shutdown(), wtp_tid_is_valid(), X28_open_send_link(), xidris_receive_sms(), and xidris_send_sms().

727 {
728  int e;
729 
730  if (place_should_be_logged(place) && place_is_not_logged(place) == 0) {
731  /*
732  * Note: giving `place' to FUNCTION_GUTS makes log lines
733  * too long and hard to follow. We'll rely on an external
734  * list of what places are used instead of reading them
735  * from the log file.
736  */
737  if ((e = thread_to[thread_slot()])) {
739  } else {
740  FUNCTION_GUTS(GW_DEBUG, "");
741  }
742  }
743 }
#define FUNCTION_GUTS_EXCL(level, place)
Definition: log.c:574
static unsigned int thread_to[(long) THREADTABLE_SIZE]
Definition: log.c:182
Definition: log.h:69
static int place_is_not_logged(const char *place)
Definition: log.c:711
#define thread_slot()
Definition: log.c:189
#define FUNCTION_GUTS(level, place)
Definition: log.c:544
static int place_should_be_logged(const char *place)
Definition: log.c:696

◆ decode()

static int decode ( char *  name)
static

Definition at line 145 of file log.c.

References LOG_DAEMON.

Referenced by log_set_syslog_facility().

146 {
147  return LOG_DAEMON;
148 }

◆ error()

void error ( int  err,
const char *  fmt,
  ... 
)

Definition at line 648 of file log.c.

References FUNCTION_GUTS, FUNCTION_GUTS_EXCL, GW_ERROR, thread_slot, and thread_to.

Referenced by add_group(), add_service(), alog_open(), alog_reopen(), at2_detect_modem_type(), at2_device_thread(), at2_init_device(), at2_open_device(), at2_open_device1(), at2_pdu_decode_deliver_sm(), at2_pdu_decode_report_sm(), at2_pdu_encode(), at2_read_buffer(), at2_read_delete_message(), at2_read_pending_incoming_messages(), at2_send_one_message(), at2_set_speed(), at2_wait_modem_command(), at2_write(), at2_write_ctrlz(), at2_write_line(), at_dial(), bb_graceful_restart(), bb_remove_message(), bearerbox_to_smpp(), block_user_signals(), boxc_sent_pop(), brunet_init(), brunet_parse_reply(), brunet_receive_sms(), cant_handle_event(), cfg_read(), cgw_listener(), cgw_open_listening_socket(), cgw_open_send_connection(), cgw_receiver(), cgw_sender(), cgw_wait_command(), change_user(), charset_convert(), check_application_headers(), check_config(), check_data_content_type_header(), check_data_x_wap_application_id_header(), check_do_elements(), check_marks(), check_variable_name(), check_variable_syntax(), cimd2_accept_message(), cimd2_get_packet(), cimd2_login(), cimd2_receive_msg(), cimd2_request(), cimd_close(), cimd_open(), cimd_open_connection(), cimd_pending_smsmessage(), cimd_receive_msg(), cimd_reopen(), cimd_submit_msg(), clickatell_parse_reply(), clickatell_receive_sms(), client_read_status(), client_session(), concat_handling_check_and_handle(), conn_destroy(), conn_flush(), conn_wait(), conn_wrap_fd(), convert_addr_from_pdu(), convert_charset(), copy_until_nul(), create_onetrans(), create_oneuser(), data_sm_to_msg(), date_parse_http(), decode_bearer_indication(), decode_binary_data(), deduce_body_state(), delayed_http_reply(), deliver_to_bearerbox_real(), dispatch(), dispatch_datagram(), dispatch_into_queue(), dlr_spool_add(), dlr_spool_get(), dlr_spool_remove(), do_queue_cleanup(), drop_from_free_ring(), emi2_handle_smscreq(), emi2_listener(), emi2_open_listening_socket(), emi2_receiver(), emi_fill_ucp60_login(), emi_open(), emi_open_session(), emi_receive_msg(), emi_reopen(), emi_submit_msg(), emimsg_send(), expect_acknowledge(), expire_cookies(), fake_listener(), fake_open_connection(), fdset_create_real(), fdset_destroy(), field_count_op(), field_count_reply(), fill_threadinfo(), find_area(), find_session_machine(), for_each_file(), generic_init(), generic_parse_reply(), generic_receive_sms(), get_connection(), get_cookies(), get_data(), get_fields(), get_header_value(), get_msg_filename(), get_variable(), get_x_kannel_from_xml(), gw_accept(), gw_dlopen_get_symbol(), gwthread_poll(), gwthread_pollfd(), handle_connect_reply(), handle_dlr(), handle_get_reply(), handle_init_event(), handle_mo_dcs(), handle_mt_dcs(), handle_operation(), handle_pdu(), handle_reply(), handle_transaction(), have_cookie(), headers_acceptable(), http_header_get(), httpsmsc_send(), httpsmsc_send_cb(), init_batch(), init_configuration(), init_machine_find_or_create(), init_reroute(), init_smsbox(), io_thread(), ip_allowed_by_ppg(), is_executable(), kannel_receive_sms(), log_open(), log_reopen(), main(), main_connection_loop(), main_for_producer_and_consumer(), main_loop(), make_server_socket(), memorybuffer_cut_rawmessage(), meta_data_merge(), meta_data_unpack(), mime_decompile(), msg_to_bb(), msg_to_emimsg(), msg_to_pdu(), msg_unpack_real(), mutex_trylock_real(), mutex_unlock_real(), numhash_add_number(), numhash_create(), obey_request(), obey_request_thread(), octstr_append_from_socket(), octstr_dump_real(), octstr_print(), octstr_read_file(), octstr_read_pipe(), octstr_write_data(), octstr_write_to_socket(), ois_check_deliver_sm_invoke(), ois_check_incoming(), ois_check_input(), ois_decode_deliver_sm_invoke(), ois_decode_submit_sm_result(), ois_deliver_sm_invoke(), ois_deliver_sm_result(), ois_extract_msg_from_buffer(), ois_open(), ois_open_listener(), ois_open_receiver(), ois_open_sender(), ois_reopen(), ois_submit_msg(), ois_submit_sm_invoke(), ois_submit_sm_result(), oisd_accept_message(), oisd_get_packet(), oisd_login(), oisd_receive_msg(), oisd_request(), open_connection(), open_file(), open_receiver(), open_send_connection(), open_transceiver(), open_transmitter(), ota_compile(), pack_challenge(), pack_content_disposition(), pack_content_range(), pack_credentials(), pack_known_header(), pack_md5(), pack_range(), pack_warning(), packet_display_error(), packet_extract(), packet_get_hex_parm(), packet_get_int_parm(), pap_compile(), pap_request_thread(), parachute_start(), parse_array_element(), parse_attr_value(), parse_attribute(), parse_body_part(), parse_cookie(), parse_data_element(), parse_date(), parse_document(), parse_element(), parse_fault_element(), parse_http_date(), parse_integer(), parse_member_element(), parse_methodcall_element(), parse_methodresponse_element(), parse_node(), parse_ota_syncsettings(), parse_param_element(), parse_params_element(), parse_preamble(), parse_rawmessage_to_msg(), parse_request_line(), parse_struct_element(), parse_text(), parse_url(), parse_value_element(), ParseError(), pass_extension_headers(), pass_optional_header(), pdu_to_msg(), poll_callback(), poller(), port_remove(), proxy_thread(), push_client_event_handle(), push_client_machine_find_or_create(), put_data(), radius_pdu_create(), radius_pdu_destroy(), radius_pdu_dump(), radius_pdu_pack(), radius_pdu_unpack(), read_data(), read_from_bearerbox_real(), read_from_box(), read_messages_from_bearerbox(), read_msg(), read_pdu(), read_test_ppg_config(), receive_push_reply(), receive_reply(), receive_request(), receive_smpp_thread(), reconnect(), remove_pid_file(), rename_store(), resp_event_handle(), resp_machine_find_or_create(), restart_box(), return_reply(), run_batch(), run_smppbox(), run_smsbox(), run_sqlbox(), run_wapbox(), sanitize_capabilities(), sema_msg_session_mo(), sema_msg_session_mt(), sema_msglist_push(), sema_open(), sema_pending_smsmessage(), sema_receive_msg(), sema_reopen(), sema_submit_msg(), sema_submit_result(), semaphore_up(), send_acknowledge(), send_msg(), send_post(), send_request(), send_udp(), server_thread(), set_cookies(), setup_official_name(), si_compile(), signal_handler(), sl_compile(), smasi_pdu_destroy(), smasi_pdu_pack(), smasi_thread(), smpp_emu_handle_pdu(), smpp_emu_reader(), smpp_error_to_string(), smpp_pdu_create(), smpp_pdu_destroy(), smpp_pdu_dump(), smpp_pdu_dump_line(), smpp_pdu_init(), smpp_pdu_pack(), smpp_pdu_read_len(), smpp_pdu_unpack(), smpp_to_bearerbox(), sms_charset_processing(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_req_sendsms(), smsbox_sendota_post(), smsbox_sendsms_post(), smsbox_start(), smsbox_thread(), smsbox_xmlrpc_post(), smsc2_add_smsc(), smsc2_reload_lists(), smsc2_remove_smsc(), smsc2_restart_smsc(), smsc2_rout(), smsc2_stop_smsc(), smsc_at2_create(), smsc_cgw_create(), smsc_cimd2_create(), smsc_emi2_create(), smsc_fake_create(), smsc_http_create(), smsc_oisd_create(), smsc_open(), smsc_smasi_create(), smsc_smpp_create(), smsc_soap_create(), smsc_wrapper_create(), smscconn_create(), smscenter_lock(), smscenter_pending_smsmessage(), smscenter_read_into_buffer(), smscenter_receive_msg(), smscenter_submit_msg(), soap_convert_token(), soap_format_xml(), soap_get_index(), soap_listener(), soap_msgdata_attribute(), soap_msgdata_deps(), soap_msgtype_deps(), soap_o2o_msgdata_attribute(), soap_parse_dlr(), soap_parse_mo(), soap_parse_response(), soap_release_dependences(), soap_select_function(), soap_server(), soap_server_start(), soap_start_cb(), soap_xmlnode_get_int64(), soap_xmlnode_get_long(), soap_xmlnode_get_octstr(), socket_set_blocking(), socket_set_nodelay(), spawn_thread(), sql_list(), sql_single(), start_client_threads(), start_fetch(), start_smsc(), store_file_load(), store_init(), store_spool_init(), store_spool_save(), tcpip_connect_nb_to_server_with_port(), tcpip_connect_to_server_with_port(), test_header_combine(), transform_message(), udp_bind(), udp_client_socket(), udp_create_address(), udp_receiver(), udp_recvfrom_flags(), udp_sendto(), udp_start(), udpc_create(), unlink_file(), unlocked_read(), unlocked_write(), unpack_cache_directive(), unpack_datagram(), unpack_parameter(), unpack_range_value(), unpack_warning_value(), unpack_wdp_datagram_real(), update_push_data_with_attribute(), update_table(), update_tables(), url_result_thread(), wait_for_ack(), wait_for_client(), wait_for_connections(), wap_msg_recv(), wap_msg_send(), wap_push_ppg_pushuser_authenticate(), wap_push_ppg_pushuser_client_phone_number_acceptable(), wapbox_start(), wbmp_create(), wbmp_create_stream(), wml_compile(), write_data(), write_to_bearerbox_real(), write_to_socket(), ws_asm_linearize(), ws_bc_decode(), ws_bc_encode(), ws_encode_buffer(), ws_pragma_use(), wsp_cap_pack_list(), wsp_cap_unpack_list(), wsp_convert_http_status_to_wsp_status(), wsp_pack_retry_after(), wtp_event_dump(), wtp_event_is_for_responder(), X28_close_send_link(), X28_data_read(), X28_data_send(), X28_open_data_link(), X28_open_send_link(), X28_reopen_data_link(), xidris_init(), xidris_parse_reply(), xidris_receive_sms(), xml_error(), xmlrpc_call_print(), xmlrpc_doc_add_value(), xmlrpc_doc_print(), xmlrpc_doc_send(), xmlrpc_get_faultcode(), xmlrpc_get_faultstring(), xmlrpc_response_add_param(), xmlrpc_response_get_faultcode(), xmlrpc_response_get_faultstring(), xmlrpc_scalar_create(), xmlrpc_scalar_get_content(), xmlrpc_value_get_content(), xmlrpc_value_set_content(), and xmlrpc_value_set_type().

649 {
650  int e;
651 
652  if ((e = thread_to[thread_slot()])) {
654  } else {
655  FUNCTION_GUTS(GW_ERROR, "");
656  }
657 }
#define FUNCTION_GUTS_EXCL(level, place)
Definition: log.c:574
static unsigned int thread_to[(long) THREADTABLE_SIZE]
Definition: log.c:182
Definition: log.h:69
#define thread_slot()
Definition: log.c:189
#define FUNCTION_GUTS(level, place)
Definition: log.c:544

◆ format()

static void format ( char *  buf,
int  level,
const char *  place,
int  e,
const char *  fmt,
int  with_timestamp_and_pid 
)
static

Definition at line 430 of file log.c.

References FORMAT_SIZE, gw_gmtime(), gw_localtime(), gwthread_self(), and gwthread_self_ids().

432 {
433  static char *tab[] = {
434  "DEBUG: ",
435  "INFO: ",
436  "WARNING: ",
437  "ERROR: ",
438  "PANIC: ",
439  "LOG: "
440  };
441  static int tab_size = sizeof(tab) / sizeof(tab[0]);
442  time_t t;
443  struct tm tm;
444  char *p, prefix[1024];
445  long tid, pid;
446 
447  p = prefix;
448 
449  if (with_timestamp_and_pid) {
450  time(&t);
451 #if LOG_TIMESTAMP_LOCALTIME
452  tm = gw_localtime(t);
453 #else
454  tm = gw_gmtime(t);
455 #endif
456  sprintf(p, "%04d-%02d-%02d %02d:%02d:%02d ",
457  tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
458  tm.tm_hour, tm.tm_min, tm.tm_sec);
459 
460  p = strchr(p, '\0');
461 
462  /* print PID and thread ID */
463  gwthread_self_ids(&tid, &pid);
464  sprintf(p, "[%ld] [%ld] ", pid, tid);
465  } else {
466  /* thread ID only */
467  tid = gwthread_self();
468  sprintf(p, "[%ld] ", tid);
469  }
470 
471  p = strchr(p, '\0');
472  if (level < 0 || level >= tab_size)
473  sprintf(p, "UNKNOWN: ");
474  else
475  sprintf(p, "%s", tab[level]);
476 
477  p = strchr(p, '\0');
478  if (place != NULL && *place != '\0')
479  sprintf(p, "%s: ", place);
480 
481  if (strlen(prefix) + strlen(fmt) > FORMAT_SIZE / 2) {
482  sprintf(buf, "%s <OUTPUT message too long>\n", prefix);
483  return;
484  }
485 
486  if (e == 0)
487  sprintf(buf, "%s%s\n", prefix, fmt);
488  else
489  sprintf(buf, "%s%s\n%sSystem error %d: %s\n",
490  prefix, fmt, prefix, e, strerror(e));
491 }
long gwthread_self(void)
struct tm gw_gmtime(time_t t)
Definition: protected.c:137
void gwthread_self_ids(long *tid, long *pid)
#define FORMAT_SIZE
Definition: log.c:429
struct tm gw_localtime(time_t t)
Definition: protected.c:121

◆ gw_backtrace()

void gw_backtrace ( void **  stack_frames,
size_t  size,
int  lock 
)

Definition at line 599 of file log.c.

References gw_native_free(), and size.

Referenced by fatal_handler(), and gw_panic().

600 {
601 #if HAVE_BACKTRACE
602  void *frames[50];
603  size_t i;
604  char **strings;
605 
606  if (stack_frames == NULL) {
607  stack_frames = frames;
608  size = backtrace(stack_frames, sizeof(frames) / sizeof(void*));
609  }
610 
611  strings = backtrace_symbols(stack_frames, size);
612 
613  if (strings) {
614  for (i = 0; i < size; i++)
615  gw_panic_output(0, "%s", strings[i]);
616  }
617  else { /* hmm, no memory available */
618  for (i = 0; i < size; i++)
619  gw_panic_output(0, "%p", stack_frames[i]);
620  }
621 
622  /*
623  * Note: we must call gw_native_free directly because if gw_free points to gw_check_free we could
624  * panic's and we have endless loop with SEGFAULT at the end.
625  */
626  gw_native_free(strings);
627 #endif
628 }
int size
Definition: wsasm.c:84
void gw_native_free(void *ptr)
Definition: gwmem-native.c:123

◆ gw_panic()

void gw_panic ( int  err,
const char *  fmt,
  ... 
)

Definition at line 630 of file log.c.

References FUNCTION_GUTS, gw_backtrace(), and GW_PANIC.

631 {
632  /*
633  * we don't want PANICs to spread accross smsc logs, so
634  * this will be always within the main core log.
635  */
636  FUNCTION_GUTS(GW_PANIC, "");
637 
638  gw_backtrace(NULL, 0, 0);
639 
640 #ifdef SEGFAULT_PANIC
641  *((char*)0) = 0;
642 #endif
643 
644  exit(EXIT_FAILURE);
645 }
void gw_backtrace(void **stack_frames, size_t size, int lock)
Definition: log.c:599
#define FUNCTION_GUTS(level, place)
Definition: log.c:544
Definition: log.h:69

◆ info()

void info ( int  err,
const char *  fmt,
  ... 
)

Definition at line 672 of file log.c.

References FUNCTION_GUTS, FUNCTION_GUTS_EXCL, GW_INFO, thread_slot, and thread_to.

Referenced by accept_boxc(), accept_smpp(), alog_open(), at2_close_device(), at2_detect_modem_type(), at2_detect_speed(), at2_device_thread(), at2_init_device(), at2_login_device(), at2_open_device1(), at2_read_modems(), at2_read_pending_incoming_messages(), at2_set_speed(), at_dial(), authorise_username(), bb_graceful_restart(), bb_smscconn_receive(), bearerbox_to_smpp(), cgw_handle_op(), cgw_listener(), cgw_open_send_connection(), cgw_read_op(), cgw_receiver(), cgw_send_loop(), cgw_wait_command(), cgwop_add(), check_login(), cimd2_accept_message(), cimd2_login(), cimd2_logout(), client(), client_session(), client_thread(), config_reload(), conn_config_ssl(), connect_to_bearerbox_real(), create_onetrans(), deliver_unit_push(), delivery_time_constraints(), dlr_flush(), dlr_init(), emi2_handle_smscreq(), emi2_idleprocessing(), emi2_idletimeout_handling(), emi2_listener(), emi2_receiver(), emi2_send_loop(), emi_close_ip(), emi_open_session(), emi_submit_msg(), empty_msg_lists(), eq_log(), expect_acknowledge(), fake_listener(), find_hb(), get_and_set_debugs(), get_cookies(), get_data(), handle_operation(), handle_pdu(), handle_push_message(), handle_submit_sm(), heartbeat_start(), heartbeat_stop(), heartbeat_thread(), help(), http_open_port_if(), httpadmin_run(), httpsmsc_receiver(), init_batch(), init_machine_find_or_create(), init_reroute(), init_smppbox(), init_smsbox(), init_sqlbox(), init_wapbox(), log_open(), log_set_log_level(), log_thread_to(), main(), main_connection_loop(), mutex_destroy(), numhash_create(), obey_request_thread(), octstr_dump_real(), oisd_accept_message(), oisd_login(), open_send_connection(), ota_pack_message(), pap_request_thread(), parachute_sig_handler(), parachute_start(), parse_address(), parse_document(), producer(), proxy_thread(), push_thread(), radius_acct_init(), radius_acct_shutdown(), read_from_box(), read_messages_from_bearerbox(), reconnect(), reload_bool(), reload_int(), resp_machine_find_or_create(), run_batch(), run_requests(), run_smppbox(), sema_decode_msg(), sema_msg_session_mo(), sema_msg_session_mt(), sema_msglist_pop(), sema_msglist_push(), sema_submit_msg(), send_file(), send_message(), send_smpp_thread(), sendsms_thread(), server(), smppboxc_run(), smsbox_req_handle(), smsbox_req_sendota(), smsbox_sendota_post(), smsbox_start(), smsbox_thread(), smsc2_graceful_restart(), smsc2_restart_smsc(), smsc2_rout(), smsc2_start(), smsc2_status(), smsc2_stop_smsc(), smsc_at2_create(), smsc_cgw_create(), smsc_emi2_create(), smsc_http_create(), smsc_soap_create(), smscconn_create(), start_fetch(), start_request(), store_file_load(), store_spool_load(), udp_addwdp_from_client(), udp_receiver(), udp_sender(), udp_start(), update_table(), update_tables(), wait_for_client(), wap_msg_recv(), wapbox_start(), wsp_headers_unpack(), wtp_event_dump(), wtp_tid_is_valid(), X28_open_data_link(), and X28_open_send_link().

673 {
674  int e;
675 
676  if ((e = thread_to[thread_slot()])) {
678  } else {
679  FUNCTION_GUTS(GW_INFO, "");
680  }
681 }
#define FUNCTION_GUTS_EXCL(level, place)
Definition: log.c:574
static unsigned int thread_to[(long) THREADTABLE_SIZE]
Definition: log.c:182
Definition: log.h:69
#define thread_slot()
Definition: log.c:189
#define FUNCTION_GUTS(level, place)
Definition: log.c:544

◆ log_close_all()

void log_close_all ( void  )

Definition at line 341 of file log.c.

References closelog(), dosyslog, file, filename, gw_rwlock_unlock(), gw_rwlock_wrlock(), logfiles, num_logfiles, and rwlock.

Referenced by get_and_set_debugs(), log_shutdown(), and main().

342 {
343  /*
344  * Writer lock.
345  */
347 
348  while (num_logfiles > 0) {
349  --num_logfiles;
350  if (logfiles[num_logfiles].file != stderr && logfiles[num_logfiles].file != NULL) {
351  int i;
352  /* look for the same filename and set file to NULL */
353  for (i = num_logfiles - 1; i >= 0; i--) {
354  if (strcmp(logfiles[num_logfiles].filename, logfiles[i].filename) == 0)
355  logfiles[i].file = NULL;
356  }
357  fclose(logfiles[num_logfiles].file);
358  logfiles[num_logfiles].file = NULL;
359  }
360  }
361 
362  /*
363  * Unlock writer.
364  */
366 
367  /* close syslog if used */
368  if (dosyslog) {
369  closelog();
370  dosyslog = 0;
371  }
372 }
static struct @66 logfiles[MAX_LOGFILES]
static int dosyslog
Definition: log.c:211
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
FILE * file
Definition: log.c:169
static RWLock rwlock
Definition: log.c:204
static int num_logfiles
Definition: log.c:174
static void closelog(void)
Definition: log.c:158
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
char filename[FILENAME_MAX+1]
Definition: log.c:171

◆ log_init()

void log_init ( void  )

Definition at line 230 of file log.c.

References add_stderr(), gw_rwlock_init_static(), rwlock, thread_to, and THREADTABLE_SIZE.

Referenced by gwlib_init().

231 {
232  unsigned long i;
233 
234  /* Initialize rwlock */
236 
237  /* default all possible thread to logging index 0, stderr */
238  for (i = 0; i < THREADTABLE_SIZE; i++) {
239  thread_to[i] = 0;
240  }
241 
242  add_stderr();
243 }
#define THREADTABLE_SIZE
Definition: log.c:181
static unsigned int thread_to[(long) THREADTABLE_SIZE]
Definition: log.c:182
static RWLock rwlock
Definition: log.c:204
static void add_stderr(void)
Definition: log.c:216
void gw_rwlock_init_static(RWLock *lock)
Definition: gw-rwlock.c:96

◆ log_open()

int log_open ( char *  filename,
int  level,
enum excl_state  excl 
)

Definition at line 375 of file log.c.

References error(), filename, gw_rwlock_unlock(), gw_rwlock_wrlock(), info(), logfiles, MAX_LOGFILES, num_logfiles, and rwlock.

Referenced by get_and_set_debugs(), init_bearerbox(), init_smppbox(), init_smsbox(), init_sqlbox(), init_wapbox(), main(), and smscconn_create().

376 {
377  FILE *f = NULL;
378  int i;
379 
381 
382  if (num_logfiles == MAX_LOGFILES) {
384  error(0, "Too many log files already open, not adding `%s'",
385  filename);
386  return -1;
387  }
388 
389  if (strlen(filename) > FILENAME_MAX) {
391  error(0, "Log filename too long: `%s'.", filename);
392  return -1;
393  }
394 
395  /*
396  * Check if the file is already opened for logging.
397  * If there is an open file, then assign the file descriptor
398  * that is already existing for this log file.
399  */
400  for (i = 0; i < num_logfiles && f == NULL; ++i) {
401  if (strcmp(logfiles[i].filename, filename) == 0)
402  f = logfiles[i].file;
403  }
404 
405  /* if not previously opened, then open it now */
406  if (f == NULL) {
407  f = fopen(filename, "a");
408  if (f == NULL) {
410  error(errno, "Couldn't open logfile `%s'.", filename);
411  return -1;
412  }
413  }
414 
415  logfiles[num_logfiles].file = f;
416  logfiles[num_logfiles].minimum_output_level = level;
417  logfiles[num_logfiles].exclusive = excl;
419  ++num_logfiles;
420  i = num_logfiles - 1;
422 
423  info(0, "Added logfile `%s' with level `%d'.", filename, level);
424 
425  return i;
426 }
void error(int err, const char *fmt,...)
Definition: log.c:648
void info(int err, const char *fmt,...)
Definition: log.c:672
static struct @66 logfiles[MAX_LOGFILES]
#define MAX_LOGFILES
Definition: log.c:167
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
static RWLock rwlock
Definition: log.c:204
static int num_logfiles
Definition: log.c:174
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
char filename[FILENAME_MAX+1]
Definition: log.c:171

◆ log_reopen()

void log_reopen ( void  )

Definition at line 297 of file log.c.

References error(), file, filename, found, gw_rwlock_unlock(), gw_rwlock_wrlock(), logfiles, num_logfiles, and rwlock.

Referenced by main(), and signal_handler().

298 {
299  int i, j, found;
300 
301  /*
302  * Writer lock.
303  */
305 
306  for (i = 0; i < num_logfiles; ++i) {
307  if (logfiles[i].file != stderr) {
308  found = 0;
309 
310  /*
311  * Reverse seek for allready reopened logfile.
312  * If we find a previous file descriptor for the same file
313  * name, then don't reopen that duplicate, but assign the
314  * file pointer to it.
315  */
316  for (j = i-1; j >= 0 && found == 0; j--) {
317  if (strcmp(logfiles[i].filename, logfiles[j].filename) == 0) {
318  logfiles[i].file = logfiles[j].file;
319  found = 1;
320  }
321  }
322  if (found)
323  continue;
324  if (logfiles[i].file != NULL)
325  fclose(logfiles[i].file);
326  logfiles[i].file = fopen(logfiles[i].filename, "a");
327  if (logfiles[i].file == NULL) {
328  error(errno, "Couldn't re-open logfile `%s'.",
329  logfiles[i].filename);
330  }
331  }
332  }
333 
334  /*
335  * Unlock writer.
336  */
338 }
void error(int err, const char *fmt,...)
Definition: log.c:648
static struct @66 logfiles[MAX_LOGFILES]
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
FILE * file
Definition: log.c:169
static struct pid_list * found
static RWLock rwlock
Definition: log.c:204
static int num_logfiles
Definition: log.c:174
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
char filename[FILENAME_MAX+1]
Definition: log.c:171

◆ log_set_debug_places()

void log_set_debug_places ( const char *  places)

Definition at line 746 of file log.c.

References loggable_places, MAX_LOGGABLE_PLACES, and num_places.

Referenced by get_and_set_debugs().

747 {
748  char *p;
749 
750  p = strtok(gw_strdup(places), " ,");
751  num_places = 0;
752  while (p != NULL && num_places < MAX_LOGGABLE_PLACES) {
754  p = strtok(NULL, " ,");
755  }
756 }
static int num_places
Definition: log.c:198
static char * loggable_places[MAX_LOGGABLE_PLACES]
Definition: log.c:197
#define MAX_LOGGABLE_PLACES
Definition: log.c:196

◆ log_set_log_level()

void log_set_log_level ( enum output_level  level)

Definition at line 265 of file log.c.

References file, filename, info(), logfiles, and num_logfiles.

Referenced by config_reload(), and httpd_loglevel().

266 {
267  int i;
268 
269  /* change everything but stderr */
270  for (i = 0; i < num_logfiles; ++i) {
271  if (logfiles[i].file != stderr) {
272  logfiles[i].minimum_output_level = level;
273  info(0, "Changed logfile `%s' to level `%d'.", logfiles[i].filename, level);
274  }
275  }
276 }
void info(int err, const char *fmt,...)
Definition: log.c:672
static struct @66 logfiles[MAX_LOGFILES]
FILE * file
Definition: log.c:169
static int num_logfiles
Definition: log.c:174
char filename[FILENAME_MAX+1]
Definition: log.c:171

◆ log_set_output_level()

void log_set_output_level ( enum output_level  level)

Definition at line 253 of file log.c.

References file, logfiles, and num_logfiles.

Referenced by get_and_set_debugs(), and main().

254 {
255  int i;
256 
257  for (i = 0; i < num_logfiles; ++i) {
258  if (logfiles[i].file == stderr) {
259  logfiles[i].minimum_output_level = level;
260  break;
261  }
262  }
263 }
static struct @66 logfiles[MAX_LOGFILES]
FILE * file
Definition: log.c:169
static int num_logfiles
Definition: log.c:174

◆ log_set_syslog()

void log_set_syslog ( const char *  ident,
int  syslog_level 
)

Definition at line 284 of file log.c.

References debug(), dosyslog, LOG_PID, openlog(), syslogfacility, and sysloglevel.

Referenced by get_and_set_debugs(), init_bearerbox(), init_smsbox(), init_wapbox(), and remove_pid_file().

285 {
286  if (ident == NULL)
287  dosyslog = 0;
288  else {
289  dosyslog = 1;
290  sysloglevel = syslog_level;
291  openlog(ident, LOG_PID, syslogfacility);
292  debug("gwlib.log", 0, "Syslog logging enabled.");
293  }
294 }
static int dosyslog
Definition: log.c:211
static void openlog(const char *ident, int option, int facility)
Definition: log.c:150
static int sysloglevel
Definition: log.c:209
Definition: log.c:142
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
static int syslogfacility
Definition: log.c:210

◆ log_set_syslog_facility()

void log_set_syslog_facility ( char *  facility)

Definition at line 278 of file log.c.

References decode(), and syslogfacility.

Referenced by init_bearerbox(), init_smsbox(), and init_wapbox().

279 {
280  if (facility != NULL)
281  syslogfacility = decode(facility);
282 }
static int decode(char *name)
Definition: log.c:145
static int syslogfacility
Definition: log.c:210

◆ log_shutdown()

void log_shutdown ( void  )

Definition at line 245 of file log.c.

References gw_rwlock_destroy(), log_close_all(), and rwlock.

Referenced by gwlib_shutdown().

246 {
247  log_close_all();
248  /* destroy rwlock */
250 }
void gw_rwlock_destroy(RWLock *lock)
Definition: gw-rwlock.c:112
static RWLock rwlock
Definition: log.c:204
void log_close_all(void)
Definition: log.c:341

◆ log_thread_to()

void log_thread_to ( int  idx)

Definition at line 759 of file log.c.

References filename, info(), logfiles, minimum_output_level, num_logfiles, thread_slot, thread_to, and warning().

Referenced by at2_device_thread(), cgw_listener(), cgw_sender(), emi2_listener(), emi2_sender(), fake_listener(), httpsmsc_receiver(), httpsmsc_send_cb(), httpsmsc_sender(), io_thread(), smasi_thread(), wrapper_receiver(), and wrapper_sender().

760 {
761  long thread_id = thread_slot();
762 
763  if (idx > 0) {
764  info(0, "Logging thread `%ld' to logfile `%s' with level `%d'.",
765  thread_id, logfiles[idx].filename, logfiles[idx].minimum_output_level);
766  thread_to[thread_id] = idx;
767  } else if (idx != 0 && num_logfiles > 0) {
768  warning(0, "Logging thread `%ld' to logfile `%s' with level `%d'.",
769  thread_id, logfiles[0].filename, logfiles[0].minimum_output_level);
770  }
771 }
void info(int err, const char *fmt,...)
Definition: log.c:672
static struct @66 logfiles[MAX_LOGFILES]
static unsigned int thread_to[(long) THREADTABLE_SIZE]
Definition: log.c:182
int minimum_output_level
Definition: log.c:170
static int num_logfiles
Definition: log.c:174
void warning(int err, const char *fmt,...)
Definition: log.c:660
char filename[FILENAME_MAX+1]
Definition: log.c:171
#define thread_slot()
Definition: log.c:189

◆ openlog()

static void openlog ( const char *  ident,
int  option,
int  facility 
)
static

Definition at line 150 of file log.c.

Referenced by log_set_syslog().

151 {
152 }

◆ place_is_not_logged()

static int place_is_not_logged ( const char *  place)
static

Definition at line 711 of file log.c.

References loggable_places, num_places, and place_matches().

Referenced by debug().

712 {
713  int i;
714 
715  if (num_places == 0)
716  return 0;
717  for (i = 0; i < num_places; ++i) {
718  if (*loggable_places[i] == '-' &&
719  place_matches(place, loggable_places[i]+1))
720  return 1;
721  }
722  return 0;
723 }
static int num_places
Definition: log.c:198
static char * loggable_places[MAX_LOGGABLE_PLACES]
Definition: log.c:197
static int place_matches(const char *place, const char *pat)
Definition: log.c:684

◆ place_matches()

static int place_matches ( const char *  place,
const char *  pat 
)
static

Definition at line 684 of file log.c.

Referenced by place_is_not_logged(), and place_should_be_logged().

685 {
686  size_t len;
687 
688  len = strlen(pat);
689  if (pat[len-1] == '*')
690  return (strncasecmp(place, pat, len - 1) == 0);
691 
692  return (strcasecmp(place, pat) == 0);
693 }

◆ place_should_be_logged()

static int place_should_be_logged ( const char *  place)
static

Definition at line 696 of file log.c.

References loggable_places, num_places, and place_matches().

Referenced by debug().

697 {
698  int i;
699 
700  if (num_places == 0)
701  return 1;
702  for (i = 0; i < num_places; ++i) {
703  if (*loggable_places[i] != '-' &&
704  place_matches(place, loggable_places[i]))
705  return 1;
706  }
707  return 0;
708 }
static int num_places
Definition: log.c:198
static char * loggable_places[MAX_LOGGABLE_PLACES]
Definition: log.c:197
static int place_matches(const char *place, const char *pat)
Definition: log.c:684

◆ PRINTFLIKE() [1/2]

static void PRINTFLIKE ( ,
 
)
static

Definition at line 494 of file log.c.

495 {
496  vfprintf(f, buf, args);
497  fflush(f);
498 }

◆ PRINTFLIKE() [2/2]

static void PRINTFLIKE ( ,
 
)
static

Definition at line 501 of file log.c.

References dosyslog, GW_DEBUG, GW_ERROR, GW_INFO, GW_PANIC, GW_WARNING, LOG_ALERT, LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_WARNING, syslog(), and sysloglevel.

502 {
503  char buf[4096]; /* Trying to syslog more than 4K could be bad */
504  int translog;
505 
506  if (level >= sysloglevel && dosyslog) {
507  vsnprintf(buf, sizeof(buf), format, args);
508  /* XXX vsnprint not 100% portable */
509 
510  switch(level) {
511  case GW_DEBUG:
512  translog = LOG_DEBUG;
513  break;
514  case GW_INFO:
515  translog = LOG_INFO;
516  break;
517  case GW_WARNING:
518  translog = LOG_WARNING;
519  break;
520  case GW_ERROR:
521  translog = LOG_ERR;
522  break;
523  case GW_PANIC:
524  translog = LOG_ALERT;
525  break;
526  default:
527  translog = LOG_INFO;
528  break;
529  }
530  syslog(translog, "%s", buf);
531  }
532 }
Definition: log.c:142
static int dosyslog
Definition: log.c:211
static int sysloglevel
Definition: log.c:209
Definition: log.h:69
Definition: log.h:69
Definition: log.h:69
static void syslog(int translog, const char *msg,...)
Definition: log.c:154
Definition: log.h:69
Definition: log.c:142
Definition: log.c:142
Definition: log.c:142
Definition: log.h:69

◆ syslog()

static void syslog ( int  translog,
const char *  msg,
  ... 
)
static

Definition at line 154 of file log.c.

Referenced by PRINTFLIKE().

155 {
156 }

◆ warning()

void warning ( int  err,
const char *  fmt,
  ... 
)

Definition at line 660 of file log.c.

References FUNCTION_GUTS, FUNCTION_GUTS_EXCL, GW_WARNING, thread_slot, and thread_to.

Referenced by add_item(), add_msisdn(), add_x_wap_tod(), alog_open(), at2_open_device1(), authorise_username(), bb_reload_smsc_groups(), bb_smscconn_receive_internal(), bb_smscconn_send_failed(), bearerbox_to_smpp(), boxc_receiver(), cant_handle_event(), cfg_get_bool(), cgw_check_acks(), cgw_listener(), charset_convert(), charset_gsm_to_utf8(), charset_utf8_to_gsm(), check_config(), check_reversible(), check_variable_syntax(), cimd2_close_socket(), cimd2_destroy(), cimd2_get_packet(), cimd2_handle_request(), cimd2_login(), cimd2_receive_msg(), cimd2_request(), cimd2_send_alive(), cimd_submit_msg(), client_session(), concat_handling_check_and_handle(), concat_handling_clear_old_parts(), config_reload(), conn_read_withlen(), convert_addr_from_pdu(), convert_cimd2_to_gsm(), convert_si_to_sic(), convert_sl_to_slc(), convert_wml_to_wmlc(), convert_wmlscript_to_wmlscriptc(), copy_until_assign(), copy_until_coma(), copy_until_nul(), create_onetrans(), create_oneuser(), date_format_http(), deliver_sms_to_queue(), destroy_methodmachines(), destroy_pushmachines(), dispatch_datagram(), dlr_add(), dlr_find(), dlr_init(), do_queue_cleanup(), emi2_idleprocessing(), emi2_listener(), emi2_send_loop(), empty_msg_lists(), fake_listener(), fdset_destroy(), fdset_listen(), fdset_unregister(), fill_message(), generic_init(), generic_parse_reply(), generic_receive_sms(), get_fields(), get_mime_boundary(), get_pattern(), get_x_kannel_from_headers(), gw_check_area_size(), gwthread_dumpsigmask(), gwthread_join(), gwthread_join_every(), gwthread_shutdown(), gwthread_sleep(), gwthread_sleep_micro(), handle_dlr(), handle_method_event(), handle_operation(), handle_pdu(), handle_push_event(), handle_push_message(), handle_split(), headers_acceptable(), heartbeat_stop(), http_header_quoted_string_len(), httpsmsc_send_cb(), init_bearerbox(), init_smppbox(), io_thread(), ip_allowed_by_ppg(), ip_allowed_by_user(), log_thread_to(), main(), main_for_producer_and_consumer(), main_loop(), main_thread(), mime_decompile(), mime_parse(), msg_to_bb(), normalize_charset(), numhash_create(), obey_request_thread(), octstr_base64_to_binary(), octstr_dump_real(), octstr_url_decode(), ois_check_input(), ois_close(), ois_disconnect(), ois_disconnect_all(), ois_pending_smsmessage(), ois_submit_msg(), oisd_accept_message(), oisd_close_socket(), oisd_destroy(), oisd_get_packet(), oisd_login(), oisd_receive_msg(), oisd_request(), oisd_send_delivery_request(), ota_pack_push_headers(), pack_accept_encoding(), pack_challenge(), pack_content_disposition(), pack_content_range(), pack_credentials(), pack_range(), pack_warning(), packet_add_parm(), packet_check(), packet_check_can_receive(), packet_check_header(), packet_check_parameter(), packet_encode_message(), packet_extract(), pap_compile(), pap_request_thread(), parse_address(), parse_attribute(), parse_bearer(), parse_code(), parse_date(), parse_delivery_method(), parse_document(), parse_element(), parse_network(), parse_node(), parse_ota_syncsettings(), parse_priority(), parse_requirement(), parse_state(), ParseWarning(), pass_data_headers(), port_add(), proxy_thread(), proxy_unpack_credentials(), read_available(), read_messages_from_bearerbox(), receive_push_reply(), retry_consumer_thread(), return_reply(), route_incoming_to_boxc(), route_msg(), sanitize_capabilities(), send_file(), send_post(), send_request(), server_thread(), set_dlr_mask(), signal_handler(), skip_until_after_colon(), smasi_pdu_create(), smasi_pdu_dump(), smasi_pdu_unpack(), smpp_emu(), sms_receive(), smsbox_req_handle(), smsbox_req_sendsms(), smsc2_add_smsc(), smsc2_restart_smsc(), smsc2_rout(), smsc2_start(), smsc_cimd2_create(), smsc_emi2_create(), smsc_http_create(), smsc_smpp_create(), smscconn_create(), smscconn_send(), soap_parse_response(), split_headers(), store_file_load(), store_to_dict(), timer_consumer_thread(), timers_shutdown(), transform_message(), udp_receiver(), unpack_accept_language_general_form(), unpack_cache_directive(), unpack_challenge(), unpack_content_range(), unpack_credentials(), unpack_datagram(), unpack_disposition(), unpack_encoding_version(), unpack_field_name(), unpack_optional_q_value(), unpack_parameter(), unpack_range_value(), unpack_retry_after(), unpack_warning_value(), unpack_wdp_datagram_real(), update_table(), update_tables(), url_pattern(), wait_for_ack(), wap_dispatch_datagram(), wdp_to_wapboxes(), write_data(), wsp_cap_unpack_list(), wsp_headers_pack(), wsp_headers_unpack(), wsp_pack_application_header(), wsp_pack_date(), wsp_pack_integer_string(), wsp_pack_separate_content_type(), wsp_pdu_unpack(), wsp_unpack_accept_charset_general_form(), wsp_unpack_accept_general_form(), wsp_unpack_app_header(), wsp_unpack_date_value(), wsp_unpack_integer_value(), wsp_unpack_well_known_field(), wtp_pdu_create(), wtp_pdu_destroy(), wtp_pdu_unpack(), wtp_unpack_wdp_datagram(), X28_open_send_link(), and xmlrpc_doc_destroy().

661 {
662  int e;
663 
664  if ((e = thread_to[thread_slot()])) {
666  } else {
668  }
669 }
#define FUNCTION_GUTS_EXCL(level, place)
Definition: log.c:574
static unsigned int thread_to[(long) THREADTABLE_SIZE]
Definition: log.c:182
Definition: log.h:69
#define thread_slot()
Definition: log.c:189
#define FUNCTION_GUTS(level, place)
Definition: log.c:544

Variable Documentation

◆ dosyslog

int dosyslog = 0
static

Definition at line 211 of file log.c.

Referenced by log_close_all(), log_set_syslog(), and PRINTFLIKE().

◆ exclusive

enum excl_state exclusive

Definition at line 172 of file log.c.

◆ file

◆ filename

◆ logfiles

◆ loggable_places

char* loggable_places[MAX_LOGGABLE_PLACES]
static

Definition at line 197 of file log.c.

Referenced by log_set_debug_places(), place_is_not_logged(), and place_should_be_logged().

◆ minimum_output_level

int minimum_output_level

Definition at line 170 of file log.c.

Referenced by log_thread_to().

◆ num_logfiles

int num_logfiles = 0
static

◆ num_places

int num_places = 0
static

Definition at line 198 of file log.c.

Referenced by log_set_debug_places(), place_is_not_logged(), and place_should_be_logged().

◆ rwlock

RWLock rwlock
static

Definition at line 204 of file log.c.

Referenced by log_close_all(), log_init(), log_open(), log_reopen(), and log_shutdown().

◆ syslogfacility

int syslogfacility = LOG_DAEMON
static

Definition at line 210 of file log.c.

Referenced by log_set_syslog(), and log_set_syslog_facility().

◆ sysloglevel

int sysloglevel
static

Definition at line 209 of file log.c.

Referenced by log_set_syslog(), and PRINTFLIKE().

◆ thread_to

unsigned int thread_to[(long) THREADTABLE_SIZE]
static

Definition at line 182 of file log.c.

Referenced by debug(), error(), info(), log_init(), log_thread_to(), and warning().

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.