Skip to content

Commit 492afe4

Browse files
committed
Restore default SIGINT behavior after taking snapshot
This feels like a hack, but it works for now pending discussion with async devs. Signed-off-by: Tudor Brindus <[email protected]>
1 parent efe513c commit 492afe4

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/trace.ml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,14 @@ module Make_commands (Backend : Backend_intf.S) = struct
454454
Ptrace.resume pid;
455455
(* Forward ^C to the child, unless it has already exited. *)
456456
let exited_ivar = Ivar.create () in
457-
Async_unix.Signal.handle
458-
~stop:(Ivar.read exited_ivar)
459-
Async_unix.Signal.terminating
460-
~f:(fun signal ->
461-
try
462-
UnixLabels.kill ~pid:(Pid.to_int pid) ~signal:(Signal_unix.to_system_int signal)
463-
with
464-
| Core_unix.Unix_error (_, (_ : string), (_ : string)) ->
465-
(* We raced, but it's OK because the child still exited. *)
466-
());
457+
let stop = Ivar.read exited_ivar in
458+
Async_unix.Signal.handle ~stop Async_unix.Signal.terminating ~f:(fun signal ->
459+
try
460+
UnixLabels.kill ~pid:(Pid.to_int pid) ~signal:(Signal_unix.to_system_int signal)
461+
with
462+
| Core_unix.Unix_error (_, (_ : string), (_ : string)) ->
463+
(* We raced, but it's OK because the child still exited. *)
464+
());
467465
(* [Monitor.try_with] because [waitpid] raises if perf died before we got here. *)
468466
let%bind.Deferred (waitpid_result : (Core_unix.Exit_or_signal.t, exn) result) =
469467
Monitor.try_with (fun () -> Async_unix.Unix.waitpid pid)
@@ -478,6 +476,12 @@ module Make_commands (Backend : Backend_intf.S) = struct
478476
error);
479477
(* This is still a little racey, but it's the best we can do without pidfds. *)
480478
Ivar.fill exited_ivar ();
479+
(* CR-someday tbrindus: [~stop] doesn't make [Async_unix.Signal.handle] restore signal
480+
handlers to their default state, so the decoding step won't be ^C-able. Restore
481+
SIGINT's handler here. Ideally we'd restore all [terminating] handlers to their
482+
default behavior, but I'm not convinced that doesn't break Async and SIGINT is all
483+
we really need. *)
484+
Deferred.upon stop (fun () -> Core.Signal.Expert.set Signal.int `Default);
481485
let%bind () = detach attachment in
482486
return pid
483487
;;
@@ -497,6 +501,7 @@ module Make_commands (Backend : Backend_intf.S) = struct
497501
Async_unix.Signal.handle ~stop [ Signal.int ] ~f:(fun (_ : Signal.t) ->
498502
Core.eprintf "[ Got signal, detaching... ]\n%!";
499503
Ivar.fill_if_empty done_ivar ());
504+
Deferred.upon stop (fun () -> Core.Signal.Expert.set Signal.int `Default);
500505
Core.eprintf "[ Attached. Press Ctrl-C to stop recording. ]\n%!";
501506
let%bind () = stop in
502507
detach attachment

0 commit comments

Comments
 (0)