]> Cypherpunks.ru repositories - gostls13.git/commitdiff
misc/ios: fix exec wrapper locking
authorElias Naur <elias.naur@gmail.com>
Fri, 25 Mar 2016 14:40:44 +0000 (15:40 +0100)
committerElias Naur <elias.naur@gmail.com>
Fri, 25 Mar 2016 16:47:01 +0000 (16:47 +0000)
The exec wrapper lock file was opened, locked and then never used
again, assuming it would close and unlock at process exit.
However, the garbage collector could collect and run the *os.File
finalizer that closes the file prematurely, rendering the lock
ineffective.

Make the lock global so that the lock is live during the entire
execution.

(Hopefully) fix the iOS builders.

Change-Id: I62429e92042a0a49c4f1ea553fdb32b6ea53a43e
Reviewed-on: https://go-review.googlesource.com/21137
Reviewed-by: David Crawshaw <crawshaw@golang.org>
misc/ios/go_darwin_arm_exec.go

index 6f0b98f11248b9cda3573a3c48fd6ed46c659b11..1eeb289c7d249ce60f96425489a879267a5040ff 100644 (file)
@@ -50,6 +50,11 @@ var (
        teamID string
 )
 
+// lock is a file lock to serialize iOS runs. It is global to avoid the
+// garbage collector finalizing it, closing the file and releasing the
+// lock prematurely.
+var lock *os.File
+
 func main() {
        log.SetFlags(0)
        log.SetPrefix("go_darwin_arm_exec: ")
@@ -84,7 +89,7 @@ func main() {
        // The lock file is never deleted, to avoid concurrent locks on distinct
        // files with the same path.
        lockName := filepath.Join(os.TempDir(), "go_darwin_arm_exec.lock")
-       lock, err := os.OpenFile(lockName, os.O_CREATE|os.O_RDONLY, 0666)
+       lock, err = os.OpenFile(lockName, os.O_CREATE|os.O_RDONLY, 0666)
        if err != nil {
                log.Fatal(err)
        }