[Box Backup] PATCH: Working Solaris port
Martin Ebourne
boxbackup@fluffy.co.uk
Fri, 3 Dec 2004 12:16:54 +0000
This message is in MIME format.
--=_4fwug1k56vb4
Content-Type: text/plain; charset="windows-1256"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
Finally had a few moments to finish this off, so here's the now tested and
working Solaris port.
The only change from the preliminary patch posted is to increase the timeout
on the backupstore test, as suggested by Ben. The tests now all pass to
success.
I have installed the client and server on Solaris and done a test backup and
restore. Only the most basic of testing but it seems to work.
One thing to note:
I have been having odd behaviour from libcrypto of openssl. If I link
dynamically then it breaks exception handling. This causes some of the tests
to fail but doesn't prevent box from running during normal usage. It does
mean, however, that when an exception is encountered you get a core dump
instead of an error message.
Linking statically resolves this. I'd be interested to hear if anyone else
finds the same, or if it works correctly for them. Quick test:
# bbackupquery broken
Box Backup Query Tool v0.08PLUS2, (c) Ben Summers 2003, 2004
Using configuration file /etc/box/bbackupd.conf
zsh: 13319 IOT instruction (core dumped) bbackupquery broken
If you get the core dump when linked dynamically you have the same problem.
Cheers,
Martin.
--=_4fwug1k56vb4
Content-Type: text/x-patch; charset="UTF-8";
name="bb-solaris-working.patch"
Content-Disposition: inline; filename="bb-solaris-working.patch"
Content-Transfer-Encoding: 7bit
diff -ur boxbackup-0.08PLUS2.orig/bin/bbackupd/BackupDaemon.cpp boxbackup-0.08PLUS2/bin/bbackupd/BackupDaemon.cpp
--- boxbackup-0.08PLUS2.orig/bin/bbackupd/BackupDaemon.cpp Thu Nov 18 14:47:09 2004
+++ boxbackup-0.08PLUS2/bin/bbackupd/BackupDaemon.cpp Fri Dec 3 11:03:46 2004
@@ -54,7 +54,12 @@
#include <sys/mount.h>
#include <signal.h>
#ifdef PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
- #include <mntent.h>
+ #ifdef PLATFORM_SUNOS
+ #include <cstdio>
+ #include <sys/mnttab.h>
+ #else
+ #include <mntent.h>
+ #endif
#endif
#include <sys/wait.h>
@@ -992,21 +997,53 @@
int numIDMaps = 0;
#ifdef PLATFORM_USES_MTAB_FILE_FOR_MOUNTS
- // Linux can't tell you where a directory is mounted. So we have to
- // read the mount entries from /etc/mtab! Bizarre that the OS itself
- // can't tell you, but there you go.
+ // Linux and others can't tell you where a directory is mounted. So we
+ // have to read the mount entries from /etc/mtab! Bizarre that the OS
+ // itself can't tell you, but there you go.
std::set<std::string, mntLenCompare> mountPoints;
// BLOCK
FILE *mountPointsFile = 0;
+#ifdef PLATFORM_SUNOS
+ // Open mounts file
+ mountPointsFile = ::fopen("/etc/mnttab", "r");
+ if(mountPointsFile == 0)
+ {
+ THROW_EXCEPTION(CommonException, OSFileError);
+ }
+
try
{
+
+ // Read all the entries, and put them in the set
+ struct mnttab entry;
+ while(getmntent(mountPointsFile, &entry) == 0)
+ {
+ TRACE1("Found mount point at %s\n", entry.mnt_mountp);
+ mountPoints.insert(std::string(entry.mnt_mountp));
+ }
+
+ // Close mounts file
+ ::fclose(mountPointsFile);
+ }
+ catch(...)
+ {
+ ::fclose(mountPointsFile);
+ throw;
+ }
+#else
// Open mounts file
+ mountPointsFile = ::setmntent("/proc/mounts", "r");
+ if(mountPointsFile == 0)
+ {
mountPointsFile = ::setmntent("/etc/mtab", "r");
+ }
if(mountPointsFile == 0)
{
THROW_EXCEPTION(CommonException, OSFileError);
}
+ try
+ {
// Read all the entries, and put them in the set
struct mntent *entry = 0;
while((entry = ::getmntent(mountPointsFile)) != 0)
@@ -1020,12 +1057,10 @@
}
catch(...)
{
- if(mountPointsFile != 0)
- {
::endmntent(mountPointsFile);
- }
throw;
}
+#endif
// Check sorting and that things are as we expect
ASSERT(mountPoints.size() > 0);
#ifndef NDEBUG
diff -ur boxbackup-0.08PLUS2.orig/infrastructure/BoxPlatform.pm boxbackup-0.08PLUS2/infrastructure/BoxPlatform.pm
--- boxbackup-0.08PLUS2.orig/infrastructure/BoxPlatform.pm Thu Nov 18 14:47:08 2004
+++ boxbackup-0.08PLUS2/infrastructure/BoxPlatform.pm Fri Dec 3 11:03:46 2004
@@ -40,7 +40,7 @@
package BoxPlatform;
use Exporter;
@ISA = qw/Exporter/;
-@EXPORT = qw/$build_os $make_command $bsd_make $platform_define $gcc_v3 $product_version $product_name $install_into_dir $sub_make_options $platform_compile_line_extra $platform_link_line_extra/;
+@EXPORT = qw/$build_os $build_cpu $make_command $bsd_make $platform_define $platform_cpu $gcc_v3 $product_version $product_name $install_into_dir $sub_make_options $platform_compile_line_extra $platform_link_line_extra/;
BEGIN
{
@@ -48,13 +48,17 @@
# which OS are we building under?
$build_os = `uname`;
chomp $build_os;
+ $build_cpu = `uname -p`;
+ chomp $build_cpu;
# Cygwin Builds usually something like CYGWIN_NT-5.0, CYGWIN_NT-5.1
# Box Backup tried on Win2000,XP only :)
+
$build_os = 'CYGWIN' if $build_os =~ m/CYGWIN/;
- $make_command = ($build_os ne 'Darwin')?'make':'bsdmake';
- $bsd_make = ($build_os ne 'Linux' && $build_os ne 'CYGWIN');
+ $make_command = ($build_os eq 'Darwin') ? 'bsdmake' : ($build_os eq 'SunOS') ? 'gmake' : 'make';
+ $bsd_make = ($build_os ne 'Linux' && $build_os ne 'CYGWIN' && $build_os ne "SunOS");
$platform_define = 'PLATFORM_'.uc($build_os);
+ $platform_cpu = 'PLATFORM_'.uc($build_cpu);
# blank extra flags by default
$platform_compile_line_extra = '';
@@ -98,6 +102,11 @@
$platform_compile_line_extra = '-I/sw/include ';
$platform_link_line_extra = '-L/sw/lib ';
}
+ }
+
+ if($build_os eq 'SunOS')
+ {
+ $platform_link_line_extra = '-lrt ';
}
}
diff -ur boxbackup-0.08PLUS2.orig/infrastructure/makebuildenv.pl boxbackup-0.08PLUS2/infrastructure/makebuildenv.pl
--- boxbackup-0.08PLUS2.orig/infrastructure/makebuildenv.pl Thu Nov 18 14:47:08 2004
+++ boxbackup-0.08PLUS2/infrastructure/makebuildenv.pl Fri Dec 3 11:03:46 2004
@@ -784,13 +784,13 @@
AR = ar
RANLIB = ranlib
.ifdef RELEASE
-CXXFLAGS = -DNDEBUG -O2 -Wall $include_paths -D$platform_define$extra_platform_defines -DBOX_VERSION="\\"$product_version\\""
+CXXFLAGS = -DNDEBUG -O2 -Wall $include_paths -D$platform_define -D$platform_cpu$extra_platform_defines -DBOX_VERSION="\\"$product_version\\""
OUTBASE = ../../release
OUTDIR = ../../release/$mod
DEPENDMAKEFLAGS = -D RELEASE
VARIENT = RELEASE
.else
-CXXFLAGS = -g -Wall $include_paths -D$platform_define$extra_platform_defines -DBOX_VERSION="\\"$product_version\\""
+CXXFLAGS = -g -Wall $include_paths -D$platform_define -D$platform_cpu$extra_platform_defines -DBOX_VERSION="\\"$product_version\\""
OUTBASE = ../../debug
OUTDIR = ../../debug/$mod
DEPENDMAKEFLAGS =
@@ -912,7 +912,7 @@
# run make for things we require
for my $dep (@all_deps_for_module)
{
- $deps_makeinfo .= "\t\t(cd ../../$dep; $make_command$sub_make_options \$(DEPENDMAKEFLAGS) -D NODEPS)\n";
+ $deps_makeinfo .= "\t\t(cd ../../$dep; \$(MAKE)$sub_make_options \$(DEPENDMAKEFLAGS) -D NODEPS)\n";
}
$deps_makeinfo .= ".\tendif\n.endif\n\n";
}
@@ -986,7 +986,7 @@
print MAKE "clean:\n\t-rm -rf \$(OUTDIR)/*\n.\tifndef SUBCLEAN\n";
for my $dep (@all_deps_for_module)
{
- print MAKE "\t(cd ../../$dep; $make_command \$(DEPENDMAKEFLAGS) -D SUBCLEAN clean)\n";
+ print MAKE "\t(cd ../../$dep; \$(MAKE) \$(DEPENDMAKEFLAGS) -D SUBCLEAN clean)\n";
}
print MAKE ".\tendif\n";
diff -ur boxbackup-0.08PLUS2.orig/infrastructure/makeparcels.pl boxbackup-0.08PLUS2/infrastructure/makeparcels.pl
--- boxbackup-0.08PLUS2.orig/infrastructure/makeparcels.pl Thu Nov 18 14:47:08 2004
+++ boxbackup-0.08PLUS2/infrastructure/makeparcels.pl Fri Dec 3 11:03:46 2004
@@ -138,7 +138,7 @@
if($type eq 'bin')
{
my $exeext = ($build_os eq 'CYGWIN')?'.exe':'';
- print MAKE "\t(cd bin/$name; $make_command $release_flag)\n";
+ print MAKE "\t(cd bin/$name; \$(MAKE) $release_flag)\n";
print MAKE "\tcp release/bin/$name/$name$exeext $dir\n";
}
elsif ($type eq 'script')
@@ -183,7 +183,7 @@
for(@parcels)
{
- print INSTALLMSG " make install-".$_."\n";
+ print INSTALLMSG " $make_command install-".$_."\n";
}
print INSTALLMSG "\n";
diff -ur boxbackup-0.08PLUS2.orig/lib/common/BoxPlatform.h boxbackup-0.08PLUS2/lib/common/BoxPlatform.h
--- boxbackup-0.08PLUS2.orig/lib/common/BoxPlatform.h Thu Nov 18 14:47:07 2004
+++ boxbackup-0.08PLUS2/lib/common/BoxPlatform.h Fri Dec 3 11:03:46 2004
@@ -169,7 +169,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"
@@ -181,6 +181,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
@@ -190,7 +225,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
@@ -226,6 +261,16 @@
#define PLATFORM_RANDOM_DEVICE_NONE
#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
diff -ur boxbackup-0.08PLUS2.orig/lib/common/NamedLock.cpp boxbackup-0.08PLUS2/lib/common/NamedLock.cpp
--- boxbackup-0.08PLUS2.orig/lib/common/NamedLock.cpp Thu Nov 18 14:47:07 2004
+++ boxbackup-0.08PLUS2/lib/common/NamedLock.cpp Fri Dec 3 11:03:46 2004
@@ -51,12 +51,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"
@@ -110,12 +107,14 @@
}
// 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);
@@ -128,6 +127,25 @@
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;
diff -ur boxbackup-0.08PLUS2.orig/lib/raidfile/RaidFileRead.cpp boxbackup-0.08PLUS2/lib/raidfile/RaidFileRead.cpp
--- boxbackup-0.08PLUS2.orig/lib/raidfile/RaidFileRead.cpp Thu Nov 18 14:47:09 2004
+++ boxbackup-0.08PLUS2/lib/raidfile/RaidFileRead.cpp Fri Dec 3 11:03:46 2004
@@ -356,11 +356,7 @@
mEOF(false)
{
// Make sure size of the IOStream::pos_type matches the pos_type used
-#ifdef PLATFORM_LINUX
ASSERT(sizeof(pos_type) >= sizeof(off_t));
-#else
- ASSERT(sizeof(pos_type) == sizeof(off_t));
-#endif
// Sanity check handles
if(mStripe1Handle != -1 && mStripe2Handle != -1)
@@ -1585,18 +1581,22 @@
continue;
}
+ // Entry...
+ std::string name;
+ unsigned int countToAdd = 1;
+
// stat the file to find out what type it is
-/* struct stat st;
+#ifdef PLATFORM_SUNOS
+ struct stat st;
std::string fullName(dn + DIRECTORY_SEPARATOR + en->d_name);
- if(::stat(fullName.c_str(), &st) != 0)
+ if(::lstat(fullName.c_str(), &st) != 0)
{
THROW_EXCEPTION(RaidFileException, OSError)
- }*/
-
- // Entry...
- std::string name;
- unsigned int countToAdd = 1;
- if(DirReadType == DirReadType_FilesOnly && en->d_type == DT_REG) // (st.st_mode & S_IFDIR) == 0)
+ }
+ if(DirReadType == DirReadType_FilesOnly && (st.st_mode & S_IFDIR) == 0)
+#else
+ if(DirReadType == DirReadType_FilesOnly && en->d_type == DT_REG)
+#endif
{
// File. Complex, need to check the extension
int dot = -1;
@@ -1624,7 +1624,11 @@
}
}
}
- if(DirReadType == DirReadType_DirsOnly && en->d_type == DT_DIR) // (st.st_mode & S_IFDIR))
+#ifdef PLATFORM_SUNOS
+ if(DirReadType == DirReadType_DirsOnly && (st.st_mode & S_IFDIR))
+#else
+ if(DirReadType == DirReadType_DirsOnly && en->d_type == DT_DIR)
+#endif
{
// Directory, and we want directories
name = en->d_name;
diff -ur boxbackup-0.08PLUS2.orig/lib/raidfile/RaidFileUtil.cpp boxbackup-0.08PLUS2/lib/raidfile/RaidFileUtil.cpp
--- boxbackup-0.08PLUS2.orig/lib/raidfile/RaidFileUtil.cpp Thu Nov 18 14:47:09 2004
+++ boxbackup-0.08PLUS2/lib/raidfile/RaidFileUtil.cpp Fri Dec 3 11:03:46 2004
@@ -93,7 +93,7 @@
if(pRevisionID != 0)
{
(*pRevisionID) = FileModificationTime(st);
-#ifdef PLATFORM_LINUX
+#ifdef PLATFORM_stat_SHORT_mtime
// On linux, the time resolution is very low for modification times.
// So add the size to it to give a bit more chance of it changing.
// TODO: Make this better.
@@ -110,7 +110,7 @@
int64_t revisionID = 0;
int setSize = rDiscSet.size();
int rfCount = 0;
-#ifdef PLATFORM_LINUX
+#ifdef PLATFORM_stat_SHORT_mtime
// TODO: replace this with better linux revision ID detection
int64_t revisionIDplus = 0;
#endif
@@ -131,7 +131,7 @@
{
int64_t rid = FileModificationTime(st);
if(rid > revisionID) revisionID = rid;
-#ifdef PLATFORM_LINUX
+#ifdef PLATFORM_stat_SHORT_mtime
revisionIDplus += st.st_size;
#endif
}
@@ -140,7 +140,7 @@
if(pRevisionID != 0)
{
(*pRevisionID) = revisionID;
-#ifdef PLATFORM_LINUX
+#ifdef PLATFORM_stat_SHORT_mtime
(*pRevisionID) += revisionIDplus;
#endif
}
diff -ur boxbackup-0.08PLUS2.orig/lib/raidfile/RaidFileWrite.cpp boxbackup-0.08PLUS2/lib/raidfile/RaidFileWrite.cpp
--- boxbackup-0.08PLUS2.orig/lib/raidfile/RaidFileWrite.cpp Thu Nov 18 14:47:09 2004
+++ boxbackup-0.08PLUS2/lib/raidfile/RaidFileWrite.cpp Fri Dec 3 11:03:46 2004
@@ -151,10 +151,21 @@
}
// Get a lock on the write file
+#ifdef PLATFORM_open_USE_fcntl
+ int errnoBlock = EAGAIN;
+ struct flock desc;
+ desc.l_type = F_WRLCK;
+ desc.l_whence = SEEK_SET;
+ desc.l_start = 0;
+ desc.l_len = 0;
+ if(::fcntl(mOSFileHandle, F_SETLK, &desc) != 0)
+#else
+ int errnoBlock = EWOULDBLOCK;
if(::flock(mOSFileHandle, LOCK_EX | LOCK_NB) != 0)
+#endif
{
// Lock was not obtained.
- bool wasLocked = (errno == EWOULDBLOCK);
+ bool wasLocked = (errno == errnoBlock);
// Close the file
::close(mOSFileHandle);
mOSFileHandle = -1;
@@ -415,7 +426,7 @@
// Then open them all for writing (in strict order)
try
{
-#ifdef PLATFORM_LINUX
+#if defined(PLATFORM_open_USE_flock) || defined(PLATFORM_open_USE_fcntl)
FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe1(stripe1FilenameW.c_str());
FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> stripe2(stripe2FilenameW.c_str());
FileHandleGuard<(O_WRONLY | O_CREAT | O_EXCL)> parity(parityFilenameW.c_str());
@@ -487,11 +498,7 @@
{
// XOR in the size at the end of the parity block
ASSERT(sizeof(RaidFileRead::FileSizeType) == (2*sizeof(unsigned int)));
-#ifdef PLATFORM_LINUX
ASSERT(sizeof(RaidFileRead::FileSizeType) >= sizeof(off_t));
-#else
- ASSERT(sizeof(RaidFileRead::FileSizeType) == sizeof(off_t));
-#endif
int sizePos = (blockSize/sizeof(unsigned int)) - 2;
RaidFileRead::FileSizeType sw = hton64(writeFileStat.st_size);
unsigned int *psize = (unsigned int *)(&sw);
@@ -548,11 +555,7 @@
// if it can't be worked out some other means -- size is required to rebuild the file if one of the stripe files is missing
if(sizeRecordRequired)
{
-#ifdef PLATFORM_LINUX
ASSERT(sizeof(writeFileStat.st_size) <= sizeof(RaidFileRead::FileSizeType));
-#else
- ASSERT(sizeof(writeFileStat.st_size) == sizeof(RaidFileRead::FileSizeType));
-#endif
RaidFileRead::FileSizeType sw = hton64(writeFileStat.st_size);
ASSERT((::lseek(parity, 0, SEEK_CUR) % blockSize) == 0);
if(::write(parity, &sw, sizeof(sw)) != sizeof(sw))
diff -ur boxbackup-0.08PLUS2.orig/lib/server/Daemon.cpp boxbackup-0.08PLUS2/lib/server/Daemon.cpp
--- boxbackup-0.08PLUS2.orig/lib/server/Daemon.cpp Thu Nov 18 14:47:07 2004
+++ boxbackup-0.08PLUS2/lib/server/Daemon.cpp Fri Dec 3 11:03:46 2004
@@ -180,7 +180,11 @@
SetupInInitialProcess();
// Set signal handler
- if(::signal(SIGHUP, SignalHandler) == SIG_ERR || ::signal(SIGTERM, SignalHandler) == SIG_ERR)
+ struct sigaction sa;
+ sa.sa_handler = SignalHandler;
+ sa.sa_flags = 0;
+ ::sigemptyset(&sa.sa_mask);
+ if(::sigaction(SIGHUP, &sa, NULL) != 0 || ::sigaction(SIGTERM, &sa, NULL) != 0)
{
THROW_EXCEPTION(ServerException, DaemoniseFailed)
}
@@ -393,8 +397,12 @@
void Daemon::EnterChild()
{
// Unset signal handlers
- ::signal(SIGHUP, SIG_DFL);
- ::signal(SIGTERM, SIG_DFL);
+ struct sigaction sa;
+ sa.sa_handler = SIG_DFL;
+ sa.sa_flags = 0;
+ ::sigemptyset(&sa.sa_mask);
+ ::sigaction(SIGHUP, &sa, NULL);
+ ::sigaction(SIGTERM, &sa, NULL);
}
diff -ur boxbackup-0.08PLUS2.orig/lib/server/Protocol.cpp boxbackup-0.08PLUS2/lib/server/Protocol.cpp
--- boxbackup-0.08PLUS2.orig/lib/server/Protocol.cpp Thu Nov 18 14:47:07 2004
+++ boxbackup-0.08PLUS2/lib/server/Protocol.cpp Fri Dec 3 11:03:46 2004
@@ -462,7 +462,14 @@
READ_START_CHECK
READ_CHECK_BYTES_AVAILABLE(sizeof(int64_t))
- rOut = ntoh64(*((int64_t*)(mpBuffer + mReadOffset)));
+#ifdef PLATFORM_ALIGN_INT
+ int64_t nvalue;
+ memcpy(&nvalue, mpBuffer + mReadOffset, sizeof(int64_t));
+#else
+ int64_t nvalue = *((int64_t*)(mpBuffer + mReadOffset));
+#endif
+ rOut = ntoh64(nvalue);
+
mReadOffset += sizeof(int64_t);
}
@@ -479,7 +486,13 @@
READ_START_CHECK
READ_CHECK_BYTES_AVAILABLE(sizeof(int32_t))
- rOut = ntohl(*((int32_t*)(mpBuffer + mReadOffset)));
+#ifdef PLATFORM_ALIGN_INT
+ int32_t nvalue;
+ memcpy(&nvalue, mpBuffer + mReadOffset, sizeof(int32_t));
+#else
+ int32_t nvalue = *((int32_t*)(mpBuffer + mReadOffset));
+#endif
+ rOut = ntohl(nvalue);
mReadOffset += sizeof(int32_t);
}
@@ -584,7 +597,12 @@
WRITE_START_CHECK
WRITE_ENSURE_BYTES_AVAILABLE(sizeof(int64_t))
- *((int64_t*)(mpBuffer + mWriteOffset)) = hton64(Value);
+ int64_t nvalue = hton64(Value);
+#ifdef PLATFORM_ALIGN_INT
+ memcpy(mpBuffer + mWriteOffset, &nvalue, sizeof(int64_t));
+#else
+ *((int64_t*)(mpBuffer + mWriteOffset)) = nvalue;
+#endif
mWriteOffset += sizeof(int64_t);
}
@@ -602,7 +620,12 @@
WRITE_START_CHECK
WRITE_ENSURE_BYTES_AVAILABLE(sizeof(int32_t))
- *((int32_t*)(mpBuffer + mWriteOffset)) = htonl(Value);
+ int32_t nvalue = htonl(Value);
+#ifdef PLATFORM_ALIGN_INT
+ memcpy(mpBuffer + mWriteOffset, &nvalue, sizeof(int32_t));
+#else
+ *((int32_t*)(mpBuffer + mWriteOffset)) = nvalue;
+#endif
mWriteOffset += sizeof(int32_t);
}
diff -ur boxbackup-0.08PLUS2.orig/lib/server/SocketStreamTLS.cpp boxbackup-0.08PLUS2/lib/server/SocketStreamTLS.cpp
--- boxbackup-0.08PLUS2.orig/lib/server/SocketStreamTLS.cpp Thu Nov 18 14:47:07 2004
+++ boxbackup-0.08PLUS2/lib/server/SocketStreamTLS.cpp Fri Dec 3 11:03:46 2004
@@ -53,7 +53,7 @@
#include <openssl/bio.h>
#include <poll.h>
#include <errno.h>
-#include <sys/ioctl.h>
+#include <fcntl.h>
#include "SocketStreamTLS.h"
#include "SSLLib.h"
@@ -171,12 +171,23 @@
}
// Make the socket non-blocking so timeouts on Read work
- int nonblocking = true;
- if(::ioctl(socket, FIONBIO, &nonblocking) == -1)
+ // This is more portable than using ioctl with FIONBIO
+ int statusFlags = 0;
+ if(::fcntl(socket, F_GETFL, &statusFlags) < 0
+ || ::fcntl(socket, F_SETFL, statusFlags | O_NONBLOCK) == -1)
{
THROW_EXCEPTION(ServerException, SocketSetNonBlockingFailed)
}
+ // FIXME: This is less portable than the above. However, it MAY be needed
+ // for cygwin, which has/had bugs with fcntl
+ //
+ // int nonblocking = true;
+ // if(::ioctl(socket, FIONBIO, &nonblocking) == -1)
+ // {
+ // THROW_EXCEPTION(ServerException, SocketSetNonBlockingFailed)
+ // }
+
// Set the two to know about each other
::SSL_set_bio(mpSSL, mpBIO, mpBIO);
diff -ur boxbackup-0.08PLUS2.orig/test/backupstore/testbackupstore.cpp boxbackup-0.08PLUS2/test/backupstore/testbackupstore.cpp
--- boxbackup-0.08PLUS2.orig/test/backupstore/testbackupstore.cpp Thu Nov 18 14:47:10 2004
+++ boxbackup-0.08PLUS2/test/backupstore/testbackupstore.cpp Fri Dec 3 11:04:38 2004
@@ -623,9 +623,9 @@
int objectsNotDel;
int deleted;
int old;
-} recusive_count_objects_results;
+} recursive_count_objects_results;
-void recusive_count_objects_r(BackupProtocolClient &protocol, int64_t id, recusive_count_objects_results &results)
+void recursive_count_objects_r(BackupProtocolClient &protocol, int64_t id, recursive_count_objects_results &results)
{
// Command
std::auto_ptr<BackupProtocolClientSuccess> dirreply(protocol.QueryListDirectory(
@@ -650,12 +650,12 @@
if(en->GetFlags() & BackupStoreDirectory::Entry::Flags_Dir)
{
- recusive_count_objects_r(protocol, en->GetObjectID(), results);
+ recursive_count_objects_r(protocol, en->GetObjectID(), results);
}
}
}
-void recusive_count_objects(const char *hostname, int64_t id, recusive_count_objects_results &results)
+void recursive_count_objects(const char *hostname, int64_t id, recursive_count_objects_results &results)
{
// Context
TLSContext context;
@@ -676,7 +676,7 @@
}
// Count objects
- recusive_count_objects_r(protocolReadOnly, id, results);
+ recursive_count_objects_r(protocolReadOnly, id, results);
// Close it
protocolReadOnly.QueryFinished();
@@ -1745,9 +1745,9 @@
// Test the deletion of objects by the housekeeping system
// First, things as they are now.
- recusive_count_objects_results before = {0,0,0};
+ recursive_count_objects_results before = {0,0,0};
- recusive_count_objects("localhost", BackupProtocolClientListDirectory::RootDirectory, before);
+ recursive_count_objects("localhost", BackupProtocolClientListDirectory::RootDirectory, before);
TEST_THAT(before.objectsNotDel != 0);
TEST_THAT(before.deleted != 0);
@@ -1771,7 +1771,7 @@
// wait for housekeeping to happen
printf("waiting for housekeeping:\n");
- for(int l = 0; l < 12; ++l)
+ for(int l = 0; l < 30; ++l)
{
::sleep(1);
printf(".");
@@ -1780,9 +1780,11 @@
printf("\n");
// Count the objects again
- recusive_count_objects_results after = {0,0,0};
- recusive_count_objects("localhost", BackupProtocolClientListDirectory::RootDirectory, after);
-
+ recursive_count_objects_results after = {0,0,0};
+ recursive_count_objects("localhost", BackupProtocolClientListDirectory::RootDirectory, after);
+printf("after.objectsNotDel=%i, deleted=%i, old=%i\n",after.objectsNotDel, after.deleted, after.old);
+
+ // If these tests fail then try increasing the timeout above
TEST_THAT(after.objectsNotDel == before.objectsNotDel);
TEST_THAT(after.deleted == 0);
TEST_THAT(after.old == 0);
diff -ur boxbackup-0.08PLUS2.orig/test/common/testcommon.cpp boxbackup-0.08PLUS2/test/common/testcommon.cpp
--- boxbackup-0.08PLUS2.orig/test/common/testcommon.cpp Thu Nov 18 14:47:08 2004
+++ boxbackup-0.08PLUS2/test/common/testcommon.cpp Fri Dec 3 11:03:46 2004
@@ -436,9 +436,11 @@
TEST_THAT(lock1.TryAndGetLock("testfiles/lock1") == true);
// Try to lock something using the same lock
TEST_CHECK_THROWS(lock1.TryAndGetLock("testfiles/non-exist/lock2"), CommonException, NamedLockAlreadyLockingSomething);
+#ifndef PLATFORM_open_USE_fcntl
// And again on that name
NamedLock lock2;
TEST_THAT(lock2.TryAndGetLock("testfiles/lock1") == false);
+#endif
}
{
// Check that it unlocked when it went out of scope
diff -ur boxbackup-0.08PLUS2.orig/test/raidfile/intercept.cpp boxbackup-0.08PLUS2/test/raidfile/intercept.cpp
--- boxbackup-0.08PLUS2.orig/test/raidfile/intercept.cpp Thu Nov 18 14:47:09 2004
+++ boxbackup-0.08PLUS2/test/raidfile/intercept.cpp Fri Dec 3 11:03:46 2004
@@ -73,7 +73,7 @@
extern "C" off_t
TEST_lseek(int fildes, off_t offset, int whence);
#else
- #ifdef PLATFORM_LINUX
+ #if defined(PLATFORM_LINUX) || defined(PLATFORM_SUNOS)
#undef __syscall
#define __syscall syscall
#else
@@ -90,7 +90,7 @@
bool intercept_enabled = false;
const char *intercept_filename = 0;
int intercept_filedes = -1;
-unsigned int intercept_errorafter = 0;
+off_t intercept_errorafter = 0;
int intercept_errno = 0;
int intercept_syscall = 0;
off_t intercept_filepos = 0;
@@ -136,7 +136,7 @@
return true;
}
// where are we in the file?
- if(intercept_filepos >= intercept_errorafter || intercept_filepos >= ((int)intercept_errorafter - size))
+ if(intercept_filepos >= intercept_errorafter || intercept_filepos >= ((off_t)intercept_errorafter - size))
{
TRACE3("Returning error %d for syscall %d, file pos %d\n", intercept_errno, syscallnum, (int)intercept_filepos);
return true;
@@ -275,9 +275,11 @@
#ifdef PLATFORM_DARWIN
int r = TEST_lseek(fildes, offset, whence);
#else
- #ifdef PLATFORM_LINUX
+ #if defined(PLATFORM_LINUX) || defined(PLATFORM_SUNOS)
off_t r = __syscall(SYS_lseek, fildes, offset, whence);
#else
+ // Should swap this condition round. No reason to assume that most OS
+ // do this syscall wierdness, default should be the sensible way
off_t r = __syscall(SYS_lseek, fildes, 0 /* extra 0 required here! */, offset, whence);
#endif
#endif
diff -ur boxbackup-0.08PLUS2.orig/test/raidfile/testraidfile.cpp boxbackup-0.08PLUS2/test/raidfile/testraidfile.cpp
--- boxbackup-0.08PLUS2.orig/test/raidfile/testraidfile.cpp Thu Nov 18 14:47:09 2004
+++ boxbackup-0.08PLUS2/test/raidfile/testraidfile.cpp Fri Dec 3 11:03:46 2004
@@ -564,8 +564,10 @@
writeA.Write("TESTTEST", 8);
{
+#ifndef PLATFORM_open_USE_fcntl
RaidFileWrite writeA2(0, "overwrite_A");
TEST_CHECK_THROWS(writeA2.Open(), RaidFileException, FileIsCurrentlyOpenForWriting);
+#endif
}
}
--=_4fwug1k56vb4--