Change concatTo to use only local node's files
[hcoop/domtool2.git] / src / main.sml
index 59607bb..5b9ee57 100644 (file)
@@ -122,15 +122,6 @@ fun eval fname =
 val dispatcher =
     Config.dispatcher ^ ":" ^ Int.toString Config.dispatcherPort
 
-fun hostname () =
-    let
-       val inf = TextIO.openIn "/etc/hostname"
-    in
-       case TextIO.inputLine inf of
-           NONE => (TextIO.closeIn inf; raise Fail "No line in /etc/hostname")
-         | SOME line => (TextIO.closeIn inf; String.substring (line, 0, size line - 1))
-    end
-
 fun request fname =
     let
        val uid = Posix.ProcEnv.getuid ()
@@ -212,21 +203,21 @@ fun service () =
                                    TextIO.closeOut outf;
                                    (eval outname;
                                     Msg.send (bio, MsgOk))
-                                    handle ErrorMsg.Error =>
-                                           (print "Compilation error\n";
-                                            Msg.send (bio,
-                                                      MsgError "Error during configuration evaluation"))
-                                         | OpenSSL.OpenSSL s =>
-                                           (print "OpenSSL error\n";
-                                            Msg.send (bio,
-                                                      MsgError
-                                                          ("Error during configuration evaluation: "
-                                                           ^ s)));
-                                   OS.FileSys.remove outname;
-                                   (ignore (OpenSSL.readChar bio);
-                                    OpenSSL.close bio)
-                                   handle OpenSSL.OpenSSL _ => ();
-                                   loop ()
+                                   handle ErrorMsg.Error =>
+                                          (print "Compilation error\n";
+                                           Msg.send (bio,
+                                                     MsgError "Error during configuration evaluation"))
+                                        | OpenSSL.OpenSSL s =>
+                                          (print "OpenSSL error\n";
+                                           Msg.send (bio,
+                                                     MsgError
+                                                         ("Error during configuration evaluation: "
+                                                          ^ s)));
+                                          OS.FileSys.remove outname;
+                                          (ignore (OpenSSL.readChar bio);
+                                           OpenSSL.close bio)
+                                          handle OpenSSL.OpenSSL _ => ();
+                                          loop ()
                                end
                              | _ =>
                                (Msg.send (bio, MsgError "Unexpected command")
@@ -237,6 +228,16 @@ fun service () =
                in
                    cmdLoop ()
                end
+                   handle OpenSSL.OpenSSL s =>
+                          (print ("OpenSSL error: " ^ s ^ "\n");
+                           OpenSSL.close bio
+                           handle OpenSSL.OpenSSL _ => ();
+                           loop ())
+                        | OS.SysErr (s, _) =>
+                          (print ("System error: " ^ s ^ "\n");
+                           OpenSSL.close bio
+                           handle OpenSSL.OpenSSL _ => ();
+                           loop ())
     in
        print "Listening for connections....\n";
        loop ();
@@ -245,7 +246,7 @@ fun service () =
 
 fun slave () =
     let
-       val host = hostname ()
+       val host = Slave.hostname ()
 
        val context = OpenSSL.context (Config.certDir ^ "/" ^ host ^ ".pem",
                                       Config.keyDir ^ "/" ^ host ^ "/key.pem",
@@ -287,6 +288,11 @@ fun slave () =
                            OpenSSL.close bio
                                          handle OpenSSL.OpenSSL _ => ();
                            loop ())
+                        | OS.SysErr (s, _) =>
+                          (print ("System error: "^ s ^ "\n");
+                           OpenSSL.close bio
+                           handle OpenSSL.OpenSSL _ => ();
+                           loop ())
     in
        loop ();
        OpenSSL.shutdown sock