On Wed, 27 Nov 2013, Patrick Chevalley wrote:

Hi,

To enable your program to react to signal you need to use fpSigAction.
See here for usage: 
http://www.freepascal.org/docs-html/rtl/baseunix/fpsigaction.html

Instead of SigUsr1 in the example you can register a procedure for SIGTerm to 
handle a termination request.
You can also add a procedure for SIGHUP if you want to implement a "service .. 
reload" action.
The complete list of signal is in rtl/linux/signal.inc

That is exactly what the daemon code does.

Procedure DoShutDown(Sig : Longint; Info : PSigInfo; Context : PSigContext); 
cdecl;

begin
  Application.StopDaemons(True);
  Application.Terminate;
end;

Procedure SysInitDaemonApp;

Var
  old,new : SigactionRec;

begin
  New.sa_handler:=@DoShutDown;
  fpSigaction(SIGQUIT,@New,@Old);
  fpSigaction(SIGTERM,@New,@Old);
  fpSigaction(SIGINT,@New,@Old);
end;

Michael.

--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to