-
Notifications
You must be signed in to change notification settings - Fork 1
/
sigint.pas
40 lines (32 loc) · 872 Bytes
/
sigint.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{$MODE OBJFPC} { -*- delphi -*- }
{$INCLUDE settings.inc}
unit sigint;
interface
uses sysutils, baseunix, exceptions;
var
Aborted: Boolean = False;
procedure InstallSigIntHandler();
implementation
procedure SigIntHandler(Signal: Longint; Info: PSigInfo; Context: PSigContext); cdecl;
begin
Aborted := True;
end;
procedure InstallSigIntHandler();
var
NewAction: PSigActionRec;
begin
New(NewAction);
if (not Assigned(NewAction)) then
OutOfMemoryError();
try
NewAction^.sa_handler := @SigIntHandler;
NewAction^.sa_flags := SA_ONESHOT;
{$IFDEF Linux} NewAction^.sa_restorer := nil; {$ENDIF}
FillByte(NewAction^.sa_mask, SizeOf(NewAction^.sa_mask), 0);
if (fpSigAction(baseunix.SIGINT, NewAction, nil) <> 0) then
raise EKernelError.Create(fpGetErrNo);
finally
Dispose(NewAction);
end;
end;
end.