diff --git a/src/launcherlib/daemon.cpp b/src/launcherlib/daemon.cpp index fde19be..ffbac5f 100644 --- a/src/launcherlib/daemon.cpp +++ b/src/launcherlib/daemon.cpp @@ -625,6 +625,12 @@ void Daemon::daemonize() exit(EXIT_SUCCESS); } + // Check the lock + if(!Daemon::lock()) + { + Logger::logErrorAndDie(EXIT_FAILURE, "%s is already running \n", PROG_NAME_LAUNCHER); + } + // Change the file mode mask umask(0); diff --git a/src/launcherlib/main.cpp b/src/launcherlib/main.cpp index 7c86c32..e0d99b1 100644 --- a/src/launcherlib/main.cpp +++ b/src/launcherlib/main.cpp @@ -21,6 +21,9 @@ #include "logger.h" #include +#include +#include +#include #include #include #include @@ -67,10 +70,17 @@ DECL_EXPORT int main(int argc, char * argv[]) Logger::openLog(PROG_NAME_LAUNCHER); Logger::logDebug("%s starting..", PROG_NAME_LAUNCHER); - // Check that an instance of launcher is not already running - if(!Daemon::lock()) + // Check that an instance of launcher is not already running already + // here if we are not going to fork. In that case the lock should be + // checked after fork() is done in Daemon::daemonize + std::vector args(argv, argv + argc); + if (find(args.begin(), args.end(), "-d") == args.end() && + find(args.begin(), args.end(), "--daemon") == args.end()) { - Logger::logErrorAndDie(EXIT_FAILURE, "%s is already running \n", PROG_NAME_LAUNCHER); + if(!Daemon::lock()) + { + Logger::logErrorAndDie(EXIT_FAILURE, "%s is already running \n", PROG_NAME_LAUNCHER); + } } // Create main daemon instance