1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

mysql_test_run_new.c:

Included header fnmatch.h on Unix
  Changed C++ comments to C comments
  Corrected indentation of code written on Windows
  Split up lines to fit into 80 columns
  Initiated some variables to avoid warnings
  Added __attribute__((unused)) to unused function parameters
  Replace tab characters with space
  Put space after 'for', 'while' etc
  Added value to 'return' from non void function removef()
  On Unix strlwr() was incorrectly declared and a no op,
  replaced it with a macro that does nothing
  Split several statements on the same line
  Other minor changes to conform to coding standard
This commit is contained in:
kent@mysql.com
2004-11-06 14:01:27 +01:00
parent ca355c8a46
commit f9715d06dc
3 changed files with 750 additions and 716 deletions

View File

@ -30,6 +30,7 @@
#ifndef __WIN__
#include <sys/wait.h>
#include <unistd.h>
#include <fnmatch.h>
#else
#include <direct.h>
#include <stdlib.h>
@ -75,13 +76,14 @@ extern char **environ;
Init an argument list.
******************************************************************************/
void init_args(arg_list_t *al)
{
ASSERT(al != NULL);
al->argc = 0;
al->size = ARG_BUF;
al->argv = malloc(al->size * sizeof(char *));
al->argc= 0;
al->size= ARG_BUF;
al->argv= malloc(al->size * sizeof(char *));
ASSERT(al->argv != NULL);
return;
@ -94,6 +96,7 @@ void init_args(arg_list_t *al)
Add an argument to a list.
******************************************************************************/
void add_arg(arg_list_t *al, const char *format, ...)
{
va_list ap;
@ -101,11 +104,11 @@ void add_arg(arg_list_t *al, const char *format, ...)
ASSERT(al != NULL);
// increase size
/* increase size */
if (al->argc >= (int)al->size)
{
al->size += ARG_BUF;
al->argv = realloc(al->argv, al->size * sizeof(char *));
al->size+= ARG_BUF;
al->argv= realloc(al->argv, al->size * sizeof(char *));
ASSERT(al->argv != NULL);
}
@ -115,7 +118,7 @@ void add_arg(arg_list_t *al, const char *format, ...)
vsprintf(temp, format, ap);
va_end(ap);
al->argv[al->argc] = malloc(strlen(temp)+1);
al->argv[al->argc]= malloc(strlen(temp)+1);
ASSERT(al->argv[al->argc] != NULL);
strcpy(al->argv[al->argc], temp);
@ -123,7 +126,7 @@ void add_arg(arg_list_t *al, const char *format, ...)
}
else
{
al->argv[al->argc] = NULL;
al->argv[al->argc]= NULL;
}
return;
@ -136,22 +139,23 @@ void add_arg(arg_list_t *al, const char *format, ...)
Free an argument list.
******************************************************************************/
void free_args(arg_list_t *al)
{
int i;
ASSERT(al != NULL);
for(i = 0; i < al->argc; i++)
for (i= 0; i < al->argc; i++)
{
ASSERT(al->argv[i] != NULL);
free(al->argv[i]);
al->argv[i] = NULL;
al->argv[i]= NULL;
}
free(al->argv);
al->argc = 0;
al->argv = NULL;
al->argc= 0;
al->argv= NULL;
return;
}
@ -163,20 +167,21 @@ void free_args(arg_list_t *al)
Sleep until the given file is no longer found.
******************************************************************************/
#ifndef __WIN__
int sleep_until_file_deleted(char *pid_file)
#else
int sleep_until_file_deleted(HANDLE pid_file)
#endif
{
int err;
int err= 0; /* Initiate to supress warning */
#ifndef __WIN__
struct stat buf;
int i;
for(i = 0; (i < TRY_MAX) && (err = !stat(pid_file, &buf)); i++) sleep(1);
for (i= 0; (i < TRY_MAX) && (err= !stat(pid_file, &buf)); i++) sleep(1);
if (err != 0) err = errno;
if (err != 0) err= errno;
#else
err= (WaitForSingleObject(pid_file, TRY_MAX*1000) == WAIT_TIMEOUT);
#endif
@ -190,20 +195,21 @@ int sleep_until_file_deleted(HANDLE pid_file)
Sleep until the given file exists.
******************************************************************************/
#ifndef __WIN__
int sleep_until_file_exists(char *pid_file)
#else
int sleep_until_file_exists(HANDLE pid_file)
#endif
{
int err;
int err= 0; /* Initiate to supress warning */
#ifndef __WIN__
struct stat buf;
int i;
for(i = 0; (i < TRY_MAX) && (err = stat(pid_file, &buf)); i++) sleep(1);
for (i= 0; (i < TRY_MAX) && (err= stat(pid_file, &buf)); i++) sleep(1);
if (err != 0) err = errno;
if (err != 0) err= errno;
#else
err= (WaitForSingleObject(pid_file, TRY_MAX*1000) == WAIT_TIMEOUT);
#endif
@ -217,16 +223,19 @@ int sleep_until_file_exists(HANDLE pid_file)
Wait for the server on the given port to start.
******************************************************************************/
int wait_for_server_start(char *bin_dir, char *mysqladmin_file, char *user, char *password, int port,char *tmp_dir)
int wait_for_server_start(char *bin_dir __attribute__((unused)),
char *mysqladmin_file,
char *user, char *password, int port,char *tmp_dir)
{
arg_list_t al;
int err, i;
int err= 0, i;
char trash[PATH_MAX];
// mysqladmin file
/* mysqladmin file */
snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir);
// args
/* args */
init_args(&al);
add_arg(&al, "%s", mysqladmin_file);
add_arg(&al, "--no-defaults");
@ -235,7 +244,7 @@ int wait_for_server_start(char *bin_dir, char *mysqladmin_file, char *user, char
add_arg(&al, "--password=%s", password);
add_arg(&al, "--silent");
//#ifdef NOT_USED
/* #ifdef NOT_USED */
#ifndef __NETWARE__
add_arg(&al, "-O");
add_arg(&al, "connect_timeout=10");
@ -248,17 +257,19 @@ int wait_for_server_start(char *bin_dir, char *mysqladmin_file, char *user, char
#endif
add_arg(&al, "ping");
// NetWare does not support the connect timeout in the TCP/IP stack
// -- we will try the ping multiple times
/*
NetWare does not support the connect timeout in the TCP/IP stack
-- we will try the ping multiple times
*/
#ifndef __WIN__
for(i = 0; (i < TRY_MAX)
&& (err = spawn(mysqladmin_file, &al, TRUE, NULL,
for (i= 0; (i < TRY_MAX)
&& (err= spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL, NULL)); i++) sleep(1);
#else
err = spawn(mysqladmin_file, &al, TRUE, NULL,trash, NULL, NULL);
err= spawn(mysqladmin_file, &al, TRUE, NULL,trash, NULL, NULL);
#endif
// free args
/* free args */
free_args(&al);
return err;
@ -271,33 +282,34 @@ int wait_for_server_start(char *bin_dir, char *mysqladmin_file, char *user, char
Spawn the given path with the given arguments.
******************************************************************************/
#ifdef __NETWARE__
int spawn(char *path, arg_list_t *al, int join, char *input,
char *output, char *error, char *pid_file)
{
pid_t pid;
int result = 0;
wiring_t wiring = { FD_UNUSED, FD_UNUSED, FD_UNUSED };
unsigned long flags = PROC_CURRENT_SPACE | PROC_INHERIT_CWD;
int result= 0;
wiring_t wiring= { FD_UNUSED, FD_UNUSED, FD_UNUSED };
unsigned long flags= PROC_CURRENT_SPACE | PROC_INHERIT_CWD;
// open wiring
/* open wiring */
if (input)
wiring.infd = open(input, O_RDONLY);
wiring.infd= open(input, O_RDONLY);
if (output)
wiring.outfd = open(output, O_WRONLY | O_CREAT | O_TRUNC);
wiring.outfd= open(output, O_WRONLY | O_CREAT | O_TRUNC);
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);
// go
pid = procve(path, flags, NULL, &wiring, NULL, NULL, 0,
/* go */
pid= procve(path, flags, NULL, &wiring, NULL, NULL, 0,
NULL, (const char **)al->argv);
// close wiring
/* close wiring */
if (wiring.infd != -1)
close(wiring.infd);
@ -322,10 +334,8 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
char win_args[1024]= "";
char command_line[1024]= "";
/*
Skip the first parameter
*/
for(i = 1; i < al->argc; i++)
/* Skip the first parameter */
for (i= 1; i < al->argc; i++)
{
ASSERT(al->argv[i] != NULL);
strcat(win_args,al->argv[i]);
@ -333,7 +343,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
}
memset(&startup_info,0,sizeof(STARTUPINFO));
startup_info.cb = sizeof(STARTUPINFO);
startup_info.cb= sizeof(STARTUPINFO);
if (input)
freopen(input, "rb", stdin);
@ -361,7 +371,8 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
{
if (join)
{
if (WaitForSingleObject(process_information.hProcess, mysqld_timeout) == WAIT_TIMEOUT)
if (WaitForSingleObject(process_information.hProcess, mysqld_timeout)
== WAIT_TIMEOUT)
{
exit_code= -1;
}
@ -393,74 +404,58 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
}
#else
int spawn(char *path, arg_list_t *al, int join, char *input,
char *output, char *error, char *pid_file)
char *output, char *error, char *pid_file __attribute__((unused)))
{
pid_t pid;
int res_exec = 0;
int result = 0;
int res_exec= 0;
int result= 0;
pid = fork();
pid= fork();
if (pid == -1)
{
fprintf(stderr, "fork was't created\n");
/*
We can't create the fork...exit with error
*/
/* We can't create the fork...exit with error */
return EXIT_FAILURE;
}
if (pid > 0)
{
/*
The parent process is waiting for child process if join is not zero
*/
/* The parent process is waiting for child process if join is not zero */
if (join)
{
waitpid(pid, &result, 0);
if (WIFEXITED(result) != 0)
{
result = WEXITSTATUS(result);
result= WEXITSTATUS(result);
}
else
{
result = EXIT_FAILURE;
result= EXIT_FAILURE;
}
}
}
else
{
/*
Child process
*/
/* Child process */
add_arg(al, NULL);
/*
Reassign streams
*/
/* Reassign streams */
if (input)
freopen(input, "r", stdin);
if (output)
freopen(output, "w", stdout);
if (error)
freopen(error, "w", stderr);
/* Spawn the process */
if ((res_exec = execve(path, al->argv, environ)) < 0)
{
if ((res_exec= execve(path, al->argv, environ)) < 0)
exit(EXIT_FAILURE);
}
/*
Restore streams
*/
/* Restore streams */
if (input)
freopen("/dev/tty", "r", stdin);
@ -483,21 +478,23 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
Stop the server with the given port and pid file.
******************************************************************************/
int stop_server(char *bin_dir __attribute__((unused)), char *mysqladmin_file,
char *user, char *password, int port,
#ifndef __WIN__
int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password, int port,
char *pid_file,char *tmp_dir)
char *pid_file,
#else
int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password, int port,
HANDLE pid_file,char *tmp_dir)
HANDLE pid_file,
#endif
char *tmp_dir)
{
arg_list_t al;
int err = 0;
int err= 0;
char trash[PATH_MAX];
snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir);
// args
/* args */
init_args(&al);
add_arg(&al, "%s", mysqladmin_file);
add_arg(&al, "--no-defaults");
@ -511,8 +508,8 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
#endif
add_arg(&al, "shutdown");
// spawn
if ((err = spawn(mysqladmin_file, &al, TRUE, NULL,
/* spawn */
if ((err= spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL, NULL)) == 0)
{
sleep_until_file_deleted(pid_file);
@ -520,21 +517,21 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
else
{
#ifndef __WIN__
pid_t pid = get_server_pid(pid_file);
pid_t pid= get_server_pid(pid_file);
// shutdown failed - kill server
/* shutdown failed - kill server */
kill_server(pid);
sleep(TRY_MAX);
// remove pid file if possible
err = remove(pid_file);
/* remove pid file if possible */
err= remove(pid_file);
#else
TerminateProcess(pid_file,err);
#endif
}
// free args
/* free args */
free_args(&al);
return err;
@ -547,40 +544,41 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
Get the VM id with the given pid file.
******************************************************************************/
#ifndef __WIN__
pid_t get_server_pid(char *pid_file)
{
char buf[PATH_MAX];
int fd, err;
char *p;
pid_t id = 0;
pid_t id= 0;
// discover id
fd = open(pid_file, O_RDONLY);
/* discover id */
fd= open(pid_file, O_RDONLY);
err = read(fd, buf, PATH_MAX);
err= read(fd, buf, PATH_MAX);
close(fd);
if (err > 0)
{
// terminate string
if ((p = strchr(buf, '\n')) != NULL)
/* terminate string */
if ((p= strchr(buf, '\n')) != NULL)
{
*p = '\0';
*p= '\0';
// check for a '\r'
if ((p = strchr(buf, '\r')) != NULL)
/* check for a '\r' */
if ((p= strchr(buf, '\r')) != NULL)
{
*p = '\0';
*p= '\0';
}
}
else
{
buf[err] = '\0';
buf[err]= '\0';
}
id = strtol(buf, NULL, 0);
id= strtol(buf, NULL, 0);
}
return id;
@ -593,6 +591,7 @@ pid_t get_server_pid(char *pid_file)
Force a kill of the server with the given pid.
******************************************************************************/
void kill_server(pid_t pid)
{
if (pid > 0)
@ -614,10 +613,11 @@ void kill_server(pid_t pid)
Delete the directory and subdirectories.
******************************************************************************/
void del_tree(char *dir)
{
#ifndef __WIN__
DIR *parent = opendir(dir);
DIR *parent= opendir(dir);
struct dirent *entry;
char temp[PATH_MAX];
@ -626,28 +626,28 @@ void del_tree(char *dir)
return;
}
while((entry = readdir(parent)) != NULL)
while ((entry= readdir(parent)) != NULL)
{
// create long name
/* create long name */
snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name);
if (entry->d_name[0] == '.')
{
// Skip
/* Skip */
}
else
if (S_ISDIR(entry->d_type))
{
// delete subdirectory
/* delete subdirectory */
del_tree(temp);
}
else
{
// remove file
/* remove file */
remove(temp);
}
}
// remove directory
/* remove directory */
rmdir(dir);
#else
struct _finddata_t parent;
@ -664,28 +664,28 @@ void del_tree(char *dir)
do
{
// create long name
/* create long name */
snprintf(temp, PATH_MAX, "%s/%s", dir, parent.name);
if (parent.name[0] == '.')
{
// Skip
/* Skip */
}
else
if (parent.attrib & _A_SUBDIR)
{
// delete subdirectory
/* delete subdirectory */
del_tree(temp);
}
else
{
// remove file
/* remove file */
remove(temp);
}
} while (_findnext(handle,&parent) == 0);
_findclose(handle);
// remove directory
/* remove directory */
_rmdir(dir);
#endif
}
@ -695,6 +695,7 @@ void del_tree(char *dir)
removef()
******************************************************************************/
int removef(const char *format, ...)
{
#ifdef __NETWARE__
@ -723,18 +724,16 @@ int removef(const char *format, ...)
va_end(ap);
p = path + strlen(path);
p= path + strlen(path);
while (*p != '\\' && *p != '/' && p > path) p--;
if ((handle=_findfirst(path,&parent)) == -1L)
{
/*
if there is not files....it's ok.
*/
/* if there is not files....it's ok */
return 0;
}
*p = '\0';
*p= '\0';
do
{
@ -754,37 +753,33 @@ int removef(const char *format, ...)
va_list ap;
char path[PATH_MAX];
char *p;
/*
Get path with mask
*/
/* Get path with mask */
va_start(ap, format);
vsnprintf(path, PATH_MAX, format, ap);
va_end(ap);
p = path + strlen(path);
p= path + strlen(path);
while (*p != '\\' && *p != '/' && p > path) p--;
*p = '\0';
*p= '\0';
p++;
parent = opendir(path);
parent= opendir(path);
if (parent == NULL)
{
return;
return 1; /* Error, directory missing */
}
while((entry = readdir(parent)) != NULL)
while ((entry= readdir(parent)) != NULL)
{
/*
entry is not directory and entry matches with mask
*/
/* entry is not directory and entry matches with mask */
if (!S_ISDIR(entry->d_type) && !fnmatch(p, entry->d_name,0))
{
// create long name
/* create long name */
snprintf(temp, PATH_MAX, "%s/%s", path, entry->d_name);
// Delete only files
/* Delete only files */
remove(temp);
}
}
@ -797,6 +792,7 @@ int removef(const char *format, ...)
get_basedir()
******************************************************************************/
void get_basedir(char *argv0, char *basedir)
{
char temp[PATH_MAX];
@ -807,34 +803,28 @@ void get_basedir(char *argv0, char *basedir)
ASSERT(basedir != NULL);
strcpy(temp, strlwr(argv0));
while((p = strchr(temp, '\\')) != NULL) *p = '/';
while ((p= strchr(temp, '\\')) != NULL) *p= '/';
if ((position = strinstr(temp, "/bin/")) != 0)
if ((position= strinstr(temp, "/bin/")) != 0)
{
p = temp + position;
*p = '\0';
p= temp + position;
*p= '\0';
strcpy(basedir, temp);
}
}
#if !defined(__NETWARE__) && !defined(__WIN__)
char *strlwr(const char *s)
{
return s;
}
#endif
uint strinstr(reg1 const char *str,reg4 const char *search)
{
reg2 my_string i,j;
my_string start = (my_string) str;
my_string start= (my_string) str;
skipp:
while (*str != '\0')
{
if (*str++ == *search)
{
i=(my_string) str; j= (my_string) search+1;
i=(my_string) str;
j= (my_string) search+1;
while (*j)
if (*i++ != *j++) goto skipp;
return ((uint) (str - start));
@ -848,6 +838,7 @@ uint strinstr(reg1 const char *str,reg4 const char *search)
remove_empty_file()
******************************************************************************/
void remove_empty_file(const char *file_name)
{
struct stat file;

View File

@ -36,7 +36,7 @@
#ifndef __WIN__
#define strnicmp strncasecmp
char *strlwr(const char *s);
#define strlwr(STRARG) (STRARG)
#else
int my_vsnprintf_(char *to, size_t n, const char* value, ...);
#endif

File diff suppressed because it is too large Load Diff