[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
|
void
|
||||||
ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
|
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 )
|
for ( QVariantMap::const_iterator iter = configurationMap.cbegin(); iter != configurationMap.cend(); ++iter )
|
||||||
{
|
{
|
||||||
QString variableName = iter.key();
|
QString variableName = iter.key();
|
||||||
if ( variableName.isEmpty() || ( variableName == "dontChroot" ) )
|
if ( variableName.isEmpty() || ( variableName == "dontChroot" ) || ( variableName == "timeout" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ( iter.value().type() != QVariant::Map )
|
if ( iter.value().type() != QVariant::Map )
|
||||||
@ -121,7 +124,7 @@ ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
continue;
|
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 )
|
if ( commands->count() > 0 )
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ContextualProcessBinding*> m_commands;
|
QList<ContextualProcessBinding*> m_commands;
|
||||||
bool m_dontChroot;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( ContextualProcessJobFactory )
|
CALAMARES_PLUGIN_FACTORY_DECLARATION( ContextualProcessJobFactory )
|
||||||
|
@ -4,14 +4,13 @@
|
|||||||
# When a given global value (string) equals a given value, then
|
# When a given global value (string) equals a given value, then
|
||||||
# the associated command is executed.
|
# the associated command is executed.
|
||||||
#
|
#
|
||||||
# The special configuration key *dontChroot* specifies whether
|
# The special top-level keys *dontChroot* and *timeout* have
|
||||||
# the commands are run in the target system (default, value *false*),
|
# meaning just like in shellprocess.conf. They are excluded from
|
||||||
# or in the host system. This key is not used for comparisons
|
# the comparison with global variables.
|
||||||
# with global configuration values.
|
|
||||||
#
|
#
|
||||||
# Configuration consists of keys for global variable names (except
|
# Configuration consists of keys for global variable names (except
|
||||||
# *dontChroot*), and the sub-keys are strings to compare to the
|
# *dontChroot* and *timeout*), and the sub-keys are strings to compare
|
||||||
# variable's value. If the variable has that particular value, the
|
# to the variable's value. If the variable has that particular value, the
|
||||||
# corresponding value (script) is executed.
|
# corresponding value (script) is executed.
|
||||||
#
|
#
|
||||||
# You can check for an empty value with "".
|
# You can check for an empty value with "".
|
||||||
@ -31,6 +30,7 @@ dontChroot: false
|
|||||||
firmwareType:
|
firmwareType:
|
||||||
efi:
|
efi:
|
||||||
- "-pkg remove efi-firmware"
|
- "-pkg remove efi-firmware"
|
||||||
- "-mkinitramfsrd -abgn"
|
- command: "-mkinitramfsrd -abgn"
|
||||||
|
timeout: 120 # This is slow
|
||||||
bios: "-pkg remove bios-firmware"
|
bios: "-pkg remove bios-firmware"
|
||||||
"": "/bin/false no-firmware-type-set"
|
"": "/bin/false no-firmware-type-set"
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
ShellProcessJob::ShellProcessJob( QObject* parent )
|
ShellProcessJob::ShellProcessJob( QObject* parent )
|
||||||
: Calamares::CppJob( parent )
|
: Calamares::CppJob( parent )
|
||||||
, m_commands( nullptr )
|
, m_commands( nullptr )
|
||||||
, m_dontChroot( false )
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,11 +69,14 @@ ShellProcessJob::exec()
|
|||||||
void
|
void
|
||||||
ShellProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
|
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" ) )
|
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() )
|
if ( m_commands->isEmpty() )
|
||||||
cDebug() << "ShellProcessJob: \"script\" contains no commands for" << moduleInstanceKey();
|
cDebug() << "ShellProcessJob: \"script\" contains no commands for" << moduleInstanceKey();
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
CalamaresUtils::CommandList* m_commands;
|
CalamaresUtils::CommandList* m_commands;
|
||||||
bool m_dontChroot;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DECLARATION( ShellProcessJobFactory )
|
CALAMARES_PLUGIN_FACTORY_DECLARATION( ShellProcessJobFactory )
|
||||||
|
@ -64,7 +64,9 @@ ShellProcessTests::testProcessListSampleConfig()
|
|||||||
CommandList cl(
|
CommandList cl(
|
||||||
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
||||||
QVERIFY( !cl.isEmpty() );
|
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()
|
void ShellProcessTests::testProcessListFromList()
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
# system from the point of view of the command (for chrooted
|
# system from the point of view of the command (for chrooted
|
||||||
# commands, that will be */*).
|
# 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
|
# If a command starts with "-" (a single minus sign), then the
|
||||||
# return value of the command following the - is ignored; otherwise,
|
# return value of the command following the - is ignored; otherwise,
|
||||||
# a failing command will abort the installation. This is much like
|
# 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 single string; this is one command that is executed.
|
||||||
# - a list of strings; these are executed one at a time, by
|
# - a list of strings; these are executed one at a time, by
|
||||||
# separate shells (/bin/sh -c is invoked for each command).
|
# 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
|
dontChroot: false
|
||||||
|
timeout: 10
|
||||||
script:
|
script:
|
||||||
- "-touch @@ROOT@@/tmp/thingy"
|
- "-touch @@ROOT@@/tmp/thingy"
|
||||||
- "/usr/bin/false"
|
- "/usr/bin/false"
|
||||||
|
- command: "/usr/local/bin/slowloris"
|
||||||
|
timeout: 3600
|
||||||
|
Loading…
Reference in New Issue
Block a user