From 3a663092cfacd3da93ace684f792885710f98a12 Mon Sep 17 00:00:00 2001 From: SeokYeon Hwang Date: Tue, 21 Oct 2014 19:29:15 +0900 Subject: [PATCH 1/5] Do not throw exception if ProcessIdToSessionId() is failed. Many security solutions forbid other program from accessing their own process. So if ProcessIdToSessionId() is failed, simply ignore it. Signed-off-by: SeokYeon Hwang --- src/lib/platform/MSWindowsSession.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib/platform/MSWindowsSession.cpp b/src/lib/platform/MSWindowsSession.cpp index 0a7e63ac..0e453092 100644 --- a/src/lib/platform/MSWindowsSession.cpp +++ b/src/lib/platform/MSWindowsSession.cpp @@ -69,20 +69,23 @@ CMSWindowsSession::isProcessInSession(const char* name, PHANDLE process = NULL) entry.th32ProcessID, &processSessionId); if (!pidToSidRet) { + // if we can not acquire session associated with a specified process, + // simply ignore it LOG((CLOG_ERR "could not get session id for process id %i", entry.th32ProcessID)); - throw XArch(new XArchEvalWindows()); } + else { + // only pay attention to processes in the active session + if (processSessionId == m_activeSessionId) { - // only pay attention to processes in the active session - if (processSessionId == m_activeSessionId) { + // store the names so we can record them for debug + nameList.push_back(entry.szExeFile); - // store the names so we can record them for debug - nameList.push_back(entry.szExeFile); - - if (_stricmp(entry.szExeFile, name) == 0) { - pid = entry.th32ProcessID; + if (_stricmp(entry.szExeFile, name) == 0) { + pid = entry.th32ProcessID; + } } } + } // now move on to the next entry (if we're not at the end) From bc772f98a64ffc3e8f4ef5f7dc719a8d8a923385 Mon Sep 17 00:00:00 2001 From: Xinyu Hou Date: Wed, 22 Oct 2014 12:53:14 +0100 Subject: [PATCH 2/5] Unable to start synergy server with "Cannot create a file when that file already exists" message #3752 Go to next iteration as soon as it fails. --- src/lib/platform/MSWindowsSession.cpp | 34 +++++++++++++++++---------- src/lib/platform/MSWindowsSession.h | 4 ++++ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/lib/platform/MSWindowsSession.cpp b/src/lib/platform/MSWindowsSession.cpp index 0e453092..b9001a8d 100644 --- a/src/lib/platform/MSWindowsSession.cpp +++ b/src/lib/platform/MSWindowsSession.cpp @@ -21,7 +21,6 @@ #include "synergy/XSynergy.h" #include "base/Log.h" -#include #include CMSWindowsSession::CMSWindowsSession() : @@ -72,6 +71,8 @@ CMSWindowsSession::isProcessInSession(const char* name, PHANDLE process = NULL) // if we can not acquire session associated with a specified process, // simply ignore it LOG((CLOG_ERR "could not get session id for process id %i", entry.th32ProcessID)); + gotEntry = nextProcessEntry(snapshot, &entry); + continue; } else { // only pay attention to processes in the active session @@ -89,17 +90,7 @@ CMSWindowsSession::isProcessInSession(const char* name, PHANDLE process = NULL) } // now move on to the next entry (if we're not at the end) - gotEntry = Process32Next(snapshot, &entry); - if (!gotEntry) { - - DWORD err = GetLastError(); - if (err != ERROR_NO_MORE_FILES) { - - // only worry about error if it's not the end of the snapshot - LOG((CLOG_ERR "could not get next process entry")); - throw XArch(new XArchEvalWindows()); - } - } + gotEntry = nextProcessEntry(snapshot, &entry); } std::string nameListJoin; @@ -161,3 +152,22 @@ CMSWindowsSession::updateActiveSession() { m_activeSessionId = WTSGetActiveConsoleSessionId(); } + + +BOOL +CMSWindowsSession::nextProcessEntry(HANDLE snapshot, LPPROCESSENTRY32 entry) +{ + BOOL gotEntry = Process32Next(snapshot, entry); + if (!gotEntry) { + + DWORD err = GetLastError(); + if (err != ERROR_NO_MORE_FILES) { + + // only worry about error if it's not the end of the snapshot + LOG((CLOG_ERR "could not get next process entry")); + throw XArch(new XArchEvalWindows()); + } + } + + return gotEntry; +} diff --git a/src/lib/platform/MSWindowsSession.h b/src/lib/platform/MSWindowsSession.h index c1ba8d9a..d30ce0b4 100644 --- a/src/lib/platform/MSWindowsSession.h +++ b/src/lib/platform/MSWindowsSession.h @@ -19,6 +19,7 @@ #define WIN32_LEAN_AND_MEAN #include +#include class CMSWindowsSession { public: @@ -39,6 +40,9 @@ public: void updateActiveSession(); +private: + BOOL nextProcessEntry(HANDLE snapshot, LPPROCESSENTRY32 entry); + private: DWORD m_activeSessionId; }; From e0101b884fd4341e461c08b45d719811b6dd65a2 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Wed, 22 Oct 2014 13:55:39 +0100 Subject: [PATCH 3/5] added branch name to package names now that buildbot builds branches, it'll be handy to see that branch name in the package name. --- ext/toolchain/commands1.py | 40 ++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/ext/toolchain/commands1.py b/ext/toolchain/commands1.py index 0540bcb4..8888b7bb 100644 --- a/ext/toolchain/commands1.py +++ b/ext/toolchain/commands1.py @@ -946,17 +946,32 @@ class InternalCommands: def getGitRevision(self): if sys.version_info < (2, 4): raise Exception("Python 2.4 or greater required.") - else: - p = subprocess.Popen( - ["git", "log", "--pretty=format:%h", "-n", "1"], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - - stdout, stderr = p.communicate() - - if p.returncode != 0: - raise Exception('Could not get revision - git info failed with code: ' + str(p.returncode)) - return stdout + p = subprocess.Popen( + ["git", "log", "--pretty=format:%h", "-n", "1"], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + stdout, stderr = p.communicate() + + if p.returncode != 0: + raise Exception('Could not get revision, git error: ' + str(p.returncode)) + + return stdout.strip() + + def getGitBranchName(self): + if sys.version_info < (2, 4): + raise Exception("Python 2.4 or greater required.") + + p = subprocess.Popen( + ["git", "rev-parse", "--abbrev-ref", "HEAD"], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + stdout, stderr = p.communicate() + + if p.returncode != 0: + raise Exception('Could not get branch name, git error: ' + str(p.returncode)) + + return stdout.strip() def find_revision_svn(self): if sys.version_info < (2, 4): @@ -1422,9 +1437,10 @@ class InternalCommands: def dist_name_rev(self, type): # find the version number (we're puting the rev in after this) pattern = '(.*\d+\.\d+\.\d+)(.*)' - replace = '\g<1>-' + self.find_revision() + '\g<2>' + replace = "\g<1>-%s@%s\g<2>" % ( + self.getGitBranchName(), self.getGitRevision()) return re.sub(pattern, replace, self.dist_name(type)) - + def dist_usage(self): print ('Usage: %s package [package-type]\n' '\n' From aa8d6c95c79b09352ab72e6fb11a45afda90b265 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Wed, 22 Oct 2014 14:06:15 +0100 Subject: [PATCH 4/5] fixed "hm dist src" command to support branches also allowed non-unix platforms to run src --- ext/toolchain/commands1.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ext/toolchain/commands1.py b/ext/toolchain/commands1.py index 8888b7bb..04ac8c96 100644 --- a/ext/toolchain/commands1.py +++ b/ext/toolchain/commands1.py @@ -1019,10 +1019,7 @@ class InternalCommands: moveExt = '' if type == 'src': - if sys.platform in ['linux2', 'darwin']: - self.distSrc() - else: - package_unsupported = True + self.distSrc() elif type == 'rpm': if sys.platform == 'linux2': @@ -1206,11 +1203,15 @@ class InternalCommands: print "Removing existing export..." shutil.rmtree(exportPath) - print 'Exporting repository to: ' + exportPath os.mkdir(exportPath) - err = os.system('git archive master | tar -x -C ' + exportPath) + + cmd = "git archive %s | tar -x -C %s" % ( + self.getGitBranchName(), exportPath) + + print 'Exporting repository to: ' + exportPath + err = os.system(cmd) if err != 0: - raise Exception('Repository export failed: ' + str(err)) + raise Exception('Repository export failed: ' + str(err)) packagePath = '../' + self.getGenerator().binDir + '/' + name + '.tar.gz' From 74873d763eace2cb49cd60b208814f4079d71501 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Wed, 22 Oct 2014 14:56:57 +0100 Subject: [PATCH 5/5] changed @ to - in package name --- ext/toolchain/commands1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/toolchain/commands1.py b/ext/toolchain/commands1.py index 04ac8c96..1eee3a41 100644 --- a/ext/toolchain/commands1.py +++ b/ext/toolchain/commands1.py @@ -1438,7 +1438,7 @@ class InternalCommands: def dist_name_rev(self, type): # find the version number (we're puting the rev in after this) pattern = '(.*\d+\.\d+\.\d+)(.*)' - replace = "\g<1>-%s@%s\g<2>" % ( + replace = "\g<1>-%s-%s\g<2>" % ( self.getGitBranchName(), self.getGitRevision()) return re.sub(pattern, replace, self.dist_name(type))