Skip to content

Commit

Permalink
Terminate on CAN network interface going down
Browse files Browse the repository at this point in the history
  • Loading branch information
hefroy committed Oct 9, 2023
1 parent 341696f commit 222c092
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/CANDataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
#include "EnumUtility.h"
#include "LoggingModule.h"
#include "TraceModule.h"
#include <cerrno>
#include <csignal>
#include <cstring>
#include <ctime>
#include <ctime> // IWYU pragma: keep
#include <linux/can.h>
#include <linux/can/raw.h>
#include <linux/errqueue.h>
Expand Down Expand Up @@ -170,7 +172,6 @@ CANDataSource::doWork( void *data )
}

dataSource->mTimer.reset();
int nmsgs = 0;
struct canfd_frame frame[PARALLEL_RECEIVED_FRAMES_FROM_KERNEL];
struct iovec frame_buffer[PARALLEL_RECEIVED_FRAMES_FROM_KERNEL];
struct mmsghdr msg[PARALLEL_RECEIVED_FRAMES_FROM_KERNEL];
Expand All @@ -190,7 +191,16 @@ CANDataSource::doWork( void *data )
msg[i].msg_hdr.msg_controllen = sizeof( cmsgReturnBuffer[i] );
}
// In one syscall receive up to PARALLEL_RECEIVED_FRAMES_FROM_KERNEL frames in parallel
nmsgs = recvmmsg( dataSource->mSocket, &msg[0], PARALLEL_RECEIVED_FRAMES_FROM_KERNEL, 0, nullptr );
int nmsgs = recvmmsg( dataSource->mSocket, &msg[0], PARALLEL_RECEIVED_FRAMES_FROM_KERNEL, 0, nullptr );
// coverity[autosar_cpp14_m19_3_1_violation]
// coverity[misra_cpp_2008_rule_19_3_1_violation] errno needs to be used to recognize network down
if ( ( nmsgs == -1 ) && ( errno == ENETDOWN ) )
{
// Network interface going down non recoverable, hence we will send signal out to terminate
FWE_LOG_ERROR( "Fatal error, network interface went down" );
std::raise( SIGUSR1 );
return;
}
for ( int i = 0; i < nmsgs; i++ )
{
// After waking up the Socket Can old messages in the kernel queue need to be ignored
Expand Down

0 comments on commit 222c092

Please sign in to comment.