2022-04-23 18:11:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!> @brief Handling of UNIX signals.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
module signals
|
|
|
|
use prec
|
|
|
|
use system_routines
|
|
|
|
|
|
|
|
implicit none
|
|
|
|
private
|
|
|
|
|
|
|
|
logical, volatile, public, protected :: &
|
2022-05-12 20:15:42 +05:30
|
|
|
signals_SIGINT = .false., & !< interrupt signal
|
2022-05-12 19:06:12 +05:30
|
|
|
signals_SIGUSR1 = .false., & !< 1. user-defined signal
|
|
|
|
signals_SIGUSR2 = .false. !< 2. user-defined signal
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
public :: &
|
|
|
|
signals_init, &
|
2022-05-12 20:15:42 +05:30
|
|
|
signals_setSIGINT, &
|
2022-04-23 18:11:10 +05:30
|
|
|
signals_setSIGUSR1, &
|
|
|
|
signals_setSIGUSR2
|
|
|
|
|
|
|
|
contains
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Register signal handlers.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
subroutine signals_init()
|
|
|
|
|
2022-05-12 20:15:42 +05:30
|
|
|
call signalint_c(c_funloc(catchSIGINT))
|
2022-04-23 18:11:10 +05:30
|
|
|
call signalusr1_c(c_funloc(catchSIGUSR1))
|
|
|
|
call signalusr2_c(c_funloc(catchSIGUSR2))
|
|
|
|
|
|
|
|
end subroutine signals_init
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-05-12 20:15:42 +05:30
|
|
|
!> @brief Set global variable signals_SIGINT to .true.
|
2022-04-23 18:11:10 +05:30
|
|
|
!> @details This function can be registered to catch signals send to the executable.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-05-12 20:15:42 +05:30
|
|
|
subroutine catchSIGINT(signal) bind(C)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
integer(C_INT), value :: signal
|
|
|
|
|
|
|
|
|
|
|
|
print'(a,i0)', ' received signal ',signal
|
2022-05-12 20:15:42 +05:30
|
|
|
call signals_setSIGINT(.true.)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
2022-05-12 20:15:42 +05:30
|
|
|
end subroutine catchSIGINT
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Set global variable signals_SIGUSR1 to .true.
|
|
|
|
!> @details This function can be registered to catch signals send to the executable.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
subroutine catchSIGUSR1(signal) bind(C)
|
|
|
|
|
|
|
|
integer(C_INT), value :: signal
|
|
|
|
|
|
|
|
|
|
|
|
print'(a,i0)', ' received signal ',signal
|
|
|
|
call signals_setSIGUSR1(.true.)
|
|
|
|
|
|
|
|
end subroutine catchSIGUSR1
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Set global variable signals_SIGUSR2 to .true.
|
|
|
|
!> @details This function can be registered to catch signals send to the executable.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
subroutine catchSIGUSR2(signal) bind(C)
|
|
|
|
|
|
|
|
integer(C_INT), value :: signal
|
|
|
|
|
|
|
|
|
|
|
|
print'(a,i0,a)', ' received signal ',signal
|
|
|
|
call signals_setSIGUSR2(.true.)
|
|
|
|
|
|
|
|
end subroutine catchSIGUSR2
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-05-12 20:15:42 +05:30
|
|
|
!> @brief Set global variable signals_SIGINT.
|
2022-04-23 18:11:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2022-05-12 20:15:42 +05:30
|
|
|
subroutine signals_setSIGINT(state)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
logical, intent(in) :: state
|
|
|
|
|
|
|
|
|
2022-05-12 20:15:42 +05:30
|
|
|
signals_SIGINT = state
|
|
|
|
print*, 'set SIGINT to',state
|
2022-04-23 18:11:10 +05:30
|
|
|
|
2022-05-12 20:15:42 +05:30
|
|
|
end subroutine signals_setSIGINT
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Set global variable signals_SIGUSR.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
subroutine signals_setSIGUSR1(state)
|
|
|
|
|
|
|
|
logical, intent(in) :: state
|
|
|
|
|
|
|
|
|
|
|
|
signals_SIGUSR1 = state
|
|
|
|
print*, 'set SIGUSR1 to',state
|
|
|
|
|
|
|
|
end subroutine signals_setSIGUSR1
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Set global variable signals_SIGUSR2.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
subroutine signals_setSIGUSR2(state)
|
|
|
|
|
|
|
|
logical, intent(in) :: state
|
|
|
|
|
|
|
|
|
|
|
|
signals_SIGUSR2 = state
|
|
|
|
print*, 'set SIGUSR2 to',state
|
|
|
|
|
|
|
|
end subroutine signals_setSIGUSR2
|
|
|
|
|
|
|
|
|
|
|
|
end module signals
|