diff options
author | Henri Herscher <henri@oreka.org> | 2005-11-17 20:33:56 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2005-11-17 20:33:56 +0000 |
commit | 7181aaef00465f3890b100a4f0f497790b418ab0 (patch) | |
tree | 19d07c8b6ea92e1b175fa87387922d2a68afd4e6 /orkaudio/Daemon.cpp | |
parent | 1ff1adc0e68aa0080f31c60ce12077ddf7be9b02 (diff) |
Now uses a lock file to prevent multiple copies of orkaudio to run at the same time
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@52 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkaudio/Daemon.cpp')
-rw-r--r-- | orkaudio/Daemon.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/orkaudio/Daemon.cpp b/orkaudio/Daemon.cpp index b324082..a4f9314 100644 --- a/orkaudio/Daemon.cpp +++ b/orkaudio/Daemon.cpp @@ -132,12 +132,20 @@ void Daemon::Run() 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 */ + lfp=open("/var/log/orkaudio/orkaudio.lock",O_RDWR|O_CREAT,0640); + if (lfp<0) + { + lfp=open("orkaudio.lock",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 */ + 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); |