2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2012-09-04 02:09:56 +00:00
|
|
|
* Copyright (C) 2012 Bolton Software Ltd.
|
|
|
|
* Copyright (C) 2009 Chris Schoeneman
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-10-14 16:29:02 +00:00
|
|
|
// TODO: rename class to CMSWindowsWatchdog
|
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2013-10-10 16:06:13 +00:00
|
|
|
#include "CMSWindowsSession.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
#include <Windows.h>
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
2013-10-14 16:29:02 +00:00
|
|
|
#include "XSynergy.h"
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
class CThread;
|
2012-07-03 14:15:05 +00:00
|
|
|
class CIpcLogOutputter;
|
2012-07-05 18:05:35 +00:00
|
|
|
class CIpcServer;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
class CMSWindowsRelauncher {
|
|
|
|
public:
|
2012-07-05 18:05:35 +00:00
|
|
|
CMSWindowsRelauncher(
|
|
|
|
bool autoDetectCommand,
|
|
|
|
CIpcServer& ipcServer,
|
|
|
|
CIpcLogOutputter& ipcLogOutputter);
|
2012-06-10 16:50:54 +00:00
|
|
|
virtual ~CMSWindowsRelauncher();
|
2013-10-10 16:06:13 +00:00
|
|
|
|
|
|
|
void startAsync();
|
2013-10-14 16:29:02 +00:00
|
|
|
std::string getCommand() const;
|
|
|
|
void setCommand(const std::string& command, bool elevate);
|
2013-10-10 16:06:13 +00:00
|
|
|
void stop();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
private:
|
2013-10-10 16:06:13 +00:00
|
|
|
void mainLoop(void*);
|
|
|
|
void outputLoop(void*);
|
|
|
|
void shutdownProcess(HANDLE handle, DWORD pid, int timeout);
|
|
|
|
void shutdownExistingProcesses();
|
2012-07-28 02:59:20 +00:00
|
|
|
HANDLE duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES security);
|
2013-10-10 16:06:13 +00:00
|
|
|
HANDLE getUserToken(LPSECURITY_ATTRIBUTES security);
|
2013-10-14 16:29:02 +00:00
|
|
|
void startProcess(std::string& command);
|
|
|
|
bool isProcessRunning();
|
|
|
|
void sendSas();
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
private:
|
2013-10-10 16:06:13 +00:00
|
|
|
CThread* m_thread;
|
|
|
|
bool m_autoDetectCommand;
|
|
|
|
std::string m_command;
|
2013-10-14 16:29:02 +00:00
|
|
|
bool m_monitoring;
|
2013-10-10 16:06:13 +00:00
|
|
|
bool m_commandChanged;
|
|
|
|
HANDLE m_stdOutWrite;
|
|
|
|
HANDLE m_stdOutRead;
|
|
|
|
CThread* m_outputThread;
|
2012-07-05 18:05:35 +00:00
|
|
|
CIpcServer& m_ipcServer;
|
|
|
|
CIpcLogOutputter& m_ipcLogOutputter;
|
2012-07-28 02:59:20 +00:00
|
|
|
bool m_elevateProcess;
|
2013-10-10 16:06:13 +00:00
|
|
|
CMSWindowsSession m_session;
|
2013-10-14 16:29:02 +00:00
|
|
|
bool m_launched;
|
|
|
|
PROCESS_INFORMATION m_processInfo;
|
|
|
|
int m_failures;
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Relauncher error
|
|
|
|
/*!
|
|
|
|
An error occured in the process watchdog.
|
|
|
|
*/
|
|
|
|
class XMSWindowsWatchdogError : public XSynergy {
|
|
|
|
public:
|
|
|
|
XMSWindowsWatchdogError(const CString& msg) : XSynergy(msg) { }
|
|
|
|
|
|
|
|
// XBase overrides
|
|
|
|
virtual CString getWhat() const throw() { return what(); }
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|