[shellprocess] Implement timeout setting
- For both shellprocess and contextualprocess, add a top-level key "timeout" that defaults to 10 seconds (which it already did). - Allows setting "global" timeout for command-lists, while still allowing individual timeouts per-command. - Setting timeout per global variable in contextualprocess is not supported; that would restrict the possible space of comparisions, while not supporting a global setting timeout seems reasonable enough. Use instances if you need wildly variable timeouts and don't want to set them individually.
This commit is contained in:
parent
2da430fa36
commit
c2aca1f5c6
@ -97,12 +97,15 @@ ContextualProcessJob::exec()
|
||||
void
|
||||
ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
m_dontChroot = CalamaresUtils::getBool( configurationMap, "dontChroot", false );
|
||||
bool dontChroot = CalamaresUtils::getBool( configurationMap, "dontChroot", false );
|
||||
int timeout = CalamaresUtils::getInteger( configurationMap, "timeout", 10 );
|
||||
if ( timeout < 1 )
|
||||
timeout = 10;
|
||||
|
||||
for ( QVariantMap::const_iterator iter = configurationMap.cbegin(); iter != configurationMap.cend(); ++iter )
|
||||
{
|
||||
QString variableName = iter.key();
|
||||
if ( variableName.isEmpty() || ( variableName == "dontChroot" ) )
|
||||
if ( variableName.isEmpty() || ( variableName == "dontChroot" ) || ( variableName == "timeout" ) )
|
||||
continue;
|
||||
|
||||
if ( iter.value().type() != QVariant::Map )
|
||||
@ -121,7 +124,7 @@ ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
continue;
|
||||
}
|
||||
|
||||
CalamaresUtils::CommandList* commands = new CalamaresUtils::CommandList( valueiter.value(), !m_dontChroot );
|
||||
CalamaresUtils::CommandList* commands = new CalamaresUtils::CommandList( valueiter.value(), !dontChroot, timeout );
|
||||
|
||||
if ( commands->count() > 0 )
|
||||
{
|
||||
|
@ -45,7 +45,6 @@ public:
|
||||
|
||||
private:
|
||||
QList<ContextualProcessBinding*> m_commands;
|
||||
bool m_dontChroot;
|
||||
};
|
||||
|
||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( ContextualProcessJobFactory )
|
||||
|
@ -4,14 +4,13 @@
|
||||
# When a given global value (string) equals a given value, then
|
||||
# the associated command is executed.
|
||||
#
|
||||
# The special configuration key *dontChroot* specifies whether
|
||||
# the commands are run in the target system (default, value *false*),
|
||||
# or in the host system. This key is not used for comparisons
|
||||
# with global configuration values.
|
||||
# The special top-level keys *dontChroot* and *timeout* have
|
||||
# meaning just like in shellprocess.conf. They are excluded from
|
||||
# the comparison with global variables.
|
||||
#
|
||||
# Configuration consists of keys for global variable names (except
|
||||
# *dontChroot*), and the sub-keys are strings to compare to the
|
||||
# variable's value. If the variable has that particular value, the
|
||||
# *dontChroot* and *timeout*), and the sub-keys are strings to compare
|
||||
# to the variable's value. If the variable has that particular value, the
|
||||
# corresponding value (script) is executed.
|
||||
#
|
||||
# You can check for an empty value with "".
|
||||
@ -31,6 +30,7 @@ dontChroot: false
|
||||
firmwareType:
|
||||
efi:
|
||||
- "-pkg remove efi-firmware"
|
||||
- "-mkinitramfsrd -abgn"
|
||||
- command: "-mkinitramfsrd -abgn"
|
||||
timeout: 120 # This is slow
|
||||
bios: "-pkg remove bios-firmware"
|
||||
"": "/bin/false no-firmware-type-set"
|
||||
|
@ -34,7 +34,6 @@
|
||||
ShellProcessJob::ShellProcessJob( QObject* parent )
|
||||
: Calamares::CppJob( parent )
|
||||
, m_commands( nullptr )
|
||||
, m_dontChroot( false )
|
||||
{
|
||||
}
|
||||
|
||||
@ -70,11 +69,14 @@ ShellProcessJob::exec()
|
||||
void
|
||||
ShellProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
|
||||
{
|
||||
m_dontChroot = CalamaresUtils::getBool( configurationMap, "dontChroot", false );
|
||||
bool dontChroot = CalamaresUtils::getBool( configurationMap, "dontChroot", false );
|
||||
int timeout = CalamaresUtils::getInteger( configurationMap, "timeout", 10 );
|
||||
if ( timeout < 1 )
|
||||
timeout = 10;
|
||||
|
||||
if ( configurationMap.contains( "script" ) )
|
||||
{
|
||||
m_commands = new CalamaresUtils::CommandList( configurationMap.value( "script" ), !m_dontChroot );
|
||||
m_commands = new CalamaresUtils::CommandList( configurationMap.value( "script" ), !dontChroot, timeout );
|
||||
if ( m_commands->isEmpty() )
|
||||
cDebug() << "ShellProcessJob: \"script\" contains no commands for" << moduleInstanceKey();
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ public:
|
||||
|
||||
private:
|
||||
CalamaresUtils::CommandList* m_commands;
|
||||
bool m_dontChroot;
|
||||
};
|
||||
|
||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( ShellProcessJobFactory )
|
||||
|
@ -64,7 +64,9 @@ ShellProcessTests::testProcessListSampleConfig()
|
||||
CommandList cl(
|
||||
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
||||
QVERIFY( !cl.isEmpty() );
|
||||
QCOMPARE( cl.count(), 2 );
|
||||
QCOMPARE( cl.count(), 3 );
|
||||
QCOMPARE( cl.at(0).timeout(), -1 );
|
||||
QCOMPARE( cl.at(2).timeout(), 3600 ); // slowloris
|
||||
}
|
||||
|
||||
void ShellProcessTests::testProcessListFromList()
|
||||
|
@ -8,6 +8,10 @@
|
||||
# system from the point of view of the command (for chrooted
|
||||
# commands, that will be */*).
|
||||
#
|
||||
# The (global) timeout for the command list can be set with
|
||||
# the *timeout* key. The value is a time in seconds, default
|
||||
# is 10 seconds if not set.
|
||||
#
|
||||
# If a command starts with "-" (a single minus sign), then the
|
||||
# return value of the command following the - is ignored; otherwise,
|
||||
# a failing command will abort the installation. This is much like
|
||||
@ -17,8 +21,14 @@
|
||||
# - a single string; this is one command that is executed.
|
||||
# - a list of strings; these are executed one at a time, by
|
||||
# separate shells (/bin/sh -c is invoked for each command).
|
||||
# - an object, specifying a key *command* and (optionally)
|
||||
# a key *timeout* to set the timeout for this specific
|
||||
# command differently from the global setting.
|
||||
---
|
||||
dontChroot: false
|
||||
timeout: 10
|
||||
script:
|
||||
- "-touch @@ROOT@@/tmp/thingy"
|
||||
- "/usr/bin/false"
|
||||
- command: "/usr/local/bin/slowloris"
|
||||
timeout: 3600
|
||||
|
Loading…
Reference in New Issue
Block a user