comparison src/main.mlton.sml @ 2192:fb113569519e

Make daemon mode support sharing of libraries across projects
author Adam Chlipala <adam@chlipala.net>
date Sun, 22 Nov 2015 10:03:35 -0500
parents 057b08253a75
children 6fb9232ade99
comparison
equal deleted inserted replaced
2191:849404a3af27 2192:fb113569519e
277 val cmd = Substring.string befor 277 val cmd = Substring.string befor
278 val rest = Substring.string (Substring.slice (after, 1, NONE)) 278 val rest = Substring.string (Substring.slice (after, 1, NONE))
279 in 279 in
280 case cmd of 280 case cmd of
281 "" => 281 "" =>
282 let 282 (case args of
283 val success = (oneRun (rev args)) 283 ["stop", "daemon"] =>
284 handle ex => (print "unhandled exception:\n"; 284 (((Socket.close listen;
285 print (General.exnMessage ex ^ "\n"); 285 OS.FileSys.remove socket) handle OS.SysErr _ => ());
286 OS.Process.failure) 286 OS.Process.exit OS.Process.success)
287 in 287 | _ =>
288 TextIO.flushOut TextIO.stdOut; 288 let
289 TextIO.flushOut TextIO.stdErr; 289 val success = (oneRun (rev args))
290 send (sock, if OS.Process.isSuccess success then 290 handle ex => (print "unhandled exception:\n";
291 "\001" 291 print (General.exnMessage ex ^ "\n");
292 else 292 OS.Process.failure)
293 "\002") 293 in
294 end 294 TextIO.flushOut TextIO.stdOut;
295 TextIO.flushOut TextIO.stdErr;
296 send (sock, if OS.Process.isSuccess success then
297 "\001"
298 else
299 "\002")
300 end)
295 | _ => loop' (rest, cmd :: args) 301 | _ => loop' (rest, cmd :: args)
296 end 302 end
297 end handle OS.SysErr _ => () 303 end handle OS.SysErr _ => ()
298 304
299 fun redirect old = 305 fun redirect old =
313 Posix.IO.dup2 {old = oldStdout, new = Posix.FileSys.stdout}; 319 Posix.IO.dup2 {old = oldStdout, new = Posix.FileSys.stdout};
314 Posix.IO.dup2 {old = oldStderr, new = Posix.FileSys.stderr}; 320 Posix.IO.dup2 {old = oldStderr, new = Posix.FileSys.stderr};
315 Posix.IO.close oldStdout; 321 Posix.IO.close oldStdout;
316 Posix.IO.close oldStderr; 322 Posix.IO.close oldStderr;
317 323
324 Settings.reset ();
318 MLton.GC.pack (); 325 MLton.GC.pack ();
319 loop () 326 loop ()
320 end 327 end
321 in 328 in
322 OS.Process.atExit (fn () => OS.FileSys.remove socket); 329 OS.Process.atExit (fn () => OS.FileSys.remove socket);
323 Socket.bind (listen, UnixSock.toAddr socket); 330 Socket.bind (listen, UnixSock.toAddr socket);
324 Socket.listen (listen, 1); 331 Socket.listen (listen, 1);
325 loop () 332 loop ()
326 end) 333 end)
327 | ["daemon", "stop"] =>
328 (OS.FileSys.remove socket handle OS.SysErr _ => OS.Process.exit OS.Process.success)
329 | args => 334 | args =>
330 let 335 let
331 val sock = UnixSock.Strm.socket () 336 val sock = UnixSock.Strm.socket ()
332 337
333 fun wait () = 338 fun wait () =