本文整理汇总了Golang中golang.org/x/sys/unix.Syscall函数的典型用法代码示例。如果您正苦于以下问题:Golang Syscall函数的具体用法?Golang Syscall怎么用?Golang Syscall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Syscall函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: lck
func lck(fd, from, ln int) (err error) {
fmt.Printf("lck:%v %v %v\n", fd, from, ln)
fmt.Println(os.Getpid())
// ol := windows.Overlapped{Offset: uint32(from), OffsetHigh: uint32(from >> 32), HEvent: windows.Handle(0)}
// r1, _, err := procLockFileEx.Call(uintptr(fd), uintptr(LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY), uintptr(0), uintptr(int32(ln)), uintptr(int32(ln >> 32)), uintptr(unsafe.Pointer(&ol)))
// if r1 != 1 {
// return err
// }
// return nil
lk := unix.Flock_t{Type: unix.F_WRLCK, Whence: int16(os.SEEK_SET), Start: int64(from), Len: int64(ln)}
//return unix.FcntlFlock(uintptr(fd), unix.F_SETLKW, &lk)
r1, _, errno := unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(unix.F_GETFL), uintptr(unsafe.Pointer(&lk)))
fmt.Printf("\tlck_test:%v %v %v\n", r1, lk, errno)
lk = unix.Flock_t{Type: unix.F_WRLCK, Whence: int16(os.SEEK_SET), Start: int64(from), Len: int64(ln)}
r1, _, errno = unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(unix.F_SETLK), uintptr(unsafe.Pointer(&lk)))
fmt.Printf("\tlck:%v %v %v\n", r1, lk, errno)
if errno == 0 {
return nil
}
err = errno
return err
}
示例2: setSTDINToBlock
// In environments where svlogd is used, the pipe that becomes STDIN of this
// program can be non-blocking. Go's File implementation does not play well
// with non-blocking pipes, in particular it does not recover from an EAGAIN
// error from read(2).
// This function defensively sets its 0th file descriptor to be blocking so
// that we do not have to handle EAGAIN errors.
func setSTDINToBlock() error {
oldflags, _, errno := unix.Syscall(unix.SYS_FCNTL, 0, unix.F_GETFL, 0)
if errno != 0 {
return fmt.Errorf("unix.FCNTL F_GETFL errno: %d", errno)
}
_, _, errno = unix.Syscall(unix.SYS_FCNTL, 0, unix.F_SETFL, oldflags&^unix.O_NONBLOCK)
if errno != 0 {
return fmt.Errorf("unix.FCNTL F_SETFL errno: %d", errno)
}
return nil
}
示例3: ioCtl
func ioCtl(fd *os.File) (bufLen int, err error) {
bufLen = 1
_, _, errno := unix.Syscall(unix.SYS_IOCTL, fd.Fd(), uintptr(unix.BIOCIMMEDIATE), uintptr(unsafe.Pointer(&bufLen)))
if errno != 0 {
err = errno
return
}
_, _, errno = unix.Syscall(unix.SYS_IOCTL, fd.Fd(), uintptr(unix.BIOCGBLEN), uintptr(unsafe.Pointer(&bufLen)))
if errno != 0 {
err = errno
}
return
}
示例4: JailAttach
func JailAttach(jid int) error {
if _, _, err := unix.Syscall(unix.SYS_JAIL_ATTACH, uintptr(jid), 0, 0); err == 0 {
return nil
} else {
return err
}
}
示例5: GetWinsize
// GetWinsize gets the winsize struct with the terminal size set by the kernel.
func GetWinsize(fd int, ws *Winsize) (err error) {
_, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd),
uintptr(TIOCGWINSZ), uintptr(unsafe.Pointer(ws)))
if e1 != 0 {
err = e1
}
return
}
示例6: Getattr
func Getattr(fd int, state *Termios) (err error) {
_, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd),
uintptr(TCGETS), uintptr(unsafe.Pointer(state)))
if e1 != 0 {
err = e1
}
return
}
示例7: setns
func setns(fd int) error {
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)
}
return nil
}
示例8: insert
func insert(fd uintptr, s string) error {
for _, c := range s {
ptr := uintptr(unsafe.Pointer(&c))
if _, _, e := unix.Syscall(unix.SYS_IOCTL, fd, unix.TIOCSTI, ptr); e != 0 {
return fmt.Errorf("syscall errno: %d\n", e)
}
}
return nil
}
示例9: getwinsize
func getwinsize() winsize {
ws := winsize{}
_, _, err := unix.Syscall(syscall.SYS_IOCTL,
uintptr(0), uintptr(syscall.TIOCGWINSZ),
uintptr(unsafe.Pointer(&ws)))
if err != 0 {
log.Fatalf("TIOCGWINSZ failed to get terminal size: %s\n", err)
}
return ws
}
示例10: Set
func (ns *netNS) Set() error {
if err := ns.errorIfClosed(); err != nil {
return err
}
if _, _, err := unix.Syscall(unix.SYS_SETNS, ns.Fd(), uintptr(unix.CLONE_NEWNET), 0); err != 0 {
return fmt.Errorf("Error switching to ns %v: %v", ns.file.Name(), err)
}
return nil
}
示例11: Mprotect
// Mprotect calls mprotect(2) on the mmapped region.
func (m Map) Mprotect(prot Perms) (err error) {
_, _, e1 := unix.Syscall(
unix.SYS_MPROTECT,
uintptr(m.Start),
uintptr(m.End-m.Start),
uintptr(prot),
)
if e1 != 0 {
return e1
}
return
}
示例12: rlck
func rlck(fd, from, ln int) (err error) {
// ol := windows.Overlapped{Offset: uint32(from), OffsetHigh: uint32(from >> 32), HEvent: windows.Handle(0)}
// r1, _, err := procLockFileEx.Call(uintptr(fd), uintptr(LOCKFILE_FAIL_IMMEDIATELY), uintptr(0), uintptr(int32(ln)), uintptr(int32(ln >> 32)), uintptr(unsafe.Pointer(&ol)))
// if r1 != 1 {
// return err
// }
// return nil
// type Flock_t struct {
// Type int16
// Whence int16
// Pad_cgo_0 [4]byte
// Start int64
// Len int64
// Pid int32
// Pad_cgo_1 [4]byte
// }
// FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command.
// func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) error {
// _, _, errno := Syscall(fcntl64Syscall, fd, uintptr(cmd), uintptr(unsafe.Pointer(lk)))
// if errno == 0 {
// return nil
// }
// return errno
// }
fmt.Printf("rlck:%v %v %v\n", fd, from, ln)
fmt.Println(os.Getpid())
lk := unix.Flock_t{Type: unix.F_RDLCK, Whence: int16(os.SEEK_SET), Start: int64(from), Len: int64(ln)}
r1, _, errno := unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(unix.F_GETFL), uintptr(unsafe.Pointer(&lk)))
fmt.Printf("\trlck_test:%v %v %v\n", r1, lk, errno)
lk = unix.Flock_t{Type: unix.F_RDLCK, Whence: int16(os.SEEK_SET), Start: int64(from), Len: int64(ln)}
r1, _, errno = unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(unix.F_SETLK), uintptr(unsafe.Pointer(&lk)))
fmt.Printf("\trlck:%v %v %v\n", r1, lk, errno)
if errno == 0 {
return nil
}
err = errno
return err
}
示例13: ifReq
func ifReq(fd *os.File, ifName string) (err error) {
req := struct {
Name [0x10]byte
pad [0x28 - 0x10]byte
}{}
copy(req.Name[:], ifName)
_, _, errno := unix.Syscall(unix.SYS_IOCTL, fd.Fd(), uintptr(unix.BIOCSETIF), uintptr(unsafe.Pointer(&req)))
if errno != 0 {
err = errno
return err
}
return
}
示例14: main
func main() {
flag.Parse()
l := uintptr(3)
if *clearSyslog {
l = 4
}
b := make([]byte, 256*1024)
if amt, _, err := unix.Syscall(unix.SYS_SYSLOG, l, uintptr(unsafe.Pointer(&b[0])), uintptr(len(b))); err == 0 {
os.Stdout.Write(b[:amt])
} else {
log.Fatalf("syslog failed: %v", err)
}
}
示例15: writeVolume
func (m *Mixer) writeVolume(channelVolume int) error {
_, _, err := unix.Syscall(
unix.SYS_IOCTL,
m.device.Fd(),
SOUND_MIXER_WRITE_VOLUME,
uintptr(unsafe.Pointer(&channelVolume)),
)
if err != 0 {
return err
}
return nil
}