mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-01 09:22:58 -05:00
fix: preserve POSIX refresh lock ownership (#14781)
Use flock instead of fcntl for the refresh token lock on POSIX. An fcntl lock is held per process, so a second thread took it without waiting, and closing that thread's fd released it for the first thread too. Another Orca instance could then send the same refresh token while the first one was still rotating it.
This commit is contained in:
1 parent
0773f717cd
commit
1bc39fd358
1 file changed
+3
-3
@@ -71,6 +71,7 @@
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <cerrno>
|
||||
#endif
|
||||
|
||||
@@ -145,10 +146,9 @@ public:
|
||||
#else
|
||||
m_fd = ::open(path.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0600);
|
||||
if (m_fd == -1) { m_locked = true; return; } // can't open -> don't block
|
||||
struct flock fl{};
|
||||
fl.l_type = F_WRLCK; fl.l_whence = SEEK_SET; fl.l_start = 0; fl.l_len = 0;
|
||||
int rc;
|
||||
do { rc = ::fcntl(m_fd, F_SETLKW, &fl); } while (rc == -1 && errno == EINTR); // blocks in kernel
|
||||
// An fcntl lock would not block other threads in this process, and any close() of this file would release it.
|
||||
do { rc = ::flock(m_fd, LOCK_EX); } while (rc == -1 && errno == EINTR); // blocks in kernel
|
||||
m_locked = (rc != -1);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user