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__ #ifndef __WIN__
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <fnmatch.h>
#else #else
#include <direct.h> #include <direct.h>
#include <stdlib.h> #include <stdlib.h>
@ -75,6 +76,7 @@ extern char **environ;
Init an argument list. Init an argument list.
******************************************************************************/ ******************************************************************************/
void init_args(arg_list_t *al) void init_args(arg_list_t *al)
{ {
ASSERT(al != NULL); ASSERT(al != NULL);
@ -94,6 +96,7 @@ void init_args(arg_list_t *al)
Add an argument to a list. Add an argument to a list.
******************************************************************************/ ******************************************************************************/
void add_arg(arg_list_t *al, const char *format, ...) void add_arg(arg_list_t *al, const char *format, ...)
{ {
va_list ap; va_list ap;
@ -101,7 +104,7 @@ void add_arg(arg_list_t *al, const char *format, ...)
ASSERT(al != NULL); ASSERT(al != NULL);
// increase size /* increase size */
if (al->argc >= (int)al->size) if (al->argc >= (int)al->size)
{ {
al->size+= ARG_BUF; al->size+= ARG_BUF;
@ -136,6 +139,7 @@ void add_arg(arg_list_t *al, const char *format, ...)
Free an argument list. Free an argument list.
******************************************************************************/ ******************************************************************************/
void free_args(arg_list_t *al) void free_args(arg_list_t *al)
{ {
int i; int i;
@ -163,13 +167,14 @@ void free_args(arg_list_t *al)
Sleep until the given file is no longer found. Sleep until the given file is no longer found.
******************************************************************************/ ******************************************************************************/
#ifndef __WIN__ #ifndef __WIN__
int sleep_until_file_deleted(char *pid_file) int sleep_until_file_deleted(char *pid_file)
#else #else
int sleep_until_file_deleted(HANDLE pid_file) int sleep_until_file_deleted(HANDLE pid_file)
#endif #endif
{ {
int err; int err= 0; /* Initiate to supress warning */
#ifndef __WIN__ #ifndef __WIN__
struct stat buf; struct stat buf;
int i; int i;
@ -190,13 +195,14 @@ int sleep_until_file_deleted(HANDLE pid_file)
Sleep until the given file exists. Sleep until the given file exists.
******************************************************************************/ ******************************************************************************/
#ifndef __WIN__ #ifndef __WIN__
int sleep_until_file_exists(char *pid_file) int sleep_until_file_exists(char *pid_file)
#else #else
int sleep_until_file_exists(HANDLE pid_file) int sleep_until_file_exists(HANDLE pid_file)
#endif #endif
{ {
int err; int err= 0; /* Initiate to supress warning */
#ifndef __WIN__ #ifndef __WIN__
struct stat buf; struct stat buf;
int i; int i;
@ -217,16 +223,19 @@ int sleep_until_file_exists(HANDLE pid_file)
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 *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; arg_list_t al;
int err, i; int err= 0, i;
char trash[PATH_MAX]; char trash[PATH_MAX];
// mysqladmin file /* mysqladmin file */
snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir); snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir);
// 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");
@ -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, "--password=%s", password);
add_arg(&al, "--silent"); add_arg(&al, "--silent");
//#ifdef NOT_USED /* #ifdef NOT_USED */
#ifndef __NETWARE__ #ifndef __NETWARE__
add_arg(&al, "-O"); add_arg(&al, "-O");
add_arg(&al, "connect_timeout=10"); 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 #endif
add_arg(&al, "ping"); 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__ #ifndef __WIN__
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,
@ -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); err= spawn(mysqladmin_file, &al, TRUE, NULL,trash, NULL, NULL);
#endif #endif
// free args /* free args */
free_args(&al); free_args(&al);
return err; 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. Spawn the given path with the given arguments.
******************************************************************************/ ******************************************************************************/
#ifdef __NETWARE__ #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 *pid_file) 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 }; 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);
@ -290,14 +302,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);
// close wiring /* close wiring */
if (wiring.infd != -1) if (wiring.infd != -1)
close(wiring.infd); close(wiring.infd);
@ -322,9 +334,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
char win_args[1024]= ""; char win_args[1024]= "";
char command_line[1024]= ""; char command_line[1024]= "";
/* /* Skip the first parameter */
Skip the first parameter
*/
for (i= 1; i < al->argc; i++) for (i= 1; i < al->argc; i++)
{ {
ASSERT(al->argv[i] != NULL); ASSERT(al->argv[i] != NULL);
@ -361,7 +371,8 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
{ {
if (join) if (join)
{ {
if (WaitForSingleObject(process_information.hProcess, mysqld_timeout) == WAIT_TIMEOUT) if (WaitForSingleObject(process_information.hProcess, mysqld_timeout)
== WAIT_TIMEOUT)
{ {
exit_code= -1; exit_code= -1;
} }
@ -393,7 +404,7 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
} }
#else #else
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 *pid_file) char *output, char *error, char *pid_file __attribute__((unused)))
{ {
pid_t pid; pid_t pid;
int res_exec= 0; int res_exec= 0;
@ -404,17 +415,13 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
if (pid == -1) if (pid == -1)
{ {
fprintf(stderr, "fork was't created\n"); 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; return EXIT_FAILURE;
} }
if (pid > 0) 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) if (join)
{ {
waitpid(pid, &result, 0); waitpid(pid, &result, 0);
@ -431,36 +438,24 @@ int spawn(char *path, arg_list_t *al, int join, char *input,
else else
{ {
/* /* Child process */
Child process
*/
add_arg(al, NULL); add_arg(al, NULL);
/* Reassign streams */
/*
Reassign streams
*/
if (input) if (input)
freopen(input, "r", stdin); freopen(input, "r", stdin);
if (output) if (output)
freopen(output, "w", stdout); freopen(output, "w", stdout);
if (error) if (error)
freopen(error, "w", stderr); freopen(error, "w", stderr);
/* Spawn the process */ /* Spawn the process */
if ((res_exec= execve(path, al->argv, environ)) < 0) if ((res_exec= execve(path, al->argv, environ)) < 0)
{
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
/* /* Restore streams */
Restore streams
*/
if (input) if (input)
freopen("/dev/tty", "r", stdin); 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. 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__ #ifndef __WIN__
int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password, int port, char *pid_file,
char *pid_file,char *tmp_dir)
#else #else
int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password, int port, HANDLE pid_file,
HANDLE pid_file,char *tmp_dir)
#endif #endif
char *tmp_dir)
{ {
arg_list_t al; arg_list_t al;
int err= 0; 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); snprintf(trash, PATH_MAX, "%s/trash.out",tmp_dir);
// 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");
@ -511,7 +508,7 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
#endif #endif
add_arg(&al, "shutdown"); add_arg(&al, "shutdown");
// spawn /* spawn */
if ((err= spawn(mysqladmin_file, &al, TRUE, NULL, if ((err= spawn(mysqladmin_file, &al, TRUE, NULL,
trash, NULL, NULL)) == 0) trash, NULL, NULL)) == 0)
{ {
@ -522,19 +519,19 @@ int stop_server(char *bin_dir, char *mysqladmin_file, char *user, char *password
#ifndef __WIN__ #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); kill_server(pid);
sleep(TRY_MAX); sleep(TRY_MAX);
// remove pid file if possible /* remove pid file if possible */
err= remove(pid_file); err= remove(pid_file);
#else #else
TerminateProcess(pid_file,err); TerminateProcess(pid_file,err);
#endif #endif
} }
// free args /* free args */
free_args(&al); free_args(&al);
return err; 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. Get the VM id with the given pid file.
******************************************************************************/ ******************************************************************************/
#ifndef __WIN__ #ifndef __WIN__
pid_t get_server_pid(char *pid_file) pid_t get_server_pid(char *pid_file)
{ {
@ -555,7 +553,7 @@ pid_t get_server_pid(char *pid_file)
char *p; char *p;
pid_t id= 0; pid_t id= 0;
// discover id /* discover id */
fd= open(pid_file, O_RDONLY); fd= open(pid_file, O_RDONLY);
err= read(fd, buf, PATH_MAX); err= read(fd, buf, PATH_MAX);
@ -564,12 +562,12 @@ pid_t get_server_pid(char *pid_file)
if (err > 0) if (err > 0)
{ {
// terminate string /* terminate string */
if ((p= strchr(buf, '\n')) != NULL) if ((p= strchr(buf, '\n')) != NULL)
{ {
*p= '\0'; *p= '\0';
// check for a '\r' /* check for a '\r' */
if ((p= strchr(buf, '\r')) != NULL) if ((p= strchr(buf, '\r')) != NULL)
{ {
*p= '\0'; *p= '\0';
@ -593,6 +591,7 @@ pid_t get_server_pid(char *pid_file)
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)
@ -614,6 +613,7 @@ void kill_server(pid_t pid)
Delete the directory and subdirectories. Delete the directory and subdirectories.
******************************************************************************/ ******************************************************************************/
void del_tree(char *dir) void del_tree(char *dir)
{ {
#ifndef __WIN__ #ifndef __WIN__
@ -628,26 +628,26 @@ void del_tree(char *dir)
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); snprintf(temp, PATH_MAX, "%s/%s", dir, entry->d_name);
if (entry->d_name[0] == '.') if (entry->d_name[0] == '.')
{ {
// Skip /* Skip */
} }
else else
if (S_ISDIR(entry->d_type)) if (S_ISDIR(entry->d_type))
{ {
// delete subdirectory /* delete subdirectory */
del_tree(temp); del_tree(temp);
} }
else else
{ {
// remove file /* remove file */
remove(temp); remove(temp);
} }
} }
// remove directory /* remove directory */
rmdir(dir); rmdir(dir);
#else #else
struct _finddata_t parent; struct _finddata_t parent;
@ -664,28 +664,28 @@ void del_tree(char *dir)
do do
{ {
// create long name /* create long name */
snprintf(temp, PATH_MAX, "%s/%s", dir, parent.name); snprintf(temp, PATH_MAX, "%s/%s", dir, parent.name);
if (parent.name[0] == '.') if (parent.name[0] == '.')
{ {
// Skip /* Skip */
} }
else else
if (parent.attrib & _A_SUBDIR) if (parent.attrib & _A_SUBDIR)
{ {
// delete subdirectory /* delete subdirectory */
del_tree(temp); del_tree(temp);
} }
else else
{ {
// remove file /* remove file */
remove(temp); remove(temp);
} }
} while (_findnext(handle,&parent) == 0); } while (_findnext(handle,&parent) == 0);
_findclose(handle); _findclose(handle);
// remove directory /* remove directory */
_rmdir(dir); _rmdir(dir);
#endif #endif
} }
@ -695,6 +695,7 @@ void del_tree(char *dir)
removef() removef()
******************************************************************************/ ******************************************************************************/
int removef(const char *format, ...) int removef(const char *format, ...)
{ {
#ifdef __NETWARE__ #ifdef __NETWARE__
@ -728,9 +729,7 @@ int removef(const char *format, ...)
if ((handle=_findfirst(path,&parent)) == -1L) if ((handle=_findfirst(path,&parent)) == -1L)
{ {
/* /* if there is not files....it's ok */
if there is not files....it's ok.
*/
return 0; return 0;
} }
@ -754,9 +753,7 @@ int removef(const char *format, ...)
va_list ap; va_list ap;
char path[PATH_MAX]; char path[PATH_MAX];
char *p; char *p;
/* /* Get path with mask */
Get path with mask
*/
va_start(ap, format); va_start(ap, format);
vsnprintf(path, PATH_MAX, format, ap); vsnprintf(path, PATH_MAX, format, ap);
@ -772,19 +769,17 @@ int removef(const char *format, ...)
if (parent == NULL) 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)) 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); snprintf(temp, PATH_MAX, "%s/%s", path, entry->d_name);
// Delete only files /* Delete only files */
remove(temp); remove(temp);
} }
} }
@ -797,6 +792,7 @@ int removef(const char *format, ...)
get_basedir() get_basedir()
******************************************************************************/ ******************************************************************************/
void get_basedir(char *argv0, char *basedir) void get_basedir(char *argv0, char *basedir)
{ {
char temp[PATH_MAX]; 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) uint strinstr(reg1 const char *str,reg4 const char *search)
{ {
reg2 my_string i,j; reg2 my_string i,j;
@ -834,7 +823,8 @@ uint strinstr(reg1 const char *str,reg4 const char *search)
{ {
if (*str++ == *search) if (*str++ == *search)
{ {
i=(my_string) str; j= (my_string) search+1; i=(my_string) str;
j= (my_string) search+1;
while (*j) while (*j)
if (*i++ != *j++) goto skipp; if (*i++ != *j++) goto skipp;
return ((uint) (str - start)); return ((uint) (str - start));
@ -848,6 +838,7 @@ uint strinstr(reg1 const char *str,reg4 const char *search)
remove_empty_file() remove_empty_file()
******************************************************************************/ ******************************************************************************/
void remove_empty_file(const char *file_name) void remove_empty_file(const char *file_name)
{ {
struct stat file; struct stat file;

View File

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

File diff suppressed because it is too large Load Diff