Forum > Linux

TDaemon Wiki Demo : start event not fired

(1/2) > >>

Michael Collier:
Hi,
I'm experimenting with linux daemons and could not get start event to fire in demo application.
https://wiki.freepascal.org/Daemons_and_Services
https://github.com/arminlinder/Lazarus-FPC-Wiki-Code-Samples/zipball/master/

I modified the code below and now it works, so looks like the demo needs a small fix to the Format function call (seems it wants 2 parameters string and number )?

See DaemonUnit1.pas

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDaemon1.DataModuleStart(Sender: TCustomDaemon; var OK: Boolean);begin  LogToFile('STARTED');  {-m.c.  LogToFile(Format('Daemon %s received start signal, PID:%d', [GetProcessID]));  // Create a suspended worker thread - see DaemonWorkerThread unit  FDaemonWorkerThread := TDaemonWorkerThread.Create;  // Parametrize it  FDaemonWorkerThread.FreeOnTerminate := False;  // Start the worker  FDaemonWorkerThread.Start;  }  OK := True;end;  
Log:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---12:54:43 Log created12:54:43 Daemon received stop signal12:54:43 Daemon stopped12:55:08 Daemon installing12:55:08 Daemon installed12:55:39 STARTED

TRon:

--- Quote from: Michael Collier on February 02, 2023, 02:05:51 pm ---https://wiki.freepascal.org/Daemons_and_Services

I modified the code below and now it works, so looks like the demo needs a small fix to the Format function call (seems it wants 2 parameters string and number )?

--- End quote ---
copy-paste error ?

this is what I read/see:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDaemon1.DataModuleStart(Sender: TCustomDaemon; var OK: Boolean);begin  LogToFile(Format('Daemon received start signal, PID:%d', [GetProcessID]));  // Create a suspended worker thread - see DaemonWorkerThread unit  FDaemonWorkerThread := TDaemonWorkerThread.Create;  // Parametrize it  FDaemonWorkerThread.FreeOnTerminate := False;  // Start the worker  FDaemonWorkerThread.Start;  OK := True;end; Thus the format only has one used format parameter (did you added the %s yourself, perhaps copied from the second example that does use two format parameter strings ?)  :)

But yes, that call to format as you have shown will fail because it is missing a string for first parameter (you only supplied one integer with the call to GetProcessID() )

Michael Collier:
Ahh I think I know what the problem is , I'm using the code from the zip download that contains the error

https://github.com/arminlinder/Lazarus-FPC-Wiki-Code-Samples/zipball/master/

The code in the wiki is correct, but download demo project is wrong?

TRon:

--- Quote from: Michael Collier on February 02, 2023, 02:31:32 pm ---The code in the wiki is correct, but download demo project is wrong?

--- End quote ---
Indeed i was copying the wiki entry. Because I did not trusted it I downloaded the zipfile and indeed there the error is present.

You can easily solve that with for example:

--- Code: --- LogToFile(Format('Daemon %s received start signal, PID:%d', ['the_name_of_your_daemon', GetProcessID]));

--- End code ---
or replace it as per wiki entry.

At least it keeps you/us alert  :D

Michael Collier:
I added an issue in github
https://github.com/arminlinder/Lazarus-FPC-Wiki-Code-Samples/issues/2

Hopefully the demo will be fixed, it's working great for me..

Navigation

[0] Message Index

[#] Next page

Go to full version