Commit 3320c165 authored by unknown's avatar unknown

Merge pilot.mysql.com:/data/msvensson/mysql/mysql-5.1-rpl

into  pilot.mysql.com:/data/msvensson/mysql/mysql-5.1-mtr


BitKeeper/etc/ignore:
  auto-union
BitKeeper/deleted/.del-rpl_row_charset.test:
  Auto merged
BitKeeper/deleted/.del-rpl_row_charset_innodb.test:
  Auto merged
CMakeLists.txt:
  Auto merged
client/mysqltest.c:
  Auto merged
configure.in:
  Auto merged
mysql-test/extra/binlog_tests/blackhole.test:
  Auto merged
mysql-test/extra/binlog_tests/mix_innodb_myisam_side_effects.test:
  Auto merged
mysql-test/include/mix1.inc:
  Auto merged
mysql-test/r/ctype_big5.result:
  Auto merged
mysql-test/r/gis.result:
  Auto merged
mysql-test/r/mysqlbinlog.result:
  Auto merged
mysql-test/r/query_cache.result:
  Auto merged
mysql-test/r/sp.result:
  Auto merged
mysql-test/r/system_mysql_db.result:
  Auto merged
mysql-test/r/trigger.result:
  Auto merged
mysql-test/r/type_blob.result:
  Auto merged
mysql-test/r/view.result:
  Auto merged
mysql-test/r/warnings.result:
  Auto merged
mysql-test/suite/federated/federated.result:
  Auto merged
mysql-test/suite/federated/federated.test:
  Auto merged
mysql-test/suite/ndb_team/r/ndb_dd_backuprestore.result:
  Auto merged
mysql-test/suite/ndb_team/r/rpl_ndb_dd_advance.result:
  Auto merged
mysql-test/suite/ndb_team/t/rpl_ndb_dd_advance.test:
  Auto merged
mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result:
  Auto merged
mysql-test/suite/rpl/r/rpl_row_log_innodb.result:
  Auto merged
mysql-test/suite/rpl/r/rpl_timezone.result:
  Auto merged
mysql-test/suite/rpl/t/rpl_load_from_master.test:
  Auto merged
mysql-test/suite/rpl/t/rpl_rotate_logs.test:
  Auto merged
mysql-test/suite/rpl/t/rpl_trigger.test:
  Auto merged
mysql-test/t/csv.test:
  Auto merged
mysql-test/t/ctype_big5.test:
  Auto merged
mysql-test/t/gis.test:
  Auto merged
mysql-test/t/innodb.test:
  Auto merged
mysql-test/t/mysqldump.test:
  Auto merged
mysql-test/t/partition.test:
  Auto merged
mysql-test/t/query_cache.test:
  Auto merged
mysql-test/t/show_check.test:
  Auto merged
mysql-test/t/sp.test:
  Auto merged
mysql-test/t/system_mysql_db_fix50117.test:
  Auto merged
mysql-test/t/trigger.test:
  Auto merged
mysql-test/t/trigger_notembedded.test:
  Auto merged
mysql-test/t/type_blob.test:
  Auto merged
mysql-test/t/view.test:
  Auto merged
mysql-test/t/warnings.test:
  Auto merged
sql/ha_ndbcluster.cc:
  Auto merged
mysql-test/Makefile.am:
  SCCS merged
mysql-test/mysql-test-run.pl:
  Use local version of mtr.pl
mysql-test/lib/mtr_cases.pm:
  Use local mtr_cases.pm
mysql-test/suite/rpl/t/disabled.def:
  Use remote disabled file
mysql-test/t/disabled.def:
  Use remote disabled file
sql/ha_ndbcluster_binlog.cc:
  Use remote
mysql-test/extra/rpl_tests/rpl_charset.test:
  Manual merge
mysql-test/lib/mtr_report.pm:
  Manual merge
mysql-test/suite/binlog/r/binlog_killed_simulate.result:
  Manual merge
mysql-test/suite/binlog/r/binlog_multi_engine.result:
  Manual merge
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
  Manual merge
mysql-test/suite/binlog/r/binlog_stm_blackhole.result:
  Manual merge
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
  Manual merge
mysql-test/suite/binlog/t/binlog_killed.test:
  Manual merge
mysql-test/suite/binlog/t/binlog_killed_simulate.test:
  Manual merge
mysql-test/suite/binlog/t/binlog_row_mix_innodb_myisam.test:
  Manual merge
mysql-test/suite/binlog/t/binlog_stm_mix_innodb_myisam.test:
  Manual merge
mysql-test/suite/ndb/r/ndb_binlog_format.result:
  Manual merge
mysql-test/suite/ndb/r/ndb_restore.result:
  Manual merge
mysql-test/suite/ndb/t/ndb_restore.test:
  Manual merge
mysql-test/suite/rpl/include/rpl_mixed_dml.inc:
  Manual merge
mysql-test/suite/rpl/r/rpl_stm_log.result:
  Manual merge
mysql-test/suite/rpl/t/rpl_row_sp005.test:
  Manual merge
mysql-test/t/log_state.test:
  Manual merge
mysql-test/t/mysqlbinlog.test:
  Manual merge
mysql-test/t/mysqlbinlog2.test:
  Manual merge
mysql-test/t/upgrade.test:
  Manual merge
parents 7c7801f9 d8d3ed3b
......@@ -58,6 +58,7 @@
./mysql.sln
./mysql.suo
./prepare
.DS_Store
.defs.mk
.depend
.depend.mk
......@@ -1178,6 +1179,7 @@ libmysqld/sql_parse.cc
libmysqld/sql_partition.cc
libmysqld/sql_plugin.cc
libmysqld/sql_prepare.cc
libmysqld/sql_profile.cc
libmysqld/sql_rename.cc
libmysqld/sql_repl.cc
libmysqld/sql_select.cc
......@@ -1279,8 +1281,12 @@ mysql-5.0.2-alpha.tar.gz
mysql-max-4.0.2-alpha-pc-linux-gnu-i686.tar.gz
mysql-test/*.ds?
mysql-test/*.vcproj
mysql-test/.DS_Store
mysql-test/funcs_1.log
mysql-test/funcs_1.tar
mysql-test/gmon.out
mysql-test/install_test_db
mysql-test/lib/My/SafeProcess/my_safe_process
mysql-test/lib/init_db.sql
mysql-test/mtr
mysql-test/mysql-test-run
......@@ -1367,9 +1373,12 @@ mysql-test/r/symlink.log
mysql-test/r/system_mysql_db.log
mysql-test/r/tmp.result
mysql-test/r/udf.log
mysql-test/reg.log
mysql-test/rpl.log
mysql-test/share/mysql
mysql-test/std_data/*.pem
mysql-test/suite/funcs_1.tar.gz
mysql-test/suite/funcs_1.tar.zip
mysql-test/suite/funcs_1/r/innodb_trig_03e.warnings
mysql-test/suite/funcs_1/r/innodb_views.warnings
mysql-test/suite/funcs_1/r/memory_trig_03e.warnings
......@@ -3012,11 +3021,3 @@ win/vs8cache.txt
ylwrap
zlib/*.ds?
zlib/*.vcproj
mysql-test/funcs_1.log
mysql-test/funcs_1.tar
mysql-test/suite/funcs_1.tar.gz
mysql-test/.DS_Store
.DS_Store
libmysqld/sql_profile.cc
mysql-test/suite/funcs_1.tar.zip
mysql-test/reg.log
......@@ -245,3 +245,4 @@ IF(WITH_EMBEDDED_SERVER)
ADD_SUBDIRECTORY(libmysqld)
ADD_SUBDIRECTORY(libmysqld/examples)
ENDIF(WITH_EMBEDDED_SERVER)
ADD_SUBDIRECTORY(mysql-test/lib/My/SafeProcess)
......@@ -1320,12 +1320,26 @@ void show_diff(DYNAMIC_STRING* ds,
const char* filename1, const char* filename2)
{
const char* diff_failed= 0;
DYNAMIC_STRING ds_tmp;
if (init_dynamic_string(&ds_tmp, "", 256, 256))
die("Out of memory");
/* First try with diff --help to see if the command exists at all */
if (run_tool("diff",
&ds_tmp, /* Get output from diff in ds_tmp */
"--help",
"2>&1",
NULL) != 0) /* Most "diff --help" tools return 0 */
{
diff_failed= "You don't appear to have diff installed";
}
else
{
dynstr_set(&ds_tmp, "");
/* First try with unified diff */
if (run_tool("diff",
&ds_tmp, /* Get output from diff in ds_tmp */
"-u",
......@@ -1344,18 +1358,26 @@ void show_diff(DYNAMIC_STRING* ds,
filename2,
"2>&1",
NULL) > 1) /* Most "diff" tools return >1 if error */
{
dynstr_set(&ds_tmp, "");
diff_failed= "Could not execute 'diff -u' or 'diff -c'";
}
}
}
if (diff_failed)
{
/*
Fallback to dump both files to result file and inform
about installing "diff"
*/
dynstr_set(&ds_tmp, "");
dynstr_append(&ds_tmp, "\n");
dynstr_append(&ds_tmp, diff_failed);
dynstr_append(&ds_tmp,
"\n"
"The two files differ but it was not possible to execute 'diff' in\n"
"order to show only the difference, tried both 'diff -u' or 'diff -c'.\n"
"Instead the whole content of the two files was shown for you to diff manually. ;)\n\n"
"order to show only the difference. Instead the whole content of the\n"
"two files was shown for you to diff manually.\n\n"
"To get a better report you should install 'diff' on your system, which you\n"
"for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n"
#ifdef __WIN__
......@@ -1373,7 +1395,6 @@ void show_diff(DYNAMIC_STRING* ds,
cat_file(&ds_tmp, filename2);
dynstr_append(&ds_tmp, "<<<<\n");
}
}
if (ds)
{
......@@ -2181,8 +2202,19 @@ void eval_expr(VAR *v, const char *p, const char **p_end)
int open_file(const char *name)
{
char buff[FN_REFLEN];
size_t length;
DBUG_ENTER("open_file");
DBUG_PRINT("enter", ("name: %s", name));
/* Extract path from current file and try it as base first */
if (dirname_part(buff, cur_file->file_name, &length))
{
strxmov(buff, buff, name, NullS);
if (access(buff, F_OK) == 0){
DBUG_PRINT("info", ("The file exists"));
name= buff;
}
}
if (!test_if_hard_path(name))
{
strxmov(buff, opt_basedir, name, NullS);
......@@ -7444,6 +7476,9 @@ void do_get_replace(struct st_command *command)
if (!*from)
die("Wrong number of arguments to replace_result in '%s'",
command->query);
#ifdef __WIN__
fix_win_paths(to, from - to);
#endif
insert_pointer_name(&from_array,to);
to= get_string(&buff, &from, command);
insert_pointer_name(&to_array,to);
......
......@@ -2758,8 +2758,8 @@ AC_CONFIG_FILES(Makefile extra/Makefile mysys/Makefile dnl
server-tools/Makefile server-tools/instance-manager/Makefile dnl
cmd-line-utils/Makefile cmd-line-utils/libedit/Makefile dnl
libmysqld/Makefile libmysqld/examples/Makefile dnl
mysql-test/Makefile dnl
mysql-test/ndb/Makefile netware/Makefile sql-bench/Makefile dnl
mysql-test/Makefile mysql-test/lib/My/SafeProcess/Makefile dnl
netware/Makefile sql-bench/Makefile dnl
include/mysql_version.h plugin/Makefile win/Makefile)
AC_CONFIG_COMMANDS([default], , test -z "$CONFIG_HEADERS" || echo timestamp > stamp-h)
......
......@@ -17,119 +17,24 @@
## Process this file with automake to create Makefile.in
SUBDIRS = ndb
testdir = $(prefix)/mysql-test
benchdir_root= $(prefix)
testdir = $(benchdir_root)/mysql-test
EXTRA_SCRIPTS = mysql-test-run-shell.sh install_test_db.sh \
valgrind.supp $(PRESCRIPTS)
EXTRA_DIST = $(EXTRA_SCRIPTS) suite
GENSCRIPTS = mysql-test-run-shell install_test_db mtr mysql-test-run
PRESCRIPTS = mysql-test-run.pl mysql-stress-test.pl
test_SCRIPTS = $(GENSCRIPTS) $(PRESCRIPTS)
CLEANFILES = $(GENSCRIPTS)
EXTRA_DIST = README \
mysql-test-run.pl \
mysql-stress-test.pl \
t r include suite extra \
lib std_data \
valgrind.supp
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I..
test_SCRIPTS = mtr mysql-test-run
CLEANFILES = $(test_SCRIPTS)
SUBDIRS = lib/My/SafeProcess
dist-hook:
mkdir -p \
$(distdir)/t \
$(distdir)/extra/binlog_tests \
$(distdir)/extra/rpl_tests \
$(distdir)/r \
$(distdir)/include \
$(distdir)/std_data \
$(distdir)/std_data/ndb_backup50 \
$(distdir)/std_data/ndb_backup51 \
$(distdir)/std_data/ndb_backup51_data_be \
$(distdir)/std_data/ndb_backup51_data_le \
$(distdir)/std_data/parts \
$(distdir)/lib \
$(distdir)/lib/My
-$(INSTALL_DATA) $(srcdir)/t/*.def $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.test $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.imtest $(distdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.sql $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.disabled $(distdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.opt $(srcdir)/t/*.slave-mi $(distdir)/t
-$(INSTALL_SCRIPT) $(srcdir)/t/*.sh $(distdir)/t
$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.test $(distdir)/extra/binlog_tests
$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.test $(distdir)/extra/rpl_tests
-$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.opt $(distdir)/extra/binlog_tests
-$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.opt $(distdir)/extra/rpl_tests
$(INSTALL_DATA) $(srcdir)/include/*.inc $(distdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.sql $(distdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.test $(distdir)/include
$(INSTALL_DATA) $(srcdir)/r/*.result $(srcdir)/r/*.require $(distdir)/r
$(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Index.xml $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.dat $(srcdir)/std_data/*.000001 $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.pem $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.frm $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.MY* $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(distdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup50/BACKUP* $(distdir)/std_data/ndb_backup50
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51/BACKUP* $(distdir)/std_data/ndb_backup51
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_be/BACKUP* $(distdir)/std_data/ndb_backup51_data_be
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_le/BACKUP* $(distdir)/std_data/ndb_backup51_data_le
$(INSTALL_DATA) $(srcdir)/std_data/parts/part_* $(distdir)/std_data/parts
$(INSTALL_DATA) $(srcdir)/lib/*.pl $(distdir)/lib
$(INSTALL_DATA) $(srcdir)/lib/My/*.pm $(distdir)/lib/My
-rm -rf `find $(distdir)/suite -type d -name SCCS` $(distdir)/suite/row_lock
# Install all files and files in directories listed in EXTRA_DIST
install-data-local:
$(mkinstalldirs) \
$(DESTDIR)$(testdir)/t \
$(DESTDIR)$(testdir)/extra/binlog_tests \
$(DESTDIR)$(testdir)/extra/rpl_tests \
$(DESTDIR)$(testdir)/r \
$(DESTDIR)$(testdir)/include \
$(DESTDIR)$(testdir)/std_data \
$(DESTDIR)$(testdir)/std_data/ndb_backup50 \
$(DESTDIR)$(testdir)/std_data/ndb_backup51 \
$(DESTDIR)$(testdir)/std_data/ndb_backup51_data_be \
$(DESTDIR)$(testdir)/std_data/ndb_backup51_data_le \
$(DESTDIR)$(testdir)/std_data/parts \
$(DESTDIR)$(testdir)/lib \
$(DESTDIR)$(testdir)/lib/My
$(INSTALL_DATA) $(srcdir)/README $(DESTDIR)$(testdir)
-$(INSTALL_DATA) $(srcdir)/t/*.def $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.test $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.imtest $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/t/*.sql $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.disabled $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.opt $(DESTDIR)$(testdir)/t
-$(INSTALL_SCRIPT) $(srcdir)/t/*.sh $(DESTDIR)$(testdir)/t
-$(INSTALL_DATA) $(srcdir)/t/*.slave-mi $(DESTDIR)$(testdir)/t
$(INSTALL_DATA) $(srcdir)/r/*.result $(DESTDIR)$(testdir)/r
$(INSTALL_DATA) $(srcdir)/r/*.require $(DESTDIR)$(testdir)/r
$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.test $(DESTDIR)$(testdir)/extra/binlog_tests
$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.test $(DESTDIR)$(testdir)/extra/rpl_tests
-$(INSTALL_DATA) $(srcdir)/extra/binlog_tests/*.opt $(DESTDIR)$(testdir)/extra/binlog_tests
-$(INSTALL_DATA) $(srcdir)/extra/rpl_tests/*.opt $(DESTDIR)$(testdir)/extra/rpl_tests
$(INSTALL_DATA) $(srcdir)/include/*.inc $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.sql $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/include/*.test $(DESTDIR)$(testdir)/include
$(INSTALL_DATA) $(srcdir)/std_data/*.dat $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.*001 $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/des_key_file $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Moscow_leap $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/Index.xml $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.pem $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.frm $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.MY* $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/*.cnf $(DESTDIR)$(testdir)/std_data
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup50/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup50
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup51
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_be/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup51_data_be
$(INSTALL_DATA) $(srcdir)/std_data/ndb_backup51_data_le/BACKUP* $(DESTDIR)$(testdir)/std_data/ndb_backup51_data_le
$(INSTALL_DATA) $(srcdir)/std_data/parts/part_* $(DESTDIR)$(testdir)/std_data/parts
$(INSTALL_DATA) $(srcdir)/lib/*.pl $(DESTDIR)$(testdir)/lib
$(INSTALL_DATA) $(srcdir)/lib/My/*.pm $(DESTDIR)$(testdir)/lib/My
for f in `(cd $(srcdir); find suite -type f | egrep -v 'SCCS|row_lock')`; \
for f in `(cd $(srcdir); find $(EXTRA_DIST) -type f)`; \
do \
d=$(DESTDIR)$(testdir)/`dirname $$f`; \
mkdir -p $$d ; \
......@@ -149,31 +54,5 @@ mysql-test-run:
$(RM) -f mysql-test-run
$(LN_S) mysql-test-run.pl mysql-test-run
SUFFIXES = .sh
.sh:
@RM@ -f $@ $@-t
@SED@ \
-e 's!@''testdir''@!$(testdir)!g' \
-e 's!@''bindir''@!$(bindir)!g' \
-e 's!@''scriptdir''@!$(bindir)!g' \
-e 's!@''prefix''@!$(prefix)!g' \
-e 's!@''datadir''@!$(datadir)!g' \
-e 's!@''localstatedir''@!$(localstatedir)!g' \
-e 's!@''libexecdir''@!$(libexecdir)!g' \
-e 's!@''PERL''@!@PERL@!' \
-e 's!@''VERSION''@!@VERSION@!' \
-e 's!@''MYSQL_TCP_PORT''@!@MYSQL_TCP_PORT@!' \
-e 's!@''MYSQL_TCP_PORT_DEFAULT''@!@MYSQL_TCP_PORT_DEFAULT@!' \
-e 's!@''MYSQL_BASE_VERSION''@!@MYSQL_BASE_VERSION@!' \
-e 's!@''MYSQL_UNIX_ADDR''@!@MYSQL_UNIX_ADDR@!' \
-e 's!@''MYSQL_TCP_PORT''@!@MYSQL_TCP_PORT@!' \
-e 's!@''MYSQL_NO_DASH_VERSION''@!@MYSQL_NO_DASH_VERSION@!' \
-e 's!@''MYSQL_SERVER_SUFFIX''@!@MYSQL_SERVER_SUFFIX@!' \
-e 's!@''USE_NDBCLUSTER''@!@TEST_NDBCLUSTER@!g' \
$< > $@-t
@CHMOD@ +x $@-t
@MV@ $@-t $@
# Don't update the files from bitkeeper
%::SCCS/s.%
#! /bin/sh
# This script is a hack for lazy developers who want to get a quick
# start on the result file. The code here is rather dirty, but it works
# If you have a spare moment feel free to improve it - the right way is
# to start mysqld yourself and run mysqltest -r
RESULT_DIR=r
if [ -z "$EDITOR" ] ; then
EDITOR=vi
fi
function die()
{
echo $1
exit 1
}
function usage()
{
echo "Usage: $0 test_name"
exit 1
}
test_name=$1
[ -z "$test_name" ] && usage
result_file=$RESULT_DIR/$test_name.result
reject_file=$RESULT_DIR/$test_name.reject
[ -f $result_file ] && die "result file $result_file has already been created"
touch $result_file
echo "Running the test case against empty file, will fail, but don't worry"
./mysql-test-run --local $test_name
if [ -f $reject_file ] ; then
echo "Below are the contents of the reject file:"
echo "-----start---------------------"
cat $reject_file
echo "-----end-----------------------"
echo "Is this the output you expected from your test case?(y/n)[n]"
read yes_no
if [ x$yes_no = xy ] ; then
echo "Press any key to edit it in $EDITOR, or Ctrl-C to abort"
read junk
$EDITOR $reject_file
edited="edited"
fi
echo "Save $edited file as master result? (y/n)[y]"
read yes_no
if [ x$yes_no != xn ]; then
mv $reject_file $result_file
fi
else
echo "Your test failed so bad, it did not even produce a reject file"
echo "You need to fix your bugs in the test case, the code, or both"
exit 1
fi
......@@ -7,7 +7,7 @@
-- source include/have_log_bin.inc
# The server need to be started in $MYSQLTEST_VARDIR since it
# uses ../std_data_ln/
# uses ../../std_data/
-- source include/uses_vardir.inc
--disable_warnings
......@@ -114,7 +114,7 @@ insert into t1 values(1);
insert ignore into t1 values(1);
replace into t1 values(100);
create table t2 (a varchar(200)) engine=blackhole;
eval load data infile '../std_data_ln/words.dat' into table t2;
eval load data infile '../../std_data/words.dat' into table t2;
alter table t1 add b int;
alter table t1 drop b;
create table t3 like t1;
......
......@@ -16,7 +16,8 @@ source include/show_binlog_events.inc;
# escaped).
flush logs;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
--exec $MYSQL_BINLOG --short-form $MYSQLTEST_VARDIR/log/master-bin.000001
let $MYSQLD_DATADIR= `select @@datadir`;
--exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001
drop table t2;
# End of 4.1 tests
......@@ -278,7 +278,7 @@ CREATE TABLE t5 (a int, PRIMARY KEY (a)) ENGINE=InnoDB;
# execute
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
load data infile '../../std_data/rpl_loaddata.dat' into table t4 (a, @b) set b= @b + bug27417(2);
# check
select * from t4;
select count(*) from t1 /* must be 2 */;
......
......@@ -20,7 +20,8 @@
eval create table t1 (a int) engine=$engine_type;
flush tables;
system rm $MYSQLTEST_VARDIR/master-data/test/t1.MYI ;
let $MYSQLD_DATADIR= `select @@datadir`;
system rm $MYSQLD_DATADIR/test/t1.MYI ;
drop table if exists t1;
save_master_pos;
connection slave;
......
......@@ -137,6 +137,8 @@ sync_slave_with_master;
select hex(c1), hex(c2) from t1;
connection master;
let $MYSQLD_DATADIR= `select @@datadir`;
--exec $MYSQL_BINLOG --short-form $MYSQLD_DATADIR/master-bin.000001
drop table t1;
sync_slave_with_master;
......
......@@ -23,12 +23,12 @@ connection master;
select last_insert_id();
create table t1(a int not null auto_increment, b int, primary key(a) );
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
# verify that LAST_INSERT_ID() is set by LOAD DATA INFILE
select last_insert_id();
create temporary table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60));
load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines;
load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by '\n##\n' starting by '>' ignore 1 lines;
create table t3 (day date,id int(9),category enum('a','b','c'),name varchar(60));
insert into t3 select * from t2;
......@@ -63,7 +63,7 @@ sync_with_master;
insert into t1 values(1,10);
connection master;
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
save_master_pos;
connection slave;
......@@ -87,7 +87,7 @@ connection master;
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
save_master_pos;
connection slave;
# The SQL slave thread should be stopped now.
......@@ -112,7 +112,7 @@ connection master;
set sql_log_bin=0;
delete from t1;
set sql_log_bin=1;
load data infile '../std_data_ln/rpl_loaddata.dat' into table t1;
load data infile '../../std_data/rpl_loaddata.dat' into table t1;
save_master_pos;
connection slave;
# The SQL slave thread should be stopped now.
......@@ -132,7 +132,7 @@ reset master;
eval create table t2 (day date,id int(9),category enum('a','b','c'),name varchar(60),
unique(day)) engine=$engine_type; # no transactions
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields
load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
'\n##\n' starting by '>' ignore 1 lines;
select * from t2;
......@@ -148,7 +148,7 @@ alter table t2 drop key day;
connection master;
delete from t2;
--error ER_DUP_ENTRY
load data infile '../std_data_ln/rpl_loaddata2.dat' into table t2 fields
load data infile '../../std_data/rpl_loaddata2.dat' into table t2 fields
terminated by ',' optionally enclosed by '%' escaped by '@' lines terminated by
'\n##\n' starting by '>' ignore 1 lines;
connection slave;
......@@ -162,7 +162,7 @@ drop table t1;
CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=INNODB;
--error ER_DUP_ENTRY
LOAD DATA INFILE "../std_data_ln/words.dat" INTO TABLE t1;
LOAD DATA INFILE "../../std_data/words.dat" INTO TABLE t1;
--disable_warnings
DROP TABLE IF EXISTS t1;
......
......@@ -32,8 +32,13 @@ reset master;
eval create table t1(n int not null auto_increment primary key)ENGINE=$engine_type;
insert into t1 values (NULL);
drop table t1;
let $LOAD_FILE= ../../std_data/words.dat;
if (!`SELECT length(load_file('$LOAD_FILE'))`){
let $LOAD_FILE= ../$LOAD_FILE;
}
eval create table t1 (word char(20) not null)ENGINE=$engine_type;
load data infile '../std_data_ln/words.dat' into table t1 ignore 1 lines;
--replace_result $LOAD_FILE LOAD_FILE
eval load data infile '$LOAD_FILE' into table t1 ignore 1 lines;
select count(*) from t1;
--replace_result $VERSION VERSION
--replace_column 2 # 5 #
......
let $LOAD_FILE= $MYSQLTEST_VARDIR/std_data/words.dat;
CREATE TABLE t1 (word CHAR(20) NOT NULL);
LOAD DATA INFILE '../std_data_ln/words.dat' INTO TABLE t1;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
eval LOAD DATA LOCAL INFILE '$MYSQL_TEST_DIR/std_data/words.dat' INTO TABLE t1;
--replace_result $LOAD_FILE LOAD_FILE
eval LOAD DATA INFILE '$LOAD_FILE' INTO TABLE t1;
--replace_result $LOAD_FILE LOAD_FILE
eval LOAD DATA INFILE '$LOAD_FILE' INTO TABLE t1;
SELECT * FROM t1 ORDER BY word LIMIT 10;
#
......
......@@ -2,7 +2,7 @@
-- source include/master-slave.inc
create table t1 (word char(20) not null);
load data infile '../std_data_ln/words.dat' into table t1;
load data infile '../../std_data/words.dat' into table t1;
--replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR
eval load data local infile '$MYSQL_TEST_DIR/std_data/words.dat' into table t1;
select * from t1 limit 10;
......
#! /bin/sh
# Sasha's hack to fix results generated with mysql-test-run --record
# to be version and test port independent. In some cases, further minor
# manual edititing may be required, but most of the time it should not
# happen
#It is assumed we are running the script in mysql-test directory
VERSION=4.0.1-alpha-debug-log
TEST_CASE=$1
if [ -z "$TEST_CASE" ] ;
then
echo "usage: $0 test_case_name"
exit 1
fi
../extra/replace $VERSION '$VERSION' 9306 '$MASTER_MYPORT' 9307 \
'$SLAVE_MYPORT' \\ \\\\ -- r/$TEST_CASE.result
#
# This test is executed twice for each test case if mysql-test-run is passed
# the flag --check-testcase.
# Before every testcase it's run with mysqltest in record mode and will
# thus produce an output file
# that can be compared to output from after the tescase.
# In that way it's possible to check that a testcase does not have
# the flag --check-testcase. Before every testcase it is run with mysqltest
# in record mode and will thus produce an output file that can be compared
# to output from after the tescase.
# In that way its possible to check that a testcase does not have
# any unwanted side affects.
#
#
# Dump all global variables
#
show global variables;
# Dump all global variables except those
# that are supposed to change
show global variables where Variable_name != 'timestamp';
#
# Dump all databases
#
# Dump all databases, there should be none
# except mysql, test and information_schema
show databases;
#
# Dump the "test" database, all it's tables and their data
#
--exec $MYSQL_DUMP --skip-comments --skip-lock-tables test
# The test database should not contain any tables
show tables from test;
#
# Dump the "mysql" database and it's tables
# Select data separately to add "order by"
#
--exec $MYSQL_DUMP --skip-comments --skip-lock-tables --no-data mysql
# Dump the "mysql" database and its tables
use mysql;
show tables;
show create table columns_priv;
show create table db;
show create table func;
show create table help_category;
show create table help_keyword;
show create table help_relation;
show create table help_relation;
show create table host;
show create table proc;
show create table procs_priv;
show create table tables_priv;
show create table time_zone;
show create table time_zone_leap_second;
show create table time_zone_name;
show create table time_zone_transition;
show create table time_zone_transition_type;
show create table user;
# Select data from system tables to make sure they have been properly
# restored after test
select * from columns_priv;
select * from db order by host, db, user;
select * from func;
......
# Use default setting for mysqld processes
!include default_mysqld.cnf
[mysqld.1]
# Run the master.sh script before starting this process
#!run-master-sh
log-bin= master-bin
[mysqlbinlog]
disable-force-if-open
# mysql_fix_privilege_tables.sh does not read from [client] so it
# need its own section
[mysql_fix_privilege_tables]
socket= @client.socket
port= @client.port
user= @client.user
password= @client.password
[ENV]
MASTER_MYPORT= @mysqld.1.port
MASTER_MYSOCK= @mysqld.1.socket
# Default values that applies to all MySQL Servers
[mysqld]
open-files-limit= 1024
local-infile
default-character-set= latin1
# Increase default connect_timeout to avoid intermittent
# disconnects when test servers are put under load see BUG#28359
connect-timeout= 60
log-bin-trust-function-creators=1
key_buffer_size= 1M
sort_buffer= 256K
max_heap_table_size= 1M
loose-innodb_data_file_path= ibdata1:10M:autoextend
set-variable= slave_net_timeout=120
log-bin
[cluster_config]
MaxNoOfSavedMessages= 1000
MaxNoOfConcurrentTransactions= 64
MaxNoOfConcurrentOperations= 10000
DataMemory= 20M
IndexMemory= 1M
Diskless= 0
TimeBetweenWatchDogCheck= 30000
MaxNoOfOrderedIndexes= 32
MaxNoOfAttributes= 2048
TimeBetweenGlobalCheckpoints= 500
NoOfFragmentLogFiles= 4
FragmentLogFileSize= 12M
DiskPageBufferMemory= 4M
# O_DIRECT has issues on 2.4 whach have not been handled, Bug #29612
#ODirect= 1
# the following parametes just function as a small regression
# test that the parameter exists
InitialNoOfOpenFiles= 27
# Increase timeouts for slow test-machines
HeartbeatIntervalDbDb= 30000
HeartbeatIntervalDbApi= 30000
#TransactionDeadlockDetectionTimeout= 7500
disable_query_log;
--require r/true.require
select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'blackhole';
enable_query_log;
if (!`SELECT count(*) FROM information_schema.engines WHERE
(support = 'YES' OR support = 'DEFAULT') AND
engine = 'blackhole'`){
skip Need blackhole engine;
}
#
# Check if the variable MYSQL_BUG25714 is set
#
--require r/have_bug25714.require
disable_query_log;
eval select LENGTH("$MYSQL_BUG25714") > 0 as "have_bug25714_exe";
enable_query_log;
disable_query_log;
--require r/true.require
select (support = 'YES' or support = 'DEFAULT') as `TRUE` from information_schema.engines where engine = 'federated';
enable_query_log;
--require r/have_ndbapi_examples.require
disable_query_log;
eval select LENGTH("$MY_NDB_EXAMPLES_BINARY") > 0 as "have_ndb_example";
eval select LENGTH("$NDB_EXAMPLES_BINARY") > 0 as "have_ndb_example";
enable_query_log;
......@@ -7,16 +7,20 @@ eval SET SESSION STORAGE_ENGINE = $engine_type;
drop table if exists t1;
--enable_warnings
let $load_file= $MYSQLTEST_VARDIR/std_data/loaddata2.dat;
# NDB does not support the create option 'Binlog of table with BLOB attribute and no PK'
# So use a dummy PK here.
create table t1 (id int unsigned not null auto_increment primary key, a text, b text);
start transaction;
load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''' (a, b);
--replace_result $load_file LOAD_FILE
eval load data infile '$load_file' into table t1 fields terminated by ',' enclosed by '''' (a, b);
commit;
select count(*) from t1;
truncate table t1;
start transaction;
load data infile '../std_data_ln/loaddata2.dat' into table t1 fields terminated by ',' enclosed by '''' (a, b);
--replace_result $load_file LOAD_FILE
eval load data infile '$load_file' into table t1 fields terminated by ',' enclosed by '''' (a, b);
rollback;
select count(*) from t1;
......
......@@ -623,7 +623,8 @@ DROP TABLE t1,t2,t3;
#
create table t1 (a int) engine=innodb;
copy_file $MYSQLTEST_VARDIR/master-data/test/t1.frm $MYSQLTEST_VARDIR/master-data/test/bug29807.frm;
let $MYSQLD_DATADIR= `select @@datadir`;
copy_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/bug29807.frm;
--error 1146
select * from bug29807;
drop table t1;
......
......@@ -2,23 +2,21 @@
# By JBM 2006-02-16 So that the code is not repeated #
# in test cases and can be reused. #
######################################################
--exec $NDB_MGM --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -e "start backup" >> $NDB_TOOLS_OUTPUT
--exec $NDB_MGM --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -e "start backup" >> $NDB_TOOLS_OUTPUT
# there is no neat way to find the backupid, this is a hack to find it...
let $dump_file= $MYSQLTEST_VARDIR/tmp/tmp.dat;
--exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="$NDB_CONNECTSTRING" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $dump_file
--exec $NDB_TOOLS_DIR/ndb_select_all --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -d sys --delimiter=',' SYSTAB_0 | grep 520093696 > $MYSQLTEST_VARDIR/tmp.dat
CREATE TEMPORARY TABLE test.backup_info (id INT, backup_id INT) ENGINE = HEAP;
CREATE TEMPORARY TABLE IF NOT EXISTS test.backup_info (id INT, backup_id INT) ENGINE = HEAP;
--replace_result $dump_file DUMP_FILE
eval LOAD DATA INFILE '$dump_file' INTO TABLE test.backup_info FIELDS TERMINATED BY ',';
DELETE FROM test.backup_info;
LOAD DATA INFILE '../tmp.dat' INTO TABLE test.backup_info FIELDS TERMINATED BY ',';
--replace_column 1 <the_backup_id>
SELECT @the_backup_id:=backup_id FROM test.backup_info;
# Load backup id into environment variable
let the_backup_id=`SELECT backup_id from test.backup_info`;
DROP TABLE test.backup_info;
let the_backup_id=`select @the_backup_id`;
remove_file $dump_file;
DROP TABLE test.backup_info;
......@@ -17,7 +17,7 @@ while ($mysql_errno)
{
if (!$counter)
{
die("Failed while waiting for mysqld to come out of readonly mode");
die Failed while waiting for mysqld to come out of readonly mode;
}
dec $counter;
--sleep 0.1
......
......@@ -3,6 +3,6 @@
# in test cases and can be reused. #
######################################################
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT" -p 8 -b $the_backup_id -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING" -p 8 -b $the_backup_id -n 2 -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
......@@ -3,9 +3,9 @@
# in test cases and can be reused. #
######################################################
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT_SLAVE" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING_SLAVE" -p 8 -b $the_backup_id -n 1 -m -r --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="localhost:$NDBCLUSTER_PORT_SLAVE" -p 8 -b $the_backup_id -n 2 -r -e --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
--exec $NDB_TOOLS_DIR/ndb_restore --no-defaults --ndb-connectstring="$NDB_CONNECTSTRING_SLAVE" -p 8 -b $the_backup_id -n 2 -r -e --print --print_meta $NDB_BACKUP_DIR/BACKUP/BACKUP-$the_backup_id >> $NDB_TOOLS_OUTPUT
......@@ -19,12 +19,6 @@
# #
###################################################################
--disable_query_log
eval set @USE_RUNNING_SERVER= '$USE_RUNNING_SERVER';
--require r/testdb_only.require
SELECT 'use extern server'
AS "Variable_name ",
IF(@USE_RUNNING_SERVER= '1','YES',
IF(@USE_RUNNING_SERVER= '0','NO','UNEXPECTED'))
AS "Value" ;
--enable_query_log
if ($USE_RUNNING_SERVER){
skip Not with extern server;
}
......@@ -32,7 +32,7 @@ let $wait_counter= 150;
while ($wait_counter)
{
let $result= `SHOW $show_type`;
let $success= `SELECT '$result' LIKE $show_pattern`;
let $success= `SELECT "$result" LIKE $show_pattern`;
if ($success)
{
let $wait_counter= 0;
......
#!/bin/sh
# Copyright (C) 1997-2006 MySQL AB
#
# 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This scripts creates the privilege tables db, host, user, tables_priv,
# columns_priv in the mysql database, as well as the func table.
if [ x$1 = x"--bin" ]; then
shift 1
BINARY_DIST=1
bindir=../bin
scriptdir=bin
libexecdir=../libexec
# Check if it's a binary distribution or a 'make install'
if test -x ../libexec/mysqld
then
execdir=../libexec
elif test -x ../../sbin/mysqld # RPM installation
then
execdir=../../sbin
bindir=../../bin
scriptdir=../bin
libexecdir=../../libexec
else
execdir=../bin
fi
fix_bin=mysql-test
else
execdir=../sql
bindir=../client
fix_bin=.
scriptdir=scripts
libexecdir=../libexec
fi
vardir=var
logdir=$vardir/log
if [ x$1 = x"-slave" ]
then
shift 1
data=var/slave-data
else
if [ x$1 = x"-1" ]
then
data=var/master-data1
else
data=var/master-data
fi
fi
ldata=$fix_bin/$data
mdata=$data/mysql
EXTRA_ARG=""
mysqld=
if test -x $execdir/mysqld
then
mysqld=$execdir/mysqld
else
if test ! -x $libexecdir/mysqld
then
echo "mysqld is missing - looked in $execdir and in $libexecdir"
exit 1
else
mysqld=$libexecdir/mysqld
fi
fi
# On IRIX hostname is in /usr/bsd so add this to the path
PATH=$PATH:/usr/bsd
hostname=`hostname` # Install this too in the user table
hostname="$hostname%" # Fix if not fully qualified hostname
#create the directories
[ -d $vardir ] || mkdir $vardir
[ -d $logdir ] || mkdir $logdir
# Create database directories mysql & test
if [ -d $data ] ; then rm -rf $data ; fi
mkdir $data $data/mysql $data/test
#for error messages
if [ x$BINARY_DIST = x1 ] ; then
basedir=..
else
basedir=.
EXTRA_ARG="--windows"
fi
INSTALL_CMD="$scriptdir/mysql_install_db --no-defaults $EXTRA_ARG --basedir=$basedir --datadir=mysql-test/$ldata --srcdir=."
echo "running $INSTALL_CMD"
cd ..
if $INSTALL_CMD
then
exit 0
else
echo "Error executing mysqld --bootstrap"
exit 1
fi
......@@ -4,6 +4,7 @@ package My::Config::Option;
use strict;
use warnings;
use Carp;
sub new {
......@@ -31,7 +32,7 @@ package My::Config::Group;
use strict;
use warnings;
use Carp;
sub new {
my ($class, $group_name)= @_;
......@@ -68,7 +69,7 @@ sub remove {
return undef unless defined $option;
# Remove from the hash
delete($self->{options_by_name}->{$option_name}) or die;
delete($self->{options_by_name}->{$option_name}) or croak;
# Remove from the array
@{$self->{options}}= grep { $_->name ne $option_name } @{$self->{options}};
......@@ -88,6 +89,33 @@ sub name {
return $self->{name};
}
sub suffix {
my ($self)= @_;
# Everything in name from the last .
my @parts= split(/\./, $self->{name});
my $suffix= pop(@parts);
return ".$suffix";
}
sub after {
my ($self, $prefix)= @_;
die unless defined $prefix;
# everything after $prefix
my $name= $self->{name};
if ($name =~ /^\Q$prefix\E(.*)$/)
{
return $1;
}
die "Failed to extract the value after '$prefix' in $name";
}
sub split {
my ($self)= @_;
# Return an array with name parts
return split(/\./, $self->{name});
}
#
# Return a specific option in the group
......@@ -100,23 +128,37 @@ sub option {
#
# Return a specific value for an option in the group
# Return value for an option in the group, fail if it does not exist
#
sub value {
my ($self, $option_name)= @_;
my $option= $self->option($option_name);
die "No option named '$option_name' in this group"
croak "No option named '$option_name' in group '$self->{name}'"
if ! defined($option);
return $option->value();
}
#
# Return value for an option if it exist
#
sub if_exist {
my ($self, $option_name)= @_;
my $option= $self->option($option_name);
return undef if ! defined($option);
return $option->value();
}
package My::Config;
use strict;
use warnings;
use Carp;
use IO::File;
use File::Basename;
......@@ -132,13 +174,13 @@ sub new {
my $self= bless { groups => [] }, $class;
my $F= IO::File->new($path, "<")
or die "Could not open '$path': $!";
or croak "Could not open '$path': $!";
while ( my $line= <$F> ) {
chomp($line);
# [group]
if ( $line =~ /\[(.*)\]/ ) {
if ( $line =~ /^\[(.*)\]/ ) {
# New group found
$group_name= $1;
#print "group: $group_name\n";
......@@ -149,7 +191,7 @@ sub new {
# Magic #! comments
elsif ( $line =~ /^#\!/) {
my $magic= $line;
die "Found magic comment '$magic' outside of group"
croak "Found magic comment '$magic' outside of group"
unless $group_name;
#print "$magic\n";
......@@ -171,8 +213,13 @@ sub new {
# !include <filename>
elsif ( $line =~ /^\!include\s*(.*?)\s*$/ ) {
my $include_file_name= dirname($path)."/".$1;
# Check that the file exists
die "The include file '$include_file_name' does not exist"
# Check that the file exists relative to path of first config file
if (! -f $include_file_name){
# Try to include file relativ to current dir
$include_file_name= $1;
}
croak "The include file '$include_file_name' does not exist"
unless -f $include_file_name;
$self->append(My::Config->new($include_file_name));
......@@ -182,7 +229,7 @@ sub new {
elsif ( $line =~ /^([\@\w-]+)\s*$/ ) {
my $option= $1;
die "Found option '$option' outside of group"
croak "Found option '$option' outside of group"
unless $group_name;
#print "$option\n";
......@@ -194,13 +241,13 @@ sub new {
my $option= $1;
my $value= $2;
die "Found option '$option=$value' outside of group"
croak "Found option '$option=$value' outside of group"
unless $group_name;
#print "$option=$value\n";
$self->insert($group_name, $option, $value);
} else {
die "Unexpected line '$line' found in '$path'";
croak "Unexpected line '$line' found in '$path'";
}
}
......@@ -231,6 +278,7 @@ sub insert {
# Add the option to the group
$group->insert($option, $value, $if_not_exist);
}
return $group;
}
#
......@@ -240,11 +288,11 @@ sub remove {
my ($self, $group_name, $option_name)= @_;
my $group= $self->group($group_name);
die "group '$group_name' does not exist"
croak "group '$group_name' does not exist"
unless defined($group);
$group->remove($option_name) or
die "option '$option_name' does not exist";
croak "option '$option_name' does not exist";
}
......@@ -267,10 +315,10 @@ sub group_exists {
#
sub _group_insert {
my ($self, $group_name)= @_;
caller eq __PACKAGE__ or die;
caller eq __PACKAGE__ or croak;
# Check that group does not already exist
die "Group already exists" if $self->group_exists($group_name);
croak "Group already exists" if $self->group_exists($group_name);
my $group= My::Config::Group->new($group_name);
push(@{$self->{groups}}, $group);
......@@ -354,11 +402,11 @@ sub value {
my ($self, $group_name, $option_name)= @_;
my $group= $self->group($group_name);
die "group '$group_name' does not exist"
croak "group '$group_name' does not exist"
unless defined($group);
my $option= $group->option($option_name);
die "option '$option_name' does not exist"
croak "option '$option_name' does not exist"
unless defined($option);
return $option->value();
......@@ -372,7 +420,7 @@ sub exists {
my ($self, $group_name, $option_name)= @_;
my $group= $self->group($group_name);
die "group '$group_name' does not exist"
croak "group '$group_name' does not exist"
unless defined($group);
my $option= $group->option($option_name);
......@@ -414,7 +462,7 @@ sub stringify {
sub save {
my ($self, $path)= @_;
my $F= IO::File->new($path, ">")
or die "Could not open '$path': $!";
or croak "Could not open '$path': $!";
print $F $self;
undef $F; # Close the file
}
......
This diff is collapsed.
# -*- cperl -*-
package My::File::Path;
use strict;
#
# File::Path::rmtree has a problem with deleting files
# and directories where it hasn't got read permission
#
# Patch this by installing a 'rmtree' function in local
# scope that first chmod all files to 0777 before calling
# the original rmtree function.
#
# This is almost gone in version 1.08 of File::Path -
# but unfortunately some hosts still suffers
# from this also in 1.08
#
use Exporter;
use base "Exporter";
our @EXPORT= qw / rmtree mkpath copytree /;
use File::Find;
use File::Path;
use File::Copy;
use Carp;
no warnings 'redefine';
sub rmtree {
my ($dir)= @_;
#
# chmod all files to 0777 before calling rmtree
#
find( {
no_chdir => 1,
wanted => sub {
chmod(0777, $_)
or warn("couldn't chmod(0777, $_): $!");
}
},
$dir
);
# Call rmtree from File::Path
goto &File::Path::rmtree;
};
sub mkpath {
goto &File::Path::mkpath;
};
sub copytree {
my ($from_dir, $to_dir) = @_;
die "Usage: copytree(<fromdir>, <todir>" unless @_ == 2;
mkpath("$to_dir");
opendir(DIR, "$from_dir")
or croak("Can't find $from_dir$!");
for(readdir(DIR)) {
next if "$_" eq "." or "$_" eq "..";
# Skip SCCS/ directories
next if "$_" eq "SCCS";
if ( -d "$from_dir/$_" )
{
copytree("$from_dir/$_", "$to_dir/$_");
next;
}
copy("$from_dir/$_", "$to_dir/$_");
}
closedir(DIR);
}
1;
# -*- cperl -*-
# Copyright (C) 2004-2006 MySQL AB
#
# 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package My::Find;
#
# Utility functions to find files in a MySQL source or bindist
#
use strict;
use Carp;
use My::Platform;
use base qw(Exporter);
our @EXPORT= qw(my_find_bin my_find_dir);
our $vs_config_dir;
my $bin_extension= ".exe" if IS_WINDOWS;
#
# my_find_bin - find an executable with "name_1...name_n" in
# paths "path_1...path_n" and return the full path
#
# Example:
# my $mysqld_exe= my_find_bin($basedir.
# ["sql", "bin"],
# ["mysqld", "mysqld-debug"]);
# my $mysql_exe= my_find_bin($basedir,
# ["client", "bin"],
# "mysql");
#
# NOTE: The function honours MTR_VS_CONFIG environment variable
#
#
sub my_find_bin {
my ($base, $paths, $names)= @_;
croak "usage: my_find_bin(<base>, <paths>, <names>)"
unless @_ == 3;
# -------------------------------------------------------
# Find and return the first executable
# -------------------------------------------------------
foreach my $path (my_find_paths($base, $paths, $names, $bin_extension)) {
return $path if ( -x $path or (IS_WINDOWS and -f $path) );
}
find_error($base, $paths, $names);
}
#
# my_find_dir - find the first existing directory in one of
# the given paths
#
# Example:
# my $charset_set= my_find_dir($basedir,
# ["mysql/share","sql/share", "share"],
# ["charset"]);
# or
# my $charset_set= my_find_dir($basedir,
# ['client_release', 'client_debug',
# 'client', 'bin']);
#
# NOTE: The function honours MTR_VS_CONFIG environment variable
#
#
sub my_find_dir {
my ($base, $paths, $dirs)= @_;
croak "usage: my_find_dir(<base>, <paths>[, <dirs>])"
unless (@_ == 3 or @_ == 2);
# -------------------------------------------------------
# Find and return the first directory
# -------------------------------------------------------
foreach my $path (my_find_paths($base, $paths, $dirs)) {
return $path if ( -d $path );
}
find_error($base, $paths, $dirs);
}
sub my_find_paths {
my ($base, $paths, $names, $extension)= @_;
# Convert the arguments into two normal arrays to ease
# further mappings
my (@names, @paths);
push(@names, ref $names eq "ARRAY" ? @$names : $names);
push(@paths, ref $paths eq "ARRAY" ? @$paths : $paths);
#print "base: $base\n";
#print "names: @names\n";
#print "paths: @paths\n";
# User can select to look in a special build dir
# which is a subdirectory of any of the paths
my @extra_dirs;
my $build_dir= $vs_config_dir || $ENV{MTR_VS_CONFIG} || $ENV{MTR_BUILD_DIR};
push(@extra_dirs, $build_dir) if defined $build_dir;
if (defined $extension){
# Append extension to names, if name does not already have extension
map { $_.=$extension unless /\.(.*)+$/ } @names;
}
# -------------------------------------------------------
# Windows specific
# -------------------------------------------------------
if (IS_WINDOWS) {
# Add the default extra build dirs unless a specific one has
# already been selected
push(@extra_dirs,
("release",
"relwithdebinfo",
"debug")) if @extra_dirs == 0;
}
#print "extra_build_dir: @extra_dirs\n";
# -------------------------------------------------------
# Build cross product of "paths * extra_build_dirs"
# -------------------------------------------------------
push(@paths, map { my $path= $_;
map { "$path/$_" } @extra_dirs
} @paths);
#print "paths: @paths\n";
# -------------------------------------------------------
# Build cross product of "paths * names"
# -------------------------------------------------------
@paths= map { my $path= $_;
map { "$path/$_" } @names
} @paths;
#print "paths: @paths\n";
# -------------------------------------------------------
# Prepend base to all paths
# -------------------------------------------------------
@paths= map { "$base/$_" } @paths;
#print "paths: @paths\n";
# -------------------------------------------------------
# Return the list of paths
# -------------------------------------------------------
return @paths;
}
sub commify {
return
(@_ == 0) ? '' :
(@_ == 1) ? $_[0] :
(@_ == 2) ? join(" or ", @_) :
join(", ", @_[0..($#_-1)], "or $_[-1]");
}
sub fnuttify {
return map('\''.$_.'\'', @_);
}
sub find_error {
my ($base, $paths, $names)= @_;
my (@names, @paths);
push(@names, ref $names eq "ARRAY" ? @$names : $names);
push(@paths, ref $paths eq "ARRAY" ? @$paths : $paths);
croak "** ERROR: Could not find ",
commify(fnuttify(@names)), " in ",
commify(fnuttify(my_find_paths($base, $paths, $names))), "\n";
}
1;
# -*- cperl -*-
# Copyright (C) 2004-2006 MySQL AB
#
# 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package My::Options;
#
# Utility functions to work with list of options
#
use strict;
sub same($$) {
my $l1= shift;
my $l2= shift;
return compare($l1,$l2) == 0;
}
sub compare ($$) {
my $l1= shift;
my $l2= shift;
my @l1= @$l1;
my @l2= @$l2;
return -1 if @l1 < @l2;
return 1 if @l1 > @l2;
while ( @l1 ) # Same length
{
my $e1= shift @l1;
my $e2= shift @l2;
my $cmp= ($e1 cmp $e2);
return $cmp if $cmp != 0;
}
return 0; # They are the same
}
sub _split_option {
my ($option)= @_;
if ($option=~ /^--(.*)=(.*)$/){
return ($1, $2);
}
elsif ($option=~ /^--(.*)$/){
return ($1, undef)
}
elsif ($option=~ /^(.*)=(.*)$/){
return ($1, $2)
}
elsif ($option=~ /^-O$/){
return (undef, undef);
}
die "Unknown option format '$option'";
}
sub _build_option {
my ($name, $value)= @_;
if ($name =~ /^O, /){
return "-".$name."=".$value;
}
elsif ($value){
return "--".$name."=".$value;
}
return "--".$name;
}
#
# Compare two list of options and return what would need
# to be done to get the server running with the new settings
#
sub diff {
my ($from_opts, $to_opts)= @_;
my %from;
foreach my $from (@$from_opts)
{
my ($opt, $value)= _split_option($from);
next unless defined($opt);
$from{$opt}= $value;
}
#print "from: ", %from, "\n";
my %to;
foreach my $to (@$to_opts)
{
my ($opt, $value)= _split_option($to);
next unless defined($opt);
$to{$opt}= $value;
}
#print "to: ", %to, "\n";
# Remove the ones that are in both lists
foreach my $name (keys %from){
if (exists $to{$name} and $to{$name} eq $from{$name}){
#print "removing '$name' from both lists\n";
delete $to{$name};
delete $from{$name};
}
}
#print "from: ", %from, "\n";
#print "to: ", %to, "\n";
# Add all keys in "to" to result
my @result;
foreach my $name (keys %to){
push(@result, _build_option($name, $to{$name}));
}
# Add all keys in "from" that are not in "to"
# to result as "set to default"
foreach my $name (keys %from){
if (not exists $to{$name}) {
push(@result, _build_option($name, "default"));
}
}
return @result;
}
sub is_set {
my ($opts, $set_opts)= @_;
foreach my $opt (@$opts){
my ($opt_name1, $value1)= _split_option($opt);
foreach my $set_opt (@$set_opts){
my ($opt_name2, $value2)= _split_option($set_opt);
if ($opt_name1 eq $opt_name2){
# Option already set
return 1;
}
}
}
return 0;
}
sub toSQL {
my (@options)= @_;
my @sql;
foreach my $option (@options) {
my ($name, $value)= _split_option($option);
#print "name: $name\n";
#print "value: $value\n";
if ($name =~ /^O, (.*)/){
push(@sql, "SET GLOBAL $1=$value");
}
elsif ($name =~ /^set-variable=(.*)/){
push(@sql, "SET GLOBAL $1=$value");
}
else {
my $sql_name= $name;
$sql_name=~ s/-/_/g;
push(@sql, "SET GLOBAL $sql_name=$value");
}
}
return join("; ", @sql);
}
sub toStr {
my $name= shift;
return "$name: ",
"['", join("', '", @_), "']\n";
}
1;
# -*- cperl -*-
# Copyright (C) 2004-2006 MySQL AB
#
# 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
package My::Platform;
use strict;
use base qw(Exporter);
our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL
native_path posix_path mixed_path);
BEGIN {
if ($^O eq "cygwin") {
# Make sure cygpath works
if ((system("cygpath > /dev/null 2>&1") >> 8) != 1){
die "Could not execute 'cygpath': $!";
}
eval 'sub IS_CYGWIN { 1 }';
}
else {
eval 'sub IS_CYGWIN { 0 }';
}
if ($^O eq "MSWin32") {
eval 'sub IS_WIN32PERL { 1 }';
}
else {
eval 'sub IS_WIN32PERL { 0 }';
}
}
BEGIN {
if (IS_CYGWIN or IS_WIN32PERL) {
eval 'sub IS_WINDOWS { 1 }';
}
else {
eval 'sub IS_WINDOWS { 0 }';
}
}
#
# native_path
# Convert from path format used by perl to the underlying
# operating systems format
#
# NOTE
# Used when running windows binaries (that expect windows paths)
# in cygwin perl (that uses unix paths)
#
sub mixed_path {
my ($path)= @_;
if (IS_CYGWIN){
return unless defined $path;
$path= `cygpath -m $path`;
chomp $path;
}
return $path;
}
sub native_path {
my ($path)= @_;
$path=~ s/\//\\/g
if (IS_CYGWIN or IS_WIN32PERL);
return $path;
}
sub posix_path {
my ($path)= @_;
if (IS_CYGWIN){
return unless defined $path;
$path= `cygpath $path`;
chomp $path;
}
return $path;
}
1;
This diff is collapsed.
# -*- cperl -*-
# Copyright (C) 2004-2006 MySQL AB
#
# 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This is a library file used by the Perl version of mysql-test-run,
# and is part of the translation of the Bourne shell script with the
# same name.
use strict;
package My::SafeProcess::Base;
#
# Utility functions for Process management
#
use Carp;
use IO::Pipe;
use base qw(Exporter);
our @EXPORT= qw(create_process);
sub winpid {
my ($pid)= @_;
return undef unless $^O eq "cygwin";
# The child get a new winpid when the exec takes
# place, wait for that to happen
my $winpid;
my $delay= 0;
do
{
# Yield to the child
select(undef, undef, undef, $delay);
# Increase the delay slightly for each loop
$delay += 0.000001;
$winpid= Cygwin::pid_to_winpid($pid);
} until ($winpid != $pid);
return $winpid;
}
#
# safe_fork
# Retry a couple of times if fork returns EAGAIN
#
sub _safe_fork {
my $retries= 5;
my $pid;
FORK:
{
$pid= fork;
if ( not defined($pid)) {
croak("fork failed after: $!") if (!$retries--);
warn("fork failed sleep 1 second and redo: $!");
sleep(1);
redo FORK;
}
}
return $pid;
};
#
# Decode exit status
#
sub exit_status {
my $self= shift;
my $raw= $self->{EXIT_STATUS};
croak("Can't call exit_status before process has died")
unless defined $raw;
if ($raw & 127)
{
# Killed by signal
my $signal_num= $raw & 127;
my $dumped_core= $raw & 128;
return 1; # Return error code
}
else
{
# Normal process exit
return $raw >> 8;
};
}
#
# Create a new process
# Return pid of the new process
#
sub create_process {
my %opts=
(
@_
);
my $path = delete($opts{'path'}) or die "path required";
my $args = delete($opts{'args'}) or die "args required";
my $input = delete($opts{'input'});
my $output = delete($opts{'output'});
my $error = delete($opts{'error'});
my $open_mode= $opts{append} ? ">>" : ">";
if ($^O eq "MSWin32"){
#printf STDERR "stdin %d, stdout %d, stderr %d\n",
# fileno STDIN, fileno STDOUT, fileno STDERR;
# input output redirect
my ($oldin, $oldout, $olderr);
open $oldin, '<&', \*STDIN or die "Failed to save old stdin: $!";
open $oldout, '>&', \*STDOUT or die "Failed to save old stdout: $!";
open $olderr, '>&', \*STDERR or die "Failed to save old stderr: $!";
if ( $input ) {
if ( ! open(STDIN, "<", $input) ) {
croak("can't redirect STDIN to '$input': $!");
}
}
if ( $output ) {
if ( ! open(STDOUT, $open_mode, $output) ) {
croak("can't redirect STDOUT to '$output': $!");
}
}
if ( $error ) {
if ( $output eq $error ) {
if ( ! open(STDERR, ">&STDOUT") ) {
croak("can't dup STDOUT: $!");
}
}
elsif ( ! open(STDERR, $open_mode, $error) ) {
croak("can't redirect STDERR to '$error': $!");
}
}
# Magic use of 'system(1, @args)' to spawn a process
# and get a proper Win32 pid
unshift (@$args, $path);
my $pid= system(1, @$args);
if ( $pid == 0 ){
print $olderr "create_process failed: $^E\n";
die "create_process failed: $^E";
}
# Retore IO redirects
open STDERR, '>&', $olderr
or croak("unable to reestablish STDERR");
open STDOUT, '>&', $oldout
or croak("unable to reestablish STDOUT");
open STDIN, '<&', $oldin
or croak("unable to reestablish STDIN");
#printf STDERR "stdin %d, stdout %d, stderr %d\n",
# fileno STDIN, fileno STDOUT, fileno STDERR;
return wantarray ? ($pid, $pid) : $pid;
}
local $SIG{PIPE}= sub { print STDERR "Got signal $@\n"; };
my $pipe= IO::Pipe->new();
my $pid= _safe_fork();
if ($pid){
# Parent
$pipe->reader();
my $line= <$pipe>; # Wait for child to say it's ready
return wantarray ? ($pid, winpid($pid)) : $pid;
}
$SIG{INT}= 'DEFAULT';
# Make this process it's own process group to be able to kill
# it and any childs(that hasn't changed group themself)
setpgrp(0,0) if $opts{setpgrp};
if ( $output and !open(STDOUT, $open_mode, $output) ) {
croak("can't redirect STDOUT to '$output': $!");
}
if ( $error ) {
if ( defined $output and $output eq $error ) {
if ( ! open(STDERR, ">&STDOUT") ) {
croak("can't dup STDOUT: $!");
}
}
elsif ( ! open(STDERR, $open_mode, $error) ) {
croak("can't redirect STDERR to '$error': $!");
}
}
if ( $input ) {
if ( ! open(STDIN, "<", $input) ) {
croak("can't redirect STDIN to '$input': $!");
}
}
# Tell parent to continue
$pipe->writer();
print $pipe "ready\n";
if ( !exec($path, @$args) ){
croak("Failed to exec '$path': $!");
}
croak("Should never come here");
}
1;
# Copyright (C) 2006 MySQL AB
#
# 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
ADD_EXECUTABLE(my_safe_process safe_process_win.cc)
ADD_EXECUTABLE(my_safe_kill safe_kill_win.cc)
# Copyright (C) 2000-2006 MySQL AB
#
# 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
bin_PROGRAMS = my_safe_process
my_safe_process_SOURCES = safe_process.cc
# Don't update the files from bitkeeper
%::SCCS/s.%
/* Copyright (C) 2004 MySQL AB
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
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
Utility program used to signal a safe_process it's time to shutdown
Usage:
safe_kill <pid>
*/
#include <windows.h>
#include <stdio.h>
int main(int argc, const char** argv )
{
DWORD pid= -1;
HANDLE shutdown_event;
char safe_process_name[32]= {0};
if (argc != 2) {
fprintf(stderr, "safe_kill <pid>\n");
exit(2);
}
pid= atoi(argv[1]);
_snprintf(safe_process_name, sizeof(safe_process_name), "safe_process[%d]", pid);
/* Open the event to signal */
if ((shutdown_event=
OpenEvent(EVENT_MODIFY_STATE, FALSE, safe_process_name)) == NULL){
fprintf(stderr, "Failed to open shutdown_event\n");
exit(1);
}
if(SetEvent(shutdown_event) == 0) {
fprintf(stderr, "Failed to signal shutdown_event\n");
CloseHandle(shutdown_event);
exit(1);
}
CloseHandle(shutdown_event);
exit(0);
}
/* Copyright (C) 2008 MySQL AB
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
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
Utility program that encapsulates process creation, monitoring
and bulletproof process cleanup
Usage:
safe_process [options to safe_process] -- progname arg1 ... argn
To safeguard mysqld you would invoke safe_process with a few options
for safe_process itself followed by a double dash to indicate start
of the command line for the program you really want to start
$> safe_process --output=output.log -- mysqld --datadir=var/data1 ...
This would redirect output to output.log and then start mysqld,
once it has done that it will continue to monitor the child as well
as the parent.
The safe_process then checks the follwing things:
1. Child exits, propagate the childs return code to the parent
by exiting with the same return code as the child.
2. Parent dies, immediately kill the child and exit, thus the
parent does not need to properly cleanup any child, it is handled
automatically.
3. Signal's recieced by the process will trigger same action as 2)
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
int verbose= 0;
int terminated= 0;
pid_t child_pid= -1;
char safe_process_name[32]= {0};
static void message(const char* fmt, ...)
{
if (!verbose)
return;
va_list args;
fprintf(stderr, "%s: ", safe_process_name);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
fflush(stderr);
}
static void die(const char* fmt, ...)
{
va_list args;
fprintf(stderr, "%s: FATAL ERROR, ", safe_process_name);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
if (int last_err= errno)
fprintf(stderr, "error: %d, %s\n", last_err, strerror(last_err));
exit(1);
}
static void kill_child (void)
{
int exit_code= 1;
int status= 0;
message("Killing child: %d", child_pid);
// Terminate whole process group
kill(-child_pid, SIGKILL);
pid_t ret_pid= waitpid(child_pid, &status, 0);
if (ret_pid == child_pid)
{
if (WIFEXITED(status))
{
// Process has exited, collect return status
exit_code= WEXITSTATUS(status);
message("Child exit: %d", exit_code);
// Exit with exit status of the child
exit(exit_code);
}
if (WIFSIGNALED(status))
message("Child killed by signal: %d", WTERMSIG(status));
exit(exit_code);
}
exit(exit_code);
}
static void handle_signal (int sig)
{
message("Got signal %d, child_pid: %d", sig, child_pid);
terminated= 1;
// Ignore further signals
signal(SIGTERM, SIG_IGN);
signal(SIGINT, SIG_IGN);
signal(SIGCHLD, SIG_IGN);
if (child_pid > 0)
kill_child();
// Continune execution, allow the child to be started and
// finally terminated by monitor loop
}
int main(int argc, char* const argv[] )
{
char* const* child_argv= 0;
pid_t own_pid= getpid();
pid_t parent_pid= getppid();
/* Install signal handlers */
signal(SIGTERM, handle_signal);
signal(SIGINT, handle_signal);
signal(SIGCHLD, handle_signal);
sprintf(safe_process_name, "safe_process[%d]", own_pid);
message("Started");
/* Parse arguments */
for (int i= 1; i < argc; i++) {
const char* arg= argv[i];
if (strcmp(arg, "--") == 0 && strlen(arg) == 2) {
/* Got the "--" delimiter */
if (i >= argc)
die("No real args -> nothing to do");
child_argv= &argv[i+1];
break;
} else {
if ( strcmp(arg, "--verbose") == 0 )
verbose++;
else if ( strncmp(arg, "--parent-pid", 10) == 0 )
{
/* Override parent_pid with a value provided by user */
const char* start;
if ((start= strstr(arg, "=")) == NULL)
die("Could not find start of option value in '%s'", arg);
start++; /* Step past = */
if ((parent_pid= atoi(start)) == 0)
die("Invalid value '%s' passed to --parent-id", start);
}
else
die("Unknown option: %s", arg);
}
}
if (!child_argv || *child_argv == 0)
die("nothing to do");
message("parent_pid: %d", parent_pid);
if (parent_pid == own_pid)
die("parent_pid is equal to own pid!");
char buf;
int pfd[2];
if (pipe(pfd) == -1)
die("Failed to create pipe");
/* Create the child process */
while((child_pid= fork()) == -1)
{
message("fork failed");
sleep(1);
}
if (child_pid == 0)
{
close(pfd[0]); // Close unused read end
// Use default signal handlers in child
signal(SIGTERM, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
// Make this process it's own process group to be able to kill
// it and any childs(that hasn't changed group themself)
setpgid(0, 0);
// Signal that child is ready
buf= 37;
write(pfd[1], &buf, 1);
// Close write end
close(pfd[1]);
if (execvp(child_argv[0], child_argv) < 0)
die("Failed to exec child");
}
close(pfd[1]); // Close unused write end
// Wait for child to signal it's ready
read(pfd[0], &buf, 1);
if(buf != 37)
die("Didn't get 37 from pipe");
close(pfd[0]); // Close read end
/* Monitor loop */
message("Started child %d, terminated: %d", child_pid, terminated);
while(!terminated)
{
// Check if parent is still alive
if (kill(parent_pid, 0) != 0){
message("Parent is not alive anymore");
break;
}
// Check if child has exited, normally this wil be
// detected immediately with SIGCHLD handler
int status= 0;
pid_t ret_pid= waitpid(child_pid, &status, WNOHANG);
if (ret_pid == child_pid)
{
int ret_code= 2;
if (WIFEXITED(status))
{
// Process has exited, collect return status
int ret_code= WEXITSTATUS(status);
message("Child exit: %d", ret_code);
// Exit with exit status of the child
exit(ret_code);
}
if (WIFSIGNALED(status))
message("Child killed by signal: %d", WTERMSIG(status));
exit(ret_code);
}
sleep(1);
}
kill_child();
exit(1);
}
#!/usr/bin/perl
# -*- cperl -*-
use strict;
use warnings;
use lib 'lib';
use My::SafeProcess::Base;
use POSIX qw(WNOHANG);
###########################################################################
# Util functions
###########################################################################
#
#Print message to stderr
#
my $verbose= 0;
sub message {
if ($verbose > 0){
use Time::localtime;
my $tm= localtime();
my $timestamp= sprintf("%02d%02d%02d %2d:%02d:%02d",
$tm->year % 100, $tm->mon+1, $tm->mday,
$tm->hour, $tm->min, $tm->sec);
print STDERR $timestamp, " monitor[$$]: ", @_, "\n";
}
}
###########################################################################
# Main program
###########################################################################
my $terminated= 0;
# Protect against being killed in the middle
# of child creation, just set the terminated flag
# to make sure the child will be killed off
# when program is ready to do that
$SIG{TERM}= sub { message("!Got signal @_"); $terminated= 1; };
$SIG{INT}= sub { message("!Got signal @_"); $terminated= 1; };
my $parent_pid= getppid();
my $found_double_dash= 0;
while (my $arg= shift(@ARGV)){
if ($arg =~ /^--$/){
$found_double_dash= 1;
last;
}
elsif ($arg =~ /^--verbose$/){
$verbose= 1;
}
else {
die "Unknown option: $arg";
}
}
my $path= shift(@ARGV); # Executable
die "usage:\n" .
" safe_process.pl [opts] -- <path> [<args> [...<args_n>]]"
unless defined $path || $found_double_dash;
message("started");
#message("path: '$path'");
message("parent: $parent_pid");
# Start process to monitor
my $child_pid=
create_process(
path => $path,
args => \@ARGV,
setpgrp => 1,
);
message("Started child $child_pid");
eval {
sub handle_signal {
$terminated= 1;
message("Got signal @_");
# Ignore all signals
foreach my $name (keys %SIG){
$SIG{$name}= 'IGNORE';
}
die "signaled\n";
};
local $SIG{TERM}= \&handle_signal;
local $SIG{INT}= \&handle_signal;
local $SIG{CHLD}= sub {
message("Got signal @_");
kill(9, -$child_pid);
my $ret= waitpid($child_pid, 0);
if ($? & 127){
exit(65); # Killed by signal
}
exit($? >> 8);
};
# Monitoring loop
while(!$terminated) {
# Check if parent is still alive
if (kill(0, $parent_pid) < 1){
message("Parent is not alive anymore");
last;
}
# Wait for child to terminate but wakeup every
# second to also check that parent is still alive
my $ret_pid;
$ret_pid= waitpid($child_pid, &WNOHANG);
if ($ret_pid == $child_pid) {
# Process has exited, collect return status
my $ret_code= $? >> 8;
message("Child exit: $ret_code");
# Exit with exit status of the child
exit ($ret_code);
}
sleep(1);
}
};
if ( $@ ) {
# The monitoring loop should have been
# broken by handle_signal
warn "Unexpected: $@" unless ( $@ =~ /signaled/ );
}
# Use negative pid in order to kill the whole
# process group
#
my $ret= kill(9, -$child_pid);
message("Killed child: $child_pid, ret: $ret");
if ($ret > 0) {
message("Killed child: $child_pid");
# Wait blocking for the child to return
my $ret_pid= waitpid($child_pid, 0);
if ($ret_pid != $child_pid){
message("unexpected pid $ret_pid returned from waitpid($child_pid)");
}
}
message("DONE!");
exit (1);
/* Copyright (C) 2004 MySQL AB
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
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/*
Utility program that encapsulates process creation, monitoring
and bulletproof process cleanup
Usage:
safe_process [options to safe_process] -- progname arg1 ... argn
To safeguard mysqld you would invoke safe_process with a few options
for safe_process itself followed by a double dash to indicate start
of the command line for the program you really want to start
$> safe_process --output=output.log -- mysqld --datadir=var/data1 ...
This would redirect output to output.log and then start mysqld,
once it has done that it will continue to monitor the child as well
as the parent.
The safe_process then checks the follwing things:
1. Child exits, propagate the childs return code to the parent
by exiting with the same return code as the child.
2. Parent dies, immediately kill the child and exit, thus the
parent does not need to properly cleanup any child, it is handled
automatically.
3. Signal's recieced by the process will trigger same action as 2)
4. The named event "safe_process[pid]" can be signaled and will
trigger same action as 2)
WARNING! Be careful when using ProcessExplorer, since it will open
a handle to each process(and maybe also the Job), the process
spawned by safe_process will not be closed off when safe_process
is killed.
*/
/* Requires Windows 2000 or higher */
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <stdio.h>
#include <tlhelp32.h>
#include <signal.h>
static int verbose= 0;
static char safe_process_name[32]= {0};
static void message(const char* fmt, ...)
{
if (!verbose)
return;
va_list args;
fprintf(stderr, "%s: ", safe_process_name);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
fflush(stderr);
}
static void die(const char* fmt, ...)
{
va_list args;
fprintf(stderr, "%s: FATAL ERROR, ", safe_process_name);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
if (int last_err= GetLastError())
fprintf(stderr, "error: %d, %s\n", last_err, strerror(last_err));
exit(1);
}
DWORD get_parent_pid(DWORD pid)
{
HANDLE snapshot;
DWORD parent_pid= -1;
PROCESSENTRY32 pe32;
pe32.dwSize= sizeof(PROCESSENTRY32);
snapshot= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE)
die("CreateToolhelp32Snapshot failed");
if (!Process32First(snapshot, &pe32))
{
CloseHandle(snapshot);
die("Process32First failed");
}
do
{
if (pe32.th32ProcessID == pid)
parent_pid= pe32.th32ParentProcessID;
} while(Process32Next( snapshot, &pe32));
CloseHandle(snapshot);
if (parent_pid == -1)
die("Could not find parent pid");
return parent_pid;
}
enum {
PARENT,
CHILD,
EVENT,
NUM_HANDLES
};
HANDLE shutdown_event;
void handle_signal (int signal)
{
message("Got signal: %d", signal);
if(SetEvent(shutdown_event) == 0) {
/* exit safe_process and (hopefully) kill off the child */
die("Failed to SetEvent");
}
}
int main(int argc, const char** argv )
{
char child_args[4096]= {0};
DWORD pid= GetCurrentProcessId();
DWORD parent_pid= get_parent_pid(pid);
HANDLE job_handle;
HANDLE wait_handles[NUM_HANDLES]= {0};
PROCESS_INFORMATION process_info= {0};
sprintf(safe_process_name, "safe_process[%d]", pid);
/* Create an event for the signal handler */
if ((shutdown_event=
CreateEvent(NULL, TRUE, FALSE, safe_process_name)) == NULL)
die("Failed to create shutdown_event");
wait_handles[EVENT]= shutdown_event;
signal(SIGINT, handle_signal);
signal(SIGBREAK, handle_signal);
signal(SIGTERM, handle_signal);
message("Started");
/* Parse arguments */
for (int i= 1; i < argc; i++) {
const char* arg= argv[i];
char* to= child_args;
if (strcmp(arg, "--") == 0 && strlen(arg) == 2) {
/* Got the "--" delimiter */
if (i >= argc)
die("No real args -> nothing to do");
/* Copy the remaining args to child_arg */
for (int j= i+1; j < argc; j++) {
to+= _snprintf(to, child_args + sizeof(child_args) - to, "%s ", argv[j]);
}
break;
} else {
if ( strcmp(arg, "--verbose") == 0 )
verbose++;
else if ( strncmp(arg, "--parent-pid", 10) == 0 )
{
/* Override parent_pid with a value provided by user */
const char* start;
if ((start= strstr(arg, "=")) == NULL)
die("Could not find start of option value in '%s'", arg);
start++; /* Step past = */
if ((parent_pid= atoi(start)) == 0)
die("Invalid value '%s' passed to --parent-id", start);
}
else
die("Unknown option: %s", arg);
}
}
if (*child_args == '\0')
die("nothing to do");
/* Open a handle to the parent process */
message("parent_pid: %d", parent_pid);
if (parent_pid == pid)
die("parent_pid is equal to own pid!");
if ((wait_handles[PARENT]=
OpenProcess(SYNCHRONIZE, FALSE, parent_pid)) == NULL)
die("Failed to open parent process with pid: %d", parent_pid);
/* Create the child process in a job */
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 };
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
/*
Create the job object to make it possible to kill the process
and all of it's children in one go
*/
if ((job_handle= CreateJobObject(NULL, NULL)) == NULL)
die("CreateJobObject failed");
/*
Make all processes associated with the job terminate when the
last handle to the job is closed.
*/
jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
if (SetInformationJobObject(job_handle, JobObjectExtendedLimitInformation,
&jeli, sizeof(jeli)) == 0)
message("SetInformationJobObject failed, continue anyway...");
#if 0
/* Setup stdin, stdout and stderr redirect */
si.dwFlags= STARTF_USESTDHANDLES;
si.hStdInput= GetStdHandle(STD_INPUT_HANDLE);
si.hStdOutput= GetStdHandle(STD_OUTPUT_HANDLE);
si.hStdError= GetStdHandle(STD_ERROR_HANDLE);
#endif
/*
Create the process suspended to make sure it's assigned to the
Job before it creates any process of it's own
*/
if (CreateProcess(NULL, (LPSTR)child_args,
NULL,
NULL,
TRUE, /* inherit handles */
CREATE_SUSPENDED,
NULL,
NULL,
&si,
&process_info) == 0)
die("CreateProcess failed");
if (AssignProcessToJobObject(job_handle, process_info.hProcess) == 0)
{
TerminateProcess(process_info.hProcess, 200);
die("AssignProcessToJobObject failed");
}
ResumeThread(process_info.hThread);
CloseHandle(process_info.hThread);
wait_handles[CHILD]= process_info.hProcess;
message("Started child %d", process_info.dwProcessId);
/* Monitor loop */
DWORD child_exit_code= 1;
DWORD wait_res= WaitForMultipleObjects(NUM_HANDLES, wait_handles,
FALSE, INFINITE);
switch (wait_res)
{
case WAIT_OBJECT_0 + PARENT:
message("Parent exit");
break;
case WAIT_OBJECT_0 + CHILD:
if (GetExitCodeProcess(wait_handles[CHILD], &child_exit_code) == 0)
message("Child exit: could not get exit_code");
else
message("Child exit: exit_code: %d", child_exit_code);
break;
case WAIT_OBJECT_0 + EVENT:
message("Wake up from shutdown_event");
break;
default:
message("Unexpected result %d from WaitForMultipleObjects", wait_res);
break;
}
message("Exiting, child: %d", process_info.dwProcessId);
if (TerminateJobObject(job_handle, 201) == 0)
message("TerminateJobObject failed");
CloseHandle(job_handle);
if (wait_res != WAIT_OBJECT_0 + CHILD)
{
/* The child has not yet returned, wait for it */
message("waiting for child to exit");
if ((wait_res= WaitForSingleObject(wait_handles[CHILD], INFINITE)) != WAIT_OBJECT_0)
{
message("child wait failed: %d", wait_res);
}
else
{
message("child wait succeeded");
}
/* Child's exit code should now be 201, no need to get it */
}
for (int i= 0; i < NUM_HANDLES; i++)
CloseHandle(wait_handles[i]);
exit(child_exit_code);
}
# -*- cperl -*-
# Copyright (C) 2005 MySQL AB
#
# 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
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This is a library file used by the Perl version of mysql-test-run,
# and is part of the translation of the Bourne shell script with the
# same name.
#use Data::Dumper;
use strict;
# $Data::Dumper::Indent= 1;
sub mtr_diff($$);
##############################################################################
#
# This is a simplified unified diff, with some special handling
# of unsorted result sets
#
##############################################################################
# FIXME replace die with mtr_error
#require "mtr_report.pl";
#mtr_diff("a.txt","b.txt");
sub mtr_diff ($$) {
my $file1 = shift;
my $file2 = shift;
# ----------------------------------------------------------------------
# We read in all of the files at once
# ----------------------------------------------------------------------
unless ( open(FILE1, $file1) )
{
mtr_warning("can't open \"$file1\": $!");
return;
}
unless ( open(FILE2, $file2) )
{
mtr_warning("can't open \"$file2\": $!");
return;
}
my $lines1= collect_lines(<FILE1>);
my $lines2= collect_lines(<FILE2>);
close FILE1;
close FILE2;
# print Dumper($lines1);
# print Dumper($lines2);
# ----------------------------------------------------------------------
# We compare line by line, but don't shift off elements until we know
# what to do. This way we use the "restart" method, do simple change
# and restart by entering the diff loop from the beginning again.
# ----------------------------------------------------------------------
my @context;
my @info; # Collect information, and output later
my $lno1= 1;
my $lno2= 1;
while ( @$lines1 or @$lines2 )
{
unless ( @$lines1 )
{
push(@info, map {['+',$lno1,$lno2++,$_]} @$lines2);
last;
}
unless ( @$lines2 )
{
push(@info, map {['-',$lno1++,$lno2,$_]} @$lines1);
last;
}
# ----------------------------------------------------------------------
# We know both have lines
# ----------------------------------------------------------------------
if ( $lines1->[0] eq $lines2->[0] )
{
# Simple case, first line match and all is well
push(@info, ['',$lno1++,$lno2++,$lines1->[0]]);
shift @$lines1;
shift @$lines2;
next;
}
# ----------------------------------------------------------------------
# Now, we know they differ
# ----------------------------------------------------------------------
# How far in the other one, is there a match?
my $idx2= find_next_match($lines1->[0], $lines2);
my $idx1= find_next_match($lines2->[0], $lines1);
# Here we could test "if ( !defined $idx2 or !defined $idx1 )" and
# use a more complicated diff algorithm in the case both contains
# each others lines, just dislocated. But for this application, there
# should be no need.
if ( !defined $idx2 )
{
push(@info, ['-',$lno1++,$lno2,$lines1->[0]]);
shift @$lines1;
}
else
{
push(@info, ['+',$lno1,$lno2++,$lines2->[0]]);
shift @$lines2;
}
}
# ----------------------------------------------------------------------
# Try to output nicely
# ----------------------------------------------------------------------
# print Dumper(\@info);
# We divide into "chunks" to output
# We want at least three lines of context
my @chunks;
my @chunk;
my $state= 'pre'; # 'pre', 'in' and 'post' difference
my $post_count= 0;
foreach my $info ( @info )
{
if ( $info->[0] eq '' and $state eq 'pre' )
{
# Collect no more than three lines of context before diff
push(@chunk, $info);
shift(@chunk) if @chunk > 3;
next;
}
if ( $info->[0] =~ /(\+|\-)/ and $state =~ /(pre|in)/ )
{
# Start/continue collecting diff
$state= 'in';
push(@chunk, $info);
next;
}
if ( $info->[0] eq '' and $state eq 'in' )
{
# Stop collecting diff, and collect context after diff
$state= 'post';
$post_count= 1;
push(@chunk, $info);
next;
}
if ( $info->[0] eq '' and $state eq 'post' and $post_count < 6 )
{
# We might find a new diff sequence soon, continue to collect
# non diffs but five up on 6.
$post_count++;
push(@chunk, $info);
next;
}
if ( $info->[0] eq '' and $state eq 'post' )
{
# We put an end to this, giving three non diff lines to
# the old chunk, and three to the new one.
my @left= splice(@chunk, -3, 3);
push(@chunks, [@chunk]);
$state= 'pre';
$post_count= 0;
@chunk= @left;
next;
}
if ( $info->[0] =~ /(\+|\-)/ and $state eq 'post' )
{
# We didn't split, continue collect diff
$state= 'in';
push(@chunk, $info);
next;
}
}
if ( $post_count > 3 )
{
$post_count -= 3;
splice(@chunk, -$post_count, $post_count);
}
push(@chunks, [@chunk]) if @chunk and $state ne 'pre';
foreach my $chunk ( @chunks )
{
my $from_file_start= $chunk->[0]->[1];
my $to_file_start= $chunk->[0]->[2];
my $from_file_offset= $chunk->[$#$chunk]->[1] - $from_file_start;
my $to_file_offset= $chunk->[$#$chunk]->[2] - $to_file_start;
print "\@\@ -$from_file_start,$from_file_offset ",
"+$to_file_start,$to_file_offset \@\@\n";
foreach my $info ( @$chunk )
{
if ( $info->[0] eq '' )
{
print " $info->[3]\n";
}
elsif ( $info->[0] eq '-' )
{
print "- $info->[3]\n";
}
elsif ( $info->[0] eq '+' )
{
print "+ $info->[3]\n";
}
}
}
# print Dumper(\@chunks);
}
##############################################################################
# Find if the string is found in the array, return the index if found,
# if not found, return "undef"
##############################################################################
sub find_next_match {
my $line= shift;
my $lines= shift;
for ( my $idx= 0; $idx < @$lines; $idx++ )
{
return $idx if $lines->[$idx] eq $line;
}
return undef; # No match found
}
##############################################################################
# Just read the lines, but handle "sets" of lines that are unordered
##############################################################################
sub collect_lines {
my @recordset;
my @lines;
while (@_)
{
my $line= shift @_;
chomp($line);
if ( $line =~ /^\Q%unordered%\E\t/ )
{
push(@recordset, $line);
}
elsif ( @recordset )
{
push(@lines, sort @recordset);
@recordset= (); # Clear it
}
else
{
push(@lines, $line);
}
}
if ( @recordset )
{
push(@lines, sort @recordset);
@recordset= (); # Clear it
}
return \@lines;
}
1;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
kill -9 `cat var/run/master.pid`
# The kill may fail if process has already gone away,
# so don't use the exit code of the kill. Use 0.
exit 0
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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