diff options
Diffstat (limited to 'lib/common')
-rwxr-xr-x | lib/common/BoxPlatform.h | 49 | ||||
-rwxr-xr-x | lib/common/NamedLock.cpp | 30 |
2 files changed, 71 insertions, 8 deletions
diff --git a/lib/common/BoxPlatform.h b/lib/common/BoxPlatform.h index 716366d2..3b75f992 100755 --- a/lib/common/BoxPlatform.h +++ b/lib/common/BoxPlatform.h @@ -133,7 +133,7 @@ #define PLATFORM_stat_SHORT_mtime #define PLATFORM_stat_NO_st_flags #define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS - #define PLATFORM_open_NO_O_EXLOCK + #define PLATFORM_open_USE_flock #define PLATFORM_sockaddr_NO_len #define PLATFORM_RANDOM_DEVICE "/dev/urandom" @@ -145,6 +145,41 @@ #endif // PLATFORM_LINUX +#ifdef PLATFORM_SUNOS + + #include <sys/types.h> + + // for ntohl etc... + #include <netinet/in.h> + + // types 'missing' + typedef uint8_t u_int8_t; +// typedef signed char int8_t; + typedef uint32_t u_int32_t; + typedef uint16_t u_int16_t; + typedef uint64_t u_int64_t; + + // not defined in Solaris, a BSD thing + #define INFTIM -1 + + //#define LLONG_MAX 9223372036854775807LL + //#define LLONG_MIN (-LLONG_MAX - 1LL) + + #define PLATFORM_STATIC_TEMP_DIRECTORY_NAME "/tmp" + + #define PLATFORM_BERKELEY_DB_NOT_SUPPORTED + #define PLATFORM_KQUEUE_NOT_SUPPORTED // This may be in Solaris 10 + #define PLATFORM_dirent_BROKEN_d_type // Well, no d_type at all actually + #define PLATFORM_stat_SHORT_mtime + #define PLATFORM_stat_NO_st_flags + #define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS + #define PLATFORM_open_USE_fcntl + #define PLATFORM_sockaddr_NO_len + + #define PLATFORM_RANDOM_DEVICE "/dev/urandom" + +#endif // PLATFORM_SUNOS + #ifdef PLATFORM_CYGWIN #define PLATFORM_BERKELEY_DB_NOT_SUPPORTED @@ -154,7 +189,7 @@ #define PLATFORM_stat_SHORT_mtime #define PLATFORM_stat_NO_st_flags #define PLATFORM_USES_MTAB_FILE_FOR_MOUNTS - #define PLATFORM_open_NO_O_EXLOCK + #define PLATFORM_open_USE_flock #define PLATFORM_sockaddr_NO_len #define PLATFORM_NO_BUILT_IN_SWAP64 @@ -192,6 +227,16 @@ #endif // PLATFORM_CYGWIN +// Check the processor type +#ifdef PLATFORM_SPARC + #define PLATFORM_ALIGN_INT +#endif + +#ifdef PLATFORM_ARM + #define PLATFORM_ALIGN_INT +#endif + + // Find out if credentials on UNIX sockets can be obtained #ifndef PLATFORM_HAVE_getpeereid #ifndef PLATFORM_HAVE_getsockopt_SO_PEERCRED diff --git a/lib/common/NamedLock.cpp b/lib/common/NamedLock.cpp index 1f6e038a..8953db89 100755 --- a/lib/common/NamedLock.cpp +++ b/lib/common/NamedLock.cpp @@ -12,12 +12,9 @@ #include <fcntl.h> #include <errno.h> #include <unistd.h> -#ifdef PLATFORM_LINUX +#ifdef PLATFORM_open_USE_flock #include <sys/file.h> -#endif // PLATFORM_LINUX -#ifdef PLATFORM_CYGWIN - #include <sys/file.h> -#endif // PLATFORM_CYGWIN +#endif // PLATFORM_open_USE_flock #include "NamedLock.h" #include "CommonException.h" @@ -71,12 +68,14 @@ bool NamedLock::TryAndGetLock(const char *Filename, int mode) } // See if the lock can be got -#ifdef PLATFORM_open_NO_O_EXLOCK +#if defined(PLATFORM_open_USE_flock) || defined(PLATFORM_open_USE_fcntl) int fd = ::open(Filename, O_WRONLY | O_CREAT | O_TRUNC, mode); if(fd == -1) { THROW_EXCEPTION(CommonException, OSFileError) } + +#ifdef PLATFORM_open_USE_flock if(::flock(fd, LOCK_EX | LOCK_NB) != 0) { ::close(fd); @@ -89,6 +88,25 @@ bool NamedLock::TryAndGetLock(const char *Filename, int mode) THROW_EXCEPTION(CommonException, OSFileError) } } +#else + struct flock desc; + desc.l_type = F_WRLCK; + desc.l_whence = SEEK_SET; + desc.l_start = 0; + desc.l_len = 0; + if(::fcntl(fd, F_SETLK, &desc) != 0) + { + ::close(fd); + if(errno == EAGAIN) + { + return false; + } + else + { + THROW_EXCEPTION(CommonException, OSFileError) + } + } +#endif // Success mFileDescriptor = fd; |