Commit c63f2410 authored by unknown's avatar unknown

merged


mysql-test/r/create.result:
  Auto merged
sql/slave.cc:
  Auto merged
sql/sql_parse.cc:
  Auto merged
parents 67056e05 438cb0f0
LIBRARY LIBMYSQL
DESCRIPTION 'MySQL 3.23 Client Library'
VERSION 2.5
EXPORTS
mysql_affected_rows
mysql_close
mysql_connect
mysql_create_db
mysql_data_seek
mysql_debug
mysql_drop_db
mysql_dump_debug_info
mysql_eof
mysql_errno
mysql_error
mysql_escape_string
mysql_fetch_field
mysql_fetch_field_direct
mysql_fetch_fields
mysql_fetch_lengths
mysql_fetch_row
mysql_field_count
mysql_field_seek
mysql_field_tell
mysql_free_result
mysql_get_client_info
mysql_get_host_info
mysql_get_proto_info
mysql_get_server_info
mysql_info
mysql_init
mysql_insert_id
mysql_kill
mysql_list_dbs
mysql_list_fields
mysql_list_processes
mysql_list_tables
mysql_num_fields
mysql_num_rows
mysql_odbc_escape_string
mysql_options
mysql_ping
mysql_query
mysql_real_connect
mysql_real_query
mysql_refresh
mysql_row_seek
mysql_row_tell
mysql_select_db
mysql_shutdown
mysql_stat
mysql_store_result
mysql_thread_id
mysql_use_result
bmove_upp
delete_dynamic
_dig_vec
init_dynamic_array
insert_dynamic
int2str
is_prefix
list_add
list_delete
max_allowed_packet
my_casecmp
my_init
my_end
my_strdup
my_malloc
my_memdup
my_no_flags_free
my_realloc
my_thread_end
my_thread_init
net_buffer_length
set_dynamic
strcend
strdup_root
strfill
strinstr
strmake
strmov
strxmov
myodbc_remove_escape
mysql_thread_safe
mysql_character_set_name
mysql_change_user
mysql_send_query
mysql_read_query_result
mysql_real_escape_string
load_defaults
free_defaults
/**************************************************************************** /****************************************************************************
MySqlShutdown - shutdown MySQL on system shutdown (Win95/98) MySqlShutdown - shutdown MySQL on system shutdown (Win95/98)
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
Revision History : Revision History :
Version Author Date Description Version Author Date Description
001.00 Irena 21-12-99 001.00 Irena 21-12-99
*****************************************************************************/ *****************************************************************************/
#include <windows.h> #include <windows.h>
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Local data // Local data
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
static char szAppName[] = "MySqlShutdown"; static char szAppName[] = "MySqlShutdown";
static HINSTANCE hInstance; static HINSTANCE hInstance;
#define MYWM_NOTIFYICON (WM_APP+100) #define MYWM_NOTIFYICON (WM_APP+100)
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Exported functions // Exported functions
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
LRESULT CALLBACK MainWindowProc (HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK MainWindowProc (HWND, UINT, WPARAM, LPARAM);
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Local functions // Local functions
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
static BOOL InitAppClass (HINSTANCE hInstance); static BOOL InitAppClass (HINSTANCE hInstance);
BOOL TrayMessageAdd(HWND hWnd, DWORD dwMessage) BOOL TrayMessageAdd(HWND hWnd, DWORD dwMessage)
{ {
BOOL res; BOOL res;
HICON hIcon =LoadIcon (hInstance, "MySql"); HICON hIcon =LoadIcon (hInstance, "MySql");
char *szTip="MySql Shutdown"; char *szTip="MySql Shutdown";
NOTIFYICONDATA tnd; NOTIFYICONDATA tnd;
tnd.cbSize = sizeof(NOTIFYICONDATA); tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = hWnd; tnd.hWnd = hWnd;
tnd.uID = 101; tnd.uID = 101;
tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP; tnd.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage = MYWM_NOTIFYICON; tnd.uCallbackMessage = MYWM_NOTIFYICON;
tnd.hIcon = hIcon; tnd.hIcon = hIcon;
strcpy(tnd.szTip, szTip); strcpy(tnd.szTip, szTip);
res = Shell_NotifyIcon(dwMessage, &tnd); res = Shell_NotifyIcon(dwMessage, &tnd);
if (hIcon) DestroyIcon(hIcon); if (hIcon) DestroyIcon(hIcon);
return res; return res;
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Name: WinMain // Name: WinMain
// Purpose: Main application entry point // Purpose: Main application entry point
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow) int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{ HWND hWnd; { HWND hWnd;
MSG Msg; MSG Msg;
hInstance=hInst; hInstance=hInst;
// Register application class if needed // Register application class if needed
if (InitAppClass (hInstance) == FALSE) return (0); if (InitAppClass (hInstance) == FALSE) return (0);
hWnd = CreateWindow (szAppName, "MySql", hWnd = CreateWindow (szAppName, "MySql",
WS_OVERLAPPEDWINDOW|WS_MINIMIZE, WS_OVERLAPPEDWINDOW|WS_MINIMIZE,
0, 0, 0, 0,
GetSystemMetrics(SM_CXSCREEN)/4, GetSystemMetrics(SM_CXSCREEN)/4,
GetSystemMetrics(SM_CYSCREEN)/4, GetSystemMetrics(SM_CYSCREEN)/4,
0, 0, hInstance, NULL); 0, 0, hInstance, NULL);
if(!hWnd) if(!hWnd)
{ {
return (0); return (0);
} }
ShowWindow (hWnd, SW_HIDE); ShowWindow (hWnd, SW_HIDE);
UpdateWindow (hWnd); UpdateWindow (hWnd);
while (GetMessage (&Msg, 0, 0, 0)) while (GetMessage (&Msg, 0, 0, 0))
{ TranslateMessage (&Msg); { TranslateMessage (&Msg);
DispatchMessage (&Msg); DispatchMessage (&Msg);
} }
return ((int) (Msg.wParam)); return ((int) (Msg.wParam));
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Name: InitAppClass // Name: InitAppClass
// Purpose: Register the main application window class // Purpose: Register the main application window class
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
static BOOL InitAppClass (HINSTANCE hInstance) static BOOL InitAppClass (HINSTANCE hInstance)
{ {
WNDCLASS cls; WNDCLASS cls;
if (GetClassInfo (hInstance, szAppName, &cls) == 0) if (GetClassInfo (hInstance, szAppName, &cls) == 0)
{ {
cls.style = CS_HREDRAW | CS_VREDRAW ;; cls.style = CS_HREDRAW | CS_VREDRAW ;;
cls.lpfnWndProc = (WNDPROC) MainWindowProc; cls.lpfnWndProc = (WNDPROC) MainWindowProc;
cls.cbClsExtra = 0; cls.cbClsExtra = 0;
cls.cbWndExtra = sizeof(HWND); cls.cbWndExtra = sizeof(HWND);
cls.hInstance = hInstance; cls.hInstance = hInstance;
cls.hIcon = LoadIcon (hInstance, "MySql"); cls.hIcon = LoadIcon (hInstance, "MySql");
cls.hCursor = LoadCursor (NULL, IDC_ARROW); cls.hCursor = LoadCursor (NULL, IDC_ARROW);
cls.hbrBackground = GetStockObject (WHITE_BRUSH) ; cls.hbrBackground = GetStockObject (WHITE_BRUSH) ;
cls.lpszMenuName = 0; //szAppName; cls.lpszMenuName = 0; //szAppName;
cls.lpszClassName = szAppName; cls.lpszClassName = szAppName;
return RegisterClass (&cls); return RegisterClass (&cls);
} }
return (TRUE); return (TRUE);
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// Name: MainWindowProc // Name: MainWindowProc
// Purpose: Window procedure for main application window. // Purpose: Window procedure for main application window.
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
LRESULT CALLBACK MainWindowProc (HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam) LRESULT CALLBACK MainWindowProc (HWND hWnd, UINT Msg,WPARAM wParam, LPARAM lParam)
{ {
static RECT rect ; static RECT rect ;
HDC hdc ; HDC hdc ;
PAINTSTRUCT ps ; PAINTSTRUCT ps ;
static BOOL bShutdown=FALSE; static BOOL bShutdown=FALSE;
switch (Msg) switch (Msg)
{ {
case WM_CREATE: case WM_CREATE:
TrayMessageAdd(hWnd, NIM_ADD); TrayMessageAdd(hWnd, NIM_ADD);
return TRUE; return TRUE;
/*************** /***************
case WM_SYSCOMMAND: case WM_SYSCOMMAND:
if(wParam==SC_CLOSE) if(wParam==SC_CLOSE)
{ HANDLE hEventShutdown; { HANDLE hEventShutdown;
bShutdown=TRUE; bShutdown=TRUE;
InvalidateRect(hWnd,NULL,TRUE); InvalidateRect(hWnd,NULL,TRUE);
ShowWindow (hWnd, SW_NORMAL); ShowWindow (hWnd, SW_NORMAL);
UpdateWindow(hWnd); UpdateWindow(hWnd);
hEventShutdown=OpenEvent(EVENT_MODIFY_STATE, 0, "MySqlShutdown"); hEventShutdown=OpenEvent(EVENT_MODIFY_STATE, 0, "MySqlShutdown");
if(hEventShutdown) if(hEventShutdown)
{ {
SetEvent(hEventShutdown); SetEvent(hEventShutdown);
CloseHandle(hEventShutdown); CloseHandle(hEventShutdown);
Sleep(1000); Sleep(1000);
MessageBox(hWnd,"Shutdown", "MySql", MB_OK); MessageBox(hWnd,"Shutdown", "MySql", MB_OK);
} }
TrayMessageAdd(hWnd, NIM_DELETE); TrayMessageAdd(hWnd, NIM_DELETE);
} }
break; break;
**************/ **************/
case WM_DESTROY: case WM_DESTROY:
TrayMessageAdd(hWnd, NIM_DELETE); TrayMessageAdd(hWnd, NIM_DELETE);
PostQuitMessage (0); PostQuitMessage (0);
return 0; return 0;
case WM_SIZE: case WM_SIZE:
GetClientRect (hWnd, &rect) ; GetClientRect (hWnd, &rect) ;
return 0 ; return 0 ;
case WM_PAINT: case WM_PAINT:
hdc = BeginPaint (hWnd, &ps) ; hdc = BeginPaint (hWnd, &ps) ;
if(bShutdown) if(bShutdown)
DrawText (hdc, "MySql shutdown in progress...", DrawText (hdc, "MySql shutdown in progress...",
-1, &rect, DT_WORDBREAK) ; -1, &rect, DT_WORDBREAK) ;
EndPaint (hWnd, &ps) ; EndPaint (hWnd, &ps) ;
return 0 ; return 0 ;
case WM_QUERYENDSESSION: //Shutdown MySql case WM_QUERYENDSESSION: //Shutdown MySql
{ HANDLE hEventShutdown; { HANDLE hEventShutdown;
bShutdown=TRUE; bShutdown=TRUE;
InvalidateRect(hWnd,NULL,TRUE); InvalidateRect(hWnd,NULL,TRUE);
ShowWindow (hWnd, SW_NORMAL); ShowWindow (hWnd, SW_NORMAL);
UpdateWindow(hWnd); UpdateWindow(hWnd);
hEventShutdown=OpenEvent(EVENT_MODIFY_STATE, 0, "MySqlShutdown"); hEventShutdown=OpenEvent(EVENT_MODIFY_STATE, 0, "MySqlShutdown");
if(hEventShutdown) if(hEventShutdown)
{ {
SetEvent(hEventShutdown); SetEvent(hEventShutdown);
CloseHandle(hEventShutdown); CloseHandle(hEventShutdown);
Sleep(1000); Sleep(1000);
MessageBox(hWnd,"Shutdown", "MySql", MB_OK); MessageBox(hWnd,"Shutdown", "MySql", MB_OK);
} }
} }
return 1; return 1;
case MYWM_NOTIFYICON: case MYWM_NOTIFYICON:
switch (lParam) switch (lParam)
{ {
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
ShowWindow(hWnd, SW_SHOWNORMAL); ShowWindow(hWnd, SW_SHOWNORMAL);
SetForegroundWindow(hWnd); // make us come to the front SetForegroundWindow(hWnd); // make us come to the front
break; break;
default: default:
break; break;
} }
break; break;
} }
return DefWindowProc (hWnd, Msg, wParam, lParam); return DefWindowProc (hWnd, Msg, wParam, lParam);
} }
// ----------------------- The end ------------------------------------------ // ----------------------- The end ------------------------------------------
MySql ICON DISCARDABLE "MYSQL.ICO" MySql ICON DISCARDABLE "MYSQL.ICO"
/**************************************************************************** /****************************************************************************
MySqlWatch - WinNT service program MySQL MySqlWatch - WinNT service program MySQL
- Re-start MySql server in case of failure - Re-start MySql server in case of failure
*****************************************************************************/ *****************************************************************************/
#include <windows.h> #include <windows.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <process.h> #include <process.h>
#include <tchar.h> #include <tchar.h>
// name of the executable // name of the executable
#define SZAPPNAME "mysqlwatch" #define SZAPPNAME "mysqlwatch"
// internal name of the service // internal name of the service
#define SZSERVICENAME "MySqlWatch" #define SZSERVICENAME "MySqlWatch"
// displayed name of the service // displayed name of the service
#define SZSERVICEDISPLAYNAME "MySqlWatch" #define SZSERVICEDISPLAYNAME "MySqlWatch"
// list of service dependencies - "dep1\0dep2\0\0" // list of service dependencies - "dep1\0dep2\0\0"
#define SZDEPENDENCIES "" #define SZDEPENDENCIES ""
VOID ServiceStart(DWORD dwArgc, LPTSTR *lpszArgv); VOID ServiceStart(DWORD dwArgc, LPTSTR *lpszArgv);
VOID ServiceStop(void); VOID ServiceStop(void);
BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint); BOOL ReportStatusToSCMgr(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint);
void AddToMessageLog(LPTSTR lpszMsg); void AddToMessageLog(LPTSTR lpszMsg);
// internal variables // internal variables
SERVICE_STATUS ssStatus; // current status of the service SERVICE_STATUS ssStatus; // current status of the service
SERVICE_STATUS_HANDLE sshStatusHandle; SERVICE_STATUS_HANDLE sshStatusHandle;
DWORD dwErr = 0; DWORD dwErr = 0;
BOOL bDebug = FALSE; BOOL bDebug = FALSE;
TCHAR szErr[256]; TCHAR szErr[256];
// internal function prototypes // internal function prototypes
void WINAPI service_ctrl(DWORD dwCtrlCode); void WINAPI service_ctrl(DWORD dwCtrlCode);
void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv); void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv);
void CmdInstallService(void); void CmdInstallService(void);
void CmdRemoveService(void); void CmdRemoveService(void);
void CmdDebugService(int argc, char **argv); void CmdDebugService(int argc, char **argv);
BOOL WINAPI ControlHandler ( DWORD dwCtrlType ); BOOL WINAPI ControlHandler ( DWORD dwCtrlType );
LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ); LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize );
// //
// FUNCTION: main // FUNCTION: main
// //
// PURPOSE: entrypoint for service // PURPOSE: entrypoint for service
// //
// PARAMETERS: // PARAMETERS:
// argc - number of command line arguments // argc - number of command line arguments
// argv - array of command line arguments // argv - array of command line arguments
// //
// RETURN VALUE: // RETURN VALUE:
// none // none
// //
// COMMENTS: // COMMENTS:
// main() either performs the command line task, or // main() either performs the command line task, or
// call StartServiceCtrlDispatcher to register the // call StartServiceCtrlDispatcher to register the
// main service thread. When the this call returns, // main service thread. When the this call returns,
// the service has stopped, so exit. // the service has stopped, so exit.
// //
void main(int argc, char **argv) void main(int argc, char **argv)
{ {
SERVICE_TABLE_ENTRY dispatchTable[] = SERVICE_TABLE_ENTRY dispatchTable[] =
{ {
{ TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main }, { TEXT(SZSERVICENAME), (LPSERVICE_MAIN_FUNCTION)service_main },
{ NULL, NULL } { NULL, NULL }
}; };
if ( (argc > 1) && if ( (argc > 1) &&
((*argv[1] == '-') || (*argv[1] == '/')) ) ((*argv[1] == '-') || (*argv[1] == '/')) )
{ {
if ( stricmp( "install", argv[1]+1 ) == 0 ) if ( stricmp( "install", argv[1]+1 ) == 0 )
{ {
CmdInstallService(); CmdInstallService();
} }
else if ( stricmp( "remove", argv[1]+1 ) == 0 ) else if ( stricmp( "remove", argv[1]+1 ) == 0 )
{ {
CmdRemoveService(); CmdRemoveService();
} }
else if ( stricmp( "debug", argv[1]+1 ) == 0 ) else if ( stricmp( "debug", argv[1]+1 ) == 0 )
{ {
bDebug = TRUE; bDebug = TRUE;
CmdDebugService(argc, argv); CmdDebugService(argc, argv);
} }
else else
{ {
goto dispatch; goto dispatch;
} }
exit(0); exit(0);
} }
// if it doesn't match any of the above parameters // if it doesn't match any of the above parameters
// the service control manager may be starting the service // the service control manager may be starting the service
// so we must call StartServiceCtrlDispatcher // so we must call StartServiceCtrlDispatcher
dispatch: dispatch:
// this is just to be friendly // this is just to be friendly
printf( "%s -install to install the service\n", SZAPPNAME ); printf( "%s -install to install the service\n", SZAPPNAME );
printf( "%s -remove to remove the service\n", SZAPPNAME ); printf( "%s -remove to remove the service\n", SZAPPNAME );
printf( "%s -debug <params> to run as a console app for debugging\n", SZAPPNAME ); printf( "%s -debug <params> to run as a console app for debugging\n", SZAPPNAME );
printf( "\nStartServiceCtrlDispatcher being called.\n" ); printf( "\nStartServiceCtrlDispatcher being called.\n" );
printf( "This may take several seconds. Please wait.\n" ); printf( "This may take several seconds. Please wait.\n" );
if (!StartServiceCtrlDispatcher(dispatchTable)) if (!StartServiceCtrlDispatcher(dispatchTable))
AddToMessageLog(TEXT("StartServiceCtrlDispatcher failed.")); AddToMessageLog(TEXT("StartServiceCtrlDispatcher failed."));
} }
// //
// FUNCTION: service_main // FUNCTION: service_main
// //
// PURPOSE: To perform actual initialization of the service // PURPOSE: To perform actual initialization of the service
// //
// PARAMETERS: // PARAMETERS:
// dwArgc - number of command line arguments // dwArgc - number of command line arguments
// lpszArgv - array of command line arguments // lpszArgv - array of command line arguments
// //
// RETURN VALUE: // RETURN VALUE:
// none // none
// //
// COMMENTS: // COMMENTS:
// This routine performs the service initialization and then calls // This routine performs the service initialization and then calls
// the user defined ServiceStart() routine to perform majority // the user defined ServiceStart() routine to perform majority
// of the work. // of the work.
// //
void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv) void WINAPI service_main(DWORD dwArgc, LPTSTR *lpszArgv)
{ {
// register our service control handler: // register our service control handler:
// //
sshStatusHandle = RegisterServiceCtrlHandler( TEXT(SZSERVICENAME), service_ctrl); sshStatusHandle = RegisterServiceCtrlHandler( TEXT(SZSERVICENAME), service_ctrl);
if (!sshStatusHandle) if (!sshStatusHandle)
goto cleanup; goto cleanup;
// SERVICE_STATUS members that don't change in example // SERVICE_STATUS members that don't change in example
// //
ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
ssStatus.dwServiceSpecificExitCode = 0; ssStatus.dwServiceSpecificExitCode = 0;
// report the status to the service control manager. // report the status to the service control manager.
// //
if (!ReportStatusToSCMgr( if (!ReportStatusToSCMgr(
SERVICE_START_PENDING, // service state SERVICE_START_PENDING, // service state
NO_ERROR, // exit code NO_ERROR, // exit code
3000)) // wait hint 3000)) // wait hint
goto cleanup; goto cleanup;
ServiceStart( dwArgc, lpszArgv ); ServiceStart( dwArgc, lpszArgv );
cleanup: cleanup:
// try to report the stopped status to the service control manager. // try to report the stopped status to the service control manager.
// //
if (sshStatusHandle) if (sshStatusHandle)
ReportStatusToSCMgr( ReportStatusToSCMgr(
SERVICE_STOPPED, SERVICE_STOPPED,
dwErr, dwErr,
0); 0);
return; return;
} }
// //
// FUNCTION: service_ctrl // FUNCTION: service_ctrl
// //
// PURPOSE: This function is called by the SCM whenever // PURPOSE: This function is called by the SCM whenever
// ControlService() is called on this service. // ControlService() is called on this service.
// //
// PARAMETERS: // PARAMETERS:
// dwCtrlCode - type of control requested // dwCtrlCode - type of control requested
// //
// RETURN VALUE: // RETURN VALUE:
// none // none
// //
// COMMENTS: // COMMENTS:
// //
void WINAPI service_ctrl(DWORD dwCtrlCode) void WINAPI service_ctrl(DWORD dwCtrlCode)
{ {
// Handle the requested control code. // Handle the requested control code.
// //
switch(dwCtrlCode) switch(dwCtrlCode)
{ {
// Stop the service. // Stop the service.
// //
case SERVICE_CONTROL_STOP: case SERVICE_CONTROL_STOP:
ssStatus.dwCurrentState = SERVICE_STOP_PENDING; ssStatus.dwCurrentState = SERVICE_STOP_PENDING;
ServiceStop(); ServiceStop();
break; break;
// Update the service status. // Update the service status.
// //
case SERVICE_CONTROL_INTERROGATE: case SERVICE_CONTROL_INTERROGATE:
break; break;
// invalid control code // invalid control code
// //
default: default:
break; break;
} }
ReportStatusToSCMgr(ssStatus.dwCurrentState, NO_ERROR, 0); ReportStatusToSCMgr(ssStatus.dwCurrentState, NO_ERROR, 0);
} }
// //
// FUNCTION: ReportStatusToSCMgr() // FUNCTION: ReportStatusToSCMgr()
// //
// PURPOSE: Sets the current status of the service and // PURPOSE: Sets the current status of the service and
// reports it to the Service Control Manager // reports it to the Service Control Manager
// //
// PARAMETERS: // PARAMETERS:
// dwCurrentState - the state of the service // dwCurrentState - the state of the service
// dwWin32ExitCode - error code to report // dwWin32ExitCode - error code to report
// dwWaitHint - worst case estimate to next checkpoint // dwWaitHint - worst case estimate to next checkpoint
// //
// RETURN VALUE: // RETURN VALUE:
// TRUE - success // TRUE - success
// FALSE - failure // FALSE - failure
// //
// COMMENTS: // COMMENTS:
// //
BOOL ReportStatusToSCMgr(DWORD dwCurrentState, BOOL ReportStatusToSCMgr(DWORD dwCurrentState,
DWORD dwWin32ExitCode, DWORD dwWin32ExitCode,
DWORD dwWaitHint) DWORD dwWaitHint)
{ {
static DWORD dwCheckPoint = 1; static DWORD dwCheckPoint = 1;
BOOL fResult = TRUE; BOOL fResult = TRUE;
if ( !bDebug ) // when debugging we don't report to the SCM if ( !bDebug ) // when debugging we don't report to the SCM
{ {
if (dwCurrentState == SERVICE_START_PENDING) if (dwCurrentState == SERVICE_START_PENDING)
ssStatus.dwControlsAccepted = 0; ssStatus.dwControlsAccepted = 0;
else else
ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
ssStatus.dwCurrentState = dwCurrentState; ssStatus.dwCurrentState = dwCurrentState;
ssStatus.dwWin32ExitCode = dwWin32ExitCode; ssStatus.dwWin32ExitCode = dwWin32ExitCode;
ssStatus.dwWaitHint = dwWaitHint; ssStatus.dwWaitHint = dwWaitHint;
if ( ( dwCurrentState == SERVICE_RUNNING ) || if ( ( dwCurrentState == SERVICE_RUNNING ) ||
( dwCurrentState == SERVICE_STOPPED ) ) ( dwCurrentState == SERVICE_STOPPED ) )
ssStatus.dwCheckPoint = 0; ssStatus.dwCheckPoint = 0;
else else
ssStatus.dwCheckPoint = dwCheckPoint++; ssStatus.dwCheckPoint = dwCheckPoint++;
// Report the status of the service to the service control manager. // Report the status of the service to the service control manager.
// //
if (!(fResult = SetServiceStatus( sshStatusHandle, &ssStatus))) { if (!(fResult = SetServiceStatus( sshStatusHandle, &ssStatus))) {
AddToMessageLog(TEXT("SetServiceStatus")); AddToMessageLog(TEXT("SetServiceStatus"));
} }
} }
return fResult; return fResult;
} }
// //
// FUNCTION: AddToMessageLog(LPTSTR lpszMsg) // FUNCTION: AddToMessageLog(LPTSTR lpszMsg)
// //
// PURPOSE: Allows any thread to log an error message // PURPOSE: Allows any thread to log an error message
// //
// PARAMETERS: // PARAMETERS:
// lpszMsg - text for message // lpszMsg - text for message
// //
// RETURN VALUE: // RETURN VALUE:
// none // none
// //
// COMMENTS: // COMMENTS:
// //
void AddToMessageLog(LPTSTR lpszMsg) void AddToMessageLog(LPTSTR lpszMsg)
{ {
TCHAR szMsg[256]; TCHAR szMsg[256];
HANDLE hEventSource; HANDLE hEventSource;
LPTSTR lpszStrings[2]; LPTSTR lpszStrings[2];
if ( !bDebug ) if ( !bDebug )
{ {
dwErr = GetLastError(); dwErr = GetLastError();
// Use event logging to log the error. // Use event logging to log the error.
// //
hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME)); hEventSource = RegisterEventSource(NULL, TEXT(SZSERVICENAME));
_stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr); _stprintf(szMsg, TEXT("%s error: %d"), TEXT(SZSERVICENAME), dwErr);
lpszStrings[0] = szMsg; lpszStrings[0] = szMsg;
lpszStrings[1] = lpszMsg; lpszStrings[1] = lpszMsg;
if (hEventSource != NULL) { if (hEventSource != NULL) {
ReportEvent(hEventSource, // handle of event source ReportEvent(hEventSource, // handle of event source
EVENTLOG_ERROR_TYPE, // event type EVENTLOG_ERROR_TYPE, // event type
0, // event category 0, // event category
0, // event ID 0, // event ID
NULL, // current user's SID NULL, // current user's SID
2, // strings in lpszStrings 2, // strings in lpszStrings
0, // no bytes of raw data 0, // no bytes of raw data
lpszStrings, // array of error strings lpszStrings, // array of error strings
NULL); // no raw data NULL); // no raw data
DeregisterEventSource(hEventSource); DeregisterEventSource(hEventSource);
} }
} }
} }
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// //
// The following code handles service installation and removal // The following code handles service installation and removal
// //
// //
// FUNCTION: CmdInstallService() // FUNCTION: CmdInstallService()
// //
// PURPOSE: Installs the service // PURPOSE: Installs the service
// //
// PARAMETERS: // PARAMETERS:
// none // none
// //
// RETURN VALUE: // RETURN VALUE:
// none // none
// //
// COMMENTS: // COMMENTS:
// //
void CmdInstallService() void CmdInstallService()
{ {
SC_HANDLE schService; SC_HANDLE schService;
SC_HANDLE schSCManager; SC_HANDLE schSCManager;
TCHAR szPath[512]; TCHAR szPath[512];
if ( GetModuleFileName( NULL, szPath, 512 ) == 0 ) if ( GetModuleFileName( NULL, szPath, 512 ) == 0 )
{ {
_tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256)); _tprintf(TEXT("Unable to install %s - %s\n"), TEXT(SZSERVICEDISPLAYNAME), GetLastErrorText(szErr, 256));
return; return;
} }
schSCManager = OpenSCManager( schSCManager = OpenSCManager(
NULL, // machine (NULL == local) NULL, // machine (NULL == local)
NULL, // database (NULL == default) NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required SC_MANAGER_ALL_ACCESS // access required
); );
if ( schSCManager ) if ( schSCManager )
{ {
schService = CreateService( schService = CreateService(
schSCManager, // SCManager database schSCManager, // SCManager database
TEXT(SZSERVICENAME), // name of service TEXT(SZSERVICENAME), // name of service
TEXT(SZSERVICEDISPLAYNAME), // name to display TEXT(SZSERVICEDISPLAYNAME), // name to display
SERVICE_ALL_ACCESS, // desired access SERVICE_ALL_ACCESS, // desired access
SERVICE_WIN32_OWN_PROCESS, // service type SERVICE_WIN32_OWN_PROCESS, // service type
SERVICE_DEMAND_START, // start type SERVICE_DEMAND_START, // start type
SERVICE_ERROR_NORMAL, // error control type SERVICE_ERROR_NORMAL, // error control type
szPath, // service's binary szPath, // service's binary
NULL, // no load ordering group NULL, // no load ordering group
NULL, // no tag identifier NULL, // no tag identifier
TEXT(SZDEPENDENCIES), // dependencies TEXT(SZDEPENDENCIES), // dependencies
NULL, // LocalSystem account NULL, // LocalSystem account
NULL); // no password NULL); // no password
if ( schService ) if ( schService )
{ {
_tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) ); _tprintf(TEXT("%s installed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
CloseServiceHandle(schService); CloseServiceHandle(schService);
} }
else else
{ {
_tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256)); _tprintf(TEXT("CreateService failed - %s\n"), GetLastErrorText(szErr, 256));
} }
CloseServiceHandle(schSCManager); CloseServiceHandle(schSCManager);
} }
else else
_tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
} }
// //
// FUNCTION: CmdRemoveService() // FUNCTION: CmdRemoveService()
// //
// PURPOSE: Stops and removes the service // PURPOSE: Stops and removes the service
// //
// PARAMETERS: // PARAMETERS:
// none // none
// //
// RETURN VALUE: // RETURN VALUE:
// none // none
// //
// COMMENTS: // COMMENTS:
// //
void CmdRemoveService() void CmdRemoveService()
{ {
SC_HANDLE schService; SC_HANDLE schService;
SC_HANDLE schSCManager; SC_HANDLE schSCManager;
schSCManager = OpenSCManager( schSCManager = OpenSCManager(
NULL, // machine (NULL == local) NULL, // machine (NULL == local)
NULL, // database (NULL == default) NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required SC_MANAGER_ALL_ACCESS // access required
); );
if ( schSCManager ) if ( schSCManager )
{ {
schService = OpenService(schSCManager, TEXT(SZSERVICENAME), SERVICE_ALL_ACCESS); schService = OpenService(schSCManager, TEXT(SZSERVICENAME), SERVICE_ALL_ACCESS);
if (schService) if (schService)
{ {
// try to stop the service // try to stop the service
if ( ControlService( schService, SERVICE_CONTROL_STOP, &ssStatus ) ) if ( ControlService( schService, SERVICE_CONTROL_STOP, &ssStatus ) )
{ {
_tprintf(TEXT("Stopping %s."), TEXT(SZSERVICEDISPLAYNAME)); _tprintf(TEXT("Stopping %s."), TEXT(SZSERVICEDISPLAYNAME));
Sleep( 1000 ); Sleep( 1000 );
while( QueryServiceStatus( schService, &ssStatus ) ) while( QueryServiceStatus( schService, &ssStatus ) )
{ {
if ( ssStatus.dwCurrentState == SERVICE_STOP_PENDING ) if ( ssStatus.dwCurrentState == SERVICE_STOP_PENDING )
{ {
_tprintf(TEXT(".")); _tprintf(TEXT("."));
Sleep( 1000 ); Sleep( 1000 );
} }
else else
break; break;
} }
if ( ssStatus.dwCurrentState == SERVICE_STOPPED ) if ( ssStatus.dwCurrentState == SERVICE_STOPPED )
_tprintf(TEXT("\n%s stopped.\n"), TEXT(SZSERVICEDISPLAYNAME) ); _tprintf(TEXT("\n%s stopped.\n"), TEXT(SZSERVICEDISPLAYNAME) );
else else
_tprintf(TEXT("\n%s failed to stop.\n"), TEXT(SZSERVICEDISPLAYNAME) ); _tprintf(TEXT("\n%s failed to stop.\n"), TEXT(SZSERVICEDISPLAYNAME) );
} }
// now remove the service // now remove the service
if( DeleteService(schService) ) if( DeleteService(schService) )
_tprintf(TEXT("%s removed.\n"), TEXT(SZSERVICEDISPLAYNAME) ); _tprintf(TEXT("%s removed.\n"), TEXT(SZSERVICEDISPLAYNAME) );
else else
_tprintf(TEXT("DeleteService failed - %s\n"), GetLastErrorText(szErr,256)); _tprintf(TEXT("DeleteService failed - %s\n"), GetLastErrorText(szErr,256));
CloseServiceHandle(schService); CloseServiceHandle(schService);
} }
else else
_tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256)); _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256));
CloseServiceHandle(schSCManager); CloseServiceHandle(schSCManager);
} }
else else
_tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
} }
// //
// FUNCTION: CmdRestartService() // FUNCTION: CmdRestartService()
// //
// PURPOSE: Stops and removes the service // PURPOSE: Stops and removes the service
// //
// PARAMETERS: // PARAMETERS:
// none // none
// //
// RETURN VALUE: // RETURN VALUE:
// none // none
// //
// COMMENTS: // COMMENTS:
// //
void CmdRestartService(char *szServiceName) void CmdRestartService(char *szServiceName)
{ {
SC_HANDLE schService; SC_HANDLE schService;
SC_HANDLE schSCManager; SC_HANDLE schSCManager;
schSCManager = OpenSCManager( schSCManager = OpenSCManager(
NULL, // machine (NULL == local) NULL, // machine (NULL == local)
NULL, // database (NULL == default) NULL, // database (NULL == default)
SC_MANAGER_ALL_ACCESS // access required SC_MANAGER_ALL_ACCESS // access required
); );
if ( schSCManager ) if ( schSCManager )
{ {
schService = OpenService(schSCManager, TEXT(szServiceName), SERVICE_ALL_ACCESS); schService = OpenService(schSCManager, TEXT(szServiceName), SERVICE_ALL_ACCESS);
if (schService) if (schService)
{ {
if(! ControlService( schService, SERVICE_CONTROL_INTERROGATE, &ssStatus ) ) if(! ControlService( schService, SERVICE_CONTROL_INTERROGATE, &ssStatus ) )
//if(QueryServiceStatus( schService, &ssStatus )==0) //if(QueryServiceStatus( schService, &ssStatus )==0)
{ {
if(GetLastError()==ERROR_SERVICE_NOT_ACTIVE) if(GetLastError()==ERROR_SERVICE_NOT_ACTIVE)
{ {
//AddToMessageLog(TEXT("Start service...")); //AddToMessageLog(TEXT("Start service..."));
StartService( schService, 0,NULL); StartService( schService, 0,NULL);
} }
else else
{ ; { ;
//AddToMessageLog(TEXT("QueryService...")); //AddToMessageLog(TEXT("QueryService..."));
//AddToMessageLog(TEXT(GetLastErrorText(szErr,256))); //AddToMessageLog(TEXT(GetLastErrorText(szErr,256)));
} }
} }
CloseServiceHandle(schService); CloseServiceHandle(schService);
} }
else else
{ _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256)); { _tprintf(TEXT("OpenService failed - %s\n"), GetLastErrorText(szErr,256));
AddToMessageLog(TEXT("OpenService...")); AddToMessageLog(TEXT("OpenService..."));
AddToMessageLog(TEXT(GetLastErrorText(szErr,256))); AddToMessageLog(TEXT(GetLastErrorText(szErr,256)));
} }
CloseServiceHandle(schSCManager); CloseServiceHandle(schSCManager);
} }
else else
{ _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256)); { _tprintf(TEXT("OpenSCManager failed - %s\n"), GetLastErrorText(szErr,256));
AddToMessageLog(TEXT("OpenSCMManager..")); AddToMessageLog(TEXT("OpenSCMManager.."));
} }
} }
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// //
// The following code is for running the service as a console app // The following code is for running the service as a console app
// //
// //
// FUNCTION: CmdDebugService(int argc, char ** argv) // FUNCTION: CmdDebugService(int argc, char ** argv)
// //
// PURPOSE: Runs the service as a console application // PURPOSE: Runs the service as a console application
// //
// PARAMETERS: // PARAMETERS:
// argc - number of command line arguments // argc - number of command line arguments
// argv - array of command line arguments // argv - array of command line arguments
// //
// RETURN VALUE: // RETURN VALUE:
// none // none
// //
// COMMENTS: // COMMENTS:
// //
void CmdDebugService(int argc, char ** argv) void CmdDebugService(int argc, char ** argv)
{ {
DWORD dwArgc; DWORD dwArgc;
LPTSTR *lpszArgv; LPTSTR *lpszArgv;
#ifdef UNICODE #ifdef UNICODE
lpszArgv = CommandLineToArgvW(GetCommandLineW(), &(dwArgc) ); lpszArgv = CommandLineToArgvW(GetCommandLineW(), &(dwArgc) );
#else #else
dwArgc = (DWORD) argc; dwArgc = (DWORD) argc;
lpszArgv = argv; lpszArgv = argv;
#endif #endif
_tprintf(TEXT("Debugging %s.\n"), TEXT(SZSERVICEDISPLAYNAME)); _tprintf(TEXT("Debugging %s.\n"), TEXT(SZSERVICEDISPLAYNAME));
SetConsoleCtrlHandler( ControlHandler, TRUE ); SetConsoleCtrlHandler( ControlHandler, TRUE );
ServiceStart( dwArgc, lpszArgv ); ServiceStart( dwArgc, lpszArgv );
} }
// //
// FUNCTION: ControlHandler ( DWORD dwCtrlType ) // FUNCTION: ControlHandler ( DWORD dwCtrlType )
// //
// PURPOSE: Handled console control events // PURPOSE: Handled console control events
// //
// PARAMETERS: // PARAMETERS:
// dwCtrlType - type of control event // dwCtrlType - type of control event
// //
// RETURN VALUE: // RETURN VALUE:
// True - handled // True - handled
// False - unhandled // False - unhandled
// //
// COMMENTS: // COMMENTS:
// //
BOOL WINAPI ControlHandler ( DWORD dwCtrlType ) BOOL WINAPI ControlHandler ( DWORD dwCtrlType )
{ {
switch( dwCtrlType ) switch( dwCtrlType )
{ {
case CTRL_BREAK_EVENT: // use Ctrl+C or Ctrl+Break to simulate case CTRL_BREAK_EVENT: // use Ctrl+C or Ctrl+Break to simulate
case CTRL_C_EVENT: // SERVICE_CONTROL_STOP in debug mode case CTRL_C_EVENT: // SERVICE_CONTROL_STOP in debug mode
_tprintf(TEXT("Stopping %s.\n"), TEXT(SZSERVICEDISPLAYNAME)); _tprintf(TEXT("Stopping %s.\n"), TEXT(SZSERVICEDISPLAYNAME));
ServiceStop(); ServiceStop();
return TRUE; return TRUE;
break; break;
} }
return FALSE; return FALSE;
} }
// //
// FUNCTION: GetLastErrorText // FUNCTION: GetLastErrorText
// //
// PURPOSE: copies error message text to string // PURPOSE: copies error message text to string
// //
// PARAMETERS: // PARAMETERS:
// lpszBuf - destination buffer // lpszBuf - destination buffer
// dwSize - size of buffer // dwSize - size of buffer
// //
// RETURN VALUE: // RETURN VALUE:
// destination buffer // destination buffer
// //
// COMMENTS: // COMMENTS:
// //
LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize ) LPTSTR GetLastErrorText( LPTSTR lpszBuf, DWORD dwSize )
{ {
DWORD dwRet; DWORD dwRet;
LPTSTR lpszTemp = NULL; LPTSTR lpszTemp = NULL;
dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY, dwRet = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
NULL, NULL,
GetLastError(), GetLastError(),
LANG_NEUTRAL, LANG_NEUTRAL,
(LPTSTR)&lpszTemp, (LPTSTR)&lpszTemp,
0, 0,
NULL ); NULL );
// supplied buffer is not long enough // supplied buffer is not long enough
if ( !dwRet || ( (long)dwSize < (long)dwRet+14 ) ) if ( !dwRet || ( (long)dwSize < (long)dwRet+14 ) )
lpszBuf[0] = TEXT('\0'); lpszBuf[0] = TEXT('\0');
else else
{ {
lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0'); //remove cr and newline character lpszTemp[lstrlen(lpszTemp)-2] = TEXT('\0'); //remove cr and newline character
_stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, GetLastError() ); _stprintf( lpszBuf, TEXT("%s (0x%x)"), lpszTemp, GetLastError() );
} }
if ( lpszTemp ) if ( lpszTemp )
LocalFree((HLOCAL) lpszTemp ); LocalFree((HLOCAL) lpszTemp );
return lpszBuf; return lpszBuf;
} }
//------------------------------------------------- //-------------------------------------------------
// this event is signalled when the // this event is signalled when the
// service should end // service should end
//------------------------------------------------- //-------------------------------------------------
HANDLE hServerStopEvent = NULL; HANDLE hServerStopEvent = NULL;
//------------------------------------------------- //-------------------------------------------------
// FUNCTION: ServiceStart // FUNCTION: ServiceStart
// //
// PURPOSE: Actual code of the service // PURPOSE: Actual code of the service
// that does the work. // that does the work.
//------------------------------------------------- //-------------------------------------------------
void ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv) void ServiceStart (DWORD dwArgc, LPTSTR *lpszArgv)
{ {
DWORD dwWait,dwTimeout=1000*60*1; DWORD dwWait,dwTimeout=1000*60*1;
if (!ReportStatusToSCMgr( if (!ReportStatusToSCMgr(
SERVICE_START_PENDING, // service state SERVICE_START_PENDING, // service state
NO_ERROR, // exit code NO_ERROR, // exit code
3000)) // wait hint 3000)) // wait hint
goto cleanup; goto cleanup;
// create the event object. The control handler function signals // create the event object. The control handler function signals
// this event when it receives the "stop" control code. // this event when it receives the "stop" control code.
// //
hServerStopEvent = CreateEvent( hServerStopEvent = CreateEvent(
NULL, // no security attributes NULL, // no security attributes
TRUE, // manual reset event TRUE, // manual reset event
FALSE, // not-signalled FALSE, // not-signalled
NULL); // no name NULL); // no name
if ( hServerStopEvent == NULL) goto cleanup; if ( hServerStopEvent == NULL) goto cleanup;
// report the status to the service control manager. // report the status to the service control manager.
// //
if (!ReportStatusToSCMgr( if (!ReportStatusToSCMgr(
SERVICE_START_PENDING, // service state SERVICE_START_PENDING, // service state
NO_ERROR, // exit code NO_ERROR, // exit code
3000)) // wait hint 3000)) // wait hint
goto cleanup; goto cleanup;
// report the status to the service control manager. // report the status to the service control manager.
// //
if (!ReportStatusToSCMgr( if (!ReportStatusToSCMgr(
SERVICE_START_PENDING, // service state SERVICE_START_PENDING, // service state
NO_ERROR, // exit code NO_ERROR, // exit code
3000)) // wait hint 3000)) // wait hint
goto cleanup; goto cleanup;
// report the status to the service control manager. // report the status to the service control manager.
// //
if (!ReportStatusToSCMgr( if (!ReportStatusToSCMgr(
SERVICE_RUNNING, // service state SERVICE_RUNNING, // service state
NO_ERROR, // exit code NO_ERROR, // exit code
0)) // wait hint 0)) // wait hint
goto cleanup; goto cleanup;
// //
// End of initialization // End of initialization
// Service is now running, perform work until shutdown // Service is now running, perform work until shutdown
// //
while ( 1 ) while ( 1 )
{ {
dwWait = WaitForSingleObject( hServerStopEvent, dwTimeout); dwWait = WaitForSingleObject( hServerStopEvent, dwTimeout);
if(dwWait==WAIT_FAILED) if(dwWait==WAIT_FAILED)
{ {
AddToMessageLog(TEXT("Error in WaitForSingleObject")); AddToMessageLog(TEXT("Error in WaitForSingleObject"));
break; break;
} }
else if(dwWait==WAIT_TIMEOUT) else if(dwWait==WAIT_TIMEOUT)
{ {
CmdRestartService("MySql"); CmdRestartService("MySql");
} }
else else
{ break; //shutdown { break; //shutdown
} }
} }
cleanup: cleanup:
if (hServerStopEvent) if (hServerStopEvent)
CloseHandle(hServerStopEvent); CloseHandle(hServerStopEvent);
} }
//------------------------------------------------- //-------------------------------------------------
// FUNCTION: ServiceStop // FUNCTION: ServiceStop
// //
// PURPOSE: Stops the service // PURPOSE: Stops the service
//------------------------------------------------- //-------------------------------------------------
void ServiceStop() void ServiceStop()
{ {
if ( hServerStopEvent ) if ( hServerStopEvent )
SetEvent(hServerStopEvent); SetEvent(hServerStopEvent);
} }
//-the end ---------------------------------------- //-the end ----------------------------------------
/* Testing of thread creation to find memory allocation bug /* Testing of thread creation to find memory allocation bug
** This is coded to use as few extern functions as possible! ** This is coded to use as few extern functions as possible!
** **
** The program must be compiled to be multithreaded ! ** The program must be compiled to be multithreaded !
** **
** The problem is that when this program is run it will allocate more and more ** The problem is that when this program is run it will allocate more and more
** memory, so there is a memory leak in the thread handling. The problem is how ** memory, so there is a memory leak in the thread handling. The problem is how
** to avoid is ! ** to avoid is !
** **
** It looks like the bug is that the std library doesn't free thread ** It looks like the bug is that the std library doesn't free thread
** specific variables if one uses a thread variable. ** specific variables if one uses a thread variable.
** If one compiles this program with -DREMOVE_BUG ** If one compiles this program with -DREMOVE_BUG
** there is no memory leaks anymore! ** there is no memory leaks anymore!
** **
** This program is tested with Microsofts VC++ 5.0, but BC5.2 is also ** This program is tested with Microsofts VC++ 5.0, but BC5.2 is also
** reported to have this bug. ** reported to have this bug.
*/ */
#include <windows.h> #include <windows.h>
#include <process.h> #include <process.h>
#include <stdio.h> #include <stdio.h>
#define TEST_COUNT 100000 #define TEST_COUNT 100000
/***************************************************************************** /*****************************************************************************
** The following is to emulate the posix thread interface ** The following is to emulate the posix thread interface
*****************************************************************************/ *****************************************************************************/
typedef HANDLE pthread_t; typedef HANDLE pthread_t;
typedef struct thread_attr { typedef struct thread_attr {
DWORD dwStackSize ; DWORD dwStackSize ;
DWORD dwCreatingFlag ; DWORD dwCreatingFlag ;
int priority ; int priority ;
} pthread_attr_t ; } pthread_attr_t ;
typedef struct { int dummy; } pthread_condattr_t; typedef struct { int dummy; } pthread_condattr_t;
typedef struct { typedef struct {
unsigned int msg; unsigned int msg;
pthread_t thread; pthread_t thread;
DWORD thread_id; DWORD thread_id;
} pthread_cond_t; } pthread_cond_t;
typedef CRITICAL_SECTION pthread_mutex_t; typedef CRITICAL_SECTION pthread_mutex_t;
#define pthread_mutex_init(A,B) InitializeCriticalSection(A) #define pthread_mutex_init(A,B) InitializeCriticalSection(A)
#define pthread_mutex_lock(A) (EnterCriticalSection(A),0) #define pthread_mutex_lock(A) (EnterCriticalSection(A),0)
#define pthread_mutex_unlock(A) LeaveCriticalSection(A) #define pthread_mutex_unlock(A) LeaveCriticalSection(A)
#define pthread_mutex_destroy(A) DeleteCriticalSection(A) #define pthread_mutex_destroy(A) DeleteCriticalSection(A)
#define pthread_handler_decl(A,B) unsigned __cdecl A(void *B) #define pthread_handler_decl(A,B) unsigned __cdecl A(void *B)
typedef unsigned (__cdecl *pthread_handler)(void *); typedef unsigned (__cdecl *pthread_handler)(void *);
#define pthread_self() GetCurrentThread() #define pthread_self() GetCurrentThread()
static unsigned int thread_count; static unsigned int thread_count;
static pthread_cond_t COND_thread_count; static pthread_cond_t COND_thread_count;
static pthread_mutex_t LOCK_thread_count; static pthread_mutex_t LOCK_thread_count;
pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,THR_LOCK_keycache, pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,THR_LOCK_keycache,
THR_LOCK_lock,THR_LOCK_isam; THR_LOCK_lock,THR_LOCK_isam;
/* /*
** We have tried to use '_beginthreadex' instead of '_beginthread' here ** We have tried to use '_beginthreadex' instead of '_beginthread' here
** but in this case the program leaks about 512 characters for each ** but in this case the program leaks about 512 characters for each
** created thread ! ** created thread !
*/ */
int pthread_create(pthread_t *thread_id, pthread_attr_t *attr, int pthread_create(pthread_t *thread_id, pthread_attr_t *attr,
pthread_handler func, void *param) pthread_handler func, void *param)
{ {
HANDLE hThread; HANDLE hThread;
hThread=(HANDLE)_beginthread(func, hThread=(HANDLE)_beginthread(func,
attr->dwStackSize ? attr->dwStackSize : attr->dwStackSize ? attr->dwStackSize :
65535,param); 65535,param);
if ((long) hThread == -1L) if ((long) hThread == -1L)
{ {
return(errno ? errno : -1); return(errno ? errno : -1);
} }
*thread_id=hThread; *thread_id=hThread;
return(0); return(0);
} }
void pthread_exit(unsigned A) void pthread_exit(unsigned A)
{ {
_endthread(); _endthread();
} }
/* /*
** The following simple implementation of conds works as long as ** The following simple implementation of conds works as long as
** only one thread uses pthread_cond_wait at a time. ** only one thread uses pthread_cond_wait at a time.
** This is coded very carefully to work with thr_lock. ** This is coded very carefully to work with thr_lock.
*/ */
static unsigned int WIN32_WAIT_SIGNAL= 30000; /* Start message to use */ static unsigned int WIN32_WAIT_SIGNAL= 30000; /* Start message to use */
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
{ {
cond->msg=WIN32_WAIT_SIGNAL++; cond->msg=WIN32_WAIT_SIGNAL++;
cond->thread=(pthread_t) pthread_self(); /* For global conds */ cond->thread=(pthread_t) pthread_self(); /* For global conds */
//IRENA //IRENA
cond->thread_id=GetCurrentThreadId(); cond->thread_id=GetCurrentThreadId();
return 0; return 0;
} }
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{ {
MSG msg ; MSG msg ;
unsigned int msgCode=cond->msg; unsigned int msgCode=cond->msg;
cond->thread=(pthread_t) pthread_self(); cond->thread=(pthread_t) pthread_self();
//IRENA //IRENA
//??? cond->thread_id=GetCurrentThreadId(); //??? cond->thread_id=GetCurrentThreadId();
//VOID(ReleaseMutex(*mutex)); //VOID(ReleaseMutex(*mutex));
LeaveCriticalSection(mutex); LeaveCriticalSection(mutex);
do do
{ {
WaitMessage() ; WaitMessage() ;
if (!PeekMessage(&msg, NULL, 1, 65534,PM_REMOVE)) if (!PeekMessage(&msg, NULL, 1, 65534,PM_REMOVE))
{ {
return errno=GetLastError() ; return errno=GetLastError() ;
} }
} while (msg.message != msgCode) ; } while (msg.message != msgCode) ;
EnterCriticalSection(mutex); EnterCriticalSection(mutex);
return 0 ; return 0 ;
} }
int pthread_cond_signal(pthread_cond_t *cond) int pthread_cond_signal(pthread_cond_t *cond)
{ {
if (!PostThreadMessage(cond->thread_id, cond->msg, 0,0)) if (!PostThreadMessage(cond->thread_id, cond->msg, 0,0))
{ {
return errno=GetLastError() ; return errno=GetLastError() ;
} }
return 0 ; return 0 ;
} }
int pthread_attr_init(pthread_attr_t *connect_att) int pthread_attr_init(pthread_attr_t *connect_att)
{ {
connect_att->dwStackSize = 0; connect_att->dwStackSize = 0;
connect_att->dwCreatingFlag = 0; connect_att->dwCreatingFlag = 0;
connect_att->priority = 0; connect_att->priority = 0;
return 0; return 0;
} }
int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack) int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack)
{ {
connect_att->dwStackSize=stack; connect_att->dwStackSize=stack;
return 0; return 0;
} }
int pthread_attr_setprio(pthread_attr_t *connect_att,int priority) int pthread_attr_setprio(pthread_attr_t *connect_att,int priority)
{ {
connect_att->priority=priority; connect_att->priority=priority;
return 0; return 0;
} }
int pthread_attr_destroy(pthread_attr_t *connect_att) int pthread_attr_destroy(pthread_attr_t *connect_att)
{ {
return 0; return 0;
} }
/* from my_pthread.c */ /* from my_pthread.c */
#ifndef REMOVE_BUG #ifndef REMOVE_BUG
__declspec(thread) int THR_KEY_my_errno; __declspec(thread) int THR_KEY_my_errno;
int _my_errno(void) int _my_errno(void)
{ {
return THR_KEY_my_errno; return THR_KEY_my_errno;
} }
#endif #endif
/***************************************************************************** /*****************************************************************************
** The test program ** The test program
*****************************************************************************/ *****************************************************************************/
pthread_handler_decl(test_thread,arg) pthread_handler_decl(test_thread,arg)
{ {
pthread_mutex_lock(&LOCK_thread_count); pthread_mutex_lock(&LOCK_thread_count);
thread_count--; thread_count--;
pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */ pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */
pthread_mutex_unlock(&LOCK_thread_count); pthread_mutex_unlock(&LOCK_thread_count);
pthread_exit(0); pthread_exit(0);
return 0; return 0;
} }
int main(int argc,char **argv) int main(int argc,char **argv)
{ {
pthread_t tid; pthread_t tid;
pthread_attr_t thr_attr; pthread_attr_t thr_attr;
int i,error; int i,error;
if ((error=pthread_cond_init(&COND_thread_count,NULL))) if ((error=pthread_cond_init(&COND_thread_count,NULL)))
{ {
fprintf(stderr,"Got error: %d from pthread_cond_init (errno: %d)", fprintf(stderr,"Got error: %d from pthread_cond_init (errno: %d)",
error,errno); error,errno);
exit(1); exit(1);
} }
pthread_mutex_init(&LOCK_thread_count,NULL); pthread_mutex_init(&LOCK_thread_count,NULL);
if ((error=pthread_attr_init(&thr_attr))) if ((error=pthread_attr_init(&thr_attr)))
{ {
fprintf(stderr,"Got error: %d from pthread_attr_init (errno: %d)", fprintf(stderr,"Got error: %d from pthread_attr_init (errno: %d)",
error,errno); error,errno);
exit(1); exit(1);
} }
if ((error=pthread_attr_setstacksize(&thr_attr,65536L))) if ((error=pthread_attr_setstacksize(&thr_attr,65536L)))
{ {
fprintf(stderr,"Got error: %d from pthread_attr_setstacksize (errno: %d)", fprintf(stderr,"Got error: %d from pthread_attr_setstacksize (errno: %d)",
error,errno); error,errno);
exit(1); exit(1);
} }
printf("Init ok. Creating %d threads\n",TEST_COUNT); printf("Init ok. Creating %d threads\n",TEST_COUNT);
for (i=1 ; i <= TEST_COUNT ; i++) for (i=1 ; i <= TEST_COUNT ; i++)
{ {
int *param= &i; int *param= &i;
if ((i % 100) == 0) if ((i % 100) == 0)
{ {
printf("%8d",i); printf("%8d",i);
fflush(stdout); fflush(stdout);
} }
if ((error=pthread_mutex_lock(&LOCK_thread_count))) if ((error=pthread_mutex_lock(&LOCK_thread_count)))
{ {
fprintf(stderr,"\nGot error: %d from pthread_mutex_lock (errno: %d)", fprintf(stderr,"\nGot error: %d from pthread_mutex_lock (errno: %d)",
error,errno); error,errno);
exit(1); exit(1);
} }
if ((error=pthread_create(&tid,&thr_attr,test_thread,(void*) param))) if ((error=pthread_create(&tid,&thr_attr,test_thread,(void*) param)))
{ {
fprintf(stderr,"\nGot error: %d from pthread_create (errno: %d)\n", fprintf(stderr,"\nGot error: %d from pthread_create (errno: %d)\n",
error,errno); error,errno);
pthread_mutex_unlock(&LOCK_thread_count); pthread_mutex_unlock(&LOCK_thread_count);
exit(1); exit(1);
} }
thread_count++; thread_count++;
pthread_mutex_unlock(&LOCK_thread_count); pthread_mutex_unlock(&LOCK_thread_count);
if ((error=pthread_mutex_lock(&LOCK_thread_count))) if ((error=pthread_mutex_lock(&LOCK_thread_count)))
fprintf(stderr,"\nGot error: %d from pthread_mutex_lock\n",error); fprintf(stderr,"\nGot error: %d from pthread_mutex_lock\n",error);
while (thread_count) while (thread_count)
{ {
if ((error=pthread_cond_wait(&COND_thread_count,&LOCK_thread_count))) if ((error=pthread_cond_wait(&COND_thread_count,&LOCK_thread_count)))
fprintf(stderr,"\nGot error: %d from pthread_cond_wait\n",error); fprintf(stderr,"\nGot error: %d from pthread_cond_wait\n",error);
} }
pthread_mutex_unlock(&LOCK_thread_count); pthread_mutex_unlock(&LOCK_thread_count);
} }
pthread_attr_destroy(&thr_attr); pthread_attr_destroy(&thr_attr);
printf("\nend\n"); printf("\nend\n");
return 0; return 0;
} }
...@@ -2328,7 +2328,7 @@ com_status(String *buffer __attribute__((unused)), ...@@ -2328,7 +2328,7 @@ com_status(String *buffer __attribute__((unused)),
(result=mysql_use_result(&mysql))) (result=mysql_use_result(&mysql)))
{ {
MYSQL_ROW cur=mysql_fetch_row(result); MYSQL_ROW cur=mysql_fetch_row(result);
tee_fprintf(stdout, "Current database:\t%s\n",cur[0]); tee_fprintf(stdout, "Current database:\t%s\n", cur[0] ? cur[0] : "");
tee_fprintf(stdout, "Current user:\t\t%s\n",cur[1]); tee_fprintf(stdout, "Current user:\t\t%s\n",cur[1]);
(void) mysql_fetch_row(result); // Read eof (void) mysql_fetch_row(result); // Read eof
} }
......
...@@ -40,6 +40,7 @@ static FILE *result_file; ...@@ -40,6 +40,7 @@ static FILE *result_file;
#ifndef DBUG_OFF #ifndef DBUG_OFF
static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace"; static const char* default_dbug_option = "d:t:o,/tmp/mysqlbinlog.trace";
#endif #endif
static const char *load_default_groups[]= { "mysqlbinlog","client",0 };
void sql_print_error(const char *format, ...); void sql_print_error(const char *format, ...);
...@@ -278,7 +279,7 @@ static void die(const char* fmt, ...) ...@@ -278,7 +279,7 @@ static void die(const char* fmt, ...)
static void print_version() static void print_version()
{ {
printf("%s Ver 2.3 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE); printf("%s Ver 2.4 for %s at %s\n", my_progname, SYSTEM_TYPE, MACHINE_TYPE);
} }
...@@ -374,6 +375,7 @@ static int parse_args(int *argc, char*** argv) ...@@ -374,6 +375,7 @@ static int parse_args(int *argc, char*** argv)
int ho_error; int ho_error;
result_file = stdout; result_file = stdout;
load_defaults("my",load_default_groups,argc,argv);
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
exit(ho_error); exit(ho_error);
...@@ -743,12 +745,16 @@ void free_tmpdir(MY_TMPDIR *tmpdir) ...@@ -743,12 +745,16 @@ void free_tmpdir(MY_TMPDIR *tmpdir)
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
static char **defaults_argv;
MY_INIT(argv[0]); MY_INIT(argv[0]);
parse_args(&argc, (char***)&argv); parse_args(&argc, (char***)&argv);
defaults_argv=argv;
if (!argc) if (!argc)
{ {
usage(); usage();
free_defaults(defaults_argv);
return -1; return -1;
} }
...@@ -778,6 +784,8 @@ int main(int argc, char** argv) ...@@ -778,6 +784,8 @@ int main(int argc, char** argv)
my_fclose(result_file, MYF(0)); my_fclose(result_file, MYF(0));
if (use_remote) if (use_remote)
mysql_close(mysql); mysql_close(mysql);
free_defaults(defaults_argv);
my_end(0);
return 0; return 0;
} }
......
...@@ -37,7 +37,7 @@ extern int h_errno; ...@@ -37,7 +37,7 @@ extern int h_errno;
#endif #endif
#ifndef HAVE_IN_ADDR_T #ifndef HAVE_IN_ADDR_T
#define in_addr_t u_long #define in_addr_t ulong
#endif #endif
static my_bool silent; static my_bool silent;
......
...@@ -2190,6 +2190,9 @@ row_rename_table_for_mysql( ...@@ -2190,6 +2190,9 @@ row_rename_table_for_mysql(
mem_heap_t* heap = NULL; mem_heap_t* heap = NULL;
char** constraints_to_drop = NULL; char** constraints_to_drop = NULL;
ulint n_constraints_to_drop = 0; ulint n_constraints_to_drop = 0;
ibool recovering_temp_table = FALSE;
ulint namelen;
ulint keywordlen;
ulint len; ulint len;
ulint i; ulint i;
char buf[10000]; char buf[10000];
...@@ -2226,10 +2229,23 @@ row_rename_table_for_mysql( ...@@ -2226,10 +2229,23 @@ row_rename_table_for_mysql(
trx->op_info = (char *) "renaming table"; trx->op_info = (char *) "renaming table";
trx_start_if_not_started(trx); trx_start_if_not_started(trx);
namelen = ut_strlen(new_name);
keywordlen = ut_strlen("_recover_innodb_tmp_table");
if (namelen >= keywordlen
&& 0 == ut_memcmp(new_name + namelen - keywordlen,
(char*)"_recover_innodb_tmp_table", keywordlen)) {
recovering_temp_table = TRUE;
}
/* Serialize data dictionary operations with dictionary mutex: /* Serialize data dictionary operations with dictionary mutex:
no deadlocks can occur then in these operations */ no deadlocks can occur then in these operations */
row_mysql_lock_data_dictionary(trx); if (!recovering_temp_table) {
row_mysql_lock_data_dictionary(trx);
}
table = dict_table_get_low(old_name); table = dict_table_get_low(old_name);
...@@ -2396,8 +2412,10 @@ row_rename_table_for_mysql( ...@@ -2396,8 +2412,10 @@ row_rename_table_for_mysql(
} }
} }
} }
funct_exit: funct_exit:
row_mysql_unlock_data_dictionary(trx); if (!recovering_temp_table) {
row_mysql_unlock_data_dictionary(trx);
}
if (graph) { if (graph) {
que_graph_free(graph); que_graph_free(graph);
......
...@@ -429,14 +429,14 @@ if [ x$SOURCE_DIST = x1 ] ; then ...@@ -429,14 +429,14 @@ if [ x$SOURCE_DIST = x1 ] ; then
MYSQL_TEST="$BASEDIR/client/mysqltest" MYSQL_TEST="$BASEDIR/client/mysqltest"
fi fi
if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then if [ -f "$BASEDIR/client/.libs/mysqldump" ] ; then
MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump --no-defaults -uroot --socket=$MASTER_MYSOCK" MYSQL_DUMP="$BASEDIR/client/.libs/mysqldump"
else else
MYSQL_DUMP="$BASEDIR/client/mysqldump --no-defaults -uroot --socket=$MASTER_MYSOCK" MYSQL_DUMP="$BASEDIR/client/mysqldump"
fi fi
if [ -f "$BASEDIR/client/.libs/mysqlbinlog" ] ; then if [ -f "$BASEDIR/client/.libs/mysqlbinlog" ] ; then
MYSQL_BINLOG="$BASEDIR/client/.libs/mysqlbinlog --local-load=$MYSQL_TMP_DIR" MYSQL_BINLOG="$BASEDIR/client/.libs/mysqlbinlog"
else else
MYSQL_BINLOG="$BASEDIR/client/mysqlbinlog --local-load=$MYSQL_TMP_DIR" MYSQL_BINLOG="$BASEDIR/client/mysqlbinlog"
fi fi
if [ -n "$STRACE_CLIENT" ]; then if [ -n "$STRACE_CLIENT" ]; then
MYSQL_TEST="strace -o $MYSQL_TEST_DIR/var/log/mysqltest.strace $MYSQL_TEST" MYSQL_TEST="strace -o $MYSQL_TEST_DIR/var/log/mysqltest.strace $MYSQL_TEST"
...@@ -459,8 +459,8 @@ else ...@@ -459,8 +459,8 @@ else
MYSQLD="$VALGRIND $BASEDIR/bin/mysqld" MYSQLD="$VALGRIND $BASEDIR/bin/mysqld"
fi fi
MYSQL_TEST="$BASEDIR/bin/mysqltest" MYSQL_TEST="$BASEDIR/bin/mysqltest"
MYSQL_DUMP="$BASEDIR/bin/mysqldump --no-defaults -uroot --socket=$MASTER_MYSOCK" MYSQL_DUMP="$BASEDIR/bin/mysqldump"
MYSQL_BINLOG="$BASEDIR/bin/mysqlbinlog --local-load=$MYSQL_TMP_DIR" MYSQL_BINLOG="$BASEDIR/bin/mysqlbinlog"
MYSQLADMIN="$BASEDIR/bin/mysqladmin" MYSQLADMIN="$BASEDIR/bin/mysqladmin"
WAIT_PID="$BASEDIR/bin/mysql_waitpid" WAIT_PID="$BASEDIR/bin/mysql_waitpid"
MYSQL_MANAGER="$BASEDIR/bin/mysqlmanager" MYSQL_MANAGER="$BASEDIR/bin/mysqlmanager"
...@@ -478,6 +478,8 @@ else ...@@ -478,6 +478,8 @@ else
fi fi
fi fi
MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK"
MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR"
export MYSQL_DUMP export MYSQL_DUMP
export MYSQL_BINLOG export MYSQL_BINLOG
...@@ -1041,7 +1043,7 @@ EOF ...@@ -1041,7 +1043,7 @@ EOF
mysql_start () mysql_start ()
{ {
# We should not start the daemon here as we don't know the argumens # We should not start the daemon here as we don't know the arguments
# for the test. Better to let the test start the daemon # for the test. Better to let the test start the daemon
# $ECHO "Starting MySQL daemon" # $ECHO "Starting MySQL daemon"
......
...@@ -78,7 +78,7 @@ Field Type Null Key Default Extra ...@@ -78,7 +78,7 @@ Field Type Null Key Default Extra
x varchar(50) YES NULL x varchar(50) YES NULL
describe t2; describe t2;
Field Type Null Key Default Extra Field Type Null Key Default Extra
x char(50) YES NULL x varchar(50) YES NULL
drop table t2; drop table t2;
create table t2 select now() as a , curtime() as b, curdate() as c , 1+1 as d , 1.0 + 1 as e , 33333333333333333 + 3 as f; create table t2 select now() as a , curtime() as b, curdate() as c , 1+1 as d , 1.0 + 1 as e , 33333333333333333 + 3 as f;
describe t2; describe t2;
......
...@@ -10,5 +10,5 @@ reset slave; ...@@ -10,5 +10,5 @@ reset slave;
start slave; start slave;
show slave status; show slave status;
Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space Master_Host Master_User Master_Port Connect_retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_do_db Replicate_ignore_db Last_errno Last_error Skip_counter Exec_master_log_pos Relay_log_space
127.0.0.1 root MASTER_PORT 1 master-bin.002 4 slave-relay-bin.002 161 master-bin.001 Yes No 0 there is an unfinished transaction in the relay log (could find neither COMMIT nor ROLLBACK in the relay log); it could be that the master died while writing the transaction to its binary log. Now the slave is rolling back the transaction. 0 79 317 127.0.0.1 root MASTER_PORT 1 master-bin.002 4 slave-relay-bin.002 161 master-bin.001 Yes No 0 Rolling back unfinished transaction (no COMMIT or ROLLBACK) from relay log. Probably cause is that the master died while writing the transaction to it's binary log. 0 79 317
reset master; reset master;
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
source include/master-slave.inc; source include/master-slave.inc;
connection slave; connection slave;
# If we are not supporting transactions in the slave, the unfinished transaction
# won't cause any error, so we need to skip the test. In the 4.0 testsuite, the
# slave always runs without InnoDB, so we check for BDB.
source include/have_bdb.inc;
stop slave; stop slave;
connection master; connection master;
flush logs; flush logs;
......
/*C4*/
/****************************************************************/
/* Author: Jethro Wright, III TS : 3/ 4/1998 9:15 */
/* Date: 02/18/1998 */
/* mytest.c : do some testing of the libmySQL.DLL.... */
/* */
/* History: */
/* 02/18/1998 jw3 also sprach zarathustra.... */
/****************************************************************/
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <mysql.h>
#define DEFALT_SQL_STMT "SELECT * FROM db"
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
/********************************************************
**
** main :-
**
********************************************************/
int
main( int argc, char * argv[] )
{
char szSQL[ 200 ], aszFlds[ 25 ][ 25 ], * pszT, szDB[ 50 ] ;
int i, j, k, l, x ;
MYSQL * myData ;
MYSQL_RES * res ;
MYSQL_FIELD * fd ;
MYSQL_ROW row ;
//....just curious....
printf( "sizeof( MYSQL ) == %d\n", sizeof( MYSQL ) ) ;
if ( argc == 2 )
{
strcpy( szDB, argv[ 1 ] ) ;
strcpy( szSQL, DEFALT_SQL_STMT ) ;
if (!strcmp(szDB,"--debug"))
{
strcpy( szDB, "mysql" ) ;
printf("Some mysql struct information (size and offset):\n");
printf("net:\t%3d %3d\n",sizeof(myData->net),offsetof(MYSQL,net));
printf("host:\t%3d %3d\n",sizeof(myData->host),offsetof(MYSQL,host));
printf("port:\t%3d %3d\n",sizeof(myData->port),offsetof(MYSQL,port));
printf("protocol_version:\t%3d %3d\n",sizeof(myData->protocol_version),
offsetof(MYSQL,protocol_version));
printf("thread_id:\t%3d %3d\n",sizeof(myData->thread_id),
offsetof(MYSQL,thread_id));
printf("affected_rows:\t%3d %3d\n",sizeof(myData->affected_rows),
offsetof(MYSQL,affected_rows));
printf("packet_length:\t%3d %3d\n",sizeof(myData->packet_length),
offsetof(MYSQL,packet_length));
printf("status:\t%3d %3d\n",sizeof(myData->status),
offsetof(MYSQL,status));
printf("fields:\t%3d %3d\n",sizeof(myData->fields),
offsetof(MYSQL,fields));
printf("field_alloc:\t%3d %3d\n",sizeof(myData->field_alloc),
offsetof(MYSQL,field_alloc));
printf("free_me:\t%3d %3d\n",sizeof(myData->free_me),
offsetof(MYSQL,free_me));
printf("options:\t%3d %3d\n",sizeof(myData->options),
offsetof(MYSQL,options));
puts("");
}
}
else if ( argc > 2 ) {
strcpy( szDB, argv[ 1 ] ) ;
strcpy( szSQL, argv[ 2 ] ) ;
}
else {
strcpy( szDB, "mysql" ) ;
strcpy( szSQL, DEFALT_SQL_STMT ) ;
}
//....
if ( (myData = mysql_init((MYSQL*) 0)) &&
mysql_real_connect( myData, NULL, NULL, NULL, NULL, MYSQL_PORT,
NULL, 0 ) )
{
if ( mysql_select_db( myData, szDB ) < 0 ) {
printf( "Can't select the %s database !\n", szDB ) ;
mysql_close( myData ) ;
return 2 ;
}
}
else {
printf( "Can't connect to the mysql server on port %d !\n",
MYSQL_PORT ) ;
mysql_close( myData ) ;
return 1 ;
}
//....
if ( ! mysql_query( myData, szSQL ) ) {
res = mysql_store_result( myData ) ;
i = (int) mysql_num_rows( res ) ; l = 1 ;
printf( "Query: %s\nNumber of records found: %ld\n", szSQL, i ) ;
//....we can get the field-specific characteristics here....
for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ )
strcpy( aszFlds[ x ], fd->name ) ;
//....
while ( row = mysql_fetch_row( res ) ) {
j = mysql_num_fields( res ) ;
printf( "Record #%ld:-\n", l++ ) ;
for ( k = 0 ; k < j ; k++ )
printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[ k ],
(((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ;
puts( "==============================\n" ) ;
}
mysql_free_result( res ) ;
}
else printf( "Couldn't execute %s on the server !\n", szSQL ) ;
//....
puts( "==== Diagnostic info ====" ) ;
pszT = mysql_get_client_info() ;
printf( "Client info: %s\n", pszT ) ;
//....
pszT = mysql_get_host_info( myData ) ;
printf( "Host info: %s\n", pszT ) ;
//....
pszT = mysql_get_server_info( myData ) ;
printf( "Server info: %s\n", pszT ) ;
//....
res = mysql_list_processes( myData ) ; l = 1 ;
if (res)
{
for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ )
strcpy( aszFlds[ x ], fd->name ) ;
while ( row = mysql_fetch_row( res ) ) {
j = mysql_num_fields( res ) ;
printf( "Process #%ld:-\n", l++ ) ;
for ( k = 0 ; k < j ; k++ )
printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[ k ],
(((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ;
puts( "==============================\n" ) ;
}
}
else
{
printf("Got error %s when retreiving processlist\n",mysql_error(myData));
}
//....
res = mysql_list_tables( myData, "%" ) ; l = 1 ;
for ( x = 0 ; fd = mysql_fetch_field( res ) ; x++ )
strcpy( aszFlds[ x ], fd->name ) ;
while ( row = mysql_fetch_row( res ) ) {
j = mysql_num_fields( res ) ;
printf( "Table #%ld:-\n", l++ ) ;
for ( k = 0 ; k < j ; k++ )
printf( " Fld #%d (%s): %s\n", k + 1, aszFlds[ k ],
(((row[k]==NULL)||(!strlen(row[k])))?"NULL":row[k])) ;
puts( "==============================\n" ) ;
}
//....
pszT = mysql_stat( myData ) ;
puts( pszT ) ;
//....
mysql_close( myData ) ;
return 0 ;
}
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
## Process this file with automake to create Makefile.in ## Process this file with automake to create Makefile.in
bin_SCRIPTS = @server_scripts@ \ bin_SCRIPTS = @server_scripts@ \
make_win_src_distribution \
msql2mysql \ msql2mysql \
mysql_config \ mysql_config \
mysql_fix_privilege_tables \ mysql_fix_privilege_tables \
...@@ -33,7 +32,8 @@ bin_SCRIPTS = @server_scripts@ \ ...@@ -33,7 +32,8 @@ bin_SCRIPTS = @server_scripts@ \
mysqldumpslow \ mysqldumpslow \
mysql_explain_log \ mysql_explain_log \
mysql_tableinfo \ mysql_tableinfo \
mysqld_multi mysqld_multi \
make_win_src_distribution
EXTRA_SCRIPTS = make_binary_distribution.sh \ EXTRA_SCRIPTS = make_binary_distribution.sh \
make_win_src_distribution.sh \ make_win_src_distribution.sh \
...@@ -66,7 +66,6 @@ pkgdata_DATA = make_binary_distribution ...@@ -66,7 +66,6 @@ pkgdata_DATA = make_binary_distribution
# failures with it. # failures with it.
CLEANFILES = @server_scripts@ \ CLEANFILES = @server_scripts@ \
make_binary_distribution \ make_binary_distribution \
make_win_src_distribution \
msql2mysql \ msql2mysql \
mysql_config \ mysql_config \
mysql_fix_privilege_tables \ mysql_fix_privilege_tables \
...@@ -79,7 +78,8 @@ CLEANFILES = @server_scripts@ \ ...@@ -79,7 +78,8 @@ CLEANFILES = @server_scripts@ \
mysql_find_rows \ mysql_find_rows \
mysqlhotcopy \ mysqlhotcopy \
mysqldumpslow \ mysqldumpslow \
mysqld_multi mysqld_multi \
make_win_src_distribution
SUPERCLEANFILES = mysqlbug SUPERCLEANFILES = mysqlbug
......
...@@ -136,7 +136,7 @@ then ...@@ -136,7 +136,7 @@ then
fi fi
fi fi
if test "$ip_only" -eq 1 if test "$ip_only" ="1"
then then
ip=`echo "$resolved" | awk '/ /{print $6}'` ip=`echo "$resolved" | awk '/ /{print $6}'`
hostname=$ip hostname=$ip
......
...@@ -2102,10 +2102,10 @@ int Start_log_event::exec_event(struct st_relay_log_info* rli) ...@@ -2102,10 +2102,10 @@ int Start_log_event::exec_event(struct st_relay_log_info* rli)
if (rli->inside_transaction) if (rli->inside_transaction)
{ {
slave_print_error(rli, 0, slave_print_error(rli, 0,
"there is an unfinished transaction in the relay log \ "\
(could find neither COMMIT nor ROLLBACK in the relay log); it could be that \ Rolling back unfinished transaction (no COMMIT or ROLLBACK) from relay log. \
the master died while writing the transaction to its binary log. Now the slave \ Probably cause is that the master died while writing the transaction to it's \
is rolling back the transaction."); binary log.");
return(1); return(1);
} }
break; break;
...@@ -2208,7 +2208,7 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli) ...@@ -2208,7 +2208,7 @@ int Rotate_log_event::exec_event(struct st_relay_log_info* rli)
{ {
memcpy(rli->master_log_name, new_log_ident, ident_len+1); memcpy(rli->master_log_name, new_log_ident, ident_len+1);
rli->master_log_pos= pos; rli->master_log_pos= pos;
DBUG_PRINT("info", ("master_log_pos: %d", (ulong) rli->master_log_pos)); DBUG_PRINT("info", ("master_log_pos: %lu", (ulong) rli->master_log_pos));
} }
rli->relay_log_pos += get_event_len(); rli->relay_log_pos += get_event_len();
pthread_mutex_unlock(&rli->data_lock); pthread_mutex_unlock(&rli->data_lock);
......
...@@ -3706,6 +3706,8 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, ...@@ -3706,6 +3706,8 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
new_field->field_name=item->name; new_field->field_name=item->name;
if (org_field->maybe_null()) if (org_field->maybe_null())
new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join new_field->flags&= ~NOT_NULL_FLAG; // Because of outer join
if (org_field->type()==FIELD_TYPE_VAR_STRING)
table->db_create_options|= HA_OPTION_PACK_RECORD;
} }
return new_field; return new_field;
} }
......
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