Save open's errno when opening temp rdb fails to prevent it from being modified (#1347)

Apparently on Mac, sleep will modify errno to ETIMEDOUT, and then it
prints the misleading message: Operation timed out.

Signed-off-by: Binbin <binloveplay1314@qq.com>
This commit is contained in:
Binbin 2024-11-25 23:56:51 +08:00 committed by GitHub
parent cf1a1e0931
commit 2d48a39c27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3688,7 +3688,11 @@ void syncWithPrimary(connection *conn) {
snprintf(tmpfile, 256, "temp-%d.%ld.rdb", (int)server.unixtime, (long int)getpid());
dfd = open(tmpfile, O_CREAT | O_WRONLY | O_EXCL, 0644);
if (dfd != -1) break;
/* We save the errno of open to prevent some systems from modifying it after
* the sleep call. For example, sleep in Mac will change errno to ETIMEDOUT. */
int saved_errno = errno;
sleep(1);
errno = saved_errno;
}
if (dfd == -1) {
serverLog(LL_WARNING, "Opening the temp file needed for PRIMARY <-> REPLICA synchronization: %s",