diff --git a/src/modules/contextualprocess/ContextualProcessJob.cpp b/src/modules/contextualprocess/ContextualProcessJob.cpp index 50a28f417..6744db054 100644 --- a/src/modules/contextualprocess/ContextualProcessJob.cpp +++ b/src/modules/contextualprocess/ContextualProcessJob.cpp @@ -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 ) { diff --git a/src/modules/contextualprocess/ContextualProcessJob.h b/src/modules/contextualprocess/ContextualProcessJob.h index aea09aa9b..e8a39c3f4 100644 --- a/src/modules/contextualprocess/ContextualProcessJob.h +++ b/src/modules/contextualprocess/ContextualProcessJob.h @@ -45,7 +45,6 @@ public: private: QList m_commands; - bool m_dontChroot; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( ContextualProcessJobFactory ) diff --git a/src/modules/contextualprocess/contextualprocess.conf b/src/modules/contextualprocess/contextualprocess.conf index 4252d1043..20668e1ce 100644 --- a/src/modules/contextualprocess/contextualprocess.conf +++ b/src/modules/contextualprocess/contextualprocess.conf @@ -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" diff --git a/src/modules/shellprocess/ShellProcessJob.cpp b/src/modules/shellprocess/ShellProcessJob.cpp index 45b8b2537..5c14284ec 100644 --- a/src/modules/shellprocess/ShellProcessJob.cpp +++ b/src/modules/shellprocess/ShellProcessJob.cpp @@ -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(); } diff --git a/src/modules/shellprocess/ShellProcessJob.h b/src/modules/shellprocess/ShellProcessJob.h index afc58fdc7..3111fc26e 100644 --- a/src/modules/shellprocess/ShellProcessJob.h +++ b/src/modules/shellprocess/ShellProcessJob.h @@ -46,7 +46,6 @@ public: private: CalamaresUtils::CommandList* m_commands; - bool m_dontChroot; }; CALAMARES_PLUGIN_FACTORY_DECLARATION( ShellProcessJobFactory ) diff --git a/src/modules/shellprocess/Tests.cpp b/src/modules/shellprocess/Tests.cpp index c406fde17..c6643325f 100644 --- a/src/modules/shellprocess/Tests.cpp +++ b/src/modules/shellprocess/Tests.cpp @@ -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() diff --git a/src/modules/shellprocess/shellprocess.conf b/src/modules/shellprocess/shellprocess.conf index 3735db987..ff53dc228 100644 --- a/src/modules/shellprocess/shellprocess.conf +++ b/src/modules/shellprocess/shellprocess.conf @@ -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