1 (* frontend.ml: Routines that implement frontend actions, such as creating directories in a slice, creating pipes etc. *)
8 (** frontendhandler class: Methods to create and unlink pipes and directories
9 @param root_dir vsys directory inside a slice
10 @param slice_name actual slice name - set with care, since the acl functionality refers to these names *)
11 class frontendHandler (root_dir,slice_name) =
14 (** regex indicating that the script passes fds around *)
15 val fd_regex = Str.regexp "^fd_"
17 method is_fd_passer fname = Str.string_match fd_regex fname 0
18 method get_slice_name () = slice_name
19 (** A new script was copied into the backend, make a corresponding entry in
21 @param rp Relative path of the entry in the backend
22 @param abspath Absolute path of the entry
23 @param perm Permissions of the entry at the frontend *)
24 method mkentry (rp:relpath) abspath perm =
25 let realperm = perm land (lnot 0o111) in
26 match rp with Relpath(rel) ->
27 let fqp = String.concat "/" [root_dir;rel] in
28 if (is_fd_passer rel) then
29 let res = Unixsocketwatcher.mkentry fqp abspath realperm slice_name in
33 Unixsocketwatcher.openentry root_dir fqp (abspath, slice_name)
35 logprint "Could not create entry %s" abspath
38 let res = Directfifowatcher.mkentry fqp abspath realperm slice_name in
42 Directfifowatcher.openentry root_dir fqp (abspath,slice_name)
44 logprint "Could not create entry %s" abspath
50 (** A new directory was created at the backend, make a corresponding directory
51 at the frontend. Refer to mkentry for parameters *)
52 method mkdir rp perm =
53 match rp with Relpath(rel) ->
54 let fqp = String.concat "/" [root_dir;rel] in
56 let s = Unix.stat fqp in
57 if (s.st_kind<>S_DIR) then
62 else if (s.st_perm <> perm) then
67 with Unix.Unix_error(_,_,_) ->
69 Directfifowatcher.add_dir_watch fqp
71 (** Functions corresponding to file deletion/directory removal *)
75 match rp with Relpath(rel) ->
76 let fqp = String.concat "/" [root_dir;rel] in
77 let fqp_in = String.concat "." [fqp;"in"] in
78 let fqp_out = String.concat "." [fqp;"out"] in
79 Directfifowatcher.closeentry fqp;
84 logprint "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
87 match rp with Relpath(rel) ->
88 let fqp = String.concat "/" [root_dir;rel] in
89 Directfifowatcher.del_dir_watch fqp;
93 logprint "Hm. %s disappeared or not empty. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
98 let s = Unix.stat root_dir in
99 if (s.st_kind<>S_DIR) then
101 Unix.unlink root_dir;
102 Unix.mkdir root_dir 0o700
104 else if (s.st_perm <> 0o700) then
107 Unix.mkdir root_dir 0o700
109 with Unix.Unix_error(_,_,_) ->
112 Unix.mkdir root_dir 0o700;
115 Directfifowatcher.add_dir_watch root_dir