Skip to content

Commit

Permalink
IH-583 Use standalone implementations of systemd functions
Browse files Browse the repository at this point in the history
Use standalone implementations of sd_notify and sd_booted in forkexecd,
networkd, and xcp-rrdd. Additionally, remove unidiomatic ignore usage
and handle failure explicitly instead.

Signed-off-by: Andrii Sultanov <[email protected]>
  • Loading branch information
last-genius committed Jun 21, 2024
1 parent 0bccef1 commit 24f9bda
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 13 deletions.
1 change: 0 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
mtime
ppx_deriving_rpc
rpclib
systemd
(ezxenstore (= :version))
(uuid (= :version))
xapi-backtrace
Expand Down
1 change: 0 additions & 1 deletion ocaml/forkexecd/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
astring
fd-send-recv
forkexec
systemd
uuid
xapi-log
xapi-stdext-unix
Expand Down
10 changes: 6 additions & 4 deletions ocaml/forkexecd/src/fe_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ let setup sock cmdargs id_to_fd_map syslog_stdout redirect_stderr_to_stdout env
Some {Fe.fd_sock_path}
)

let systemd_managed () = try Daemon.booted () with Unix.Unix_error _ -> false

let _ =
Sys.set_signal Sys.sigpipe Sys.Signal_ignore ;

Expand All @@ -63,8 +61,12 @@ let _ =
in
Xapi_stdext_unix.Unixext.mkdir_rec Forkhelpers.temp_dir_server 0o755 ;

if systemd_managed () then
Daemon.notify Daemon.State.Ready |> ignore ;
let module Daemon = Xapi_stdext_unix.Unixext.Daemon in
if Daemon.systemd_booted () then
if Daemon.systemd_notify Daemon.State.Ready then
()
else
warn "Sending systemd notification failed at %s" __LOC__ ;

(* At this point the init.d script should return and we are listening on our socket. *)
while true do
Expand Down
1 change: 0 additions & 1 deletion ocaml/networkd/bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
rpclib.json
result
rresult
systemd
threads.posix
xapi-client
xapi-consts
Expand Down
6 changes: 5 additions & 1 deletion ocaml/networkd/bin/networkd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ let () =
Debug.with_thread_associated "main" start server
)
() ;
ignore (Daemon.notify Daemon.State.Ready) ;
let module Daemon = Xapi_stdext_unix.Unixext.Daemon in
if Daemon.systemd_notify Daemon.State.Ready then
()
else
D.warn "Sending systemd notification failed at %s" __LOC__ ;
while true do
Thread.delay 300. ; Network_server.on_timer ()
done
1 change: 0 additions & 1 deletion ocaml/networkd/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
rpclib.core
rpclib.json
rresult
systemd
threads.posix
uri
xapi-stdext-pervasives
Expand Down
2 changes: 0 additions & 2 deletions ocaml/xcp-rrdd/bin/rrdd/dune
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
rrd-transport
rrd-transport.lib
stunnel
systemd
threads.posix
uuid
xapi-backtrace
Expand Down Expand Up @@ -55,7 +54,6 @@
rpclib.xml
rrdd_libs_internal
rrd-transport
systemd
threads.posix
uuid
xapi-backtrace
Expand Down
7 changes: 6 additions & 1 deletion ocaml/xcp-rrdd/bin/rrdd/xcp_rrdd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,12 @@ let _ =
try Watcher.create_watcher_thread ()
with _ -> error "xenstore-watching thread has failed"
in
ignore (Daemon.notify Daemon.State.Ready) ;
let module Daemon = Xapi_stdext_unix.Unixext.Daemon in
if Daemon.systemd_booted () then
if Daemon.systemd_notify Daemon.State.Ready then
()
else
warn "Sending systemd notification failed at %s" __LOC__ ;
debug "Creating monitoring loop thread .." ;
let () =
try Debug.with_thread_associated "main" monitor_write_loop writers
Expand Down
1 change: 0 additions & 1 deletion xapi-rrdd.opam
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ depends: [
"mtime"
"ppx_deriving_rpc"
"rpclib"
"systemd"
"ezxenstore" {= version}
"uuid" {= version}
"xapi-backtrace"
Expand Down

0 comments on commit 24f9bda

Please sign in to comment.