fix(posix): silence rcS bc + px4_daemon socket-close errors

Two cosmetic-but-noisy errors at every SITL boot once the rcS runs via
the portable /bin/sh backend (this branch's commit 9abb4ac867). On
ROS Integration Tests the container ships without bc, so the
PX4_SIM_SPEED_FACTOR multiplications fail and rcS emits:

  px4-rc: 190: etc/init.d-posix/rcS: bc: not found
  COM_DL_LOSS_T set to
  ERROR [param] not enough arguments.
  Try 'param set COM_DL_LOSS_T 3 [fail]'

(The ros_test_runner.py path always sets PX4_SIM_SPEED_FACTOR=1, so
the bc block always runs even though the multiplication is a no-op.)
Substitute awk -v s="$SF" 'BEGIN{print s*N}' for the bc one-liners.
awk is in coreutils on every PX4 dev / CI image and produces identical
floating-point output; bc is not packaged in the ROS Integration
container.

Separately, every external param-set call from the rcS races the
daemon's closesocket() and the client's recv() picks up ECONNRESET
(or EPIPE) instead of a clean EOF, even though the {0, retval}
sentinel is already buffered. The Linux #else branch unconditionally
logged "unable to read from socket" and returned -1, drowning the rcS
output in spurious errors:

  EKF2_EV_CTRL: curr: 0 -> new: 15
  ERROR [px4_daemon] unable to read from socket

Mirror the Windows WSAECONNRESET / WSAESHUTDOWN handling on Linux:
when errno is ECONNRESET / EPIPE and the sentinel is buffered, honour
it as end-of-stream instead of treating the close race as a failure.
Also append strerror(errno) to the surviving error path so a real
socket failure (EBADF, EINTR, ENOMEM, ...) still surfaces with the
underlying cause.

Both fixes are no-ops on the happy path; they only suppress error
output that the daemon-client teardown race emits during normal
shutdown.
Signed-off-by: Nuno Marques <n.marques21@hotmail.com>
This commit is contained in:
Nuno Marques
2026-05-08 14:36:35 -07:00
parent 16c10cfd82
commit fd61773e6f
2 changed files with 18 additions and 4 deletions
+3 -3
View File
@@ -187,15 +187,15 @@ param set-default UXRCE_DDS_AG_IP 2130706433 # 127.0.0.1
# Adapt timeout parameters if simulation runs faster or slower than realtime.
if [ -n "$PX4_SIM_SPEED_FACTOR" ]; then
COM_DL_LOSS_T_LONGER=$(echo "$PX4_SIM_SPEED_FACTOR * 10" | bc)
COM_DL_LOSS_T_LONGER=$(awk -v s="$PX4_SIM_SPEED_FACTOR" 'BEGIN{print s*10}')
echo "COM_DL_LOSS_T set to $COM_DL_LOSS_T_LONGER"
param set COM_DL_LOSS_T $COM_DL_LOSS_T_LONGER
COM_RC_LOSS_T_LONGER=$(echo "$PX4_SIM_SPEED_FACTOR * 1.0" | bc)
COM_RC_LOSS_T_LONGER=$(awk -v s="$PX4_SIM_SPEED_FACTOR" 'BEGIN{print s*1.0}')
echo "COM_RC_LOSS_T set to $COM_RC_LOSS_T_LONGER"
param set COM_RC_LOSS_T $COM_RC_LOSS_T_LONGER
COM_OF_LOSS_T_LONGER=$(echo "$PX4_SIM_SPEED_FACTOR * 1.0" | bc)
COM_OF_LOSS_T_LONGER=$(awk -v s="$PX4_SIM_SPEED_FACTOR" 'BEGIN{print s*1.0}')
echo "COM_OF_LOSS_T set to $COM_OF_LOSS_T_LONGER"
param set COM_OF_LOSS_T $COM_OF_LOSS_T_LONGER
fi
@@ -318,7 +318,21 @@ Client::_listen()
PX4_ERR("unable to read from socket: WSA error = %d", wsa_err);
#else
PX4_ERR("unable to read from socket");
// ECONNRESET / EPIPE can fire on AF_UNIX too if the daemon
// closes the socket between sending the {0, retval} sentinel
// and our recv() picking up the EOF. The bytes have already
// been delivered into our kernel buffer, so honour the
// sentinel rather than reporting a spurious socket error.
if (errno == ECONNRESET || errno == EPIPE) {
if (n_buffer_used == 2) {
return buffer[1];
}
return -1;
}
PX4_ERR("unable to read from socket: %s", strerror(errno));
#endif
return -1;