forked from CakeML/regression
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper utility for acquiring the lock
For running commands alongside the server without interfering with its operation.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |