summaryrefslogtreecommitdiffstats
path: root/src/corelib/ipc/qsharedmemory_systemv.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/ipc/qsharedmemory_systemv.cpp')
-rw-r--r--src/corelib/ipc/qsharedmemory_systemv.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/corelib/ipc/qsharedmemory_systemv.cpp b/src/corelib/ipc/qsharedmemory_systemv.cpp
index b14f5db39f..dc9de11091 100644
--- a/src/corelib/ipc/qsharedmemory_systemv.cpp
+++ b/src/corelib/ipc/qsharedmemory_systemv.cpp
@@ -11,9 +11,11 @@
#include <errno.h>
+#if QT_CONFIG(sharedmemory)
#if QT_CONFIG(sysv_shm)
#include <sys/types.h>
#include <sys/ipc.h>
+#include <sys/mman.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -71,19 +73,10 @@ key_t QSharedMemorySystemV::handle(QSharedMemoryPrivate *self)
return 0;
}
- // ftok requires that an actual file exists somewhere
- if (!QFile::exists(QFile::decodeName(nativeKeyFile))) {
- self->setError(QSharedMemory::NotFound,
- QSharedMemory::tr("%1: UNIX key file doesn't exist")
- .arg("QSharedMemory::handle:"_L1));
- return 0;
- }
-
unix_key = ftok(nativeKeyFile, int(self->nativeKey.type()));
- if (-1 == unix_key) {
- self->setError(QSharedMemory::KeyError,
- QSharedMemory::tr("%1: ftok failed")
- .arg("QSharedMemory::handle:"_L1));
+ if (unix_key < 0) {
+ self->setUnixErrorString("QSharedMemory::handle"_L1);
+ nativeKeyFile.clear();
unix_key = 0;
}
return unix_key;
@@ -167,6 +160,8 @@ bool QSharedMemorySystemV::attach(QSharedMemoryPrivate *self, QSharedMemory::Acc
int id = shmget(unix_key, 0, (mode == QSharedMemory::ReadOnly ? 0400 : 0600));
if (-1 == id) {
self->setUnixErrorString("QSharedMemory::attach (shmget)"_L1);
+ unix_key = 0;
+ nativeKeyFile.clear();
return false;
}
@@ -214,3 +209,4 @@ bool QSharedMemorySystemV::detach(QSharedMemoryPrivate *self)
QT_END_NAMESPACE
#endif // QT_CONFIG(sysv_shm)
+#endif // QT_CONFIG(sharedmemory)