diff options
author | Henri Herscher <henri@oreka.org> | 2005-11-16 03:40:48 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2005-11-16 03:40:48 +0000 |
commit | 901ba08dfcc1a3fde28aea465df8926bf513362f (patch) | |
tree | f70237b12eb45d27d0f3da08c2d65e79bd413231 /orkaudio/Daemon.cpp | |
parent | 7653151cb08cfa40eec22e7aac3068b009207bc8 (diff) |
Orkaudio now daemonizes under linux when run without any argument.
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@45 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkaudio/Daemon.cpp')
-rw-r--r-- | orkaudio/Daemon.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/orkaudio/Daemon.cpp b/orkaudio/Daemon.cpp index ed7e5a6..b324082 100644 --- a/orkaudio/Daemon.cpp +++ b/orkaudio/Daemon.cpp @@ -119,6 +119,30 @@ void Daemon::Run() serviceStatus.dwCurrentState = SERVICE_RUNNING; SetServiceStatus( serviceStatusHandle, &serviceStatus ); } +#else // non WIN32 + int i,lfp; + char str[10]; + if(getppid()==1) return; /* already a daemon */ + i=fork(); + if (i<0) exit(1); /* fork error */ + if (i>0) exit(0); /* parent exits */ + /* child (daemon) continues */ + setsid(); /* obtain a new process group */ + for (i=getdtablesize();i>=0;--i) close(i); /* close all descriptors */ + i=open("/dev/null",O_RDWR); dup(i); dup(i); /* handle standart I/O */ + umask(027); /* set newly created file permissions */ + //chdir(RUNNING_DIR); /* change running directory */ + //lfp=open(LOCK_FILE,O_RDWR|O_CREAT,0640); + //if (lfp<0) exit(1); /* can not open */ + //if (lockf(lfp,F_TLOCK,0)<0) exit(0); /* can not lock */ + /* first instance continues */ + //sprintf(str,"%d\n",getpid()); + //write(lfp,str,strlen(str)); /* record pid to lockfile */ + //signal(SIGCHLD,SIG_IGN); /* ignore child */ + //signal(SIGTSTP,SIG_IGN); /* ignore tty signals */ + //signal(SIGTTOU,SIG_IGN); + //signal(SIGTTIN,SIG_IGN); + //signal(SIGHUP,signal_handler); /* catch hangup signal */ #endif DaemonSingleton::instance()->m_runHandler(); |