summaryrefslogtreecommitdiffstats
path: root/src/pvsDaemon.cpp
diff options
context:
space:
mode:
authorSebastien Braun2010-10-05 22:57:48 +0200
committerSebastien Braun2010-10-05 22:57:48 +0200
commit0cb19c0a597bfb7a6cac416fb5c0b0a89043081e (patch)
tree1c076c798ae6ce960bccde2e0aea675143d961d8 /src/pvsDaemon.cpp
parentFix SIGSEGV-generating lookup bug when incoming multicast transfers are retried (diff)
parent[PVSGUI] parsing cmdargs fixed (diff)
downloadpvs-0cb19c0a597bfb7a6cac416fb5c0b0a89043081e.tar.gz
pvs-0cb19c0a597bfb7a6cac416fb5c0b0a89043081e.tar.xz
pvs-0cb19c0a597bfb7a6cac416fb5c0b0a89043081e.zip
Merge remote branch 'openslx/master' into mcastft
Conflicts: CMakeLists.txt pvsmgr.qrc src/gui/clientConfigDialog.cpp src/gui/mainWindow.cpp src/gui/ui/mainwindow.ui src/gui/ui/mainwindowtouch.ui src/pvs.cpp src/pvs.h src/pvsDaemon.cpp src/pvsgui.cpp
Diffstat (limited to 'src/pvsDaemon.cpp')
-rw-r--r--src/pvsDaemon.cpp247
1 files changed, 68 insertions, 179 deletions
diff --git a/src/pvsDaemon.cpp b/src/pvsDaemon.cpp
index 591d43b..4918a60 100644
--- a/src/pvsDaemon.cpp
+++ b/src/pvsDaemon.cpp
@@ -3,21 +3,18 @@
#include <stdlib.h>
#include "pvs.h"
#include "src/net/pvsLocalhostCommunicator.h"
-#include "src/util/pvsSettingsManager.h"
#include "setup.h"
#include "src/net/pvsMsg.h"
#include "src/core/pvsChatClient.h"
PVS *mainClient = NULL;
-
-// This define works as a switch whether to run as deamon or regular app
-#define as_daemon
+QTextStream qout(stdout);
/// VERSION_STRING is defined in src/version.h
void printVersion(bool doExit)
{
-
- printf("Version:\t"VERSION_STRING"\n");
+ qout << "Version:\t"VERSION_STRING"\n";
+ qout.flush();
if (doExit)
exit(0);
}
@@ -25,57 +22,48 @@ void printVersion(bool doExit)
/// outputs the full help text
void printHelp()
{
- printf("**************************************************************\n");
- printf("\nPool Video Switch Client\n");
- printf("**************************************************************\n");
- printVersion(false);
- printf("**************************************************************\n");
- printf("Usage:\tpoolVSClient <<option> <value>, ... >\n\n");
- printf("Options:\n\n");
- printf("-vncScriptFile <fullpath\\filename>\n\tSpecifies a custom location for the vnc-start/stop-script.\n\tIf not specified, ~/.pvs/pvs-vncsrv is expected.\n\n");
- printf("-freq <seconds>\n\tSpecifies how long to wait until a reconnection attempt is made.\n\tDefault is 5.\n\n");
- printf("-port <port>\n\tSpecifies on which port to run.\n\tDefault is %d.\n\n", SERVER_PORT_INT);
- printf("-h or --help\n\t Shows this help text and exits.\n\n");
- printf("-v or --version\n\t Shows the current version and exits.\n");
- printf(
- "-c <string command>:<string value> \n\t Sends the command and the optional value to a running PVS-Client.\n\t Command and value may not contain spaces or colons.\n\t The dividing colon is mandatory.\n");
- printf("-commands: \n\tPrints out available commands to use with -c . \n ");
- printf("**************************************************************\n");
+ qout << "**************************************************************\n";
+ qout << "Pool Video Switch Client\n";
+ qout << "**************************************************************\n";
+ qout << QObject::tr("Version: ") << VERSION_STRING << "\n";
+ qout << "**************************************************************\n";
+ qout << QObject::tr("Usage:") << "\tpoolVSClient " << QObject::tr("<<option> <value>, ... >") << "\n\n";
+ qout << QObject::tr("Options:") << "\n\n";
+ qout << QObject::tr("-vncScriptFile <fullpath\\filename>") << "\n\t" << QObject::tr("Specifies a custom location for the vnc-start/stop-script.")<< "\n\t" << QObject::tr("If not specified, /usr/bin/pvs-vncsrv is expected.") << "\n\n";
+ qout << QObject::tr("-freq <seconds>") << "\n\t" << QObject::tr("Specifies how long to wait until a reconnection attempt is made.") << "\n\t" << QObject::tr("Default is 5.") << "\n\n";
+ qout << QObject::tr("-port <port>") << "\n\t" << QObject::tr("Specifies on which port to run.") << "\n\t" << QObject::tr("Default is ") << SERVER_PORT_INT << ".\n\n";
+ qout << QObject::tr("-h or --help") << "\n\t" << QObject::tr("Shows this help text and exits.") << "\n\n";
+ qout << QObject::tr("-v or --version") << "\n\t" << QObject::tr("Shows the current version and exits.") << "\n";
+ qout << QObject::tr("-d or --daemon") << "\n\t" << QObject::tr("Start as daemon.") << "\n";
+ qout << QObject::tr("-c <string command>:<string value>") << "\n\t" << QObject::tr("Sends the command and the optional value to a running PVS-Client.") << "\n\t" << QObject::tr("Command and value may not contain spaces or colons.") << "\n\t" << QObject::tr("The dividing colon is mandatory.") << "\n";
+ qout << "--commands: \n\t" << QObject::tr("Prints out available commands to use with -c.") << "\n";
+ qout << "**************************************************************\n";
+ qout.flush();
exit(0);
}
/// outputs a brief help text
void printNotice()
{
- printf(
- "Use -h or --help to get a listing of all options.\n-v or --version gives you the current version.\n\n");
+ qout << QObject::tr("Use -h or --help to get a listing of all options.\n-v or --version gives you the current version.\n\n");
+ qout.flush();
}
void printCommands()
{
- printf("**************************************************************\n");
- printf("chat:<on/ off/ 1/ 2/ 3>\n ");
- printf("on = turns that chat option on\n off = turns the chat option off\n 1 = bossmode\n 2 = community\n 3 = private\n");
- printf("stop \n\t Stops the running PVS-Client.\n");
- printf("**************************************************************\n");
+ qout << "**************************************************************\n";
+ qout << "stop \n\t Stops the running PVS-Client.\n";
+ qout << "**************************************************************\n";
+ qout.flush();
exit(0);
}
///
int main(int argc, char** argv)
{
+ bool _daemon = false;
int frequency = 5;
int port = -1;
-#ifdef as_daemon
- bool no_fork = false;
-#endif
-
- QFileInfo script;
- script.setFile("/usr/bin/pvs-vncsrv");
- if (!script.exists())
- script.setFile("/usr/local/bin/pvs-vncsrv");
- if (!script.exists())
- script.setFile("/home/" + getUserName() + "/.pvs/pvs-vncsrv");
QCoreApplication app(argc, argv);
app.setOrganizationName("openslx");
@@ -86,17 +74,37 @@ int main(int argc, char** argv)
translator.load(":pvs");
app.installTranslator(&translator);
+ QFileInfo script;
+#ifdef __WIN32__
+ //TODO Win32
+ if (!script.exists())
+ script.setFile(getHomeDir() + "/.pvs/pvs-vncsrv_win32.bat");
+#else
+ QSettings settings;
+ if (!QFile::exists(settings.fileName()))
+ {
+ QDir::root().mkpath(QFileInfo(settings.fileName()).path());
+ QFile::copy("/etc/openslx/pvs.conf", settings.fileName());
+ }
+ QString s = settings.value("VNC/script").toString();
+ script.setFile(s);
+ if (!script.exists())
+ script.setFile("/usr/bin/pvs-vncsrv");
+ if (!script.exists())
+ script.setFile("/usr/local/bin/pvs-vncsrv");
+ if (!script.exists())
+ script.setFile(getHomeDir() + "/.pvs/pvs-vncsrv");
+#endif //__WIN32__
PVSLocalhostCommunicator com(getPolicyFilePath(QString(
".comfile")));
com.run();
if (!(com.running()))
{
- printf("Error. UDS Communicator is not running. Exiting.\n");
+ qDebug("Error. UDS Communicator is not running. Exiting.");
exit(0);
}
- printf("UDS Communicator is running.\n");
int option_index = 0;
while (1)
@@ -106,18 +114,16 @@ int main(int argc, char** argv)
{ "help", no_argument, 0, 'h' },
{ "commands", no_argument, 0, 'o' },
{ "version", no_argument, 0, 'v' },
+ { "daemon", no_argument, 0, 'd' },
{ "port", required_argument, 0, 'p' },
{ "freq", required_argument, 0, 'f' },
{ "client", required_argument, 0, 'e' },
{ "script", required_argument, 0, 's' },
-#ifdef as_daemon
- { "no-fork", no_argument, 0, 'F' },
-#endif
{ 0, 0, 0, 0 },
};
/* getopt_long stores the option index here. */
- int c = getopt_long(argc, argv, "hvoFc:f:e:s:p:", long_options,
+ int c = getopt_long(argc, argv, "hvodc:f:e:s:p:", long_options,
&option_index);
option_index++;
if (c == -1)
@@ -134,6 +140,9 @@ int main(int argc, char** argv)
case 'v':
printVersion(true);
break;
+ case 'd':
+ _daemon = true;
+ break;
case 'c':
{
if (option_index + 1 < argc)
@@ -141,78 +150,22 @@ int main(int argc, char** argv)
if (com.server())
{
// wont work, no daemon running
- printf("Error. No running PVS-Client found. Exiting.\n");
+ qDebug("No running PVS-Client found. Exiting.");
com.stop();
}
else
{
- QStringList line = QString::fromLocal8Bit(argv[option_index
- + 1]).split(":");
- QString &ident = line[0];
- QString message;
- if (line.size() > 1)
- message = line[1];
- if (ident.size() > 0) // no use sending empty idents... not even sure if this COULD happen
- {
- bool flag = false;
- if (ident == "make")
- PVSSettingsManager::getManager()->setConfigs();
- else if (ident == "chat" && message == "boss")
- {
- PVSSettingsManager::getManager()->reWriteConfigs("chatmode", "bossmode");
- flag = true;
-
- }
- else if (ident == "chat" && message == "all")
- {
- PVSSettingsManager::getManager()->reWriteConfigs("chatmode", "community");
- flag = true;
- }
- else if (ident == "chat" && message == "private")
- {
- PVSSettingsManager::getManager()->reWriteConfigs("chatmode", "private");
- flag = true;
- }
- else if (ident == "chat" && message == "on")
- {
- PVSSettingsManager::getManager()->reWriteConfigs("chatstate", "on");
- flag = true;
- }
- else if (ident == "chat" && message == "off")
- {
- PVSSettingsManager::getManager()->reWriteConfigs("chatstate", "off");
- flag = true;
- }
- else if (ident == "room")
- {
- //PVSSettingsManager::getManager()->reWriteConfigs(ident, message);
- flag = true;
- }
- else if (ident == "stop" && message == NULL)
- flag = true;
- else
- printf("option %s doesn't exist\n", ident.toUtf8().data());
-
- if (flag)
- {
- qDebug("Will send i: %s, m: %s\n", ident.toUtf8().data(), message.toUtf8().data());
- com.sendCommand(ident, message);
- QCoreApplication::processEvents(QEventLoop::AllEvents);
- printf("Sent command. Exiting.\n");
- }
- }
-
- else
- printf("Something went horribly wrong, since the ident is empty.\n");
-
- }
+ qDebug("Will send i: %s, m: %s\n", argv[option_index + 1], "");
+ com.sendCommand(QString(argv[option_index + 1]), "");
+ QCoreApplication::processEvents(QEventLoop::AllEvents);
+ qDebug("Sent command. Exiting.");
+ }
}
else
{
- printf("Error. No command issued. Exiting.\n");
+ qDebug("Error. No command issued. Exiting.");
}
exit(0); // and gone
- break;
}
case 'f':
{
@@ -257,7 +210,7 @@ int main(int argc, char** argv)
{
if (option_index + 1 < argc)
{
- printf("WARNING: -e is deprecated\n");
+ qDebug("WARNING: -e is deprecated");
option_index++;
continue;
}
@@ -273,13 +226,6 @@ int main(int argc, char** argv)
}
break;
}
-#ifdef as_daemon
- case 'F':
- {
- no_fork = true;
- break;
- }
-#endif
case '?':
{
ConsoleLog writeError(
@@ -296,7 +242,7 @@ int main(int argc, char** argv)
if (!com.server())
{
- printf("Error. PoolVSClient already running. Exiting\n");
+ qDebug("Error. PoolVSClient already running. Exiting");
com.stop();
exit(0);
}
@@ -304,66 +250,14 @@ int main(int argc, char** argv)
ConsoleLog setLogName(QString("log.client"));
ConsoleLog writeLine(QString("PVS-Client started."));
-#ifdef as_daemon
-
- if (!no_fork)
+ if (_daemon)
{
- /* Our process ID and Session ID */
- pid_t pid, sid;
-
- /* Fork off the parent process */
- pid = fork();
- if (pid < 0)
- {
- exit(-1);
- }
- /* If we got a good PID, then
- we can exit the parent process. */
- if (pid > 0)
- {
- exit(0);
- }
-
- /* Change the file mode mask */
- umask(0);
-
- /* Open any logs here */
-
- /* Create a new SID for the child process */
- sid = setsid();
- if (sid < 0)
- {
- /* Log the failure */
- exit(-1);
- }
-
- /* Change the current working directory */
- if ((chdir("/")) < 0)
- {
- /* Log the failure */
- exit(-1);
- }
-
- /* Close out the standard file descriptors */
- close(STDIN_FILENO);
- freopen ((QString("/home/").append(getUserName().append(QString("/.pvs/dump")))).toUtf8().data(),"w",stdout);
- //close(STDOUT_FILENO);
- close(STDERR_FILENO);
-
- /* Daemon-specific initialization goes here */
-
- /* The Big Loop */
+ #ifndef __WIN32__
+ daemon(1, 1);
+ #endif /*__WIN32__*/
}
- else
- {
- /* just the umask(), please */
- umask(0);
- }
-
-#endif
mainClient = new PVS();
- PVSSettingsManager::getManager()->setConfigFile(getPolicyFilePath("clientconf"));
com.getDispatcher()->addListener("*", mainClient, &PVS::onDaemonCommand);
if (port <= 0)
@@ -374,11 +268,6 @@ int main(int argc, char** argv)
createPolicyDir();
createPolicyFiles();
- // long int gr = 0;
- mainClient->setScriptPath(script.filePath());
- app.exec();
- delete mainClient;
-
- return 0;
+ return app.exec();
}