From ae200df01979325c2dc2a22fbc3fc4bdb74e8f81 Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Tue, 24 Mar 2009 02:32:47 +0000 Subject: [PATCH] --- unixsocketwatcher.ml | 50 +++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/unixsocketwatcher.ml b/unixsocketwatcher.ml index 7525055..8f68d82 100644 --- a/unixsocketwatcher.ml +++ b/unixsocketwatcher.ml @@ -22,28 +22,7 @@ type slice_name = string let unix_socket_table: (control_path_name,(exec_path_name*slice_name*Unix.file_descr) option) Hashtbl.t = Hashtbl.create 1024 -(** Make a pair of fifo entries *) -let mkentry fqp exec_fqp perm slice_name = - logprint "Making control entry %s->%s\n" fqp exec_fqp; - let control_filename=sprintf "%s.control" fqp in - try - let listening_socket = socket PF_UNIX SOCK_STREAM 0 in - (try Unix.unlink control_filename with _ -> ()); - let socket_address = ADDR_UNIX(control_filename) in - bind listening_socket socket_address; - listen listening_socket 10; - ( (* Make the user the owner of the pipes in a non-chroot environment *) - if (!Globals.nochroot) then - let pwentry = Unix.getpwnam slice_name in - Unix.chown control_filename pwentry.pw_uid pwentry.pw_gid - ); - Hashtbl.replace unix_socket_table control_filename (Some(exec_fqp,slice_name,listening_socket)); - Success - with - e->logprint "Error creating FIFO: %s->%s. May be something wrong at the frontend.\n" fqp exec_fqp;Failed - let receive_event (listening_socket_spec:fname_and_fd) (_:fname_and_fd) = - print "Here\n"; let (_,listening_socket) = listening_socket_spec in try let (data_socket, addr) = accept listening_socket in @@ -53,7 +32,7 @@ let receive_event (listening_socket_spec:fname_and_fd) (_:fname_and_fd) = let entry_info = try Hashtbl.find unix_socket_table fname - with _ -> None in + with _ -> logprint "Received unexpected socket event from %s\n" fname;None in match entry_info with | Some(execpath,slice_name,fd) -> begin @@ -62,7 +41,7 @@ let receive_event (listening_socket_spec:fname_and_fd) (_:fname_and_fd) = begin (*Child*) (* Close all fds except for the socket *) - execv execpath,[execpath]; + ignore(execv execpath,[execpath]); logprint "Could not execve %s" execpath end end @@ -70,6 +49,28 @@ let receive_event (listening_socket_spec:fname_and_fd) (_:fname_and_fd) = end | _ -> logprint "Serious error! Got a non UNIX connection over a UNIX socket\n" with e-> logprint "Error accepting socket\n" + +(** Make a pair of fifo entries *) +let mkentry fqp exec_fqp perm slice_name = + logprint "Making control entry %s->%s\n" fqp exec_fqp; + let control_filename=sprintf "%s.control" fqp in + try + let listening_socket = socket PF_UNIX SOCK_STREAM 0 in + (try Unix.unlink control_filename with _ -> ()); + let socket_address = ADDR_UNIX(control_filename) in + bind listening_socket socket_address; + listen listening_socket 10; + ( (* Make the user the owner of the pipes in a non-chroot environment *) + if (!Globals.nochroot) then + let pwentry = Unix.getpwnam slice_name in + Unix.chown control_filename pwentry.pw_uid pwentry.pw_gid + ); + Hashtbl.replace unix_socket_table control_filename (Some(exec_fqp,slice_name,listening_socket)); + Fdwatcher.add_fd (None,listening_socket) (None,listening_socket) receive_event; + Success + with + e->logprint "Error creating FIFO: %s->%s. May be something wrong at the frontend.\n" fqp exec_fqp;Failed + (** Close sockets that just got removed *) let closeentry fqp = @@ -80,12 +81,9 @@ let closeentry fqp = | Some(_,_,fd) -> shutdown fd SHUTDOWN_ALL; close_if_open fd; - Fdwatcher.add_fd (None,fd) (None,fd) receive_event; Hashtbl.remove unix_socket_table control_filename - - let initialize () = () -- 2.43.0