OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SANDBOX_LINUX_SECCOMP_BPF_DIE_H__ |
| 6 #define SANDBOX_LINUX_SECCOMP_BPF_DIE_H__ |
| 7 |
| 8 namespace playground2 { |
| 9 |
| 10 class Die { |
| 11 public: |
| 12 // This is the main API for using this file. Prints a error message and |
| 13 // exits with a fatal error. |
| 14 #define SANDBOX_DIE(m) Die::SandboxDie(m, __FILE__, __LINE__) |
| 15 |
| 16 // Terminate the program, even if the current sandbox policy prevents some |
| 17 // of the more commonly used functions used for exiting. |
| 18 // Most users would want to call SANDBOX_DIE() instead, as it logs extra |
| 19 // information. But calling ExitGroup() is correct and in some rare cases |
| 20 // preferable. So, we make it part of the public API. |
| 21 static void ExitGroup() __attribute__((noreturn)); |
| 22 |
| 23 // This method gets called by SANDBOX_DIE(). There is normally no reason |
| 24 // to call it directly unless you are defining your own exiting macro. |
| 25 static void SandboxDie(const char *msg, const char *file, int line) |
| 26 __attribute__((noreturn)); |
| 27 |
| 28 // Writes a message to stderr. Used as a fall-back choice, if we don't have |
| 29 // any other way to report an error. |
| 30 static void LogToStderr(const char *msg, const char *file, int line); |
| 31 |
| 32 // We generally want to run all exit handlers. This means, on SANDBOX_DIE() |
| 33 // we should be calling LOG(FATAL). But there are some situations where |
| 34 // we just need to print a message and then terminate. This would typically |
| 35 // happen in cases where we consume the error message internally (e.g. in |
| 36 // unit tests or in the supportsSeccompSandbox() method). |
| 37 static void EnableSimpleExit() { simple_exit_ = true; } |
| 38 |
| 39 private: |
| 40 static bool simple_exit_; |
| 41 |
| 42 DISALLOW_IMPLICIT_CONSTRUCTORS(Die); |
| 43 }; |
| 44 |
| 45 } // namespace |
| 46 |
| 47 #endif // SANDBOX_LINUX_SECCOMP_BPF_DIE_H__ |
OLD | NEW |