コミットメタ情報

リビジョン3c4a80d6dc9c8b9dddb94bf0b8c804ea73e4c064 (tree)
日時2013-06-04 20:04:14
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

Fix a bug where two or more users can't use xkeymacs at the same time on the same host

This fix append the user name to the name of each named pipe. It can
avoid the conflict of the multiple instances of xkeymacs on the same
host.

It also fixes a bug where 64bit DLL ignores any key press on the
failure in the IPC.

変更サマリ

差分

--- a/xkeymacs/mainfrm.cpp
+++ b/xkeymacs/mainfrm.cpp
@@ -165,7 +165,7 @@ void CMainFrame::TerminatePollThread()
165165 DWORD ack, read;
166166 IPC32Message msg;
167167 msg.Type = IPC32_TERMINATE;
168- CallNamedPipe(XKEYMACS32_PIPE, &msg, sizeof(msg.Type), &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT);
168+ CallNamedPipe(PipeName(PIPENAME_IPC32).GetName(), &msg, sizeof(msg.Type), &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT);
169169 WaitForSingleObject(m_hThread, 5000);
170170 CloseHandle(m_hThread);
171171 }
@@ -196,7 +196,7 @@ bool SendAck(HANDLE pipe)
196196
197197 DWORD WINAPI CMainFrame::PollMessage(LPVOID)
198198 {
199- HANDLE pipe = CreateNamedPipe(XKEYMACS32_PIPE, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, 1,
199+ HANDLE pipe = CreateNamedPipe(PipeName(PIPENAME_IPC32).GetName(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, 1,
200200 sizeof(DWORD), sizeof(IPC32Message), 0, NULL);
201201 if (pipe == INVALID_HANDLE_VALUE) {
202202 #ifdef DEBUG_IPC
--- a/xkeymacs/profile.cpp
+++ b/xkeymacs/profile.cpp
@@ -8,6 +8,7 @@
88 #include "mainfrm.h"
99 #include "../xkeymacsdll/xkeymacsdll.h"
1010 #include "../xkeymacsdll/Utils.h"
11+#include "../xkeymacsdll/PipeName.h"
1112
1213 #ifdef _DEBUG
1314 #undef THIS_FILE
@@ -269,6 +270,7 @@ void CProfile::SetDllData()
269270 appConfig.CmdID[CONTROL]['X'] = 1; // C-x is available.
270271 }
271272 m_Config.Is106Keyboard = Is106Keyboard();
273+ _tcscpy_s(m_Config.PipeNameForIPC32, PipeName(PIPENAME_IPC32).GetName());
272274 CXkeymacsDll::SetConfig(m_Config);
273275 if (!CXkeymacsApp::IsWow64())
274276 return;
--- a/xkeymacs/xkeymacs-vc10.vcxproj
+++ b/xkeymacs/xkeymacs-vc10.vcxproj
@@ -105,7 +105,7 @@
105105 <GenerateDebugInformation>true</GenerateDebugInformation>
106106 <SubSystem>Windows</SubSystem>
107107 <AdditionalLibraryDirectories>C:\WinDDK\7600.16385.1\lib\Mfc\i386;C:\WinDDK\7600.16385.1\lib\ATL\i386</AdditionalLibraryDirectories>
108- <AdditionalDependencies>Version.lib;ShLwApi.Lib;Imm32.lib;$(SolutionDir)xkeymacsdll\$(IntDir)$(TargetName).lib</AdditionalDependencies>
108+ <AdditionalDependencies>Secur32.lib;Version.lib;ShLwApi.Lib;Imm32.lib;$(SolutionDir)xkeymacsdll\$(IntDir)$(TargetName).lib</AdditionalDependencies>
109109 <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
110110 </Link>
111111 <ResourceCompile>
@@ -128,7 +128,7 @@
128128 <GenerateDebugInformation>true</GenerateDebugInformation>
129129 <SubSystem>Windows</SubSystem>
130130 <AdditionalLibraryDirectories>C:\WinDDK\7600.16385.1\lib\Mfc\amd64;C:\WinDDK\7600.16385.1\lib\ATL\amd64</AdditionalLibraryDirectories>
131- <AdditionalDependencies>Version.lib;ShLwApi.Lib;Imm32.lib;$(SolutionDir)xkeymacsdll\$(IntDir)$(TargetName).lib</AdditionalDependencies>
131+ <AdditionalDependencies>Secur32.lib;Version.lib;ShLwApi.Lib;Imm32.lib;$(SolutionDir)xkeymacsdll\$(IntDir)$(TargetName).lib</AdditionalDependencies>
132132 <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
133133 </Link>
134134 <ResourceCompile>
@@ -157,7 +157,7 @@
157157 <EnableCOMDATFolding>true</EnableCOMDATFolding>
158158 <OptimizeReferences>true</OptimizeReferences>
159159 <AdditionalLibraryDirectories>C:\WinDDK\7600.16385.1\lib\Mfc\i386;C:\WinDDK\7600.16385.1\lib\ATL\i386</AdditionalLibraryDirectories>
160- <AdditionalDependencies>Version.lib;ShLwApi.Lib;Imm32.lib;$(SolutionDir)xkeymacsdll\$(IntDir)$(TargetName).lib</AdditionalDependencies>
160+ <AdditionalDependencies>Secur32.lib;Version.lib;ShLwApi.Lib;Imm32.lib;$(SolutionDir)xkeymacsdll\$(IntDir)$(TargetName).lib</AdditionalDependencies>
161161 <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
162162 </Link>
163163 <ResourceCompile>
@@ -185,7 +185,7 @@
185185 <EnableCOMDATFolding>true</EnableCOMDATFolding>
186186 <OptimizeReferences>true</OptimizeReferences>
187187 <AdditionalLibraryDirectories>C:\WinDDK\7600.16385.1\lib\Mfc\amd64;C:\WinDDK\7600.16385.1\lib\ATL\amd64</AdditionalLibraryDirectories>
188- <AdditionalDependencies>Version.lib;ShLwApi.Lib;Imm32.lib;$(SolutionDir)xkeymacsdll\$(IntDir)$(TargetName).lib</AdditionalDependencies>
188+ <AdditionalDependencies>Secur32.lib;Version.lib;ShLwApi.Lib;Imm32.lib;$(SolutionDir)xkeymacsdll\$(IntDir)$(TargetName).lib</AdditionalDependencies>
189189 <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
190190 </Link>
191191 <ResourceCompile>
--- a/xkeymacs/xkeymacs.cpp
+++ b/xkeymacs/xkeymacs.cpp
@@ -17,6 +17,7 @@ static char THIS_FILE[] = __FILE__;
1717 // CXkeymacsApp
1818
1919 HANDLE CXkeymacsApp::m_64bitProcessHandle = INVALID_HANDLE_VALUE;
20+PipeName CXkeymacsApp::m_PipeNameForIPC64;
2021
2122 BEGIN_MESSAGE_MAP(CXkeymacsApp, CWinApp)
2223 //{{AFX_MSG_MAP(CXkeymacsApp)
@@ -77,6 +78,7 @@ BOOL CXkeymacsApp::InitInstance()
7778
7879 if (IsWow64() && !Start64bitProcess())
7980 return FALSE;
81+ m_PipeNameForIPC64.Init(PIPENAME_IPC64);
8082 CProfile::LoadData();
8183 CProfile::SetDllData();
8284
@@ -137,7 +139,7 @@ void CXkeymacsApp::SendIPC64Message(DWORD msg)
137139 return;
138140 DWORD ack, read;
139141 for (int i = 0; i < 10; Sleep(100), ++i)
140- if (CallNamedPipe(XKEYMACS64_PIPE, &msg, sizeof(msg), &ack, sizeof(DWORD), &read, NMPWAIT_WAIT_FOREVER))
142+ if (CallNamedPipe(m_PipeNameForIPC64.GetName(), &msg, sizeof(msg), &ack, sizeof(DWORD), &read, NMPWAIT_WAIT_FOREVER))
141143 return;
142144 #ifdef DEBUG_IPC
143145 else
--- a/xkeymacs/xkeymacs.h
+++ b/xkeymacs/xkeymacs.h
@@ -18,6 +18,7 @@
1818 // CXkeymacsApp:
1919 // See xkeymacs.cpp for the implementation of this class
2020 //
21+#include "../xkeymacsdll/PipeName.h"
2122
2223 class CXkeymacsApp : public CWinApp
2324 {
@@ -45,6 +46,8 @@ public:
4546 private:
4647 HANDLE m_hMutex;
4748 static HANDLE m_64bitProcessHandle;
49+ static PipeName m_PipeNameForIPC64;
50+
4851 };
4952
5053 //{{AFX_INSERT_LOCATION}}
--- a/xkeymacs/xkeymacs64.cpp
+++ b/xkeymacs/xkeymacs64.cpp
@@ -2,6 +2,7 @@
22 #include "mainfrm64.h"
33 #include "../xkeymacsdll/xkeymacsdll.h"
44 #include "../xkeymacsdll/Utils.h"
5+#include "../xkeymacsdll/PipeName.h"
56
67 CXkeymacsApp::CXkeymacsApp()
78 {
@@ -34,7 +35,6 @@ BOOL CXkeymacsApp::InitInstance()
3435 AfxBeginThread(PollIPCMessage, m_pMainWnd);
3536 if (start32bit)
3637 Start32bitProcess();
37- CXkeymacsDll::SetHooks();
3838 return TRUE;
3939 }
4040
@@ -64,7 +64,7 @@ bool SendAck(HANDLE pipe)
6464
6565 UINT PollIPCMessage(LPVOID param)
6666 {
67- HANDLE hPipe = CreateNamedPipe(XKEYMACS64_PIPE, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, 1, 512, 512, 0, NULL);
67+ HANDLE hPipe = CreateNamedPipe(PipeName(PIPENAME_IPC64).GetName(), PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, 1, 512, 512, 0, NULL);
6868 if (hPipe == INVALID_HANDLE_VALUE) {
6969 #ifdef DEBUG_IPC
7070 CUtils::Log(_T("PollIPCMessage: CreateNamedPipe failed. (%d)"), GetLastError());
@@ -92,7 +92,8 @@ UINT PollIPCMessage(LPVOID param)
9292 goto exit;
9393 break;
9494 case IPC64_RELOAD:
95- CXkeymacsDll::LoadConfig();
95+ if (CXkeymacsDll::LoadConfig())
96+ CXkeymacsDll::ResetHooks();
9697 break;
9798 case IPC64_DISABLE:
9899 CXkeymacsDll::SetHookStateDirect(false);
--- /dev/null
+++ b/xkeymacsdll/PipeName.cpp
@@ -0,0 +1,22 @@
1+#include "PipeName.h"
2+
3+void PipeName::Init(LPCTSTR name)
4+{
5+ m_PipeName = tstring(_T("\\\\.\\pipe\\")) + name;
6+ TCHAR uname[UNLEN + 1] = {_T('\0')};
7+ ULONG size = UNLEN + 1;
8+ if (GetUserName(uname, &size)) {
9+ tstring str(uname);
10+ for (auto iter = str.begin(); iter != str.end(); ++iter)
11+ if (*iter == _T('\\'))
12+ *iter = _T('-');
13+ m_PipeName = (m_PipeName + _T("-") + str).substr(0, 256);
14+
15+ }
16+ DWORD error = GetLastError();
17+}
18+
19+LPCTSTR PipeName::GetName()
20+{
21+ return m_PipeName.c_str();
22+}
\ No newline at end of file
--- /dev/null
+++ b/xkeymacsdll/PipeName.h
@@ -0,0 +1,15 @@
1+#pragma once
2+
3+#include "tstring.h"
4+
5+class AFX_EXT_CLASS PipeName
6+{
7+public:
8+ PipeName() {};
9+ PipeName(LPCTSTR name) { Init(name); };
10+ void Init(LPCTSTR name);
11+ LPCTSTR GetName();
12+private:
13+ tstring m_PipeName;
14+};
15+
--- a/xkeymacsdll/ipc.h
+++ b/xkeymacsdll/ipc.h
@@ -1,9 +1,4 @@
1-#ifndef IPC_H_INCLUDED
2-#define IPC_H_INCLUDED
3-
4-#if _MSC_VER > 1000
51 #pragma once
6-#endif // _MSC_VER > 1000
72
83 #include "defs.h"
94
@@ -21,10 +16,13 @@ struct AppConfig {
2116 bool IgnoreUndefMetaCtrl;
2217 };
2318
19+#define PIPENAME_MAX 256
20+
2421 struct Config {
2522 AppConfig AppConfig[MAX_APP];
2623 KeyBind FuncDefs[MAX_FUNCTION][MAX_DEFINITION];
2724 bool Is106Keyboard;
25+ TCHAR PipeNameForIPC32[PIPENAME_MAX + 1];
2826 };
2927
3028 enum XKEYMACS_IPC32 { IPC32_TERMINATE, IPC32_ICON, IPC32_HOOKSTATE };
@@ -44,6 +42,5 @@ struct IPC32Message {
4442 };
4543 };
4644
47-#define XKEYMACS32_PIPE _T("\\\\.\\pipe\\XKEYMACS_IPC32")
48-#define XKEYMACS64_PIPE _T("\\\\.\\pipe\\XKEYMACS_IPC64")
49-#endif
45+#define PIPENAME_IPC32 _T("xkeymacs32")
46+#define PIPENAME_IPC64 _T("xkeymacs64")
--- /dev/null
+++ b/xkeymacsdll/tstring.h
@@ -0,0 +1,8 @@
1+#pragma once
2+#include <string>
3+
4+#ifdef _UNICODE
5+typedef std::wstring tstring;
6+#else
7+typedef std::string tstring;
8+#endif
--- a/xkeymacsdll/xkeymacsdll-vc10.vcxproj
+++ b/xkeymacsdll/xkeymacsdll-vc10.vcxproj
@@ -106,7 +106,7 @@
106106 <SubSystem>Windows</SubSystem>
107107 <AdditionalLibraryDirectories>C:\WinDDK\7600.16385.1\lib\Mfc\i386;C:\WinDDK\7600.16385.1\lib\ATL\i386</AdditionalLibraryDirectories>
108108 <ModuleDefinitionFile>xkeymacsdll.def</ModuleDefinitionFile>
109- <AdditionalDependencies>Imm32.lib</AdditionalDependencies>
109+ <AdditionalDependencies>Secur32.lib;Imm32.lib</AdditionalDependencies>
110110 <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
111111 <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
112112 </Link>
@@ -131,7 +131,7 @@
131131 <SubSystem>Windows</SubSystem>
132132 <AdditionalLibraryDirectories>C:\WinDDK\7600.16385.1\lib\Mfc\amd64;C:\WinDDK\7600.16385.1\lib\ATL\amd64</AdditionalLibraryDirectories>
133133 <ModuleDefinitionFile>xkeymacs64dll.def</ModuleDefinitionFile>
134- <AdditionalDependencies>Imm32.lib</AdditionalDependencies>
134+ <AdditionalDependencies>Secur32.lib;Imm32.lib</AdditionalDependencies>
135135 <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
136136 <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
137137 </Link>
@@ -162,7 +162,7 @@
162162 <OptimizeReferences>true</OptimizeReferences>
163163 <AdditionalLibraryDirectories>C:\WinDDK\7600.16385.1\lib\Mfc\i386;C:\WinDDK\7600.16385.1\lib\ATL\i386</AdditionalLibraryDirectories>
164164 <ModuleDefinitionFile>xkeymacsdll.def</ModuleDefinitionFile>
165- <AdditionalDependencies>Imm32.lib</AdditionalDependencies>
165+ <AdditionalDependencies>Secur32.lib;Imm32.lib</AdditionalDependencies>
166166 <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
167167 <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
168168 </Link>
@@ -192,7 +192,7 @@
192192 <OptimizeReferences>true</OptimizeReferences>
193193 <AdditionalLibraryDirectories>C:\WinDDK\7600.16385.1\lib\Mfc\amd64;C:\WinDDK\7600.16385.1\lib\ATL\amd64</AdditionalLibraryDirectories>
194194 <ModuleDefinitionFile>xkeymacs64dll.def</ModuleDefinitionFile>
195- <AdditionalDependencies>Imm32.lib</AdditionalDependencies>
195+ <AdditionalDependencies>Secur32.lib;Imm32.lib</AdditionalDependencies>
196196 <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
197197 <ProgramDatabaseFile>$(IntDir)$(TargetName).pdb</ProgramDatabaseFile>
198198 </Link>
@@ -207,6 +207,7 @@
207207 <ClCompile Include="CmdTable.cpp" />
208208 <ClCompile Include="CmdTableData.cpp" />
209209 <ClCompile Include="Commands.cpp" />
210+ <ClCompile Include="PipeName.cpp" />
210211 <ClCompile Include="KbdMacro.cpp" />
211212 <ClCompile Include="StdAfx.cpp">
212213 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
@@ -229,9 +230,11 @@
229230 <ClInclude Include="Commands.h" />
230231 <ClInclude Include="defs.h" />
231232 <ClInclude Include="ipc.h" />
233+ <ClInclude Include="PipeName.h" />
232234 <ClInclude Include="KbdMacro.h" />
233235 <ClInclude Include="resource.h" />
234236 <ClInclude Include="StdAfx.h" />
237+ <ClInclude Include="tstring.h" />
235238 <ClInclude Include="Utils.h" />
236239 <ClInclude Include="xkeymacsdll.h" />
237240 </ItemGroup>
--- a/xkeymacsdll/xkeymacsdll-vc10.vcxproj.filters
+++ b/xkeymacsdll/xkeymacsdll-vc10.vcxproj.filters
@@ -45,6 +45,9 @@
4545 <ClCompile Include="CmdTableData.cpp">
4646 <Filter>Source Files</Filter>
4747 </ClCompile>
48+ <ClCompile Include="PipeName.cpp">
49+ <Filter>Source Files</Filter>
50+ </ClCompile>
4851 </ItemGroup>
4952 <ItemGroup>
5053 <None Include="xkeymacsdll.def">
@@ -91,6 +94,12 @@
9194 <ClInclude Include="CmdTable.h">
9295 <Filter>Header Files</Filter>
9396 </ClInclude>
97+ <ClInclude Include="tstring.h">
98+ <Filter>Header Files</Filter>
99+ </ClInclude>
100+ <ClInclude Include="PipeName.h">
101+ <Filter>Header Files</Filter>
102+ </ClInclude>
94103 </ItemGroup>
95104 <ItemGroup>
96105 <ResourceCompile Include="xkeymacsdll.rc">
--- a/xkeymacsdll/xkeymacsdll.cpp
+++ b/xkeymacsdll/xkeymacsdll.cpp
@@ -222,7 +222,7 @@ void CXkeymacsDll::SetHookState(bool enable)
222222 IPC32Message msg;
223223 msg.Type = IPC32_HOOKSTATE;
224224 msg.Enable = enable;
225- if (!CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, Enable) + sizeof(bool), &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT))
225+ if (!CallNamedPipe(m_Config.PipeNameForIPC32, &msg, offsetof(IPC32Message, Enable) + sizeof(bool), &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT))
226226 CUtils::Log(_T("SetHookState: CallNamedPipe failed. (%d)"), GetLastError());
227227
228228 ShowHookState();
@@ -777,7 +777,7 @@ void CXkeymacsDll::SendIconMessage(IconState *state, int num)
777777 IPC32Message msg;
778778 msg.Type = IPC32_ICON;
779779 memcpy(msg.IconState, state, num * sizeof(IconState));
780- if (!CallNamedPipe(XKEYMACS32_PIPE, &msg, offsetof(IPC32Message, IconState) + sizeof(IconState) * num, &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT)) {
780+ if (!CallNamedPipe(m_Config.PipeNameForIPC32, &msg, offsetof(IPC32Message, IconState) + sizeof(IconState) * num, &ack, sizeof(DWORD), &read, NMPWAIT_NOWAIT)) {
781781 #ifdef DEBUG_IPC
782782 CUtils::Log(_T("SendIconMessage: CallNamedPipe failed. (%d)"), GetLastError());
783783 #endif
旧リポジトリブラウザで表示