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
Ensure that restore_terminal
is called on sigint
#151
Conversation
Do we really want |
@ulrikstrid Can you be more precise with your objection? Why wouldn't we want
The only thing I would suggest, perhaps for a separate PR, is to use |
The only other thing I can think of is that |
Actually, if it works, a better approach might be to use |
|
Would it make sense to handle |
Yes, please. |
src/http/http.ml
Outdated
@@ -837,6 +837,16 @@ let run | |||
ignore | |||
in | |||
|
|||
let prev_signal_behavior = ref Sys.Signal_default in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try combining this with the next line with
let rec prev_signal_behavior := Sys.signal ...
Not sure if it will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, that's a syntax error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, I meant
let rec prev_signal_behavior = ref (Sys.signal ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, but is that possible with the new structure?
let prev_signal_behavior = ref Sys.Signal_default in
let handler () = (Sys.Signal_handle (fun signal ->
restore_terminal ();
match !prev_signal_behavior with
| Sys.Signal_default -> exit 1
| Sys.Signal_handle f -> f signal
| Sys.Signal_ignore -> ignore ()
)) in
prev_signal_behavior := Sys.signal Sys.sigint @@ handler ();
prev_signal_behavior := Sys.signal Sys.sigterm @@ handler ();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new structure is incorrect AFAIK, as the derferencing of prev_signal_behavior
is suspended inside closures (fun signal -> ...
), which are only called upon actual reception of signals. By then, the setup code will have assigned prev_signal_behavior
twice, the second time for SIGTERM, completely losing the SIGINT previous behavior, and making both signals behave as the previous behavior of SIGTERM.
By far the easiest way to get this code right (and to make it immediately legible for readers) is to use a local reference for each signal, and you will probably be able to use the rec
in that case, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not exactly sure what you mean by using "a local reference for each signal". It seems to me that the ref has to be passed as an argument to some sort of create_handler
function, no?
let create_handler prev_signal_behavior = (Sys.Signal_handle (fun signal ->
restore_terminal ();
match !prev_signal_behavior with
| Sys.Signal_default -> exit 1
| Sys.Signal_handle f -> f signal
| Sys.Signal_ignore -> ignore ()
)) in
let rec sigint_behavior = ref (Sys.signal Sys.sigint @@ handler sigint_behavior);
Except it looks like this rec is also not possible, I'm getting a compilation error:
This kind of expression is not allowed as right-hand side of `let rec'ocamllsp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the ref
can and really should be created inside the create_handler
function, which guarantees that it will be local to that handler. create_handler
should take a signal number, not a ref to a signal behavior.
Actually, it looks like it's not possible. Setting any handler for
|
Try SIGTERM instead. One or both of us may have confused the signals. SIGKILL is, looking again, the uncatchable one. |
Looks good now, thanks! |
re #93