Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: installer/src/installer-lib/process.cpp

Issue 6003395731128320: Only take into account processes that have our plugin loaded (Closed)
Left Patch Set: Changes for x64 custom action and addressing comments Created March 27, 2014, 11:22 p.m.
Right Patch Set: Simplify Process_Closer constructor Created March 31, 2014, 8:31 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « installer/src/installer-lib/process.h ('k') | installer/src/installer-lib/test/process_test.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include <stdexcept> 1 #include <stdexcept>
2 #include <functional> 2 #include <functional>
3 #include <wctype.h> 3 #include <wctype.h>
4 // <thread> is C++11, but implemented in VS2012 4 // <thread> is C++11, but implemented in VS2012
5 #include <thread> 5 #include <thread>
6 6
7 #include "process.h" 7 #include "process.h"
8 8
9 //------------------------------------------------------- 9 //-------------------------------------------------------
10 // Windows_Handle 10 // Windows_Handle
(...skipping 16 matching lines...) Expand all
27 validate_handle() ; 27 validate_handle() ;
28 } 28 }
29 29
30 void Windows_Handle::validate_handle() 30 void Windows_Handle::validate_handle()
31 { 31 {
32 if ( handle == INVALID_HANDLE_VALUE ) 32 if ( handle == INVALID_HANDLE_VALUE )
33 { 33 {
34 // TODO: This code really deserves use of a proper exception class that pack ages 34 // TODO: This code really deserves use of a proper exception class that pack ages
35 // Windows API errors consistently. 35 // Windows API errors consistently.
36 char tmp[256]; 36 char tmp[256];
37 » sprintf(tmp, "Invalid handle. Last error: %d", GetLastError()); 37 sprintf_s(tmp, "Invalid handle. Last error: %d", GetLastError());
Wladimir Palant 2014/03/28 07:30:17 sprintf() is deprecated, please use sprintf_s() in
38 throw std::runtime_error( tmp ) ; 38 throw std::runtime_error( tmp ) ;
39 } 39 }
40 } 40 }
41 41
42 //------------------------------------------------------- 42 //-------------------------------------------------------
43 // process_by_name_CI 43 // process_by_name_CI
44 //------------------------------------------------------- 44 //-------------------------------------------------------
45 process_by_name_CI::process_by_name_CI( const wchar_t * name ) 45 process_by_name_CI::process_by_name_CI( const wchar_t * name )
46 : name( name ), length( wcslen( name ) ) 46 : name( name ), length( wcslen( name ) )
47 {} 47 {}
48 48
49 bool process_by_name_CI::operator()( const PROCESSENTRY32W & process ) 49 bool process_by_name_CI::operator()( const PROCESSENTRY32W & process )
50 { 50 {
51 return 0 == wcsncmpi( process.szExeFile, name, length ) ; 51 return 0 == wcsncmpi( process.szExeFile, name, length ) ;
52 } 52 }
53 53
54 54
55 //-------------------------------------------------------
56 // process_by_any_exe_with_any_module
57 //-------------------------------------------------------
Wladimir Palant 2014/03/28 07:30:17 I guess I am missing the point of having of this c
58 bool process_by_any_exe_with_any_module::operator()( const PROCESSENTRY32W & pro cess ) 55 bool process_by_any_exe_with_any_module::operator()( const PROCESSENTRY32W & pro cess )
59 { 56 {
60 if ( processNames.find( process.szExeFile ) != processNames.end() ) 57 if (processNames.find(process.szExeFile) != processNames.end())
61 { 58 {
62 if (moduleNames.empty()) 59 if (moduleNames.empty())
63 » » return true; 60 return true;
64 61
65 » ModulesSnapshot ms( process.th32ProcessID ); 62 ModulesSnapshot ms(process.th32ProcessID);
66 » MODULEENTRY32* me = ms.begin(); 63 MODULEENTRY32W* me = ms.first();
67 » while ( me != ms.end() ) 64 while (me != NULL)
68 » { 65 {
69 » » if (moduleNames.find( me->szModule ) != moduleNames.end()) 66 if (moduleNames.find(me->szModule) != moduleNames.end())
70 » » { 67 {
71 » » » return true; 68 return true;
72 » » } 69 }
73 » » me = ms.next(); 70 me = ms.next();
74 » } 71 }
Wladimir Palant 2014/03/28 07:30:17 Nit: Please use spaces for indentation.
75 } 72 }
76 return false; 73 return false;
77 } 74 }
78 75
79 //------------------------------------------------------- 76 //-------------------------------------------------------
80 // wcscmpi 77 // wcscmpi
81 //------------------------------------------------------- 78 //-------------------------------------------------------
82 int wcscmpi( const wchar_t * s1, const wchar_t * s2 ) 79 int wcscmpi( const wchar_t * s1, const wchar_t * s2 )
83 { 80 {
84 // Note: Equality of character sequences is case-insensitive in all predicates below. 81 // Note: Equality of character sequences is case-insensitive in all predicates below.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 156
160 //------------------------------------------------------- 157 //-------------------------------------------------------
161 // Snapshot 158 // Snapshot
162 //------------------------------------------------------- 159 //-------------------------------------------------------
163 Snapshot::Snapshot() 160 Snapshot::Snapshot()
164 : handle( ::CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) ) 161 : handle( ::CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) )
165 { 162 {
166 process.dwSize = sizeof( PROCESSENTRY32W ) ; 163 process.dwSize = sizeof( PROCESSENTRY32W ) ;
167 } 164 }
168 165
169 PROCESSENTRY32W * Snapshot::begin() 166 PROCESSENTRY32W * Snapshot::first()
170 { 167 {
171 return ::Process32FirstW( handle, & process ) ? ( & process ) : 0 ; 168 return ::Process32FirstW(handle, &process) ? (&process) : 0;
172 } 169 }
173 170
174 PROCESSENTRY32W * Snapshot::next() 171 PROCESSENTRY32W * Snapshot::next()
175 { 172 {
176 return ::Process32NextW( handle, & process ) ? ( & process ) : 0 ; 173 return ::Process32NextW(handle, &process) ? (&process) : 0;
177 } 174 }
178 175
179 void Snapshot::refresh() 176 void Snapshot::refresh()
180 { 177 {
181 handle = ::CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ) ; 178 handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
182 } 179 }
183 180
184 181
185 //------------------------------------------------------- 182 //-------------------------------------------------------
186 // ModulesSnapshot 183 // ModulesSnapshot
187 //------------------------------------------------------- 184 //-------------------------------------------------------
188 ModulesSnapshot::ModulesSnapshot(DWORD processId) 185 ModulesSnapshot::ModulesSnapshot(DWORD processId)
189 : handle( ::CreateToolhelp32Snapshot( TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processId ) ) 186 : handle(::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, p rocessId))
Wladimir Palant 2014/03/28 07:30:17 Style nit: That's rather unusual style in this fil
190 { 187 {
191 module.dwSize = sizeof( MODULEENTRY32 ) ; 188 module.dwSize = sizeof(MODULEENTRY32);
192 } 189 }
193 190
194 MODULEENTRY32W * ModulesSnapshot::begin() 191 MODULEENTRY32W * ModulesSnapshot::first()
195 { 192 {
196 return ::Module32FirstW( handle, & module ) ? ( & module ) : 0 ; 193 return ::Module32FirstW(handle, &module) ? (&module) : 0;
197 } 194 }
198 195
199 MODULEENTRY32W * ModulesSnapshot::next() 196 MODULEENTRY32W * ModulesSnapshot::next()
200 { 197 {
201 return ::Module32NextW( handle, & module ) ? ( & module ) : 0 ; 198 return ::Module32NextW(handle, &module) ? (&module) : 0;
202 } 199 }
Wladimir Palant 2014/03/28 07:30:17 This fakes a C++ iterator interface but does so in
Eric 2014/03/28 12:06:00 Yep. It really ought be a proper iterator class, b
Oleksandr 2014/03/28 12:48:35 I actually like the way it is implemented. The ite
Wladimir Palant 2014/03/28 13:55:24 This is simply misleading, one looks at the loop a
Oleksandr 2014/03/28 14:28:16 Fixed in Patchset 4 On 2014/03/28 13:55:24, Wladim
203 200
204 201
205 //------------------------------------------------------- 202 //-------------------------------------------------------
206 // send_message, send_endsession_messages 203 // send_message, send_endsession_messages
207 //------------------------------------------------------- 204 //-------------------------------------------------------
208 /** 205 /**
209 * Default process exit wait time (per message) 5000 ms 206 * Default process exit wait time (per message) 5000 ms
210 * 207 *
211 * 5 seconds is time that the system will wait before it considers a process non -responsive. 208 * 5 seconds is time that the system will wait before it considers a process non -responsive.
212 */ 209 */
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if ( ! is_running() ) 445 if ( ! is_running() )
449 { 446 {
450 return true ; 447 return true ;
451 } 448 }
452 } 449 }
453 // Assert is_running() 450 // Assert is_running()
454 } 451 }
455 // No control path leaves the for-loop. 452 // No control path leaves the for-loop.
456 } ; 453 } ;
457 454
LEFTRIGHT

Powered by Google App Engine
This is Rietveld