mirror of
https://github.com/espressif/openthread.git
synced 2026-08-11 13:17:48 +00:00
[posix] handle signals SIGHUP or SIGTERM and exit (#2930)
This commit adds signal handler in posix example platform for signals SIGHUP and SIGTERM. Upon receiving either signal the process is terminated using `exit(0)`.
This commit is contained in:
committed by
Jonathan Hui
parent
44e583a554
commit
c551e30350
@@ -70,6 +70,7 @@ __forceinline void timersub(struct timeval *a, struct timeval *b, struct timeval
|
||||
#include <fcntl.h>
|
||||
#include <netinet/in.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
@@ -57,9 +57,17 @@ uint32_t WELLKNOWN_NODE_ID = 34;
|
||||
|
||||
extern bool gPlatformPseudoResetWasRequested;
|
||||
|
||||
static volatile bool gTerminate = false;
|
||||
|
||||
#ifndef _WIN32
|
||||
int gArgumentsCount = 0;
|
||||
char **gArguments = NULL;
|
||||
|
||||
static void handleSignal(int aSignal)
|
||||
{
|
||||
(void)aSignal;
|
||||
gTerminate = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void PlatformInit(int aArgCount, char *aArgVector[])
|
||||
@@ -85,6 +93,9 @@ void PlatformInit(int aArgCount, char *aArgVector[])
|
||||
|
||||
gArgumentsCount = aArgCount;
|
||||
gArguments = aArgVector;
|
||||
|
||||
signal(SIGTERM, &handleSignal);
|
||||
signal(SIGHUP, &handleSignal);
|
||||
#endif
|
||||
|
||||
NODE_ID = (uint32_t)strtol(aArgVector[1], &endptr, 0);
|
||||
@@ -149,6 +160,11 @@ void PlatformProcessDrivers(otInstance *aInstance)
|
||||
}
|
||||
}
|
||||
|
||||
if (gTerminate)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
platformUartProcess();
|
||||
platformRadioProcess(aInstance);
|
||||
platformAlarmProcess(aInstance);
|
||||
|
||||
Reference in New Issue
Block a user