After having successfully converted the
SampleD C daemon code into working,
non-deprecated C code (ie replacing the deprecated ASL logging with OSLog; replacing the myriad deprecated launch_ functions with launch_activate_socket) my quest to convert it into Pascal has hit a pot hole, er, wall.
My working, converted, C code:
#include <launch.h>
[...]
int *listening_fd_array;
size_t listening_fds_count;
int err;
[...]
err = launch_activate_socket("MySocket", &listening_fd_array, &listening_fds_count);
if (err != 0) {
os_log_error
(OS_LOG_DEFAULT
, "launch_activate_socket() failed error %d (%s)", err
, strerror(err
));}
if (NULL == listening_fd_array) {
os_log_error(OS_LOG_DEFAULT, "No known sockets found to answer requests on!");
retval = EXIT_FAILURE;
goto done;
}
My failed Pascal attempt:
function launch_activate_socket(const name: string; var fds: PInteger; cnt: size_t): integer; external name '_launch_activate_socket';
[...]
var
err : integer;
listening_fd_array: PInteger;
listening_fds_count: size_t;
[...]
err := launch_activate_socket('MySocket', listening_fd_array, listening_fds_count);
if(err <> 0) then
begin
if(err = ENOENT) then
writeln('Error: Socket not found in plist file (', err, ')')
else if(err = ESRCH) then
writeln('Error: Calling process is not managed by launchd (', err, ')')
else if(err = EALREADY) then
writeln('Error: Socket already activated (', err, ')')
else
writeln('Error: ', err);
end;
if(Nil = listening_fds_count) then
begin
writeln('No known sockets found to answer requests on!');
goto Done;
end;
Where did I go wrong? It compiles successfully, but errors out with ESRCH and "No known sockets...".