Explorar el Código

Dpkg::IPC: new option to clean the environment

* scripts/Dpkg/IPC.pm (fork_and_exec): New delete_env option
that allows to remove environment variable within the child
process.
Raphael Hertzog hace 18 años
padre
commit
2bcb104ad9
Se han modificado 1 ficheros con 12 adiciones y 0 borrados
  1. 12 0
      scripts/Dpkg/IPC.pm

+ 12 - 0
scripts/Dpkg/IPC.pm

@@ -111,6 +111,11 @@ calling exec.
 Hash reference. The child process will populate %ENV with the items of the
 hash before calling exec. This allows exporting environment variables.
 
+=item delete_env
+
+Array reference. The child process will remove all environment variables
+listed in the array before calling exec.
+
 =back
 
 =cut
@@ -142,6 +147,10 @@ sub _sanity_check_opts {
 	error("parameter env must be a hash reference");
     }
 
+    if (exists $opts{"delete_env"} and ref($opts{"delete_env"}) ne 'ARRAY') {
+	error("parameter delete_env must be an array reference");
+    }
+
     return %opts;
 }
 
@@ -188,6 +197,9 @@ sub fork_and_exec {
 		$ENV{$_} = $opts{"env"}{$_};
 	    }
 	}
+	if ($opts{"delete_env"}) {
+	    delete $ENV{$_} foreach (@{$opts{"delete_env"}});
+	}
 	# Change the current directory
 	if ($opts{"chdir"}) {
 	    chdir($opts{"chdir"}) || syserr(_g("chdir to %s"), $opts{"chdir"});