diff --git a/src/ProcessSemaphore_C4droid.cpp b/src/ProcessSemaphore_C4droid.cpp index e2e859a..1db1ed0 100644 --- a/src/ProcessSemaphore_C4droid.cpp +++ b/src/ProcessSemaphore_C4droid.cpp @@ -8,6 +8,9 @@ #include #include #include +#include +#include + #include using namespace std; @@ -81,12 +84,12 @@ ProcessSemaphore::ProcessSemaphore(int key, int action, int default_value) : _p( if(action==1) { - _p->fd=open(_p->buff,O_RDWR|O_CREAT|O_TRUNC|O_EXCL); + _p->fd=open(_p->buff,O_RDWR|O_CREAT|O_EXCL,0666); _p->owner=true; } else { - _p->fd=open(_p->buff,O_RDWR); + _p->fd=open(_p->buff,O_RDWR,0666); } if(_p->fd>=0) /// Opened. @@ -103,6 +106,10 @@ ProcessSemaphore::ProcessSemaphore(int key, int action, int default_value) : _p( flock(_p->fd,LOCK_UN); } } + else + { + perror("Failed to open file. "); + } if(_p->status!=0&&_p->status!=2) /// Clean up { @@ -152,7 +159,7 @@ int ProcessSemaphore::p() typedef void (*fnvi)(int); _global_process_semaphore_value=0; fnvi old=signal(SIGUSR1,_global_process_semaphore_handler); - //*/ + */ flock(_p->fd,LOCK_UN); @@ -162,6 +169,7 @@ int ProcessSemaphore::p() while(1) { flock(_p->fd,LOCK_EX); + x=impl::LockInfo::getFrom(_p->fd); if(x.current_value>0) /// Someone has released resource! { x.current_value=x.current_value-1;