merged 1.4 r1043:1044 into trunk

This commit is contained in:
Nick Bolton
2011-06-18 23:44:23 +00:00
parent 7f4138a376
commit 2fe11744cf
28 changed files with 1101 additions and 267 deletions

View File

@@ -36,9 +36,6 @@
using namespace std;
int
ensureSingleInstance();
#if SYSAPI_UNIX
void
@@ -52,15 +49,12 @@ removeLock();
int
main(int argc, char **argv)
{
// make sure integ tests don't run in parallel.
int err = ensureSingleInstance();
if (err != 0)
return err;
#if SYSAPI_UNIX
// register SIGINT handling (to delete lock file)
signal(SIGINT, signalHandler);
atexit(removeLock);
#if SYSAPI_WIN32
if (CArchMiscWindows::isWindows95Family())
{
std::cerr << "Windows 95 family not supported." << std::endl;
return 1;
}
#endif
#if SYSAPI_WIN32
@@ -76,87 +70,3 @@ main(int argc, char **argv)
return RUN_ALL_TESTS();
}
int
ensureSingleInstance()
{
#if SYSAPI_WIN32
// get info for current process (we'll use the name later).
PROCESSENTRY32 selfEntry;
if (!CArchMiscWindows::getSelfProcessEntry(selfEntry))
cerr << "could not process info for self "
<< "(error: " << GetLastError() << ")" << endl;
// get current task list.
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot == INVALID_HANDLE_VALUE)
cerr << "could not get process snapshot "
<< "(error: " << GetLastError() << ")" << endl;
PROCESSENTRY32 entry;
BOOL gotEntry = Process32First(snapshot, &entry);
if (!gotEntry)
cerr << "could not get first process entry "
<< "(error: " << GetLastError() << ")" << endl;
while (gotEntry)
{
string checkName(entry.szExeFile);
// if entry has the same name as this process, but is not
// the current process...
if ((checkName.find(selfEntry.szExeFile) != string::npos) &&
(entry.th32ProcessID != selfEntry.th32ProcessID))
{
cerr << "error: process already running: "
<< entry.th32ProcessID << " -> " << entry.szExeFile << endl;
return ERROR_ALREADY_RUNNING;
}
gotEntry = Process32Next(snapshot, &entry);
}
#elif SYSAPI_UNIX
// fail if lock file exists
struct stat info;
int statResult = stat(LOCK_FILE, &info);
if (statResult == 0)
{
cerr << "error: lock file exists: " << LOCK_FILE << endl;
return ERROR_ALREADY_RUNNING;
}
// write an empty lock file
cout << "creating lock: " << LOCK_FILE << endl;
ofstream stream;
stream.open(LOCK_FILE);
if (!stream.is_open())
cerr << "error: could not create lock" << endl;
stream << "";
stream.close();
#endif
return 0;
}
#if SYSAPI_UNIX
void
signalHandler(int signal)
{
removeLock();
}
void
removeLock()
{
// remove lock file so other instances can run.
cout << "removing lock: " << LOCK_FILE << endl;
unlink(LOCK_FILE);
}
#endif