当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.InotifyRmWatch函数代码示例

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


在下文中一共展示了InotifyRmWatch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: doDel

func (this *watcher) doDel() error {
	if res, errno := syscall.InotifyRmWatch(this.fd, uint32(this.wd)); res < 0 {
		return os.NewSyscallError("inotify_add_watch", errno)
	}

	return nil
}
开发者ID:darvik80,项目名称:monitor,代码行数:7,代码来源:fsevents_linux.go

示例2: Remove

// Remove stops watching the named file or directory (non-recursively).
func (w *Watcher) Remove(name string) error {
	name = filepath.Clean(name)

	// Fetch the watch.
	w.mu.Lock()
	defer w.mu.Unlock()
	watch, ok := w.watches[name]

	// Remove it from inotify.
	if !ok {
		return fmt.Errorf("can't remove non-existent inotify watch for: %s", name)
	}
	// inotify_rm_watch will return EINVAL if the file has been deleted;
	// the inotify will already have been removed.
	// That means we can safely delete it from our watches, whatever inotify_rm_watch does.
	delete(w.watches, name)
	success, errno := syscall.InotifyRmWatch(w.fd, watch.wd)
	if success == -1 {
		// TODO: Perhaps it's not helpful to return an error here in every case.
		// the only two possible errors are:
		// EBADF, which happens when w.fd is not a valid file descriptor of any kind.
		// EINVAL, which is when fd is not an inotify descriptor or wd is not a valid watch descriptor.
		// Watch descriptors are invalidated when they are removed explicitly or implicitly;
		// explicitly by inotify_rm_watch, implicitly when the file they are watching is deleted.
		return errno
	}
	return nil
}
开发者ID:DaveDaCoda,项目名称:docker,代码行数:29,代码来源:inotify.go

示例3: remove

func (w *inotify) remove(id Id) error {
	watch, ok := w.watches[id]
	if !ok {
		return fmt.Errorf("can't remove non-existent inotify watch for: %x", id)
	}
	success, errno := syscall.InotifyRmWatch(w.watchfd, uint32(watch))
	if success == -1 {
		return os.NewSyscallError("inotify_rm_watch", errno)
	}
	delete(w.watches, id)
	return nil
}
开发者ID:napsy,项目名称:lab,代码行数:12,代码来源:watcher_linux.go

示例4: removeWatch

// RemoveWatch removes path from the watched file set.
func (w *Watcher) removeWatch(path string) error {
	watch, ok := w.watches[path]
	if !ok {
		return errors.New(fmt.Sprintf("can't remove non-existent inotify watch for: %s", path))
	}
	success, errno := syscall.InotifyRmWatch(w.fd, watch.wd)
	if success == -1 {
		return os.NewSyscallError("inotify_rm_watch", errno)
	}
	delete(w.watches, path)
	return nil
}
开发者ID:jbaikge,项目名称:SublimeTextScripts,代码行数:13,代码来源:fsnotify_linux.go

示例5: inotify_rm_watch

func inotify_rm_watch(name string) {
	wd, found := wd_by_name[name]
	if false == found {
		return
	}
	retval, _ /*err*/ := syscall.InotifyRmWatch(inotify_fd, uint32(wd))
	if -1 == retval {
		//println("tabby: InotifyRmWatch failed, errno = ", err)
		return
	}
	delete(name_by_wd, wd)
	delete(wd_by_name, name)
}
开发者ID:udhos,项目名称:tabby,代码行数:13,代码来源:inotify_unix.go

示例6: rmWatch

func (w *Watcher) rmWatch(path string) error {

	if found := w.wm.find(path); found != nil {
		success, errno := syscall.InotifyRmWatch(w.fd, uint32(found.(watch).wd))
		if success == -1 {
			return os.NewSyscallError("inotify_rm_watch", errno)
		}
		w.wm.remove(path)
		fmt.Println("移除监控目录:", path)
	} else {
		fmt.Println("没有找到对应的监控", path)
	}
	return nil

}
开发者ID:nopsky,项目名称:sfserver,代码行数:15,代码来源:notify.go

示例7: Remove

// Remove stops watching the the named file or directory (non-recursively).
func (w *Watcher) Remove(name string) error {
	name = filepath.Clean(name)
	w.mu.Lock()
	defer w.mu.Unlock()
	watch, ok := w.watches[name]
	if !ok {
		return fmt.Errorf("can't remove non-existent inotify watch for: %s", name)
	}
	success, errno := syscall.InotifyRmWatch(w.fd, watch.wd)
	if success == -1 {
		return os.NewSyscallError("inotify_rm_watch", errno)
	}
	delete(w.watches, name)
	return nil
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:16,代码来源:inotify.go

示例8: removeWatch

func (w *Watcher) removeWatch(path string) error {
	watch, ok := w.watches[path]
	if !ok {
		return fmt.Errorf("can't remove non-existent inotify watch for: %s", path)
	}
	if len(w.watches) == 1 {
		atomic.CompareAndSwapInt32(w.state, 1, 0)
	}
	delete(w.watches, path)
	success, errno := syscall.InotifyRmWatch(w.fd, watch.wd)
	if success == -1 {
		return os.NewSyscallError("inotify_rm_watch", errno)
	}
	return nil
}
开发者ID:smillaedler,项目名称:inotify,代码行数:15,代码来源:inotify_linux.go

示例9: main

func main() {
	fd, err := syscall.InotifyInit()
	if err != nil {
		log.Fatal(err)
	}
	defer syscall.Close(fd)

	wd, err := syscall.InotifyAddWatch(fd, "test1.log", syscall.IN_ALL_EVENTS)
	_, err = syscall.InotifyAddWatch(fd, "../test2.log", syscall.IN_ALL_EVENTS)
	//_, err = syscall.InotifyAddWatch(fd, ".", syscall.IN_ALL_EVENTS)
	if err != nil {
		log.Fatal(err)
	}
	defer syscall.InotifyRmWatch(fd, uint32(wd))

	fmt.Printf("WD is %d\n", wd)

	for {
		// Room for at least 128 events
		buffer := make([]byte, syscall.SizeofInotifyEvent*128)
		bytesRead, err := syscall.Read(fd, buffer)
		if err != nil {
			log.Fatal(err)
		}

		if bytesRead < syscall.SizeofInotifyEvent {
			// No point trying if we don't have at least one event
			continue
		}

		fmt.Printf("Size of InotifyEvent is %s\n", syscall.SizeofInotifyEvent)
		fmt.Printf("Bytes read: %d\n", bytesRead)

		offset := 0
		for offset < bytesRead-syscall.SizeofInotifyEvent {
			event := (*syscall.InotifyEvent)(unsafe.Pointer(&buffer[offset]))
			fmt.Printf("%+v\n", event)

			if (event.Mask & syscall.IN_ACCESS) > 0 {
				fmt.Printf("Saw IN_ACCESS for %+v\n", event)
			}

			// We need to account for the length of the name
			offset += syscall.SizeofInotifyEvent + int(event.Len)
		}
	}

}
开发者ID:tomnomnom,项目名称:go-learning,代码行数:48,代码来源:inotify.go

示例10: RemoveWatch

// RemoveWatch removes path from the watched file set.
func (w *Watcher) RemoveWatch(path string) error {
	watch, ok := w.watches[path]
	if !ok {
		return errors.New(fmt.Sprintf("can't remove non-existent inotify watch for: %s", path))
	}
	success, errno := syscall.InotifyRmWatch(w.fd, watch.wd)
	if success == -1 {
		return os.NewSyscallError("inotify_rm_watch", errno)
	}
	delete(w.watches, path)
	// Locking here to protect the read from paths in readEvents.
	w.mu.Lock()
	delete(w.paths, int(watch.wd))
	w.mu.Unlock()
	return nil
}
开发者ID:COLDTURNIP,项目名称:kubernetes,代码行数:17,代码来源:inotify_linux.go

示例11: RemoveWatch

// RemoveWatch removes path from the watched file set.
func (w *Watcher) RemoveWatch(path string) error {
	if w.isClosed {
		return errors.New(fmt.Sprintf("can't remove non-existent inotify watch for: %s", path))
	}
	w.mu.Lock()
	defer w.mu.Unlock()
	watch, ok := w.watches[path]
	if !ok {
		return errors.New(fmt.Sprintf("can't remove non-existent inotify watch for: %s", path))
	}
	success, errno := syscall.InotifyRmWatch(w.fd, watch.wd)
	if success == -1 {
		return os.NewSyscallError("inotify_rm_watch", errno)
	}
	delete(w.watches, path)
	delete(w.paths, int(watch.wd))
	return nil
}
开发者ID:seacoastboy,项目名称:inotify,代码行数:19,代码来源:inotify_linux.go

示例12: Unwatch

// Unwatch implements notify.watcher interface. It looks for watch descriptor
// related to registered path and if found, calls inotify_rm_watch(2) function.
// This method is allowed to return EINVAL error when concurrently requested to
// delete identical path.
func (i *inotify) Unwatch(path string) (err error) {
	iwd := int32(invalidDescriptor)
	i.RLock()
	for iwdkey, wd := range i.m {
		if wd.path == path {
			iwd = iwdkey
			break
		}
	}
	i.RUnlock()
	if iwd == invalidDescriptor {
		return errors.New("notify: path " + path + " is already watched")
	}
	fd := atomic.LoadInt32(&i.fd)
	if _, err = syscall.InotifyRmWatch(int(fd), uint32(iwd)); err != nil {
		return
	}
	i.Lock()
	delete(i.m, iwd)
	i.Unlock()
	return nil
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:26,代码来源:watcher_inotify.go

示例13: Remove

// Remove stops watching the the named file or directory (non-recursively).
func (w *Watcher) Remove(name string) error {
	name = filepath.Clean(name)
	w.mu.Lock()
	defer w.mu.Unlock()
	watch, ok := w.watches[name]
	if !ok {
		return fmt.Errorf("can't remove non-existent inotify watch for: %s", name)
	}
	success, errno := syscall.InotifyRmWatch(w.fd, watch.wd)
	if success == -1 {
		return os.NewSyscallError("inotify_rm_watch", errno)
	}

	// not delete(w.watches, name) here, but in ignoreLinux()
	// use condv to sync with ignoreLinux()
	for ok {
		w.cv.Wait()
		_, ok = w.watches[name]
	}

	return nil
}
开发者ID:makarski,项目名称:fsnotify,代码行数:23,代码来源:inotify.go

示例14: Remove

// Remove stops watching the named file or directory (non-recursively).
func (w *Watcher) Remove(name string) error {
	name = filepath.Clean(name)

	// Fetch the watch.
	w.mu.Lock()
	defer w.mu.Unlock()
	watch, ok := w.watches[name]

	// Remove it from inotify.
	if !ok {
		return fmt.Errorf("can't remove non-existent inotify watch for: %s", name)
	}
	// inotify_rm_watch will return EINVAL if the file has been deleted;
	// the inotify will already have been removed.
	// watches and pathes are deleted in ignoreLinux() implicitly and asynchronously
	// by calling inotify_rm_watch() below. e.g. readEvents() goroutine receives IN_IGNORE
	// so that EINVAL means that the wd is being rm_watch()ed or its file removed
	// by another thread and we have not received IN_IGNORE event.
	success, errno := syscall.InotifyRmWatch(w.fd, watch.wd)
	if success == -1 {
		// TODO: Perhaps it's not helpful to return an error here in every case.
		// the only two possible errors are:
		// EBADF, which happens when w.fd is not a valid file descriptor of any kind.
		// EINVAL, which is when fd is not an inotify descriptor or wd is not a valid watch descriptor.
		// Watch descriptors are invalidated when they are removed explicitly or implicitly;
		// explicitly by inotify_rm_watch, implicitly when the file they are watching is deleted.
		return errno
	}

	// wait until ignoreLinux() deleting maps
	exists := true
	for exists {
		w.cv.Wait()
		_, exists = w.watches[name]
	}

	return nil
}
开发者ID:BenPhegan,项目名称:vagrantshadow,代码行数:39,代码来源:inotify.go

示例15: Close

// Close implements notify.watcher interface. It removes all existing watch
// descriptors and wakes up producer goroutine by sending data to the write end
// of the pipe. The function waits for a signal from producer which means that
// all operations on current monitoring instance are done.
func (i *inotify) Close() (err error) {
	i.Lock()
	if fd := atomic.LoadInt32(&i.fd); fd == invalidDescriptor {
		i.Unlock()
		return nil
	}
	for iwd := range i.m {
		if _, e := syscall.InotifyRmWatch(int(i.fd), uint32(iwd)); e != nil && err == nil {
			err = e
		}
		delete(i.m, iwd)
	}
	switch _, errwrite := syscall.Write(i.pipefd[1], []byte{0x00}); {
	case errwrite != nil && err == nil:
		err = errwrite
		fallthrough
	case errwrite != nil:
		i.Unlock()
	default:
		i.Unlock()
		i.wg.Wait()
	}
	return
}
开发者ID:Codzart,项目名称:go-ethereum,代码行数:28,代码来源:watcher_inotify.go


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