Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable Windows critical error handler #5828

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ users)
## Internal

## Internal: Windows
* Ensure that the system critical error dialog is disabled when opam starts [#5828 @dra27]

## Test

Expand Down
3 changes: 3 additions & 0 deletions src/client/opamCliMain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,9 @@ let json_out () =
(Printexc.to_string e)

let main () =
if Sys.win32 then
(* Disable the critical error handling dialog *)
ignore (OpamStubs.setErrorMode (1 lor OpamStubs.getErrorMode ()));
OpamStd.Sys.at_exit (fun () ->
flush_all_noerror ();
if OpamClientConfig.(!r.print_stats) then (
Expand Down
2 changes: 2 additions & 0 deletions src/core/opamStubs.dummy.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ let getProcessAncestry = that's_a_no_no
let getConsoleAlias _ = that's_a_no_no
let win_create_process _ _ _ _ _ = that's_a_no_no
let getConsoleWindowClass = that's_a_no_no
let setErrorMode = that's_a_no_no
let getErrorMode = that's_a_no_no
6 changes: 6 additions & 0 deletions src/core/opamStubs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,9 @@ val win_create_process : string -> string -> string option -> Unix.file_descr ->
val getConsoleWindowClass : unit -> string option
(** Windows only. Returns the name of the class for the Console window or [None]
if there is no console. *)

val setErrorMode : int -> int
(** Windows only. Directly wraps SetErrorMode. *)

val getErrorMode : unit -> int
(** Windows only. Directly wraps GetErrorMode. *)
2 changes: 2 additions & 0 deletions src/stubs/win32/opamWin32Stubs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ external sendMessageTimeout : nativeint -> int -> int -> 'a -> 'b -> 'c -> int *
external getProcessAncestry : unit -> (int32 * string) list = "OPAMW_GetProcessAncestry"
external getConsoleAlias : string -> string -> string = "OPAMW_GetConsoleAlias"
external getConsoleWindowClass : unit -> string option = "OPAMW_GetConsoleWindowClass"
external setErrorMode : int -> int = "OPAMW_SetErrorMode"
external getErrorMode : unit -> int = "OPAMW_GetErrorMode"
10 changes: 10 additions & 0 deletions src/stubs/win32/opamWindows.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,13 @@ CAMLprim value OPAMW_GetConsoleWindowClass(value unit)

CAMLreturn(result);
}

CAMLprim value OPAMW_SetErrorMode(value mode)
{
return Val_int(SetErrorMode((UINT)Int_val(mode)));
}

CAMLprim value OPAMW_GetErrorMode(value mode)
{
return Val_int(GetErrorMode());
}
Loading