- let (_,listening_socket) = listening_socket_spec in
- try
- let (data_socket, addr) = accept listening_socket in
- match addr with
- | ADDR_UNIX(fname) ->
- begin
- let entry_info =
- try
- Hashtbl.find unix_socket_table fname
- with _ -> logprint "Received unexpected socket event from %s\n" fname;None in
- match entry_info with
- | Some(execpath,slice_name,fd) ->
- begin
- let child = fork () in
- if (child == 0) then
- begin
- (*Child*)
- (* Close all fds except for the socket *)
- ignore(execv execpath,[execpath]);
- logprint "Could not execve %s" execpath
- end
- end
- | None -> ()
- end
- | _ -> logprint "Serious error! Got a non UNIX connection over a UNIX socket\n"
- with e-> logprint "Error accepting socket\n"
+ 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"