[libcalamares] Fix up Runner (as a replacement for current system code)
This commit is contained in:
parent
24ca64deac
commit
89824a9e0d
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
#include "JobQueue.h"
|
#include "JobQueue.h"
|
||||||
|
#include "Settings.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
/** @brief Descend from directory, always relative
|
/** @brief Descend from directory, always relative
|
||||||
@ -129,10 +130,12 @@ Calamares::Utils::Runner::run()
|
|||||||
return ProcessResult::Code::NoWorkingDirectory;
|
return ProcessResult::Code::NoWorkingDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessChannelMode( QProcess::MergedChannels );
|
process.setProcessChannelMode( QProcess::MergedChannels );
|
||||||
process.setWorkingDirectory( workingDirectory.absolutePath() );
|
if ( !m_directory.isEmpty() )
|
||||||
|
{
|
||||||
|
process.setWorkingDirectory( workingDirectory.absolutePath() );
|
||||||
|
}
|
||||||
if ( m_location == RunLocation::RunInTarget )
|
if ( m_location == RunLocation::RunInTarget )
|
||||||
{
|
{
|
||||||
process.setProgram( "chroot" );
|
process.setProgram( "chroot" );
|
||||||
@ -144,40 +147,25 @@ Calamares::Utils::Runner::run()
|
|||||||
process.setArguments( m_command );
|
process.setArguments( m_command );
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProcessResult::Code::Crashed;
|
cDebug() << Logger::SubEntry << "Running" << Logger::Redacted( m_command );
|
||||||
#if 0
|
|
||||||
if ( !workingPath.isEmpty() )
|
|
||||||
{
|
|
||||||
if ( QDir( workingPath ).exists() )
|
|
||||||
{
|
|
||||||
process.setWorkingDirectory( QDir( workingPath ).absolutePath() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cWarning() << "Invalid working directory:" << workingPath;
|
|
||||||
return ProcessResult::Code::NoWorkingDirectory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cDebug() << Logger::SubEntry << "Running" << program << RedactedList( arguments );
|
|
||||||
process.start();
|
process.start();
|
||||||
if ( !process.waitForStarted() )
|
if ( !process.waitForStarted() )
|
||||||
{
|
{
|
||||||
cWarning() << "Process" << args.first() << "failed to start" << process.error();
|
cWarning() << "Process" << m_command.first() << "failed to start" << process.error();
|
||||||
return ProcessResult::Code::FailedToStart;
|
return ProcessResult::Code::FailedToStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !stdInput.isEmpty() )
|
if ( !m_input.isEmpty() )
|
||||||
{
|
{
|
||||||
process.write( stdInput.toLocal8Bit() );
|
process.write( m_input.toLocal8Bit() );
|
||||||
}
|
}
|
||||||
process.closeWriteChannel();
|
process.closeWriteChannel();
|
||||||
|
|
||||||
if ( !process.waitForFinished( timeoutSec > std::chrono::seconds::zero()
|
if ( !process.waitForFinished( m_timeout > std::chrono::seconds::zero()
|
||||||
? ( static_cast< int >( std::chrono::milliseconds( timeoutSec ).count() ) )
|
? ( static_cast< int >( std::chrono::milliseconds( m_timeout ).count() ) )
|
||||||
: -1 ) )
|
: -1 ) )
|
||||||
{
|
{
|
||||||
cWarning() << "Process" << args.first() << "timed out after" << timeoutSec.count() << "s. Output so far:\n"
|
cWarning() << "Process" << m_command.first() << "timed out after" << m_timeout.count() << "ms. Output so far:\n"
|
||||||
<< Logger::NoQuote << process.readAllStandardOutput();
|
<< Logger::NoQuote << process.readAllStandardOutput();
|
||||||
return ProcessResult::Code::TimedOut;
|
return ProcessResult::Code::TimedOut;
|
||||||
}
|
}
|
||||||
@ -186,12 +174,12 @@ Calamares::Utils::Runner::run()
|
|||||||
|
|
||||||
if ( process.exitStatus() == QProcess::CrashExit )
|
if ( process.exitStatus() == QProcess::CrashExit )
|
||||||
{
|
{
|
||||||
cWarning() << "Process" << args.first() << "crashed. Output so far:\n" << Logger::NoQuote << output;
|
cWarning() << "Process" << m_command.first() << "crashed. Output so far:\n" << Logger::NoQuote << output;
|
||||||
return ProcessResult::Code::Crashed;
|
return ProcessResult::Code::Crashed;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto r = process.exitCode();
|
auto r = process.exitCode();
|
||||||
bool showDebug = ( !Calamares::Settings::instance() ) || ( Calamares::Settings::instance()->debugMode() );
|
const bool showDebug = ( !Calamares::Settings::instance() ) || ( Calamares::Settings::instance()->debugMode() );
|
||||||
if ( r == 0 )
|
if ( r == 0 )
|
||||||
{
|
{
|
||||||
if ( showDebug && !output.isEmpty() )
|
if ( showDebug && !output.isEmpty() )
|
||||||
@ -203,14 +191,15 @@ Calamares::Utils::Runner::run()
|
|||||||
{
|
{
|
||||||
if ( !output.isEmpty() )
|
if ( !output.isEmpty() )
|
||||||
{
|
{
|
||||||
cDebug() << Logger::SubEntry << "Target cmd:" << RedactedList( args ) << "Exit code:" << r << "output:\n"
|
cDebug() << Logger::SubEntry << "Target cmd:" << Logger::Redacted( m_command ) << "Exit code:" << r
|
||||||
|
<< "output:\n"
|
||||||
<< Logger::NoQuote << output;
|
<< Logger::NoQuote << output;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cDebug() << Logger::SubEntry << "Target cmd:" << RedactedList( args ) << "Exit code:" << r << "(no output)";
|
cDebug() << Logger::SubEntry << "Target cmd:" << Logger::Redacted( m_command ) << "Exit code:" << r
|
||||||
|
<< "(no output)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ProcessResult( r, output );
|
return ProcessResult( r, output );
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,8 @@ public:
|
|||||||
Runner();
|
Runner();
|
||||||
/** @brief Create a runner with a specified command
|
/** @brief Create a runner with a specified command
|
||||||
*
|
*
|
||||||
* Equivalent to Calamares::Utils::Runner::Runner()
|
* Equivalent to Calamares::Utils::Runner::Runner() followed by
|
||||||
|
* calling setCommand().
|
||||||
*/
|
*/
|
||||||
Runner( const QStringList& command );
|
Runner( const QStringList& command );
|
||||||
virtual ~Runner() override;
|
virtual ~Runner() override;
|
||||||
|
Loading…
Reference in New Issue
Block a user