X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=unixsocketwatcher.ml;h=7663be93f8c9512072df23a0d65fd42d09841d81;hb=0a4a3a68d48188e50ae321557f4527a8dffaf73a;hp=f0e3f5aa46a71152ecf8c3fffca6747f5b6f35e4;hpb=7bc9992d20a4bd829defeba7956415ad38211421;p=vsys.git diff --git a/unixsocketwatcher.ml b/unixsocketwatcher.ml index f0e3f5a..7663be9 100644 --- a/unixsocketwatcher.ml +++ b/unixsocketwatcher.ml @@ -13,6 +13,8 @@ open Globals open Fdwatcher open Printf +exception Exec_failed + let close_if_open fd = (try (ignore(close fd);) with _ -> ()) type control_path_name = string @@ -36,21 +38,27 @@ let receive_event (listening_socket_spec:fname_and_fd) (_:fname_and_fd) = match mapping with |None -> logprint "Received unexpected socket event\n";() |Some (execpath, slice_name) -> - print "Execpath: %s\n" execpath; begin - let child = fork () in + 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 - print "Fd: %d\n" fd; let _ = - execv execpath [|execpath;slice_name;sprintf "%d" fd|] (*with + (* 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"