22# ****************************
33package MySQLaccess;
44# use strict;
5- use POSIX qw(tmpnam);
5+ use File::Temp qw(tempfile tmpnam);
66use Fcntl;
77
88BEGIN {
@@ -32,7 +32,6 @@ BEGIN {
3232 $ACCESS_U_BCK = ' user_backup' ;
3333 $ACCESS_D_BCK = ' db_backup' ;
3434 $DIFF = ' /usr/bin/diff' ;
35- $TMP_PATH = ' /tmp' ; # path to writable tmp-directory
3635 $MYSQLDUMP = ' @bindir@/mysqldump' ;
3736 # path to mysqldump executable
3837
@@ -432,7 +431,7 @@ use IPC::Open3;
432431# no caching on STDOUT
433432 $| =1;
434433
435- $MYSQL_CNF = POSIX:: tmpnam ();
434+ $MYSQL_CNF = tmpnam ();
436435 %MYSQL_CNF = (client => { },
437436 mysql => { },
438437 mysqldump => { },
@@ -577,8 +576,6 @@ if (!defined($Param{'host'})) { $Param{'host'}='localhost'; }
577576push(@MySQLaccess::Grant::Error,' not_found_mysql' ) if ! (-x $MYSQL );
578577push(@MySQLaccess::Grant::Error,' not_found_diff' ) if ! (-x $DIFF );
579578push(@MySQLaccess::Grant::Error,' not_found_mysqldump' ) if ! (-x $MYSQLDUMP );
580- push(@MySQLaccess::Grant::Error,' not_found_tmp' ) if ! (-d $TMP_PATH );
581- push(@MySQLaccess::Grant::Error,' write_err_tmp' ) if ! (-w $TMP_PATH );
582579if (@MySQLaccess::Grant::Error) {
583580 MySQLaccess::Report::Print_Error_Messages () ;
584581 exit 0;
@@ -1777,17 +1774,15 @@ sub Diff_Privileges {
17771774 @before = sort(@before);
17781775 @after = sort(@after);
17791776
1780- $before = " $MySQLaccess ::TMP_PATH/$MySQLaccess ::script.before.$$ " ;
1781- $after = " $MySQLaccess ::TMP_PATH/$MySQLaccess ::script.after.$$ " ;
1782- # $after = "/tmp/t0";
1783- open(BEFORE," > $before " ) ||
1784- push(@MySQLaccess::Report::Errors," Can't open temporary file $before for writing" );
1785- open(AFTER," > $after " ) ||
1786- push(@MySQLaccess::Report::Errors," Can't open temporary file $after for writing" );
1787- print BEFORE join(" \n" ,@before);
1788- print AFTER join(" \n" ,@after);
1789- close(BEFORE);
1790- close(AFTER);
1777+ ($hb , $before ) = tempfile(" $MySQLaccess ::script.XXXXXX" ) or
1778+ push(@MySQLaccess::Report::Errors," Can't create temporary file: $! " );
1779+ ($ha , $after ) = tempfile(" $MySQLaccess ::script.XXXXXX" ) or
1780+ push(@MySQLaccess::Report::Errors," Can't create temporary file: $! " );
1781+
1782+ print $hb join(" \n" ,@before);
1783+ print $ha join(" \n" ,@after);
1784+ close $hb ;
1785+ close $ha ;
17911786
17921787 # ----------------------------------
17931788 # compute difference
@@ -1800,8 +1795,8 @@ sub Diff_Privileges {
18001795
18011796 # ----------------------------------
18021797 # cleanup temp. files
1803- unlink(BEFORE );
1804- unlink(AFTER );
1798+ unlink($before );
1799+ unlink($after );
18051800
18061801 return \@ diffs;
18071802}
@@ -2316,14 +2311,6 @@ BEGIN {
23162311 => "The diff program <$MySQLaccess::DIFF> could not be found.\n"
23172312 ."+ Check your path, or\n"
23182313 ."+ edit the source of this script to point \$DIFF to the diff program.\n"
2319- ,' not_found_tmp'
2320- => "The temporary directory <$MySQLaccess::TMP_PATH> could not be found.\n"
2321- ."+ create this directory (writeable!), or\n"
2322- ."+ edit the source of this script to point \$TMP_PATH to the right directory.\n"
2323- ,' write_err_tmp'
2324- => "The temporary directory <$MySQLaccess::TMP_PATH> is not writable.\n"
2325- ."+ make this directory writeable!, or\n"
2326- ."+ edit the source of this script to point \$TMP_PATH to another directory.\n"
23272314 ,' Unrecognized_option'
23282315 => "Sorry,\n"
23292316 ."You are using an old version of the mysql-program,\n"
0 commit comments