Recent

Author Topic: UPD message fail with Error[22] Invalid argument on FreeBSD  (Read 509 times)

ig

  • New Member
  • *
  • Posts: 10
UPD message fail with Error[22] Invalid argument on FreeBSD
« on: March 31, 2023, 08:30:18 am »
Hi,

This is a rather complex question, so stay with me for a while. I'll sketch the situation as accurate as possible, but if you need more info, give me a call.

I'm running FPC and Lazarus on FreeBSD
OS: FreeBSD 13.1
FPC: 3.2.2
Lazarus: 2.2.2

FPC and Lazarus are Installed using the pkg system

I started with Lazarus 2.2.0 and FPC 3.2.2. Upgraded after a while. The described issue below didn't became visible unit I upgraded to Lazarus 2.2.4. But it's not related to 2.2.4 or even 2.2.6 - I can now also reproduce this on 2.2.2.

Short version:
Sending UDP messages as root user to a server works. Using the same program using a non-privileged user doesn't, i.e. executable is built, but does not work properly,
Quote
Send error[22]: Invalid arguments
is reported.


Using Python create a server handling UDP messages:
Code: Pascal  [Select][+][-]
  1. import socket
  2. scksrv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  3. scksrv.bind(('127.0.0.1', 23223))
  4. scksrv.recvfrom(100)


Logon to FreeBSD as root user and install the additional package lNet.
Create a application with a Form. On the form drop the LUDPComponent.
Write the following program:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   LUDPComponent1.Host := '127.0.0.1';
  4.   LUDPComponent1.Port := 23223;
  5.   if LUDPComponent1.Connect(LUDPComponent1.Host, LUDPComponent1.Port) then
  6.     LUDPComponent1.SendMessage('Hello', Format('%s:%d', [LUDPComponent1.Host, LUDPComponent1.Port]))
  7.   else
  8.     ShowMessage('Connection failed');
  9. end;
  10.  
  11. procedure TForm1.LUDPComponent1Error(const msg: string; aSocket: TLSocket);
  12. begin
  13.   ShowMessage(msg);
  14. end;


Run the application. You'll notice that the message arrives at the server, so no problem.

On the same machine logon a a non-privileged user:
Launch Lazarus, Provide the location of the FPC RTL and start the IDE. You'll notice that the lNet package is not installed. So install the lNet package and rebuild the IDE.

At start-up the IDE now complains that the Fppkg configuration is incorrect. the option is given to change it manually or write. I've selected to write the proposed configuration. The fppkg configuration complains that :
Quote
File: /usr/home/ig/.config/fppkg.cfg

Error: there is a problem with the Fppkg configuration. (Fppkg reports that the RTL is not installed.)

You could try to restore the configuration files automatically, or adapt the configuration file manually.



Write the same Python server program and create the same Lazarus application.

Run the Python server and the application.  The result is: Send error [22]: Invalid argument.

At first I thought this was a bug, in either lNet or Lazarus, but I fear the Fppkg configuration together with the Lazarus configuration is wrong. The Fppkg issue never arose of the root user, so I'm a little bit puzzled.

I've analyzed the configuration files for root and non-privileged user, and they differ largely.
  • Where does this difference come from?
  • Why is there a difference between the root user and the non-privileged user?
  • Are there different templates used?
  • If so why and what needs adapting?


« Last Edit: March 31, 2023, 11:20:33 am by ig »

Zvoni

  • Hero Member
  • *****
  • Posts: 1757
Re: UPD message fail with Error[22] Invalid argument on FreeBSD
« Reply #1 on: March 31, 2023, 11:30:48 am »
Quote
FPC and Lazarus are Installed using the pkg system
That's probably your problem.
My guess is access-rights to paths
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

cappe

  • Full Member
  • ***
  • Posts: 191
Re: UPD message fail with Error[22] Invalid argument on FreeBSD
« Reply #2 on: March 31, 2023, 11:42:22 am »
it seems to work for me too, I repeat it seems because I have not investigated.

ig

  • New Member
  • *
  • Posts: 10
Re: UPD message fail with Error[22] Invalid argument on FreeBSD
« Reply #3 on: April 05, 2023, 11:40:52 am »
it seems to work for me too, I repeat it seems because I have not investigated.

Could you post your configuration details?
FreeBSD version, patch level?
FPC version?
Lazarus version?

Configuration files?

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10716
  • FPC developer.
Re: UPD message fail with Error[22] Invalid argument on FreeBSD
« Reply #4 on: April 05, 2023, 11:52:48 am »
Run the Python server and the application.  The result is: Send error [22]: Invalid argument.

Who gets that error ? What does krace /truss say about it?



ig

  • New Member
  • *
  • Posts: 10
Re: UPD message fail with Error[22] Invalid argument on FreeBSD
« Reply #5 on: April 06, 2023, 08:48:52 am »
The Lazarus application gets the error. The Python server is just use to very the reception of the message.

I've just tested this using Indy10; this works; meaning that there is an issue with lNet/Lazarus and the OS.

I'm willing to figure this out, but some more info on how to tackle this would be welcome. Can you give me some more info on
Quote
krace /truss

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10716
  • FPC developer.
Re: UPD message fail with Error[22] Invalid argument on FreeBSD
« Reply #6 on: April 06, 2023, 09:51:28 am »
I can't remember how it goes, but it is the strace equivalent for FreeBSD.

ktrace ./yourexe

and then later

ktrace > mylog.txt

I can vaguely remember they renamed it to the sysv equivalent truss, but that might also be Mac OS X.

22 is invalid argument, so probably some syscall or so in lnet is dated.

ig

  • New Member
  • *
  • Posts: 10
Re: UPD message fail with Error[22] Invalid argument on FreeBSD
« Reply #7 on: May 04, 2023, 08:47:10 am »
Solved the issue - txs to Michael Canneyt

The problem is located in lNet.

Since FreeBSD 13.1p<something> the size reported in the IP address structure has changed.

In lNet the following function is patched - a fix to the main branch will come soon

function TLSocket.DoSend(const aData; const aSize: Integer): Integer;
var
   AddressLength: Longint = SizeOf(FPeerAddress.IPv4); // <<-- this has changed as a patch to work on IPv4 only: old line = SizeOf(FPeerAddress)
begin
   if FSocketType = SOCK_STREAM then
     Result := Sockets.fpSend(FHandle, @aData, aSize, LMSG)
   else
     Result := sockets.fpsendto(FHandle, @aData, aSize, LMSG, @FPeerAddress,AddressLength);
end;

This is temporary path to make thinks work.
Hope this helps for the moment.

 

TinyPortal © 2005-2018