Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(546)

Side by Side Diff: chromecast/browser/cast_browser_main_parts.cc

Issue 1002603006: Raise SIGKILL if cast_service doesn't Finalize() within timeout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromecast/browser/cast_browser_main_parts.h" 5 #include "chromecast/browser/cast_browser_main_parts.h"
6 6
7 #if !defined(OS_ANDROID)
7 #include <signal.h> 8 #include <signal.h>
8 #include <sys/prctl.h> 9 #include <sys/prctl.h>
10 #endif
9 11
10 #include "base/command_line.h" 12 #include "base/command_line.h"
11 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
12 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
13 #include "base/path_service.h" 15 #include "base/path_service.h"
14 #include "base/prefs/pref_registry_simple.h" 16 #include "base/prefs/pref_registry_simple.h"
15 #include "base/run_loop.h" 17 #include "base/run_loop.h"
16 #include "cc/base/switches.h" 18 #include "cc/base/switches.h"
17 #include "chromecast/base/metrics/cast_metrics_helper.h" 19 #include "chromecast/base/metrics/cast_metrics_helper.h"
18 #include "chromecast/base/metrics/grouped_histogram.h" 20 #include "chromecast/base/metrics/grouped_histogram.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (sigaction(kSignalsToRunClosure[i], &sa_new, &sa_old) == -1) { 76 if (sigaction(kSignalsToRunClosure[i], &sa_new, &sa_old) == -1) {
75 NOTREACHED(); 77 NOTREACHED();
76 } else { 78 } else {
77 DCHECK_EQ(sa_old.sa_handler, SIG_DFL); 79 DCHECK_EQ(sa_old.sa_handler, SIG_DFL);
78 } 80 }
79 } 81 }
80 82
81 // Get the first signal to exit when the parent process dies. 83 // Get the first signal to exit when the parent process dies.
82 prctl(PR_SET_PDEATHSIG, kSignalsToRunClosure[0]); 84 prctl(PR_SET_PDEATHSIG, kSignalsToRunClosure[0]);
83 } 85 }
86
87 const int kKillOnAlarmTimeoutSec = 5; // 5 seconds
88
89 void KillOnAlarm(int signum) {
90 LOG(ERROR) << "Got alarm signal for termination: " << signum;
91 raise(SIGKILL);
92 }
93
94 void RegisterKillOnAlarm(int timeout_seconds) {
95 struct sigaction sa_new;
96 memset(&sa_new, 0, sizeof(sa_new));
97 sa_new.sa_handler = KillOnAlarm;
98 sigfillset(&sa_new.sa_mask);
99 sa_new.sa_flags = SA_RESTART;
100
101 struct sigaction sa_old;
102 if (sigaction(SIGALRM, &sa_new, &sa_old) == -1) {
103 NOTREACHED();
104 } else {
105 DCHECK_EQ(sa_old.sa_handler, SIG_DFL);
106 }
107
108 if (alarm(timeout_seconds) > 0) {
109 NOTREACHED() << "Previous alarm() was cancelled";
110 }
byungchul 2015/03/23 20:00:35 remove {}
maclellant 2015/03/23 20:24:28 Done.
111 }
112
113 void DeregisterKillOnAlarm() {
114 struct sigaction sa_new;
115 memset(&sa_new, 0, sizeof(sa_new));
116 sa_new.sa_handler = SIG_DFL;
117 sigfillset(&sa_new.sa_mask);
118 sa_new.sa_flags = SA_RESTART;
119
120 struct sigaction sa_old;
121 if (sigaction(SIGALRM, &sa_new, &sa_old) == -1) {
122 NOTREACHED();
123 } else {
124 DCHECK_EQ(sa_old.sa_handler, KillOnAlarm);
125 }
126 }
84 #endif // !defined(OS_ANDROID) 127 #endif // !defined(OS_ANDROID)
85 128
86 } // namespace 129 } // namespace
87 130
88 namespace chromecast { 131 namespace chromecast {
89 namespace shell { 132 namespace shell {
90 133
91 namespace { 134 namespace {
92 135
93 struct DefaultCommandLineSwitch { 136 struct DefaultCommandLineSwitch {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 cast_browser_process_->cast_service()->Stop(); 313 cast_browser_process_->cast_service()->Stop();
271 return true; 314 return true;
272 #endif 315 #endif
273 } 316 }
274 317
275 void CastBrowserMainParts::PostMainMessageLoopRun() { 318 void CastBrowserMainParts::PostMainMessageLoopRun() {
276 #if defined(OS_ANDROID) 319 #if defined(OS_ANDROID)
277 // Android does not use native main MessageLoop. 320 // Android does not use native main MessageLoop.
278 NOTREACHED(); 321 NOTREACHED();
279 #else 322 #else
323 // If the services owned by the browser process do not finalize correctly, we
324 // trigger a SIGKILL on the current process to forcibly terminate. This avoids
325 // indefinte hangs when resources cannot clean up properly.
326 RegisterKillOnAlarm(kKillOnAlarmTimeoutSec);
byungchul 2015/03/23 20:00:35 Should it be before cast_browser_process_->cast_se
gunsch 2015/03/23 20:14:21 +1
maclellant 2015/03/23 20:24:28 Done.
280 cast_browser_process_->cast_service()->Finalize(); 327 cast_browser_process_->cast_service()->Finalize();
281 cast_browser_process_->metrics_service_client()->Finalize(); 328 cast_browser_process_->metrics_service_client()->Finalize();
282 cast_browser_process_.reset(); 329 cast_browser_process_.reset();
330 DeregisterKillOnAlarm();
283 #endif 331 #endif
284 } 332 }
285 333
286 } // namespace shell 334 } // namespace shell
287 } // namespace chromecast 335 } // namespace chromecast
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698