Note that this signal handler is not async signal safe ! * Ideally a signal handler should only flip a bit and defer * heavy work to some kind of bottom-half processing. */
| 115 | * Ideally a signal handler should only flip a bit and defer |
| 116 | * heavy work to some kind of bottom-half processing. */ |
| 117 | void signal_handler(int signum, siginfo_t* /*info*/, void* /*context*/) |
| 118 | { |
| 119 | const char* name = "UNKNOWN SIGNAL"; |
| 120 | |
| 121 | for (const auto& s : ALL_SIGNALS) { |
| 122 | if (s.number == signum) { |
| 123 | name = s.name; |
| 124 | break; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | write_to_stderr("\n"); |
| 129 | write_to_stderr("HyperHDR caught signal :"); |
| 130 | write_to_stderr(name); |
| 131 | write_to_stderr("\n"); |
| 132 | |
| 133 | /* Anything below here is unsafe ! */ |
| 134 | |
| 135 | switch (signum) |
| 136 | { |
| 137 | case SIGBUS: |
| 138 | case SIGSEGV: |
| 139 | case SIGABRT: |
| 140 | case SIGFPE: |
| 141 | print_trace(); |
| 142 | |
| 143 | /* Don't catch our own signal */ |
| 144 | install_default_handler(signum); |
| 145 | |
| 146 | kill(getpid(), signum); |
| 147 | return; |
| 148 | case SIGINT: |
| 149 | case SIGTERM: |
| 150 | case SIGPIPE: |
| 151 | default: |
| 152 | /* If the signal_handler is hit before the event loop is started, |
| 153 | * following call will do nothing. So we queue the call. */ |
| 154 | |
| 155 | HyperHdrInstance::signalTerminateTriggered(); |
| 156 | |
| 157 | QUEUE_CALL_0(qApp, quit); |
| 158 | |
| 159 | // Reset signal handler to default (in case this handler is not capable of stopping) |
| 160 | install_default_handler(signum); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | } // namespace DefaultSignalHandler |
| 165 | #endif // _WIN32 |
nothing calls this directly
no test coverage detected