Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/base/libmesh_exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ void enableFPE(bool on);
*/
void enableSEGV(bool on);

/**
* Toggle libMesh handling of SIGINT (Ctrl+C) interrupts
*/
void enableSIGINT(bool on);

/**
* A class to represent the internal "this should never happen"
* errors, to be thrown by "libmesh_error();"
Expand Down
3 changes: 3 additions & 0 deletions src/base/libmesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,9 @@ LibMeshInit::LibMeshInit (int argc, const char * const * argv,
if (libMesh::on_command_line("--enable-segv"))
libMesh::enableSEGV(true);

if (libMesh::on_command_line("--enable-sigint"))
libMesh::enableSIGINT(true);

#if defined(LIBMESH_HAVE_HDF5) && !defined(_MSC_VER)
// We may be running with ExodusII configured not to use HDF5 (in
// which case user code which wants to lock files has to do flock()
Expand Down
36 changes: 36 additions & 0 deletions src/base/libmesh_exceptions.C
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ void libmesh_handleSEGV(int /*signo*/, siginfo_t * info, void * /*context*/)
<< " run ...\n" \
<< " bt");
}


void libmesh_handleSIGINT(int /*signo*/, siginfo_t * /*info*/, void * /*context*/)
{
libmesh_error_msg("Interrupt (Ctrl+C?) signaled!");
}
#endif
} // anonymous namespace

Expand Down Expand Up @@ -255,4 +261,34 @@ void enableSEGV(bool on)
#endif
}


// Enable handling of SIGINT (Ctrl+C) by libMesh
void enableSIGINT(bool on)
{
#if LIBMESH_HAVE_DECL_SIGACTION
static struct sigaction old_action;
static bool was_on = false;

if (on)
{
struct sigaction new_action;
was_on = true;

// Set up the structure to specify the new action.
new_action.sa_sigaction = libmesh_handleSIGINT;
sigemptyset (&new_action.sa_mask);
new_action.sa_flags = SA_SIGINFO;

sigaction (SIGINT, &new_action, &old_action);
}
else if (was_on)
{
was_on = false;
sigaction (SIGINT, &old_action, nullptr);
}
#else
libmesh_error_msg("System call sigaction not supported.");
#endif
}

} // namespace libMesh