inotify.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Copyright 2020 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package inotify // import "k8s.io/utils/inotify"
  14. import (
  15. "sync"
  16. )
  17. // Event represents a notification
  18. type Event struct {
  19. Mask uint32 // Mask of events
  20. Cookie uint32 // Unique cookie associating related events (for rename(2))
  21. Name string // File name (optional)
  22. }
  23. type watch struct {
  24. wd uint32 // Watch descriptor (as returned by the inotify_add_watch() syscall)
  25. flags uint32 // inotify flags of this watch (see inotify(7) for the list of valid flags)
  26. }
  27. // Watcher represents an inotify instance
  28. type Watcher struct {
  29. mu sync.Mutex
  30. fd int // File descriptor (as returned by the inotify_init() syscall)
  31. watches map[string]*watch // Map of inotify watches (key: path)
  32. paths map[int]string // Map of watched paths (key: watch descriptor)
  33. Error chan error // Errors are sent on this channel
  34. Event chan *Event // Events are returned on this channel
  35. done chan bool // Channel for sending a "quit message" to the reader goroutine
  36. isClosed bool // Set to true when Close() is first called
  37. }