CUBRID Engine  latest
util_func.c File Reference
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <assert.h>
#include <chrono>
#include <time.h>
#include <stdarg.h>
#include <sys/timeb.h>
#include <sys/time.h>
#include "util_func.h"
#include "porting.h"
#include "error_code.h"
#include "utility.h"
#include "system_parameter.h"
#include "environment_variable.h"
Include dependency graph for util_func.c:

Go to the source code of this file.

Macros

#define UTIL_LOG_MAX_HEADER_LEN   (40)
 
#define UTIL_LOG_MAX_MSG_SIZE   (1024)
 
#define UTIL_LOG_BUFFER_SIZE   (UTIL_LOG_MAX_MSG_SIZE + UTIL_LOG_MAX_HEADER_LEN)
 
#define UTIL_LOG_FILENAME   "cubrid_utility.log"
 
#define MAX_RETRY_COUNT   10
 

Functions

static FILE * util_log_file_backup (FILE *fp, const char *path)
 
static FILE * util_log_file_fopen (const char *path)
 
static FILE * fopen_and_lock (const char *path)
 
static int util_log_header (char *buf, size_t buf_len)
 
static int util_log_write_internal (const char *msg, const char *prefix_str)
 
template<typename Duration >
static void util_get_seconds_and_rest_since_epoch (std::chrono::seconds &secs, Duration &rest)
 
unsigned int hashpjw (const char *s)
 
int util_compare_filepath (const char *file1, const char *file2)
 
static void system_interrupt_handler (int sig)
 
static void system_quit_handler (int sig)
 
void util_disarm_signal_handlers (void)
 
void util_arm_signal_handlers (SIG_HANDLER sigint_handler, SIG_HANDLER sigquit_handler)
 
char ** util_split_string (const char *str, const char *delim)
 
void util_free_string_array (char **array)
 
time_t util_str_to_time_since_epoch (char *str)
 
void util_shuffle_string_array (char **array, int count)
 
int util_log_write_result (int error)
 
int util_log_write_errid (int message_id,...)
 
int util_log_write_errstr (const char *format,...)
 
int util_log_write_warnstr (const char *format,...)
 
int util_log_write_command (int argc, char *argv[])
 
int util_bsearch (const void *key, const void *base, int n_elems, unsigned int sizeof_elem, int(*func_compare)(const void *, const void *), bool *out_found)
 
template<typename Duration >
void util_get_seconds_and_rest_since_epoch (std::chrono::seconds &secs, Duration &rest)
 
void util_get_second_and_ms_since_epoch (time_t *secs, int *msec)
 

Variables

static char * util_Log_filename = NULL
 
static char util_Log_filename_buf [PATH_MAX]
 
static char util_Log_buffer [UTIL_LOG_BUFFER_SIZE]
 
static SIG_HANDLER user_interrupt_handler = NULL
 
static SIG_HANDLER user_quit_handler = NULL
 

Macro Definition Documentation

#define MAX_RETRY_COUNT   10

Referenced by fopen_and_lock().

#define UTIL_LOG_BUFFER_SIZE   (UTIL_LOG_MAX_MSG_SIZE + UTIL_LOG_MAX_HEADER_LEN)

Definition at line 49 of file util_func.c.

Referenced by util_log_write_internal().

#define UTIL_LOG_FILENAME   "cubrid_utility.log"

Definition at line 52 of file util_func.c.

Referenced by util_log_write_internal().

#define UTIL_LOG_MAX_HEADER_LEN   (40)

Definition at line 47 of file util_func.c.

Referenced by util_log_header().

#define UTIL_LOG_MAX_MSG_SIZE   (1024)

Function Documentation

static FILE * fopen_and_lock ( const char *  path)
static

Definition at line 719 of file util_func.c.

References MAX_RETRY_COUNT, NULL, and SLEEP_MILISEC.

Referenced by util_log_file_backup(), and util_log_file_fopen().

Here is the caller graph for this function:

unsigned int hashpjw ( const char *  s)

Definition at line 83 of file util_func.c.

References assert, and NULL.

Referenced by dl_validate_candidates(), pp_generic_case_hash(), and pp_generic_hash().

Here is the caller graph for this function:

static void system_interrupt_handler ( int  sig)
static

Definition at line 159 of file util_func.c.

References NULL, os_set_signal_handler(), and user_interrupt_handler.

Referenced by util_arm_signal_handlers(), and util_compare_filepath().

Here is the caller graph for this function:

static void system_quit_handler ( int  sig)
static

Definition at line 177 of file util_func.c.

References NULL, os_set_signal_handler(), and user_quit_handler.

Referenced by util_arm_signal_handlers(), and util_compare_filepath().

Here is the caller graph for this function:

void util_arm_signal_handlers ( SIG_HANDLER  sigint_handler,
SIG_HANDLER  sigquit_handler 
)
int util_bsearch ( const void *  key,
const void *  base,
int  n_elems,
unsigned int  sizeof_elem,
int(*)(const void *, const void *)  func_compare,
bool out_found 
)

Definition at line 764 of file util_func.c.

References max, and min.

Referenced by file_extdata_find_ordered(), and vacuum_add_dropped_file().

Here is the caller graph for this function:

int util_compare_filepath ( const char *  file1,
const char *  file2 
)
void util_disarm_signal_handlers ( void  )

Definition at line 192 of file util_func.c.

References NULL, os_set_signal_handler(), user_interrupt_handler, and user_quit_handler.

Referenced by util_arm_signal_handlers().

Here is the caller graph for this function:

void util_free_string_array ( char **  array)

Definition at line 292 of file util_func.c.

References i, and NULL.

Referenced by boot_restart_client(), server_monitor_thr_f(), util_free_ha_conf(), util_get_num_of_ha_nodes(), util_is_replica_node(), and util_make_ha_conf().

Here is the caller graph for this function:

void util_get_second_and_ms_since_epoch ( time_t *  secs,
int *  msec 
)

Definition at line 829 of file util_func.c.

References assert, and NULL.

Referenced by db_calculate_current_time(), db_sys_date_and_epoch_time(), db_sys_datetime(), fetch_peek_arith(), logddl_get_time_string(), qexec_execute_query(), ut_time_string(), and util_log_header().

Here is the caller graph for this function:

template<typename Duration >
static void util_get_seconds_and_rest_since_epoch ( std::chrono::seconds &  secs,
Duration &  rest 
)
static

Definition at line 818 of file util_func.c.

template<typename Duration >
void util_get_seconds_and_rest_since_epoch ( std::chrono::seconds &  secs,
Duration &  rest 
)

Definition at line 818 of file util_func.c.

static FILE * util_log_file_backup ( FILE *  fp,
const char *  path 
)
static

Definition at line 698 of file util_func.c.

References assert, fopen_and_lock(), and NULL.

Referenced by util_log_file_fopen().

Here is the caller graph for this function:

static FILE * util_log_file_fopen ( const char *  path)
static

Definition at line 672 of file util_func.c.

References assert, fopen_and_lock(), NULL, prm_get_integer_value(), PRM_ID_ER_LOG_SIZE, and util_log_file_backup().

Referenced by util_log_write_internal().

Here is the caller graph for this function:

static int util_log_header ( char *  buf,
size_t  buf_len 
)
static

Definition at line 634 of file util_func.c.

References assert, envvar_get(), NULL, p, pid, util_get_second_and_ms_since_epoch(), UTIL_LOG_MAX_HEADER_LEN, and UTIL_PID_ENVVAR_NAME.

Referenced by util_log_write_internal().

Here is the caller graph for this function:

int util_log_write_command ( int  argc,
char *  argv[] 
)

Definition at line 540 of file util_func.c.

References i, NULL, p, strlen, UTIL_LOG_MAX_MSG_SIZE, and util_log_write_internal().

Referenced by main().

Here is the caller graph for this function:

int util_log_write_errstr ( const char *  format,
  ... 
)
static int util_log_write_internal ( const char *  msg,
const char *  prefix_str 
)
static
int util_log_write_result ( int  error)

Definition at line 448 of file util_func.c.

References NO_ERROR, NULL, and util_log_write_internal().

Referenced by main().

Here is the caller graph for this function:

int util_log_write_warnstr ( const char *  format,
  ... 
)

Definition at line 516 of file util_func.c.

References UTIL_LOG_MAX_MSG_SIZE, and util_log_write_internal().

Referenced by backupdb().

Here is the caller graph for this function:

void util_shuffle_string_array ( char **  array,
int  count 
)

Definition at line 412 of file util_func.c.

References i, and NULL.

Referenced by boot_client_all_finalize().

Here is the caller graph for this function:

char** util_split_string ( const char *  str,
const char *  delim 
)

Definition at line 247 of file util_func.c.

References cubregex::count(), NULL, and strdup().

Referenced by boot_restart_client(), server_monitor_thr_f(), util_split_ha_db(), util_split_ha_node(), and util_split_ha_sync().

Here is the caller graph for this function:

time_t util_str_to_time_since_epoch ( char *  str)

Definition at line 310 of file util_func.c.

References ER_GENERIC_ERROR, NO_ERROR, NULL, and strdup().

Referenced by applyinfo(), applylogdb(), and la_delay_replica().

Here is the caller graph for this function:

Variable Documentation

SIG_HANDLER user_interrupt_handler = NULL
static
SIG_HANDLER user_quit_handler = NULL
static
char util_Log_buffer[UTIL_LOG_BUFFER_SIZE]
static

Definition at line 56 of file util_func.c.

Referenced by util_log_write_internal().

char* util_Log_filename = NULL
static

Definition at line 54 of file util_func.c.

Referenced by util_log_write_internal().

char util_Log_filename_buf[PATH_MAX]
static

Definition at line 55 of file util_func.c.

Referenced by util_log_write_internal().