From 7181aaef00465f3890b100a4f0f497790b418ab0 Mon Sep 17 00:00:00 2001 From: Henri Herscher Date: Thu, 17 Nov 2005 20:33:56 +0000 Subject: 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 --- orkaudio/Daemon.cpp | 18 +++++++++++++----- 1 file 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); -- cgit v1.2.3