mysql_test_run.c and associated files, with my initial changes and WAX's changes for Windows

This commit is contained in:
greg@gcw.ath.cx 2003-07-23 01:35:24 -04:00
parent 19efafcc13
commit 6f60424629
5 changed files with 944 additions and 558 deletions

View File

@ -22,6 +22,7 @@ carsten@tsort.bitbybit.dk
davida@isil.mysql.com davida@isil.mysql.com
gluh@gluh.(none) gluh@gluh.(none)
gluh@gluh.mysql.r18.ru gluh@gluh.mysql.r18.ru
greg@gcw.ath.cx
greg@mysql.com greg@mysql.com
guilhem@mysql.com guilhem@mysql.com
gweir@work.mysql.com gweir@work.mysql.com

View File

@ -1,4 +1,4 @@
# Copyright (c) 2002 Novell, Inc. All Rights Reserved. # Copyright (c) 2002 Novell, Inc. All Rights Reserved.
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -11,37 +11,37 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
INCLUDES= -I$(srcdir)/../include -I../include -I.. INCLUDES= -I$(srcdir)/../include -I../include -I..
bin_PROGRAMS= mysqld_safe mysql_install_db mysql_test_run libmysql bin_PROGRAMS= mysqld_safe mysql_install_db mysql_test_run libmysql
mysqld_safe_SOURCES= mysqld_safe.c my_manage.c mysqld_safe_SOURCES= mysqld_safe.c my_manage.c
mysql_install_db_SOURCES= mysql_install_db.c my_manage.c mysql_install_db_SOURCES= mysql_install_db.c my_manage.c
mysql_test_run_SOURCES= mysql_test_run.c my_manage.c mysql_test_run_SOURCES= mysql_test_run.c my_manage.c
libmysql_SOURCES= libmysqlmain.c libmysql_SOURCES= libmysqlmain.c
libmysql_LDADD= ../libmysql/.libs/libmysqlclient.a libmysql_LDADD= ../libmysql/.libs/libmysqlclient.a
netware_build_files = client/mysql.def client/mysqladmin.def \ netware_build_files = client/mysql.def client/mysqladmin.def \
client/mysqlbinlog.def client/mysqlcheck.def \ client/mysqlbinlog.def client/mysqlcheck.def \
client/mysqldump.def client/mysqlimport.def \ client/mysqldump.def client/mysqlimport.def \
client/mysqlshow.def client/mysqltest.def \ client/mysqlshow.def client/mysqltest.def \
extra/mysql_install.def extra/my_print_defaults.def \ extra/mysql_install.def extra/my_print_defaults.def \
extra/perror.def extra/replace.def \ extra/perror.def extra/replace.def \
extra/resolveip.def extra/comp_err.def \ extra/resolveip.def extra/comp_err.def \
isam/isamchk.def \ isam/isamchk.def \
isam/isamlog.def isam/pack_isam.def \ isam/isamlog.def isam/pack_isam.def \
libmysqld/libmysqld.def myisam/myisamchk.def \ libmysqld/libmysqld.def myisam/myisamchk.def \
myisam/myisamlog.def myisam/myisampack.def \ myisam/myisamlog.def myisam/myisampack.def \
sql/mysqld.def sql/mysqld.def
link_sources: link_sources:
set -x; \ set -x; \
for f in $(netware_build_files); do \ for f in $(netware_build_files); do \
rm -f $(srcdir)/../$$f; \ rm -f $(srcdir)/../$$f; \
org=`echo $$f | sed -e 's/.*\/\(.*\)/\1/g'`; \ org=`echo $$f | sed -e 's/.*\/\(.*\)/\1/g'`; \
@LN_CP_F@ $(srcdir)/$$org $(srcdir)/../$$f; \ @LN_CP_F@ $(srcdir)/$$org $(srcdir)/../$$f; \
done; done;
# Don't update the files from bitkeeper # Don't update the files from bitkeeper
%::SCCS/s.% %::SCCS/s.%

View File

@ -1,90 +1,104 @@
/* /*
Copyright (c) 2003 Novell, Inc. All Rights Reserved. Copyright (c) 2003 MySQL AB
Copyright (c) 2003 Novell, Inc.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation; either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdio.h> /*****************************************************************************
#include <errno.h> ** Utility functions for support programs
#include <dirent.h> *****************************************************************************/
#include <string.h>
#include <screen.h> /* MySQL library headers */
#include <proc.h> #include <my_global.h>
#include <ctype.h> #include <my_sys.h>
#include <sys/stat.h> #include <my_dir.h>
#include <fcntl.h> #include <m_string.h>
#include <assert.h>
/* These 'should' be POSIX or ANSI */
#include <assert.h> /* ASSERT */
#include <stdarg.h> /* vsprintf, va_* */
#include <sys/types.h> /* pid_t */
#ifndef __WIN__
#include <unistd.h> /* fork, rmdir, execve */
#endif
#include <stdio.h> /* freopen */
#include <stdlib.h> /* FILE */
#ifndef __WIN__
#include <dirent.h> /* opendir, readdir */
#endif
#if !defined(__NETWARE__) && !defined(__WIN__)
#include <sys/wait.h>
#endif
#if !defined(__NETWARE__)
#include <signal.h>
#endif
/* For ASSERT -- Not totally sure about this one: */
#if !defined(ASSERT)
#define ASSERT(A) assert(A)
#endif
#include "my_manage.h" #include "my_manage.h"
#define __STDC__ 1
#include "process.h"
/****************************************************************************** /******************************************************************************
macros init_args()
******************************************************************************/
/****************************************************************************** Init an argument list.
global variables
******************************************************************************/
/******************************************************************************
functions
******************************************************************************/
/******************************************************************************
init_args()
Init an argument list.
******************************************************************************/ ******************************************************************************/
void init_args(arg_list_t *al) void init_args(arg_list_t *al)
{ {
#ifndef __WIN__
ASSERT(al != NULL); ASSERT(al != NULL);
al->argc = 0; al->argc = 0;
al->size = ARG_BUF; al->size = ARG_BUF;
al->argv = malloc(al->size * sizeof(char *)); al->argv = (char **)my_malloc(al->size * sizeof(char *), MYF(MY_WME));
ASSERT(al->argv != NULL); ASSERT(al->argv != NULL);
#else
win_args[0]= '\0';
skip_first_param= TRUE;
#endif
return; return;
} }
/****************************************************************************** /******************************************************************************
add_arg() add_arg()
Add an argument to a list. Add an argument to a list.
******************************************************************************/ ******************************************************************************/
void add_arg(arg_list_t *al, char *format, ...) void add_arg(arg_list_t *al, const char *format, ...)
{ {
#ifndef __WIN__
va_list ap; va_list ap;
char temp[PATH_MAX]; char temp[PATH_MAX];
ASSERT(al != NULL); ASSERT(al != NULL);
// increase size /* increase size */
if (al->argc >= al->size) if (al->argc >= (int)al->size)
{ {
al->size += ARG_BUF; al->size += ARG_BUF;
al->argv = realloc(al->argv, al->size * sizeof(char *)); al->argv = (char **)my_realloc((char *)al->argv, al->size * sizeof(char *), MYF(MY_WME));
ASSERT(al->argv != NULL); ASSERT(al->argv != NULL);
} }
@ -94,7 +108,7 @@ void add_arg(arg_list_t *al, char *format, ...)
vsprintf(temp, format, ap); vsprintf(temp, format, ap);
va_end(ap); va_end(ap);
al->argv[al->argc] = malloc(strlen(temp)+1); al->argv[al->argc] = my_malloc(strlen(temp)+1, MYF(MY_WME));
ASSERT(al->argv[al->argc] != NULL); ASSERT(al->argv[al->argc] != NULL);
strcpy(al->argv[al->argc], temp); strcpy(al->argv[al->argc], temp);
@ -104,19 +118,36 @@ void add_arg(arg_list_t *al, char *format, ...)
{ {
al->argv[al->argc] = NULL; al->argv[al->argc] = NULL;
} }
#else
va_list ap;
char param[PATH_MAX];
if (!skip_first_param)
{
va_start(ap, format);
vsprintf(&param, format, ap);
va_end(ap);
strcat(win_args," ");
strcat(win_args,param);
}
else
{
skip_first_param= FALSE;
}
#endif
return; return;
} }
/****************************************************************************** /******************************************************************************
free_args() free_args()
Free an argument list. Free an argument list.
******************************************************************************/ ******************************************************************************/
void free_args(arg_list_t *al) void free_args(arg_list_t *al)
{ {
#ifndef __WIN__
int i; int i;
ASSERT(al != NULL); ASSERT(al != NULL);
@ -124,74 +155,110 @@ void free_args(arg_list_t *al)
for(i = 0; i < al->argc; i++) for(i = 0; i < al->argc; i++)
{ {
ASSERT(al->argv[i] != NULL); ASSERT(al->argv[i] != NULL);
free(al->argv[i]); my_free(al->argv[i], MYF(MY_WME));
al->argv[i] = NULL; al->argv[i] = NULL;
} }
free(al->argv); my_free((char *)al->argv, MYF(MY_WME));
al->argc = 0; al->argc = 0;
al->argv = NULL; al->argv = NULL;
#endif
return; return;
} }
/****************************************************************************** /******************************************************************************
sleep_until_file_deleted() sleep_until_file_deleted()
Sleep until the given file is no longer found. Sleep until the given file is no longer found.
******************************************************************************/ ******************************************************************************/
int sleep_until_file_deleted(char *pid_file) int sleep_until_file_deleted(char *pid_file)
{ {
struct stat buf; MY_STAT stat_info;
int i, err; int i, err = 0;
#ifndef __WIN__
for(i = 0; (i < TRY_MAX) && (err = !stat(pid_file, &buf)); i++) sleep(1); for(i = 0; i < TRY_MAX; i++)
{
if (err != 0) err = errno; if (my_stat(pid_file, &stat_info, MYF(0)) == (MY_STAT *) NULL)
{
return err; err = errno;
break;
}
my_sleep(1);
}
#else
switch (pid_mode)
{
case MASTER_PID:
err= (WaitForSingleObject(master_server, TRY_MAX*1000) == WAIT_TIMEOUT);
pid_mode= 0;
break;
case SLAVE_PID:
err= (WaitForSingleObject(slave_server, TRY_MAX*1000) == WAIT_TIMEOUT);
pid_mode= 0;
break;
};
#endif
return err;
} }
/****************************************************************************** /******************************************************************************
sleep_until_file_exists() sleep_until_file_exists()
Sleep until the given file exists. Sleep until the given file exists.
******************************************************************************/ ******************************************************************************/
int sleep_until_file_exists(char *pid_file) int sleep_until_file_exists(char *pid_file)
{ {
struct stat buf; MY_STAT stat_info;
int i, err; int i, err = 0;
for(i = 0; (i < TRY_MAX) && (err = stat(pid_file, &buf)); i++) sleep(1); #ifndef __WIN__
for(i = 0; i < TRY_MAX; i++)
if (err != 0) err = errno; {
if (my_stat(pid_file, &stat_info, MYF(0)) == (MY_STAT *) NULL)
return err; {
err = errno;
break;
}
my_sleep(1);
}
#else
switch (pid_mode)
{
case MASTER_PID:
WaitForSingleObject(master_server, TRY_MAX*1000);
pid_mode= 0;
break;
case SLAVE_PID:
WaitForSingleObject(slave_server, TRY_MAX*1000);
pid_mode= 0;
break;
};
#endif
return err;
} }
/****************************************************************************** /******************************************************************************
wait_for_server_start() wait_for_server_start()
Wait for the server on the given port to start. Wait for the server on the given port to start.
******************************************************************************/ ******************************************************************************/
int wait_for_server_start(char *bin_dir, char *user, char *password, int port) int wait_for_server_start(char *bin_dir, char *user, char *password, int port)
{ {
arg_list_t al; arg_list_t al;
int err, i; int err = 0, i;
char mysqladmin_file[PATH_MAX];
char trash[PATH_MAX]; char trash[PATH_MAX];
// mysqladmin file /* mysqladmin file */
snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir); my_snprintf(trash, PATH_MAX, "/tmp/trash.out");
snprintf(trash, PATH_MAX, "/tmp/trash.out");
/* args */
// args
init_args(&al); init_args(&al);
add_arg(&al, "%s", mysqladmin_file); add_arg(&al, "%s", mysqladmin_file);
add_arg(&al, "--no-defaults"); add_arg(&al, "--no-defaults");
@ -205,13 +272,13 @@ int wait_for_server_start(char *bin_dir, char *user, char *password, int port)
add_arg(&al, "--host=localhost"); add_arg(&al, "--host=localhost");
add_arg(&al, "ping"); add_arg(&al, "ping");
// NetWare does not support the connect timeout in the TCP/IP stack /* NetWare does not support the connect timeout in the TCP/IP stack
// -- we will try the ping multiple times -- we will try the ping multiple times */
for(i = 0; (i < TRY_MAX) for(i = 0; (i < TRY_MAX)
&& (err = spawn(mysqladmin_file, &al, TRUE, NULL, && (err = spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL)); i++) sleep(1); trash, NULL, NOT_NEED_PID)); i++) sleep(1);
// free args /* free args */
free_args(&al); free_args(&al);
return err; return err;
@ -219,20 +286,23 @@ int wait_for_server_start(char *bin_dir, char *user, char *password, int port)
/****************************************************************************** /******************************************************************************
spawn() spawn()
Spawn the given path with the given arguments. Spawn the executable at the given path with the given arguments.
******************************************************************************/ ******************************************************************************/
#ifdef __NETWARE__
int spawn(char *path, arg_list_t *al, int join, char *input, int spawn(char *path, arg_list_t *al, int join, char *input,
char *output, char *error) char *output, char *error)
{ {
pid_t pid; pid_t pid;
int result = 0; int result = 0;
wiring_t wiring = { FD_UNUSED, FD_UNUSED, FD_UNUSED }; wiring_t wiring = { FD_UNUSED, FD_UNUSED, FD_UNUSED };
unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD; unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD;
// open wiring /* open wiring */
if (input) if (input)
wiring.infd = open(input, O_RDONLY); wiring.infd = open(input, O_RDONLY);
@ -242,14 +312,14 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
if (error) if (error)
wiring.errfd = open(error, O_WRONLY | O_CREAT | O_TRUNC); wiring.errfd = open(error, O_WRONLY | O_CREAT | O_TRUNC);
// procve requires a NULL /* procve requires a NULL */
add_arg(al, NULL); add_arg(al, NULL);
// go /* go */
pid = procve(path, flags, NULL, &wiring, NULL, NULL, 0, pid = procve(path, flags, NULL, &wiring, NULL, NULL, 0,
NULL, (const char **)al->argv); NULL, (const char **)al->argv);
if (pid == -1) if (pid == -1)
{ {
result = -1; result = -1;
} }
@ -257,8 +327,8 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
{ {
waitpid(pid, &result, 0); waitpid(pid, &result, 0);
} }
// close wiring /* close wiring */
if (wiring.infd != -1) if (wiring.infd != -1)
close(wiring.infd); close(wiring.infd);
@ -268,207 +338,411 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
if (wiring.errfd != -1) if (wiring.errfd != -1)
close(wiring.errfd); close(wiring.errfd);
return result; return result;
} }
#else /* NOT __NETWARE__ */
#ifdef __WIN__
int my_vsnprintf_(char *to, size_t n, const char* value, ...)
{
char *start=to, *end=to+n-1;
uint length, num_state, pre_zero;
reg2 char *par;// = value;
va_list args;
va_start(args,value);
par = va_arg(args, char *);
while (par != NULL)
{
uint plen,left_len = (uint)(end-to)+1;
if (!par) par = (char*)"(null)";
plen = (uint) strlen(par);
if (left_len <= plen)
plen = left_len - 1;
to=strnmov(to+strlen(to),par,plen);
par = va_arg(args, char *);
}
va_end(args);
DBUG_ASSERT(to <= end);
*to='\0';
return (uint) (to - start);
}
int spawn(char *path, arg_list_t *al, int join, char *input,
char *output, char *error)
{
char *cl;
char *arg;
intptr_t result;
int j;
int err;
STARTUPINFO startup_info;
PROCESS_INFORMATION process_information;
ULONG dosretval;
int retval;
DWORD exit_code;
SECURITY_ATTRIBUTES process_attributes, thread_attributes;
char command_line[1024]= "";
memset(&startup_info,0,sizeof(STARTUPINFO));
startup_info.cb = sizeof(STARTUPINFO);
if (input)
freopen(input, "rb", stdin);
if (output)
freopen(output, "wb", stdout);
if (error)
freopen(error, "wb", stderr);
result= CreateProcess(
path,
&win_args,
NULL,
NULL,
TRUE,
0,
NULL,
NULL,
&startup_info,
&process_information
);
if (process_information.hProcess)
{
if (join)
{
if (WaitForSingleObject(process_information.hProcess, mysqld_timeout) == WAIT_TIMEOUT)
{
exit_code= -1;
}
else
{
GetExitCodeProcess(process_information.hProcess, &exit_code);
}
CloseHandle(process_information.hProcess);
}
else
{
exit_code= 0;
}
if (run_server)
{
switch (pid_mode)
{
case MASTER_PID:
master_server= process_information.hProcess;
break;
case SLAVE_PID:
slave_server= process_information.hProcess;
break;
};
pid_mode= 0;
run_server= FALSE;
};
}
else
{
exit_code= -1;
}
if (input)
freopen("CONIN$","rb",stdin);
if (output)
freopen("CONOUT$","wb",stdout);
if (error)
freopen("CONOUT$","wb",stderr);
return exit_code;
}
#else /* NOT __NETWARE__, NOT __WIN__ */
/* This assumes full POSIX.1 compliance */
int spawn(char *path, arg_list_t *al, int join, char *input,
char *output, char *error)
{
int result = 0;
pid_t pid;
if ((pid = fork()))
{
/* Remains in parent process */
if (join && (pid != -1))
waitpid(pid, &result, 0);
}
else
{
/* Child process */
/* Reassign streams */
if (input)
freopen(input, "r", stdin);
if (output)
freopen(output, "w", stdout);
if (error)
freopen(error, "w", stderr);
/* Spawn the process */
execve(path, al->argv, environ);
}
return result;
}
#endif /* __WIN__ */
#endif /* __NETWARE__ */
/****************************************************************************** /******************************************************************************
stop_server() stop_server()
Stop the server with the given port and pid file. Stop the server with the given port and pid file.
******************************************************************************/ ******************************************************************************/
int stop_server(char *bin_dir, char *user, char *password, int port, int stop_server(char *bin_dir, char *user, char *password, int port,
char *pid_file) char *pid_file)
{ {
arg_list_t al; arg_list_t al;
int err, i, argc = 0; int err;
char mysqladmin_file[PATH_MAX];
char trash[PATH_MAX]; char trash[PATH_MAX];
// mysqladmin file my_snprintf(trash, PATH_MAX, "/tmp/trash.out");
snprintf(mysqladmin_file, PATH_MAX, "%s/mysqladmin", bin_dir);
snprintf(trash, PATH_MAX, "/tmp/trash.out");
// args
init_args(&al);
add_arg(&al, "%s", mysqladmin_file);
add_arg(&al, "--no-defaults");
add_arg(&al, "--port=%u", port);
add_arg(&al, "--user=%s", user);
add_arg(&al, "--password=%s", password);
add_arg(&al, "-O");
add_arg(&al, "shutdown_timeout=20");
add_arg(&al, "shutdown");
// spawn /* args */
if ((err = spawn(mysqladmin_file, &al, TRUE, NULL, init_args(&al);
trash, NULL)) == 0) add_arg(&al, "%s", mysqladmin_file);
{ add_arg(&al, "--no-defaults");
sleep_until_file_deleted(pid_file); add_arg(&al, "--port=%u", port);
} add_arg(&al, "--user=%s", user);
else add_arg(&al, "--password=%s", password);
{ add_arg(&al, "-O");
add_arg(&al, "shutdown_timeout=20");
add_arg(&al, "shutdown");
/* spawn */
if ((err = spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL)) == 0)
{
sleep_until_file_deleted(pid_file);
}
else
{
pid_t pid = get_server_pid(pid_file); pid_t pid = get_server_pid(pid_file);
// shutdown failed - kill server
kill_server(pid);
sleep(TRY_MAX);
// remove pid file if possible /* shutdown failed - kill server */
err = remove(pid_file); kill_server(pid);
sleep(TRY_MAX);
/* remove pid file if possible */
err = my_delete(pid_file, MYF(MY_WME));
} }
// free args /* free args */
free_args(&al); free_args(&al);
return err; return err;
} }
/****************************************************************************** /******************************************************************************
get_server_pid() get_server_pid()
Get the VM id with the given pid file. Get the VM id with the given pid file.
******************************************************************************/ ******************************************************************************/
pid_t get_server_pid(char *pid_file) pid_t get_server_pid(char *pid_file)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX];
int fd, err; int err;
char *p; File fd;
pid_t id; char *p;
pid_t id = 0;
// discover id
fd = open(pid_file, O_RDONLY); /* discover id */
fd = my_open(pid_file, O_RDONLY, MYF(MY_WME));
err = read(fd, buf, PATH_MAX);
err = my_read(fd, buf, PATH_MAX, MYF(MY_WME));
close(fd);
my_close(fd, MYF(MY_WME));
if (err > 0)
{ if (err > 0)
// terminate string {
if ((p = strchr(buf, '\n')) != NULL) /* terminate string */
{ if ((p = strchr(buf, '\n')) != NULL)
*p = NULL; {
*p = '\0';
// check for a '\r'
if ((p = strchr(buf, '\r')) != NULL) /* check for a '\r' */
{ if ((p = strchr(buf, '\r')) != NULL)
*p = NULL; {
} *p = '\0';
} }
else }
{ else
buf[err] = NULL; {
} buf[err] = '\0';
}
id = strtol(buf, NULL, 0);
}
id = strtol(buf, NULL, 0);
}
return id; return id;
} }
/****************************************************************************** /******************************************************************************
kill_server() kill_server()
Force a kill of the server with the given pid. Force a kill of the server with the given pid.
******************************************************************************/ ******************************************************************************/
void kill_server(pid_t pid) void kill_server(pid_t pid)
{ {
if (pid > 0) if (pid > 0)
{ {
// destroy vm
#if !defined(__NETWARE__)
/* Send SIGTERM to pid */
kill(pid, SIGTERM);
#else /* __NETWARE__ */
/* destroy vm */
NXVmDestroy(pid); NXVmDestroy(pid);
#endif
} }
} }
/****************************************************************************** /******************************************************************************
del_tree() del_tree()
Delete the directory and subdirectories. Delete the directory and subdirectories.
******************************************************************************/ ******************************************************************************/
void del_tree(char *dir) void del_tree(char *dir)
{ {
DIR *parent = opendir(dir); MY_DIR *current;
DIR *entry; uint i;
char temp[PATH_MAX]; char temp[PATH_MAX];
if (parent == NULL)
{
return;
}
while((entry = readdir(parent)) != NULL)
{
// create long name
snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name);
if (entry->d_name[0] == '.')
{
// Skip
}
else if (S_ISDIR(entry->d_type))
{
// delete subdirectory
del_tree(temp);
}
else
{
// remove file
remove(temp);
}
}
// remove directory
rmdir(dir);
}
/******************************************************************************
removef()
******************************************************************************/
int removef(char *format, ...)
{
va_list ap;
char path[PATH_MAX];
va_start(ap, format);
vsnprintf(path, PATH_MAX, format, ap);
va_end(ap);
return remove(path); current = my_dir(dir, MYF(MY_WME | MY_WANT_STAT));
/* current is NULL if dir does not exist */
if (current == NULL)
return;
for (i = 0; i < current->number_off_files; i++)
{
/* create long name */
my_snprintf(temp, PATH_MAX, "%s/%s", dir, current->dir_entry[i].name);
if (current->dir_entry[i].name[0] == '.')
{
/* Skip */
}
else if (MY_S_ISDIR(current->dir_entry[i].mystat.st_mode))
{
/* delete subdirectory */
del_tree(temp);
}
else
{
/* remove file */
my_delete(temp, MYF(MY_WME));
}
}
my_dirend(current);
/* remove directory */
rmdir(dir);
} }
/****************************************************************************** /******************************************************************************
get_basedir() removef()
******************************************************************************/
int removef(const char *format, ...)
{
va_list ap;
char path[PATH_MAX];
va_start(ap, format);
my_vsnprintf(path, PATH_MAX, format, ap);
va_end(ap);
#ifdef __WIN__
{
MY_DIR *current;
uint i;
struct _finddata_t find;
char temp[PATH_MAX];
#ifdef _WIN64
__int64 handle;
#else
long handle;
#endif
char *p;
p= strrchr(path,'\\');
if (p == NULL)
{
p= strrchr(path,'/');
if (p == NULL)
p= &path;
else
p++;
}
else
p++;
if ((handle=_findfirst(path,&find)) == -1L)
return 0;
do
{
strcpy(p,find.name);
my_delete(path, MYF(MY_WME));
} while (!_findnext(handle,&find));
_findclose(handle);
}
#else
return my_delete(path, MYF(MY_WME));
#endif
}
/******************************************************************************
get_basedir()
******************************************************************************/ ******************************************************************************/
void get_basedir(char *argv0, char *basedir) void get_basedir(char *argv0, char *basedir)
{ {
char temp[PATH_MAX]; char temp[PATH_MAX];
char *p; char *p;
ASSERT(argv0 != NULL); ASSERT(argv0 != NULL);
ASSERT(basedir != NULL); ASSERT(basedir != NULL);
strcpy(temp, strlwr(argv0)); strcpy(temp, argv0);
while((p = strchr(temp, '\\')) != NULL) *p = '/'; #ifndef __WIN__
casedn_str(temp);
if ((p = strindex(temp, "/bin/")) != NULL) #endif
{ while((p = strchr(temp, '\\')) != NULL) *p = '/';
*p = NULL;
strcpy(basedir, temp); if ((p = strstr(temp, "/bin/")) != NullS)
} {
*p = '\0';
strcpy(basedir, temp);
}
} }

View File

@ -26,17 +26,41 @@
******************************************************************************/ ******************************************************************************/
#include <stdlib.h> #include <stdlib.h>
#ifndef __WIN__
#include <unistd.h> #include <unistd.h>
#endif
/****************************************************************************** /******************************************************************************
macros macros
******************************************************************************/ ******************************************************************************/
#ifdef __WIN__
#define PATH_MAX _MAX_PATH
#define NAME_MAX _MAX_FNAME
#define kill(A,B) TerminateProcess((HANDLE)A,0)
#define NOT_NEED_PID 0
#define MASTER_PID 1
#define SLAVE_PID 2
#define mysqld_timeout 60000
intptr_t master_server;
intptr_t slave_server;
int pid_mode;
bool run_server;
char win_args[1024];
bool skip_first_param;
#endif
#define ARG_BUF 10 #define ARG_BUF 10
#define TRY_MAX 5 #define TRY_MAX 5
#ifdef __NETWARE__
#define strstr(A,B) strindex(A,B)
#endif
/****************************************************************************** /******************************************************************************
structures structures
@ -53,6 +77,8 @@ typedef struct
} arg_list_t; } arg_list_t;
typedef int pid_t;
/****************************************************************************** /******************************************************************************
global variables global variables
@ -66,7 +92,7 @@ typedef struct
******************************************************************************/ ******************************************************************************/
void init_args(arg_list_t *); void init_args(arg_list_t *);
void add_arg(arg_list_t *, char *, ...); void add_arg(arg_list_t *, const char *, ...);
void free_args(arg_list_t *); void free_args(arg_list_t *);
int sleep_until_file_exists(char *); int sleep_until_file_exists(char *);
@ -80,8 +106,12 @@ pid_t get_server_pid(char *);
void kill_server(pid_t pid); void kill_server(pid_t pid);
void del_tree(char *); void del_tree(char *);
int removef(char *, ...); int removef(const char *, ...);
void get_basedir(char *, char *); void get_basedir(char *, char *);
char mysqladmin_file[PATH_MAX];
#endif /* _MY_MANAGE */ #endif /* _MY_MANAGE */

File diff suppressed because it is too large Load Diff