123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081(************************************************************************)(* * The Coq Proof Assistant / The Coq Development Team *)(* v * Copyright INRIA, CNRS and contributors *)(* <O___,, * (see version control and CREDITS file for authors & dates) *)(* \VV/ **************************************************************)(* // * This file is distributed under the terms of the *)(* * GNU Lesser General Public License Version 2.1 *)(* * (see LICENSE file for the text of the license) *)(************************************************************************)openSpawnletpr_errs=Printf.eprintf"(Spawned,%d) %s\n%!"(Unix.getpid())sletprerr_endlines=ifCDebug.(get_flagmisc)thenbeginpr_errsendelse()typechandescr=AnonPipe|Socketofstring*int*intletopen_bin_connectionhprpw=letopenUnixinlet_,cout=open_connection(ADDR_INET(inet_addr_of_stringh,pr))inletcin,_=open_connection(ADDR_INET(inet_addr_of_stringh,pw))inset_binary_mode_incintrue;set_binary_mode_outcouttrue;letcin=CThread.prepare_in_channel_for_thread_friendly_iocinincin,coutletcontrollerhprpw=prerr_endline"starting controller thread";letmain()=letic,oc=open_bin_connectionhprpwinletloop()=trymatchCThread.thread_friendly_input_valueicwith|Hello_->prerr_endline"internal protocol error";exit1|ReqDie->prerr_endline"death sentence received";exit0with|e->prerr_endline("control channel broken: "^Printexc.to_stringe);exit1inloop()inignore(CThread.createmain())letmain_channel=refNoneletcontrol_channel=refNoneletchannels=refNoneletinit_channels()=if!channels<>NonethenCErrors.anomaly(Pp.str"init_channels called twice.");let()=match!main_channelwith|None->()|Some(Socket(mh,mpr,mpw))->channels:=Some(open_bin_connectionmhmprmpw);|SomeAnonPipe->letstdin=Unix.in_channel_of_descr(Unix.dupUnix.stdin)inletstdout=Unix.out_channel_of_descr(Unix.dupUnix.stdout)inUnix.dup2Unix.stderrUnix.stdout;set_binary_mode_instdintrue;set_binary_mode_outstdouttrue;letstdin=CThread.prepare_in_channel_for_thread_friendly_iostdininchannels:=Some(stdin,stdout);inmatch!control_channelwith|None->()|Some(Socket(ch,cpr,cpw))->controllerchcprcpw|SomeAnonPipe->CErrors.anomaly(Pp.str"control channel cannot be a pipe.")letget_channels()=match!channelswith|None->Printf.eprintf"Fatal error: ideslave communication channels not set.\n";exit1|Some(ic,oc)->ic,ocletprocess_id()=Printf.sprintf"%d:%s:%d"(Unix.getpid())(ifFlags.async_proofs_is_worker()then!Flags.async_proofs_worker_idelse"master")(Thread.id(Thread.self()))