Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 "installer-lib.h" | 7 #include "installer-lib.h" |
8 #include "process.h" | 8 #include "process.h" |
9 #include "handle.h" | 9 #include "handle.h" |
10 #include "session.h" | 10 #include "session.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 * The present use of this method is not closing dozens of applications, so delay performance is not critical. | 209 * The present use of this method is not closing dozens of applications, so delay performance is not critical. |
210 * | 210 * |
211 * \return | 211 * \return |
212 * The negation of is_running. | 212 * The negation of is_running. |
213 * If is_running() was true at the beginning, then this function will have run refresh() before returning. | 213 * If is_running() was true at the beginning, then this function will have run refresh() before returning. |
214 * | 214 * |
215 * \sa | 215 * \sa |
216 * - MSDN [WM_QUERYENDSESSION message](http://msdn.microsoft.com/en-us/library/ windows/desktop/aa376890%28v=vs.85%29.aspx) | 216 * - MSDN [WM_QUERYENDSESSION message](http://msdn.microsoft.com/en-us/library/ windows/desktop/aa376890%28v=vs.85%29.aspx) |
217 * - MSDN [WM_ENDSESSION message](http://msdn.microsoft.com/en-us/library/windo ws/desktop/aa376889%28v=vs.85%29.aspx) | 217 * - MSDN [WM_ENDSESSION message](http://msdn.microsoft.com/en-us/library/windo ws/desktop/aa376889%28v=vs.85%29.aspx) |
218 */ | 218 */ |
219 bool ProcessCloser::ShutDown() | 219 bool ProcessCloser::ShutDown(ImmediateSession& session) |
220 { | 220 { |
221 /* | 221 /* |
222 * If we're not running, we don't need to shut down. | 222 * If we're not running, we don't need to shut down. |
223 */ | 223 */ |
224 if ( ! IsRunning() ) | 224 if ( ! IsRunning() ) |
225 { | 225 { |
226 return true ; | 226 return true ; |
227 } | 227 } |
228 | 228 |
229 /* | 229 /* |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 case 3 : | 271 case 3 : |
272 { | 272 { |
273 /* | 273 /* |
274 * Send WM_CLOSE to every admissible window. | 274 * Send WM_CLOSE to every admissible window. |
275 */ | 275 */ |
276 send_message m( WM_CLOSE, 0, 0 ) ; | 276 send_message m( WM_CLOSE, 0, 0 ) ; |
277 iterate_our_windows( m ) ; | 277 iterate_our_windows( m ) ; |
278 } | 278 } |
279 break ; | 279 break ; |
280 | 280 |
281 default : | 281 case 4: |
Eric
2015/03/13 16:49:48
This should be "case 4 :" and we should retain the
| |
282 /* | 282 /* |
283 * We're out of ways to try to shut down. Oh well. Take cover. It gets viol ent here. | 283 * Oh well. Take cover. It gets violent here. Try to kill all matching proc esses. |
Eric
2015/03/13 16:49:48
Good comment.
| |
284 */ | 284 */ |
285 for (auto it = pid_set.begin(); it != pid_set.end(); ++it) | 285 for (auto it = pid_set.begin(); it != pid_set.end(); ++it) |
286 { | 286 { |
287 HANDLE tmpHandle = OpenProcess(PROCESS_TERMINATE, FALSE, *it); | 287 HANDLE tmpHandle = OpenProcess(PROCESS_TERMINATE, FALSE, *it); |
288 if (tmpHandle != NULL) | 288 if (!tmpHandle) |
Eric
2015/03/13 16:49:48
We can use implicit conversion to bool here.
I wo
| |
289 { | 289 { |
290 Windows_Handle procHandle(tmpHandle); | 290 std::ostringstream stream; |
291 TerminateProcess(tmpHandle, 0); | 291 stream << "Can't open process for termination. Error: " << GetLastErro r(); |
Eric
2015/05/14 15:09:25
This message should indicate a warning rather than
| |
292 session.Log(stream.str()); | |
293 continue; | |
292 } | 294 } |
293 } | 295 Windows_Handle procHandle(tmpHandle); |
294 Refresh(); | 296 if (!TerminateProcess(tmpHandle, 0)) |
295 | 297 { |
296 return !IsRunning() ; | 298 std::ostringstream stream; |
299 stream << "Can't terminate process. Error: " << GetLastError(); | |
300 session.Log(stream.str()); | |
301 } | |
302 } | |
303 break; | |
304 | |
305 default: | |
306 // We're out of ways to try to shut down. | |
307 return false; | |
297 } | 308 } |
298 | 309 |
299 /* | 310 /* |
300 * Wait loop. | 311 * Wait loop. |
301 */ | 312 */ |
302 for ( unsigned int j = 0 ; j < 50 ; ++ j ) | 313 for ( unsigned int j = 0 ; j < 50 ; ++ j ) |
303 { | 314 { |
304 std::this_thread::sleep_for( std::chrono::milliseconds( 30 ) ) ; | 315 std::this_thread::sleep_for( std::chrono::milliseconds( 30 ) ) ; |
sergei
2015/04/02 08:04:09
no spaces?
| |
305 Refresh() ; | 316 Refresh() ; |
306 if ( ! IsRunning() ) | 317 if ( ! IsRunning() ) |
307 { | 318 { |
308 return true ; | 319 return true ; |
309 } | 320 } |
310 } | 321 } |
311 // Assert is_running() | 322 // Assert is_running() |
312 } | 323 } |
313 // No control path leaves the for-loop. | 324 // No control path leaves the for-loop. |
314 } ; | 325 } ; |
315 | 326 |
LEFT | RIGHT |