forked from External/grumble
Windows support for blobstore
This commit is contained in:
parent
34b9fbaec4
commit
4e20111ff6
4 changed files with 46 additions and 4 deletions
|
|
@ -5,4 +5,10 @@ GOFILES = \
|
|||
blobstore.go \
|
||||
blobreader.go
|
||||
|
||||
ifeq ($(GOOS),windows)
|
||||
GOFILES += pid_windows.go
|
||||
else
|
||||
GOFILES += pid_unix.go
|
||||
endif
|
||||
|
||||
include $(GOROOT)/src/Make.pkg
|
||||
|
|
|
|||
|
|
@ -186,10 +186,9 @@ func acquireLockfile(path string) os.Error {
|
|||
return err
|
||||
}
|
||||
|
||||
pid, err := strconv.Atoi(string(content))
|
||||
pid, err := strconv.Atoui64(string(content))
|
||||
if err == nil {
|
||||
errno := syscall.Kill(pid, 0)
|
||||
if errno == 0 {
|
||||
if pidRunning(pid) {
|
||||
return ErrLocked
|
||||
}
|
||||
}
|
||||
|
|
@ -220,7 +219,7 @@ func acquireLockfile(path string) os.Error {
|
|||
} else if err != nil {
|
||||
return err
|
||||
} else {
|
||||
_, err = lockfile.WriteString(strconv.Itoa(syscall.Getpid()))
|
||||
_, err = lockfile.WriteString(strconv.Uitoa64(getPid()))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
17
pkg/blobstore/pid_unix.go
Normal file
17
pkg/blobstore/pid_unix.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2011 The Grumble Authors
|
||||
// The use of this source code is goverened by a BSD-style
|
||||
// license that can be found in the LICENSE-file.
|
||||
|
||||
package blobstore
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func getPid() uint64 {
|
||||
return uint64(syscall.Getpid())
|
||||
}
|
||||
|
||||
func pidRunning(pid uint64) bool {
|
||||
return syscall.Kill(int(pid), 0) == 0
|
||||
}
|
||||
20
pkg/blobstore/pid_windows.go
Normal file
20
pkg/blobstore/pid_windows.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (c) 2011 The Grumble Authors
|
||||
// The use of this source code is goverened by a BSD-style
|
||||
// license that can be found in the LICENSE-file.
|
||||
|
||||
package blobstore
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func getPid() uint64 {
|
||||
handle, _ := syscall.GetCurrentProcess()
|
||||
return uint64(handle)
|
||||
}
|
||||
|
||||
func pidRunning(pid uint64) bool {
|
||||
var status uint32
|
||||
syscall.GetExitCodeProcess(uint32(pid), &status)
|
||||
return status == 259 // STILL_ACTIVE
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue