Implement waiting for parent updater process to finish.

* Set the --wait argument when launching new updater processes with the ID of the process to wait for.
 * Add ProcessUtils::currentProcessId() utility method and PLATFORM_PID define
This commit is contained in:
Robert Knight 2011-08-22 18:46:03 +01:00
parent 57e13d941b
commit 50a21f004d
4 changed files with 28 additions and 4 deletions

View file

@ -1,5 +1,6 @@
#pragma once
// basic platform defines
#ifdef __linux__
#define PLATFORM_LINUX
#endif
@ -17,3 +18,9 @@
#define PLATFORM_UNIX
#endif
// platform-specific type aliases
#if defined(PLATFORM_UNIX)
#define PLATFORM_PID pid_t
#else
#define PLATFORM_PID DWORD
#endif

View file

@ -22,6 +22,15 @@
#include <mach-o/dyld.h>
#endif
PLATFORM_PID ProcessUtils::currentProcessId()
{
#ifdef PLATFORM_UNIX
return getpid();
#else
return GetCurrentProcessId();
#endif
}
int ProcessUtils::runSync(const std::string& executable,
const std::list<std::string>& args)
{
@ -74,10 +83,10 @@ void ProcessUtils::runElevated(const std::string& executable,
#endif
}
bool ProcessUtils::waitForProcess(long long pid)
bool ProcessUtils::waitForProcess(PLATFORM_PID pid)
{
#ifdef PLATFORM_UNIX
pid_t result = ::waitpid(static_cast<pid_t>(pid), 0, 0);
pid_t result = ::waitpid(pid, 0, 0);
if (result < 0)
{
LOG(Error,"waitpid() failed with error: " + std::string(strerror(errno)));
@ -86,7 +95,7 @@ bool ProcessUtils::waitForProcess(long long pid)
#elif defined(PLATFORM_WINDOWS)
HANDLE hProc;
if (!(hProc = OpenProcess(SYNCHRONIZE, FALSE, static_cast<DWORD>(pid))))
if (!(hProc = OpenProcess(SYNCHRONIZE, FALSE, pid)))
{
LOG(Error,"Unable to get process handle for pid " + intToStr(pid) + " last error " + intToStr(GetLastError()));
return false;

View file

@ -1,11 +1,15 @@
#pragma once
#include "Platform.h"
#include <list>
#include <string>
class ProcessUtils
{
public:
static PLATFORM_PID currentProcessId();
static std::string currentProcessPath();
static int runSync(const std::string& executable,
@ -17,7 +21,7 @@ class ProcessUtils
static void runElevated(const std::string& executable,
const std::list<std::string>& args);
static bool waitForProcess(long long pid);
static bool waitForProcess(PLATFORM_PID pid);
private:
static void runElevatedLinux(const std::string& executable,

View file

@ -77,6 +77,8 @@ void UpdateInstaller::run() throw ()
std::list<std::string> args = updaterArgs();
args.push_back("--mode");
args.push_back("main");
args.push_back("--wait");
args.push_back(intToStr(ProcessUtils::currentProcessId()));
if (!checkAccess())
{
@ -136,6 +138,8 @@ void UpdateInstaller::run() throw ()
std::list<std::string> args = updaterArgs();
args.push_back("--mode");
args.push_back("cleanup");
args.push_back("--wait");
args.push_back(intToStr(ProcessUtils::currentProcessId()));
ProcessUtils::runAsync(updaterPath,args);
}
else if (m_mode == Cleanup)