OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_TERMINATOR_H__ |
| 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_TERMINATOR_H__ |
| 7 |
| 8 #include <signal.h> |
| 9 |
| 10 namespace chromeos_update_engine { |
| 11 |
| 12 // A class allowing graceful delayed exit. |
| 13 class Terminator { |
| 14 public: |
| 15 // Initializes the terminator and sets up signal handlers. |
| 16 static void Init(); |
| 17 |
| 18 // Terminates the current process. |
| 19 static void Exit(); |
| 20 |
| 21 // Set to true if the terminator should block termination requests in an |
| 22 // attempt to block exiting. |
| 23 static void set_exit_blocked(bool block) { exit_blocked_ = block ? 1 : 0; } |
| 24 |
| 25 // Returns true if the system is trying to terminate the process, false |
| 26 // otherwise. Returns true only if exit was blocked when the termination |
| 27 // request arrived. |
| 28 static bool exit_requested() { return exit_requested_ != 0; } |
| 29 |
| 30 private: |
| 31 // The signal handler. |
| 32 static void HandleSignal(int signum); |
| 33 |
| 34 static volatile sig_atomic_t exit_blocked_; |
| 35 static volatile sig_atomic_t exit_requested_; |
| 36 }; |
| 37 |
| 38 class ScopedTerminatorExitUnblocker { |
| 39 public: |
| 40 ~ScopedTerminatorExitUnblocker(); |
| 41 }; |
| 42 |
| 43 } // namespace chromeos_update_engine |
| 44 |
| 45 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_TERMINATOR_H__ |
OLD | NEW |