Skip to content

Commit

Permalink
Add helper utility for acquiring the lock
Browse files Browse the repository at this point in the history
For running commands alongside the server without interfering with its
operation.
  • Loading branch information
xrchz committed Nov 8, 2017
1 parent d90f6c6 commit ad77048
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions flock.sml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(*
Acquire the lock that is used by the server to run a command without
interfering with the server
*)
use "regressionLib.sml";
open regressionLib
open Posix.Process
fun main () =
let
val args = CommandLine.arguments ()
val () = assert (not (List.null args)) ["usage: ./flock cmd args ..."]
val fd = acquire_lock ()
in
case fork() of
NONE => execp (List.hd args, args)
| SOME pid =>
let
val (pid',status) = wait ()
val () = assert (pid=pid') ["wrong child"]
val () = Posix.IO.close fd
in
case status of
W_EXITED => ()
| W_EXITSTATUS w => exit w
| _ => exit (Word8.fromInt 126)
end
end

0 comments on commit ad77048

Please sign in to comment.