[Box Backup-dev] COMMIT r581 - in box/chris/general: bin/bbackupd lib/common lib/server test/basicserver test/basicserver/testfiles
boxbackup-dev@fluffy.co.uk
boxbackup-dev@fluffy.co.uk
Mon, 22 May 2006 13:04:15 +0000 (GMT)
Author: chris
Date: 2006-05-22 13:03:59 +0000 (Mon, 22 May 2006)
New Revision: 581
Modified:
box/chris/general/bin/bbackupd/bbackupd.cpp
box/chris/general/lib/common/Test.h
box/chris/general/lib/server/Daemon.cpp
box/chris/general/test/basicserver/testbasicserver.cpp
box/chris/general/test/basicserver/testfiles/srv2.conf
Log:
* test/basicserver/testfiles/srv2.conf
- UNIX sockets are not supported on Windows
* test/basicserver/testbasicserver.cpp
- Must initialise Winsock library before using it
- Don't try to HUP the server on Windows, we can't
- Don't check for memory leaks on Windows, the process dies before it can
write the file
* lib/server/Daemon.cpp
- Must initialise Winsock library before using it
* lib/common/Test.h
- Don't log failure to open process that doesn't exist
- Use TerminateProcess (for now) to kill the server
* bin/bbackupd/bbackupd.cpp
- Moved Winsock initialisation to Daemon class
Modified: box/chris/general/bin/bbackupd/bbackupd.cpp
===================================================================
--- box/chris/general/bin/bbackupd/bbackupd.cpp 2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/bin/bbackupd/bbackupd.cpp 2006-05-22 13:03:59 UTC (rev 581)
@@ -57,19 +57,7 @@
{
runAsWin32Service = true;
}
-
- // Under win32 we must initialise the Winsock library
- // before using sockets
-
- WSADATA info;
- if (WSAStartup(0x0101, &info) == SOCKET_ERROR)
- {
- // box backup will not run without sockets
- ::syslog(LOG_ERR, "Failed to initialise Windows Sockets");
- THROW_EXCEPTION(BackupStoreException, Internal)
- }
-
gpDaemonService = new Win32BackupService();
EnableBackupRights();
@@ -101,9 +89,6 @@
BOX_FILE_BBACKUPD_DEFAULT_CONFIG, argc, argv);
}
- // Clean up our sockets
- WSACleanup();
-
::closelog();
return ExitCode;
Modified: box/chris/general/lib/common/Test.h
===================================================================
--- box/chris/general/lib/common/Test.h 2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/lib/common/Test.h 2006-05-22 13:03:59 UTC (rev 581)
@@ -174,8 +174,11 @@
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, false, pid);
if (hProcess == NULL)
{
- printf("Failed to open process %d: error %d\n",
- pid, (int)GetLastError());
+ if (GetLastError() != ERROR_INVALID_PARAMETER)
+ {
+ printf("Failed to open process %d: error %d\n",
+ pid, (int)GetLastError());
+ }
return false;
}
CloseHandle(hProcess);
@@ -284,7 +287,24 @@
inline bool KillServer(int pid)
{
- TEST_THAT(SendCommands("terminate"));
+ HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, false, pid);
+ if (hProcess == NULL)
+ {
+ printf("Failed to open process %d: error %d\n",
+ pid, (int)GetLastError());
+ return false;
+ }
+
+ if (!TerminateProcess(hProcess, 1))
+ {
+ printf("Failed to terminate process %d: error %d\n",
+ pid, (int)GetLastError());
+ CloseHandle(hProcess);
+ return false;
+ }
+
+ CloseHandle(hProcess);
+
::sleep(1);
return !ServerIsAlive(pid);
}
Modified: box/chris/general/lib/server/Daemon.cpp
===================================================================
--- box/chris/general/lib/server/Daemon.cpp 2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/lib/server/Daemon.cpp 2006-05-22 13:03:59 UTC (rev 581)
@@ -23,6 +23,10 @@
#include <syslog.h>
#endif
+#ifdef WIN32
+ #include <ws2tcpip.h>
+#endif
+
#include "Daemon.h"
#include "Configuration.h"
#include "ServerException.h"
@@ -359,6 +363,20 @@
#endif
return 1;
}
+
+ // Under win32 we must initialise the Winsock library
+ // before using sockets
+
+ WSADATA info;
+
+ if (WSAStartup(0x0101, &info) == SOCKET_ERROR)
+ {
+ // will not run without sockets
+ ::syslog(LOG_ERR, "Failed to initialise Windows Sockets");
+ THROW_EXCEPTION(CommonException, Internal)
+ }
+
+ int retcode = 0;
// Main Daemon running
try
@@ -388,7 +406,8 @@
mConfigFileName.c_str(),
errors.c_str());
// And give up
- return 1;
+ retcode = 1;
+ break;
}
// delete old configuration
@@ -416,22 +435,24 @@
::syslog(LOG_ERR, "%s: terminating due to exception %s "
"(%d/%d)", DaemonName(), e.what(), e.GetType(),
e.GetSubType());
- return 1;
+ retcode = 1;
}
catch(std::exception &e)
{
::syslog(LOG_ERR, "%s: terminating due to exception %s",
DaemonName(), e.what());
- return 1;
+ retcode = 1;
}
catch(...)
{
::syslog(LOG_ERR, "%s: terminating due to unknown exception",
DaemonName());
- return 1;
+ retcode = 1;
}
+
+ WSACleanup();
- return 0;
+ return retcode;
}
// --------------------------------------------------------------------------
Modified: box/chris/general/test/basicserver/testbasicserver.cpp
===================================================================
--- box/chris/general/test/basicserver/testbasicserver.cpp 2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/test/basicserver/testbasicserver.cpp 2006-05-22 13:03:59 UTC (rev 581)
@@ -431,6 +431,14 @@
}
}
+#ifdef WIN32
+ // Under win32 we must initialise the Winsock library
+ // before using sockets
+
+ WSADATA info;
+ TEST_THAT(WSAStartup(0x0101, &info) != SOCKET_ERROR)
+#endif
+
//printf("SKIPPING TESTS------------------------\n");
//goto protocolserver;
@@ -460,6 +468,7 @@
"testfiles" DIRECTORY_SEPARATOR "srv1b.conf",
"testfiles" DIRECTORY_SEPARATOR "srv1.conf")
!= -1);
+#ifndef WIN32
// Get it to reread the config file
TEST_THAT(HUPServer(pid));
::sleep(1);
@@ -467,9 +476,12 @@
// Check that new file exists
TEST_THAT(TestFileExists("testfiles"
DIRECTORY_SEPARATOR "srv1.test2"));
+#endif // !WIN32
// Kill it off
TEST_THAT(KillServer(pid));
+#ifndef WIN32
TestRemoteProcessMemLeaks("generic-daemon.memleaks");
+#endif // !WIN32
}
}
@@ -488,36 +500,46 @@
{
// Will it restart?
TEST_THAT(ServerIsAlive(pid));
+#ifndef WIN32
TEST_THAT(HUPServer(pid));
::sleep(1);
TEST_THAT(ServerIsAlive(pid));
+#endif // !WIN32
// Make some connections
{
SocketStream conn1;
conn1.Open(Socket::TypeINET, "localhost", 2003);
+#ifndef WIN32
SocketStream conn2;
conn2.Open(Socket::TypeUNIX, "testfiles/srv2.sock");
SocketStream conn3;
conn3.Open(Socket::TypeINET, "localhost", 2003);
+#endif // !WIN32
// Quick check that reconnections fail
TEST_CHECK_THROWS(conn1.Open(Socket::TypeUNIX, "testfiles/srv2.sock");, ServerException, SocketAlreadyOpen);
// Stuff some data around
std::vector<IOStream *> conns;
conns.push_back(&conn1);
+#ifndef WIN32
conns.push_back(&conn2);
conns.push_back(&conn3);
+#endif // !WIN32
Srv2TestConversations(conns);
// Implicit close
}
+#ifndef WIN32
// HUP again
TEST_THAT(HUPServer(pid));
::sleep(1);
TEST_THAT(ServerIsAlive(pid));
+#endif // !WIN32
// Kill it
TEST_THAT(KillServer(pid));
::sleep(1);
TEST_THAT(!ServerIsAlive(pid));
+#ifndef WIN32
TestRemoteProcessMemLeaks("test-srv2.memleaks");
+#endif // !WIN32
}
}
Modified: box/chris/general/test/basicserver/testfiles/srv2.conf
===================================================================
--- box/chris/general/test/basicserver/testfiles/srv2.conf 2006-05-21 14:11:18 UTC (rev 580)
+++ box/chris/general/test/basicserver/testfiles/srv2.conf 2006-05-22 13:03:59 UTC (rev 581)
@@ -1,6 +1,6 @@
Server
{
PidFile = testfiles/srv2.pid
- ListenAddresses = inet:localhost,unix:testfiles/srv2.sock
+ ListenAddresses = inet:localhost
}