Commits

Peter Szilagyi committed ce75de8

Handle some signals to remove the omake-server lock file in common cases.

Comments (0)

Files changed (1)

ocaml/omake/top.ml

     let slot_spec () = Command.Spec.( empty +> const slot )
     let main_spec =
       Command.Spec.(
-        step (fun m debug -> 
-          if debug then Omake.debug := true; 
+        step (fun m debug ->
+          if debug then Omake.debug := true;
           m ?foreground:(Some false) ?unlink_lock_file:(Some true)  ())
         ++ empty
         +> flag "-debug" no_arg
     let main _ =
       schedule ~quit:false (fun () ->
         at_exit (fun () -> printf "Hello, world!\n");
+	List.iter Signal.standard ~f:(fun signal ->
+	  (match Core.Std.Signal.default_sys_behavior signal with
+	  | `Continue | `Dump_core | `Ignore | `Stop ->
+	    (* Leave the default signal handler, or at any rate rely on lower level
+	       libraries to do the right thing with this signal. *)
+	    ()
+	  | `Terminate ->
+	    (* Let do_at_exit remove the lock. *)
+	    Signal.handle [signal] ~f:(fun signal ->
+	      Log.printf "Shutting down on %s" (Signal.to_string signal);
+	      shutdown (Signal.to_system_int signal))));
         try_with Server.start >>| function
         | Ok () ->
           Log.printf "Impossible: start_controller returned";