33 #include <sys/timeb.h> 39 #include <sys/timeb.h> 53 #define DDL_LOG_MSG (256) 54 #define DDL_LOG_PATH "log/ddl_audit" 55 #define DDL_LOG_LOADDB_FILE_PATH "log/ddl_audit/loaddb" 56 #define DDL_LOG_CSQL_FILE_PATH "log/ddl_audit/csql" 57 #define FILE_BUFFER_SIZE (1024) 58 #define TIME_STRING_SIZE (16) 59 #define DDL_TIME_LEN (32) 101 static void unix_style_path (
char *path);
112 static void logddl_timeval_diff (
struct timeval *start,
struct timeval *end,
long *res_sec,
long *res_msec);
121 if (ddl_audit_handle !=
NULL)
129 if (ddl_audit_handle ==
NULL)
145 if (ddl_audit_handle ==
NULL)
167 ddl_audit_handle->
msg[0] =
'\0';
187 if (ddl_audit_handle !=
NULL)
213 snprintf (ddl_audit_handle->
db_name, sizeof (ddl_audit_handle->
db_name), db_name);
215 pstr = (
char *) strchr (ddl_audit_handle->
db_name,
'@');
227 snprintf (ddl_audit_handle->
user_name, sizeof (ddl_audit_handle->
user_name), user_name);
236 snprintf (ddl_audit_handle->
ip_addr, sizeof (ddl_audit_handle->
ip_addr), ip_addr);
245 ddl_audit_handle->
pid =
pid;
284 strncpy (ddl_audit_handle->
sql_text, sql_text, len);
285 ddl_audit_handle->
sql_text[len] =
'\0';
330 strncpy (ddl_audit_handle->
load_filename, load_filename, PATH_MAX);
377 if (time_val ==
NULL)
380 gettimeofday (&time,
NULL);
397 va_start (args, fmt);
443 if (ddl_audit_handle)
445 jsp_mode = ddl_audit_handle->
jsp_mode;
455 snprintf (ddl_audit_handle->
elapsed_time, 20,
"elapsed time %ld.%03ld", sec, msec);
466 if (src_file ==
NULL || dest_file ==
NULL)
471 if (access (dest_file, F_OK) == 0)
476 FILE *fsource = fopen (src_file,
"r");
482 FILE *fdest = fopen (dest_file,
"w");
504 retval = ferror (fsource);
509 if (fwrite (buf,
sizeof (
char), size, fdest) != size)
511 retval = ferror (fdest);
533 const char *env_root =
NULL;
535 const char *name_tmp =
NULL;
538 if (ddl_audit_handle ==
NULL || file_full_path ==
NULL || copy_filename ==
NULL || buf_size < 0)
548 if (name_tmp ==
NULL)
550 name_tmp = file_full_path;
557 retval = snprintf (copy_filename, buf_size,
"%s_%s_%d", name_tmp, time, getpid ());
561 copy_filename[0] =
'\0';
571 const char *env_root =
NULL;
574 if (ddl_audit_handle ==
NULL || copy_filename ==
NULL || copy_fullpath ==
NULL || buf_size < 0)
597 copy_fullpath[0] =
'\0';
607 const char *env_root =
NULL;
617 snprintf (filename_buf, buf_size,
"%s/%s/%s_%d_ddl.log", env_root,
DDL_LOG_PATH, ddl_audit_handle->
br_name,
623 snprintf (filename_buf, buf_size,
"%s/%s/%s_%s_ddl.log", env_root,
DDL_LOG_PATH,
628 filename_buf[0] =
'\0';
635 filename_buf[0] =
'\0';
648 if (ddl_audit_handle->
log_filepath[0] ==
'\0' || len < 0)
785 if (len < 0 || fwrite (buf,
sizeof (
char), len, fp) != (
size_t) len)
812 struct timeval time_val;
829 va_start (args, fmt);
833 gettimeofday (&time_val,
NULL);
871 ddl_audit_handle->
pid, ddl_audit_handle->
user_name, ddl_audit_handle->
msg,
878 ddl_audit_handle->
pid, ddl_audit_handle->
user_name, ddl_audit_handle->
msg);
892 if (len < 0 || fwrite (msg,
sizeof (
char), len, fp) != len)
922 struct timeval time_val;
943 va_start (args, fmt);
947 gettimeofday (&time_val,
NULL);
971 if (len < 0 || fwrite (buf,
sizeof (
char), len, fp) != (
size_t) len)
1004 char result[20] = { 0 };
1005 struct timeval exec_end, log_time;
1006 long elapsed_sec = 0;
1007 long elapsed_msec = 0;
1014 gettimeofday (&exec_end,
NULL);
1020 gettimeofday (&log_time,
NULL);
1026 if (ddl_audit_handle->
err_code < 0)
1028 snprintf (result,
sizeof (result),
"ERROR:%d", ddl_audit_handle->
err_code);
1029 snprintf (ddl_audit_handle->
msg,
DDL_LOG_MSG,
"Commited count %8d, Error line %d",
1034 strcpy (result,
"OK");
1039 ddl_audit_handle->
pid, ddl_audit_handle->
user_name, result, ddl_audit_handle->
msg,
1046 if (ddl_audit_handle->
err_code < 0)
1048 snprintf (result,
sizeof (result),
"ERROR:%d", ddl_audit_handle->
err_code);
1054 ddl_audit_handle->
pid,
1056 (ddl_audit_handle->
auto_commit_mode) ?
"autocommit mode on" :
"autocommit mode off",
1061 strcpy (result,
"OK");
1064 ddl_audit_handle->
pid,
1066 (ddl_audit_handle->
auto_commit_mode) ?
"autocommit mode on" :
"autocommit mode off",
1072 if (ddl_audit_handle->
err_code < 0)
1074 snprintf (result,
sizeof (result),
"ERROR:%d", ddl_audit_handle->
err_code);
1079 strcpy (result,
"OK");
1084 ddl_audit_handle->
pid,
1092 if (ddl_audit_handle->
err_code < 0)
1094 snprintf (result,
sizeof (result),
"ERROR:%d", ddl_audit_handle->
err_code);
1098 strcpy (result,
"OK");
1125 char backup_file[PATH_MAX] = { 0 };
1126 #if !defined(WINDOWS) 1127 sigset_t new_mask, old_mask;
1130 snprintf (backup_file,
sizeof (backup_file),
"%s.bak", path);
1132 #if !defined(WINDOWS) 1133 sigfillset (&new_mask);
1134 sigdelset (&new_mask, SIGINT);
1135 sigdelset (&new_mask, SIGQUIT);
1136 sigdelset (&new_mask, SIGTERM);
1137 sigdelset (&new_mask, SIGHUP);
1138 sigdelset (&new_mask, SIGABRT);
1139 if (sigprocmask (SIG_SETMASK, &new_mask, &old_mask) == 0)
1141 unlink (backup_file);
1142 rename (path, backup_file);
1143 sigprocmask (SIG_SETMASK, &old_mask,
NULL);
1146 unlink (backup_file);
1147 rename (path, backup_file);
1154 #define MAX_RETRY_COUNT 100 1155 int retry_count = 0;
1156 FILE *ddl_log_fp =
NULL;
1159 ddl_log_fp = fopen (path, mode);
1160 if (ddl_log_fp !=
NULL)
1162 if (lockf (fileno (ddl_log_fp), F_TLOCK, 0) < 0)
1164 fclose (ddl_log_fp);
1178 #if defined(WINDOWS) 1180 unix_style_path (
char *path)
1183 for (p = path; *
p; p++)
1194 char *
p, path[PATH_MAX] = { 0 };
1196 if (new_dir ==
NULL)
1199 strcpy (path, new_dir);
1203 #if defined(WINDOWS) 1204 unix_style_path (path);
1208 #if defined(WINDOWS) 1211 else if (
strlen (path) > 3 && path[2] ==
'/')
1222 p = strchr (p,
'/');
1229 if (access (path, F_OK) < 0)
1231 if (mkdir (path, 0777) < 0)
1250 time_t t = time (
NULL);
1252 localtime_r (&t, &at_tm);
1253 at_tm.tm_year += 1900;
1256 snprintf (buf, size,
"%04d%02d%02d_%02d%02d%02d", at_tm.tm_year, at_tm.tm_mon, at_tm.tm_mday, at_tm.tm_hour,
1257 at_tm.tm_min, at_tm.tm_sec);
1265 struct tm tm, *tm_p;
1274 if (time_val ==
NULL)
1281 sec = time_val->tv_sec;
1282 millisec = time_val->tv_usec / 1000;
1285 tm_p = localtime_r (&sec, &tm);
1288 buf[0] = ((tm.tm_year % 100) / 10) +
'0';
1289 buf[1] = (tm.tm_year % 10) +
'0';
1291 buf[3] = (tm.tm_mon / 10) +
'0';
1292 buf[4] = (tm.tm_mon % 10) +
'0';
1294 buf[6] = (tm.tm_mday / 10) +
'0';
1295 buf[7] = (tm.tm_mday % 10) +
'0';
1297 buf[9] = (tm.tm_hour / 10) +
'0';
1298 buf[10] = (tm.tm_hour % 10) +
'0';
1300 buf[12] = (tm.tm_min / 10) +
'0';
1301 buf[13] = (tm.tm_min % 10) +
'0';
1303 buf[15] = (tm.tm_sec / 10) +
'0';
1304 buf[16] = (tm.tm_sec % 10) +
'0';
1306 buf[20] = (millisec % 10) +
'0';
1308 buf[19] = (millisec % 10) +
'0';
1310 buf[18] = (millisec % 10) +
'0';
1319 for (; *
string !=
'\0';
string++)
1323 strcpy (
string,
string + 1);
1374 sec = end->tv_sec - start->tv_sec;
1375 msec = (end->tv_usec / 1000) - (start->tv_usec / 1000);
static int logddl_make_copy_dir(T_APP_NAME app_name, char *copy_filename, char *copy_fullpath, size_t buf_size)
#define SLEEP_MILISEC(sec, msec)
const char * envvar_root(void)
void logddl_set_msg(const char *fmt,...)
static int logddl_create_dir(const char *new_dir)
char br_name[BROKER_NAME_LEN]
static FILE * logddl_open(T_APP_NAME app_name)
void logddl_write_end_for_csql_fileinput(const char *fmt,...)
static FILE * logddl_fopen_and_lock(const char *path, const char *mode)
void logddl_set_db_name(const char *db_name)
char db_name[DB_MAX_IDENTIFIER_LENGTH]
static int logddl_file_copy(char *src_file, char *dest_file)
bool logddl_is_ddl_type(int node_type)
static int logddl_make_filename(char *filename_buf, size_t buf_size, T_APP_NAME app_name)
static int logddl_get_time_string(char *buf, struct timeval *time_val)
char load_filename[PATH_MAX]
void logddl_set_jsp_mode(bool mode)
void logddl_set_logging_enabled(bool enable)
void logddl_set_sql_text(char *sql_text, int len)
void logddl_set_execute_type(char exe_type)
UINT64 prm_get_bigint_value(PARAM_ID prm_id)
static void logddl_set_elapsed_time(long sec, long msec)
void logddl_set_err_msg(char *msg)
char user_name[DB_MAX_USER_LENGTH]
char copy_fullpath[PATH_MAX]
void logddl_set_csql_input_type(T_CSQL_INPUT_TYPE input_type)
static int logddl_create_log_msg(char *msg)
T_LOADDB_FILE_TYPE loaddb_file_type
static int logddl_get_current_date_time_string(char *buf, size_t size)
T_CSQL_INPUT_TYPE csql_input_type
static bool is_executed_ddl_for_csql
void logddl_set_commit_count(int count)
#define DB_MAX_IDENTIFIER_LENGTH
static bool ddl_logging_enabled
static enum scanner_mode mode
static void logddl_remove_char(char *string, char ch)
void logddl_set_load_filename(const char *load_filename)
#define LOGDDL_RUN_EXECUTE_FUNC
#define DDL_LOG_BUFFER_SIZE
void logddl_set_br_index(const int index)
#define LOGDDL_RUN_EXECUTE_BATCH_FUNC
static const char * logddl_get_app_name(T_APP_NAME app_name)
int count(int &result, const cub_regex_object ®, const std::string &src, const int position, const INTL_CODESET codeset)
void util_get_second_and_ms_since_epoch(time_t *secs, int *msec)
struct timeval qry_exec_begin_time
char log_filepath[PATH_MAX]
void logddl_set_br_name(const char *br_name)
static void logddl_backup(const char *path)
static int logddl_make_copy_filename(T_APP_NAME app_name, const char *file_full_path, char *copy_filename, size_t buf_size)
void logddl_set_pid(const int pid)
char elapsed_time[DDL_TIME_LEN]
void logddl_set_loaddb_file_type(T_LOADDB_FILE_TYPE file_type)
static T_DDL_AUDIT_HANDLE * ddl_audit_handle
void logddl_set_app_name(T_APP_NAME app_name)
void logddl_set_commit_mode(bool mode)
bool prm_get_bool_value(PARAM_ID prm_id)
#define ALLOC_COPY(PTR, STR)
static void logddl_timeval_diff(struct timeval *start, struct timeval *end, long *res_sec, long *res_msec)
bool logddl_get_jsp_mode()
#define DDL_LOG_LOADDB_FILE_PATH
void logddl_set_user_name(const char *user_name)
void logddl_write_tran_str(const char *fmt,...)
void logddl_free(bool all_free)
void logddl_set_err_code(int err_code)
char str_qry_exec_begin_time[DDL_TIME_LEN]
#define DB_MAX_USER_LENGTH
void logddl_set_ip(const char *ip_addr)
void logddl_set_stmt_type(int stmt_type)
#define DDL_LOG_CSQL_FILE_PATH
void logddl_set_file_line(int file_line)
static bool is_executed_ddl_for_trans
char copy_filename[PATH_MAX]
void logddl_set_start_time(struct timeval *time_val)