mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 23:07:18 +00:00
[host] return a proper exit code
This commit is contained in:
parent
29ea8ecf6b
commit
ad9e84eaaa
@ -21,6 +21,15 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
// exit code for user opted to exit looking-glass-host
|
||||||
|
#define LG_HOST_EXIT_USER 0xfee1dead
|
||||||
|
// exit code for capture errors that should result in a restart, e.g. UAC
|
||||||
|
#define LG_HOST_EXIT_CAPTURE 0xdead0000
|
||||||
|
// exit code for terminated
|
||||||
|
#define LG_HOST_EXIT_KILLED 0xdeadbeef
|
||||||
|
// exit code for failed to start
|
||||||
|
#define LG_HOST_EXIT_FAILED 0xdeadbaad
|
||||||
|
|
||||||
int app_main(int argc, char * argv[]);
|
int app_main(int argc, char * argv[]);
|
||||||
bool app_init();
|
bool app_init();
|
||||||
void app_quit();
|
void app_quit();
|
||||||
|
@ -1,12 +1,3 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
// exit code for user opted to exit looking-glass-host
|
|
||||||
#define LG_HOST_EXIT_USER 0xfee1dead
|
|
||||||
// exit code for capture errors that should result in a restart, e.g. UAC
|
|
||||||
#define LG_HOST_EXIT_CAPTURE 0xdead0000
|
|
||||||
// exit code for terminated
|
|
||||||
#define LG_HOST_EXIT_KILLED 0xdeadbeef
|
|
||||||
// exit code for failed to start
|
|
||||||
#define LG_HOST_EXIT_FAILED 0xdeadbaad
|
|
||||||
|
|
||||||
bool HandleService(int argc, char * argv[]);
|
bool HandleService(int argc, char * argv[]);
|
||||||
|
@ -71,6 +71,8 @@ enum AppState
|
|||||||
|
|
||||||
struct app
|
struct app
|
||||||
{
|
{
|
||||||
|
int exitcode;
|
||||||
|
|
||||||
PLGMPHost lgmp;
|
PLGMPHost lgmp;
|
||||||
|
|
||||||
PLGMPHostQueue pointerQueue;
|
PLGMPHostQueue pointerQueue;
|
||||||
@ -417,7 +419,7 @@ int app_main(int argc, char * argv[])
|
|||||||
{
|
{
|
||||||
option_free();
|
option_free();
|
||||||
DEBUG_ERROR("Failed to get the application's data path");
|
DEBUG_ERROR("Failed to get the application's data path");
|
||||||
return -1;
|
return LG_HOST_EXIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t len = strlen(dataPath) + sizeof(CONFIG_FILE) + 1;
|
const size_t len = strlen(dataPath) + sizeof(CONFIG_FILE) + 1;
|
||||||
@ -434,18 +436,18 @@ int app_main(int argc, char * argv[])
|
|||||||
{
|
{
|
||||||
option_free();
|
option_free();
|
||||||
DEBUG_ERROR("Failure to parse the command line");
|
DEBUG_ERROR("Failure to parse the command line");
|
||||||
return -1;
|
return LG_HOST_EXIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!option_validate())
|
if (!option_validate())
|
||||||
{
|
{
|
||||||
option_free();
|
option_free();
|
||||||
return -1;
|
return LG_HOST_EXIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform platform specific initialization
|
// perform platform specific initialization
|
||||||
if (!app_init())
|
if (!app_init())
|
||||||
return -1;
|
return LG_HOST_EXIT_FAILED;
|
||||||
|
|
||||||
DEBUG_INFO("Looking Glass Host (%s)", BUILD_VERSION);
|
DEBUG_INFO("Looking Glass Host (%s)", BUILD_VERSION);
|
||||||
|
|
||||||
@ -453,13 +455,13 @@ int app_main(int argc, char * argv[])
|
|||||||
if (!ivshmemInit(&shmDev))
|
if (!ivshmemInit(&shmDev))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to find the IVSHMEM device");
|
DEBUG_ERROR("Failed to find the IVSHMEM device");
|
||||||
return -1;
|
return LG_HOST_EXIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ivshmemOpen(&shmDev))
|
if (!ivshmemOpen(&shmDev))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to open the IVSHMEM device");
|
DEBUG_ERROR("Failed to open the IVSHMEM device");
|
||||||
return -1;
|
return LG_HOST_EXIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exitcode = 0;
|
int exitcode = 0;
|
||||||
@ -479,19 +481,22 @@ int app_main(int argc, char * argv[])
|
|||||||
sizeof(udata), (uint8_t *)&udata)) != LGMP_OK)
|
sizeof(udata), (uint8_t *)&udata)) != LGMP_OK)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("lgmpHostInit Failed: %s", lgmpStatusString(status));
|
DEBUG_ERROR("lgmpHostInit Failed: %s", lgmpStatusString(status));
|
||||||
goto fail;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
|
goto fail_ivshmem;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((status = lgmpHostQueueNew(app.lgmp, FRAME_QUEUE_CONFIG, &app.frameQueue)) != LGMP_OK)
|
if ((status = lgmpHostQueueNew(app.lgmp, FRAME_QUEUE_CONFIG, &app.frameQueue)) != LGMP_OK)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("lgmpHostQueueCreate Failed (Frame): %s", lgmpStatusString(status));
|
DEBUG_ERROR("lgmpHostQueueCreate Failed (Frame): %s", lgmpStatusString(status));
|
||||||
goto fail;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
|
goto fail_lgmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((status = lgmpHostQueueNew(app.lgmp, POINTER_QUEUE_CONFIG, &app.pointerQueue)) != LGMP_OK)
|
if ((status = lgmpHostQueueNew(app.lgmp, POINTER_QUEUE_CONFIG, &app.pointerQueue)) != LGMP_OK)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("lgmpHostQueueNew Failed (Pointer): %s", lgmpStatusString(status));
|
DEBUG_ERROR("lgmpHostQueueNew Failed (Pointer): %s", lgmpStatusString(status));
|
||||||
goto fail;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
|
goto fail_lgmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < POINTER_SHAPE_BUFFERS; ++i)
|
for(int i = 0; i < POINTER_SHAPE_BUFFERS; ++i)
|
||||||
@ -499,7 +504,8 @@ int app_main(int argc, char * argv[])
|
|||||||
if ((status = lgmpHostMemAlloc(app.lgmp, MAX_POINTER_SIZE, &app.pointerMemory[i])) != LGMP_OK)
|
if ((status = lgmpHostMemAlloc(app.lgmp, MAX_POINTER_SIZE, &app.pointerMemory[i])) != LGMP_OK)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("lgmpHostMemAlloc Failed (Pointer): %s", lgmpStatusString(status));
|
DEBUG_ERROR("lgmpHostMemAlloc Failed (Pointer): %s", lgmpStatusString(status));
|
||||||
goto fail;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
|
goto fail_lgmp;
|
||||||
}
|
}
|
||||||
memset(lgmpHostMemPtr(app.pointerMemory[i]), 0, MAX_POINTER_SIZE);
|
memset(lgmpHostMemPtr(app.pointerMemory[i]), 0, MAX_POINTER_SIZE);
|
||||||
}
|
}
|
||||||
@ -508,7 +514,8 @@ int app_main(int argc, char * argv[])
|
|||||||
if ((status = lgmpHostMemAlloc(app.lgmp, MAX_POINTER_SIZE, &app.pointerShape)) != LGMP_OK)
|
if ((status = lgmpHostMemAlloc(app.lgmp, MAX_POINTER_SIZE, &app.pointerShape)) != LGMP_OK)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("lgmpHostMemAlloc Failed (Pointer Shape): %s", lgmpStatusString(status));
|
DEBUG_ERROR("lgmpHostMemAlloc Failed (Pointer Shape): %s", lgmpStatusString(status));
|
||||||
goto fail;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
|
goto fail_lgmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
const long sz = sysinfo_getPageSize();
|
const long sz = sysinfo_getPageSize();
|
||||||
@ -522,7 +529,8 @@ int app_main(int argc, char * argv[])
|
|||||||
if ((status = lgmpHostMemAllocAligned(app.lgmp, app.maxFrameSize, sz, &app.frameMemory[i])) != LGMP_OK)
|
if ((status = lgmpHostMemAllocAligned(app.lgmp, app.maxFrameSize, sz, &app.frameMemory[i])) != LGMP_OK)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("lgmpHostMemAlloc Failed (Frame): %s", lgmpStatusString(status));
|
DEBUG_ERROR("lgmpHostMemAlloc Failed (Frame): %s", lgmpStatusString(status));
|
||||||
goto fail;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
|
goto fail_lgmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -548,8 +556,8 @@ int app_main(int argc, char * argv[])
|
|||||||
if (!iface)
|
if (!iface)
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to find a supported capture interface");
|
DEBUG_ERROR("Failed to find a supported capture interface");
|
||||||
exitcode = -1;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
goto fail;
|
goto fail_lgmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG_INFO("Using : %s", iface->getName());
|
DEBUG_INFO("Using : %s", iface->getName());
|
||||||
@ -562,7 +570,7 @@ int app_main(int argc, char * argv[])
|
|||||||
if (!lgCreateTimer(100, lgmpTimer, NULL, &app.lgmpTimer))
|
if (!lgCreateTimer(100, lgmpTimer, NULL, &app.lgmpTimer))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to create the LGMP timer");
|
DEBUG_ERROR("Failed to create the LGMP timer");
|
||||||
goto fail;
|
goto fail_timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(app.state != APP_STATE_SHUTDOWN)
|
while(app.state != APP_STATE_SHUTDOWN)
|
||||||
@ -572,8 +580,8 @@ int app_main(int argc, char * argv[])
|
|||||||
{
|
{
|
||||||
if (!captureStart())
|
if (!captureStart())
|
||||||
{
|
{
|
||||||
exitcode = -1;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
goto exit;
|
goto fail_capture;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -590,8 +598,8 @@ int app_main(int argc, char * argv[])
|
|||||||
{
|
{
|
||||||
if (!captureRestart())
|
if (!captureRestart())
|
||||||
{
|
{
|
||||||
exitcode = -1;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
goto exit;
|
goto finish;
|
||||||
}
|
}
|
||||||
app.state = APP_STATE_RUNNING;
|
app.state = APP_STATE_RUNNING;
|
||||||
}
|
}
|
||||||
@ -617,7 +625,7 @@ int app_main(int argc, char * argv[])
|
|||||||
|
|
||||||
case CAPTURE_RESULT_ERROR:
|
case CAPTURE_RESULT_ERROR:
|
||||||
DEBUG_ERROR("Capture interface reported a fatal error");
|
DEBUG_ERROR("Capture interface reported a fatal error");
|
||||||
exitcode = -1;
|
exitcode = LG_HOST_EXIT_FAILED;
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -627,17 +635,21 @@ int app_main(int argc, char * argv[])
|
|||||||
captureStop();
|
captureStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exitcode = app.exitcode;
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
stopThreads();
|
stopThreads();
|
||||||
|
|
||||||
exit:
|
fail_capture:
|
||||||
lgTimerDestroy(app.lgmpTimer);
|
lgTimerDestroy(app.lgmpTimer);
|
||||||
|
|
||||||
|
fail_timer:
|
||||||
LG_LOCK_FREE(app.pointerLock);
|
LG_LOCK_FREE(app.pointerLock);
|
||||||
|
|
||||||
iface->deinit();
|
iface->deinit();
|
||||||
iface->free();
|
iface->free();
|
||||||
fail:
|
|
||||||
|
|
||||||
|
fail_lgmp:
|
||||||
for(int i = 0; i < LGMP_Q_FRAME_LEN; ++i)
|
for(int i = 0; i < LGMP_Q_FRAME_LEN; ++i)
|
||||||
lgmpHostMemFree(&app.frameMemory[i]);
|
lgmpHostMemFree(&app.frameMemory[i]);
|
||||||
for(int i = 0; i < LGMP_Q_POINTER_LEN; ++i)
|
for(int i = 0; i < LGMP_Q_POINTER_LEN; ++i)
|
||||||
@ -645,6 +657,7 @@ fail:
|
|||||||
lgmpHostMemFree(&app.pointerShape);
|
lgmpHostMemFree(&app.pointerShape);
|
||||||
lgmpHostFree(&app.lgmp);
|
lgmpHostFree(&app.lgmp);
|
||||||
|
|
||||||
|
fail_ivshmem:
|
||||||
ivshmemClose(&shmDev);
|
ivshmemClose(&shmDev);
|
||||||
ivshmemFree(&shmDev);
|
ivshmemFree(&shmDev);
|
||||||
return exitcode;
|
return exitcode;
|
||||||
@ -652,5 +665,6 @@ fail:
|
|||||||
|
|
||||||
void app_quit(void)
|
void app_quit(void)
|
||||||
{
|
{
|
||||||
|
app.exitcode = LG_HOST_EXIT_USER;
|
||||||
app.state = APP_STATE_SHUTDOWN;
|
app.state = APP_STATE_SHUTDOWN;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user