Skip to content

Commit

Permalink
Return '107' if some rpm %post configuration script failed (bsc#1047233)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandres committed Sep 5, 2017
1 parent 05674a0 commit c0daf13
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
10 changes: 8 additions & 2 deletions doc/zypper.8
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: zypper
.\" Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\" 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
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions doc/zypper.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
41 changes: 33 additions & 8 deletions src/callbacks/rpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include <ctime>

#include <zypp/base/Logger.h>
#include <zypp/base/IOStream.h>
#include <zypp/base/String.h>
#include <zypp/base/Regex.h>
#include <zypp/sat/Queue.h>
#include <zypp/sat/FileConflicts.h>
#include <zypp/ZYppCallbacks.h>
Expand All @@ -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
///////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -273,10 +302,8 @@ struct RemoveResolvableReportReceiver : public callback::ReceiveReport<target::r
Zypper::instance().setExitCode(ZYPPER_EXIT_ERR_ZYPP);
else
{
// print additional rpm output
// bnc #369450
if ( !reason.empty() )
Zypper::instance().out().info(reason);
// bnc #369450: print additional rpm output
processAdditionalRpmOutput( reason );
}
}

Expand Down Expand Up @@ -347,10 +374,8 @@ struct InstallResolvableReportReceiver : public callback::ReceiveReport<target::
Zypper::instance().setExitCode(ZYPPER_EXIT_ERR_ZYPP);
else
{
// print additional rpm output
// bnc #369450
if ( !reason.empty() )
Zypper::instance().out().info(reason);
// bnc #369450: print additional rpm output
processAdditionalRpmOutput( reason );
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define ZYPPER_EXIT_INF_CAP_NOT_FOUND 104 // given capability not found (for install/remove)
#define ZYPPER_EXIT_ON_SIGNAL 105 // SIGINT or SIGTERM received (HOW CAN THIS BE 'info'?)
#define ZYPPER_EXIT_INF_REPOS_SKIPPED 106 // some repos have been skipped due to refresh errors
#define ZYPPER_EXIT_INF_RPM_SCRIPT_FAILED 107 // some rpm %post configuration script failed

// undefine _, N_ and PL_ macros from libzypp
#ifdef _
Expand Down

0 comments on commit c0daf13

Please sign in to comment.