[fpc-pascal] Suppressing ^C signal from stdin
Sven Barth
pascaldragon at googlemail.com
Wed Jan 1 21:26:38 CET 2014
On 01.01.2014 20:48, Mark Morgan Lloyd wrote:
> When reading characters from a program's stdin using fpRead(), what's
> the best way of suppressing ^C so that it doesn't raise SIGTERM or
> whatever? I want to be able to handle signals indicating e.g. a UPS
> power-failure message, but not to get trivial stuff from the keyboard.
>
> Platform is predominantly Linux, possibly also Solaris and one of the
> BSDs. Anybody porting the program to Windows will have to do their own
> dirty work :-)
>
For Unix systems you could hook the SIGINT signal:
=== code begin ===
uses
baseunix;
procedure SigIntHandler(signal: longint; info: psiginfo; context:
psigcontext); cdecl;
begin
(* ignore signal *)
end;
var
oldsigrec, newsigrec: sigactionrec;
begin
FillChar(newsigrec, SizeOf(newsigrec), 0);
newsigrec.sa_handler := @SigIntHandler;
FpSigaction(SIGINT, @newsigrec, @oldsigrec);
// do something
end.
=== code end ===
For Windows there is this:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms685049%28v=vs.85%29.aspx
(your application should be of apptype console of course)
Regards,
Sven
More information about the fpc-pascal
mailing list