Skip to content

Commit

Permalink
Preparing for full PR idaholab#12722
Browse files Browse the repository at this point in the history
  • Loading branch information
socratesgorilla committed Jan 19, 2023
1 parent bdf93fc commit c51ef42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
18 changes: 7 additions & 11 deletions framework/src/base/MooseInit.C
Expand Up @@ -37,39 +37,35 @@ void my_sig_handler (int signum)

switch (signum)
{
case SIGINT:
printf("...caught SIGINT at %s", ctime(&now));
break;

case SIGUSR1:
printf("...caught SIGUSR1 at %s, ignoring...\n",ctime(&now));
printf("...caught SIGUSR1 at %s, triggering checkpoint write...\n",ctime(&now));
break;

// this shouldnt be possible to trigger... but just in case.
default:
printf("...caught other unknown signal: %d at %s", signum, ctime(&now));
printf(" see \"man 7 signal\" for a list of known signals\n");
break;
printf(" --> Restoring default handler for signal %d\n", signum);
signal(signum, SIG_DFL);
return;
}

// re-register default signal handler for action
#ifndef HAVE_MPI
// dummy variables
int x = 0;
int y = 0;
MPI_Barrier(MPI_COMM_WORLD);
MPI_Allreduce(&x,&y,1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
printf(" --> Restoring default handler for signal %d\n", signum);
signal(signum, SIG_DFL);
#endif
Moose::autosave_flag = true;
return;
}

void register_sig_handler()
{
printf("Registering user-specified signal handlers for PID %d\n", getpid());

signal(SIGINT, my_sig_handler);
signal(SIGTERM, my_sig_handler);
printf("Registering signal handlers for PID %d\n", getpid());
signal(SIGUSR1, my_sig_handler);
}

Expand Down
4 changes: 4 additions & 0 deletions test/tests/misc/signal_handler/tests
@@ -1,12 +1,16 @@
[Tests]
issues = '#12722'
[test_signal]
type = SignalTester
input = 'simple_transient_diffusion.i'
requirement = 'The app should write out a checkpoint file at any time by sending a signal to it.'

[]
[test_signal_recover]
type = RunApp
input = 'simple_transient_diffusion.i'
cli_args = '--recover'
prereq = 'test_signal'
requirement = 'The app should be able to recover from the autosaved checkpoint created by a signal.'
[]
[]

0 comments on commit c51ef42

Please sign in to comment.