[debhelper-devel] [debhelper] 08/08: Dh_Lib: Avoid shell forking when installing maintscripts

Niels Thykier nthykier at moszumanska.debian.org
Sat Jul 15 19:12:36 UTC 2017


This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch shell-out-less
in repository debhelper.

commit 547f317ea88f7fa3f538b42e0ab7dc5895bcad1d
Author: Niels Thykier <niels at thykier.net>
Date:   Sat Jul 15 17:11:27 2017 +0000

    Dh_Lib: Avoid shell forking when installing maintscripts
    
    Signed-off-by: Niels Thykier <niels at thykier.net>
---
 Debian/Debhelper/Dh_Lib.pm | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 66fe9d0..10ab0ab 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -1457,17 +1457,30 @@ sub debhelper_script_subst {
 	if ($file ne '') {
 		if (-f "debian/$ext$script.debhelper") {
 			# Add this into the script, where it has #DEBHELPER#
-			complex_doit("perl -pe 's~#DEBHELPER#~qx{cat debian/$ext$script.debhelper}~eg' < $file > $tmp/DEBIAN/$script");
+			doit({ stdout => "$tmp/DEBIAN/$script" }, 'perl', '-pe',
+				 "s~#DEBHELPER#~qx{cat debian/$ext$script.debhelper}~eg", $file);
 		}
 		else {
 			# Just get rid of any #DEBHELPER# in the script.
-			complex_doit("sed s/#DEBHELPER#// < $file > $tmp/DEBIAN/$script");
+			doit({ stdout => "$tmp/DEBIAN/$script" }, 'sed', 's/#DEBHELPER#//', $file);
 		}
 		reset_perm_and_owner('0755', "$tmp/DEBIAN/$script");
 	}
 	elsif ( -f "debian/$ext$script.debhelper" ) {
-		complex_doit("printf '#!/bin/sh\nset -e\n' > $tmp/DEBIAN/$script");
-		complex_doit("cat debian/$ext$script.debhelper >> $tmp/DEBIAN/$script");
+		if ($dh{VERBOSE}) {
+			verbose_print(q{printf '#!/bin/sh\nset -e\n' > } . "$tmp/DEBIAN/$script");
+			verbose_print("cat debian/$ext$script.debhelper >> $tmp/DEBIAN/$script");
+		}
+		open(my $out_fd, '>', "$tmp/DEBIAN/$script") or error("open($tmp/DEBIAN/$script): $!");
+		print {$out_fd} "#!/bin/sh\n";
+		print {$out_fd} "set -e\n";
+		open(my $in_fd, '<', "debian/$ext$script.debhelper")
+			or error("open(debian/$ext$script.debhelper): $!");
+		while (my $line = <$in_fd>) {
+			print {$out_fd} $line;
+		}
+		close($in_fd);
+		close($out_fd) or error("close($tmp/DEBIAN/$script): $!");
 		reset_perm_and_owner('0755', "$tmp/DEBIAN/$script");
 	}
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git




More information about the debhelper-devel mailing list