[RFC/PATCH] Unify handling of known shell names
Several places search for known shell names. As one can see in the
code they diverged over time. Move the regex to common_data.pm to
avoid that happening in the future.
Also add mksh while at it.
---
checks/common_data.pm | 4 ++++
checks/infofiles | 6 +++++-
checks/menus | 3 ++-
checks/scripts | 23 ++++++++++++++---------
4 files changed, 25 insertions(+), 11 deletions(-)
I really really need some comments about that one.
Particular points:
1) Is it correct to change $within_another_shell to match /bin/sh?
2) Is it correct to not ignore t?csh in menus/infofiles (this code
should really be further unified in a follow-up patch BTW)?
3) Is it correct to add zsh to most places?
diff --git a/checks/common_data.pm b/checks/common_data.pm
index 6d4dd20..6105b4e 100644
--- a/checks/common_data.pm
+++ b/checks/common_data.pm
@@ -13,6 +13,7 @@ our @EXPORT = qw
%known_libpngs %known_x_metapackages
%non_standard_archs %all_cpus %all_oses
%known_doc_base_formats
+ $known_shells_regex
);
# To let "perl -cw" test know we use these variables;
@@ -26,6 +27,7 @@ use vars qw
%known_libpngs %known_x_metapackages
%all_cpus %all_oses
%known_doc_base_formats
+ $known_shells_regex
);
# simple defines for commonly needed data
@@ -174,6 +176,8 @@ use vars qw
%known_doc_base_formats = map { $_ => 1 }
( 'html', 'text', 'pdf', 'postscript', 'info', 'dvi', 'debiandoc-sgml' );
+$known_shells_regex = qr'(?:(?:b|d)?a|t?c|(?:pd|m)?k|z)?sh';
+
1;
# Local Variables:
diff --git a/checks/infofiles b/checks/infofiles
index 1f956c3..249b796 100644
--- a/checks/infofiles
+++ b/checks/infofiles
@@ -21,6 +21,10 @@
package Lintian::infofiles;
use strict;
+
+use lib "$ENV{'LINTIAN_ROOT'}/checks/";
+use common_data;
+
use Tags;
use Util;
use File::Basename;
@@ -150,7 +154,7 @@ sub check_script {
fail("cannot open maintainer script control/$script for reading: $!");
$interp = <IN>;
$interp = '' unless defined $interp;
- if ($interp =~ m,^\#\!\s*/bin/(a|ba|k|pdk)?sh,) {
+ if ($interp =~ m,^\#\!\s*/bin/$known_shells_regex,) {
$interp = 'sh';
} elsif ($interp =~ m,^\#\!\s*/usr/bin/perl,) {
$interp = 'perl';
diff --git a/checks/menus b/checks/menus
index 228e4ba..9d4cb7c 100644
--- a/checks/menus
+++ b/checks/menus
@@ -22,6 +22,7 @@
package Lintian::menus;
use strict;
+
use lib "$ENV{'LINTIAN_ROOT'}/checks/";
use common_data;
@@ -579,7 +580,7 @@ sub check_script {
fail("cannot open maintainer script control/$script for reading: $!");
$interp = <IN>;
$interp = '' unless defined $interp;
- if ($interp =~ m,^\#\!\s*/bin/(a|ba|k|pdk)?sh,) {
+ if ($interp =~ m,^\#\!\s*/bin/$known_shells_regex,) {
$interp = 'sh';
} elsif ($interp =~ m,^\#\!\s*/usr/bin/perl,) {
$interp = 'perl';
diff --git a/checks/scripts b/checks/scripts
index cd19dab..c4f33d5 100644
--- a/checks/scripts
+++ b/checks/scripts
@@ -24,6 +24,9 @@
package Lintian::scripts;
use strict;
+
+use lib "$ENV{'LINTIAN_ROOT'}/checks/";
+use common_data;
use Dep;
use Tags;
use Util;
@@ -276,13 +279,15 @@ for my $filename (sort keys %{$info->scripts}) {
# Syntax-check most shell scripts, but don't syntax-check scripts that end
# in .dpatch. bash -n doesn't stop checking at exit 0 and goes on to blow
# up on the patch itself.
- # zsh -n is broken, see #485885
- if ($base =~ /^(?:(?:b|d)?a|k)?sh$/) {
- if (-x "$interpreter" && ! script_is_evil_and_wrong("unpacked/$filename")) {
- if ($filename !~ m,\.dpatch$,) {
- if (check_script_syntax($interpreter, "unpacked/$filename")) {
- tag("shell-script-fails-syntax-check", $filename);
- }
+ if ($base =~ /^$known_shells_regex$/) {
+ if (-x $interpreter
+ and ! script_is_evil_and_wrong("unpacked/$filename")
+ and $filename !~ m,\.dpatch$,
+ # exclude some shells. zsh -n is broken, see #485885
+ and $base !~ m/^(z|t?c)sh$/) {
+
+ if (check_script_syntax($interpreter, "unpacked/$filename")) {
+ tag("shell-script-fails-syntax-check", $filename);
}
}
}
@@ -449,7 +454,7 @@ while (<SCRIPTS>) {
tag("csh-considered-harmful", $filename)
if ($base eq 'csh' or $base eq 'tcsh');
- my $shellscript = $base =~ /^((b|d)?a|t?c|(pd)?k)?sh$/ ? 1 : 0;
+ my $shellscript = $base =~ /^$known_shells_regex$/ ? 1 : 0;
# Only syntax-check scripts we can check with bash.
my $checkbashisms;
@@ -530,7 +535,7 @@ while (<SCRIPTS>) {
$cat_string = "";
}
my $within_another_shell = 0;
- if (m,(^|\s+)((/usr)?/bin/)?((b|d)?a|k|z|t?c)sh\s+-c\s*.+,) {
+ if (m,(^|\s+)((/usr)?/bin/)?$known_shells_regex\s+-c\s*.+,) {
$within_another_shell = 1;
}
# if cat_string is set, we are in a HERE document and need not
--
1.6.0.1
--
Frank Lichtenheld <djpig@debian.org>
www: http://www.djpig.de/
Reply to: