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

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

Issue 2990863002: Implement the 'shared' subcommand for mmutex (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
« no previous file with comments | « mmutex/cmd/mmutex/main.go ('k') | mmutex/cmd/mmutex/shared_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mmutex/cmd/mmutex/shared.go
diff --git a/mmutex/cmd/mmutex/exclusive.go b/mmutex/cmd/mmutex/shared.go
similarity index 59%
copy from mmutex/cmd/mmutex/exclusive.go
copy to mmutex/cmd/mmutex/shared.go
index 00ff24d6e694ec1206be158578886e8c09df413e..7cea7f97ed96e5f42e322c06a73be6cdce723038 100644
--- a/mmutex/cmd/mmutex/exclusive.go
+++ b/mmutex/cmd/mmutex/shared.go
@@ -26,25 +26,30 @@ import (
"github.com/luci/luci-go/mmutex/lib"
)
-var cmdExclusive = &subcommands.Command{
- UsageLine: "exclusive -- <command>",
- ShortDesc: "acquires an exclusive lock before running the command",
+var cmdShared = &subcommands.Command{
+ UsageLine: "shared [options] -- <command>",
+ ShortDesc: "acquires a shared lock before running the command",
CommandRun: func() subcommands.CommandRun {
- c := &cmdExclusiveRun{}
- c.Flags.DurationVar(&c.fslockTimeout, "fslock-timeout", 0, "Lock acquisition timeout")
- c.Flags.DurationVar(&c.fslockPollingInterval, "fslock-polling-interval", 0, "Lock acquisition polling interval")
+ c := &cmdSharedRun{}
+ c.Flags.DurationVar(&c.fslockTimeout, "fslock-timeout", 2*time.Hour, "Lock acquisition timeout")
+ c.Flags.DurationVar(&c.fslockPollingInterval, "fslock-polling-interval", 5*time.Second, "Lock acquisition polling interval")
return c
},
}
-type cmdExclusiveRun struct {
+type cmdSharedRun struct {
subcommands.CommandRunBase
fslockTimeout time.Duration
fslockPollingInterval time.Duration
}
-func (c *cmdExclusiveRun) Run(a subcommands.Application, args []string, env subcommands.Env) int {
- if err := RunExclusive(args, c.fslockTimeout, c.fslockPollingInterval); err != nil {
+func (c *cmdSharedRun) Run(a subcommands.Application, args []string, env subcommands.Env) int {
+ if err := RunShared(args, c.fslockTimeout, c.fslockPollingInterval); err != nil {
+ if exitErr, ok := err.(*exec.ExitError); ok {
+ return lib.GetExitCode(exitErr)
+ }
+
+ // The error pertains to this binary rather than the executed command.
fmt.Fprintln(os.Stderr, err)
return 1
} else {
@@ -52,9 +57,9 @@ func (c *cmdExclusiveRun) Run(a subcommands.Application, args []string, env subc
}
}
-func RunExclusive(command []string, timeout time.Duration, pollingInterval time.Duration) error {
+func RunShared(command []string, timeout time.Duration, pollingInterval time.Duration) error {
blocker := lib.CreateBlockerUntil(time.Now().Add(timeout), pollingInterval)
- return fslock.WithBlocking(LockFilePath, blocker, func() error {
+ return fslock.WithSharedBlocking(LockFilePath, blocker, func() error {
cmd := exec.Command(command[0], command[1:]...)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
« no previous file with comments | « mmutex/cmd/mmutex/main.go ('k') | mmutex/cmd/mmutex/shared_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698