From 15cbdf2a18bd56a5918b03253ce68b6449924a0d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 8 May 2020 10:37:15 +0200 Subject: [PATCH 1/3] [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(); } From 5af2a87709608ab39371892316ae7d326fc2ee8f Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 8 May 2020 13:01:33 +0200 Subject: [PATCH 2/3] [calamares] Remove redundant KF5/ in includes - We link to these frameworks, which gives us a KF5 include path already --- src/calamares/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index 4761b4fe1..d460e44e3 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -27,9 +27,9 @@ #include "3rdparty/kdsingleapplicationguard/kdsingleapplicationguard.h" -#include +#include #ifdef WITH_KF5Crash -#include +#include #endif #include From b7214b8edeec687c99bfebba28ad4a42af77148a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 8 May 2020 15:22:15 +0200 Subject: [PATCH 3/3] [calamares] Switch over to DBus unique activation - By default, try to use DBus service to keep Calamares unique - The older implementation via KDSingleApplicationGuard is still available, just not used by default. --- CMakeLists.txt | 13 +++++++++++- src/calamares/CMakeLists.txt | 9 +++++---- src/calamares/main.cpp | 39 +++++++++++++++++++++--------------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6edece315..8603099db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ option( BUILD_TESTING "Build the testing tree." ON ) option( WITH_PYTHON "Enable Python modules API (requires Boost.Python)." ON ) option( WITH_PYTHONQT "Enable next generation Python modules API (experimental, requires PythonQt)." OFF ) option( WITH_KF5Crash "Enable crash reporting with KCrash." ON ) +option( WITH_KF5DBus "Use DBus service for unique-application." ON ) # Possible debugging flags are: # - DEBUG_TIMEZONES draws latitude and longitude lines on the timezone @@ -290,7 +291,7 @@ if( ECM_FOUND ) include(KDEInstallDirs) endif() -find_package( KF5 QUIET COMPONENTS CoreAddons Crash ) +find_package( KF5 QUIET COMPONENTS CoreAddons Crash DBusAddons ) set_package_properties( KF5::CoreAddons PROPERTIES TYPE REQUIRED @@ -299,8 +300,17 @@ set_package_properties( PURPOSE "About Calamares" ) if( NOT KF5Crash_FOUND ) + if( WITH_KF5Crash ) + message(WARNING "WITH_KF5Crash is set, but KF5::Crash is not available.") + endif() set( WITH_KF5Crash OFF ) endif() +if( NOT KF5DBusAddons_FOUND ) + if( WITH_KF5DBus ) + message(WARNING "WITH_KF5DBus is set, but KF5::DBusAddons is not available.") + endif() + set( WITH_KF5DBus OFF ) +endif() if( BUILD_TESTING ) enable_testing() @@ -520,6 +530,7 @@ add_feature_info(Python ${WITH_PYTHON} "Python job modules") add_feature_info(PythonQt ${WITH_PYTHONQT} "Python view modules") add_feature_info(Config ${INSTALL_CONFIG} "Install Calamares configuration") add_feature_info(KCrash ${WITH_KF5Crash} "Crash dumps via KCrash") +add_feature_info(KDBusAddons ${WITH_KF5DBus} "Unique-application via DBus") # Add all targets to the build-tree export set set( CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Calamares" CACHE PATH "Installation directory for CMake files" ) diff --git a/src/calamares/CMakeLists.txt b/src/calamares/CMakeLists.txt index 81fd0d132..336c27317 100644 --- a/src/calamares/CMakeLists.txt +++ b/src/calamares/CMakeLists.txt @@ -41,12 +41,13 @@ target_link_libraries( calamares_bin KF5::CoreAddons ) if( WITH_KF5Crash ) - target_link_libraries( calamares_bin - PRIVATE - KF5::Crash - ) + target_link_libraries( calamares_bin PRIVATE KF5::Crash ) target_compile_definitions( calamares_bin PRIVATE WITH_KF5Crash ) endif() +if( WITH_KF5DBus ) + target_link_libraries( calamares_bin PRIVATE KF5::DBusAddons ) + target_compile_definitions( calamares_bin PRIVATE WITH_KF5DBus ) +endif() install( TARGETS calamares_bin BUNDLE DESTINATION . diff --git a/src/calamares/main.cpp b/src/calamares/main.cpp index d460e44e3..030ccc239 100644 --- a/src/calamares/main.cpp +++ b/src/calamares/main.cpp @@ -25,9 +25,15 @@ #include "utils/Logger.h" #include "utils/Retranslator.h" +#ifndef WITH_KF5DBus +#warning "KDSingleApplicationGuard is deprecated" #include "3rdparty/kdsingleapplicationguard/kdsingleapplicationguard.h" +#endif #include +#ifdef WITH_KF5DBus +#include +#endif #ifdef WITH_KF5Crash #include #endif @@ -137,26 +143,27 @@ main( int argc, char* argv[] ) bool is_debug = handle_args( a ); - if ( !is_debug ) +#ifdef WITH_KF5DBus + KDBusService service( is_debug ? KDBusService::Multiple : KDBusService::Unique ); +#else + KDSingleApplicationGuard guard( is_debug ? KDSingleApplicationGuard::NoPolicy + : KDSingleApplicationGuard::AutoKillOtherInstances ); + if ( !is_debug && !guard.isPrimaryInstance() ) { - KDSingleApplicationGuard guard( KDSingleApplicationGuard::AutoKillOtherInstances ); - - if ( !guard.isPrimaryInstance() ) + // 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 ) { - // 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 + qDebug() << "Other running Calamares instances:"; } + for ( const auto& i : instancelist ) + { + qDebug() << " " << i.isValid() << i.pid() << i.arguments(); + } + return 69; // EX_UNAVAILABLE on FreeBSD } +#endif Calamares::Settings::init( is_debug ); a.init();