Changes: Fixed file locking when --daemon is used.

RevBy: Pertti Kellomäki
pull/1/head
Jussi Lind 15 years ago
parent 73d10fc05d
commit fe6c689250

@ -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);

@ -21,6 +21,9 @@
#include "logger.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <signal.h>
#include <fcntl.h>
@ -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<std::string> 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

Loading…
Cancel
Save