[fpc-pascal] Suppressing ^C signal from stdin
Mark Morgan Lloyd
markMLl.fpc-pascal at telemetry.co.uk
Thu Jan 2 09:41:05 CET 2014
Tomas Hajny wrote:
> On Wed, January 1, 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 :-)
>
> The general platform independent solution would have been 'Crt.CheckBreak
> := false' (or System.SysSetCtrlBreakHandler without unit Crt should you
> not use/need that) - except for the fact that maintainers of most
> platforms (all those mentioned by you) decided not to implement/support
> this functionality and thus it would not work for those platforms you are
> interested in... :-/
Good point. In practice using Crt might be a problem when I come to
adding an alternative graphical frontend to the emulator: I think this
highlights (as has been discussed elsewhere) the lack of a simple
terminal component in Lazarus.
I've played around a bit and find that in Linux (other platforms
untested) provided that I add action.Sa_Flags := SA_SIGINFO; I can get
the PID inside the signal handler. This is zero for a ^C, which
potentially allows one to distinguish between a spurious ^C and a SIGINT
sent by kill.
--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk
[Opinions above are the author's, not those of his employers or colleagues]
More information about the fpc-pascal
mailing list