2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Add option --warning-exit-0 to exit 0 instead of 3 with warnings

This commit is contained in:
Jay Berkenbilt 2020-10-20 17:58:47 -04:00
parent 90217e6686
commit 758e3e38f5
5 changed files with 47 additions and 10 deletions

View File

@ -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.

3
TODO
View File

@ -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

View File

@ -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>

View File

@ -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
@ -2118,6 +2124,12 @@ ArgParser::argNoWarn()
o.suppress_warnings = true;
}
void
ArgParser::argWarningExitZero()
{
::EXIT_WARNING = 0;
}
void
ArgParser::argDeterministicId()
{

View File

@ -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",