From 02069ba128a478464dba41335b55554d6534aec2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Thu, 19 Mar 2020 10:09:03 +0100
Subject: [PATCH] [server] fix signal emission management

---
 src/plugins/server/main.ml   | 4 +++-
 src/plugins/server/states.ml | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/plugins/server/main.ml b/src/plugins/server/main.ml
index fe34558ded9..976f0d47d54 100644
--- a/src/plugins/server/main.ml
+++ b/src/plugins/server/main.ml
@@ -341,6 +341,7 @@ let create ~pretty ?(equal=(=)) ~fetch () =
 (* -------------------------------------------------------------------------- *)
 
 let start server =
+  emitter := do_signal server ;
   match server.daemon with
   | Some _ -> ()
   | None ->
@@ -357,6 +358,7 @@ let start server =
     end
 
 let stop server =
+  emitter := nop ;
   match server.daemon with
   | None -> ()
   | Some daemon ->
@@ -368,6 +370,7 @@ let stop server =
     end
 
 let foreground server =
+  emitter := do_signal server ;
   match server.daemon with
   | None -> ()
   | Some daemon ->
@@ -386,7 +389,6 @@ let run server =
       Sys.catch_break true
     ) ;
     foreground server ;
-    emitter := do_signal server ;
     set_active true ;
     Senv.feedback "Server running." ;
     begin
diff --git a/src/plugins/server/states.ml b/src/plugins/server/states.ml
index 9d3d3976816..8b28add10a6 100644
--- a/src/plugins/server/states.ml
+++ b/src/plugins/server/states.ml
@@ -27,7 +27,7 @@ type 'a callback = ('a -> unit) -> unit
 let install signal hook = function
   | None -> ()
   | Some add_hook ->
-    let once = ref false in
+    let once = ref true in
     let install ok =
       if ok && !once then
         begin
-- 
GitLab