Kannel: Open Source WAP and SMS gateway  svn-r5335
log.h File Reference

Go to the source code of this file.

Macros

#define panic   gw_panic
 

Enumerations

enum  output_level {
  GW_DEBUG, GW_INFO, GW_WARNING, GW_ERROR,
  GW_PANIC, GW_BACKTRACE
}
 
enum  excl_state { GW_NON_EXCL, GW_EXCL }
 

Functions

void log_init (void)
 
void log_shutdown (void)
 
void gw_panic (int, const char *,...) PRINTFLIKE(2
 
void void gw_backtrace (void **, size_t, int)
 
void error (int, const char *,...) PRINTFLIKE(2
 
void void warning (int, const char *,...) PRINTFLIKE(2
 
void void void info (int, const char *,...) PRINTFLIKE(2
 
void void void void debug (const char *, int, const char *,...) PRINTFLIKE(3
 
void void void void void log_set_debug_places (const char *places)
 
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)
 
int log_open (char *filename, int level, enum excl_state excl)
 
void log_reopen (void)
 
void log_close_all (void)
 
void log_thread_to (int idx)
 

Macro Definition Documentation

◆ panic

#define panic   gw_panic

Definition at line 87 of file log.h.

Referenced by accept_thread(), at2_detect_modem_type(), at2_read_modems(), bb_smscconn_receive(), become_daemon(), cfg_get_group_checksum(), cfg_get_real(), cfg_read(), check(), check_args(), check_comparisons(), client(), client_destroy(), client_session(), conn_claim(), connect_to_bearerbox(), convert(), convert_wmlscript_to_wmlscriptc(), create_onetrans(), create_oneuser(), dlr_db_fields_create(), dlr_init(), dlr_init_spool(), emi2_handle_smscreq(), emi2_idleprocessing(), entity_read(), generic_init(), get_and_set_debugs(), getthreadinfo(), gw_check_calloc(), gw_check_claim_area(), gw_check_free(), gw_check_malloc(), gw_check_realloc(), gw_native_calloc(), gw_native_malloc(), gw_native_realloc(), gw_rwlock_create(), gw_rwlock_destroy(), gw_rwlock_init_static(), gw_rwlock_rdlock(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gwthread_init(), handle_action(), handle_reply(), handle_transaction(), handler(), http_use_proxy(), httpadmin_start(), httpd_emu_create(), init_batch(), init_bearerbox(), init_reroute(), init_smppbox(), init_smsbox(), init_smsc_routes(), init_sqlbox(), init_wapbox(), ip_allowed_by_ppg(), lock(), main(), main_for_extract(), main_for_list_add_and_delete(), main_for_producer_and_consumer(), main_thread(), msg_pack(), mutex_destroy(), mutex_lock_real(), mutex_trylock_real(), mutex_unlock_real(), new_thread(), octstr_imm(), parachute_init_signals(), parachute_start(), post_content_create(), proxy_thread(), push_content_create(), radius_acct_init(), radius_type_convert(), read_ppg_config(), read_test_ppg_config(), receive_request(), record_allocation(), restore_user_signals(), run_requests(), run_smppbox(), run_sqlbox(), semaphore_create(), semaphore_destroy(), semaphore_getvalue(), send_post(), server(), setup_official_name(), signal_handler(), smpp_emu(), smpp_emu_handle_pdu(), smppboxc_run(), smsbox_start(), smsbox_thread(), smsboxc_run(), smsc2_start(), smsc_emu_create(), smsc_smasi_create(), smsc_smpp_create(), smscconn_create(), sqlboxc_run(), start_http_thread(), start_wap(), start_wapbox(), store_file_init(), store_file_load(), udp_addwdp_from_client(), udp_addwdp_from_server(), unlock(), unlock_in_real(), unlock_out_real(), unpack_accept_language_general_form(), unpack_cache_directive(), unpack_field_name(), unpack_parameter(), wait_for_client(), wap_event_create_real(), wap_event_destroy(), wap_event_duplicate(), wap_event_name(), wapbox_start(), wapboxc_run(), write_pid_file(), wsp_pdu_create(), wsp_pdu_destroy(), wsp_pdu_pack(), wsp_unpack_accept_charset_general_form(), wsp_unpack_accept_general_form(), wsp_unpack_well_known_field(), and wtp_pdu_pack().

Enumeration Type Documentation

◆ excl_state

enum excl_state
Enumerator
GW_NON_EXCL 
GW_EXCL 

Definition at line 73 of file log.h.

73  {
75 };
Definition: log.h:74

◆ output_level

Enumerator
GW_DEBUG 
GW_INFO 
GW_WARNING 
GW_ERROR 
GW_PANIC 
GW_BACKTRACE 

Definition at line 68 of file log.h.

68  {
70 };
Definition: log.h:69
Definition: log.h:69
Definition: log.h:69
Definition: log.h:69
Definition: log.h:69

Function Documentation

◆ debug()

void void void void debug ( const char *  ,
int  ,
const char *  ,
  ... 
)

◆ error()

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

◆ gw_backtrace()

void void gw_backtrace ( void **  ,
size_t  ,
int   
)

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  ,
const char *  ,
  ... 
)

◆ info()

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

◆ 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 void void void 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

◆ warning()

void void warning ( int  ,
const char *  ,
  ... 
)
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.