Skip to content

Commit 6af2e71

Browse files
authored
Merge pull request #35 from edwintorok/sockpath
CP-29470: Use a path on tmpfs for temporary sockets and files
2 parents 140df2e + 00de3f7 commit 6af2e71

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/forkhelpers.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ let getpid (_sock, pid) = pid
7070

7171
type 'a result = Success of string * 'a | Failure of string * exn
7272

73+
let temp_dir = "/var/run/nonpersistent/forkexecd/"
74+
7375
(** Creates a temporary file and opens it for logging. The fd is passed to the function
7476
'f'. The logfile is guaranteed to be closed afterwards, and unlinked if either the delete flag is set or the call fails. If the
7577
function 'f' throws an error then the log file contents are read in *)
76-
let with_logfile_fd ?(delete = true) prefix f =
77-
let logfile = Filename.temp_file prefix ".log" in
78+
let with_logfile_fd ?(delete = true) prefix f =
79+
let logfile = Filename.temp_file ~temp_dir prefix ".log" in
7880
let read_logfile () =
7981
let contents = Xapi_stdext_unix.Unixext.string_of_file logfile in
8082
Unix.unlink logfile;

lib/forkhelpers.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,7 @@ type 'a result =
104104
function [f] throws an error then the log file contents are read in *)
105105
val with_logfile_fd : ?delete:bool -> string -> (Unix.file_descr -> 'a) -> 'a result
106106

107+
(** Temporary directory used for communication *)
108+
val temp_dir: string
107109

108110

src/fe_main.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
open Fe_debug
22

33
let setup sock cmdargs id_to_fd_map syslog_stdout redirect_stderr_to_stdout env =
4-
let fd_sock_path = Printf.sprintf "/var/xapi/forker/fd_%s"
4+
let fd_sock_path = Printf.sprintf "%s/fd_%s" Forkhelpers.temp_dir
55
(Uuidm.to_string (Uuidm.create `V4)) in
66
let fd_sock = Fecomms.open_unix_domain_sock () in
77
Xapi_stdext_unix.Unixext.unlink_safe fd_sock_path;
@@ -44,6 +44,7 @@ let _ =
4444
Sys.set_signal Sys.sigpipe (Sys.Signal_ignore);
4545

4646
let main_sock = Fecomms.open_unix_domain_sock_server "/var/xapi/forker/main" in
47+
Xapi_stdext_unix.Unixext.mkdir_rec (Forkhelpers.temp_dir) 0o755;
4748

4849
Daemon.notify Daemon.State.Ready |> ignore;
4950

0 commit comments

Comments
 (0)