Commit 3a91f1a9 authored by Alexander Barkov's avatar Alexander Barkov

Code reorganization in the initialization and clean-up code.

- Getting rid of some duplicate code in the Windows and Linux sections
- Moving the initializationa and clean-up code to connect_init_func()
  and connect_done_func(). This allows to use services provided by
  mysqld, for example my_snprintf(), which do not work in
  "__attribute__((constructor))init()".
- Removing the "__attribute__((constructor)) init()" and
  "__attribute__((destructor)) fini()" functions
- Using MariaDB's my_getpw() instead of different calls for Windows
  and Linux.
- Fixing a potentially wrong memory write in strcat() when creating
  the full connect.ini file name.
  strcat() can go outside of the buffer size when directory name is
  long enough. Using safe my_snprintf() instead.

modified:
  storage/connect/ha_connect.cc
parent 7bc69b7a
...@@ -163,7 +163,8 @@ extern "C" { ...@@ -163,7 +163,8 @@ extern "C" {
/****************************************************************************/ /****************************************************************************/
/* Initialize the ha_connect static members. */ /* Initialize the ha_connect static members. */
/****************************************************************************/ /****************************************************************************/
char connectini[_MAX_PATH]= "connect.ini"; #define CONNECT_INI "connect.ini"
char connectini[_MAX_PATH]= CONNECT_INI;
int xtrace= 0; int xtrace= 0;
ulong ha_connect::num= 0; ulong ha_connect::num= 0;
//int DTVAL::Shift= 0; //int DTVAL::Shift= 0;
...@@ -337,9 +338,36 @@ static void init_connect_psi_keys() ...@@ -337,9 +338,36 @@ static void init_connect_psi_keys()
} }
#endif #endif
/**
@brief
Plugin initialization
*/
static int connect_init_func(void *p) static int connect_init_func(void *p)
{ {
DBUG_ENTER("connect_init_func"); DBUG_ENTER("connect_init_func");
char dir[_MAX_PATH - sizeof(CONNECT_INI) - 1];
#ifdef LIBXML2_SUPPORT
XmlInitParserLib();
#endif // LIBXML2_SUPPORT
/* Build connect.ini file name */
my_getwd(dir, sizeof(dir) - 1, MYF(0));
snprintf(connectini, sizeof(connectini), "%s%s", dir, CONNECT_INI);
sql_print_information("CONNECT: %s=%s", CONNECT_INI, connectini);
if ((xtrace= GetPrivateProfileInt("CONNECT", "Trace", 0, connectini)))
{
sql_print_information("CONNECT: xtrace=%d", xtrace);
sql_print_information("CONNECT: plgini=%s", plgini);
sql_print_information("CONNECT: plgxini=%s", plgxini);
sql_print_information("CONNECT: nmfile=%s", nmfile);
sql_print_information("CONNECT: pdebug=%s", pdebug);
sql_print_information("CONNECT: version=%s", version);
trace= xtrace;
} // endif xtrace
#ifdef HAVE_PSI_INTERFACE #ifdef HAVE_PSI_INTERFACE
init_connect_psi_keys(); init_connect_psi_keys();
...@@ -366,19 +394,27 @@ static int connect_init_func(void *p) ...@@ -366,19 +394,27 @@ static int connect_init_func(void *p)
#endif // !MARIADB #endif // !MARIADB
if (xtrace) if (xtrace)
printf("connect_init: hton=%p\n", p); sql_print_information("connect_init: hton=%p", p);
DTVAL::SetTimeShift(); // Initialize time zone shift once for all DTVAL::SetTimeShift(); // Initialize time zone shift once for all
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/**
@brief
Plugin clean up
*/
static int connect_done_func(void *p) static int connect_done_func(void *p)
{ {
int error= 0; int error= 0;
PCONNECT pc, pn; PCONNECT pc, pn;
DBUG_ENTER("connect_done_func"); DBUG_ENTER("connect_done_func");
#ifdef LIBXML2_SUPPORT
XmlCleanupParserLib();
#endif // LIBXML2_SUPPORT
if (connect_open_tables.records) if (connect_open_tables.records)
error= 1; error= 1;
...@@ -3809,80 +3845,3 @@ maria_declare_plugin(connect) ...@@ -3809,80 +3845,3 @@ maria_declare_plugin(connect)
} }
maria_declare_plugin_end; maria_declare_plugin_end;
#endif // MARIADB #endif // MARIADB
#if defined(WIN32)
/**************************************************************************/
/* DllMain */
/**************************************************************************/
bool APIENTRY DllMain(HINSTANCE hInst, ULONG ulReason, PCONTEXT pctx)
{
switch (ulReason) {
case DLL_PROCESS_ATTACH:
printf("CONNECT Engine loaded...\n");
GetCurrentDirectory(sizeof(connectini), connectini);
strcat(connectini, "\\connect.ini");
if ((xtrace= GetPrivateProfileInt("CONNECT", "Trace", 0, connectini))) {
printf("connectini=%s xtrace=%d\n", connectini, xtrace);
printf("plgini=%s\n", plgini);
printf("plgxini=%s\n", plgxini);
printf("nmfile=%s\n", nmfile);
printf("pdebug=%s\n", pdebug);
printf("version=%s\n", version);
trace= xtrace;
} // endif xtrace
#ifdef LIBXML2_SUPPORT
XmlInitParserLib();
#endif // LIBXML2_SUPPORT
break;
case DLL_PROCESS_DETACH:
#ifdef LIBXML2_SUPPORT
XmlCleanupParserLib();
#endif // LIBXML2_SUPPORT
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
default:
break;
} // endswitch ulReason
return true;
} // end of DllMain
#else // !WIN32
/**************************************************************************/
/* Library's initialization function. */
/**************************************************************************/
void __attribute__((constructor)) init()
{
printf("CONNECT Engine loaded...\n");
getcwd(connectini, sizeof(connectini));
strcat(connectini, "/connect.ini");
printf("connectini=%s\n", connectini);
if ((xtrace= GetPrivateProfileInt("CONNECT", "Trace", 0, connectini))) {
printf("connectini=%s xtrace=%d\n", connectini, xtrace);
printf("plgini=%s\n", plgini);
printf("plgxini=%s\n", plgxini);
printf("nmfile=%s\n", nmfile);
printf("pdebug=%s\n", pdebug);
printf("version=%s\n", version);
trace= xtrace;
} // endif xtrace
#ifdef LIBXML2_SUPPORT
XmlInitParserLib();
#endif // LIBXML2_SUPPORT
} // end of init
/**************************************************************************/
/* Library's cleanup function */
/**************************************************************************/
void __attribute__((destructor)) fini()
{
#ifdef LIBXML2_SUPPORT
XmlCleanupParserLib();
#endif // LIBXML2_SUPPORT
} // end of fini
#endif // !WIN32
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment