Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1136)

Unified Diff: mmutex/cmd/mmutex/main.go

Issue 2980603003: Flesh out the mmutex binary wrapper and test for existence of lockfile (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)
+ }
+ }
}
« no previous file with comments | « mmutex/cmd/mmutex/.gitignore ('k') | mmutex/lib/flock.go » ('j') | mmutex/lib/flock.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698