Recent

Author Topic: Linux daemon's AccessViolation  (Read 2321 times)

auRazor

  • New Member
  • *
  • Posts: 17
Linux daemon's AccessViolation
« on: January 21, 2021, 06:00:26 am »
I converted a Delphi windows application to freepascal daemon to run on linux.

I am using the lazdaemonapp and daemonapp code

The app was throwing an AccessViolation error every time i would send a killall -SIGTERM command.

After many hours I went back to base and created a new application with no code in it apart from DaemonApplication, DaemonMapper and DaemonApp code ran it and get the access violation message in syslog and this on the command line

$ ../temp/daemonexample/project1 -r
Exception at 0000000000000000: EAccessViolation:
Access violation.

Has anyone else used the apps and had any issues?

FreePascal=3.0.4
Lazarus=2.0.6
OS=Ubuntu 20.10

This is basically all the code

Project
Code: Pascal  [Select][+][-]
  1. Program project1;
  2.  
  3. Uses
  4. {$IFDEF UNIX}{$IFDEF UseCThreads}
  5.   CThreads,
  6. {$ENDIF}{$ENDIF}
  7.   DaemonApp, lazdaemonapp, DaemonMapperUnit1, DaemonUnit1
  8.   { add your units here };
  9.  
  10. begin
  11.   Application.Initialize;
  12.   Application.Run;
  13. end.

Mapper
Code: Pascal  [Select][+][-]
  1. unit DaemonMapperUnit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, DaemonApp;
  9.  
  10. type
  11.  
  12.   { TDaemonMapper1 }
  13.  
  14.   TDaemonMapper1 = class(TDaemonMapper)
  15.     procedure DaemonMapper1Create(Sender: TObject);
  16.   private
  17.  
  18.   public
  19.  
  20.   end;
  21.  
  22. var
  23.   DaemonMapper1: TDaemonMapper1;
  24.  
  25. implementation
  26.  
  27. procedure RegisterMapper;
  28. begin
  29.   RegisterDaemonMapper(TDaemonMapper1)
  30. end;
  31.  
  32. {$R *.lfm}
  33.  
  34. { TDaemonMapper1 }
  35.  
  36. procedure TDaemonMapper1.DaemonMapper1Create(Sender: TObject);
  37. var
  38. D : TDaemonDef;
  39. begin
  40.   D:=DaemonDefs.Add as TDaemonDef;
  41.   D.DisplayName:='Test Service daemon';
  42.   D.Name:='TestServiceDaemon';
  43.   D.DaemonClassName:='TDaemon1';
  44. end;
  45.  
  46.  
  47. initialization
  48.   RegisterMapper;
  49. end.
  50.  
  51.  

App
Code: Pascal  [Select][+][-]
  1. unit DaemonUnit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, DaemonApp;
  9.  
  10. type
  11.   TDaemon1 = class(TDaemon)
  12.   private
  13.  
  14.   public
  15.  
  16.   end;
  17.  
  18. var
  19.   Daemon1: TDaemon1;
  20.  
  21. implementation
  22.  
  23. procedure RegisterDaemon;
  24. begin
  25.   RegisterDaemonClass(TDaemon1)
  26. end;
  27.  
  28. {$R *.lfm}
  29.  
  30.  
  31. initialization
  32.   RegisterDaemon;
  33. end.
  34.  

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: Linux daemon's AccessViolation
« Reply #1 on: January 21, 2021, 07:36:17 am »
You didn't include any lfm file. I compiled from your sources (commenting out the lfm include statements) and got this when run:


Exception at 000000000042A5E6: EStreamError:
Failed to initialize component class "TDaemonMapper1": No streaming method available.


I don't use lazdaemon myself. I have some dockerized microservices written in FPC. Running in Docker means I don't have to care about daemonization.

auRazor

  • New Member
  • *
  • Posts: 17
Re: Linux daemon's AccessViolation
« Reply #2 on: January 21, 2021, 08:53:18 am »
You didn't include any lfm file. I compiled from your sources (commenting out the lfm include statements) and got this when run:


Exception at 000000000042A5E6: EStreamError:
Failed to initialize component class "TDaemonMapper1": No streaming method available.


I don't use lazdaemon myself. I have some dockerized microservices written in FPC. Running in Docker means I don't have to care about daemonization.


How did you get that error Pierce? My debugger goes to the assembler window. I would love to dockerize but that is not an option right  now. Have an attached the project zipped up

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: Linux daemon's AccessViolation
« Reply #3 on: January 21, 2021, 09:52:38 am »
How did you get that error Pierce? My debugger goes to the assembler window.

I ran the program on the command line.

Have an attached the project zipped up

I can't get it to load cleanly. See attached. I selected 'cancel loading this component' and plowed on. The program compiles. Running it:


./project1
Usage: /tmp/project1 [command]
Where command is one of the following:
  -i --install   To install the program as a service
  -u --uninstall To uninstall the service
  -r --run       To run the service


Oh, I am using Lazarus 2.0.10 with FPC 3.2.0, on Ubuntu 20.04.
« Last Edit: January 21, 2021, 10:02:29 am by PierceNg »

auRazor

  • New Member
  • *
  • Posts: 17
Re: Linux daemon's AccessViolation
« Reply #4 on: January 21, 2021, 10:37:57 am »
You need to add the lazdaemon package and run the application with a -r
/tmp/project1 -r

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: Linux daemon's AccessViolation
« Reply #5 on: January 21, 2021, 01:16:37 pm »
You need to add the lazdaemon package and run the application with a -r
/tmp/project1 -r

No access violation error in my case.


/tmp% ./project1 -r


auRazor

  • New Member
  • *
  • Posts: 17
Re: Linux daemon's AccessViolation
« Reply #6 on: January 21, 2021, 01:44:51 pm »
You need to add the lazdaemon package and run the application with a -r
/tmp/project1 -r

No access violation error in my case.


/tmp% ./project1 -r


Not even in syslog?

PierceNg

  • Sr. Member
  • ****
  • Posts: 369
    • SamadhiWeb
Re: Linux daemon's AccessViolation
« Reply #7 on: January 21, 2021, 03:11:20 pm »
Not even in syslog?

The program didn't crash. It is just doing nothing.


    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                             
  13236 pierce    20   0   14308   3292   3016 S   0.0   0.0   0:00.00 project1                                             

auRazor

  • New Member
  • *
  • Posts: 17
Re: Linux daemon's AccessViolation
« Reply #8 on: January 22, 2021, 01:04:36 am »
I upgrade to fpc 3.2 and lazarus 2.0.10 and the program compiled and run without the issue. So i went back to the original program and now have another issue compiling zeoslib.

I was kind of thinking that maybe I just need to recompile the freepascal library as I have upgraded the OS since I installed it but anyway

auRazor

  • New Member
  • *
  • Posts: 17
Re: Linux daemon's AccessViolation
« Reply #9 on: January 22, 2021, 04:16:19 am »
So after upgrading to FPC 3.2 my UDP server was not binding to a socket properly, so I rolled back and it was working as expected but getting the access violation again. Can't win %) %)

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Linux daemon's AccessViolation
« Reply #10 on: January 22, 2021, 06:52:35 am »
As for the not working with FPC 3.2.0, did you check the FPC 3.2.0 - User changes which may break code and possibly also FPC 3.2.0 - New Features ?

 

TinyPortal © 2005-2018