From a36945b51467bb226bd644125ce6ec0ddc44171f Mon Sep 17 00:00:00 2001 From: starlet-dx <15929766099@163.com> Date: Tue, 30 Jan 2024 15:17:02 +0800 Subject: [PATCH] Fix exit with status code 0 for --help (cherry picked from commit 3deed882e1717f82aa351800b16f01ad0bec4bb2) --- scrub.spec | 9 ++- usage-Exit-with-status-code-0-for-help.patch | 48 ++++++++++++ usage-Output-to-stdout-on-exit-code-0.patch | 81 ++++++++++++++++++++ 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 usage-Exit-with-status-code-0-for-help.patch create mode 100644 usage-Output-to-stdout-on-exit-code-0.patch diff --git a/scrub.spec b/scrub.spec index c1bb28d..7b0cf3c 100644 --- a/scrub.spec +++ b/scrub.spec @@ -1,10 +1,14 @@ Name: scrub Version: 2.6.1 -Release: 2 +Release: 3 Summary: A disk overwrite utility License: GPLv2+ URL: https://github.com/chaos/scrub Source0: http://github.com/chaos/scrub/releases/download/2.6.1/scrub-2.6.1.tar.gz +# https://github.com/chaos/scrub/commit/006fd942abd78d3128d427f1ede9786abe14c65f +Patch0: usage-Exit-with-status-code-0-for-help.patch +# https://github.com/chaos/scrub/commit/bd88864d8ee15a65d5ecdb3818afa4d5193d2455 +Patch1: usage-Output-to-stdout-on-exit-code-0.patch BuildRequires: gettext, gcc @@ -34,6 +38,9 @@ retrieving the data more difficult. It operates in one of three modes: %{_mandir}/man1/scrub.1* %changelog +* Tue Jan 30 2024 yaoxin - 2.6.1-3 +- Fix exit with status code 0 for --help + * Tue Jun 29 2021 zhouwenpei - 2.6.1-2 - add buildrequire gcc and gettext. diff --git a/usage-Exit-with-status-code-0-for-help.patch b/usage-Exit-with-status-code-0-for-help.patch new file mode 100644 index 0000000..ad24675 --- /dev/null +++ b/usage-Exit-with-status-code-0-for-help.patch @@ -0,0 +1,48 @@ +From 006fd942abd78d3128d427f1ede9786abe14c65f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ville=20Skytt=C3=A4?= +Date: Thu, 12 Apr 2018 08:07:29 +0300 +Subject: [PATCH] usage: Exit with status code 0 for --help + +--- + src/scrub.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/src/scrub.c b/src/scrub.c +index 0a325cb..fceb639 100644 +--- a/src/scrub.c ++++ b/src/scrub.c +@@ -110,7 +110,7 @@ static struct option longopts[] = { + char *prog; + + static void +-usage(void) ++usage(int rc) + { + fprintf(stderr, + "Usage: %s [OPTIONS] file [file...]\n" +@@ -132,7 +132,7 @@ usage(void) + + fprintf(stderr, "Available patterns are:\n"); + seq_list (); +- exit(1); ++ exit(rc); + } + + int +@@ -225,12 +225,14 @@ main(int argc, char *argv[]) + nopt = true; + break; + case 'h': /* --help */ ++ usage(0); ++ break; + default: +- usage(); ++ usage(1); + } + } + if (argc == optind) +- usage(); ++ usage(1); + if (Xopt && argc - optind > 1) { + fprintf(stderr, "%s: -X only takes one directory name\n", prog); + exit(1); diff --git a/usage-Output-to-stdout-on-exit-code-0.patch b/usage-Output-to-stdout-on-exit-code-0.patch new file mode 100644 index 0000000..10d1a56 --- /dev/null +++ b/usage-Output-to-stdout-on-exit-code-0.patch @@ -0,0 +1,81 @@ +From bd88864d8ee15a65d5ecdb3818afa4d5193d2455 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ville=20Skytt=C3=A4?= +Date: Thu, 12 Apr 2018 08:39:20 +0300 +Subject: [PATCH] usage: Output to stdout on exit code 0 + +--- + src/pattern.c | 6 +++--- + src/pattern.h | 4 +++- + src/scrub.c | 7 ++++--- + 3 files changed, 10 insertions(+), 7 deletions(-) + +diff --git a/src/pattern.c b/src/pattern.c +index 10430f9..6c0eedc 100644 +--- a/src/pattern.c ++++ b/src/pattern.c +@@ -420,7 +420,7 @@ seq2str(const sequence_t *sp, char *buf, int len) + } + + void +-seq_list(void) ++seq_list(FILE *fp) + { + const int len = seq_count(); + char buf[80]; +@@ -428,10 +428,10 @@ seq_list(void) + + for (i = 0; i < len; i++) { + seq2str(sequences[i], buf, sizeof(buf)); +- fprintf(stderr, "%s\n", buf); ++ fprintf(fp, "%s\n", buf); + } + seq2str(&custom_seq, buf, sizeof(buf)); +- fprintf(stderr, "%s\n", buf); ++ fprintf(fp, "%s\n", buf); + } + + /* +diff --git a/src/pattern.h b/src/pattern.h +index bcf5374..e1d0144 100644 +--- a/src/pattern.h ++++ b/src/pattern.h +@@ -1,3 +1,5 @@ ++#include ++ + #define MAXPATBYTES 16 + #define MAXSEQPATTERNS 35 + typedef enum { +@@ -19,7 +21,7 @@ typedef struct { + } sequence_t; + + const sequence_t *seq_lookup(char *name); +-void seq_list(void); ++void seq_list(FILE *fp); + char *pat2str(pattern_t p); + void memset_pat(void *s, pattern_t p, size_t n); + +diff --git a/src/scrub.c b/src/scrub.c +index fceb639..6671ed5 100644 +--- a/src/scrub.c ++++ b/src/scrub.c +@@ -112,7 +112,8 @@ char *prog; + static void + usage(int rc) + { +- fprintf(stderr, ++ FILE *fp = rc ? stderr : stdout; ++ fprintf(fp, + "Usage: %s [OPTIONS] file [file...]\n" + " -v, --version display scrub version and exit\n" + " -p, --pattern pat select scrub pattern sequence\n" +@@ -130,8 +131,8 @@ usage(int rc) + " -h, --help display this help message\n" + , prog); + +- fprintf(stderr, "Available patterns are:\n"); +- seq_list (); ++ fprintf(fp, "Available patterns are:\n"); ++ seq_list (fp); + exit(rc); + } +