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,6 +76,7 @@ extern char **environ;
Init an argument list.
******************************************************************************/
void init_args(arg_list_t *al)
{
ASSERT(al != NULL);
@ -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,7 +104,7 @@ 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;
@ -136,6 +139,7 @@ void add_arg(arg_list_t *al, const char *format, ...)
Free an argument list.
******************************************************************************/
void free_args(arg_list_t *al)
{
int i;
@ -163,13 +167,14 @@ 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;
@ -190,13 +195,14 @@ 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;
@ -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,8 +257,10 @@ 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,
@ -258,7 +269,7 @@ int wait_for_server_start(char *bin_dir, char *mysqladmin_file, char *user, char
err= spawn(mysqladmin_file, &al, TRUE, NULL,trash, NULL, NULL);
#endif
// free args
/* free args */
free_args(&al);
return err;
@ -271,6 +282,7 @@ 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)
@ -280,7 +292,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
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);
@ -290,14 +302,14 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
if (error)
wiring.errfd= open(error, O_WRONLY | O_CREAT | O_TRUNC);
// procve requires a NULL
/* procve requires a NULL */
add_arg(al, NULL);
// go
/* 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,9 +334,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
char win_args[1024]= "";
char command_line[1024]= "";
/*
Skip the first parameter
*/
/* Skip the first parameter */
for (i= 1; i < al->argc; i++)
{
ASSERT(al->argv[i] != NULL);
@ -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,7 +404,7 @@ 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;
@ -404,17 +415,13 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
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);
@ -431,36 +438,24 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
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)
{
exit(EXIT_FAILURE);
}
/*
Restore streams
*/
/* Restore streams */
if (input)
freopen("/dev/tty", "r", stdin);
@ -483,13 +478,15 @@ 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;
@ -497,7 +494,7 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
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,7 +508,7 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
#endif
add_arg(&al, "shutdown");
// spawn
/* spawn */
if ((err= spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL, NULL)) == 0)
{
@ -522,19 +519,19 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
#ifndef __WIN__
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
/* 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,6 +544,7 @@ 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)
{
@ -555,7 +553,7 @@ pid_t get_server_pid(char *pid_file)
char *p;
pid_t id= 0;
// discover id
/* discover id */
fd= open(pid_file, O_RDONLY);
err= read(fd, buf, PATH_MAX);
@ -564,12 +562,12 @@ pid_t get_server_pid(char *pid_file)
if (err > 0)
{
// terminate string
/* terminate string */
if ((p= strchr(buf, '\n')) != NULL)
{
*p= '\0';
// check for a '\r'
/* check for a '\r' */
if ((p= strchr(buf, '\r')) != NULL)
{
*p= '\0';
@ -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,6 +613,7 @@ void kill_server(pid_t pid)
Delete the directory and subdirectories.
******************************************************************************/
void del_tree(char *dir)
{
#ifndef __WIN__
@ -628,26 +628,26 @@ void del_tree(char *dir)
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__
@ -728,9 +729,7 @@ int removef(const char *format, ...)
if ((handle=_findfirst(path,&parent)) == -1L)
{
/*
if there is not files....it's ok.
*/
/* if there is not files....it's ok */
return 0;
}
@ -754,9 +753,7 @@ 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);
@ -772,19 +769,17 @@ int removef(const char *format, ...)
if (parent == NULL)
{
return;
return 1; /* Error, directory missing */
}
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];
@ -817,13 +813,6 @@ void get_basedir(char *argv0, char *basedir)
}
}
#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;
@ -834,7 +823,8 @@ uint strinstr(reg1 const char *str,reg4 const char *search)
{
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