From 3303c09a9d82119cb3fe4be74c7aaf1dee248436 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Nov 2011 19:40:34 +1100 Subject: [PATCH] desktop: exit if loop() doesn't run for 5 seconds this should stop runaway processes --- libraries/Desktop/support/main.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/Desktop/support/main.cpp b/libraries/Desktop/support/main.cpp index ad06f17ebd..8017f45ceb 100644 --- a/libraries/Desktop/support/main.cpp +++ b/libraries/Desktop/support/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "desktop.h" void setup(void); @@ -20,6 +21,12 @@ static void usage(void) printf("\t-w wipe eeprom and dataflash\n"); } +void sig_alarm(int sig) +{ + printf("alarm signal in desktop emulation - loop not running\n"); + exit(1); +} + int main(int argc, char * const argv[]) { int opt; @@ -43,6 +50,9 @@ int main(int argc, char * const argv[]) } } + signal(SIGALRM, sig_alarm); + alarm(5); + // run main setup() function from sketch setup(); @@ -51,6 +61,8 @@ int main(int argc, char * const argv[]) fd_set fds; int fd_high = 0; + alarm(5); + FD_ZERO(&fds); FD_SET(0, &fds); loop();