MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / lockDatabaseFile

Function lockDatabaseFile

src/jrd/os/posix/unix.cpp:982–1016  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

980
981
982static 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
1019static bool unix_error(const TEXT* string,

Callers 3

unix.cppFile · 0.85
PIO_force_writeFunction · 0.85
PIO_openFunction · 0.85

Calls 4

GdsClass · 0.85
UnixClass · 0.85
maybeCloseFileFunction · 0.70
ERR_postFunction · 0.50

Tested by

no test coverage detected