IPC: don't check for the file's existence before ftok()

It's documented to return -1 when the file doesn't exist, so we gain
nothing by saying a file we ourselves must have created doesn't exist.

Change-Id: I12a088d1ae424825abd3fffd171dfa1de6705787
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Thiago Macieira 2022-10-14 08:47:23 -07:00
parent 950e9dad0e
commit 3653ca72b1

View File

@ -72,19 +72,9 @@ 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);
unix_key = 0;
}
return unix_key;