From 4085f259a6905e5173ad723460035b5fb73d00a4 Mon Sep 17 00:00:00 2001 From: Selva Nair Date: Sat, 4 Feb 2023 15:04:04 -0500 Subject: [PATCH] On WM_CLOSE do not ask user confirmation - WM_CLOSE is sent if the process is terminated from task manager or by taskkill etc. Waiting for user confirmation in such cases leads to abnormal termination of process leaving behind openvpn.exe, active connections state not saved to the registry etc. CloseApplication() now gets a second argument ask_user. Signed-off-by: Selva Nair --- main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index 9a742a4..bce2596 100644 --- a/main.c +++ b/main.c @@ -63,7 +63,7 @@ /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); static void ShowSettingsDialog(); -void CloseApplication(HWND hwnd); +void CloseApplication(HWND hwnd, BOOL ask_user); void ImportConfigFileFromDisk(); void ImportConfigFromAS(); static void SaveAutoRestartList(); @@ -456,7 +456,7 @@ HandleCopyDataMessage(const COPYDATASTRUCT *copy_data) } else if(copy_data->dwData == WM_OVPN_EXIT) { - CloseApplication(o.hWnd); + CloseApplication(o.hWnd, true); } else if(copy_data->dwData == WM_OVPN_IMPORT && str) { @@ -628,7 +628,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM ShowSettingsDialog(); } else if (LOWORD(wParam) == IDM_CLOSE) { - CloseApplication(hwnd); + CloseApplication(hwnd, true); } /* rest of the handlers require a connection id */ else { @@ -670,7 +670,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM break; case WM_CLOSE: - CloseApplication(hwnd); + CloseApplication(hwnd, false); /* do not wait for user confirmation */ break; case WM_DESTROY: @@ -844,10 +844,10 @@ ShowSettingsDialog() void -CloseApplication(HWND hwnd) +CloseApplication(HWND hwnd, BOOL ask_user) { /* Show a message if any non-persistent connections are active */ - for (connection_t *c = o.chead; c; c = c->next) + for (connection_t *c = o.chead; c && ask_user; c = c->next) { if (c->state == disconnected || c->flags & FLAG_DAEMON_PERSISTENT)