File 0075-RHEL-6.1-Directly-include-String-ShellQuote.patch of Package libguestfs
From 9257a2c999d2afe9c5c670f9d4f33196e916179f Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <rjones@redhat.com>
Date: Mon, 29 Nov 2010 18:41:38 +0000
Subject: [PATCH 75/78] RHEL 6.1: Directly include String::ShellQuote.
Directly include a snippet from String::ShellQuote so that we
don't need to depend on this external library, which is not
included in RHEL 6.1.
This affects virt-make-fs and (old) virt-inspector.
---
configure.ac | 2 +-
inspector1/virt-inspector | 90 ++++++++++++++++++++++++++++++++++++++++++++-
tools/virt-make-fs | 91 ++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 180 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index bb7a265..5507a58 100644
--- a/configure.ac
+++ b/configure.ac
@@ -809,7 +809,7 @@ dnl Check for Perl modules needed by Perl virt tools (virt-df, etc.)
AS_IF([test "x$PERL" != "xno"],
[
missing_perl_modules=no
- for pm in Pod::Usage Getopt::Long Sys::Virt Data::Dumper Locale::TextDomain Win::Hivex Win::Hivex::Regedit String::ShellQuote; do
+ for pm in Pod::Usage Getopt::Long Sys::Virt Data::Dumper Locale::TextDomain Win::Hivex Win::Hivex::Regedit; do
AC_MSG_CHECKING([for $pm])
if ! $PERL -M$pm -e1 >/dev/null 2>&1; then
AC_MSG_RESULT([no])
diff --git a/inspector1/virt-inspector b/inspector1/virt-inspector
index 36fbfa9..97ab684 100644
--- a/inspector1/virt-inspector
+++ b/inspector1/virt-inspector
@@ -27,7 +27,6 @@ use Pod::Usage;
use Getopt::Long;
use Data::Dumper;
use XML::Writer;
-use String::ShellQuote qw(shell_quote);
use Locale::TextDomain 'libguestfs';
# Optional:
@@ -874,6 +873,88 @@ sub output_query_kernel_arch
=back
+=cut
+
+# Avoid having to depend on external String::ShellQuote package
+# by including the code here.
+
+# $Id: ShellQuote.pm,v 1.9 2005/05/03 10:53:33 roderick Exp $
+#
+# Copyright (c) 1997 Roderick Schertler. All rights reserved. This
+# program is free software; you can redistribute it and/or modify it
+# under the same terms as Perl itself.
+
+sub _shell_quote_backend {
+ my @in = @_;
+ my @err = ();
+
+ if (0) {
+ require RS::Handy;
+ print RS::Handy::data_dump(\@in);
+ }
+
+ return \@err, '' unless @in;
+
+ my $ret = '';
+ foreach (@in) {
+ if (!defined $_ or $_ eq '') {
+ $_ = "''";
+ next;
+ }
+
+ if (s/\x00//g) {
+ push @err, "No way to quote string containing null (\\000) bytes";
+ }
+
+ # = does need quoting else in command position it's a program-local
+ # environment setting
+
+ if (m|[^\w!%+,\-./:@^]|) {
+
+ # ' -> '\''
+ s/'/'\\''/g;
+
+ # make multiple ' in a row look simpler
+ # '\'''\'''\'' -> '"'''"'
+ s|((?:'\\''){2,})|q{'"} . (q{'} x (length($1) / 4)) . q{"'}|ge;
+
+ $_ = "'$_'";
+ s/^''//;
+ s/''$//;
+ }
+ }
+ continue {
+ $ret .= "$_ ";
+ }
+
+ chop $ret;
+ return \@err, $ret;
+}
+
+#=item B<shell_quote> [I<string>]...
+#
+#B<shell_quote> quotes strings so they can be passed through the shell.
+#Each I<string> is quoted so that the shell will pass it along as a
+#single argument and without further interpretation. If no I<string>s
+#are given an empty string is returned.
+#
+#If any I<string> can't be safely quoted B<shell_quote> will B<croak>.
+#
+#=cut
+
+sub shell_quote {
+ my ($rerr, $s) = _shell_quote_backend @_;
+
+ if (@$rerr) {
+ my %seen;
+ @$rerr = grep { !$seen{$_}++ } @$rerr;
+ my $s = join '', map { "shell_quote(): $_\n" } @$rerr;
+ chomp $s;
+ croak $s;
+ }
+ return $s;
+}
+
=head1 SHELL QUOTING
Libvirt guest names can contain arbitrary characters, some of which
@@ -913,3 +994,10 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Contains code from perl String::ShellQuote under the following
+copyright and license:
+
+Copyright (c) 1997 Roderick Schertler. All rights reserved. This
+program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
diff --git a/tools/virt-make-fs b/tools/virt-make-fs
index f9f65d0..6978e28 100755
--- a/tools/virt-make-fs
+++ b/tools/virt-make-fs
@@ -27,7 +27,7 @@ use Getopt::Long;
use File::Temp qw(tempdir);
use POSIX qw(mkfifo floor);
use Data::Dumper;
-use String::ShellQuote qw(shell_quote);
+use Carp qw(croak);
use Locale::TextDomain 'libguestfs';
=encoding utf8
@@ -524,6 +524,88 @@ sub create_pipe
return $pipe;
}
+# Avoid having to depend on external String::ShellQuote package
+# by including the code here.
+
+# $Id: ShellQuote.pm,v 1.9 2005/05/03 10:53:33 roderick Exp $
+#
+# Copyright (c) 1997 Roderick Schertler. All rights reserved. This
+# program is free software; you can redistribute it and/or modify it
+# under the same terms as Perl itself.
+
+sub _shell_quote_backend {
+ my @in = @_;
+ my @err = ();
+
+ if (0) {
+ require RS::Handy;
+ print RS::Handy::data_dump(\@in);
+ }
+
+ return \@err, '' unless @in;
+
+ my $ret = '';
+ foreach (@in) {
+ if (!defined $_ or $_ eq '') {
+ $_ = "''";
+ next;
+ }
+
+ if (s/\x00//g) {
+ push @err, "No way to quote string containing null (\\000) bytes";
+ }
+
+ # = does need quoting else in command position it's a program-local
+ # environment setting
+
+ if (m|[^\w!%+,\-./:@^]|) {
+
+ # ' -> '\''
+ s/'/'\\''/g;
+
+ # make multiple ' in a row look simpler
+ # '\'''\'''\'' -> '"'''"'
+ s|((?:'\\''){2,})|q{'"} . (q{'} x (length($1) / 4)) . q{"'}|ge;
+
+ $_ = "'$_'";
+ s/^''//;
+ s/''$//;
+ }
+ }
+ continue {
+ $ret .= "$_ ";
+ }
+
+ chop $ret;
+ return \@err, $ret;
+}
+
+#=item B<shell_quote> [I<string>]...
+#
+#B<shell_quote> quotes strings so they can be passed through the shell.
+#Each I<string> is quoted so that the shell will pass it along as a
+#single argument and without further interpretation. If no I<string>s
+#are given an empty string is returned.
+#
+#If any I<string> can't be safely quoted B<shell_quote> will B<croak>.
+#
+#=cut
+
+sub shell_quote {
+ my ($rerr, $s) = _shell_quote_backend @_;
+
+ if (@$rerr) {
+ my %seen;
+ @$rerr = grep { !$seen{$_}++ } @$rerr;
+ my $s = join '', map { "shell_quote(): $_\n" } @$rerr;
+ chomp $s;
+ croak $s;
+ }
+ return $s;
+}
+
+#----------------------------------------------------------------------
+
=head1 SHELL QUOTING
Libvirt guest names can contain arbitrary characters, some of which
@@ -577,3 +659,10 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+Contains code from perl String::ShellQuote under the following
+copyright and license:
+
+Copyright (c) 1997 Roderick Schertler. All rights reserved. This
+program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
--
1.7.1