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

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

Issue 872073005: Get SIGTERM when parent process dies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 #include <signal.h> 7 #include <signal.h>
8 #include <sys/prctl.h>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
11 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h" 13 #include "base/path_service.h"
13 #include "base/prefs/pref_registry_simple.h" 14 #include "base/prefs/pref_registry_simple.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "cc/base/switches.h" 16 #include "cc/base/switches.h"
16 #include "chromecast/base/metrics/cast_metrics_helper.h" 17 #include "chromecast/base/metrics/cast_metrics_helper.h"
17 #include "chromecast/base/metrics/grouped_histogram.h" 18 #include "chromecast/base/metrics/grouped_histogram.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 void RunClosureOnSignal(int signum) { 51 void RunClosureOnSignal(int signum) {
51 LOG(ERROR) << "Got signal " << signum; 52 LOG(ERROR) << "Got signal " << signum;
52 DCHECK(g_signal_closure); 53 DCHECK(g_signal_closure);
53 // Expect main thread got this signal. Otherwise, weak_ptr of run_loop will 54 // Expect main thread got this signal. Otherwise, weak_ptr of run_loop will
54 // crash the process. 55 // crash the process.
55 g_signal_closure->Run(); 56 g_signal_closure->Run();
56 } 57 }
57 58
58 void RegisterClosureOnSignal(const base::Closure& closure) { 59 void RegisterClosureOnSignal(const base::Closure& closure) {
59 DCHECK(!g_signal_closure); 60 DCHECK(!g_signal_closure);
61 DCHECK_GT(arraysize(kSignalsToRunClosure), 0U);
62
60 // Allow memory leak by intention. 63 // Allow memory leak by intention.
61 g_signal_closure = new base::Closure(closure); 64 g_signal_closure = new base::Closure(closure);
62 65
63 struct sigaction sa_new; 66 struct sigaction sa_new;
64 memset(&sa_new, 0, sizeof(sa_new)); 67 memset(&sa_new, 0, sizeof(sa_new));
65 sa_new.sa_handler = RunClosureOnSignal; 68 sa_new.sa_handler = RunClosureOnSignal;
66 sigfillset(&sa_new.sa_mask); 69 sigfillset(&sa_new.sa_mask);
67 sa_new.sa_flags = SA_RESTART; 70 sa_new.sa_flags = SA_RESTART;
68 71
69 for (size_t i = 0; i < arraysize(kSignalsToRunClosure); i++) { 72 for (size_t i = 0; i < arraysize(kSignalsToRunClosure); i++) {
70 struct sigaction sa_old; 73 struct sigaction sa_old;
71 if (sigaction(kSignalsToRunClosure[i], &sa_new, &sa_old) == -1) { 74 if (sigaction(kSignalsToRunClosure[i], &sa_new, &sa_old) == -1) {
72 NOTREACHED(); 75 NOTREACHED();
73 } else { 76 } else {
74 DCHECK_EQ(sa_old.sa_handler, SIG_DFL); 77 DCHECK_EQ(sa_old.sa_handler, SIG_DFL);
75 } 78 }
76 } 79 }
80
81 // Get the first signal to exit when the parent process dies.
82 prctl(PR_SET_PDEATHSIG, kSignalsToRunClosure[0]);
77 } 83 }
78 84
79 } // namespace 85 } // namespace
80 86
81 namespace chromecast { 87 namespace chromecast {
82 namespace shell { 88 namespace shell {
83 89
84 namespace { 90 namespace {
85 91
86 struct DefaultCommandLineSwitch { 92 struct DefaultCommandLineSwitch {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 258 }
253 259
254 void CastBrowserMainParts::PostMainMessageLoopRun() { 260 void CastBrowserMainParts::PostMainMessageLoopRun() {
255 cast_browser_process_->cast_service()->Finalize(); 261 cast_browser_process_->cast_service()->Finalize();
256 cast_browser_process_->metrics_service_client()->Finalize(); 262 cast_browser_process_->metrics_service_client()->Finalize();
257 cast_browser_process_.reset(); 263 cast_browser_process_.reset();
258 } 264 }
259 265
260 } // namespace shell 266 } // namespace shell
261 } // namespace chromecast 267 } // 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