$OpenBSD: patch-local_fixproc,v 1.2 2005/06/13 20:33:17 naddy Exp $
--- local/fixproc.orig	Sat Apr 20 09:30:13 2002
+++ local/fixproc	Mon Jun 13 22:31:57 2005
@@ -129,6 +129,8 @@
 #
 # Timothy Kong		3/1995
 
+use File::Temp qw(tempfile);
+
 $database_file = '/local/etc/fixproc.conf';
 
 $debug = 0;			# specify debug level using -dN
@@ -191,20 +193,19 @@ for $proc ( @proc_list )
 sub create_sh_script
 {
   local ($file) = pop (@_);
+  local ($fh) = pop (@_);
   local ($i) = pop (@_);
 
   printf (stderr "create_sh_script\n") if ($debug > 0);
 
   $! = $fixproc_error;
-  open (file, ">"."$file") || die "$0: cannot open $file\n";
   while ( $shell_lines[$i] ne $shell_end_marker )
     {
-      printf (file "%s", $shell_lines[$i]);
+      printf ($fh "%s", $shell_lines[$i]);
       $i++;
     }
-  close (file);
-  system "chmod +x $file";
-  return file;
+  close ($fh);
+  chmod 0755, $file;
 }
 
 
@@ -230,14 +231,13 @@ sub do_fix
   else
     {
       # it must be "shell", so execute the shell script defined in database
+      local ($tmpfh, $tmpfile) = tempfile("fix_XXXXXXXX", DIR => "/tmp");
 
-      local ($tmpfile) = "/tmp/fix_$$";
+      &create_sh_script ($fix{$proc}, $tmpfh, $tmpfile);
 
-      &create_sh_script ($fix{$proc}, $tmpfile);
-
       	# return code is number divided by 256
       $error_code = (system "$tmpfile") / 256;
-      system "rm $tmpfile";
+      unlink($tmpfile);
       return ($fix_failed_error) if ($error_code != 0);
         # sleep needed here?
       return &do_exist ($proc);
@@ -262,13 +262,13 @@ sub do_check
       # if not "exist", then it must be "shell", so execute the shell script
       # defined in database
 
-      local ($tmpfile) = "/tmp/check_$$";
+      local ($tmpfh, $tmpfile) = tempfile("check_XXXXXXXX", DIR => "/tmp");
 
-      &create_sh_script ($check{$proc}, $tmpfile);
+      &create_sh_script ($fix{$proc}, $tmpfh, $tmpfile);
 
       	# return code is number divided by 256
       $error_code = (system "$tmpfile") / 256;
-      system "rm $tmpfile";
+      unlink($tmpfile);
       return ($check_failed_error) if ($error_code != 0);
 
       # check passed, continue
