mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
move assignment of signal handlers into utility function in terminal.cpp
This commit is contained in:
parent
7726924cb1
commit
929515c672
@ -48,9 +48,7 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#if HAVE_MPI
|
||||
#include <mpi.h>
|
||||
@ -206,17 +204,7 @@ static inline int start(int argc, char **argv, bool registerParams=true)
|
||||
using Problem = GetPropType<TypeTag, Properties::Problem>;
|
||||
using TM = GetPropType<TypeTag, Properties::ThreadManager>;
|
||||
|
||||
// set the signal handlers to reset the TTY to a well defined state on unexpected
|
||||
// program aborts
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
signal(SIGINT, resetTerminal);
|
||||
signal(SIGHUP, resetTerminal);
|
||||
signal(SIGABRT, resetTerminal);
|
||||
signal(SIGFPE, resetTerminal);
|
||||
signal(SIGSEGV, resetTerminal);
|
||||
signal(SIGPIPE, resetTerminal);
|
||||
signal(SIGTERM, resetTerminal);
|
||||
}
|
||||
assignResetTerminalSignalHandlers();
|
||||
|
||||
resetLocale();
|
||||
|
||||
|
@ -105,6 +105,21 @@ int getTtyWidth()
|
||||
return ttyWidth;
|
||||
}
|
||||
|
||||
void assignResetTerminalSignalHandlers()
|
||||
{
|
||||
// set the signal handlers to reset the TTY to a well defined state on unexpected
|
||||
// program aborts
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
signal(SIGINT, resetTerminal);
|
||||
signal(SIGHUP, resetTerminal);
|
||||
signal(SIGABRT, resetTerminal);
|
||||
signal(SIGFPE, resetTerminal);
|
||||
signal(SIGSEGV, resetTerminal);
|
||||
signal(SIGPIPE, resetTerminal);
|
||||
signal(SIGTERM, resetTerminal);
|
||||
}
|
||||
}
|
||||
|
||||
void resetTerminal()
|
||||
{
|
||||
// make sure stderr and stderr do not contain any unwritten data and make sure that
|
||||
|
@ -44,6 +44,11 @@ std::string breakLines(const std::string& msg,
|
||||
*/
|
||||
int getTtyWidth();
|
||||
|
||||
/*!
|
||||
* \brief Assign signal handlers that reset the terminal on errors.
|
||||
*/
|
||||
void assignResetTerminalSignalHandlers();
|
||||
|
||||
/*!
|
||||
* \brief Resets the current TTY to a usable state if the program was aborted.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user