42 #include <sys/timeb.h> 47 #include <sys/timeb.h> 48 #include <netinet/tcp.h> 52 #include <sys/procfs.h> 66 #if defined (ENABLE_UNUSED_FUNCTION) 68 ut_access_log (
int as_index,
struct timeval *
start_time,
char error_flag,
int error_log_offset)
71 char *access_log = getenv (ACCESS_LOG_ENV_STR);
79 struct timeval end_time;
81 gettimeofday (&end_time,
NULL);
83 t1 = start_time->tv_sec;
85 if (localtime_r (&t1, &ct1) ==
NULL || localtime_r (&t2, &ct2) ==
NULL)
92 if (access_log ==
NULL)
94 fp = fopen (access_log,
"a");
98 script = (
char *)
"-";
100 clt_ip = (
char *)
"-";
101 if (clt_appl ==
NULL)
102 clt_appl = (
char *)
"-";
103 for (p = clt_appl; *
p; p++)
105 if (*p ==
' ' || *p ==
'\t' || *p ==
'\n' || *p ==
'\r')
109 if (clt_appl[0] ==
'\0')
110 clt_appl = (
char *)
"-";
113 sprintf (err_str,
"ERR");
115 sprintf (err_str,
"-");
119 "%d %s %s %s %d.%03d %d.%03d %02d/%02d/%02d %02d:%02d:%02d ~ " "%02d/%02d/%02d %02d:%02d:%02d %d %s %d %d\n",
120 as_index + 1, clt_ip, clt_appl, script, (
int) start_time->tv_sec, (
int) (start_time->tv_usec / 1000),
121 (
int) end_time.tv_sec, (
int) (end_time.tv_usec / 1000), ct1.tm_year, ct1.tm_mon + 1, ct1.tm_mday,
122 ct1.tm_hour, ct1.tm_min, ct1.tm_sec, ct2.tm_year, ct2.tm_mon + 1, ct2.tm_mday, ct2.tm_hour, ct2.tm_min,
123 ct2.tm_sec, (
int) getpid (), err_str, error_file_offset, uts_size ());
126 "%d %s %s %s %d.%03d %d.%03d %02d/%02d/%02d %02d:%02d:%02d ~ " "%02d/%02d/%02d %02d:%02d:%02d %d %s %d\n",
127 as_index + 1, clt_ip, clt_appl, script, (
int) start_time->tv_sec, (
int) (start_time->tv_usec / 1000),
128 (
int) end_time.tv_sec, (
int) (end_time.tv_usec / 1000), ct1.tm_year, ct1.tm_mon + 1, ct1.tm_mday,
129 ct1.tm_hour, ct1.tm_min, ct1.tm_sec, ct2.tm_year, ct2.tm_mon + 1, ct2.tm_mday, ct2.tm_hour, ct2.tm_min,
130 ct2.tm_sec, (
int) getpid (), err_str, -1);
134 return (end_time.tv_sec - start_time->tv_sec);
138 #if defined (ENABLE_UNUSED_FUNCTION) 140 ut_file_lock (
char *lock_file)
144 fd = open (lock_file, O_CREAT | O_EXCL, 0666);
149 #ifdef LOCK_FILE_DEBUG 152 fp = fopen (
"uts_file_lock.log",
"a");
155 fprintf (fp,
"[%d] file lock error. err = [%d], [%s]\n", (
int) getpid (), errno, strerror (errno));
167 ut_file_unlock (
char *lock_file)
184 phandle = OpenProcess (PROCESS_TERMINATE,
FALSE, pid);
187 TerminateProcess (phandle, 0);
188 CloseHandle (phandle);
201 for (i = 0; i < 10; i++)
203 if (kill (pid, SIGTERM) < 0)
208 if (kill (pid, 0) < 0)
228 if (broker_name !=
NULL)
246 if (broker_name !=
NULL && proxy_id >= 0)
264 if (broker_name !=
NULL)
272 if (shard_flag ==
OFF)
293 optlen =
sizeof (optval);
295 setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, (
const char *) &optval, optlen);
302 run_child (
const char *appl_name)
307 STARTUPINFO start_info;
308 PROCESS_INFORMATION proc_info;
311 memset (cwd, 0,
sizeof (cwd));
312 getcwd (cwd,
sizeof (cwd));
314 GetStartupInfo (&start_info);
316 sprintf (cmd,
"%s/%s.exe", cwd, appl_name);
325 new_pid = proc_info.dwProcessId;
327 CloseHandle (proc_info.hProcess);
328 CloseHandle (proc_info.hThread);
353 struct prpsinfo info;
354 const char *procdir =
"/proc";
358 sprintf (pname,
"%s/%05d", procdir, pid);
361 if ((procfd = open (pname, O_RDONLY)) == -1)
366 if (ioctl (procfd, PIOCPSINFO, (
char *) &info) == -1)
371 if (saverr == EAGAIN)
373 if (saverr != ENOENT)
380 return (info.pr_bysize);
392 fp = fopen (as_pid_file_name,
"w");
395 fprintf (fp,
"%d\n", (
int) getpid ());
401 as_db_err_log_set (
char *br_name,
int proxy_index,
int shard_id,
int shard_cas_id,
int as_index,
int shard_flag)
405 if (shard_flag ==
ON)
432 if (time_val ==
NULL)
438 sec = time_val->tv_sec;
439 millisec = time_val->tv_usec / 1000;
442 tm_p = localtime_r (&sec, &tm);
445 buf[0] = ((tm.tm_year % 100) / 10) +
'0';
446 buf[1] = (tm.tm_year % 10) +
'0';
448 buf[3] = (tm.tm_mon / 10) +
'0';
449 buf[4] = (tm.tm_mon % 10) +
'0';
451 buf[6] = (tm.tm_mday / 10) +
'0';
452 buf[7] = (tm.tm_mday % 10) +
'0';
454 buf[9] = (tm.tm_hour / 10) +
'0';
455 buf[10] = (tm.tm_hour % 10) +
'0';
457 buf[12] = (tm.tm_min / 10) +
'0';
458 buf[13] = (tm.tm_min % 10) +
'0';
460 buf[15] = (tm.tm_sec / 10) +
'0';
461 buf[16] = (tm.tm_sec % 10) +
'0';
463 buf[20] = (millisec % 10) +
'0';
465 buf[19] = (millisec % 10) +
'0';
467 buf[18] = (millisec % 10) +
'0';
480 snprintf (ip_str, len,
"%d.%d.%d.%d", (
unsigned char) ip_addr[0], (
unsigned char) ip_addr[1],
481 (
unsigned char) ip_addr[2], (
unsigned char) ip_addr[3]);
489 for (i = 0; i < size; i++)
494 return (
float) total / size;
504 if (*ready_flag != 0)
513 h_process = OpenProcess (PROCESS_QUERY_INFORMATION,
FALSE, pid);
514 if (h_process !=
NULL)
516 CloseHandle (h_process);
525 if (kill (pid, 0) == 0)
548 if (snprintf (port_name, len,
"%s%s.B", dir_name, broker_name) < 0)
562 if (snprintf (port_name, len,
"%s%s.P%d", dir_name, broker_name, proxy_id + 1) < 0)
576 if (snprintf (port_name, len,
"%s%s.%d", dir_name, broker_name, as_id + 1) < 0)
590 if (size_str ==
NULL || default_unit ==
NULL)
595 val = strtod (size_str, &end);
596 if (end == (
char *) size_str)
607 unit = (
char *) default_unit;
610 if (strcasecmp (unit,
"b") == 0)
615 else if ((strcasecmp (unit,
"k") == 0) || (strcasecmp (unit,
"kb") == 0))
619 else if ((strcasecmp (unit,
"m") == 0) || (strcasecmp (unit,
"mb") == 0))
624 else if ((strcasecmp (unit,
"g") == 0) || (strcasecmp (unit,
"gb") == 0))
649 if (time_str ==
NULL || default_unit ==
NULL)
654 val = strtod (time_str, &end);
655 if (end == (
char *) time_str)
666 unit = (
char *) default_unit;
669 if ((strcasecmp (unit,
"ms") == 0) || (strcasecmp (unit,
"msec") == 0))
674 else if ((strcasecmp (unit,
"s") == 0) || (strcasecmp (unit,
"sec") == 0))
678 else if (strcasecmp (unit,
"min") == 0)
683 else if (strcasecmp (unit,
"h") == 0)
708 if (snprintf (pid_name, len,
"%s%s_%d.pid", dir_name, br_name, as_index + 1) < 0)
#define SLEEP_MILISEC(sec, msec)
void ut_cd_work_dir(void)
const char * envvar_root(void)
int ut_set_keepalive(int sock)
#define PATH_INFO_ENV_STR
double ut_time_string_to_sec(const char *time_str, const char *default_unit)
char * ut_get_ipv4_string(char *ip_str, int len, const unsigned char *ip_addr)
bool ut_is_appl_server_ready(int pid, char *ready_flag)
char broker_name[BROKER_NAME_LEN]
#define CLT_APPL_NAME_ENV_STR
void ut_get_broker_port_name(char *port_name, char *broker_name, int len)
void ut_cd_root_dir(void)
int ut_time_string(char *buf, struct timeval *time_val)
char * get_cubrid_file(T_CUBRID_FILE_ID fid, char *buf, size_t len)
int ut_kill_as_process(int pid, char *broker_name, int as_index, int shard_flag)
char * envvar_bindir_file(char *path, size_t size, const char *filename)
double ut_size_string_to_kbyte(const char *size_str, const char *default_unit)
static struct timeval start_time
void as_db_err_log_set(char *br_name, int proxy_index, int shard_id, int shard_cas_id, int as_index, int shard_flag)
void util_get_second_and_ms_since_epoch(time_t *secs, int *msec)
int ut_kill_process(int pid)
void as_pid_file_create(char *br_name, int as_index)
char db_err_log_file[BROKER_PATH_MAX]
void ut_get_proxy_port_name(char *port_name, char *broker_name, int proxy_id, int len)
void ut_get_as_port_name(char *port_name, char *broker_name, int as_id, int len)
#define REMOTE_ADDR_ENV_STR
void ut_get_as_pid_name(char *pid_name, char *br_name, int as_index, int len)
int ut_kill_broker_process(int pid, char *broker_name)
int ut_kill_proxy_process(int pid, char *broker_name, int proxy_id)
#define SERVICE_READY_WAIT_COUNT
float ut_get_avg_from_array(int array[], int size)