From 758e3e38f5aceea2502179c7c4840911337f8a3f Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 20 Oct 2020 17:58:47 -0400 Subject: Add option --warning-exit-0 to exit 0 instead of 3 with warnings --- ChangeLog | 8 ++++++++ TODO | 3 --- manual/qpdf-manual.xml | 22 +++++++++++++++++++--- qpdf/qpdf.cc | 18 +++++++++++++++--- qpdf/qtest/qpdf.test | 6 +++++- 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2fbf7fad..3c748cc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2020-10-20 Jay Berkenbilt + * Add --warning-exit-0 option to the qpdf command line. When + specified, qpdf will exit with a status of 0 rather than 3 when + there are warnings without errors. Combine with --no-warn to + completely ignore warnings. + + * Bug fix: fix further cases in which errors were written to + stdout. Fixes #438. + * Build option: add --disable-rpath option to ./configure, which disables passing -rpath to the linker when building shared libraries with libtool. Fixes #422. diff --git a/TODO b/TODO index e872e8b6..98512644 100644 --- a/TODO +++ b/TODO @@ -1,9 +1,6 @@ Candidates for upcoming release =============================== -* Quick issues: - * Add --warning-exit-0 option. Search for --no-warn in the docs. - * Easy build/test * #352: building standalone executables (lambda layer) * #460: potential malware in fuzzer seed corpus diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml index 9579562c..866a5016 100644 --- a/manual/qpdf-manual.xml +++ b/manual/qpdf-manual.xml @@ -603,7 +603,9 @@ make 0: no errors or warnings were found. The - file may still have problems qpdf can't detect. + file may still have problems qpdf can't detect. If + was specified, exit status 0 + is used even if there are warnings. @@ -618,7 +620,9 @@ make able to recover from. In some cases, the resulting file may still be damaged. Note that qpdf still exits with status 3 if it finds warnings even when - is specified. + is specified. With + , warnings without errors + exit with status 0 instead of 3. @@ -778,7 +782,19 @@ make Suppress writing of warnings to stderr. If warnings were detected and suppressed, qpdf will still - exit with exit code 3. + exit with exit code 3. See also + . + + + + + + + + If warnings are found but no errors, exit with exit code 0 + instead 3. When combined with , the + effect is for qpdf to completely ignore + warnings. diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index b7ac6fc0..4bb00561 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -30,7 +30,7 @@ #include static int constexpr EXIT_ERROR = 2; -static int constexpr EXIT_WARNING = 3; +static int EXIT_WARNING = 3; // may be changed to 0 at runtime // For is-encrypted and requires-password static int constexpr EXIT_IS_NOT_ENCRYPTED = 2; @@ -773,6 +773,7 @@ class ArgParser void argVerbose(); void argProgress(); void argNoWarn(); + void argWarningExitZero(); void argDeterministicId(); void argStaticId(); void argStaticAesIv(); @@ -1017,6 +1018,7 @@ ArgParser::initOptionTable() (*t)["verbose"] = oe_bare(&ArgParser::argVerbose); (*t)["progress"] = oe_bare(&ArgParser::argProgress); (*t)["no-warn"] = oe_bare(&ArgParser::argNoWarn); + (*t)["warning-exit-0"] = oe_bare(&ArgParser::argWarningExitZero); (*t)["deterministic-id"] = oe_bare(&ArgParser::argDeterministicId); (*t)["static-id"] = oe_bare(&ArgParser::argStaticId); (*t)["static-aes-iv"] = oe_bare(&ArgParser::argStaticAesIv); @@ -1230,6 +1232,7 @@ ArgParser::argHelp() << "--verbose provide additional informational output\n" << "--progress give progress indicators while writing output\n" << "--no-warn suppress warnings\n" + << "--warning-exit-0 exit with code 0 instead of 3 if there are warnings\n" << "--linearize generated a linearized (web optimized) file\n" << "--replace-input use in place of specifying an output file; qpdf will\n" << " replace the input file with the output\n" @@ -1621,8 +1624,11 @@ ArgParser::argHelp() << "Ordinarily, qpdf exits with a status of 0 on success or a status of 2\n" << "if any errors occurred. If there were warnings but not errors, qpdf\n" << "exits with a status of 3. If warnings would have been issued but --no-warn\n" - << "was given, an exit status of 3 is still used. qpdf does not use exit\n" - << "status 1, since that is used by the shell if it can't execute qpdf.\n"; + << "was given, an exit status of 3 is still used. If you want qpdf to exit\n" + << "with status 0 when there are warnings, use the --warning-exit-0 flag.\n" + << "When --no-warn and --warning-exit-0 are used together, the effect is for\n" + << "qpdf to completely ignore warnings. qpdf does not use exit status 1,\n" + << "since that is used by the shell if it can't execute qpdf.\n"; } void @@ -2118,6 +2124,12 @@ ArgParser::argNoWarn() o.suppress_warnings = true; } +void +ArgParser::argWarningExitZero() +{ + ::EXIT_WARNING = 0; +} + void ArgParser::argDeterministicId() { diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index d7986c21..71f55636 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -2472,7 +2472,7 @@ my @badfiles = ("not a PDF file", # 1 "startxref to space then eof", # 38 ); -$n_tests += @badfiles + 6; +$n_tests += @badfiles + 7; # Test 6 contains errors in the free table consistency, but we no # longer have any consistency check for this since it is not important @@ -2499,6 +2499,10 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i) $td->runtest("Suppress warnings", {$td->COMMAND => "qpdf --no-warn bad14.pdf a.pdf"}, {$td->STRING => "", $td->EXIT_STATUS => 3}); +$td->runtest("Suppress warnings", + {$td->COMMAND => + "qpdf --no-warn --warning-exit-0 bad14.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); $td->runtest("Suppress warnings with --check", {$td->COMMAND => "qpdf --check --no-warn bad14.pdf"}, {$td->FILE => "bad14-check-no-warn.out", -- cgit v1.2.3-54-g00ecf