33 #include <sys/types.h> 61 #define CFG_MAX_LINE 4096 74 static char **
cfg_copy_hosts (
const char **host_array,
int *num_hosts);
75 static const char *
cfg_pop_host (
const char *host_list,
char *buffer,
int *length);
76 static bool cfg_host_exists (
char *host_list,
char *hostname,
int num_items);
137 char *
p, *end, *token =
NULL;
152 length = (int) (end - p);
155 token = (
char *) malloc (length + 1);
158 strncpy (token, p, length);
159 token[length] =
'\0';
176 char *
p, *end, *token =
NULL;
197 length = (int) (end - p);
200 token = (
char *) malloc (length + 1);
203 strncpy (token, p, length);
204 token[length] =
'\0';
222 #if !defined (DO_NOT_USE_CUBRIDENV) 223 const char *env_name;
227 if (env_name ==
NULL ||
strlen (env_name) == 0)
234 if (env_name[
strlen (env_name) - 1] ==
'/')
259 char *return_str =
NULL;
262 static char working_dir[PATH_MAX];
263 return_str = _fullpath (working_dir,
".", PATH_MAX);
265 return_str = getenv (
"PWD");
283 if ((file_p = fopen (buffer,
"a+")) ==
NULL)
285 #if !defined(CS_MODE) 305 char filename[PATH_MAX];
312 file_p = fopen (filename,
"a+");
334 char filename[PATH_MAX];
343 file_p = fopen (filename,
"wbc");
345 file_p = fopen (filename,
"w");
350 file_p = fopen (filename,
"r");
361 #if !defined(CS_MODE) 363 file_p = fopen (filename,
"r+");
398 DB_INFO *databases, *last, *db;
400 char *primary_host =
NULL;
402 char *ha_node_list =
NULL;
404 databases = last =
NULL;
406 #if defined(SERVER_MODE) 410 ha_node_list = (str) ? str + 1 :
NULL;
422 if (*str !=
'\0' && *str !=
'#')
427 if (databases !=
NULL)
447 if (primary_host !=
NULL)
455 if (databases ==
NULL)
468 if (databases !=
NULL)
500 DB_INFO *databases, *last, *db;
502 char *primary_host =
NULL;
503 struct stat stat_buffer;
506 #if defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS) 510 databases = last =
NULL;
512 if (lseek (vdes, 0L, SEEK_SET) == 0L)
514 fstat (vdes, &stat_buffer);
515 line = (
char *) malloc (stat_buffer.st_size + 1);
522 read (vdes, line, (
unsigned int) stat_buffer.st_size);
523 line[stat_buffer.st_size] =
'\0';
531 if (databases !=
NULL)
547 if (primary_host !=
NULL)
554 if (databases ==
NULL)
568 if (databases !=
NULL)
603 #if !defined(WINDOWS) 604 sigset_t new_mask, old_mask;
611 #if !defined(WINDOWS) 612 sigfillset (&new_mask);
613 sigdelset (&new_mask, SIGINT);
614 sigdelset (&new_mask, SIGQUIT);
615 sigdelset (&new_mask, SIGTERM);
616 sigdelset (&new_mask, SIGHUP);
617 sigdelset (&new_mask, SIGABRT);
618 sigprocmask (SIG_SETMASK, &new_mask, &old_mask);
621 fprintf (file_p,
"#db-name\tvol-path\t\tdb-host\t\tlog-path\t\tlob-base-path\n");
622 for (db_info_p = databases; db_info_p !=
NULL; db_info_p = db_info_p->
next)
626 char short_path[256];
627 GetShortPathName (db_info_p->
pathname, short_path, 256);
628 fprintf (file_p,
"%s%s\t%s\t", db_info_p->
name, (t ?
"\t" :
""), short_path);
630 fprintf (file_p,
"%s%s\t%s\t", db_info_p->
name, (t ?
"\t" :
""), db_info_p->
pathname);
635 char **array = db_info_p->
hosts;
636 fprintf (file_p,
"%s", *array++);
637 while (*array !=
NULL)
639 fprintf (file_p,
":%s", *array++);
644 fprintf (file_p,
"localhost");
650 GetShortPathName (db_info_p->
logpath, short_path, 256);
651 fprintf (file_p,
"\t%s ", short_path);
653 fprintf (file_p,
"\t%s ", db_info_p->
logpath);
659 fprintf (file_p,
"\t%s ", db_info_p->
lobpath);
662 fprintf (file_p,
"\n");
667 #if !defined(WINDOWS) 668 sigprocmask (SIG_SETMASK, &old_mask,
NULL);
689 char line[LINE_MAX], *s;
692 #if !defined(WINDOWS) 693 sigset_t new_mask, old_mask;
696 #if defined(DONT_USE_MANDATORY_LOCK_IN_WINDOWS) 701 #if !defined(WINDOWS) 702 sigfillset (&new_mask);
703 sigdelset (&new_mask, SIGINT);
704 sigdelset (&new_mask, SIGQUIT);
705 sigdelset (&new_mask, SIGTERM);
706 sigdelset (&new_mask, SIGHUP);
707 sigdelset (&new_mask, SIGABRT);
708 sigprocmask (SIG_SETMASK, &new_mask, &old_mask);
711 lseek (vdes, 0L, SEEK_SET);
712 n = sprintf (line,
"#db-name\tvol-path\t\tdb-host\t\tlog-path\t\tlob-base-path\n");
713 write (vdes, line, n);
714 for (db_info_p = databases; db_info_p !=
NULL; db_info_p = db_info_p->
next)
718 s += sprintf (s,
"%s%s\t%s\t", db_info_p->
name, (t ?
"\t" :
""), db_info_p->
pathname);
722 char **array = db_info_p->
hosts;
723 s += sprintf (s,
"%s", *array++);
724 while (*array !=
NULL)
726 s += sprintf (s,
":%s", *array++);
731 s += sprintf (s,
"localhost");
735 s += sprintf (s,
"\t%s", db_info_p->
logpath);
739 s += sprintf (s,
"\t%s", db_info_p->
lobpath);
741 s += sprintf (s,
"\n");
742 n = (int) (s - line);
743 write (vdes, line, n);
746 ftruncate (vdes, lseek (vdes, 0L, SEEK_CUR));
748 #if !defined(WINDOWS) 749 sigprocmask (SIG_SETMASK, &old_mask,
NULL);
761 DB_INFO *db_info_p, *next_info_p;
763 for (db_info_p = databases, next_info_p =
NULL; db_info_p !=
NULL; db_info_p = next_info_p)
766 next_info_p = db_info_p->
next;
792 #if defined(CUBRID_DEBUG) 799 cfg_dump_directory (
const DB_INFO * databases)
804 for (db_info_p = databases; db_info_p !=
NULL; db_info_p = db_info_p->
next)
806 fprintf (stdout,
"%s %s ", db_info_p->
name, db_info_p->
pathname);
810 while ((*((db_info_p->
hosts) + i)) !=
NULL)
812 fprintf (stdout,
"%s", (*(db_info_p->
hosts + i)));
816 fprintf (stdout,
",");
820 fprintf (stdout,
" ");
826 fprintf (stdout,
"%s ", db_info_p->
logpath);
830 fprintf (stdout,
"%s", db_info_p->
lobpath);
832 fprintf (stdout,
"\n");
851 if (db_info_p !=
NULL)
887 db_info_p->
hosts = ptr_p;
904 cfg_new_db (
const char *name,
const char *path,
const char *logpath,
const char *lobpath,
const char **hosts)
909 if (db_info_p ==
NULL)
972 if (db_info_p !=
NULL)
1010 DB_INFO *db_info_p, *found_info_p;
1012 found_info_p =
NULL;
1013 for (db_info_p = db_info_list_p; db_info_p !=
NULL && found_info_p ==
NULL; db_info_p = db_info_p->
next)
1015 if (strcmp (db_info_p->
name, name) == 0)
1017 found_info_p = db_info_p;
1021 return (found_info_p);
1035 cfg_add_db (
DB_INFO ** dir,
const char *name,
const char *path,
const char *logpath,
const char *lobpath,
1042 const char *hosts[2];
1045 db_info_p =
cfg_new_db (name, path, logpath, lobpath, hosts);
1052 if (db_info_p !=
NULL)
1054 db_info_p->
next = *dir;
1069 DB_INFO *dir_info_p, *db_info_p;
1075 if (dir_info_p ==
NULL)
1077 #if !defined(CS_MODE) 1086 if (db_info_p ==
NULL)
1088 #if !defined(CS_MODE) 1099 (
const char **) db_info_p->
hosts);
1112 #if !defined(CS_MODE) 1130 DB_INFO *db_info_p, *prev_info_p, *found_info_p;
1133 for (db_info_p = *dir_info_p, found_info_p =
NULL, prev_info_p =
NULL; db_info_p !=
NULL && found_info_p ==
NULL;
1134 db_info_p = db_info_p->
next)
1136 if (strcmp (db_info_p->
name, name) == 0)
1138 found_info_p = db_info_p;
1142 prev_info_p = db_info_p;
1145 if (found_info_p !=
NULL)
1147 if (prev_info_p ==
NULL)
1149 *dir_info_p = found_info_p->
next;
1153 prev_info_p->
next = found_info_p->
next;
1189 if (*count == 0 || hosts_data ==
NULL)
1195 host_array = (
char **) calloc (*count + 1,
sizeof (
char **));
1196 if (host_array ==
NULL)
1201 for (i = 0; i < *
count; i++)
1203 host_array[
i] = hosts_data;
1205 if (hosts_data ==
NULL)
1210 *hosts_data++ =
'\0';
1224 if (host_array !=
NULL)
1226 if (*host_array !=
NULL)
1249 int current_host_length = 0;
1250 const char *start, *
host;
1269 current_host_length = 0;
1274 current_host_length++;
1287 strncpy (buffer, start, current_host_length);
1288 *(buffer + current_host_length) =
'\0';
1298 *length = current_host_length;
1315 int i = 0, len, hostname_len;
1317 hostname_len = (int)
strlen (hostname);
1319 current_host = host_list;
1320 while ((current_host !=
NULL) && (i < num_items))
1323 if (next_sep ==
NULL)
1325 if (strcmp (current_host, hostname) == 0)
1338 if (len == hostname_len && strncmp (current_host, hostname, len) == 0)
1345 current_host = next_sep + 1;
1370 for (num = 0, host = host_array[0];
host; num++, host = host_array[num])
1372 buffer_size +=
strlen (host) + 1;
1380 buffer = (
char *) malloc (buffer_size);
1387 new_array = (
char **) calloc (num + 1,
sizeof (
char **));
1388 if (new_array ==
NULL)
1395 for (num = 0, host = host_array[0];
host; num++, host = host_array[num])
1397 strcpy (buffer, host);
1398 new_array[num] = buffer;
1399 buffer +=
strlen (host) + 1;
1402 if (host_array[0] ==
NULL)
1427 int host_list_length, host_length, host_count;
1428 const char *str_ptr;
1429 char *full_host_list, *host_ptr;
1434 host_list_length = 0;
1437 if (include_local_host)
1443 host_list_length +=
strlen (local_host) + 1;
1446 strcpy (local_host,
"localhost");
1447 host_list_length += (int)
strlen (local_host) + 1;
1451 if (primary_host_name !=
NULL && *primary_host_name !=
'\0')
1453 host_list_length += (int)
strlen (primary_host_name) + 1;
1468 if (host_list_length == 0)
1472 full_host_list = (
char *) malloc (host_list_length + 1);
1473 if (full_host_list ==
NULL)
1478 host_ptr = full_host_list;
1481 if (primary_host_name !=
NULL && *primary_host_name !=
'\0')
1483 str_ptr = primary_host_name;
1484 while (*str_ptr !=
'\0')
1486 str_ptr =
cfg_pop_host (str_ptr, host_ptr, &host_length);
1487 if (host_length > 0)
1492 host_ptr += host_length;
1503 while (*str_ptr !=
'\0')
1505 str_ptr =
cfg_pop_host (str_ptr, host_ptr, &host_length);
1506 if (host_length > 0)
1511 host_ptr += host_length;
1519 if (*local_host !=
'\0')
1523 strcpy (host_ptr, local_host);
1524 host_ptr +=
strlen (local_host);
1537 if (host_count != 0)
1539 *count = host_count;
1540 return full_host_list;
char * cfg_maycreate_get_directory_filename(char *buffer)
DB_INFO * cfg_find_db(const char *db_name)
static FILE * cfg_open_directory_file(bool write_flag)
char ** cfg_get_hosts(const char *prim_host, int *count, bool include_local_host)
void cfg_free_hosts(char **host_array)
#define ER_CFG_FIND_DATABASE
void cfg_update_db(DB_INFO *db_info_p, const char *path, const char *logpath, const char *lobpath, const char *host)
static char ** cfg_copy_hosts(const char **host_array, int *num_hosts)
#define DATABASES_FILENAME
static int cfg_ensure_directory_write(void)
static char * cfg_next_line(char *str_p)
static char * cfg_next_char(char *str_p)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
char * cfg_create_host_list(const char *primary_host_name, bool include_local_host, int *count)
static char * cfg_pop_token(char *str_p, char **token_p)
#define ER_OUT_OF_VIRTUAL_MEMORY
static char * cfg_pop_linetoken(char *str_p, char **token_p)
char * cfg_os_working_directory(void)
bool cfg_delete_db(DB_INFO **dir_info_p, const char *name)
static char CFG_HOST_SEPARATOR
int cfg_read_directory_ex(int vdes, DB_INFO **info_p, bool write_flag)
void er_set_with_oserror(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int count(int &result, const cub_regex_object ®, const std::string &src, const int position, const INTL_CODESET codeset)
DB_INFO * cfg_add_db(DB_INFO **dir, const char *name, const char *path, const char *logpath, const char *lobpath, const char *host)
#define DATABASES_ENVNAME
const char * envvar_get(const char *name)
static void error(const char *msg)
char * envvar_vardir_file(char *path, size_t size, const char *filename)
int cfg_read_directory(DB_INFO **info_p, bool write_flag)
static bool cfg_host_exists(char *host_list, char *hostname, int num_items)
#define free_and_init(ptr)
char * prm_get_string_value(PARAM_ID prm_id)
static const char * cfg_pop_host(const char *host_list, char *buffer, int *length)
#define ER_CFG_INVALID_DATABASES
char * strdup(const char *str)
#define ER_CFG_NO_WRITE_ACCESS
void cfg_write_directory_ex(int vdes, const DB_INFO *databases)
static void cfg_get_directory_filename(char *buffer, int *local)
#define CUB_MAXHOSTNAMELEN
void cfg_free_directory(DB_INFO *databases)
#define GETHOSTNAME(p, l)
DB_INFO * cfg_new_db(const char *name, const char *path, const char *logpath, const char *lobpath, const char **hosts)
#define ER_CFG_READ_DATABASES
DB_INFO * cfg_find_db_list(DB_INFO *db_info_list_p, const char *name)
void cfg_write_directory(const DB_INFO *databases)