Skip to content

Commit 8bf7d1b

Browse files
Fix a bug of invalid parameter for shm_open on macOS26
1 parent a64e060 commit 8bf7d1b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/tsharedmemory_unix.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,33 @@ bool TSharedMemory::attach()
112112
}
113113

114114
struct stat st;
115+
int flags = 0;
115116

116-
_fd = shm_open(qUtf8Printable(_name), O_RDWR | O_CLOEXEC, S_IRUSR | S_IWUSR);
117+
_fd = shm_open(qUtf8Printable(_name), O_RDWR, S_IRUSR | S_IWUSR);
117118
if (_fd < 0) {
118119
if (errno != ENOENT) {
119120
// error
121+
tSystemError("SharedMemory shm_open error. name:{} errno:{} [{}:{}]", _name, errno, __FILE__, __LINE__);
120122
goto error;
121123
}
122124
}
123125

126+
flags = fcntl(_fd, F_GETFD);
127+
if (flags < 0 || fcntl(_fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
128+
tSystemError("SharedMemory fcntl error. name:{} errno:{} [{}:{}]", _name, errno, __FILE__, __LINE__);
129+
goto error;
130+
}
131+
124132
if (fstat(_fd, &st) < 0) {
125133
// error
134+
tSystemError("SharedMemory fstat error. name:{} errno:{} [{}:{}]", _name, errno, __FILE__, __LINE__);
126135
goto error;
127136
}
128137

129138
_ptr = mmap(nullptr, st.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, _fd, 0);
130139
if (_ptr == MAP_FAILED) {
131140
// error
141+
tSystemError("SharedMemory mmap error. name:{} errno:{} [{}:{}]", _name, errno, __FILE__, __LINE__);
132142
goto error;
133143
}
134144

@@ -137,8 +147,6 @@ bool TSharedMemory::attach()
137147
return true;
138148

139149
error:
140-
tSystemError("SharedMemory attach error [{}:{}]", __FILE__, __LINE__);
141-
142150
if (_fd > 0) {
143151
tf_close(_fd);
144152
_fd = 0;

0 commit comments

Comments
 (0)