Package: dpkg-dev
Version: 1.16.4.3
Severity: normal
Tags: patch

Some error messages (especially about wrong command line
options) output the usage information as part of the
error message but outputs those to stdout, making it
impossible to keep expected information and error messages
seperate.

The following patch (against current git master) fixes that.

        Bernhard R. Link


From: "Bernhard R. Link" <brl...@debian.org>
Date: Thu, 12 Jul 2012 18:24:47 +0200
Subject: [PATCH] scripts: do not output usage part of error message to stdout

Add an optional argument to usage() functions to determine
an file descriptor to output to. This way --help output still
can go to stdout where it belongs to while the usage part of
error messages does not garble the stdout.

Signed-off-by: Bernhard R. Link <brl...@debian.org>
---
 scripts/Dpkg/ErrorHandling.pm      |    2 +-
 scripts/changelog/debian.pl        |    6 ++++--
 scripts/dpkg-architecture.pl       |    4 +++-
 scripts/dpkg-buildflags.pl         |    4 +++-
 scripts/dpkg-buildpackage.pl       |    4 +++-
 scripts/dpkg-checkbuilddeps.pl     |    6 ++++--
 scripts/dpkg-distaddfile.pl        |    4 +++-
 scripts/dpkg-genchanges.pl         |    4 +++-
 scripts/dpkg-gencontrol.pl         |    4 +++-
 scripts/dpkg-gensymbols.pl         |    4 +++-
 scripts/dpkg-maintscript-helper.sh |    5 ++---
 scripts/dpkg-mergechangelogs.pl    |    8 +++++---
 scripts/dpkg-name.pl               |    6 ++++--
 scripts/dpkg-parsechangelog.pl     |    4 +++-
 scripts/dpkg-scanpackages.pl       |    6 ++++--
 scripts/dpkg-scansources.pl        |    8 +++++---
 scripts/dpkg-shlibdeps.pl          |    4 +++-
 scripts/dpkg-source.pl             |    4 +++-
 scripts/dpkg-vendor.pl             |    4 +++-
 19 files changed, 62 insertions(+), 29 deletions(-)

diff --git a/scripts/Dpkg/ErrorHandling.pm b/scripts/Dpkg/ErrorHandling.pm
index bdb3fe3..2f4e73c 100644
--- a/scripts/Dpkg/ErrorHandling.pm
+++ b/scripts/Dpkg/ErrorHandling.pm
@@ -104,7 +104,7 @@ sub usageerr(@)
     $msg = sprintf($msg, @_) if (@_);
     warn "$progname: $msg\n\n";
     # XXX: access to main namespace
-    main::usage();
+    main::usage(\*STDERR);
     exit(2);
 }
 
diff --git a/scripts/changelog/debian.pl b/scripts/changelog/debian.pl
index e201862..b42de58 100755
--- a/scripts/changelog/debian.pl
+++ b/scripts/changelog/debian.pl
@@ -44,7 +44,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...] [<changelogfile>]
 
 Options:
@@ -103,7 +105,7 @@ GetOptions( "file=s" => \$file,
            "format=s" => \&set_format,
            "all|a" => \$all,
            )
-    or do { usage(); exit(2) };
+    or do { usage(\*STDERR); exit(2) };
 
 usageerr('too many arguments') if @ARGV > 1;
 
diff --git a/scripts/dpkg-architecture.pl b/scripts/dpkg-architecture.pl
index 6ed7a72..afb36d6 100755
--- a/scripts/dpkg-architecture.pl
+++ b/scripts/dpkg-architecture.pl
@@ -43,7 +43,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...] [<command>]")
     . "\n\n" . _g(
 "Options:
diff --git a/scripts/dpkg-buildflags.pl b/scripts/dpkg-buildflags.pl
index a87dd42..80c2743 100755
--- a/scripts/dpkg-buildflags.pl
+++ b/scripts/dpkg-buildflags.pl
@@ -38,7 +38,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<command>]")
     . "\n\n" . _g(
 "Commands:
diff --git a/scripts/dpkg-buildpackage.pl b/scripts/dpkg-buildpackage.pl
index 768fb6e..82c721a 100755
--- a/scripts/dpkg-buildpackage.pl
+++ b/scripts/dpkg-buildpackage.pl
@@ -49,7 +49,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...]")
     . "\n\n" . _g(
 "Options:
diff --git a/scripts/dpkg-checkbuilddeps.pl b/scripts/dpkg-checkbuilddeps.pl
index c203710..e8ccf8a 100755
--- a/scripts/dpkg-checkbuilddeps.pl
+++ b/scripts/dpkg-checkbuilddeps.pl
@@ -40,7 +40,9 @@ sub version()
 }
 
 sub usage {
-       printf _g(
+       my $into = shift || \*STDOUT;
+
+       printf $into _g(
 "Usage: %s [<option>...] [<control-file>]")
        . "\n\n" . _g(
 "Options:
@@ -72,7 +74,7 @@ if (!GetOptions('A' => \$ignore_bd_arch,
                 'c=s' => \$bc_value,
                 'a=s' => \$host_arch,
                 'admindir=s' => \$admindir)) {
-       usage();
+       usage(\*STDERR);
        exit(2);
 }
 
diff --git a/scripts/dpkg-distaddfile.pl b/scripts/dpkg-distaddfile.pl
index ae0c3b9..d281535 100755
--- a/scripts/dpkg-distaddfile.pl
+++ b/scripts/dpkg-distaddfile.pl
@@ -43,7 +43,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...] <filename> <section> <priority>
 
 Options:
diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl
index 0826641..4812dd1 100755
--- a/scripts/dpkg-genchanges.pl
+++ b/scripts/dpkg-genchanges.pl
@@ -106,7 +106,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...]")
     . "\n\n" . _g(
 "Options:
diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl
index 8df486e..b59d386 100755
--- a/scripts/dpkg-gencontrol.pl
+++ b/scripts/dpkg-gencontrol.pl
@@ -69,7 +69,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...]")
     . "\n\n" . _g(
 "Options:
diff --git a/scripts/dpkg-gensymbols.pl b/scripts/dpkg-gensymbols.pl
index 3d29a93..2d105ca 100755
--- a/scripts/dpkg-gensymbols.pl
+++ b/scripts/dpkg-gensymbols.pl
@@ -59,7 +59,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...]")
     . "\n\n" . _g(
 "Options:
diff --git a/scripts/dpkg-maintscript-helper.sh 
b/scripts/dpkg-maintscript-helper.sh
index 48793b8..7cef27d 100755
--- a/scripts/dpkg-maintscript-helper.sh
+++ b/scripts/dpkg-maintscript-helper.sh
@@ -250,7 +250,7 @@ END
 }
 
 badusage() {
-       usage
+       usage >&2
        exit 1
 }
 
@@ -306,8 +306,7 @@ mv_conffile)
        Hint: upgrading dpkg to a newer version might help.
 
        END
-       usage
-       exit 1
+       badusage
 esac
 
 exit 0
diff --git a/scripts/dpkg-mergechangelogs.pl b/scripts/dpkg-mergechangelogs.pl
index c19de08..e9e1f94 100755
--- a/scripts/dpkg-mergechangelogs.pl
+++ b/scripts/dpkg-mergechangelogs.pl
@@ -60,7 +60,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf(_g(
+    my $into = shift || \*STDOUT;
+
+    printf($into _g(
 "Usage: %s [<option>...] <old> <new-a> <new-b> [<out>]
 
 Options:
@@ -75,14 +77,14 @@ my $merge_prereleases;
 unless (GetOptions('help|?' => sub { usage(); exit(0) },
                   'merge-prereleases|m' => \$merge_prereleases,
                   'version' => sub { version(); exit(0) })) {
-    usage();
+    usage(\*STDERR);
     exit(2);
 }
 my ($old, $new_a, $new_b, $out_file) = @ARGV;
 unless (defined $old and defined $new_a and defined $new_b and
         -e $old and -e $new_a and -e $new_b)
 {
-    usage();
+    usage(\*STDERR);
     exit(2);
 }
 
diff --git a/scripts/dpkg-name.pl b/scripts/dpkg-name.pl
index 6edc032..15089a1 100755
--- a/scripts/dpkg-name.pl
+++ b/scripts/dpkg-name.pl
@@ -48,9 +48,11 @@ sub version()
 
 sub usage()
 {
-    printf(_g("Usage: %s [<option>...] <file>...\n"), $progname);
+    my $into = shift || \*STDOUT;
 
-    print(_g("
+    printf($into _g("Usage: %s [<option>...] <file>...\n"), $progname);
+
+    print($into _g("
 Options:
   -a, --no-architecture    no architecture part in filename.
   -o, --overwrite          overwrite if file exists.
diff --git a/scripts/dpkg-parsechangelog.pl b/scripts/dpkg-parsechangelog.pl
index 1dcaf9a..55432bd 100755
--- a/scripts/dpkg-parsechangelog.pl
+++ b/scripts/dpkg-parsechangelog.pl
@@ -41,7 +41,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...]")
     . "\n\n" . _g(
 "Options:
diff --git a/scripts/dpkg-scanpackages.pl b/scripts/dpkg-scanpackages.pl
index adbb1c4..31955eb 100755
--- a/scripts/dpkg-scanpackages.pl
+++ b/scripts/dpkg-scanpackages.pl
@@ -63,7 +63,9 @@ sub version {
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...] <binary-path> [<override-file> [<path-prefix>]] > 
Packages
 
 Options:
@@ -146,7 +148,7 @@ sub load_override_extra
     close($comp_file);
 }
 
-usage() and exit 1 if not $result;
+usage(\*STDERR) and exit 1 if not $result;
 
 if (not @ARGV >= 1 && @ARGV <= 3) {
     usageerr(_g("one to three arguments expected"));
diff --git a/scripts/dpkg-scansources.pl b/scripts/dpkg-scansources.pl
index 67050e6..f5f22b8 100755
--- a/scripts/dpkg-scansources.pl
+++ b/scripts/dpkg-scansources.pl
@@ -63,7 +63,7 @@ my $Extra_override_file = undef;
 
 my @Option_spec = (
     'debug!'           => \$Debug,
-    'help|?'           => \&usage,
+    'help|?'           => sub { usage(); exit 0; },
     'no-sort|n'                => \$No_sort,
     'source-override|s=s' => \$Src_override,
     'extra-override|e=s' => \$Extra_override_file,
@@ -80,7 +80,9 @@ sub version {
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...] <binary-path> [<override-file> [<path-prefix>]] > 
Sources
 
 Options:
@@ -298,7 +300,7 @@ sub process_dsc {
 sub main {
     my (@out);
 
-    GetOptions(@Option_spec) or usage;
+    GetOptions(@Option_spec) or usage(\*STDERR);
     @ARGV >= 1 && @ARGV <= 3 or usageerr(_g("one to three arguments 
expected"));
 
     push @ARGV, undef          if @ARGV < 2;
diff --git a/scripts/dpkg-shlibdeps.pl b/scripts/dpkg-shlibdeps.pl
index ad0c06f..d5908c1 100755
--- a/scripts/dpkg-shlibdeps.pl
+++ b/scripts/dpkg-shlibdeps.pl
@@ -548,7 +548,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...] <executable>|-e<executable> [<option>...]")
     . "\n\n" . _g(
 "Positional options (order is significant):
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index f2edb95..c773b5f 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -474,7 +474,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...] <command>")
     . "\n\n" . _g(
 "Commands:
diff --git a/scripts/dpkg-vendor.pl b/scripts/dpkg-vendor.pl
index e2f8cc0..c9745a2 100755
--- a/scripts/dpkg-vendor.pl
+++ b/scripts/dpkg-vendor.pl
@@ -38,7 +38,9 @@ later for copying conditions. There is NO warranty.
 }
 
 sub usage {
-    printf _g(
+    my $into = shift || \*STDOUT;
+
+    printf $into _g(
 "Usage: %s [<option>...] [<command>]")
     . "\n\n" . _g(
 "Options:
-- 
1.7.10.4




-- 
To UNSUBSCRIBE, email to debian-dpkg-bugs-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to