@@ -31,10 +31,6 @@ let log_destination = ref "syslog:daemon"
3131
3232let log_level = ref Syslog. Debug
3333
34- let daemon = ref false
35-
36- let have_daemonized () = Unix. getppid () = 1
37-
3834let common_prefix = " org.xen.xapi."
3935
4036let finally f g =
@@ -196,11 +192,6 @@ let common_options =
196192 , (fun () -> ! log_destination)
197193 , " Where to write log messages"
198194 )
199- ; ( " daemon"
200- , Arg. Bool (fun x -> daemon := x)
201- , (fun () -> string_of_bool ! daemon)
202- , " True if we are to daemonise"
203- )
204195 ; ( " disable-logging-for"
205196 , Arg. String
206197 (fun x ->
@@ -552,8 +543,6 @@ let http_handler call_of_string string_of_response process s =
552543 Response. write (fun _t -> () ) response oc
553544 )
554545
555- let ign_int (t : int ) = ignore t
556-
557546let default_raw_fn rpc_fn s =
558547 http_handler Xmlrpc. call_of_string Xmlrpc. string_of_response rpc_fn s
559548
@@ -635,52 +624,6 @@ let serve_forever = function
635624 let rec forever () = Thread. delay 3600. ; forever () in
636625 forever ()
637626
638- let pidfile_write filename =
639- let fd =
640- Unix. openfile filename [Unix. O_WRONLY ; Unix. O_CREAT ; Unix. O_TRUNC ] 0o640
641- in
642- finally
643- (fun () ->
644- let pid = Unix. getpid () in
645- let buf = string_of_int pid ^ " \n " |> Bytes. of_string in
646- let len = Bytes. length buf in
647- if Unix. write fd buf 0 len <> len then
648- failwith " pidfile_write failed"
649- )
650- (fun () -> Unix. close fd)
651-
652- (* Cf Stevens et al, Advanced Programming in the UNIX Environment,
653- Section 13.3 *)
654- let daemonize ?start_fn () =
655- if not (have_daemonized () ) then
656- ign_int (Unix. umask 0 ) ;
657- match Unix. fork () with
658- | 0 -> (
659- if Unix. setsid () == - 1 then failwith " Unix.setsid failed" ;
660- Sys. set_signal Sys. sighup Sys. Signal_ignore ;
661- match Unix. fork () with
662- | 0 ->
663- Option. iter (fun fn -> fn () ) start_fn ;
664- Unix. chdir " /" ;
665- mkdir_rec (Filename. dirname ! pidfile) 0o755 ;
666- pidfile_write ! pidfile ;
667- let nullfd = Unix. openfile " /dev/null" [Unix. O_RDWR ] 0 in
668- Unix. dup2 nullfd Unix. stdin ;
669- Unix. dup2 nullfd Unix. stdout ;
670- Unix. dup2 nullfd Unix. stderr ;
671- Unix. close nullfd
672- | _ ->
673- exit 0
674- )
675- | _ ->
676- exit 0
677-
678- let maybe_daemonize ?start_fn () =
679- if ! daemon then
680- daemonize ?start_fn ()
681- else
682- Option. iter (fun fn -> fn () ) start_fn
683-
684627let cli ~name ~doc ~version ~cmdline_gen =
685628 let default = Term. (ret (const (fun _ -> `Help (`Pager , None )) $ const () )) in
686629 let version =
0 commit comments