[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
master
Nikos Gorogiannis 5 years ago committed by Facebook Github Bot
parent f298d728c5
commit 5ee59cea23

@ -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}

@ -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

@ -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 () ) ;
()

Loading…
Cancel
Save