Poco::NamedMutex and Poco::NamedEvent (System V Semaphores implementation): files are now opened with O_RDONLY | O_CREAT instead of O_WRONLY | O_CREAT, allowing sharing between different users. Furthermore, ftok() is called with 'p' as project ID argument.

This commit is contained in:
Günter Obiltschnig 2017-09-11 21:12:12 +02:00
parent 7896a1b7dd
commit 33bc8b5011
2 changed files with 4 additions and 4 deletions

View File

@ -58,12 +58,12 @@ NamedEventImpl::NamedEventImpl(const std::string& name):
if ((long) _sem == (long) SEM_FAILED) if ((long) _sem == (long) SEM_FAILED)
throw SystemException(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name); throw SystemException(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name);
#else #else
int fd = open(fileName.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); int fd = open(fileName.c_str(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd != -1) if (fd != -1)
close(fd); close(fd);
else else
throw SystemException(Poco::format("cannot create named event %s (lockfile)", fileName), _name); throw SystemException(Poco::format("cannot create named event %s (lockfile)", fileName), _name);
key_t key = ftok(fileName.c_str(), 0); key_t key = ftok(fileName.c_str(), 'p');
if (key == -1) if (key == -1)
throw SystemException(Poco::format("cannot create named mutex %s (ftok() failed, errno=%d)", fileName, errno), _name); throw SystemException(Poco::format("cannot create named mutex %s (ftok() failed, errno=%d)", fileName, errno), _name);
_semid = semget(key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT | IPC_EXCL); _semid = semget(key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT | IPC_EXCL);

View File

@ -58,12 +58,12 @@ NamedMutexImpl::NamedMutexImpl(const std::string& name):
if ((long) _sem == (long) SEM_FAILED) if ((long) _sem == (long) SEM_FAILED)
throw SystemException(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name); throw SystemException(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name);
#else #else
int fd = open(fileName.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); int fd = open(fileName.c_str(), O_RDONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd != -1) if (fd != -1)
close(fd); close(fd);
else else
throw SystemException(Poco::format("cannot create named mutex %s (lockfile)", fileName), _name); throw SystemException(Poco::format("cannot create named mutex %s (lockfile)", fileName), _name);
key_t key = ftok(fileName.c_str(), 0); key_t key = ftok(fileName.c_str(), 'p');
if (key == -1) if (key == -1)
throw SystemException(Poco::format("cannot create named mutex %s (ftok() failed, errno=%d)", fileName, errno), _name); throw SystemException(Poco::format("cannot create named mutex %s (ftok() failed, errno=%d)", fileName, errno), _name);
_semid = semget(key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT | IPC_EXCL); _semid = semget(key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT | IPC_EXCL);