• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang unix.Syscall函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中golang.org/x/sys/unix.Syscall函数的典型用法代码示例。如果您正苦于以下问题:Golang Syscall函数的具体用法?Golang Syscall怎么用?Golang Syscall使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Syscall函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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

}
开发者ID:mrkovec,项目名称:str,代码行数:25,代码来源:fileStorage_linux.go


示例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
}
开发者ID:petertseng,项目名称:p2,代码行数:17,代码来源:main.go


示例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
}
开发者ID:songgao,项目名称:ether,代码行数:13,代码来源:bpf.go


示例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
	}
}
开发者ID:sdoumbouya,项目名称:jetpack,代码行数:7,代码来源:main.go


示例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
}
开发者ID:kless,项目名称:term,代码行数:9,代码来源:sys_unix.go


示例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
}
开发者ID:kless,项目名称:term,代码行数:8,代码来源:sys_unix.go


示例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
}
开发者ID:cholcombe973,项目名称:pcstat,代码行数:8,代码来源:mnt_ns_linux.go


示例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
}
开发者ID:etherealmachine,项目名称:ttyecho,代码行数:9,代码来源:ttyecho.go


示例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
}
开发者ID:cholcombe973,项目名称:pcstat,代码行数:10,代码来源:winsize.go


示例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
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:11,代码来源:ns.go


示例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
}
开发者ID:EricLagergren,项目名称:proc,代码行数:13,代码来源:maps.go


示例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
}
开发者ID:mrkovec,项目名称:str,代码行数:40,代码来源:fileStorage_linux.go


示例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
}
开发者ID:songgao,项目名称:ether,代码行数:13,代码来源:bpf.go


示例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)
	}
}
开发者ID:u-root,项目名称:u-root,代码行数:13,代码来源:dmesg.go


示例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
}
开发者ID:bernerdschaefer,项目名称:applemediakeyd,代码行数:14,代码来源:mixer.go


示例16: msync

// Call msync(2) with the MS_SYNC flag on a slice previously returned by
// mmap(2).
func msync(p []byte) (err error) {
	_, _, errno := unix.Syscall(
		unix.SYS_MSYNC,
		uintptr(unsafe.Pointer(&p[0])),
		uintptr(len(p)),
		unix.MS_SYNC)

	if errno != 0 {
		err = errno
		return
	}

	return
}
开发者ID:andrewgaul,项目名称:fuse,代码行数:16,代码来源:flush_fs_test.go


示例17: FileMincore

// mmap the given file, get the mincore vector, then
// return it as an []bool
func FileMincore(f *os.File, size int64) ([]bool, error) {
	//skip could not mmap error when the file size is 0
	if int(size) == 0 {
		return nil, nil
	}
	// mmap is a []byte
	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)
	}
	// TODO: check for MAP_FAILED which is ((void *) -1)
	// but maybe unnecessary since it looks like errno is always set when MAP_FAILED

	// one byte per page, only LSB is used, remainder is reserved and clear
	vecsz := (size + int64(os.Getpagesize()) - 1) / int64(os.Getpagesize())
	vec := make([]byte, vecsz)

	// get all of the arguments to the mincore syscall converted to uintptr
	mmap_ptr := uintptr(unsafe.Pointer(&mmap[0]))
	size_ptr := uintptr(size)
	vec_ptr := uintptr(unsafe.Pointer(&vec[0]))

	// use Go's ASM to submit directly to the kernel, no C wrapper needed
	// mincore(2): int mincore(void *addr, size_t length, unsigned char *vec);
	// 0 on success, takes the pointer to the mmap, a size, which is the
	// size that came from f.Stat(), and the vector, which is a pointer
	// 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 := 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 unix.Munmap(mmap)

	mc := make([]bool, vecsz)

	// there is no bitshift only bool
	for i, b := range vec {
		if b%2 == 1 {
			mc[i] = true
		} else {
			mc[i] = false
		}
	}

	return mc, nil
}
开发者ID:cholcombe973,项目名称:pcstat,代码行数:50,代码来源:mincore.go


示例18: MakeNetworkNS

func MakeNetworkNS(containerID string) string {
	namespace := "/var/run/netns/" + containerID

	err := os.MkdirAll("/var/run/netns", 0600)
	Expect(err).NotTo(HaveOccurred())

	// create an empty file at the mount point
	mountPointFd, err := os.Create(namespace)
	Expect(err).NotTo(HaveOccurred())
	mountPointFd.Close()

	var wg sync.WaitGroup
	wg.Add(1)

	// do namespace work in a dedicated goroutine, so that we can safely
	// Lock/Unlock OSThread without upsetting the lock/unlock state of
	// the caller of this function.  See block comment above.
	go (func() {
		defer wg.Done()

		runtime.LockOSThread()
		defer runtime.UnlockOSThread()

		defer GinkgoRecover()

		// capture current thread's original netns
		currentThreadNetNSPath := getCurrentThreadNetNSPath()
		originalNetNS, err := unix.Open(currentThreadNetNSPath, unix.O_RDONLY, 0)
		Expect(err).NotTo(HaveOccurred())
		defer unix.Close(originalNetNS)

		// create a new netns on the current thread
		err = unix.Unshare(unix.CLONE_NEWNET)
		Expect(err).NotTo(HaveOccurred())

		// bind mount the new netns from the current thread onto the mount point
		err = unix.Mount(currentThreadNetNSPath, namespace, "none", unix.MS_BIND, "")
		Expect(err).NotTo(HaveOccurred())

		// reset current thread's netns to the original
		_, _, e1 := unix.Syscall(unix.SYS_SETNS, uintptr(originalNetNS), uintptr(unix.CLONE_NEWNET), 0)
		Expect(e1).To(BeZero())
	})()

	wg.Wait()

	return namespace
}
开发者ID:aanm,项目名称:cni,代码行数:48,代码来源:testhelpers.go


示例19: readVolume

func (m *Mixer) readVolume() (int, error) {
	var currentVolume int

	_, _, err := unix.Syscall(
		unix.SYS_IOCTL,
		m.device.Fd(),
		SOUND_MIXER_READ_VOLUME,
		uintptr(unsafe.Pointer(&currentVolume)),
	)

	if err != 0 {
		return 0, err
	}

	return currentVolume & 0xff, nil
}
开发者ID:bernerdschaefer,项目名称:applemediakeyd,代码行数:16,代码来源:mixer.go


示例20: Setattr

func Setattr(fd int, action uint, state *Termios) (err error) {
	switch action {
	case TCSANOW:
		action = TCSETS
	case TCSADRAIN:
		action = TCSETSW
	case TCSAFLUSH:
		action = TCSETSF
	}

	_, _, e1 := unix.Syscall(unix.SYS_IOCTL, uintptr(fd),
		uintptr(action), uintptr(unsafe.Pointer(state)))
	if e1 != 0 {
		err = e1
	}
	return
}
开发者ID:kless,项目名称:term,代码行数:17,代码来源:sys_unix.go



注:本文中的golang.org/x/sys/unix.Syscall函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang unix.Wait4函数代码示例发布时间:2022-05-28
下一篇:
Golang unix.PtraceAttach函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap