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 let res = Directfifowatcher.mkentry fqp abspath realperm slice_name in
32 Directfifowatcher.openentry root_dir fqp (abspath,slice_name)
34 logprint "Could not create entry %s" abspath
36 if (is_fd_passer rel) then
37 let res = Unixsocketwatcher.mkentry fqp abspath realperm slice_name in
41 Unixsocketwatcher.openentry root_dir fqp (abspath, slice_name)
43 logprint "Could not create entry %s" abspath
49 (** A new directory was created at the backend, make a corresponding directory
50 at the frontend. Refer to mkentry for parameters *)
51 method mkdir rp perm =
52 match rp with Relpath(rel) ->
53 let fqp = String.concat "/" [root_dir;rel] in
55 let s = Unix.stat fqp in
56 if (s.st_kind<>S_DIR) then
61 else if (s.st_perm <> perm) then
66 with Unix.Unix_error(_,_,_) ->
68 Directfifowatcher.add_dir_watch fqp
70 (** Functions corresponding to file deletion/directory removal *)
74 match rp with Relpath(rel) ->
75 let fqp = String.concat "/" [root_dir;rel] in
76 let fqp_in = String.concat "." [fqp;"in"] in
77 let fqp_out = String.concat "." [fqp;"out"] in
78 Directfifowatcher.closeentry fqp;
83 logprint "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
86 match rp with Relpath(rel) ->
87 let fqp = String.concat "/" [root_dir;rel] in
88 Directfifowatcher.del_dir_watch fqp;
92 logprint "Hm. %s disappeared or not empty. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
97 let s = Unix.stat root_dir in
98 if (s.st_kind<>S_DIR) then
100 Unix.unlink root_dir;
101 Unix.mkdir root_dir 0o700
103 else if (s.st_perm <> 0o700) then
106 Unix.mkdir root_dir 0o700
108 with Unix.Unix_error(_,_,_) ->
111 Unix.mkdir root_dir 0o700;
114 Directfifowatcher.add_dir_watch root_dir