Commit 758e3e38f5aceea2502179c7c4840911337f8a3f
1 parent
90217e66
Add option --warning-exit-0 to exit 0 instead of 3 with warnings
Showing
5 changed files
with
47 additions
and
10 deletions
ChangeLog
| 1 | 1 | 2020-10-20 Jay Berkenbilt <ejb@ql.org> |
| 2 | 2 | |
| 3 | + * Add --warning-exit-0 option to the qpdf command line. When | |
| 4 | + specified, qpdf will exit with a status of 0 rather than 3 when | |
| 5 | + there are warnings without errors. Combine with --no-warn to | |
| 6 | + completely ignore warnings. | |
| 7 | + | |
| 8 | + * Bug fix: fix further cases in which errors were written to | |
| 9 | + stdout. Fixes #438. | |
| 10 | + | |
| 3 | 11 | * Build option: add --disable-rpath option to ./configure, which |
| 4 | 12 | disables passing -rpath to the linker when building shared |
| 5 | 13 | libraries with libtool. Fixes #422. | ... | ... |
TODO
| 1 | 1 | Candidates for upcoming release |
| 2 | 2 | =============================== |
| 3 | 3 | |
| 4 | -* Quick issues: | |
| 5 | - * Add --warning-exit-0 option. Search for --no-warn in the docs. | |
| 6 | - | |
| 7 | 4 | * Easy build/test |
| 8 | 5 | * #352: building standalone executables (lambda layer) |
| 9 | 6 | * #460: potential malware in fuzzer seed corpus | ... | ... |
manual/qpdf-manual.xml
| ... | ... | @@ -603,7 +603,9 @@ make |
| 603 | 603 | <listitem> |
| 604 | 604 | <para> |
| 605 | 605 | <literal>0</literal>: no errors or warnings were found. The |
| 606 | - file may still have problems qpdf can't detect. | |
| 606 | + file may still have problems qpdf can't detect. If | |
| 607 | + <option>--warning-exit-0</option> was specified, exit status 0 | |
| 608 | + is used even if there are warnings. | |
| 607 | 609 | </para> |
| 608 | 610 | </listitem> |
| 609 | 611 | <listitem> |
| ... | ... | @@ -618,7 +620,9 @@ make |
| 618 | 620 | able to recover from. In some cases, the resulting file may |
| 619 | 621 | still be damaged. Note that qpdf still exits with status |
| 620 | 622 | <literal>3</literal> if it finds warnings even when |
| 621 | - <option>--no-warn</option> is specified. | |
| 623 | + <option>--no-warn</option> is specified. With | |
| 624 | + <option>--warning-exit-0</option>, warnings without errors | |
| 625 | + exit with status 0 instead of 3. | |
| 622 | 626 | </para> |
| 623 | 627 | </listitem> |
| 624 | 628 | </itemizedlist> |
| ... | ... | @@ -778,7 +782,19 @@ make |
| 778 | 782 | <para> |
| 779 | 783 | Suppress writing of warnings to stderr. If warnings were |
| 780 | 784 | detected and suppressed, <command>qpdf</command> will still |
| 781 | - exit with exit code 3. | |
| 785 | + exit with exit code 3. See also | |
| 786 | + <option>--warning-exit-0</option>. | |
| 787 | + </para> | |
| 788 | + </listitem> | |
| 789 | + </varlistentry> | |
| 790 | + <varlistentry> | |
| 791 | + <term><option>--warning-exit-0</option></term> | |
| 792 | + <listitem> | |
| 793 | + <para> | |
| 794 | + If warnings are found but no errors, exit with exit code 0 | |
| 795 | + instead 3. When combined with <option>--no-warn</option>, the | |
| 796 | + effect is for <command>qpdf</command> to completely ignore | |
| 797 | + warnings. | |
| 782 | 798 | </para> |
| 783 | 799 | </listitem> |
| 784 | 800 | </varlistentry> | ... | ... |
qpdf/qpdf.cc
| ... | ... | @@ -30,7 +30,7 @@ |
| 30 | 30 | #include <qpdf/QIntC.hh> |
| 31 | 31 | |
| 32 | 32 | static int constexpr EXIT_ERROR = 2; |
| 33 | -static int constexpr EXIT_WARNING = 3; | |
| 33 | +static int EXIT_WARNING = 3; // may be changed to 0 at runtime | |
| 34 | 34 | |
| 35 | 35 | // For is-encrypted and requires-password |
| 36 | 36 | static int constexpr EXIT_IS_NOT_ENCRYPTED = 2; |
| ... | ... | @@ -773,6 +773,7 @@ class ArgParser |
| 773 | 773 | void argVerbose(); |
| 774 | 774 | void argProgress(); |
| 775 | 775 | void argNoWarn(); |
| 776 | + void argWarningExitZero(); | |
| 776 | 777 | void argDeterministicId(); |
| 777 | 778 | void argStaticId(); |
| 778 | 779 | void argStaticAesIv(); |
| ... | ... | @@ -1017,6 +1018,7 @@ ArgParser::initOptionTable() |
| 1017 | 1018 | (*t)["verbose"] = oe_bare(&ArgParser::argVerbose); |
| 1018 | 1019 | (*t)["progress"] = oe_bare(&ArgParser::argProgress); |
| 1019 | 1020 | (*t)["no-warn"] = oe_bare(&ArgParser::argNoWarn); |
| 1021 | + (*t)["warning-exit-0"] = oe_bare(&ArgParser::argWarningExitZero); | |
| 1020 | 1022 | (*t)["deterministic-id"] = oe_bare(&ArgParser::argDeterministicId); |
| 1021 | 1023 | (*t)["static-id"] = oe_bare(&ArgParser::argStaticId); |
| 1022 | 1024 | (*t)["static-aes-iv"] = oe_bare(&ArgParser::argStaticAesIv); |
| ... | ... | @@ -1230,6 +1232,7 @@ ArgParser::argHelp() |
| 1230 | 1232 | << "--verbose provide additional informational output\n" |
| 1231 | 1233 | << "--progress give progress indicators while writing output\n" |
| 1232 | 1234 | << "--no-warn suppress warnings\n" |
| 1235 | + << "--warning-exit-0 exit with code 0 instead of 3 if there are warnings\n" | |
| 1233 | 1236 | << "--linearize generated a linearized (web optimized) file\n" |
| 1234 | 1237 | << "--replace-input use in place of specifying an output file; qpdf will\n" |
| 1235 | 1238 | << " replace the input file with the output\n" |
| ... | ... | @@ -1621,8 +1624,11 @@ ArgParser::argHelp() |
| 1621 | 1624 | << "Ordinarily, qpdf exits with a status of 0 on success or a status of 2\n" |
| 1622 | 1625 | << "if any errors occurred. If there were warnings but not errors, qpdf\n" |
| 1623 | 1626 | << "exits with a status of 3. If warnings would have been issued but --no-warn\n" |
| 1624 | - << "was given, an exit status of 3 is still used. qpdf does not use exit\n" | |
| 1625 | - << "status 1, since that is used by the shell if it can't execute qpdf.\n"; | |
| 1627 | + << "was given, an exit status of 3 is still used. If you want qpdf to exit\n" | |
| 1628 | + << "with status 0 when there are warnings, use the --warning-exit-0 flag.\n" | |
| 1629 | + << "When --no-warn and --warning-exit-0 are used together, the effect is for\n" | |
| 1630 | + << "qpdf to completely ignore warnings. qpdf does not use exit status 1,\n" | |
| 1631 | + << "since that is used by the shell if it can't execute qpdf.\n"; | |
| 1626 | 1632 | } |
| 1627 | 1633 | |
| 1628 | 1634 | void |
| ... | ... | @@ -2119,6 +2125,12 @@ ArgParser::argNoWarn() |
| 2119 | 2125 | } |
| 2120 | 2126 | |
| 2121 | 2127 | void |
| 2128 | +ArgParser::argWarningExitZero() | |
| 2129 | +{ | |
| 2130 | + ::EXIT_WARNING = 0; | |
| 2131 | +} | |
| 2132 | + | |
| 2133 | +void | |
| 2122 | 2134 | ArgParser::argDeterministicId() |
| 2123 | 2135 | { |
| 2124 | 2136 | o.deterministic_id = true; | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -2472,7 +2472,7 @@ my @badfiles = ("not a PDF file", # 1 |
| 2472 | 2472 | "startxref to space then eof", # 38 |
| 2473 | 2473 | ); |
| 2474 | 2474 | |
| 2475 | -$n_tests += @badfiles + 6; | |
| 2475 | +$n_tests += @badfiles + 7; | |
| 2476 | 2476 | |
| 2477 | 2477 | # Test 6 contains errors in the free table consistency, but we no |
| 2478 | 2478 | # longer have any consistency check for this since it is not important |
| ... | ... | @@ -2499,6 +2499,10 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i) |
| 2499 | 2499 | $td->runtest("Suppress warnings", |
| 2500 | 2500 | {$td->COMMAND => "qpdf --no-warn bad14.pdf a.pdf"}, |
| 2501 | 2501 | {$td->STRING => "", $td->EXIT_STATUS => 3}); |
| 2502 | +$td->runtest("Suppress warnings", | |
| 2503 | + {$td->COMMAND => | |
| 2504 | + "qpdf --no-warn --warning-exit-0 bad14.pdf a.pdf"}, | |
| 2505 | + {$td->STRING => "", $td->EXIT_STATUS => 0}); | |
| 2502 | 2506 | $td->runtest("Suppress warnings with --check", |
| 2503 | 2507 | {$td->COMMAND => "qpdf --check --no-warn bad14.pdf"}, |
| 2504 | 2508 | {$td->FILE => "bad14-check-no-warn.out", | ... | ... |