--- run-mailcap.orig 2020-04-26 01:35:54.000000000 -0700 +++ run-mailcap 2020-06-01 12:10:54.636874000 -0700 @@ -12,6 +12,7 @@ use Encode qw(decode); use I18N::Langinfo qw(langinfo CODESET); use File::Spec; +use File::Temp qw(tempfile); $debug=($ENV{RUN_MAILCAP_DEBUG} || 0); $norun=0; @@ -138,22 +139,13 @@ ($head,$tail) = split(/%s/,$template,2); -# $tmpfile = POSIX::tmpnam($name); -# unlink($tmpfile); + my($fh, $filename) = tempfile( + TEMPLATE => $head . 'XXXXX', + SUFFIX => $tail, + ); - $cmd = "tempfile --mode=600"; - $cmd .= " --prefix $head" if $head; - $cmd .= " --suffix $tail" if $tail; - - $tmpfile = `$cmd`; - chomp($tmpfile); - -# $tmpfile = $ENV{TMPDIR}; -# $tmpfile = "/tmp" unless $tmpfile; -# $tmpfile.= "/$name"; -# unlink($tmpfile); - - return $tmpfile; + chmod(0600, $fh); + return $filename; } @@ -481,8 +473,14 @@ $match =~ m/nametemplate=(.*?)\s*($|;)/; my $prefix = $1; my $linked = 0; + my $iterations = 0; while (!$linked) { $tmplink = TempFile($prefix); + + if (++$iterations > 50) { + die "looped too many times trying to make temp file"; + } + # race: unlink($tmplink); $linked = symlink($file,$tmplink); }