123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263(**
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*)openHack_coreletlog_oc=refNoneletenabled=reftrueletdisable()=enabled:=falseletinitpids_file=assert(!log_oc=None);Sys_utils.with_umask0o111beginfun()->Sys_utils.mkdir_no_fail(Filename.dirnamepids_file);letoc=open_outpids_fileinlog_oc:=Someoc;Unix.(set_close_on_exec(descr_of_out_channeloc))endletlog?reason?(no_fail=false)pid=if!enabledthenletpid=Sys_utils.pid_of_handlepidinletreason=matchreasonwith|None->"unknown"|Somes->sinmatch!log_ocwith|Nonewhenno_fail->()|None->failwith"Can't write pid to uninitialized pids log"|Someoc->Printf.fprintfoc"%d\t%s\n%!"pidreasonexceptionFailedToGetPidsletget_pidspids_file=tryletic=open_inpids_fileinletresults=ref[]inbegintrywhiletruedoletrow=input_lineicinifStr.string_match(Str.regexp"^\\([0-9]+\\)\t\\(.+\\)")row0thenletpid=int_of_string(Str.matched_group1row)inletreason=Str.matched_group2rowinresults:=(pid,reason)::!results;done;withEnd_of_file->()end;close_inic;List.rev!resultswithSys_error_->raiseFailedToGetPidsletclose()=Hack_option.iter!log_oc~f:close_out;log_oc:=None