Skip to content

Commit

Permalink
Switches from syscall to golang.org/x/sys/unix
Browse files Browse the repository at this point in the history
According to
https://golang.org/pkg/syscall/
and
https://docs.google.com/document/d/1QXzI9I1pOfZPujQzxhyRy6EeHYTQitKKjHfpq0zpxZs/edit
the syscall library is essentially deprecated
moving forward with go 1.4.

"NOTE: This package is locked down. Code outside
the standard Go repository should be migrated to
use the corresponding package in the go.sys
subrepository. That is also where updates
required by new systems or versions should be
applied."
  • Loading branch information
manniwood committed Aug 11, 2015
1 parent f5eaebd commit 9efe8a0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and has some build problems.
I wrote this is so that Apache Cassandra users can see if ssTables are being
cached. If $GOPATH/bin is in your PATH, this will get it installed:

go get golang.org/x/sys/unix
go get github.com/tobert/pcstat/pcstat
pcstat /var/lib/cassandra/data/*/*/*-Data.db

Expand Down
9 changes: 5 additions & 4 deletions mincore.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ package pcstat
import (
"fmt"
"os"
"syscall"
"unsafe"

"golang.org/x/sys/unix"
)

// mmap the given file, get the mincore vector, then
// return it as an []bool
func FileMincore(f *os.File, size int64) ([]bool, error) {
// mmap is a []byte
mmap, err := syscall.Mmap(int(f.Fd()), 0, int(size), syscall.PROT_NONE, syscall.MAP_SHARED)
mmap, err := unix.Mmap(int(f.Fd()), 0, int(size), unix.PROT_NONE, unix.MAP_SHARED)
if err != nil {
return nil, fmt.Errorf("could not mmap: %v", err)
}
Expand All @@ -50,11 +51,11 @@ func FileMincore(f *os.File, size int64) ([]bool, error) {
// to the memory behind an []byte
// this writes a snapshot of the data into vec which a list of 8-bit flags
// with the LSB set if the page in that position is currently in VFS cache
ret, _, err := syscall.Syscall(syscall.SYS_MINCORE, mmap_ptr, size_ptr, vec_ptr)
ret, _, err := unix.Syscall(unix.SYS_MINCORE, mmap_ptr, size_ptr, vec_ptr)
if ret != 0 {
return nil, fmt.Errorf("syscall SYS_MINCORE failed: %v", err)
}
defer syscall.Munmap(mmap)
defer unix.Munmap(mmap)

mc := make([]bool, vecsz)

Expand Down
5 changes: 3 additions & 2 deletions mnt_ns_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (
"os"
"strconv"
"strings"
"syscall"

"golang.org/x/sys/unix"
)

// not available before Go 1.4
Expand Down Expand Up @@ -62,7 +63,7 @@ func getMountNs(pid int) int {
}

func setns(fd int) error {
ret, _, err := syscall.Syscall(SYS_SETNS, uintptr(uint(fd)), uintptr(CLONE_NEWNS), 0)
ret, _, err := unix.Syscall(SYS_SETNS, uintptr(uint(fd)), uintptr(CLONE_NEWNS), 0)
if ret != 0 {
return fmt.Errorf("syscall SYS_SETNS failed: %v", err)
}
Expand Down
4 changes: 3 additions & 1 deletion pcstat/winsize.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"log"
"syscall"
"unsafe"

"golang.org/x/sys/unix"
)

// adapted from https://groups.google.com/d/msg/golang-nuts/8d4pOPmSL9Q/H6WUqbGNELEJ
Expand All @@ -36,7 +38,7 @@ type winsize struct {

func getwinsize() winsize {
ws := winsize{}
_, _, err := syscall.Syscall(syscall.SYS_IOCTL,
_, _, err := unix.Syscall(syscall.SYS_IOCTL,
uintptr(0), uintptr(syscall.TIOCGWINSZ),
uintptr(unsafe.Pointer(&ws)))
if err != 0 {
Expand Down

0 comments on commit 9efe8a0

Please sign in to comment.