| 980 | |
| 981 | |
| 982 | static void lockDatabaseFile(int& desc, const bool share, const bool temporary, |
| 983 | const char* fileName, ISC_STATUS operation) |
| 984 | { |
| 985 | bool shared = (!temporary) && share; |
| 986 | bool busy = false; |
| 987 | |
| 988 | do |
| 989 | { |
| 990 | #ifndef HAVE_FLOCK |
| 991 | struct FLOCK lck; |
| 992 | lck.l_type = shared ? F_RDLCK : F_WRLCK; |
| 993 | lck.l_whence = SEEK_SET; |
| 994 | lck.l_start = 0; |
| 995 | lck.l_len = 0; |
| 996 | |
| 997 | if (fcntl(desc, F_SETLK, &lck) == 0) |
| 998 | return; |
| 999 | busy = (errno == EACCES) || (errno == EAGAIN); |
| 1000 | #else |
| 1001 | if (flock(desc, (shared ? LOCK_SH : LOCK_EX) | LOCK_NB) == 0) |
| 1002 | return; |
| 1003 | busy = (errno == EWOULDBLOCK); |
| 1004 | #endif |
| 1005 | } while (errno == EINTR); |
| 1006 | |
| 1007 | maybeCloseFile(desc); |
| 1008 | |
| 1009 | Arg::Gds err(isc_io_error); |
| 1010 | err << "lock" << fileName; |
| 1011 | if (busy) |
| 1012 | err << Arg::Gds(isc_already_opened); |
| 1013 | else |
| 1014 | err << Arg::Gds(operation) << Arg::Unix(errno); |
| 1015 | ERR_post(err); |
| 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | static bool unix_error(const TEXT* string, |
no test coverage detected