diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2013-06-14 20:31:57 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2013-06-14 20:31:57 +0000 |
commit | 900072bfb5757e0b79aaf4f65231b07a9f1fb336 (patch) | |
tree | b0799eddcd6e1114acd44eaecbec5f31835038d7 | |
parent | a106b631e4c2cf50b53f6e5b9a1a38b80bfa0eca (diff) |
Use mkstemp/mkdtemp not $$ for temp files.
-rw-r--r-- | bin/ksh/tests/th | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/bin/ksh/tests/th b/bin/ksh/tests/th index dfdaea1f147..9fb3ef33b11 100644 --- a/bin/ksh/tests/th +++ b/bin/ksh/tests/th @@ -1,5 +1,5 @@ #!/usr/bin/perl -# $OpenBSD: th,v 1.14 2013/06/14 20:11:11 millert Exp $ +# $OpenBSD: th,v 1.15 2013/06/14 20:31:56 millert Exp $ # @@ -132,6 +132,7 @@ use POSIX qw(EINTR); use Getopt::Std; +use File::Temp qw/ :mktemp /; $os = defined $^O ? $^O : 'unknown'; @@ -190,11 +191,15 @@ EOF "os:$os", '1' ); -$temps = "/tmp/rts$$"; -$tempi = "/tmp/rti$$"; -$tempo = "/tmp/rto$$"; -$tempe = "/tmp/rte$$"; -$tempdir = "/tmp/rtd$$"; +($fh, $temps) = mkstemp("/tmp/rts.XXXXXXXX"); +close($fh); +($fh, $tempi) = mkstemp("/tmp/rti.XXXXXXXX"); +close($fh); +($fh, $tempo) = mkstemp("/tmp/rto.XXXXXXXX"); +close($fh); +($fh, $tempe) = mkstemp("/tmp/rte.XXXXXXXX"); +close($fh); +$tempdir = mkdtemp("/tmp/rtd.XXXXXXXX"); $nfailed = 0; $nxfailed = 0; @@ -256,8 +261,6 @@ foreach $k (keys(%ENV)) { } $ENV{$k} = $v while ($k,$v) = each %new_env; -die "$prog: couldn't make directory $tempdir - $!\n" if !mkdir($tempdir, 0777); - chop($pwd = `pwd 2> /dev/null`); die "$prog: couldn't get current working directory\n" if $pwd eq ''; die "$prog: couldn't cd to $pwd - $!\n" if !chdir($pwd); @@ -388,6 +391,8 @@ run_test #print "Running test $name...\n" if $verbose; + return undef if !&scrub_dir($tempdir); + if (defined $test{'stdin'}) { return undef if !&write_file($tempi, $test{'stdin'}); $ifile = $tempi; @@ -399,8 +404,6 @@ run_test return undef if !&write_file($temps, $test{'script'}); } - return undef if !&scrub_dir($tempdir); - if (!chdir($tempdir)) { print STDERR "$prog: couldn't cd to $tempdir - $!\n"; return undef; |