Class: Fanotify::Event
- Inherits:
-
Object
- Object
- Fanotify::Event
- Defined in:
- lib/fanotify/event.rb
Overview
One parsed fanotify event and any descriptors owned by it.
Constant Summary collapse
- INFO_FID =
1- INFO_DFID_NAME =
2- INFO_DFID =
3- INFO_PIDFD =
4- INFO_ERROR =
5- INFO_RANGE =
6- INFO_OLD_DFID_NAME =
10- INFO_NEW_DFID_NAME =
12
Instance Attribute Summary collapse
-
#dfid ⇒ Object
readonly
Returns the value of attribute dfid.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_count ⇒ Object
readonly
Returns the value of attribute error_count.
-
#fid ⇒ Object
readonly
Returns the value of attribute fid.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#new_dfid ⇒ Object
readonly
Returns the value of attribute new_dfid.
-
#new_name ⇒ Object
readonly
Returns the value of attribute new_name.
-
#notifier ⇒ Object
readonly
Returns the value of attribute notifier.
-
#old_dfid ⇒ Object
readonly
Returns the value of attribute old_dfid.
-
#old_name ⇒ Object
readonly
Returns the value of attribute old_name.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#pidfd ⇒ Object
readonly
Returns the value of attribute pidfd.
-
#pidfd_error ⇒ Object
readonly
Returns the value of attribute pidfd_error.
-
#range_count ⇒ Object
readonly
Returns the value of attribute range_count.
-
#range_offset ⇒ Object
readonly
Returns the value of attribute range_offset.
-
#raw_mask ⇒ Object
readonly
Returns the value of attribute raw_mask.
Class Method Summary collapse
Instance Method Summary collapse
- #allow!(audit: false) ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #defer! ⇒ Object
- #deferred? ⇒ Boolean
- #deleted? ⇒ Boolean
- #deny!(audit: false) ⇒ Object
- #file ⇒ Object
-
#initialize(attributes, notifier: nil, own_fds: false) ⇒ Event
constructor
A new instance of Event.
- #mask ⇒ Object
- #overflow? ⇒ Boolean
- #path ⇒ Object
- #permission? ⇒ Boolean
- #process_path ⇒ Object
- #responded? ⇒ Boolean
Constructor Details
#initialize(attributes, notifier: nil, own_fds: false) ⇒ Event
Returns a new instance of Event.
47 48 49 50 51 52 53 54 55 |
# File 'lib/fanotify/event.rb', line 47 def initialize(attributes, notifier: nil, own_fds: false) @raw_mask = attributes.fetch(:raw_mask) @pid = attributes[:pid].negative? ? nil : attributes[:pid] @notifier = notifier @event_fd = attributes[:fd] unless attributes[:fd] == FAN_NOFD @response_mutex = Mutex.new @file_descriptor = attributes[:file_descriptor] if own_fds attributes.fetch(:infos).each { |info| apply_info(info, own_fds:) } end |
Instance Attribute Details
#dfid ⇒ Object (readonly)
Returns the value of attribute dfid.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def dfid @dfid end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def error @error end |
#error_count ⇒ Object (readonly)
Returns the value of attribute error_count.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def error_count @error_count end |
#fid ⇒ Object (readonly)
Returns the value of attribute fid.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def fid @fid end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def name @name end |
#new_dfid ⇒ Object (readonly)
Returns the value of attribute new_dfid.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def new_dfid @new_dfid end |
#new_name ⇒ Object (readonly)
Returns the value of attribute new_name.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def new_name @new_name end |
#notifier ⇒ Object (readonly)
Returns the value of attribute notifier.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def notifier @notifier end |
#old_dfid ⇒ Object (readonly)
Returns the value of attribute old_dfid.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def old_dfid @old_dfid end |
#old_name ⇒ Object (readonly)
Returns the value of attribute old_name.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def old_name @old_name end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def pid @pid end |
#pidfd ⇒ Object (readonly)
Returns the value of attribute pidfd.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def pidfd @pidfd end |
#pidfd_error ⇒ Object (readonly)
Returns the value of attribute pidfd_error.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def pidfd_error @pidfd_error end |
#range_count ⇒ Object (readonly)
Returns the value of attribute range_count.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def range_count @range_count end |
#range_offset ⇒ Object (readonly)
Returns the value of attribute range_offset.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def range_offset @range_offset end |
#raw_mask ⇒ Object (readonly)
Returns the value of attribute raw_mask.
15 16 17 |
# File 'lib/fanotify/event.rb', line 15 def raw_mask @raw_mask end |
Class Method Details
.parse(buffer) ⇒ Object
20 21 22 |
# File 'lib/fanotify/event.rb', line 20 def parse(buffer) Native.parse(buffer).map { |attributes| new(attributes) } end |
Instance Method Details
#allow!(audit: false) ⇒ Object
95 |
# File 'lib/fanotify/event.rb', line 95 def allow!(audit: false) = respond!(FAN_ALLOW, audit:) |
#close ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/fanotify/event.rb', line 116 def close @response_mutex.synchronize do return if closed? begin respond_without_lock(FAN_ALLOW, audit: false) if && !responded? && notifier ensure active_error = $! close_error = nil if deferred? begin notifier.__send__(:unregister_pending, @pending_token) rescue StandardError => error close_error ||= error ensure @pending_token = nil @deferred = false end end [@file, @file_descriptor, @pidfd_descriptor].each do |resource| resource&.close unless resource&.closed? rescue StandardError => error close_error ||= error end @closed = true raise close_error if !active_error && close_error end nil end rescue Exception # Closing the group is the only remaining fail-open response. fail_open_notifier raise end |
#closed? ⇒ Boolean
93 |
# File 'lib/fanotify/event.rb', line 93 def closed? = @closed || false |
#defer! ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/fanotify/event.rb', line 98 def defer! raise Error, "only permission events can be deferred" unless raise Error, "event is not associated with a notifier" unless notifier @response_mutex.synchronize do raise Error, "event is closed" if closed? raise Error, "event has already been responded to" if responded? return self if deferred? Thread.handle_interrupt(Exception => :never) do @pending_token = notifier.__send__(:register_pending, self, @event_fd, [@file_descriptor, @pidfd_descriptor].compact) @deferred = true end end self end |
#deferred? ⇒ Boolean
92 |
# File 'lib/fanotify/event.rb', line 92 def deferred? = @deferred || false |
#deleted? ⇒ Boolean
88 |
# File 'lib/fanotify/event.rb', line 88 def deleted? = path&.end_with?(" (deleted)") || false |
#deny!(audit: false) ⇒ Object
96 |
# File 'lib/fanotify/event.rb', line 96 def deny!(audit: false) = respond!(FAN_DENY, audit:) |
#file ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/fanotify/event.rb', line 61 def file @response_mutex.synchronize do raise Error, "event is closed" if closed? @file ||= @file_descriptor&.to_io&.dup end end |
#mask ⇒ Object
57 58 59 |
# File 'lib/fanotify/event.rb', line 57 def mask EVENT_MASKS.filter_map { |name, value| name if (raw_mask & value).positive? } end |
#overflow? ⇒ Boolean
89 |
# File 'lib/fanotify/event.rb', line 89 def overflow? = (raw_mask & FAN_Q_OVERFLOW).positive? |
#path ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fanotify/event.rb', line 69 def path @response_mutex.synchronize do raise Error, "event is closed" if closed? return unless @event_fd File.readlink("/proc/self/fd/#{@event_fd}") end rescue SystemCallError nil end |
#permission? ⇒ Boolean
90 |
# File 'lib/fanotify/event.rb', line 90 def = (raw_mask & Notifier::PERMISSION_MASK).positive? |
#process_path ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/fanotify/event.rb', line 80 def process_path return unless pid File.readlink("/proc/#{pid}/exe") rescue SystemCallError nil end |
#responded? ⇒ Boolean
91 |
# File 'lib/fanotify/event.rb', line 91 def responded? = @responded || false |