[spi-hdlc-adapter] add syslog to record signal (#3966)

This commit is contained in:
Zhanglong Xia
2019-07-09 04:38:23 -07:00
committed by Jonathan Hui
parent d0285164a0
commit 668256290d
+12 -1
View File
@@ -171,6 +171,8 @@ static int sSpiSmallPacketSize = 32; // in bytes
static bool sSlaveDidReset = false;
static int sCaughtSignal = -1;
// If sUseRawFrames is set to true, HDLC encoding/encoding
// is skipped and the raw frames are read-from/written-to
// the sHdlcInputFd/sHdlcOutputFd whole. See `--raw`.
@@ -212,6 +214,7 @@ static void signal_SIGINT(int sig)
// Can't use syslog() because it isn't async signal safe.
// So we write to stderr
IGNORE_RETURN_VALUE(write(STDERR_FILENO, message, sizeof(message) - 1));
sCaughtSignal = sig;
// Restore the previous handler so that if we end up getting
// this signal again we perform the system default action.
@@ -231,6 +234,7 @@ static void signal_SIGTERM(int sig)
// Can't use syslog() because it isn't async signal safe.
// So we write to stderr
IGNORE_RETURN_VALUE(write(STDERR_FILENO, message, sizeof(message) - 1));
sCaughtSignal = sig;
// Restore the previous handler so that if we end up getting
// this signal again we perform the system default action.
@@ -250,6 +254,7 @@ static void signal_SIGHUP(int sig)
// Can't use syslog() because it isn't async signal safe.
// So we write to stderr
IGNORE_RETURN_VALUE(write(STDERR_FILENO, message, sizeof(message) - 1));
sCaughtSignal = sig;
// We don't restore the "previous handler"
// because we always want to let the main
@@ -569,7 +574,8 @@ static int push_pull_spi(void)
if (ret < 0)
{
perror("do_spi_xfer");
perror("push_pull_spi:do_spi_xfer");
syslog(LOG_ERR, "push_pull_spi:do_spi_xfer: errno=%d (%s)", errno, strerror(errno));
// Print out a helpful error message for
// a common error.
@@ -1993,6 +1999,11 @@ int main(int argc, char *argv[])
// SHUTDOWN
bail:
if (sCaughtSignal != -1)
{
syslog(LOG_ERR, "Caught %s", strsignal(sCaughtSignal));
}
syslog(LOG_NOTICE, "Shutdown. (sRet = %d)", sRet);
syslog(LOG_NOTICE, "Reset NCP/RCP");