Chromium Code Reviews| Index: mmutex/cmd/mmutex/main.go |
| diff --git a/mmutex/cmd/mmutex/main.go b/mmutex/cmd/mmutex/main.go |
| index d61b202902035f014f3edb4f856c6365c1465583..416c9565cbbac9b442ac8f442bb48e5b43d862d9 100644 |
| --- a/mmutex/cmd/mmutex/main.go |
| +++ b/mmutex/cmd/mmutex/main.go |
| @@ -4,6 +4,31 @@ |
| package main |
| +import ( |
| + "flag" |
| + "fmt" |
| + "os" |
| + |
| + "github.com/luci/luci-go/mmutex/lib" |
| +) |
| + |
| +// TODO(charliea): Compute this path from $MMUTEX_LOCK_DIR rather than using a constant. |
| +const lockFilePath = "/tmp/lock" |
| + |
| func main() { |
| - // TODO(charliea): Write the command line interface. |
| + var isExclusive = flag.Bool("x", false, "Runs the command after acquiring an exclusive lock") |
|
iannucci
2017/07/11 20:52:14
we will probably want to convert this to use the l
charliea (OOO until 10-5)
2017/07/11 23:26:16
Done. Started with just "exclusive" for now, given
|
| + var isShared = flag.Bool("s", false, "Runs the command after acquiring a shared lock") |
| + flag.Parse() |
| + |
| + if (*isExclusive && *isShared) || (!*isExclusive && !*isShared) { |
| + fmt.Fprintf(os.Stderr, "mmutex must be run in either exclusive mode (-x) or shared mode (-s), but not both.\\n") |
| + os.Exit(1) |
| + } |
| + |
| + if *isExclusive { |
| + if err := lib.AcquireExclusiveLock(lockFilePath); err != nil { |
| + fmt.Fprintf(os.Stderr, "error acquiring exclusive lock: %s\n", err) |
| + os.Exit(1) |
| + } |
| + } |
| } |