From 36562f351c91379a1c3185505521cf42a2f63d3d Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 10 May 2018 21:39:01 +0300 Subject: [PATCH] Better error message. GitOrigin-RevId: 90f177a01b941a8fe029fb6363858260a0ca1f3b --- tdutils/td/utils/port/FileFd.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tdutils/td/utils/port/FileFd.cpp b/tdutils/td/utils/port/FileFd.cpp index 17a2727f..b414744a 100644 --- a/tdutils/td/utils/port/FileFd.cpp +++ b/tdutils/td/utils/port/FileFd.cpp @@ -345,7 +345,7 @@ Status FileFd::lock(FileFd::LockFlags flags, int32 max_tries) { lock.l_whence = SEEK_SET; if (fcntl(get_native_fd(), F_SETLK, &lock) == -1) { - if (errno == EAGAIN && --max_tries > 0) { + if (errno == EAGAIN) { #elif TD_PORT_WINDOWS OVERLAPPED overlapped; std::memset(&overlapped, 0, sizeof(overlapped)); @@ -363,10 +363,14 @@ Status FileFd::lock(FileFd::LockFlags flags, int32 max_tries) { } if (!result) { - if (GetLastError() == ERROR_LOCK_VIOLATION && --max_tries > 0) { + if (GetLastError() == ERROR_LOCK_VIOLATION) { #endif - usleep_for(100000); - continue; + if (--max_tries > 0) { + usleep_for(100000); + continue; + } + + return OS_ERROR("Can't lock file because it is already in use; check for another program instance running"); } return OS_ERROR("Can't lock file");