From: H.G.Muller Date: Tue, 18 Jun 2019 15:03:11 +0000 (+0200) Subject: Pop up error when locking toerny file fails X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=7dda741fdfbf8ca233fde718f4b759119cce20bb;p=xboard.git Pop up error when locking toerny file fails The WinBoard implementation of flock is made compatible with the Linux version, returning 0 for success and -1 for fail. ReserveGame now tests this, and makes us drop out of tournament mode with an error popup when a failure occurs. --- diff --git a/backend.c b/backend.c index fe7ad95..77baf51 100644 --- a/backend.c +++ b/backend.c @@ -1522,7 +1522,10 @@ ReserveGame (int gameNr, char resChar) if(tf == NULL) { nextGame = appData.matchGames + 1; return; } // kludge to terminate match safeStrCpy(buf, lastMsg, MSG_SIZ); DisplayMessage(_("Pick new game"), ""); - flock(fileno(tf), LOCK_EX); // lock the tourney file while we are messing with it + if(flock(fileno(tf), LOCK_EX)) { // lock the tourney file while we are messing with it + abortMatch = TRUE; appData.matchMode = FALSE; DisplayError("Access to tourney file denied", 0); + fclose(tf); return; + } ParseArgsFromFile(tf); p = q = appData.results; if(appData.debugMode) { diff --git a/winboard/winboard.c b/winboard/winboard.c index 361f54f..ac5fc03 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -2068,8 +2068,6 @@ static int TranslatePieceToFontPiece( int piece ) case WhiteSilver: return PM_WSG; case WhiteLance: - - return PM_WL; case WhiteFalcon: return PM_WV; @@ -10257,19 +10255,19 @@ SettingsPopUp(ChessProgramState *cps) int flock(int fid, int code) { + int res; HANDLE hFile = (HANDLE) _get_osfhandle(fid); OVERLAPPED ov; ov.hEvent = NULL; ov.Offset = 0; ov.OffsetHigh = 0; switch(code) { - case 1: LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK, 0, 1024, 0, &ov); break; // LOCK_SH - - case 2: LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK, 0, 1024, 0, &ov); break; // LOCK_EX - case 3: UnlockFileEx(hFile, 0, 1024, 0, &ov); break; // LOCK_UN + case 1: res = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK, 0, 1024, 0, &ov); break; // LOCK_SH + case 2: res = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK, 0, 1024, 0, &ov); break; // LOCK_EX + case 3: res = UnlockFileEx(hFile, 0, 1024, 0, &ov); break; // LOCK_UN default: return -1; } - return 0; + return -!res; } char *