From c0daf13947e3caf62093b04b5aac2039ae2c0aff Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Tue, 5 Sep 2017 13:37:20 +0200 Subject: [PATCH] Return '107' if some rpm %post configuration script failed (bsc#1047233) --- doc/zypper.8 | 10 ++++++++-- doc/zypper.8.txt | 3 +++ src/callbacks/rpm.h | 41 +++++++++++++++++++++++++++++++++-------- src/main.h | 1 + 4 files changed, 45 insertions(+), 10 deletions(-) diff --git a/doc/zypper.8 b/doc/zypper.8 index 079199109a..f4bfcb337f 100644 --- a/doc/zypper.8 +++ b/doc/zypper.8 @@ -2,12 +2,12 @@ .\" Title: zypper .\" Author: [see the "AUTHORS" section] .\" Generator: DocBook XSL Stylesheets v1.78.1 -.\" Date: 08/09/2017 +.\" Date: 09/05/2017 .\" Manual: ZYPPER .\" Source: SUSE Linux .\" Language: English .\" -.TH "ZYPPER" "8" "08/09/2017" "SUSE Linux" "ZYPPER" +.TH "ZYPPER" "8" "09/05/2017" "SUSE Linux" "ZYPPER" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -3814,6 +3814,12 @@ Returned upon exiting after receiving a SIGINT or SIGTERM\&. Some repository had to be disabled temporarily because it failed to refresh\&. You should check your repository configuration (e\&.g\&. \fBzypper ref \-f\fR)\&. .RE +.PP +\fB107\fR \- \fBZYPPER_EXIT_INF_RPM_SCRIPT_FAILED\fR +.RS 4 +Installation basically succeeded, but some of the packages %post install scripts returned an error\&. These packages were successfully unpacked to disk and are registered in the rpm database, but due to the failed install script they may not work as expected\&. The failed scripts output might reveal what actually went wrong\&. Any scripts output is also logged to +\fB/var/log/zypp/history\fR\&. +.RE .sp Zypper subcommands (see section \fBSUBCOMMANDS\fR) may return \fBdifferent codes\fR which should be described in the commands man page\&. Call \fBzypper help \fR\fB\fIsubcommand\fR\fR to see the subcommands man page if one is provided\&. .SH "HOMEPAGE" diff --git a/doc/zypper.8.txt b/doc/zypper.8.txt index 472d981718..47917c30a2 100644 --- a/doc/zypper.8.txt +++ b/doc/zypper.8.txt @@ -1762,6 +1762,9 @@ There are several exit codes defined for zypper built-in commands for use e.g. w Returned upon exiting after receiving a SIGINT or SIGTERM. *106* - *ZYPPER_EXIT_INF_REPOS_SKIPPED*:: Some repository had to be disabled temporarily because it failed to refresh. You should check your repository configuration (e.g. *zypper ref -f*). +*107* - *ZYPPER_EXIT_INF_RPM_SCRIPT_FAILED*:: + Installation basically succeeded, but some of the packages %post install scripts returned an error. These packages were successfully unpacked to disk and are registered in the rpm database, but due to the failed install script they may not work as expected. The failed scripts output might reveal what actually went wrong. Any scripts output is also logged to */var/log/zypp/history*. + Zypper subcommands (see section *SUBCOMMANDS*) may return *different codes* which should be described in the commands man page. Call *zypper help 'subcommand'* to see the subcommands man page if one is provided. diff --git a/src/callbacks/rpm.h b/src/callbacks/rpm.h index 97240a2ffa..c147cd2bf3 100644 --- a/src/callbacks/rpm.h +++ b/src/callbacks/rpm.h @@ -13,7 +13,9 @@ #include #include +#include #include +#include #include #include #include @@ -34,6 +36,33 @@ namespace str::replaceAll( translatedFormat_r, "%s-%s", "%s" ); return str::Format( translatedFormat_r) % ident_r; } + + /** Print additional rpm outout and scan for %script errors. */ + void processAdditionalRpmOutput( const std::string & output_r ) + { + if ( ! output_r.empty() ) + { + std::istringstream input( output_r ); + + Out::Info info( Zypper::instance().out() ); + ColorStream msg( info << "", ColorContext::HIGHLIGHT ); + for ( iostr::EachLine in( input ); in; in.next() ) + { + const std::string & line( *in ); + + static str::regex rx("^(warning|error): %.* scriptlet failed, "); + static str::smatch what; + if ( str::regex_match( line, what, rx ) ) + { + msg << ( (line[0] == 'w' ? ColorContext::MSG_WARNING : ColorContext::MSG_ERROR) << *in ) << endl; + Zypper::instance().setExitInfoCode( ZYPPER_EXIT_INF_RPM_SCRIPT_FAILED ); + } + else + msg << *in << endl; + } + } + } + } // namespace /////////////////////////////////////////////////////////////////// @@ -273,10 +302,8 @@ struct RemoveResolvableReportReceiver : public callback::ReceiveReport