Commit 033740f8 authored by Mart Lubbers's avatar Mart Lubbers

Initial signal API

parent 870958dd
Pipeline #20538 failed with stage
in 3 minutes and 6 seconds
definition module System.Signal
from Data.Error import :: MaybeErrorString, :: MaybeError
from System.OSError import :: MaybeOSError, :: OSError, :: OSErrorMessage, :: OSErrorCode
:: SigHandler
//All portable signals numbers:
SIGABRT :== 6
SIGALRM :== 14
SIGHUP :== 1
SIGINT :== 2
SIGKILL :== 9 // Can't catch that one
SIGQUIT :== 3
SIGTERM :== 15
SIGTRAP :== 5
/*
* Install a signal handler
*
* @param Signal type
* @param World
* @return Error or handler
* @return New world
*/
signalInstall :: !Int !*env -> *(MaybeOSError *SigHandler, !*env)
/*
* Poll a signal, this resets the state
*
* @param Signal handler
* @param World
* @return Was thrown
* @return New handler
* @return New world
*/
signalPoll :: !*SigHandler !*env -> *(!MaybeErrorString Bool, !*SigHandler, !*env)
implementation module System.Signal
import StdEnv
import Data.Error
import System.OSError
import code from "systemsignal.o"
:: SigHandler :== Int
signalInstall :: !Int !*env -> *(MaybeOSError *SigHandler, !*env)
signalInstall signum w
# (ok, h, w) = signalInstall_ signum w
| ok <> 0 = getLastOSError w
= (Ok h, w)
where
signalInstall_ :: !Int !*env -> *(!Int, !*SigHandler, !*env)
signalInstall_ _ _ = code {
ccall signal_install "I:VII:A"
}
signalPoll :: !*SigHandler !*env -> *(!MaybeErrorString Bool, !*SigHandler, !*env)
signalPoll h w
# (ok, s, h, w) = signalPoll_ h w
| ok <> 0 = (Error "Invalid handler", h, w)
= (Ok s, h, w)
where
signalPoll_ :: !*SigHandler !*env -> *(!Int, !Bool, !*SigHandler, !*env)
signalPoll_ _ _= code {
ccall signal_poll "I:VIII:A"
}
#include <stdlib.h>
#include <signal.h>
static long signal_state[NSIG] = {0};
static void signal_handler(int sig, siginfo_t *si, void *unused)
{
signal_state[sig] = 1;
(void)si;
(void)unused;
}
void signal_install(long signum, long *ok, long *handler)
{
struct sigaction act;
act.sa_flags = SA_SIGINFO;
sigemptyset(&act.sa_mask);
act.sa_sigaction = signal_handler;
*ok = sigaction(signum, &act, NULL);
*handler = signum;
}
void signal_poll(long handler, long *ok, long *state, long *handlerr)
{
*ok = 1;
if(0 < handler && handler < NSIG){
*handlerr = handler;
*state = signal_state[handler];
signal_state[handler] = 0;
*ok = 0;
}
}
......@@ -175,6 +175,7 @@ import qualified System.Process
import qualified System.TTS
import qualified System.Time
import qualified System.Time.GenJSON
import qualified System.Signal
import qualified System._Directory
import qualified System._FilePath
import qualified System._Finalized
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment