From 29b55a5cae70c270a2b02b0ab25a4674f0ebea5a Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Thu, 30 Jul 2015 07:34:34 +0200 Subject: [PATCH] wineconsole: Consistently return nonzero exitcode on error. --- programs/wineconsole/curses.c | 2 +- programs/wineconsole/user.c | 2 +- programs/wineconsole/wineconsole.c | 32 ++++++++++++++++-------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/programs/wineconsole/curses.c b/programs/wineconsole/curses.c index 2903b80652d..7413c8f00f5 100644 --- a/programs/wineconsole/curses.c +++ b/programs/wineconsole/curses.c @@ -1018,7 +1018,7 @@ static int WCCURSES_MainLoop(struct inner_data* data) WCCURSES_Resize(data); - if (pipe( PRIVATE(data)->sync_pipe ) == -1) return 0; + if (pipe( PRIVATE(data)->sync_pipe ) == -1) return 1; PRIVATE(data)->input_thread = CreateThread( NULL, 0, input_thread, data, 0, &id ); while (!data->dying && WaitForSingleObject(data->hSynchro, INFINITE) == WAIT_OBJECT_0) diff --git a/programs/wineconsole/user.c b/programs/wineconsole/user.c index 5c8c2c0281d..4725ebd31c1 100644 --- a/programs/wineconsole/user.c +++ b/programs/wineconsole/user.c @@ -1382,7 +1382,7 @@ static int WCUSER_MainLoop(struct inner_data* data) * so GetMessage would lead to delayed processing */ while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE)) { - if (msg.message == WM_QUIT) return 0; + if (msg.message == WM_QUIT) return 1; WINE_TRACE("dispatching msg %04x\n", msg.message); DispatchMessageW(&msg); } diff --git a/programs/wineconsole/wineconsole.c b/programs/wineconsole/wineconsole.c index bdd5629dd9a..b8b517a4f07 100644 --- a/programs/wineconsole/wineconsole.c +++ b/programs/wineconsole/wineconsole.c @@ -720,7 +720,7 @@ static struct inner_data* WINECON_Init(HINSTANCE hInst, DWORD pid, LPCWSTR appna * * Spawn the child process when invoked with wineconsole foo bar */ -static BOOL WINECON_Spawn(struct inner_data* data, LPWSTR cmdLine) +static int WINECON_Spawn(struct inner_data* data, LPWSTR cmdLine) { PROCESS_INFORMATION info; STARTUPINFOW startup; @@ -743,20 +743,22 @@ static BOOL WINECON_Spawn(struct inner_data* data, LPWSTR cmdLine) { WINE_ERR("Can't dup handles\n"); /* no need to delete handles, we're exiting the program anyway */ - return FALSE; + return 1; } done = CreateProcessW(NULL, cmdLine, NULL, NULL, TRUE, 0L, NULL, NULL, &startup, &info); + if (done) + { + CloseHandle(info.hProcess); + CloseHandle(info.hThread); + } /* we no longer need the handles passed to the child for the console */ CloseHandle(startup.hStdInput); CloseHandle(startup.hStdOutput); CloseHandle(startup.hStdError); - CloseHandle(info.hProcess); - CloseHandle(info.hThread); - - return done; + return !done; } struct wc_init { @@ -852,9 +854,9 @@ int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdSh { case from_event: /* case of wineconsole , signal process that created us that we're up and running */ - if (!(data = WINECON_Init(hInst, 0, NULL, wci.backend, nCmdShow))) return 0; - ret = SetEvent(wci.event); - if (!ret) WINE_ERR("SetEvent failed.\n"); + if (!(data = WINECON_Init(hInst, 0, NULL, wci.backend, nCmdShow))) return 1; + ret = !SetEvent(wci.event); + if (ret != 0) WINE_ERR("SetEvent failed.\n"); break; case from_process_name: { @@ -865,30 +867,30 @@ int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nCmdSh buffer = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!buffer) - return 0; + return 1; MultiByteToWideChar(CP_ACP, 0, wci.ptr, -1, buffer, len); if (!(data = WINECON_Init(hInst, GetCurrentProcessId(), buffer, wci.backend, nCmdShow))) { HeapFree(GetProcessHeap(), 0, buffer); - return 0; + return 1; } ret = WINECON_Spawn(data, buffer); HeapFree(GetProcessHeap(), 0, buffer); - if (!ret) + if (ret != 0) { WINECON_Delete(data); printf_res(IDS_CMD_LAUNCH_FAILED, wine_dbgstr_a(wci.ptr)); - return 0; + return ret; } } break; default: - return 0; + return 1; } - if (ret) + if (!ret) { WINE_TRACE("calling MainLoop.\n"); ret = data->fnMainLoop(data);