Class: OsCtld::Console::Console

Inherits:
TTY
  • Object
show all
Defined in:
lib/osctld/console/console.rb

Overview

Special case for tty0 (/dev/console)

tty0 is opened on container start, at least when it's started by osctld. The tty is accessed using unix server socket created by the osctld container wrapper.

Instance Attribute Summary

Attributes inherited from TTY

#ct, #n, #tty_in_io, #tty_out_io, #tty_pid

Instance Method Summary collapse

Methods inherited from TTY

#add_client, #client_read, #close, #initialize, #opened?, #remove_client, #start, #sync, #tty_read, #tty_write, #wake, #watch_ios

Methods included from Utils::SwitchUser

#ct_attach, #ct_syscmd

Constructor Details

This class inherits a constructor from OsCtld::Console::TTY

Instance Method Details

#connect(pid, socket) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/osctld/console/console.rb', line 15

def connect(pid, socket)
  tries = 0

  begin
    c = UNIXSocket.new(socket)

  rescue Errno::ENOENT
    raise if tries >= (0.2 * 50 * 10) # try for 10 seconds
    tries += 1
    sleep(0.2)
    retry
  end

  sync do
    @opened = true
    self.tty_pid = pid
    self.tty_in_io = c
    self.tty_out_io = c
    wake
  end
end

#on_closeObject (protected)



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/osctld/console/console.rb', line 38

def on_close
  if ct.state == :stopped && ct.ephemeral? && !ct.is_being_manipulated?
    # The container deletion has to be invoked from another thread, because
    # the current thread is used to handle the console and has to exit when
    # the container is being deleted.
    t = Thread.new do
      Commands::Container::Delete.run({
        pool: ct.pool.name,
        id: ct.id,
        force: true,
        manipulation_lock: 'wait',
      })
    end

    ThreadReaper.add(t, nil)
  end
end

#openObject



11
12
13
# File 'lib/osctld/console/console.rb', line 11

def open
  # Does nothing for tty0, it is opened automatically on ct start
end