let (_,ifd) = idesc in
let cp = try Hashtbl.find open_fds ifd with
Not_found->
- printf "Fifo fd disappeared\n";flush Pervasives.stdout;raise Bug
+ fprintf logfd "Fifo fd disappeared\n";flush logfd;raise Bug
in
match (cp) with
| Fifo(fifo_outchan) ->
begin
cont:=false
end
- | Unix_error(_,s1,s2) -> printf "Unix error %s - %s\n" s1 s2;flush Pervasives.stdout;cont:=false
+ | Unix_error(_,s1,s2) -> fprintf logfd "Unix error %s - %s\n" s1 s2;flush logfd;cont:=false
| Sys_error(s) -> (* We get this error if the EPIPE comes before the EOF marker*) cont:=false
- | e -> printf "Error - received unexpected event from file system !!!\n";raise e
+ | e -> fprintf logfd "Error - received unexpected event from file system !!!\n";raise e
done
- | _ -> printf "Bug! Process fd received in the channel handler\n";flush Pervasives.stdout;raise Bug
-
+ | _ -> fprintf logfd "Bug! Process fd received in the channel handler\n";flush logfd;raise Bug
let rec openentry_int fifoin fifoout (abspath:string*string) =
let fdin =
try openfile fifoin [O_RDONLY;O_NONBLOCK] 0o777 with
- e->printf "Error opening and connecting FIFO: %s,%o\n" fifoin 0o777;flush Pervasives.stdout;raise e
+ e->fprintf logfd "Error opening and connecting FIFO: %s,%o\n" fifoin 0o777;flush logfd;raise e
in
Hashtbl.replace fdmap fdin abspath;
Fdwatcher.add_fd (Some(fifoin),fdin) (Some(fifoout),stdout) receive_fifo_event
close fdin;
Fdwatcher.del_fd fdin;
let abspath = try
- Hashtbl.find fdmap fdin with _ -> printf "Bug: Phantom pipe\n";flush Pervasives.stdout;raise Bug
+ Hashtbl.find fdmap fdin with _ -> fprintf logfd "Bug: Phantom pipe\n";flush logfd;raise Bug
in
openentry_int fifoin fifoout abspath
(** receive an event from a fifo and connect to the corresponding service, or to
| Some(str)->
(
try openfile str [O_WRONLY;O_NONBLOCK] 0o777 with
- _->printf "Output pipe not open, using stdout in place of %s\n" str;flush Pervasives.stdout;stdout
+ _->fprintf logfd "Output pipe not open, using stdout in place of %s\n" str;flush logfd;stdout
)
- | None-> printf "Bug, nameless pipe\n";flush Pervasives.stdout;raise Bug
+ | None-> fprintf logfd "Bug, nameless pipe\n";flush logfd;raise Bug
in
(* Check if the input descriptor is already registered (=> a session is open).
If not, register it and start a new session.*)
let (script_infd,pout) = Unix.pipe () in
let (pin,script_outfd) = Unix.pipe () in
set_nonblock script_infd;
- let rpid = try Some(create_process execpath [|execpath;slice_name|] pin pout pout) with e -> printf "Error executing service: %s\n" execpath;flush Pervasives.stdout;None
+ ignore(sigprocmask SIG_BLOCK [Sys.sigchld]);
+ let rpid = try Some(create_process execpath [|execpath;slice_name|] pin pout pout) with e -> fprintf logfd "Error executing service: %s\n" execpath;flush logfd;None
in
match rpid with
| None-> BrokenPipe
let cont = ref true in
while (!cont) do
try
- printf "Reading...\n";flush Pervasives.stdout;
+ fprintf logfd "Reading...\n";flush logfd;
let curline = input_line inchan_fd in
fprintf out_channel "%s\n" curline;flush out_channel
with
(
match (evfname,fname_other) with
| Some(str1),Some(str2)->
- printf "Reopening entry\n";flush Pervasives.stdout;
+ fprintf logfd "Reopening entry\n";flush logfd;
reopenentry_int evfd str1 str2
| Some(str1),None ->
- printf "Bug, nameless pipe\n";flush Pervasives.stdout;raise Bug
+ fprintf logfd "Bug, nameless pipe\n";flush logfd;raise Bug
| None,_ ->
- printf "Race condition -> user deleted file before closing it. Clever ploy, but won't work.\n";
- flush Pervasives.stdout
+ fprintf logfd "Race condition -> user deleted file before closing it. Clever ploy, but won't work.\n";
+ flush logfd
);
cont:=false
- |Sys_blocked_io ->printf "Sysblockedio\n";flush Pervasives.stdout;
+ |Sys_blocked_io ->fprintf logfd "Sysblockedio\n";flush logfd;
cont:=false
- | _ ->printf "Bug: unhandled exception\n";flush Pervasives.stdout;raise Bug
- done
+ | Unix_error(_,s1,s2) -> fprintf logfd "Unix error %s - %s\n" s1 s2;flush logfd;cont:=false
+ (*| _ ->fprintf logfd "Bug: unhandled exception\n";flush
+ * logfd;raise Bug*)
+ done;
+ ignore(sigprocmask SIG_UNBLOCK [Sys.sigchld])
| BrokenPipe -> ()
- | Fifo(_) -> printf "BUG! received process event from fifo\n";raise Bug
+ | Fifo(_) -> fprintf logfd "BUG! received process event from fifo\n";raise Bug
(** Make a pair of fifo entries *)
let mkentry fqp abspath perm uname =
- printf "Making entry %s->%s\n" fqp abspath;flush Pervasives.stdout;
+ fprintf logfd "Making entry %s->%s\n" fqp abspath;flush logfd;
let fifoin=sprintf "%s.in" fqp in
let fifoout=sprintf "%s.out" fqp in
(try Unix.unlink fifoin with _ -> ());
);
Success
with
- e->printf "Error creating FIFO: %s->%s. May be something wrong at the frontend.\n" fqp fifoout;flush Pervasives.stdout;Failed)
+ e->fprintf logfd "Error creating FIFO: %s->%s. May be something wrong at the frontend.\n" fqp fifoout;flush logfd;Failed)
(** Open fifos for a session. Will shutdown vsys if the fifos don't exist *)
let openentry fqp abspath perm =