From 20465eb98f66786930e2b955a79a5231d21fe4c3 Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 25 Nov 2024 21:12:03 +0800 Subject: [PATCH] smaller scope Signed-off-by: Binbin --- src/replication.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/replication.c b/src/replication.c index 7785f3999c..92dcc3a105 100644 --- a/src/replication.c +++ b/src/replication.c @@ -3684,18 +3684,17 @@ void syncWithPrimary(connection *conn) { /* Prepare a suitable temp file for bulk transfer */ if (!useDisklessLoad()) { - /* 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; while (maxtries--) { 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; - saved_errno = errno; + /* 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) { - errno = saved_errno; serverLog(LL_WARNING, "Opening the temp file needed for PRIMARY <-> REPLICA synchronization: %s", strerror(errno)); goto error;