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

Side by Side Diff: chrome/common/service_process_util_posix.cc

Issue 6825063: Patch for bug 74983 (among others) to be applied to M11 696 branch. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/696/src
Patch Set: intentionally disabled mac tests. tested by hand. Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/service_process_util_posix.h" 5 #include "chrome/common/service_process_util_posix.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 9
10 namespace { 10 namespace {
11 int g_signal_socket = -1; 11 int g_signal_socket = -1;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // down by an appropriate process. 48 // down by an appropriate process.
49 int message = ServiceProcessShutdownMonitor::kShutDownMessage; 49 int message = ServiceProcessShutdownMonitor::kShutDownMessage;
50 if (write(g_signal_socket, &message, sizeof(message)) < 0) { 50 if (write(g_signal_socket, &message, sizeof(message)) < 0) {
51 PLOG(ERROR) << "write"; 51 PLOG(ERROR) << "write";
52 } 52 }
53 } 53 }
54 54
55 ServiceProcessState::StateData::StateData() {} 55 ServiceProcessState::StateData::StateData() {}
56 56
57 void ServiceProcessState::StateData::SignalReady() { 57 void ServiceProcessState::StateData::SignalReady() {
58 CHECK_EQ(g_signal_socket, -1);
58 CHECK(MessageLoopForIO::current()->WatchFileDescriptor( 59 CHECK(MessageLoopForIO::current()->WatchFileDescriptor(
59 sockets_[0], true, MessageLoopForIO::WATCH_READ, 60 sockets_[0], true, MessageLoopForIO::WATCH_READ,
60 &watcher_, shut_down_monitor_.get())); 61 &watcher_, shut_down_monitor_.get()));
61 g_signal_socket = sockets_[1]; 62 g_signal_socket = sockets_[1];
62 63
63 // Set up signal handler for SIGTERM. 64 // Set up signal handler for SIGTERM.
64 struct sigaction action; 65 struct sigaction action;
65 action.sa_sigaction = SigTermHandler; 66 action.sa_sigaction = SigTermHandler;
66 sigemptyset(&action.sa_mask); 67 sigemptyset(&action.sa_mask);
67 action.sa_flags = SA_SIGINFO; 68 action.sa_flags = SA_SIGINFO;
(...skipping 19 matching lines...) Expand all
87 state_->AddRef(); 88 state_->AddRef();
88 state_->sockets_[0] = -1; 89 state_->sockets_[0] = -1;
89 state_->sockets_[1] = -1; 90 state_->sockets_[1] = -1;
90 state_->set_action_ = false; 91 state_->set_action_ = false;
91 return true; 92 return true;
92 } 93 }
93 94
94 bool ServiceProcessState::SignalReady( 95 bool ServiceProcessState::SignalReady(
95 base::MessageLoopProxy* message_loop_proxy, Task* shutdown_task) { 96 base::MessageLoopProxy* message_loop_proxy, Task* shutdown_task) {
96 CHECK(state_); 97 CHECK(state_);
97 CHECK_EQ(g_signal_socket, -1); 98 scoped_ptr<Task> scoped_shutdown_task(shutdown_task);
98
99 #if defined(OS_LINUX) 99 #if defined(OS_LINUX)
100 state_->running_lock_.reset(TakeServiceRunningLock(true)); 100 state_->running_lock_.reset(TakeServiceRunningLock(true));
101 if (state_->running_lock_.get() == NULL) { 101 if (state_->running_lock_.get() == NULL) {
102 return false; 102 return false;
103 } 103 }
104 #endif // OS_LINUX 104 #endif // OS_LINUX
105 state_->shut_down_monitor_.reset( 105 state_->shut_down_monitor_.reset(
106 new ServiceProcessShutdownMonitor(shutdown_task)); 106 new ServiceProcessShutdownMonitor(scoped_shutdown_task.release()));
107 if (pipe(state_->sockets_) < 0) { 107 if (pipe(state_->sockets_) < 0) {
108 PLOG(ERROR) << "pipe"; 108 PLOG(ERROR) << "pipe";
109 return false; 109 return false;
110 } 110 }
111 #if defined(OS_MACOSX)
112 state_->state_ = this;
113 message_loop_proxy->PostTask(FROM_HERE,
114 NewRunnableMethod(state_,
115 &ServiceProcessState::StateData::WatchExecutable));
116 #endif // OS_MACOSX
111 message_loop_proxy->PostTask(FROM_HERE, 117 message_loop_proxy->PostTask(FROM_HERE,
112 NewRunnableMethod(state_, &ServiceProcessState::StateData::SignalReady)); 118 NewRunnableMethod(state_, &ServiceProcessState::StateData::SignalReady));
113 return true; 119 return true;
114 } 120 }
115 121
116 void ServiceProcessState::TearDownState() { 122 void ServiceProcessState::TearDownState() {
117 g_signal_socket = -1;
118 if (state_) { 123 if (state_) {
119 if (state_->sockets_[0] != -1) { 124 if (state_->sockets_[0] != -1) {
120 close(state_->sockets_[0]); 125 close(state_->sockets_[0]);
121 } 126 }
122 if (state_->sockets_[1] != -1) { 127 if (state_->sockets_[1] != -1) {
123 close(state_->sockets_[1]); 128 close(state_->sockets_[1]);
124 } 129 }
125 if (state_->set_action_) { 130 if (state_->set_action_) {
126 if (sigaction(SIGTERM, &state_->old_action_, NULL) < 0) { 131 if (sigaction(SIGTERM, &state_->old_action_, NULL) < 0) {
127 PLOG(ERROR) << "sigaction"; 132 PLOG(ERROR) << "sigaction";
128 } 133 }
129 } 134 }
135 g_signal_socket = -1;
130 state_->Release(); 136 state_->Release();
131 state_ = NULL; 137 state_ = NULL;
132 } 138 }
133 } 139 }
OLDNEW
« no previous file with comments | « chrome/common/service_process_util_posix.h ('k') | chrome/common/service_process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698