From a9dd6acbaca836fc4e943e69a31b2e7acda32045 Mon Sep 17 00:00:00 2001
From: Hongxu Jia <hongxu.jia@windriver.com>
Date: Wed, 13 Nov 2024 19:49:23 +0800
Subject: [PATCH] fix 'bzip2 --version > /tmp/aaa 2>&1' hang

According to [1]

As of the current version 1.0.8, bzip2 --version will print version
info but it will also continue compressing stdin:

  $ ./bzip2 --version
  bzip2, a block-sorting file compressor.  Version 1.0.8, 13-Jul-2019.
  
     Copyright (C) 1996-2019 by Julian Seward.
  
     This program is free software; [...]
  
  bzip2: I won't write compressed data to a terminal.
  bzip2: For help, type: `bzip2 --help'.

Debian (and its downstreams like Ubuntu) will patch this out [2],
making the < /dev/null unnecessary:

[1] https://stackoverflow.com/questions/59757176/why-using-dev-null-with-a-program-like-bzip2
[2] https://sources.debian.org/src/bzip2/1.0.8-6/debian/patches/20-legacy.patch/

Upstream-Status: Submitted [bzip2-devel@sourceware.org]

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 bzip2.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/bzip2.c b/bzip2.c
index d95d280..6ec9871 100644
--- a/bzip2.c
+++ b/bzip2.c
@@ -1890,7 +1890,9 @@ IntNative main ( IntNative argc, Char *argv[] )
                case '8': blockSize100k    = 8; break;
                case '9': blockSize100k    = 9; break;
                case 'V':
-               case 'L': license();            break;
+               case 'L': license();
+                         exit ( 0 );
+                         break;
                case 'v': verbosity++; break;
                case 'h': usage ( progName );
                          exit ( 0 );
@@ -1916,8 +1918,8 @@ IntNative main ( IntNative argc, Char *argv[] )
       if (ISFLAG("--keep"))              keepInputFiles   = True;    else
       if (ISFLAG("--small"))             smallMode        = True;    else
       if (ISFLAG("--quiet"))             noisy            = False;   else
-      if (ISFLAG("--version"))           license();                  else
-      if (ISFLAG("--license"))           license();                  else
+      if (ISFLAG("--version"))           { license(); exit ( 0 ); }  else
+      if (ISFLAG("--license"))           { license(); exit ( 0 ); }  else
       if (ISFLAG("--exponential"))       workFactor = 1;             else 
       if (ISFLAG("--repetitive-best"))   redundant(aa->name);        else
       if (ISFLAG("--repetitive-fast"))   redundant(aa->name);        else
-- 
2.34.1

