Creepiest bug ever
authorSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 29 Feb 2008 19:40:33 +0000 (19:40 +0000)
committerSapan Bhatia <sapanb@cs.princeton.edu>
Fri, 29 Feb 2008 19:40:33 +0000 (19:40 +0000)
Makefile
fifowatcher.ml
vsyssh/vsyssh.c

index 65e5736..45d0312 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -33,8 +33,8 @@ ocaml_inotify-0.4/inotify.cmxa:
 vsys: ocaml_inotify-0.4/inotify.cmxa globals.cmx fdwatcher.cmx conffile.cmx dirwatcher.cmx fifowatcher.cmx frontend.cmx backend.cmx main.cmx docs
        ocamlopt -I ocaml_inotify-0.4 str.cmxa unix.cmxa inotify.cmxa globals.cmx fdwatcher.cmx dirwatcher.cmx fifowatcher.cmx frontend.cmx backend.cmx str.cmxa conffile.cmx main.cmx -o vsys
 
-vsys.b: inotify.cma inotify.cmi globals.ml fdwatcher.ml dirwatcher.ml fifowatcher.ml frontend.ml backend.ml main.ml
-       ocamlc -g str.cma unix.cma inotify.cma globals.cmo fdwatcher.cmo dirwatcher.cmo fifowatcher.cmo frontend.cmo backend.cmo str.cma main.cmo -o vsys.b
+vsys.b: ocaml_inotify-0.4/inotify.cma inotify.cmi globals.ml fdwatcher.ml dirwatcher.ml fifowatcher.ml frontend.ml backend.ml main.ml
+       ocamlc -g str.cma unix.cma ocaml_inotify-0.4/inotify.cma globals.cmo fdwatcher.cmo dirwatcher.cmo fifowatcher.cmo frontend.cmo backend.cmo str.cma conffile.cmo main.cmo -o vsys.b
 
 install: vsys
        cp vsys $(INSTALL_DIR)/usr/bin
index 9b42a51..6e2a12a 100644 (file)
@@ -50,7 +50,6 @@ let receive_process_event (idesc: fname_and_fd) (_: fname_and_fd) =
             done
       | _ -> 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 
@@ -71,6 +70,7 @@ and reopenentry_int fdin fifoin fifoout =
   @param outdescriptor Name of output pipe, out descriptor
   *)
 and receive_fifo_event eventdescriptor outdescriptor =
+  printf "received fifo event\n";flush Pervasives.stdout;
   let (evfname,evfd) = eventdescriptor in
   let (fname_other,fd_other) = outdescriptor in
   (* Open the output pipe, or use stdout instead *)
@@ -87,11 +87,13 @@ and receive_fifo_event eventdescriptor outdescriptor =
    If not, register it and start a new session.*)
   let pipe = try Hashtbl.find open_fds evfd with
     | Not_found ->
+        printf "fd not found!\n";flush Pervasives.stdout;
         (* Ok, need to launch script *)
         let execpath,slice_name = Hashtbl.find fdmap evfd in
         let (script_infd,pout) = Unix.pipe () in
         let (pin,script_outfd) = Unix.pipe () in
           set_nonblock script_infd;
+          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
@@ -139,8 +141,11 @@ and receive_fifo_event eventdescriptor outdescriptor =
                     cont:=false
                 |Sys_blocked_io ->fprintf logfd "Sysblockedio\n";flush logfd;
                                   cont:=false
-                | _ ->fprintf logfd "Bug: unhandled exception\n";flush logfd;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(_) -> fprintf logfd "BUG! received process event from fifo\n";raise Bug
 
index 3d32454..586c6a7 100644 (file)
@@ -60,6 +60,8 @@ int main(int argc, char **argv, char **envp)
                                int ret;
                                printf("vsys>");fflush(stdout);
                                ret = select(vfd0+1, &set, NULL, NULL, &tv);
+                               FD_SET(0, &set);
+                               FD_SET(vfd0, &set);
                                if (FD_ISSET(0,&set)) {
                                        char lineread[2048];
                                        int ret;
@@ -68,12 +70,13 @@ int main(int argc, char **argv, char **envp)
                                        write(vfd1,lineread,ret);
                                        FD_CLR(0,&set);
                                }
-                               else if (FD_ISSET(vfd0,&set)) {
+                               if (FD_ISSET(vfd0,&set)) {
                                        char lineread[2048];
                                        int ret;
                                        printf("Here2\n");
                                        ret=read(vfd0,lineread,2048);
                                        write(1,lineread,ret);
+                                       printf("Here3\n");
                                        FD_CLR(vfd0,&set);
                                }
                        }