forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure the Chromoting Host process eventually terminates when shut down.
The host process is meant to shut down cleanly when receiving a SIGTERM, or if there is a configuration error. This CL implements a timed watchdog, running on a new thread, that triggers a forced exit of the process, in case it fails to terminate normally within a reasonable time (for example, if some thread is inside a blocking call). BUG=420090 TEST=The watchdog shouldn't normally trigger, but I manually added a Sleep() to some thread to verify that it triggers if a thread is blocked for too long. Review URL: https://codereview.chromium.org/784243003 Cr-Commit-Position: refs/heads/master@{#307819}
- Loading branch information
lambroslambrou
authored and
Commit bot
committed
Dec 11, 2014
1 parent
f4b23f1
commit df71588
Showing
4 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "remoting/host/shutdown_watchdog.h" | ||
|
||
#include <stdlib.h> // For _exit() on Windows. | ||
|
||
#include "base/logging.h" | ||
|
||
#if defined(OS_POSIX) | ||
#include <unistd.h> | ||
#endif // defined(OS_POSIX) | ||
|
||
namespace remoting { | ||
|
||
ShutdownWatchdog::ShutdownWatchdog(const base::TimeDelta& duration) | ||
: base::Watchdog(duration, "Shutdown watchdog", true) { | ||
} | ||
|
||
void ShutdownWatchdog::SetExitCode(int exit_code) { | ||
base::AutoLock lock(lock_); | ||
exit_code_ = exit_code; | ||
} | ||
|
||
void ShutdownWatchdog::Alarm() { | ||
// Holding a lock while calling _exit() might not be a safe thing to do, so | ||
// make a local copy. | ||
int exit_code; | ||
{ | ||
base::AutoLock lock(lock_); | ||
exit_code = exit_code_; | ||
} | ||
|
||
LOG(ERROR) << "Shutdown watchdog triggered, exiting with code " << exit_code; | ||
_exit(exit_code); | ||
} | ||
|
||
} // namespace remoting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef REMOTING_HOST_SHUTDOWN_WATCHDOG_H_ | ||
#define REMOTING_HOST_SHUTDOWN_WATCHDOG_H_ | ||
|
||
#include "base/synchronization/lock.h" | ||
#include "base/threading/watchdog.h" | ||
|
||
namespace remoting { | ||
|
||
// This implements a watchdog timer that ensures the host process eventually | ||
// terminates, even if some threads are blocked or being kept alive for | ||
// some reason. This is not expected to trigger if host shutdown is working | ||
// correctly (on a normally loaded system). The triggering of the alarm | ||
// indicates a sign of trouble, and so the Alarm() method will log some | ||
// diagnostic information before shutting down the process. | ||
class ShutdownWatchdog : public base::Watchdog { | ||
public: | ||
// Creates a watchdog that waits for |duration| (after the watchdog is | ||
// armed) before shutting down the process. | ||
explicit ShutdownWatchdog(const base::TimeDelta& duration); | ||
|
||
// This method should be called to set the process's exit-code before arming | ||
// the watchdog. Otherwise an exit-code of 0 is assumed. | ||
void SetExitCode(int exit_code); | ||
|
||
void Alarm() override; | ||
|
||
private: | ||
int exit_code_; | ||
|
||
// Protects |exit_code_|, since Alarm() gets called on a separate thread. | ||
base::Lock lock_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(ShutdownWatchdog); | ||
}; | ||
|
||
} // namespace remoting | ||
|
||
#endif // REMOTING_HOST_SHUTDOWN_WATCHDOG_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters