diff --git a/examples/platforms/simulation/alarm.c b/examples/platforms/simulation/alarm.c index 3a151806437..af32239745b 100644 --- a/examples/platforms/simulation/alarm.c +++ b/examples/platforms/simulation/alarm.c @@ -114,7 +114,7 @@ void platformAlarmInit(uint32_t aSpeedUpFactor) if (sigaction(OPENTHREAD_CONFIG_MICRO_TIMER_SIGNAL, &sa, NULL) == -1) { perror("sigaction"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } struct sigevent sev; @@ -126,7 +126,7 @@ void platformAlarmInit(uint32_t aSpeedUpFactor) if (-1 == timer_create(CLOCK_MONOTONIC, &sev, &sMicroTimer)) { perror("timer_create"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } } #endif @@ -198,7 +198,7 @@ void otPlatAlarmMicroStartAt(otInstance *aInstance, uint32_t aT0, uint32_t aDt) if (-1 == timer_settime(sMicroTimer, 0, &its, NULL)) { perror("otPlatAlarmMicroStartAt timer_settime()"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } } #endif // __linux__ @@ -217,7 +217,7 @@ void otPlatAlarmMicroStop(otInstance *aInstance) if (-1 == timer_settime(sMicroTimer, 0, &its, NULL)) { perror("otPlatAlarmMicroStop timer_settime()"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } } #endif // __linux__ diff --git a/examples/platforms/simulation/ble.c b/examples/platforms/simulation/ble.c index e8f96daa099..b757a5eba5a 100644 --- a/examples/platforms/simulation/ble.c +++ b/examples/platforms/simulation/ble.c @@ -37,6 +37,7 @@ #include #include +#include "lib/platform/exit_code.h" #include "utils/code_utils.h" #define PLAT_BLE_MSG_DATA_MAX 2048 @@ -76,7 +77,7 @@ static void initFds(void) exit: if (sFd == -1) { - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } } @@ -207,7 +208,7 @@ void platformBleProcess(otInstance *aInstance, const fd_set *aReadFdSet, const f else if (errno != EINTR && errno != EAGAIN) { perror("recvfrom BLE simulation failed"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } } exit: diff --git a/examples/platforms/simulation/infra_if.c b/examples/platforms/simulation/infra_if.c index 4b904d04dc5..580b8b06af3 100644 --- a/examples/platforms/simulation/infra_if.c +++ b/examples/platforms/simulation/infra_if.c @@ -252,7 +252,7 @@ void platformInfraIfInit(void) if (*endptr != '\0') { fprintf(stderr, "\r\nInvalid PORT_OFFSET: %s\r\n", str); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } sPortOffset *= (MAX_NETWORK_SIZE + 1); @@ -332,7 +332,7 @@ OT_TOOL_WEAK void otPlatInfraIfRecvIcmp6Nd(otInstance *aInstance, OT_UNUSED_VARIABLE(aBufferLength); fprintf(stderr, "\n\r Weak otPlatInfraIfRecvIcmp6Nd is being used\n\r"); - exit(1); + DieNow(OT_EXIT_FAILURE); } #endif // OPENTHREAD_SIMULATION_IMPLEMENT_INFRA_IF && OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE diff --git a/examples/platforms/simulation/mdns_socket.c b/examples/platforms/simulation/mdns_socket.c index 88abcb50cac..61926c0ba63 100644 --- a/examples/platforms/simulation/mdns_socket.c +++ b/examples/platforms/simulation/mdns_socket.c @@ -76,26 +76,16 @@ static int sMdnsFd6 = -1; #endif #endif -#define VerifyOrDie(aCondition, aErrMsg) \ - do \ - { \ - if (!(aCondition)) \ - { \ - fprintf(stderr, "\n\r" aErrMsg ". errono:%s\n\r", strerror(errno)); \ - exit(1); \ - } \ - } while (false) - static void SetReuseAddrPort(int aFd) { int ret; int yes = 1; ret = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)); - VerifyOrDie(ret >= 0, "setsocketopt(SO_REUSEADDR) failed"); + VerifyOrDie(ret >= 0, OT_EXIT_FAILURE); ret = setsockopt(aFd, SOL_SOCKET, SO_REUSEPORT, (char *)&yes, sizeof(yes)); - VerifyOrDie(ret >= 0, "setsocketopt(SO_REUSEPORT) failed"); + VerifyOrDie(ret >= 0, OT_EXIT_FAILURE); } static void OpenIp4Socket(uint32_t aInfraIfIndex) @@ -109,7 +99,7 @@ static void OpenIp4Socket(uint32_t aInfraIfIndex) int value; fd = socket(AF_INET, SOCK_DGRAM, 0); - VerifyOrDie(fd >= 0, "socket() failed"); + VerifyOrDie(fd >= 0, OT_EXIT_FAILURE); #ifdef __linux__ { @@ -117,10 +107,10 @@ static void OpenIp4Socket(uint32_t aInfraIfIndex) const char *ifname; ifname = if_indextoname(aInfraIfIndex, nameBuffer); - VerifyOrDie(ifname != NULL, "if_indextoname() failed"); + VerifyOrDie(ifname != NULL, OT_EXIT_ERROR_ERRNO); ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname)); - VerifyOrDie(ret >= 0, "setsocketopt(SO_BINDTODEVICE) failed"); + VerifyOrDie(ret >= 0, OT_EXIT_ERROR_ERRNO); } #else value = aInfraIfIndex; @@ -129,15 +119,15 @@ static void OpenIp4Socket(uint32_t aInfraIfIndex) u8 = 255; ret = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &u8, sizeof(u8)); - VerifyOrDie(ret >= 0, "setsocketopt(IP_MULTICAST_TTL) failed"); + VerifyOrDie(ret >= 0, OT_EXIT_ERROR_ERRNO); value = 255; ret = setsockopt(fd, IPPROTO_IP, IP_TTL, &value, sizeof(value)); - VerifyOrDie(ret >= 0, "setsocketopt(IP_TTL) failed"); + VerifyOrDie(ret >= 0, OT_EXIT_ERROR_ERRNO); u8 = 1; ret = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &u8, sizeof(u8)); - VerifyOrDie(ret >= 0, "setsocketopt(IP_MULTICAST_LOOP) failed"); + VerifyOrDie(ret >= 0, OT_EXIT_ERROR_ERRNO); SetReuseAddrPort(fd); @@ -149,7 +139,7 @@ static void OpenIp4Socket(uint32_t aInfraIfIndex) mreqn.imr_ifindex = aInfraIfIndex; ret = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &mreqn, sizeof(mreqn)); - VerifyOrDie(ret >= 0, "setsocketopt(IP_MULTICAST_IF) failed"); + VerifyOrDie(ret >= 0, OT_EXIT_ERROR_ERRNO); } memset(&addr, 0, sizeof(addr)); @@ -158,7 +148,7 @@ static void OpenIp4Socket(uint32_t aInfraIfIndex) addr.sin_port = htons(MDNS_PORT); ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); - VerifyOrDie(ret >= 0, "bind() failed"); + VerifyOrDie(ret >= 0, OT_EXIT_ERROR_ERRNO); sMdnsFd4 = fd; } @@ -468,8 +458,7 @@ OT_TOOL_WEAK uint16_t otMessageRead(const otMessage *aMessage, uint16_t aOffset, OT_UNUSED_VARIABLE(aLength); fprintf(stderr, "\n\rWeak otMessageRead() is incorrectly used\n\r"); - exit(1); - + DieNow(OT_EXIT_FAILURE); return 0; } @@ -477,7 +466,7 @@ OT_TOOL_WEAK void otMessageFree(otMessage *aMessage) { OT_UNUSED_VARIABLE(aMessage); fprintf(stderr, "\n\rWeak otMessageFree() is incorrectly used\n\r"); - exit(1); + DieNow(OT_EXIT_FAILURE); } OT_TOOL_WEAK otMessage *otIp6NewMessage(otInstance *aInstance, const otMessageSettings *aSettings) @@ -486,7 +475,7 @@ OT_TOOL_WEAK otMessage *otIp6NewMessage(otInstance *aInstance, const otMessageSe OT_UNUSED_VARIABLE(aSettings); fprintf(stderr, "\n\rWeak otIp6NewMessage() is incorrectly used\n\r"); - exit(1); + DieNow(OT_EXIT_FAILURE); return NULL; } @@ -498,7 +487,7 @@ OT_TOOL_WEAK otError otMessageAppend(otMessage *aMessage, const void *aBuf, uint OT_UNUSED_VARIABLE(aLength); fprintf(stderr, "\n\rWeak otMessageFree() is incorrectly used\n\r"); - exit(1); + DieNow(OT_EXIT_FAILURE); return OT_ERROR_NOT_IMPLEMENTED; } @@ -509,7 +498,7 @@ OT_TOOL_WEAK void otIp4ToIp4MappedIp6Address(const otIp4Address *aIp4Address, ot OT_UNUSED_VARIABLE(aIp6Address); fprintf(stderr, "\n\rWeak otIp4ToIp4MappedIp6Address() is incorrectly used\n\r"); - exit(1); + DieNow(OT_EXIT_FAILURE); } OT_TOOL_WEAK otError otIp4FromIp4MappedIp6Address(const otIp6Address *aIp6Address, otIp4Address *aIp4Address) @@ -518,7 +507,7 @@ OT_TOOL_WEAK otError otIp4FromIp4MappedIp6Address(const otIp6Address *aIp6Addres OT_UNUSED_VARIABLE(aIp4Address); fprintf(stderr, "\n\rWeak otIp4FromIp4MappedIp6Address() is incorrectly used\n\r"); - exit(1); + DieNow(OT_EXIT_FAILURE); return OT_ERROR_NOT_IMPLEMENTED; } @@ -534,7 +523,7 @@ OT_TOOL_WEAK void otPlatMdnsHandleReceive(otInstance *aInstance OT_UNUSED_VARIABLE(aAddress); fprintf(stderr, "\n\rWeak otPlatMdnsHandleReceive() is incorrectly used\n\r"); - exit(1); + DieNow(OT_EXIT_FAILURE); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/examples/platforms/simulation/radio.c b/examples/platforms/simulation/radio.c index acf4bc029d4..6f82210b1f1 100644 --- a/examples/platforms/simulation/radio.c +++ b/examples/platforms/simulation/radio.c @@ -42,6 +42,7 @@ #include #include "simul_utils.h" +#include "lib/platform/exit_code.h" #include "utils/code_utils.h" #include "utils/link_metrics.h" #include "utils/mac_frame.h" @@ -1231,7 +1232,7 @@ void parseFromEnvAsUint16(const char *aEnvName, uint16_t *aValue) if (*endptr != '\0') { fprintf(stderr, "Invalid %s: %s\n", aEnvName, env); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } } } diff --git a/examples/platforms/simulation/simul_utils.c b/examples/platforms/simulation/simul_utils.c index 43a6ac42d27..cae9c00061a 100644 --- a/examples/platforms/simulation/simul_utils.c +++ b/examples/platforms/simulation/simul_utils.c @@ -33,8 +33,22 @@ #include #include +#include "lib/platform/exit_code.h" #include "utils/code_utils.h" +#define ExpectOrExit(aCondition, aExitCode) \ + do \ + { \ + if (!(aCondition)) \ + { \ + const char *start = strrchr(__FILE__, '/'); \ + OT_UNUSED_VARIABLE(start); \ + otLogInfoPlat("%s() at %s:%d: %s", __func__, (start ? start + 1 : __FILE__), __LINE__, \ + otExitCodeToString(aExitCode)); \ + goto exit; \ + } \ + } while (false) + #define UTILS_SOCKET_LOCAL_HOST_ADDR "127.0.0.1" #define UTILS_SOCKET_GROUP_ADDR "224.0.0.116" #define UTILS_SOCKET_GROUP_ADDR6 "ff02::116" @@ -71,13 +85,13 @@ static void InitRxSocket(utilsSocket *aSocket, const struct in_addr *aIp4Address int rval; fd = socket(aIp4Address ? AF_INET : AF_INET6, SOCK_DGRAM, IPPROTO_UDP); - otEXPECT_ACTION(fd != -1, perror("socket(RxFd)")); + ExpectOrExit(fd != -1, OT_EXIT_ERROR_ERRNO); rval = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); - otEXPECT_ACTION(rval != -1, perror("setsockopt(RxFd, SO_REUSEADDR)")); + ExpectOrExit(rval != -1, OT_EXIT_ERROR_ERRNO); rval = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)); - otEXPECT_ACTION(rval != -1, perror("setsockopt(RxFd, SO_REUSEPORT)")); + ExpectOrExit(rval != -1, OT_EXIT_ERROR_ERRNO); if (aIp4Address) { @@ -85,22 +99,22 @@ static void InitRxSocket(utilsSocket *aSocket, const struct in_addr *aIp4Address struct sockaddr_in *sockaddr = &aSocket->mGroupAddr.mSockAddr4; rval = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, aIp4Address, sizeof(*aIp4Address)); - otEXPECT_ACTION(rval != -1, perror("setsockopt(RxFd, IP_MULTICAST_IF)")); + ExpectOrExit(rval != -1, OT_EXIT_ERROR_ERRNO); memset(sockaddr, 0, sizeof(*sockaddr)); sockaddr->sin_family = AF_INET; sockaddr->sin_port = htons(aSocket->mPortBase); - otEXPECT_ACTION(inet_pton(AF_INET, UTILS_SOCKET_GROUP_ADDR, &sockaddr->sin_addr), perror("inet_pton(AF_INET)")); + ExpectOrExit(inet_pton(AF_INET, UTILS_SOCKET_GROUP_ADDR, &sockaddr->sin_addr), OT_EXIT_ERROR_ERRNO); memset(&mreq, 0, sizeof(mreq)); mreq.imr_multiaddr = sockaddr->sin_addr; mreq.imr_address = *aIp4Address; // This address is used to identify the network interface rval = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); - otEXPECT_ACTION(rval != -1, perror("setsockopt(RxFd, IP_ADD_MEMBERSHIP)")); + ExpectOrExit(rval != -1, OT_EXIT_ERROR_ERRNO); rval = bind(fd, (struct sockaddr *)sockaddr, sizeof(*sockaddr)); - otEXPECT_ACTION(rval != -1, perror("bind(RxFd)")); + ExpectOrExit(rval != -1, OT_EXIT_ERROR_ERRNO); } else { @@ -108,24 +122,23 @@ static void InitRxSocket(utilsSocket *aSocket, const struct in_addr *aIp4Address struct sockaddr_in6 *sockaddr = &aSocket->mGroupAddr.mSockAddr6; rval = setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF, &aIfIndex, sizeof(aIfIndex)); - otEXPECT_ACTION(rval != -1, perror("setsockopt(RxFd, IPV6_MULTICAST_IF)")); + ExpectOrExit(rval != -1, OT_EXIT_ERROR_ERRNO); memset(sockaddr, 0, sizeof(*sockaddr)); sockaddr->sin6_family = AF_INET6; sockaddr->sin6_port = htons(aSocket->mPortBase); sockaddr->sin6_scope_id = aIfIndex; // This specifies network interface for link local scope - otEXPECT_ACTION(inet_pton(AF_INET6, UTILS_SOCKET_GROUP_ADDR6, &sockaddr->sin6_addr), - perror("inet_pton(AF_INET6)")); + ExpectOrExit(inet_pton(AF_INET6, UTILS_SOCKET_GROUP_ADDR6, &sockaddr->sin6_addr), OT_EXIT_ERROR_ERRNO); memset(&mreq, 0, sizeof(mreq)); mreq.ipv6mr_multiaddr = sockaddr->sin6_addr; mreq.ipv6mr_interface = aIfIndex; rval = setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)); - otEXPECT_ACTION(rval != -1, perror("setsockopt(RxFd, IPV6_JOIN_GROUP)")); + ExpectOrExit(rval != -1, OT_EXIT_ERROR_ERRNO); rval = bind(fd, (struct sockaddr *)sockaddr, sizeof(*sockaddr)); - otEXPECT_ACTION(rval != -1, perror("bind(RxFd)")); + ExpectOrExit(rval != -1, OT_EXIT_ERROR_ERRNO); } aSocket->mRxFd = fd; @@ -133,7 +146,7 @@ static void InitRxSocket(utilsSocket *aSocket, const struct in_addr *aIp4Address exit: if (aSocket->mRxFd == -1) { - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } } @@ -170,7 +183,7 @@ void InitTxSocketIp6(utilsSocket *aSocket, const struct in6_addr *aAddress, unsi exit: if (aSocket->mTxFd == -1) { - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } } @@ -185,7 +198,7 @@ static void InitTxSocketIp4(utilsSocket *aSocket, const struct in_addr *aAddress // Prepare `mTxFd` fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - otEXPECT_ACTION(fd != -1, perror("socket(TxFd)")); + ExpectOrExit((fd != -1), OT_EXIT_ERROR_ERRNO); memset(&sockaddr, 0, sizeof(sockaddr)); sockaddr.sin_family = AF_INET; @@ -193,20 +206,20 @@ static void InitTxSocketIp4(utilsSocket *aSocket, const struct in_addr *aAddress sockaddr.sin_addr = *aAddress; rval = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF, &sockaddr.sin_addr, sizeof(sockaddr.sin_addr)); - otEXPECT_ACTION(rval != -1, perror("setsockopt(TxFd, IP_MULTICAST_IF)")); + ExpectOrExit((rval != -1), OT_EXIT_ERROR_ERRNO); rval = setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &one, sizeof(one)); - otEXPECT_ACTION(rval != -1, perror("setsockopt(TxFd, IP_MULTICAST_LOOP)")); + ExpectOrExit((rval != -1), OT_EXIT_ERROR_ERRNO); rval = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)); - otEXPECT_ACTION(rval != -1, perror("bind(TxFd)")); + ExpectOrExit((rval != -1), OT_EXIT_ERROR_ERRNO); aSocket->mTxFd = fd; exit: if (aSocket->mTxFd == -1) { - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } } @@ -218,12 +231,11 @@ static bool TryInitSocketIfname(utilsSocket *aSocket, const char *aLocalInterfac struct ifaddrs *ifaddr = NULL; unsigned int ifIndex = 0; - otEXPECT((ifIndex = if_nametoindex(aLocalInterface))); + ExpectOrExit((ifIndex = if_nametoindex(aLocalInterface)), OT_EXIT_ERROR_ERRNO); if (getifaddrs(&ifaddr) == -1) { - perror("getifaddrs"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } for (struct ifaddrs *ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) @@ -268,7 +280,7 @@ static bool TryInitSocketIfname(utilsSocket *aSocket, const char *aLocalInterfac else { fprintf(stderr, "No sock address for TX socket!\n"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } InitRxSocket(aSocket, (addr6 ? NULL : addr4), ifIndex); @@ -284,7 +296,7 @@ static bool TryInitSocketIp4(utilsSocket *aSocket, const char *aLocalInterface) { struct in_addr addr4; - otEXPECT(inet_pton(AF_INET, aLocalInterface, &addr4)); + ExpectOrExit((inet_pton(AF_INET, aLocalInterface, &addr4)), OT_EXIT_ERROR_ERRNO); InitTxSocketIp4(aSocket, &addr4); InitRxSocket(aSocket, &addr4, 0); @@ -300,12 +312,11 @@ static bool TryInitSocketIp6(utilsSocket *aSocket, const char *aLocalInterface) struct in6_addr addr6; struct ifaddrs *ifaddr = NULL; - otEXPECT(inet_pton(AF_INET6, aLocalInterface, &addr6)); + ExpectOrExit((inet_pton(AF_INET6, aLocalInterface, &addr6)), OT_EXIT_ERROR_ERRNO); if (getifaddrs(&ifaddr) == -1) { - perror("getifaddrs"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } for (struct ifaddrs *ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) @@ -327,8 +338,7 @@ static bool TryInitSocketIp6(utilsSocket *aSocket, const char *aLocalInterface) ifIndex = if_nametoindex(ifa->ifa_name); if (ifIndex == 0) { - perror("if_nametoindex"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } InitTxSocketIp6(aSocket, &addr6, ifIndex); @@ -355,7 +365,7 @@ void utilsInitSocket(utilsSocket *aSocket, uint16_t aPortBase) !TryInitSocketIp6(aSocket, gLocalInterface)) { fprintf(stderr, "Failed to simulate node %d on %s\n", gNodeId, gLocalInterface); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } } @@ -432,8 +442,7 @@ uint16_t utilsReceiveFromSocket(const utilsSocket *aSocket, } else if (errno != EINTR && errno != EAGAIN) { - perror("recvfrom(RxFd)"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } return len; @@ -449,7 +458,6 @@ void utilsSendOverSocket(const utilsSocket *aSocket, const void *aBuffer, uint16 if (rval < 0) { - perror("sendto(sTxFd)"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } } diff --git a/examples/platforms/simulation/system.c b/examples/platforms/simulation/system.c index 6483a36f6bd..4855f88c148 100644 --- a/examples/platforms/simulation/system.c +++ b/examples/platforms/simulation/system.c @@ -53,6 +53,7 @@ #include #include "simul_utils.h" +#include "lib/platform/exit_code.h" uint32_t gNodeId = 1; @@ -70,6 +71,7 @@ static void handleSignal(int aSignal) /** * Defines the argument return values. + * */ enum { diff --git a/examples/platforms/simulation/trel.c b/examples/platforms/simulation/trel.c index 696b1a59cab..6f105576917 100644 --- a/examples/platforms/simulation/trel.c +++ b/examples/platforms/simulation/trel.c @@ -316,7 +316,7 @@ void platformTrelInit(uint32_t aSpeedUpFactor) if (*endptr != '\0') { fprintf(stderr, "\r\nInvalid PORT_OFFSET: %s\r\n", str); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } sPortOffset *= (MAX_NETWORK_SIZE + 1); diff --git a/examples/platforms/simulation/uart.c b/examples/platforms/simulation/uart.c index 70d38711882..9cc9c386ebe 100644 --- a/examples/platforms/simulation/uart.c +++ b/examples/platforms/simulation/uart.c @@ -41,6 +41,7 @@ #include #include "simul_utils.h" +#include "lib/platform/exit_code.h" #include "utils/code_utils.h" #include "utils/uart.h" @@ -202,8 +203,7 @@ otError otPlatUartFlush(void) } else { - perror("write(UART)"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } exit: @@ -225,22 +225,19 @@ void platformUartProcess(void) if (rval < 0) { - perror("poll"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } if (rval > 0) { if ((pollfd[0].revents & error_flags) != 0) { - perror("s_in_fd"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } if ((pollfd[1].revents & error_flags) != 0) { - perror("s_out_fd"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } if (pollfd[0].revents & POLLIN) @@ -249,8 +246,7 @@ void platformUartProcess(void) if (rval <= 0) { - perror("read"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } otPlatUartReceived(s_receive_buffer, (uint16_t)rval); @@ -272,8 +268,7 @@ void platformUartProcess(void) } else if (errno != EINTR) { - perror("write"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } } } diff --git a/examples/platforms/simulation/virtual_time/platform-sim.c b/examples/platforms/simulation/virtual_time/platform-sim.c index 1c2c8189494..b387719bd02 100644 --- a/examples/platforms/simulation/virtual_time/platform-sim.c +++ b/examples/platforms/simulation/virtual_time/platform-sim.c @@ -87,7 +87,7 @@ void otSimSendEvent(const struct Event *aEvent) if (rval < 0) { perror("sendto"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } } @@ -99,7 +99,7 @@ static void receiveEvent(otInstance *aInstance) if (rval < 0 || (uint16_t)rval < offsetof(struct Event, mData)) { perror("recvfrom"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } platformAlarmAdvanceNow(event.mDelay); @@ -182,13 +182,13 @@ static void socket_init(void) if (sSockFd == -1) { perror("socket"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } if (bind(sSockFd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) == -1) { perror("bind"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } } @@ -204,7 +204,7 @@ void otSysInit(int argc, char *argv[]) if (argc != 2) { - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } openlog(basename(argv[0]), LOG_PID, LOG_USER); @@ -218,7 +218,7 @@ void otSysInit(int argc, char *argv[]) if (*endptr != '\0' || gNodeId < 1 || gNodeId > MAX_NETWORK_SIZE) { fprintf(stderr, "Invalid NodeId: %s\n", argv[1]); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_FAILURE); } socket_init(); @@ -268,7 +268,7 @@ void otSysProcessDrivers(otInstance *aInstance) if ((rval < 0) && (errno != EINTR)) { perror("select"); - exit(EXIT_FAILURE); + DieNow(OT_EXIT_ERROR_ERRNO); } if (rval > 0 && FD_ISSET(sSockFd, &read_fds))