OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "tools/android/forwarder2/daemon.h" | 5 #include "tools/android/forwarder2/daemon.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <signal.h> | 9 #include <signal.h> |
10 #include <sys/file.h> | 10 #include <sys/file.h> |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // Restore the previous signal action for SIGCHLD. | 248 // Restore the previous signal action for SIGCHLD. |
249 if (sigaction(SIGCHLD, &old_action, NULL) < 0) { | 249 if (sigaction(SIGCHLD, &old_action, NULL) < 0) { |
250 PError("sigaction"); | 250 PError("sigaction"); |
251 failed = true; | 251 failed = true; |
252 } | 252 } |
253 return !failed; | 253 return !failed; |
254 } | 254 } |
255 | 255 |
256 bool Daemon::Kill() { | 256 bool Daemon::Kill() { |
257 pid_t daemon_pid = Socket::GetUnixDomainSocketProcessOwner(identifier_); | 257 pid_t daemon_pid = Socket::GetUnixDomainSocketProcessOwner(identifier_); |
258 if (daemon_pid < 0) | 258 if (daemon_pid < 0) { |
259 return true; // No daemon running. | 259 LOG(ERROR) << "No forwarder daemon seems to be running"; |
| 260 return true; |
| 261 } |
260 if (kill(daemon_pid, SIGTERM) < 0) { | 262 if (kill(daemon_pid, SIGTERM) < 0) { |
261 if (errno == ESRCH /* invalid PID */) | 263 if (errno == ESRCH /* invalid PID */) { |
262 // The daemon exited for some reason (e.g. kill by a process other than | 264 // The daemon exited for some reason (e.g. kill by a process other than |
263 // us) right before the call to kill() above. | 265 // us) right before the call to kill() above. |
| 266 LOG(ERROR) << "Could not kill daemon with PID " << daemon_pid; |
264 return true; | 267 return true; |
| 268 } |
265 PError("kill"); | 269 PError("kill"); |
266 return false; | 270 return false; |
267 } | 271 } |
268 for (int i = 0; i < kNumTries; ++i) { | 272 for (int i = 0; i < kNumTries; ++i) { |
269 const pid_t previous_pid = daemon_pid; | 273 const pid_t previous_pid = daemon_pid; |
270 daemon_pid = Socket::GetUnixDomainSocketProcessOwner(identifier_); | 274 daemon_pid = Socket::GetUnixDomainSocketProcessOwner(identifier_); |
271 if (daemon_pid < 0) | 275 if (daemon_pid < 0) |
272 return true; | 276 return true; |
273 // Since we are polling we might not see the 'daemon exited' event if | 277 // Since we are polling we might not see the 'daemon exited' event if |
274 // another daemon was spawned during our idle period. | 278 // another daemon was spawned during our idle period. |
275 if (daemon_pid != previous_pid) { | 279 if (daemon_pid != previous_pid) { |
276 LOG(WARNING) << "Daemon (pid=" << previous_pid | 280 LOG(WARNING) << "Daemon (pid=" << previous_pid |
277 << ") was successfully killed but a new daemon (pid=" | 281 << ") was successfully killed but a new daemon (pid=" |
278 << daemon_pid << ") seems to be running now."; | 282 << daemon_pid << ") seems to be running now."; |
279 return true; | 283 return true; |
280 } | 284 } |
281 usleep(kIdleTimeMSec * 1000); | 285 usleep(kIdleTimeMSec * 1000); |
282 } | 286 } |
283 LOG(ERROR) << "Timed out while killing daemon. " | 287 LOG(ERROR) << "Timed out while killing daemon. " |
284 "It might still be tearing down."; | 288 "It might still be tearing down."; |
285 return false; | 289 return false; |
286 } | 290 } |
287 | 291 |
288 } // namespace forwarder2 | 292 } // namespace forwarder2 |
OLD | NEW |