Fix non-termination problem in embedded mode (win32).

Embedded mode starts a background thread which, under Windows, prevents
the process from exiting on a return from main(). We explicitly
terminate the process instead of returning.
This commit is contained in:
Daniel Beer 2012-10-31 08:52:47 +12:00
parent 5c9648fb23
commit f52fe6f1d4
1 changed files with 20 additions and 7 deletions

View File

@ -386,22 +386,24 @@ int main(int argc, char **argv)
args.devarg.vcc_mv = 3000;
args.devarg.requested_serial = NULL;
if (parse_cmdline_args(argc, argv, &args) < 0)
return -1;
goto fail_parse;
if (args.flags & OPT_EMBEDDED)
input_module = &input_async;
if (input_module->init() < 0)
return -1;
goto fail_input;
output_set_embedded(args.flags & OPT_EMBEDDED);
if (sockets_init() < 0)
return -1;
if (sockets_init() < 0) {
ret = -1;
goto fail_sockets;
}
printc_dbg("%s\n", version_text);
if (setup_driver(&args) < 0) {
sockets_exit();
return -1;
ret = -1;
goto fail_driver;
}
if (device_probe_id(device_default) < 0)
@ -425,10 +427,21 @@ int main(int argc, char **argv)
}
simio_exit();
stab_exit();
device_destroy();
stab_exit();
fail_driver:
sockets_exit();
fail_sockets:
input_module->exit();
fail_input:
fail_parse:
/* We need to do this on Windows, because in embedded mode we
* may still have a running background thread for input. If so,
* returning from main() won't cause the process to terminate.
*/
#if defined(__Windows__) || defined(__CYGWIN__)
ExitProcess(ret);
#endif
return ret;
}