Class: Seccomp::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/seccomp/notification.rb

Overview

One immutable user-notification request.

Constant Summary collapse

ATTRIBUTES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Fields copied from the kernel notification request.

%i[id pid flags syscall arch instruction_pointer args].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notifier, data) ⇒ void

Examples:

Notification.new(notifier, data)

Parameters:

  • notifier (Notifier)

    response channel

  • data (Hash)

    low-level request fields



15
16
17
18
19
# File 'lib/seccomp/notification.rb', line 15

def initialize(notifier, data)
  @notifier = notifier
  ATTRIBUTES.each { |attribute| instance_variable_set("@#{attribute}", data.fetch(attribute)) }
  @args.freeze
end

Instance Attribute Details

#archObject (readonly)

Returns the value of attribute arch.



9
10
11
# File 'lib/seccomp/notification.rb', line 9

def arch
  @arch
end

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/seccomp/notification.rb', line 9

def args
  @args
end

#flagsObject (readonly)

Returns the value of attribute flags.



9
10
11
# File 'lib/seccomp/notification.rb', line 9

def flags
  @flags
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/seccomp/notification.rb', line 9

def id
  @id
end

#instruction_pointerObject (readonly)

Returns the value of attribute instruction_pointer.



9
10
11
# File 'lib/seccomp/notification.rb', line 9

def instruction_pointer
  @instruction_pointer
end

#pidObject (readonly)

Returns the value of attribute pid.



9
10
11
# File 'lib/seccomp/notification.rb', line 9

def pid
  @pid
end

#syscallObject (readonly)

Returns the value of attribute syscall.



9
10
11
# File 'lib/seccomp/notification.rb', line 9

def syscall
  @syscall
end

Instance Method Details

#add_fd(io, flags: 0, newfd: 0, newfd_flags: 0) ⇒ Integer

Returns installed descriptor.

Examples:

notification.add_fd(file)

Parameters:

  • io (IO)

    descriptor to install

  • flags (Integer) (defaults to: 0)

    addfd flags

  • newfd (Integer) (defaults to: 0)

    requested target descriptor

  • newfd_flags (Integer) (defaults to: 0)

    target descriptor flags

Returns:

  • (Integer)

    installed descriptor

Raises:



73
74
75
76
# File 'lib/seccomp/notification.rb', line 73

def add_fd(io, flags: 0, newfd: 0, newfd_flags: 0)
  @notifier.add_fd(id: id, source_fd: io.fileno, flags: flags,
                   newfd: newfd, newfd_flags: newfd_flags)
end

#allow(value = 0) ⇒ nil

Examples:

notification.allow(0)

Parameters:

  • value (Integer) (defaults to: 0)

    syscall return value

Returns:

  • (nil)

Raises:

  • (Error)

    if responding fails



43
44
45
# File 'lib/seccomp/notification.rb', line 43

def allow(value = 0)
  respond(val: value)
end

#continue!nil

Examples:

notification.continue!

Returns:

  • (nil)

Raises:

  • (Error)

    if responding fails



62
63
64
# File 'lib/seccomp/notification.rb', line 62

def continue!
  respond(flags: LowLevel::USER_NOTIF_FLAG_CONTINUE)
end

#deny(errno) ⇒ nil

Examples:

notification.deny(Errno::EPERM)

Parameters:

  • errno (Integer, SystemCallError, Class)

    positive errno

Returns:

  • (nil)

Raises:

  • (Error)

    if responding fails

  • (ArgumentError)

    for an invalid errno



52
53
54
55
56
57
# File 'lib/seccomp/notification.rb', line 52

def deny(errno)
  number = errno_number(errno)
  raise ArgumentError, "errno must not be zero" if number.zero?

  respond(error: -number.abs)
end

#respond(val: 0, error: 0, flags: 0) ⇒ nil

Examples:

notification.respond(val: 3)

Parameters:

  • val (Integer) (defaults to: 0)

    syscall return value

  • error (Integer, SystemCallError, Class) (defaults to: 0)

    positive or negative errno

  • flags (Integer) (defaults to: 0)

    response flags

Returns:

  • (nil)

Raises:

  • (Error)

    if responding fails



34
35
36
37
# File 'lib/seccomp/notification.rb', line 34

def respond(val: 0, error: 0, flags: 0)
  error = -errno_number(error).abs unless error.is_a?(Integer) && error.zero?
  @notifier.respond(id: id, val: val, error: error, flags: flags)
end

#valid?Boolean

Returns whether the kernel still recognizes the request.

Examples:

notification.valid?

Returns:

  • (Boolean)

    whether the kernel still recognizes the request

Raises:

  • (Error)

    if validation fails



24
25
26
# File 'lib/seccomp/notification.rb', line 24

def valid?
  @notifier.id_valid?(id)
end