Class: Seccomp::Notifier
- Inherits:
-
Object
- Object
- Seccomp::Notifier
- Includes:
- Enumerable
- Defined in:
- lib/seccomp/notifier.rb
Overview
Receives and responds to seccomp user notifications.
Instance Method Summary collapse
-
#add_fd(id:, source_fd:, flags: 0, newfd: 0, newfd_flags: 0) ⇒ Integer
Installed descriptor.
- #close ⇒ nil
-
#closed? ⇒ Boolean
Whether the owner filter is closed.
-
#each {|Notification| ... } ⇒ Enumerator, Notifier
Enumerator or receiver.
-
#id_valid?(id) ⇒ Boolean
Whether still valid.
- #initialize(filter, fd) ⇒ void constructor
-
#receive(timeout: nil) ⇒ Notification?
Request or nil on timeout.
- #respond(id:, val: 0, error: 0, flags: 0) ⇒ nil
Constructor Details
#initialize(filter, fd) ⇒ void
18 19 20 21 22 23 |
# File 'lib/seccomp/notifier.rb', line 18 def initialize(filter, fd) @filter = filter @fd = fd @io = IO.for_fd(fd, autoclose: false) @receive_lock = filter.__send__(:notification_receive_lock) end |
Instance Method Details
#add_fd(id:, source_fd:, flags: 0, newfd: 0, newfd_flags: 0) ⇒ Integer
Returns installed descriptor.
93 94 95 96 97 |
# File 'lib/seccomp/notifier.rb', line 93 def add_fd(id:, source_fd:, flags: 0, newfd: 0, newfd_flags: 0) ensure_open! result = LowLevel.notify_addfd(@fd, id, flags, source_fd, newfd, newfd_flags) check_notification_result!(result, call: "seccomp_notify_addfd") end |
#close ⇒ nil
101 102 103 |
# File 'lib/seccomp/notifier.rb', line 101 def close @filter.close end |
#closed? ⇒ Boolean
Returns whether the owner filter is closed.
107 108 109 |
# File 'lib/seccomp/notifier.rb', line 107 def closed? @filter.closed? end |
#each {|Notification| ... } ⇒ Enumerator, Notifier
Returns enumerator or receiver.
46 47 48 49 50 51 52 53 54 |
# File 'lib/seccomp/notifier.rb', line 46 def each return enum_for(__method__) unless block_given? loop do yield receive rescue NotificationCanceledError next end end |
#id_valid?(id) ⇒ Boolean
Returns whether still valid.
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/seccomp/notifier.rb', line 74 def id_valid?(id) ensure_open! result = LowLevel.notify_id_valid(@fd, id) return true if result.zero? ensure_open! return false if [-Errno::ENOENT::Errno, -Errno::EINVAL::Errno].include?(result) check_notification_result!(result, call: "seccomp_notify_id_valid") end |
#receive(timeout: nil) ⇒ Notification?
Returns request or nil on timeout.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/seccomp/notifier.rb', line 31 def receive(timeout: nil) validate_timeout!(timeout) deadline = monotonic_time + timeout if timeout acquired = acquire_receive_lock(deadline) return nil unless acquired receive_locked(remaining_timeout(deadline)) ensure @receive_lock.unlock if acquired end |
#respond(id:, val: 0, error: 0, flags: 0) ⇒ nil
63 64 65 66 67 68 |
# File 'lib/seccomp/notifier.rb', line 63 def respond(id:, val: 0, error: 0, flags: 0) ensure_open! check_notification_result!(LowLevel.notify_respond(@fd, id, val, error, flags), call: "seccomp_notify_respond") nil end |