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 = Str.string_match fd_regex fname 0
19 method get_slice_name () = slice_name
20 (** A new script was copied into the backend, make a corresponding entry in
22 @param rp Relative path of the entry in the backend
23 @param abspath Absolute path of the entry
24 @param perm Permissions of the entry at the frontend *)
25 method mkentry (rp:relpath) abspath perm =
26 let realperm = perm land (lnot 0o111) in
27 match rp with Relpath(rel) ->
28 let fqp = String.concat "/" [root_dir;rel] in
29 if (this#is_fd_passer rel) then
30 let res = Unixsocketwatcher.mkentry fqp abspath realperm slice_name in
36 logprint "Could not create entry %s" abspath
39 let res = Directfifowatcher.mkentry fqp abspath realperm slice_name in
43 Directfifowatcher.openentry root_dir fqp (abspath,slice_name)
45 logprint "Could not create entry %s" abspath
51 (** A new directory was created at the backend, make a corresponding directory
52 at the frontend. Refer to mkentry for parameters *)
53 method mkdir rp perm =
54 match rp with Relpath(rel) ->
55 let fqp = String.concat "/" [root_dir;rel] in
57 let s = Unix.stat fqp in
58 if (s.st_kind<>S_DIR) then
63 else if (s.st_perm <> perm) then
68 with Unix.Unix_error(_,_,_) ->
70 Directfifowatcher.add_dir_watch fqp
72 (** Functions corresponding to file deletion/directory removal *)
76 match rp with Relpath(rel) ->
77 let fqp = String.concat "/" [root_dir;rel] in
78 let fqp_in = String.concat "." [fqp;"in"] in
79 let fqp_out = String.concat "." [fqp;"out"] in
80 let fqp_control = String.concat "." [fqp;"out"] in
82 if (this#is_fd_passer rel) then
84 Unixsocketwatcher.closeentry fqp;
86 Unix.unlink fqp_control
88 logprint "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
92 Directfifowatcher.closeentry fqp;
97 logprint "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
101 match rp with Relpath(rel) ->
102 let fqp = String.concat "/" [root_dir;rel] in
103 Directfifowatcher.del_dir_watch fqp;
107 logprint "Hm. %s disappeared or not empty. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
112 let s = Unix.stat root_dir in
113 if (s.st_kind<>S_DIR) then
115 Unix.unlink root_dir;
116 Unix.mkdir root_dir 0o700
118 else if (s.st_perm <> 0o700) then
121 Unix.mkdir root_dir 0o700
123 with Unix.Unix_error(_,_,_) ->
126 Unix.mkdir root_dir 0o700;
129 Directfifowatcher.add_dir_watch root_dir