2012-06-10 16:50:54 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
2016-09-07 14:24:00 +00:00
|
|
|
* Copyright (C) 2012-2016 Symless Ltd.
|
2012-09-04 02:09:56 +00:00
|
|
|
* 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
|
2015-05-03 02:33:52 +00:00
|
|
|
* found in the file LICENSE that should have accompanied this file.
|
2012-06-10 16:50:54 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-02-28 12:36:45 +00:00
|
|
|
#include "platform/MSWindowsSession.h"
|
|
|
|
#include "synergy/XSynergy.h"
|
2014-10-27 16:39:18 +00:00
|
|
|
#include "arch/IArchMultithread.h"
|
2014-02-28 12:36:45 +00:00
|
|
|
|
2012-06-10 16:50:54 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
|
2014-11-11 13:51:47 +00:00
|
|
|
class Thread;
|
|
|
|
class IpcLogOutputter;
|
|
|
|
class IpcServer;
|
|
|
|
class FileLogOutputter;
|
2012-06-10 16:50:54 +00:00
|
|
|
|
2014-11-11 14:50:09 +00:00
|
|
|
class MSWindowsWatchdog {
|
2012-06-10 16:50:54 +00:00
|
|
|
public:
|
2016-12-28 11:50:32 +00:00
|
|
|
MSWindowsWatchdog(
|
|
|
|
bool autoDetectCommand,
|
|
|
|
IpcServer& ipcServer,
|
|
|
|
IpcLogOutputter& ipcLogOutputter);
|
|
|
|
virtual ~MSWindowsWatchdog();
|
2013-10-10 16:06:13 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
void startAsync();
|
|
|
|
std::string getCommand() const;
|
|
|
|
void setCommand(const std::string& command, bool elevate);
|
|
|
|
void stop();
|
|
|
|
bool isProcessActive();
|
|
|
|
void setFileLogOutputter(FileLogOutputter* outputter);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
private:
|
2016-12-28 11:50:32 +00:00
|
|
|
void mainLoop(void*);
|
|
|
|
void outputLoop(void*);
|
|
|
|
void shutdownProcess(HANDLE handle, DWORD pid, int timeout);
|
|
|
|
void shutdownExistingProcesses();
|
|
|
|
HANDLE duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES security);
|
|
|
|
HANDLE getUserToken(LPSECURITY_ATTRIBUTES security);
|
|
|
|
void startProcess();
|
|
|
|
BOOL doStartProcess(String& command, HANDLE userToken, LPSECURITY_ATTRIBUTES sa);
|
|
|
|
void sendSas();
|
|
|
|
void getActiveDesktop(LPSECURITY_ATTRIBUTES security);
|
|
|
|
void testOutput(String buffer);
|
2012-06-10 16:50:54 +00:00
|
|
|
|
|
|
|
private:
|
2016-12-28 11:50:32 +00:00
|
|
|
Thread* m_thread;
|
|
|
|
bool m_autoDetectCommand;
|
|
|
|
std::string m_command;
|
|
|
|
bool m_monitoring;
|
|
|
|
bool m_commandChanged;
|
|
|
|
HANDLE m_stdOutWrite;
|
|
|
|
HANDLE m_stdOutRead;
|
|
|
|
Thread* m_outputThread;
|
|
|
|
IpcServer& m_ipcServer;
|
|
|
|
IpcLogOutputter& m_ipcLogOutputter;
|
|
|
|
bool m_elevateProcess;
|
|
|
|
MSWindowsSession m_session;
|
|
|
|
PROCESS_INFORMATION m_processInfo;
|
|
|
|
int m_processFailures;
|
|
|
|
bool m_processRunning;
|
|
|
|
FileLogOutputter* m_fileLogOutputter;
|
|
|
|
bool m_autoElevated;
|
|
|
|
ArchMutex m_mutex;
|
|
|
|
ArchCond m_condVar;
|
|
|
|
bool m_ready;
|
2013-10-14 16:29:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//! Relauncher error
|
|
|
|
/*!
|
|
|
|
An error occured in the process watchdog.
|
|
|
|
*/
|
|
|
|
class XMSWindowsWatchdogError : public XSynergy {
|
|
|
|
public:
|
2016-12-28 11:50:32 +00:00
|
|
|
XMSWindowsWatchdogError(const String& msg) : XSynergy(msg) { }
|
2013-10-14 16:29:02 +00:00
|
|
|
|
2016-12-28 11:50:32 +00:00
|
|
|
// XBase overrides
|
|
|
|
virtual String getWhat() const throw() { return what(); }
|
2012-06-10 16:50:54 +00:00
|
|
|
};
|