From 15cbdf2a18bd56a5918b03253ce68b6449924a0d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 8 May 2020 10:37:15 +0200 Subject: [PATCH] [calamares] Allow multiple instances if -d is given - Calamares doesn't like to run multiple instances, since they would interfere with each other (stealing disks from each other, for instance). The single-application code tries to prevent that. - For -d runs, for developers where presumably they know what they are doing, the single-application restriction is annoying: especially if you need two instances at once for some kind of visual comparison. Drop the single-app requirement if -d is given. --- src/calamares/main.cpp | 51 +++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index 2af46119b..4761b4fe1 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -63,7 +63,13 @@ debug_level( QCommandLineParser& parser, QCommandLineOption& levelOption ) } } -static void +/** @brief Handles the command-line arguments + * + * Sets up internals for Calamares based on command-line arguments like `-D`, + * `-d`, etc. Returns @c true if this is a *debug* run, i.e. if the `-d` + * command-line flag is given, @c false otherwise. + */ +static bool handle_args( CalamaresApplication& a ) { QCommandLineOption debugOption( QStringList { "d", "debug" }, @@ -100,8 +106,8 @@ handle_args( CalamaresApplication& a ) CalamaresUtils::setXdgDirs(); } CalamaresUtils::setAllowLocalTranslation( parser.isSet( debugOption ) || parser.isSet( debugTxOption ) ); - Calamares::Settings::init( parser.isSet( debugOption ) ); - a.init(); + + return parser.isSet( debugOption ); } int @@ -129,25 +135,30 @@ main( int argc, char* argv[] ) // TODO: umount anything in /tmp/calamares-... as an emergency save function #endif - KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); - if ( guard.isPrimaryInstance() ) - { - handle_args( a ); - return a.exec(); - } - else + bool is_debug = handle_args( a ); + + if ( !is_debug ) { - // Here we have not yet set-up the logger system, so qDebug() is ok - auto instancelist = guard.instances(); - qDebug() << "Calamares is already running, shutting down."; - if ( instancelist.count() > 0 ) - { - qDebug() << "Other running Calamares instances:"; - } - for ( const auto& i : instancelist ) + KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); + + if ( !guard.isPrimaryInstance() ) { - qDebug() << " " << i.isValid() << i.pid() << i.arguments(); + // Here we have not yet set-up the logger system, so qDebug() is ok + auto instancelist = guard.instances(); + qDebug() << "Calamares is already running, shutting down."; + if ( instancelist.count() > 0 ) + { + qDebug() << "Other running Calamares instances:"; + } + for ( const auto& i : instancelist ) + { + qDebug() << " " << i.isValid() << i.pid() << i.arguments(); + } + return 69; // EX_UNAVAILABLE on FreeBSD } - return 69; // EX_UNAVAILABLE on FreeBSD } + + Calamares::Settings::init( is_debug ); + a.init(); + return a.exec(); }