+let receive_event (listening_socket_spec:fname_and_fd) (_:fname_and_fd) =
+ let (_,listening_socket) = listening_socket_spec in
+ try
+ let (data_socket, _) = accept listening_socket in
+ let (mapping) =
+ try
+ Hashtbl.find unix_socket_table_fd listening_socket
+ with _ -> None in
+ match mapping with
+ |None -> logprint "Received unexpected socket event\n";()
+ |Some (execpath, slice_name) ->
+ begin
+ let child = try fork () with _ -> -1 in
+ if (child == 0) then
+ begin
+ (* Child *)
+ (* Close all fds except for the socket *)
+ let fd = Obj.magic data_socket in
+ let _ =
+ (* Close fds *)
+ for i = 3 to 1023 do
+ if (i != fd) then close_if_open(Obj.magic i)
+ done;
+ execv execpath [|execpath;slice_name;sprintf "%d" fd|];
+ raise Exec_failed
+ (*with
+ Unix_error(num,str1,str2)->logprint "Error %d: %s (%s)" (Obj.magic num) str1 str2;raise (Unix_error(num,str1,str2))*)
+ in
+ logprint "Could not execve %s" execpath
+ end
+ else
+ close_if_open(data_socket)
+ end
+ | None -> ()
+ with e-> logprint "Error accepting socket\n"
+