From 5ee59cea23ab2477ce0bb1f11b038c7e6b89ba5a Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Thu, 5 Sep 2019 10:03:34 -0700 Subject: [PATCH] [sqlite] fix daemon logic in non-forking integrations Summary: In integrations where the capturing process isn't forked off the main Infer process, but launched, eg, via a script pretending to be a compiler, the reference indicating whether the server is running will always be false, and thus such integrations will never try to connect to the write daemon. Fix this by - making `sqlite-write-daemon` authoritative wrt connecting to the daemon. - launching the daemon earlier in the setup process. Reviewed By: jberdine Differential Revision: D17204002 fbshipit-source-id: 23d452fac --- infer/src/base/DBWriter.ml | 16 ++++------------ infer/src/base/DBWriter.mli | 3 +++ infer/src/infer.ml | 16 +++++++++++----- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/infer/src/base/DBWriter.ml b/infer/src/base/DBWriter.ml index 4d2fcc03f..adff68f4c 100644 --- a/infer/src/base/DBWriter.ml +++ b/infer/src/base/DBWriter.ml @@ -293,21 +293,13 @@ module Server = struct send Command.Handshake end -let server_running = ref false +let use_daemon = Config.(sqlite_write_daemon && (not (buck || genrule_mode)) && jobs > 1) -let perform cmd = if !server_running then Server.send cmd else Command.execute cmd +let perform cmd = if use_daemon then Server.send cmd else Command.execute cmd -let start () = - if not !server_running then ( - Server.start () ; - server_running := true ) - - -let stop () = - if !server_running then ( - Server.send Command.Terminate ; - server_running := false ) +let start () = Server.start () +let stop () = Server.send Command.Terminate let replace_attributes ~pname_str ~pname ~akind ~source_file ~attributes ~proc_desc ~callees = Command.ReplaceAttributes {pname_str; pname; akind; source_file; attributes; proc_desc; callees} diff --git a/infer/src/base/DBWriter.mli b/infer/src/base/DBWriter.mli index 344732242..2d3aea8da 100644 --- a/infer/src/base/DBWriter.mli +++ b/infer/src/base/DBWriter.mli @@ -8,6 +8,9 @@ open! IStd +val use_daemon : bool +(** indicates that there should be a daemon running *) + val replace_attributes : pname_str:string -> pname:Sqlite3.Data.t diff --git a/infer/src/infer.ml b/infer/src/infer.ml index 8ac990618..e6ec47bbf 100644 --- a/infer/src/infer.ml +++ b/infer/src/infer.ml @@ -26,6 +26,14 @@ let run driver_mode = let run driver_mode = ScubaLogging.execute_with_time_logging "run" (fun () -> run driver_mode) let setup () = + let db_start = + let already_started = ref false in + fun () -> + if (not !already_started) && CLOpt.is_originator && DBWriter.use_daemon then ( + DBWriter.start () ; + Epilogues.register ~f:DBWriter.stop ~description:"Stop Sqlite write daemon" ; + already_started := true ) + in ( match Config.command with | Analyze -> ResultsDir.assert_results_dir "have you run capture before?" @@ -49,18 +57,16 @@ let setup () = if CLOpt.is_originator && (not Config.continue_capture) && not Driver.(equal_mode driver_mode Analyze) - then SourceFiles.mark_all_stale () + then ( db_start () ; SourceFiles.mark_all_stale () ) | Explore -> ResultsDir.assert_results_dir "please run an infer analysis first" | Events -> ResultsDir.assert_results_dir "have you run infer before?" ) ; + db_start () ; if CLOpt.is_originator then ( RunState.add_run_to_sequence () ; RunState.store () ; - if Config.memcached then Memcached.start () ; - if Config.(sqlite_write_daemon && (not (buck || genrule_mode)) && jobs > 1) then ( - DBWriter.start () ; - Epilogues.register ~f:DBWriter.stop ~description:"Stop Sqlite write daemon" ) ) ; + if Config.memcached then Memcached.start () ) ; ()