OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 state_->sockets_[1] = -1; | 89 state_->sockets_[1] = -1; |
90 state_->set_action_ = false; | 90 state_->set_action_ = false; |
91 return true; | 91 return true; |
92 } | 92 } |
93 | 93 |
94 bool ServiceProcessState::SignalReady( | 94 bool ServiceProcessState::SignalReady( |
95 base::MessageLoopProxy* message_loop_proxy, Task* shutdown_task) { | 95 base::MessageLoopProxy* message_loop_proxy, Task* shutdown_task) { |
96 CHECK(state_); | 96 CHECK(state_); |
97 CHECK_EQ(g_signal_socket, -1); | 97 CHECK_EQ(g_signal_socket, -1); |
98 | 98 |
99 #if defined(OS_LINUX) | 99 if (!SignalReadyPlatformSpecific()) { |
100 state_->running_lock_.reset(TakeServiceRunningLock(true)); | |
101 if (state_->running_lock_.get() == NULL) { | |
102 return false; | 100 return false; |
103 } | 101 } |
104 #endif // OS_LINUX | 102 |
105 state_->shut_down_monitor_.reset( | 103 state_->shut_down_monitor_.reset( |
106 new ServiceProcessShutdownMonitor(shutdown_task)); | 104 new ServiceProcessShutdownMonitor(shutdown_task)); |
107 if (pipe(state_->sockets_) < 0) { | 105 if (pipe(state_->sockets_) < 0) { |
108 PLOG(ERROR) << "pipe"; | 106 PLOG(ERROR) << "pipe"; |
109 return false; | 107 return false; |
110 } | 108 } |
111 message_loop_proxy->PostTask(FROM_HERE, | 109 message_loop_proxy->PostTask(FROM_HERE, |
112 NewRunnableMethod(state_, &ServiceProcessState::StateData::SignalReady)); | 110 NewRunnableMethod(state_, &ServiceProcessState::StateData::SignalReady)); |
113 return true; | 111 return true; |
114 } | 112 } |
115 | 113 |
116 void ServiceProcessState::TearDownState() { | 114 void ServiceProcessState::TearDownState() { |
117 g_signal_socket = -1; | 115 g_signal_socket = -1; |
118 if (state_) { | 116 if (state_) { |
119 if (state_->sockets_[0] != -1) { | 117 if (state_->sockets_[0] != -1) { |
120 close(state_->sockets_[0]); | 118 close(state_->sockets_[0]); |
121 } | 119 } |
122 if (state_->sockets_[1] != -1) { | 120 if (state_->sockets_[1] != -1) { |
123 close(state_->sockets_[1]); | 121 close(state_->sockets_[1]); |
124 } | 122 } |
125 if (state_->set_action_) { | 123 if (state_->set_action_) { |
126 if (sigaction(SIGTERM, &state_->old_action_, NULL) < 0) { | 124 if (sigaction(SIGTERM, &state_->old_action_, NULL) < 0) { |
127 PLOG(ERROR) << "sigaction"; | 125 PLOG(ERROR) << "sigaction"; |
128 } | 126 } |
129 } | 127 } |
130 state_->Release(); | 128 state_->Release(); |
131 state_ = NULL; | 129 state_ = NULL; |
132 } | 130 } |
133 } | 131 } |
OLD | NEW |