2022-04-23 18:11:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @author Martin Diehl, Max-Planck-Institut für Eisenforschung GmbH
|
|
|
|
!> @brief Handling of UNIX signals.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
module signal
|
2022-04-23 18:11:10 +05:30
|
|
|
use prec
|
|
|
|
use system_routines
|
|
|
|
|
2022-06-22 02:16:54 +05:30
|
|
|
implicit none(type,external)
|
2022-04-23 18:11:10 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
logical, volatile, public, protected :: &
|
2023-01-19 22:07:45 +05:30
|
|
|
signal_SIGINT = .false., & !< interrupt signal
|
|
|
|
signal_SIGUSR1 = .false., & !< 1. user-defined signal
|
|
|
|
signal_SIGUSR2 = .false. !< 2. user-defined signal
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
public :: &
|
2023-01-19 22:07:45 +05:30
|
|
|
signal_init, &
|
|
|
|
signal_setSIGINT, &
|
|
|
|
signal_setSIGUSR1, &
|
|
|
|
signal_setSIGUSR2
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
contains
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
|
|
|
!> @brief Register signal handlers.
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
subroutine signal_init()
|
2022-04-23 18:11:10 +05:30
|
|
|
|
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))
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
end subroutine signal_init
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
!> @brief Set global variable signal_SIGINT to .true.
|
2023-02-11 20:00:12 +05:30
|
|
|
!> @details This function can be registered to catch signals sent to the executable.
|
2022-04-23 18:11:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
subroutine catchSIGINT(sig) bind(C)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
integer(C_INT), value :: sig
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
print'(a,i0)', ' received signal ',sig
|
|
|
|
call signal_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
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
!> @brief Set global variable signal_SIGUSR1 to .true.
|
2023-02-11 20:00:12 +05:30
|
|
|
!> @details This function can be registered to catch signals sent to the executable.
|
2022-04-23 18:11:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
subroutine catchSIGUSR1(sig) bind(C)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
integer(C_INT), value :: sig
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
print'(a,i0)', ' received signal ',sig
|
|
|
|
call signal_setSIGUSR1(.true.)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
end subroutine catchSIGUSR1
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
!> @brief Set global variable signal_SIGUSR2 to .true.
|
2023-02-11 20:00:12 +05:30
|
|
|
!> @details This function can be registered to catch signals sent to the executable.
|
2022-04-23 18:11:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
subroutine catchSIGUSR2(sig) bind(C)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
integer(C_INT), value :: sig
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
print'(a,i0,a)', ' received signal ',sig
|
|
|
|
call signal_setSIGUSR2(.true.)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
end subroutine catchSIGUSR2
|
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
!> @brief Set global variable signal_SIGINT.
|
2022-04-23 18:11:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
subroutine signal_setSIGINT(state)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
logical, intent(in) :: state
|
|
|
|
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
signal_SIGINT = state
|
2022-05-12 20:15:42 +05:30
|
|
|
print*, 'set SIGINT to',state
|
2022-04-23 18:11:10 +05:30
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
end subroutine signal_setSIGINT
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
!> @brief Set global variable signal_SIGUSR.
|
2022-04-23 18:11:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
subroutine signal_setSIGUSR1(state)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
logical, intent(in) :: state
|
|
|
|
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
signal_SIGUSR1 = state
|
2022-04-23 18:11:10 +05:30
|
|
|
print*, 'set SIGUSR1 to',state
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
end subroutine signal_setSIGUSR1
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
|
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
!> @brief Set global variable signal_SIGUSR2.
|
2022-04-23 18:11:10 +05:30
|
|
|
!--------------------------------------------------------------------------------------------------
|
2023-01-19 22:07:45 +05:30
|
|
|
subroutine signal_setSIGUSR2(state)
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
logical, intent(in) :: state
|
|
|
|
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
signal_SIGUSR2 = state
|
2022-04-23 18:11:10 +05:30
|
|
|
print*, 'set SIGUSR2 to',state
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
end subroutine signal_setSIGUSR2
|
2022-04-23 18:11:10 +05:30
|
|
|
|
|
|
|
|
2023-01-19 22:07:45 +05:30
|
|
|
end module signal
|