From 2ef021041c265b1346c6d91412526233ee4ebc15 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil <33750417+thattil@users.noreply.github.com> Date: Thu, 23 Mar 2023 13:58:40 +0100 Subject: [PATCH] rx_arping sigchld (#701) * rx_arping pclose gave -1 due to sigchld being ignored, fixed with sig handler doing a wait --- RELEASE.txt | 5 +++++ slsReceiverSoftware/src/Arping.cpp | 18 ++++++++++++------ slsReceiverSoftware/src/Arping.h | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/RELEASE.txt b/RELEASE.txt index 156c7942f..b886cd246 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -28,6 +28,11 @@ This document describes the differences between v7.0.1 and v7.0.0 Compilation issues from 7.0.0 fixed. + * Arping error + Cmdline: rx_arping + API: setRxArping/ getRxArping + Even if arping was successful, it gave an error. Fixed. + 2 On-board Detector Server Compatibility diff --git a/slsReceiverSoftware/src/Arping.cpp b/slsReceiverSoftware/src/Arping.cpp index 98c2c2993..edc1f4b93 100644 --- a/slsReceiverSoftware/src/Arping.cpp +++ b/slsReceiverSoftware/src/Arping.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace sls { @@ -16,6 +17,10 @@ namespace sls { #define gettid() syscall(SYS_gettid) #endif +void func(int signum) { + wait(NULL); +} + Arping::Arping() {} Arping::~Arping() { @@ -44,10 +49,11 @@ pid_t Arping::GetProcessId() const { return childPid; } bool Arping::IsRunning() const { return runningFlag; } void Arping::StartProcess() { - TestCommands(); - // to prevent zombies from child processes being killed - signal(SIGCHLD, SIG_IGN); + signal(SIGCHLD, func); + + // test once to throw exception if arping failed + TestForErrors(); // Needs to be a fork and udp socket deleted after Listening threads // done running to prevent udp socket cannot bind because of popen @@ -90,7 +96,7 @@ void Arping::ProcessExecution() { } } -void Arping::TestCommands() { +void Arping::TestForErrors() { // atleast one interface must be set up if (commands[0].empty()) { throw RuntimeError( @@ -116,7 +122,7 @@ std::string Arping::ExecuteCommands() { FILE *sysFile = popen(cmd.c_str(), "r"); if (sysFile == NULL) { std::ostringstream os; - os << "Could not Arping [" << cmd << " ] : Popen fail"; + os << "Could not Arping (" << cmd << " ) : Popen fail (" << strerror(errno) << ')'; return os.str(); } @@ -128,7 +134,7 @@ std::string Arping::ExecuteCommands() { // check exit status of command if (pclose(sysFile)) { std::ostringstream os; - os << "Could not arping[" << cmd << "] : " << output; + os << "Could not arping (" << cmd << ") : " << strerror(errno); return os.str(); } else { LOG(logDEBUG) << output; diff --git a/slsReceiverSoftware/src/Arping.h b/slsReceiverSoftware/src/Arping.h index bd6ea21a6..96172f76c 100644 --- a/slsReceiverSoftware/src/Arping.h +++ b/slsReceiverSoftware/src/Arping.h @@ -28,7 +28,7 @@ class Arping { void StopProcess(); private: - void TestCommands(); + void TestForErrors(); std::string ExecuteCommands(); void ProcessExecution();