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

Unified Diff: terminator.cc

Issue 3608015: AU: Catch terminate signals and block exit if necessary. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: typo Created 10 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « terminator.h ('k') | testrunner.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: terminator.cc
diff --git a/terminator.cc b/terminator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1d33e324e86e608e1aa7767337c2a2fb59dc1fc5
--- /dev/null
+++ b/terminator.cc
@@ -0,0 +1,36 @@
+// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
adlr 2010/10/07 17:26:05 it might be a bit more efficient to have the OS ki
petkov 2010/10/07 17:29:31 Yeah, thought about this. It seems better to exit
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "update_engine/terminator.h"
+
+#include <cstdlib>
+
+namespace chromeos_update_engine {
+
+volatile sig_atomic_t Terminator::exit_blocked_ = 0;
+volatile sig_atomic_t Terminator::exit_requested_ = 0;
+
+void Terminator::Init() {
+ signal(SIGTERM, HandleSignal);
+}
+
+void Terminator::Exit() {
+ exit(0);
+}
+
+void Terminator::HandleSignal(int signum) {
+ if (exit_blocked_ == 0) {
+ Exit();
+ }
+ exit_requested_ = 1;
+}
+
+ScopedTerminatorExitUnblocker::~ScopedTerminatorExitUnblocker() {
+ Terminator::set_exit_blocked(false);
+ if (Terminator::exit_requested()) {
+ Terminator::Exit();
+ }
+}
+
+} // namespace chromeos_update_engine
« no previous file with comments | « terminator.h ('k') | testrunner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698