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 |