From e6b2f0774b71683b4a970ce64c96e6d31f11e488 Mon Sep 17 00:00:00 2001 From: David Scott Date: Mon, 20 May 2013 12:41:58 +0000 Subject: [PATCH] Update to use new switch-capable xcp-idl --- networkd/networkd.ml | 59 ++++++++++---------------------------------- 1 file changed, 13 insertions(+), 46 deletions(-) diff --git a/networkd/networkd.ml b/networkd/networkd.ml index ebfb0ac53..38ed7f949 100644 --- a/networkd/networkd.ml +++ b/networkd/networkd.ml @@ -12,8 +12,6 @@ * GNU Lesser General Public License for more details. *) -let name = "xcp-networkd" - open Pervasiveext open Fun open Network_utils @@ -21,40 +19,8 @@ open Network_utils module D = Debug.Debugger(struct let name = "networkd" end) open D -let server = Http_svr.Server.empty () - -let path = Filename.concat "/var/lib/xcp" name - module Server = Network_interface.Server(Network_server) -let xmlrpc_handler process req bio context = - let body = Http_svr.read_body req bio in - let s = Buf_io.fd_of bio in - let rpc = Xmlrpc.call_of_string body in - try - let result = process context rpc in - let str = Xmlrpc.string_of_response result in - Http_svr.response_str req s str - with e -> - debug "Caught %s" (Printexc.to_string e); - debug "Backtrace: %s" (Printexc.get_backtrace ()); - Http_svr.response_unauthorised ~req (Printf.sprintf "Go away: %s" (Printexc.to_string e)) s - -let start_server path process = - Http_svr.Server.add_handler server Http.Post "/" (Http_svr.BufIO (xmlrpc_handler process)); - - debug "Listening on %s" path; - Unixext.mkdir_safe (Filename.dirname path) 0o700; - Unixext.unlink_safe path; - let domain_sock = Http_svr.bind (Unix.ADDR_UNIX(path)) "unix_rpc" in - Http_svr.start server domain_sock; - - let localhost = Unix.inet_addr_of_string "127.0.0.1" in - let localhost_sock = Http_svr.bind (Unix.ADDR_INET(localhost, 4094)) "inet-RPC" in - Http_svr.start server localhost_sock; - - () - let resources = [ { Xcp_service.name = "brctl"; description = "used to set up bridges"; @@ -70,10 +36,13 @@ let resources = [ } ] -let start () = +let start server = Network_monitor_thread.start (); Network_server.on_startup (); - start_server path Server.process + let (_: Thread.t) = Thread.create (fun () -> + Xcp_service.serve_forever server + ) () in + () let stop signal = Network_server.on_shutdown signal; @@ -86,12 +55,15 @@ let handle_shutdown () = Sys.set_signal Sys.sigpipe Sys.Signal_ignore let _ = - let pidfile = ref "" in Xcp_service.configure ~resources (); - if !Xcp_service.daemon then begin - Xcp_service.daemonize (); - end; + let server = Xcp_service.make + ~path:!Network_interface.default_path + ~queue_name:!Network_interface.queue_name + ~rpc_fn:(Server.process ()) + () in + + Xcp_service.maybe_daemonize (); Debug.set_facility Syslog_transitional.Local5; @@ -99,12 +71,7 @@ let _ = Debug.disable "http"; handle_shutdown (); - Debug.with_thread_associated "main" start (); - - if !pidfile <> "" then begin - Unixext.mkdir_rec (Filename.dirname !pidfile) 0o755; - Unixext.pidfile_write !pidfile; - end; + Debug.with_thread_associated "main" start server; while true do Thread.delay 300.;