summaryrefslogtreecommitdiffstats
path: root/src/pvsDaemon.cpp
diff options
context:
space:
mode:
authorSebastien Braun2010-07-17 16:43:49 +0200
committerSebastien Braun2010-07-17 16:58:40 +0200
commit6f686ba9729a6539eb192b9756b9d05a9f5887ba (patch)
tree8ffbea49cb4eede0eb085798f50baf430dd24a92 /src/pvsDaemon.cpp
parentFix License header for McastConfiguration.cpp (diff)
downloadpvs-6f686ba9729a6539eb192b9756b9d05a9f5887ba.tar.gz
pvs-6f686ba9729a6539eb192b9756b9d05a9f5887ba.tar.xz
pvs-6f686ba9729a6539eb192b9756b9d05a9f5887ba.zip
Implement --no-fork/-F command line argument for pvs
Diffstat (limited to 'src/pvsDaemon.cpp')
-rw-r--r--src/pvsDaemon.cpp97
1 files changed, 59 insertions, 38 deletions
diff --git a/src/pvsDaemon.cpp b/src/pvsDaemon.cpp
index e87bfe7..591d43b 100644
--- a/src/pvsDaemon.cpp
+++ b/src/pvsDaemon.cpp
@@ -66,6 +66,9 @@ int main(int argc, char** argv)
{
int frequency = 5;
int port = -1;
+#ifdef as_daemon
+ bool no_fork = false;
+#endif
QFileInfo script;
script.setFile("/usr/bin/pvs-vncsrv");
@@ -107,11 +110,14 @@ int main(int argc, char** argv)
{ "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, "hvoc:f:e:s:p:", long_options,
+ int c = getopt_long(argc, argv, "hvoFc:f:e:s:p:", long_options,
&option_index);
option_index++;
if (c == -1)
@@ -267,6 +273,13 @@ int main(int argc, char** argv)
}
break;
}
+#ifdef as_daemon
+ case 'F':
+ {
+ no_fork = true;
+ break;
+ }
+#endif
case '?':
{
ConsoleLog writeError(
@@ -293,51 +306,59 @@ int main(int argc, char** argv)
#ifdef as_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)
+ if (!no_fork)
{
- exit(0);
- }
+ /* Our process ID and Session ID */
+ pid_t pid, sid;
- /* Change the file mode mask */
- umask(0);
+ /* 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);
+ }
- /* Open any logs here */
+ /* Change the file mode mask */
+ umask(0);
- /* Create a new SID for the child process */
- sid = setsid();
- if (sid < 0)
- {
- /* Log the failure */
- exit(-1);
- }
+ /* Open any logs here */
- /* Change the current working directory */
- if ((chdir("/")) < 0)
- {
- /* Log the failure */
- exit(-1);
- }
+ /* 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);
+ /* 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 */
+ /* Daemon-specific initialization goes here */
- /* The Big Loop */
+ /* The Big Loop */
+ }
+ else
+ {
+ /* just the umask(), please */
+ umask(0);
+ }
#endif