(fun frontend->
try begin
frontend#mkdir (mk_rel_path fqp) (s.st_perm);
- Dirwatcher.add_watch fqp [S_Create;S_Delete] (Some(func))
+ Dirwatcher.add_watch fqp [S_Create;S_Delete] func
end
with _ ->
fprintf logfd "Could not create %s. Looks like a slice shot itself in the foot\n" fqp;flush logfd;
@param evlist Description of what happened
@param fname Name of the file that the event applies to
*)
- method handle_dir_event dirname evlist fname =
+ method handle_dir_event _ dirname evlist fname =
let fqp = String.concat "/" [dirname;fname] in
if ((Str.string_match file_regexp fname 0) && not (Str.string_match acl_file_regexp fname 0)) then
begin
in
begin
build_initial_tree dir_root;
- Dirwatcher.add_watch dir_root [S_Create;S_Delete] (Some(this#handle_dir_event));
+ Dirwatcher.add_watch dir_root [S_Create;S_Delete] (this#handle_dir_event);
end
end
-(** fifowatcher.ml: Routines to handle non-persistent scripts *)
+(** directfifowatcher.ml: Routines to handle non-persistent scripts *)
+(* Semantics:
+ * - The 'out' descriptor must be opened first
+ * - As soon as the backend script dies, the connection to the entry is
+ * closed.
+ *)
open Inotify
open Unix
| [] -> false
| car::cdr -> if (car==elt) then true else list_check cdr elt
-
-
-
(* vsys is activated when a client opens an in file *)
-let connect_file fqp_in =
+let connect_file mask_events fqp_out =
(* Do we care about this file? *)
let entry_info = try
- Hashtbl.find direct_fifo_table fqp_in with _ -> fprintf logfd "[Alert] Access via unauthorized vsys entry: %s\n" fqp_in;flush logfd;None in
+ Hashtbl.find direct_fifo_table fqp_out with _ -> None in
match entry_info with
| Some(execpath,slice_name) ->
fprintf logfd "Executing %s for slice %s\n" execpath slice_name;flush logfd;
begin
- let len = String.length fqp_in in
- let fqp = String.sub fqp_in 0 (len-3) in
- let fqp_out = String.concat "." [fqp;"out"] in
+ let len = String.length fqp_out in
+ let fqp = String.sub fqp_out 0 (len-4) in
+ mask_events true;
+ let fqp_in = String.concat "." [fqp;"in"] in
let fifo_fdin =
try openfile fqp_in [O_RDONLY;O_NONBLOCK] 0o777 with
e->fprintf logfd "Error opening and connecting FIFO: %s\n" fqp_in;flush logfd;raise e
try openfile fqp_out [O_WRONLY;O_NONBLOCK] 0o777 with
_->fprintf logfd "%s Output pipe not open, using stdout in place of %s\n" slice_name fqp_out;flush logfd;stdout
in
- try ignore(create_process execpath [|execpath;slice_name|] fifo_fdin fifo_fdout fifo_fdout) with e -> fprintf logfd "Error executing service: %s\n" execpath;flush logfd
+ try ignore(create_process execpath [|execpath;slice_name|] fifo_fdin fifo_fdout fifo_fdout); with e -> begin fprintf logfd "Error executing service: %s\n" execpath;flush logfd end;
+ close fifo_fdin;
+ close fifo_fdout;
+ mask_events false;
end
| None -> ()
(** Open fifos for a session. SHOULD NOt shutdown vsys if the fifos don't exist *)
let openentry fqp backend_spec =
- let fqp_in = String.concat "." [fqp;"in"] in
+ let fqp_in = String.concat "." [fqp;"out"] in
Hashtbl.replace direct_fifo_table fqp_in (Some(backend_spec))
(** Close fifos that just got removed *)
let closeentry fqp =
- let fqp_in = String.concat "." [fqp;"in"] in
+ let fqp_in = String.concat "." [fqp;"out"] in
Hashtbl.remove direct_fifo_table fqp_in
-let direct_fifo_handler dirname evlist fname =
- printf "Received event %s %s\n" dirname fname;flush Pervasives.stdout;
+let direct_fifo_handler wd dirname evlist fname =
+ let mask_events flag =
+ if (flag) then Dirwatcher.mask_events wd else Dirwatcher.unmask_events wd
+ in
let is_event = list_check evlist in
if (is_event Open) then
- let fqp_in = String.concat "/" [dirname;fname] in
- connect_file fqp_in
+ let fqp_out = String.concat "/" [dirname;fname] in
+ connect_file mask_events fqp_out
let add_dir_watch fqp =
- Dirwatcher.add_watch fqp [S_Open] (Some(direct_fifo_handler))
+ Dirwatcher.add_watch fqp [S_Open] direct_fifo_handler
let del_dir_watch fqp =
(* XXX Dirwatcher.del_watch fqp *)
* leaks - fix implementation of rmdir accordingly
*)
+type 'a handlertype = Nohandler | Activehandler of 'a | Maskedhandler of 'a
+
let wdmap = Hashtbl.create 1024
let fd = Inotify.init ()
flush logfd
let add_watch dir events handler =
- printf "Adding watch for %s\n" dir;flush Pervasives.stdout;
let wd = Inotify.add_watch fd dir events in
- Hashtbl.add wdmap wd (dir,handler)
+ Hashtbl.add wdmap wd (dir,Activehandler(handler))
+
+let mask_events wd =
+ let (dirname,handler) = try Hashtbl.find wdmap wd with Not_found->("",Nohandler)
+ in
+ match handler with
+ | Activehandler(func)->
+ Hashtbl.replace wdmap wd (dirname,Maskedhandler(func))
+ | _ ->
+ ()
+
+let unmask_events wd =
+ let (dirname,handler) = try Hashtbl.find wdmap wd with Not_found->("",Nohandler)
+ in
+ match handler with
+ | Maskedhandler(func)->
+ Hashtbl.replace wdmap wd (dirname,Activehandler(func))
+ | _ ->
+ ()
+
(* XXX
let del_watch dir =
| (wd,evlist,_,Some(str)) ->
let purestr = asciiz(str) in
let (dirname,handler) =
- try Hashtbl.find wdmap wd with Not_found->fprintf logfd "Unknown watch descriptor\n";raise Not_found
+ try Hashtbl.find wdmap wd with Not_found->("",Nohandler)
in
(
match handler with
- | None->handle_dir_event dirname evlist purestr
- | Some(handler)->handler dirname evlist purestr
+ | Nohandler->fprintf logfd "Unhandled watch descriptor\n";flush logfd
+ | Activehandler(handler)->handler wd dirname evlist purestr
+ | Maskedhandler(_)->()
)
| _ -> ())
evs
strcat(inf,".in");
strcat(outf,".out");
- vfd1 = open(inf,O_WRONLY|O_NONBLOCK);
vfd0 = open(outf,O_RDONLY|O_NONBLOCK);
+ printf("Out file: %d\n",vfd0);
+ vfd1 = open(inf,O_WRONLY);
+ printf("In file: %d\n",vfd1);
if (vfd0==-1 || vfd1 == -1) {
- printf("Error opening vsys entry %s\n", argv[1]);
+ printf("Error opening vsys entry %s (%s)\n", argv[1],strerror(errno));
exit(1);
}