diff --git a/other/antimicrox.1 b/other/antimicrox.1 index c8f1c7bf5..057031f9d 100644 --- a/other/antimicrox.1 +++ b/other/antimicrox.1 @@ -40,9 +40,6 @@ start joysticks on a specific set. Value can be a controller index, name, or GUI \fB\-\-next\fR Advance profile loading set options. .TP -\fB\-d\fR, \fB\-\-daemon\fR -launch program as a daemon. -.TP \fB\-\-log\-level\fR \fI{debug,info,warn}\fR Enable logging. Default: warn .TP diff --git a/src/commandlineutility.cpp b/src/commandlineutility.cpp index b95bc1011..9b749a617 100644 --- a/src/commandlineutility.cpp +++ b/src/commandlineutility.cpp @@ -40,7 +40,6 @@ CommandLineUtility::CommandLineUtility(QObject *parent) showRequest = false; unloadProfile = false; startSetNumber = 0; - daemonMode = false; displayString = ""; listControllers = false; mappingController = false; @@ -87,7 +86,6 @@ void CommandLineUtility::parseArguments(const QApplication &parsed_app) QCoreApplication::translate("main", "Start joysticks on a specific set. Value can be a " "controller index, name, or GUID"), QCoreApplication::translate("main", "number value")}, - {{"daemon", "d"}, QCoreApplication::translate("main", "Launch program as a daemon. Use only on Linux.")}, {"log-level", QCoreApplication::translate("main", "Enable logging. Levels (from the least strict): warn,info,verbose,debug"), QCoreApplication::translate("main", "log-type")}, @@ -184,10 +182,6 @@ void CommandLineUtility::parseArguments(const QApplication &parsed_app) parseArgsMap(parser); } - if (parser.isSet("daemon")) - { - daemonMode = true; - } #ifdef WITH_X11 if (parser.isSet("display")) { @@ -462,8 +456,6 @@ bool CommandLineUtility::shouldMapController() { return mappingController; } QString CommandLineUtility::getEventGenerator() { return eventGenerator; } -bool CommandLineUtility::launchAsDaemon() { return daemonMode; } - QString CommandLineUtility::getDisplayString() { return displayString; } Logger::LogLevel CommandLineUtility::getCurrentLogLevel() { return currentLogLevel; } diff --git a/src/commandlineutility.h b/src/commandlineutility.h index fc4deb865..fd0440f3f 100644 --- a/src/commandlineutility.h +++ b/src/commandlineutility.h @@ -117,7 +117,6 @@ class CommandLineUtility : public QObject QList *getJoyStartSetNumberList(); QList const &getControllerOptionsList(); - bool launchAsDaemon(); QString getDisplayString(); Logger::LogLevel getCurrentLogLevel(); @@ -129,7 +128,6 @@ class CommandLineUtility : public QObject bool hiddenRequest; bool showRequest; bool unloadProfile; - bool daemonMode; bool listControllers; bool mappingController; diff --git a/src/main.cpp b/src/main.cpp index f35b0f705..59b919040 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,9 +60,6 @@ #include - #include - #include - #ifdef WITH_X11 #include "x11extras.h" #endif @@ -385,152 +382,36 @@ int main(int argc, char *argv[]) LocalAntiMicroServer *localServer = nullptr; #ifdef Q_OS_UNIX - if (cmdutility.launchAsDaemon()) - { - pid_t pid, sid; - pid = fork(); // Fork the Parent Process - - if (pid == 0) - { - PRINT_STDOUT() << QObject::tr("Daemon launched"); - - localServer = new LocalAntiMicroServer(); - localServer->startLocalServer(); - } else if (pid < 0) - { - qCritical() << QObject::tr("Failed to launch daemon"); - - deleteInputDevices(joysticks); - delete joysticks; - joysticks = nullptr; - - return 1; - } else if (pid > 0) // We got a good pid, Close the Parent Process - { - PRINT_STDOUT() << QObject::tr("Launching daemon") << " PID: " << pid << "\n"; - - deleteInputDevices(joysticks); - delete joysticks; - joysticks = nullptr; - - return 0; - } + localServer = new LocalAntiMicroServer(); + localServer->startLocalServer(); #ifdef WITH_X11 - if (QApplication::platformName() == QStringLiteral("xcb")) - { - if (cmdutility.getDisplayString().isEmpty()) - { - X11Extras::getInstance()->syncDisplay(); - } else - { - X11Extras::setCustomDisplay(cmdutility.getDisplayString()); - X11Extras::getInstance()->syncDisplay(); - - if (X11Extras::getInstance()->display() == nullptr) - { - qCritical() << QObject::tr("Display string \"%1\" is not valid.").arg(cmdutility.getDisplayString()); - - deleteInputDevices(joysticks); - delete joysticks; - joysticks = nullptr; - - delete localServer; - localServer = nullptr; - - X11Extras::getInstance()->closeDisplay(); - - exit(EXIT_FAILURE); - } - } - } - - #endif - - umask(0); // Change File Mask - sid = setsid(); // Create a new Signature Id for our child - - if (sid < 0) + if (QApplication::platformName() == QStringLiteral("xcb")) + { + if (!cmdutility.getDisplayString().isEmpty()) { - qCritical() << QObject::tr("Failed to set a signature id for the daemon"); - - deleteInputDevices(joysticks); - delete joysticks; - joysticks = nullptr; - - delete localServer; - localServer = nullptr; + X11Extras::getInstance()->syncDisplay(cmdutility.getDisplayString()); - #ifdef WITH_X11 - if (QApplication::platformName() == QStringLiteral("xcb")) + if (X11Extras::getInstance()->display() == nullptr) { - X11Extras::getInstance()->closeDisplay(); - } - #endif - - exit(EXIT_FAILURE); - } - - if ((chdir("/")) < 0) - { - qCritical() << QObject::tr("Failed to change working directory to /"); + qCritical() << QObject::tr("Display string \"%1\" is not valid.").arg(cmdutility.getDisplayString()); - deleteInputDevices(joysticks); - delete joysticks; - joysticks = nullptr; + deleteInputDevices(joysticks); + delete joysticks; + joysticks = nullptr; - delete localServer; - localServer = nullptr; + delete localServer; + localServer = nullptr; - #ifdef WITH_X11 - - if (QApplication::platformName() == QStringLiteral("xcb")) - { X11Extras::getInstance()->closeDisplay(); - } - #endif - - exit(EXIT_FAILURE); - } - - // Close Standard File Descriptors - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - } else - { - localServer = new LocalAntiMicroServer(); - localServer->startLocalServer(); - - #ifdef WITH_X11 - - if (QApplication::platformName() == QStringLiteral("xcb")) - { - if (!cmdutility.getDisplayString().isEmpty()) - { - X11Extras::getInstance()->syncDisplay(cmdutility.getDisplayString()); - if (X11Extras::getInstance()->display() == nullptr) - { - qCritical() << QObject::tr("Display string \"%1\" is not valid.").arg(cmdutility.getDisplayString()); - - deleteInputDevices(joysticks); - delete joysticks; - joysticks = nullptr; - - delete localServer; - localServer = nullptr; - - X11Extras::getInstance()->closeDisplay(); - - exit(EXIT_FAILURE); - } + exit(EXIT_FAILURE); } } - - #endif } + #endif + #elif defined(Q_OS_WIN) localServer = new LocalAntiMicroServer(); localServer->startLocalServer();