[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.
main
Adriaan de Groot 5 years ago
parent 401a34fcbd
commit 15cbdf2a18

@ -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 ) handle_args( CalamaresApplication& a )
{ {
QCommandLineOption debugOption( QStringList { "d", "debug" }, QCommandLineOption debugOption( QStringList { "d", "debug" },
@ -100,8 +106,8 @@ handle_args( CalamaresApplication& a )
CalamaresUtils::setXdgDirs(); CalamaresUtils::setXdgDirs();
} }
CalamaresUtils::setAllowLocalTranslation( parser.isSet( debugOption ) || parser.isSet( debugTxOption ) ); CalamaresUtils::setAllowLocalTranslation( parser.isSet( debugOption ) || parser.isSet( debugTxOption ) );
Calamares::Settings::init( parser.isSet( debugOption ) );
a.init(); return parser.isSet( debugOption );
} }
int int
@ -129,25 +135,30 @@ main( int argc, char* argv[] )
// TODO: umount anything in /tmp/calamares-... as an emergency save function // TODO: umount anything in /tmp/calamares-... as an emergency save function
#endif #endif
KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); bool is_debug = handle_args( a );
if ( guard.isPrimaryInstance() )
{ if ( !is_debug )
handle_args( a );
return a.exec();
}
else
{ {
// Here we have not yet set-up the logger system, so qDebug() is ok KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances );
auto instancelist = guard.instances();
qDebug() << "Calamares is already running, shutting down."; if ( !guard.isPrimaryInstance() )
if ( instancelist.count() > 0 )
{
qDebug() << "Other running Calamares instances:";
}
for ( const auto& i : instancelist )
{ {
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();
} }

Loading…
Cancel
Save