diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | manual/qpdf-manual.xml | 22 | ||||
-rw-r--r-- | qpdf/qpdf.cc | 18 | ||||
-rw-r--r-- | qpdf/qtest/qpdf.test | 6 |
5 files changed, 47 insertions, 10 deletions
@@ -1,5 +1,13 @@ 2020-10-20 Jay Berkenbilt <ejb@ql.org> + * 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. @@ -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 <listitem> <para> <literal>0</literal>: 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 + <option>--warning-exit-0</option> was specified, exit status 0 + is used even if there are warnings. </para> </listitem> <listitem> @@ -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 <literal>3</literal> if it finds warnings even when - <option>--no-warn</option> is specified. + <option>--no-warn</option> is specified. With + <option>--warning-exit-0</option>, warnings without errors + exit with status 0 instead of 3. </para> </listitem> </itemizedlist> @@ -778,7 +782,19 @@ make <para> Suppress writing of warnings to stderr. If warnings were detected and suppressed, <command>qpdf</command> will still - exit with exit code 3. + exit with exit code 3. See also + <option>--warning-exit-0</option>. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term><option>--warning-exit-0</option></term> + <listitem> + <para> + If warnings are found but no errors, exit with exit code 0 + instead 3. When combined with <option>--no-warn</option>, the + effect is for <command>qpdf</command> to completely ignore + warnings. </para> </listitem> </varlistentry> 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 <qpdf/QIntC.hh> 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 @@ -2119,6 +2125,12 @@ ArgParser::argNoWarn() } void +ArgParser::argWarningExitZero() +{ + ::EXIT_WARNING = 0; +} + +void ArgParser::argDeterministicId() { o.deterministic_id = true; 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", |