+ | (LibXsltErrorMsg _) as msg -> logger#logBold (string_of_xslt_msg msg)
+ | (LibXsltDebugMsg _) as msg -> logger#logEmph (string_of_xslt_msg msg))
+ libxslt_logger#msgs
+;;
+
+ (* LibXSLT logger *)
+let veillogger = new Uwobo_common.libXsltLogger ;;
+
+ (* start_new_session cmd_pipe_exit res_pipe_entrance outchan port logfile
+ @param cmd_pipe Pipe to be closed before forking
+ @param res_pipe Pipe to be closed before forking
+ @param outchan To be closed before forking
+ @param port The port to be used
+ @param logfile The logfile to redirect the stdout and sterr to
+ *)
+ (* It can raise Failure "Connection refused" *)
+ (* It can raise Failure "Port already in use" *)
+let start_new_session cmd_pipe res_pipe outchan port logfile =
+ let environment =
+ (* Here I am loosing the current value of port_env_var; *)
+ (* this should not matter *)
+ Unix.putenv port_env_var (string_of_int port) ;
+ Unix.environment ()
+ in
+ (* Let's check that the port is free *)
+ (try
+ ignore
+ (Http_client.Convenience.http_head_message
+ ("http://127.0.0.1:" ^ string_of_int port ^ "/help")) ;
+ raise (Failure "Port already in use")
+ with
+ Failure "Connection refused" -> ()
+ ) ;
+ match Unix.fork () with
+ 0 ->
+ Unix.handle_unix_error
+ (function () ->
+ (* 1. We close all the open pipes to avoid duplicating them *)
+ Unix.close (Unix.descr_of_out_channel cmd_pipe) ;
+ Unix.close (Unix.descr_of_in_channel res_pipe) ;
+ Unix.close (Unix.descr_of_out_channel outchan) ;
+ (* 2. We redirect stdout and stderr to the logfile *)
+ Unix.close Unix.stdout ;
+ assert
+ (Unix.openfile logfile [Unix.O_WRONLY ; Unix.O_APPEND ; Unix.O_CREAT]
+ 0o664 = Unix.stdout) ;
+ Unix.close Unix.stderr ;
+ assert
+ (Unix.openfile logfile [Unix.O_WRONLY ; Unix.O_APPEND ; Unix.O_CREAT]
+ 0o664 = Unix.stderr) ;
+ prerr_endline "***** Starting a new session" ;
+ (* 3. We exec a new copy of uwobo *)
+ Unix.execve Sys.executable_name [||] environment ;
+ (* It should never reach this point *)
+ assert false
+ ) ()
+ | child when child > 0 ->
+ (* let's check if the new UWOBO started correctly *)
+ Unix.sleep 5 ;
+ (* It can raise Failure "Connection refused" *)
+ ignore
+ (Http_client.Convenience.http_head_message
+ ("http://127.0.0.1:" ^ string_of_int port ^ "/help"))
+ | _ -> failwith "Can't fork :-("