Skip to content

Commit

Permalink
Remove daemon mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
pktiuk committed Jan 14, 2022
1 parent 9968712 commit 91d61e3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 145 deletions.
3 changes: 0 additions & 3 deletions other/antimicrox.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions src/commandlineutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ CommandLineUtility::CommandLineUtility(QObject *parent)
showRequest = false;
unloadProfile = false;
startSetNumber = 0;
daemonMode = false;
displayString = "";
listControllers = false;
mappingController = false;
Expand Down Expand Up @@ -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")},
Expand Down Expand Up @@ -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"))
{
Expand Down Expand Up @@ -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; }
Expand Down
2 changes: 0 additions & 2 deletions src/commandlineutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ class CommandLineUtility : public QObject
QList<int> *getJoyStartSetNumberList();
QList<ControllerOptionsInfo> const &getControllerOptionsList();

bool launchAsDaemon();
QString getDisplayString();

Logger::LogLevel getCurrentLogLevel();
Expand All @@ -129,7 +128,6 @@ class CommandLineUtility : public QObject
bool hiddenRequest;
bool showRequest;
bool unloadProfile;
bool daemonMode;
bool listControllers;
bool mappingController;

Expand Down
148 changes: 16 additions & 132 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,152 +385,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();
Expand Down

0 comments on commit 91d61e3

Please sign in to comment.