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;
+ logprint "Could not create %s. Looks like a slice shot itself in the foot\n" fqp;
)
slice_list
| S_REG ->
this#new_script slice_list fqp
| _ ->
- fprintf logfd "Don't know what to do with %s\n" curfile;flush logfd
+ logprint "Don't know what to do with %s\n" curfile
end
end
with _
let check_dir fe =
let (vsysdir,slice) = fe in
let verdict = try Some(Unix.stat vsysdir) with
- _ -> fprintf logfd "vsys directory not setup for slice %s\n" slice;flush logfd;None
+ _ -> logprint "vsys directory not setup for slice %s\n" slice;None
in
match verdict with
| None->false
let read_frontends f =
let setup_ok = if (!Globals.failsafe) then check_dir else fun _ -> true in
- let f_file = try open_in f with e -> fprintf logfd "Could not open config file\n";flush logfd;raise e
+ let f_file = try open_in f with e -> logprint "Could not open config file\n";raise e
in
let rec read_conf_file cur_list =
let next_line = try Some(input_line f_file) with _ -> None in
let openentry_safet fifoin =
let fdin =
try openfile fifoin [O_RDONLY;O_NONBLOCK] 0o777 with
- e->fprintf logfd "Error opening and connecting FIFO: %s,%o\n" fifoin 0o777;flush logfd;raise e
+ e->logprint "Error opening and connecting FIFO: %s,%o\n" fifoin 0o777;raise e
in
fdin
let fqp_out = String.concat "." [fqp;"out"] in
let fifo_fdout =
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
+ _->logprint "%s Output pipe not open, using stdout in place of %s\n" slice_name fqp_out;stdout
in
ignore(sigprocmask SIG_BLOCK [Sys.sigchld]);
(
| Some(pid) ->
if (fifo_fdout <> stdout) then close_if_open fifo_fdout;
Hashtbl.add pidmap pid (fqp_in,fifo_fdout)
- | None ->fprintf logfd "Error executing service: %s\n" execpath;flush logfd;reopenentry fqp_in
+ | None ->logprint "Error executing service: %s\n" execpath;reopenentry fqp_in
);
ignore(sigprocmask SIG_UNBLOCK [Sys.sigchld]);
end
(** Make a pair of fifo entries *)
let mkentry fqp abspath perm uname =
- fprintf logfd "Making entry %s->%s\n" fqp abspath;flush logfd;
+ logprint "Making entry %s->%s\n" fqp abspath;
let fifoin=sprintf "%s.in" fqp in
let fifoout=sprintf "%s.out" fqp in
(try Unix.unlink fifoin with _ -> ());
);
Success
with
- e->fprintf logfd "Error creating FIFO: %s->%s. May be something wrong at the frontend.\n" fqp fifoout;flush logfd;Failed)
+ e->logprint "Error creating FIFO: %s->%s. May be something wrong at the frontend.\n" fqp fifoout;Failed)
(** Close fifos that just got removed *)
let handle_dir_event dirname evlist str =
let fname = String.concat "/" [dirname;str] in
- fprintf logfd "File: %s. " fname;List.iter
- (fun e ->
- fprintf logfd "Event: %s\n" (string_of_event e))
- evlist;
- flush logfd
+ logprint "File: %s. " fname;
+ List.iter
+ (fun e ->
+ logprint "Event: %s\n" (string_of_event e))
+ evlist
let add_watch dir events handler =
- let evcheck = list_check events in
let wd = Inotify.add_watch fd dir events in
Hashtbl.add wdmap wd (dir,Some(handler))
(* Ignore the possibility that the whole directory can disappear and come
let mask_watch fqp =
try
+ print "Masking %s %d\n" fqp (String.length fqp);
Hashtbl.replace masks fqp true
with _ ->
()
Hashtbl.remove masks fqp
end
else
- fprintf logfd "WARNING: %s -- Unpaired unmask\n" fqp;flush logfd
+ logprint "WARNING: %s -- Unpaired unmask\n" fqp
let asciiz s =
let rec findfirstnul str idx len =
try Hashtbl.find wdmap wd with Not_found->("",None)
in
match handler with
- | None->fprintf logfd "Unhandled watch descriptor\n";flush logfd
+ | None->logprint "Unhandled watch descriptor\n"
| Some(handler)->
let fqp = String.concat "/" [dirname;purestr] in
let mask_filter = Hashtbl.mem masks fqp in
- if (not mask_filter) then
- begin
+ begin
+ (*print "Received event for - %s\n"
+ * fqp;*)
+ if ((not mask_filter) && false) then
handler wd dirname evlist purestr
- end
+ else
+ print "%s is masked\n" fqp
+ end
end
| _ -> ())
evs
func evd fd_other
with e->
let wtf = Printexc.to_string e in
- fprintf logfd "%s\n" wtf
+ logprint "%s\n" wtf
) fds
done
Unix.unlink fqp_in;
Unix.unlink fqp_out
with _ ->
- fprintf logfd "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ());flush logfd
+ logprint "Hm. %s disappeared. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
method rmdir rp =
match rp with Relpath(rel) ->
try
Unix.rmdir fqp
with _ ->
- fprintf logfd "Hm. %s disappeared or not empty. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ());flush logfd
+ logprint "Hm. %s disappeared or not empty. Looks like slice %s shot itself in the foot\n" fqp (this#get_slice_name ())
initializer
(
let failsafe = ref false
let logfd = open_out_gen [Open_append;Open_creat] 0o644 !log_filepath
+let logprint fmt = Printf.fprintf logfd (fmt ^^ "%!")
+let print fmt = Printf.printf (fmt ^^ "%!")
+
type result = Success | Failed
type fname_and_fd = string option * Unix.file_descr
]
let _ =
- printf "Starting Vsys v%s\n" Globals.vsys_version;flush stdout;
- fprintf logfd "Starting Vsys v%s\n" Globals.vsys_version;flush logfd;
+ logprint "Starting Vsys v%s\n" Globals.vsys_version;
+ print "Starting Vsys v%s\n" Globals.vsys_version;
Arg.parse cmdspeclist (fun x->()) "Usage: vsys <list of mount points>";
if (!Globals.backend == "") then
printf "Try vsys --help\n"
begin
if (!daemonize) then
begin
- printf "Daemonizing\n";flush Pervasives.stdout;
+ print "Daemonizing\n";
let child = Unix.fork () in
if (child <> 0) then
begin
let felst = List.map
(fun lst->let (x,y)=lst in
- fprintf logfd "Slice %s (%s)\n" x y;
- flush logfd;
+ logprint "Slice %s (%s)\n" x y;
new frontendHandler lst)
!input_file_list in
let _ = new backendHandler !Globals.backend felst in