Skip to content

Commit

Permalink
Track file/line for POSIX errors when that's enabled for CHIP_ERROR (#…
Browse files Browse the repository at this point in the history
…9829)

* Use a macro for creating POSIX errors.

This allows us to add file/line tracking

* Add file/line tracking for POSIX errors.

Only tracks the file/line if that's configured for CHIP_ERROR in general.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Sep 27, 2021
1 parent b7b455c commit 5691169
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 71 deletions.
2 changes: 1 addition & 1 deletion examples/platform/nrfconnect/util/test/TestInetCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ void ServiceEvents(struct ::timeval & aSleepTime)
int selectRes = select(numFDs, &readFDs, &writeFDs, &exceptFDs, &aSleepTime);
if (selectRes < 0)
{
LOG_INF("select failed: %s", ErrorStr(System::MapErrorPOSIX(errno)));
LOG_INF("select failed: %s", ErrorStr(CHIP_ERROR_POSIX(errno)));
return;
}
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS
Expand Down
2 changes: 1 addition & 1 deletion src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jint JNI_OnLoad(JavaVM * jvm, void * reserved)
// Create and start the IO thread.
sShutdown = false;
pthreadErr = pthread_create(&sIOThread, NULL, IOThreadMain, NULL);
VerifyOrExit(pthreadErr == 0, err = System::MapErrorPOSIX(pthreadErr));
VerifyOrExit(pthreadErr == 0, err = CHIP_ERROR_POSIX(pthreadErr));

exit:
if (err != CHIP_NO_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX<ImplClass>::_InitChipStack()
mShouldRunEventLoop.store(true, std::memory_order_relaxed);

int ret = pthread_cond_init(&mEventQueueStoppedCond, nullptr);
VerifyOrReturnError(ret == 0, System::MapErrorPOSIX(ret));
VerifyOrReturnError(ret == 0, CHIP_ERROR_POSIX(ret));

ret = pthread_mutex_init(&mStateLock, nullptr);
VerifyOrReturnError(ret == 0, System::MapErrorPOSIX(ret));
VerifyOrReturnError(ret == 0, CHIP_ERROR_POSIX(ret));

mHasValidChipTask = false;

Expand Down Expand Up @@ -211,11 +211,11 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX<ImplClass>::_StartEventLoopTask()
{
int err;
err = pthread_attr_init(&mChipTaskAttr);
VerifyOrReturnError(err == 0, System::MapErrorPOSIX(err));
VerifyOrReturnError(err == 0, CHIP_ERROR_POSIX(err));
err = pthread_attr_getschedparam(&mChipTaskAttr, &mChipTaskSchedParam);
VerifyOrReturnError(err == 0, System::MapErrorPOSIX(err));
VerifyOrReturnError(err == 0, CHIP_ERROR_POSIX(err));
err = pthread_attr_setschedpolicy(&mChipTaskAttr, SCHED_RR);
VerifyOrReturnError(err == 0, System::MapErrorPOSIX(err));
VerifyOrReturnError(err == 0, CHIP_ERROR_POSIX(err));

//
// We need to grab the lock here since we have to protect setting
Expand All @@ -233,7 +233,7 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX<ImplClass>::_StartEventLoopTask()

pthread_mutex_unlock(&mStateLock);

return System::MapErrorPOSIX(err);
return CHIP_ERROR_POSIX(err);
}

template <class ImplClass>
Expand Down Expand Up @@ -290,7 +290,7 @@ CHIP_ERROR GenericPlatformManagerImpl_POSIX<ImplClass>::_StopEventLoopTask()

exit:
mHasValidChipTask = false;
return System::MapErrorPOSIX(err);
return CHIP_ERROR_POSIX(err);
}

template <class ImplClass>
Expand Down
2 changes: 1 addition & 1 deletion src/inet/DNSResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ CHIP_ERROR DNSResolver::ProcessGetAddrInfoResult(int returnCode, struct addrinfo
err = INET_ERROR_DNS_TRY_AGAIN;
break;
case EAI_SYSTEM:
err = chip::System::MapErrorPOSIX(errno);
err = CHIP_ERROR_POSIX(errno);
break;
default:
err = INET_ERROR_DNS_NO_RECOVERY;
Expand Down
34 changes: 17 additions & 17 deletions src/inet/IPEndPointBasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static CHIP_ERROR SocketsSetMulticastLoopback(int aSocket, bool aLoopback, int a
const unsigned int lValue = aLoopback;
if (setsockopt(aSocket, aProtocol, aOption, &lValue, sizeof(lValue)) != 0)
{
return chip::System::MapErrorPOSIX(errno);
return CHIP_ERROR_POSIX(errno);
}

return CHIP_NO_ERROR;
Expand Down Expand Up @@ -265,7 +265,7 @@ static CHIP_ERROR SocketsIPv4JoinLeaveMulticastGroup(int aSocket, InterfaceId aI

if (setsockopt(aSocket, IPPROTO_IP, aCommand, &lMulticastRequest, sizeof(lMulticastRequest)) != 0)
{
return chip::System::MapErrorPOSIX(errno);
return CHIP_ERROR_POSIX(errno);
}
return CHIP_NO_ERROR;
}
Expand All @@ -287,7 +287,7 @@ static CHIP_ERROR SocketsIPv6JoinLeaveMulticastGroup(int aSocket, InterfaceId aI

if (setsockopt(aSocket, IPPROTO_IPV6, aCommand, &lMulticastRequest, sizeof(lMulticastRequest)) != 0)
{
return chip::System::MapErrorPOSIX(errno);
return CHIP_ERROR_POSIX(errno);
}
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -684,7 +684,7 @@ CHIP_ERROR IPEndPointBasis::Bind(IPAddressType aAddressType, const IPAddress & a
sa.sin6_scope_id = static_cast<decltype(sa.sin6_scope_id)>(aInterfaceId);

if (bind(mSocket, reinterpret_cast<const sockaddr *>(&sa), static_cast<unsigned>(sizeof(sa))) != 0)
lRetval = chip::System::MapErrorPOSIX(errno);
lRetval = CHIP_ERROR_POSIX(errno);

// Instruct the kernel that any messages to multicast destinations should be
// sent down the interface specified by the caller.
Expand Down Expand Up @@ -713,7 +713,7 @@ CHIP_ERROR IPEndPointBasis::Bind(IPAddressType aAddressType, const IPAddress & a
sa.sin_addr = aAddress.ToIPv4();

if (bind(mSocket, reinterpret_cast<const sockaddr *>(&sa), static_cast<unsigned>(sizeof(sa))) != 0)
lRetval = chip::System::MapErrorPOSIX(errno);
lRetval = CHIP_ERROR_POSIX(errno);

// Instruct the kernel that any messages to multicast destinations should be
// sent down the interface to which the specified IPv4 address is bound.
Expand Down Expand Up @@ -750,7 +750,7 @@ CHIP_ERROR IPEndPointBasis::BindInterface(IPAddressType aAddressType, InterfaceI
// Stop interface-based filtering.
if (setsockopt(mSocket, SOL_SOCKET, SO_BINDTODEVICE, "", 0) == -1)
{
lRetval = chip::System::MapErrorPOSIX(errno);
lRetval = CHIP_ERROR_POSIX(errno);
}
}
else
Expand All @@ -760,13 +760,13 @@ CHIP_ERROR IPEndPointBasis::BindInterface(IPAddressType aAddressType, InterfaceI

if (if_indextoname(aInterfaceId, lInterfaceName) == NULL)
{
lRetval = chip::System::MapErrorPOSIX(errno);
lRetval = CHIP_ERROR_POSIX(errno);
}

if (lRetval == CHIP_NO_ERROR &&
setsockopt(mSocket, SOL_SOCKET, SO_BINDTODEVICE, lInterfaceName, socklen_t(strlen(lInterfaceName))) == -1)
{
lRetval = chip::System::MapErrorPOSIX(errno);
lRetval = CHIP_ERROR_POSIX(errno);
}
}

Expand Down Expand Up @@ -899,7 +899,7 @@ CHIP_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System:
// Send IP packet.
const ssize_t lenSent = sendmsg(mSocket, &msgHeader, 0);
if (lenSent == -1)
return chip::System::MapErrorPOSIX(errno);
return CHIP_ERROR_POSIX(errno);
if (lenSent != aBuffer->DataLength())
return CHIP_ERROR_OUTBOUND_MESSAGE_TOO_BIG;
return CHIP_NO_ERROR;
Expand Down Expand Up @@ -930,13 +930,13 @@ CHIP_ERROR IPEndPointBasis::GetSocket(IPAddressType aAddressType, int aType, int

mSocket = ::socket(family, aType, aProtocol);
if (mSocket == -1)
return chip::System::MapErrorPOSIX(errno);
return CHIP_ERROR_POSIX(errno);
ReturnErrorOnFailure(static_cast<System::LayerSockets *>(Layer().SystemLayer())->StartWatchingSocket(mSocket, &mWatch));

mAddrType = aAddressType;

// NOTE WELL: the errors returned by setsockopt() here are not
// returned as Inet layer chip::System::MapErrorPOSIX(errno)
// returned as Inet layer CHIP_ERROR_POSIX(errno)
// codes because they are normally expected to fail on some
// platforms where the socket option code is defined in the
// header files but not [yet] implemented. Certainly, there is
Expand Down Expand Up @@ -1052,7 +1052,7 @@ void IPEndPointBasis::HandlePendingIO(uint16_t aPort)

if (rcvLen < 0)
{
lStatus = chip::System::MapErrorPOSIX(errno);
lStatus = CHIP_ERROR_POSIX(errno);
}
else if (rcvLen > lBuffer->AvailableDataLength())
{
Expand Down Expand Up @@ -1131,7 +1131,7 @@ void IPEndPointBasis::HandlePendingIO(uint16_t aPort)
}
else
{
if (OnReceiveError != nullptr && lStatus != chip::System::MapErrorPOSIX(EAGAIN))
if (OnReceiveError != nullptr && lStatus != CHIP_ERROR_POSIX(EAGAIN))
{
OnReceiveError(this, lStatus, nullptr);
}
Expand Down Expand Up @@ -1227,7 +1227,7 @@ CHIP_ERROR IPEndPointBasis::SendMsg(const IPPacketInfo * aPktInfo, chip::System:
nw_connection_send(mConnection, content, NW_CONNECTION_DEFAULT_MESSAGE_CONTEXT, true, ^(nw_error_t error) {
if (error)
{
res = chip::System::MapErrorPOSIX(nw_error_get_error_code(error));
res = CHIP_ERROR_POSIX(nw_error_get_error_code(error));
}
else
{
Expand Down Expand Up @@ -1258,7 +1258,7 @@ void IPEndPointBasis::HandleDataReceived(const nw_connection_t & aConnection)
errno = nw_error_get_error_code(receive_error);
if (!(error_domain == nw_error_domain_posix && errno == ECANCELED))
{
CHIP_ERROR error = chip::System::MapErrorPOSIX(errno);
CHIP_ERROR error = CHIP_ERROR_POSIX(errno);
IPPacketInfo packetInfo;
GetPacketInfo(aConnection, packetInfo);
dispatch_async(mDispatchQueue, ^{
Expand Down Expand Up @@ -1402,7 +1402,7 @@ CHIP_ERROR IPEndPointBasis::StartListener()

case nw_listener_state_failed:
ChipLogDetail(Inet, "Listener: Failed");
res = chip::System::MapErrorPOSIX(nw_error_get_error_code(error));
res = CHIP_ERROR_POSIX(nw_error_get_error_code(error));
break;

case nw_listener_state_ready:
Expand Down Expand Up @@ -1458,7 +1458,7 @@ CHIP_ERROR IPEndPointBasis::StartConnection(nw_connection_t & aConnection)

case nw_connection_state_failed:
ChipLogDetail(Inet, "Connection: Failed");
res = chip::System::MapErrorPOSIX(nw_error_get_error_code(error));
res = CHIP_ERROR_POSIX(nw_error_get_error_code(error));
break;

case nw_connection_state_ready:
Expand Down
4 changes: 2 additions & 2 deletions src/inet/InetInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ DLL_EXPORT CHIP_ERROR GetInterfaceName(InterfaceId intfId, char * nameBuf, size_
#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
char intfName[IF_NAMESIZE];
if (if_indextoname(intfId, intfName) == nullptr)
return chip::System::MapErrorPOSIX(errno);
return CHIP_ERROR_POSIX(errno);
if (strlen(intfName) >= nameBufSize)
return CHIP_ERROR_NO_MEMORY;
strcpy(nameBuf, intfName);
Expand Down Expand Up @@ -172,7 +172,7 @@ DLL_EXPORT CHIP_ERROR InterfaceNameToId(const char * intfName, InterfaceId & int
#if CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS
intfId = if_nametoindex(intfName);
if (intfId == 0)
return (errno == ENXIO) ? INET_ERROR_UNKNOWN_INTERFACE : chip::System::MapErrorPOSIX(errno);
return (errno == ENXIO) ? INET_ERROR_UNKNOWN_INTERFACE : CHIP_ERROR_POSIX(errno);
return CHIP_NO_ERROR;
#endif // CHIP_SYSTEM_CONFIG_USE_SOCKETS && CHIP_SYSTEM_CONFIG_USE_BSD_IFADDRS

Expand Down
2 changes: 1 addition & 1 deletion src/inet/InetLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ CHIP_ERROR InetLayer::InitQueueLimiter(void)
{
if (sem_init(&mDroppableEvents, 0, INET_CONFIG_MAX_DROPPABLE_EVENTS) != 0)
{
return chip::System::MapErrorPOSIX(errno);
return CHIP_ERROR_POSIX(errno);
}
return CHIP_NO_ERROR;
}
Expand Down
Loading

0 comments on commit 5691169

Please sign in to comment.