1 (* frontend.ml: Routines that implement frontend actions, such as creating directories in a slice, creating pipes etc. *)
9 (** frontendhandler class: Methods to create and unlink pipes and directories
10 @param root_dir vsys directory inside a slice
11 @param slice_name actual slice name - set with care, since the acl functionality refers to these names *)
12 class frontendHandler (root_dir,slice_name) =
15 (** regex indicating that the script passes fds around *)
16 val fd_regex = Str.regexp "fd_"
18 method is_fd_passer fname =
19 try let _ = Str.search_forward fd_regex fname 0
26 method get_slice_name () = slice_name
27 (** A new script was copied into the backend, make a corresponding entry in
29 @param rp Relative path of the entry in the backend
30 @param abspath Absolute path of the entry
31 @param perm Permissions of the entry at the frontend *)
32 method mkentry (rp:relpath) abspath perm =
33 let realperm = perm land (lnot 0o111) in
34 match rp with Relpath(rel) ->
35 let fqp = String.concat "/" [root_dir;rel] in
36 if (this#is_fd_passer rel) then
37 let res = Unixsocketwatcher.mkentry fqp abspath realperm slice_name in
43 logprint "Could not create entry %s" abspath
46 let res = Directfifowatcher.mkentry fqp abspath realperm slice_name in
50 Directfifowatcher.openentry root_dir fqp (abspath,slice_name)
52 logprint "Could not create entry %s" abspath
58 (** A new directory was created at the backend, make a corresponding directory
59 at the frontend. Refer to mkentry for parameters *)
60 method mkdir rp perm =
61 match rp with Relpath(rel) ->
62 let fqp = String.concat "/" [root_dir;rel] in
64 let s = Unix.stat fqp in
65 if (s.st_kind<>S_DIR) then
70 else if (s.st_perm <> perm) then
75 with Unix.Unix_error(_,_,_) ->
77 Directfifowatcher.add_dir_watch fqp
79 (** Functions corresponding to file deletion/directory removal *)
83 match rp with Relpath(rel) ->
84 let fqp = String.concat "/" [root_dir;rel] in
85 let fqp_in = String.concat "." [fqp;"in"] in
86 let fqp_out = String.concat "." [fqp;"out"] in
87 let fqp_control = String.concat "." [fqp;"out"] in
89 if (this#is_fd_passer rel) then
91 Unixsocketwatcher.closeentry fqp;
93 Unix.unlink fqp_control
95 logprint "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
99 Directfifowatcher.closeentry fqp;
104 logprint "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
108 match rp with Relpath(rel) ->
109 let fqp = String.concat "/" [root_dir;rel] in
110 Directfifowatcher.del_dir_watch fqp;
114 logprint "Hm. %s disappeared or not empty. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
119 let s = Unix.stat root_dir in
120 if (s.st_kind<>S_DIR) then
122 Unix.unlink root_dir;
123 Unix.mkdir root_dir 0o700
125 else if (s.st_perm <> 0o700) then
128 Unix.mkdir root_dir 0o700
130 with Unix.Unix_error(_,_,_) ->
133 Unix.mkdir root_dir 0o700;
136 Directfifowatcher.add_dir_watch root_dir