From a089c4ea3221ae8a21ccee5fbe51141713ec92ea Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 18 Mar 2021 19:05:51 -0400 Subject: [PATCH] [host] service: introduce fatal errors for ivshmem failures Also for failure to parse command line. For these errors, restarting with exponential backoff will not help: no amount of restarting the service could possibly make the ivshmem device exist or larger, so we shouldn't try. --- host/include/interface/platform.h | 2 ++ host/platform/Windows/src/service.c | 4 ++++ host/src/app.c | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/host/include/interface/platform.h b/host/include/interface/platform.h index 4331ab44..c9b1beef 100644 --- a/host/include/interface/platform.h +++ b/host/include/interface/platform.h @@ -29,6 +29,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA #define LG_HOST_EXIT_KILLED 0x30 // exit code for failed to start #define LG_HOST_EXIT_FAILED 0x40 +// exit code for failed to start, and no amount of restarting could help +#define LG_HOST_EXIT_FATAL 0x50 int app_main(int argc, char * argv[]); bool app_init(); diff --git a/host/platform/Windows/src/service.c b/host/platform/Windows/src/service.c index ea355158..b5a3970f 100644 --- a/host/platform/Windows/src/service.c +++ b/host/platform/Windows/src/service.c @@ -717,6 +717,10 @@ VOID WINAPI SvcMain(DWORD dwArgc, LPTSTR *lpszArgv) break; } + case LG_HOST_EXIT_FATAL: + doLog("Host application failed to start with fatal error; will not restart\n"); + goto stopped; + default: doLog("Host application failed due to unknown error; restarting\n"); break; diff --git a/host/src/app.c b/host/src/app.c index fdc752e7..7f092117 100644 --- a/host/src/app.c +++ b/host/src/app.c @@ -440,7 +440,7 @@ int app_main(int argc, char * argv[]) { option_free(); DEBUG_ERROR("Failed to get the application's data path"); - return LG_HOST_EXIT_FAILED; + return LG_HOST_EXIT_FATAL; } const size_t len = strlen(dataPath) + sizeof(CONFIG_FILE) + 1; @@ -457,18 +457,18 @@ int app_main(int argc, char * argv[]) { option_free(); DEBUG_ERROR("Failure to parse the command line"); - return LG_HOST_EXIT_FAILED; + return LG_HOST_EXIT_FATAL; } if (!option_validate()) { option_free(); - return LG_HOST_EXIT_FAILED; + return LG_HOST_EXIT_FATAL; } // perform platform specific initialization if (!app_init()) - return LG_HOST_EXIT_FAILED; + return LG_HOST_EXIT_FATAL; DEBUG_INFO("Looking Glass Host (%s)", BUILD_VERSION); @@ -476,13 +476,13 @@ int app_main(int argc, char * argv[]) if (!ivshmemInit(&shmDev)) { DEBUG_ERROR("Failed to find the IVSHMEM device"); - return LG_HOST_EXIT_FAILED; + return LG_HOST_EXIT_FATAL; } if (!ivshmemOpen(&shmDev)) { DEBUG_ERROR("Failed to open the IVSHMEM device"); - return LG_HOST_EXIT_FAILED; + return LG_HOST_EXIT_FATAL; } int exitcode = 0; @@ -502,21 +502,21 @@ int app_main(int argc, char * argv[]) sizeof(udata), (uint8_t *)&udata)) != LGMP_OK) { DEBUG_ERROR("lgmpHostInit Failed: %s", lgmpStatusString(status)); - exitcode = LG_HOST_EXIT_FAILED; + exitcode = LG_HOST_EXIT_FATAL; goto fail_ivshmem; } if ((status = lgmpHostQueueNew(app.lgmp, FRAME_QUEUE_CONFIG, &app.frameQueue)) != LGMP_OK) { DEBUG_ERROR("lgmpHostQueueCreate Failed (Frame): %s", lgmpStatusString(status)); - exitcode = LG_HOST_EXIT_FAILED; + exitcode = LG_HOST_EXIT_FATAL; goto fail_lgmp; } if ((status = lgmpHostQueueNew(app.lgmp, POINTER_QUEUE_CONFIG, &app.pointerQueue)) != LGMP_OK) { DEBUG_ERROR("lgmpHostQueueNew Failed (Pointer): %s", lgmpStatusString(status)); - exitcode = LG_HOST_EXIT_FAILED; + exitcode = LG_HOST_EXIT_FATAL; goto fail_lgmp; } @@ -525,7 +525,7 @@ int app_main(int argc, char * argv[]) if ((status = lgmpHostMemAlloc(app.lgmp, MAX_POINTER_SIZE, &app.pointerMemory[i])) != LGMP_OK) { DEBUG_ERROR("lgmpHostMemAlloc Failed (Pointer): %s", lgmpStatusString(status)); - exitcode = LG_HOST_EXIT_FAILED; + exitcode = LG_HOST_EXIT_FATAL; goto fail_lgmp; } memset(lgmpHostMemPtr(app.pointerMemory[i]), 0, MAX_POINTER_SIZE); @@ -535,7 +535,7 @@ int app_main(int argc, char * argv[]) if ((status = lgmpHostMemAlloc(app.lgmp, MAX_POINTER_SIZE, &app.pointerShape)) != LGMP_OK) { DEBUG_ERROR("lgmpHostMemAlloc Failed (Pointer Shape): %s", lgmpStatusString(status)); - exitcode = LG_HOST_EXIT_FAILED; + exitcode = LG_HOST_EXIT_FATAL; goto fail_lgmp; } @@ -550,7 +550,7 @@ int app_main(int argc, char * argv[]) if ((status = lgmpHostMemAllocAligned(app.lgmp, app.maxFrameSize, sz, &app.frameMemory[i])) != LGMP_OK) { DEBUG_ERROR("lgmpHostMemAlloc Failed (Frame): %s", lgmpStatusString(status)); - exitcode = LG_HOST_EXIT_FAILED; + exitcode = LG_HOST_EXIT_FATAL; goto fail_lgmp; } }