11package libcontainer
22
33import (
4- "encoding/json"
5- "fmt"
64 "io"
75 "os"
86)
@@ -17,57 +15,3 @@ type Console interface {
1715 // Fd returns the fd for the master of the pty.
1816 File () * os.File
1917}
20-
21- const (
22- TerminalInfoVersion uint32 = 201610041
23- TerminalInfoType uint8 = 'T'
24- )
25-
26- // TerminalInfo is the structure which is passed as the non-ancillary data
27- // in the sendmsg(2) call when runc is run with --console-socket. It
28- // contains some information about the container which the console master fd
29- // relates to (to allow for consumers to use a single unix socket to handle
30- // multiple containers). This structure will probably move to runtime-spec
31- // at some point. But for now it lies in libcontainer.
32- type TerminalInfo struct {
33- // Version of the API.
34- Version uint32 `json:"version"`
35-
36- // Type of message (future proofing).
37- Type uint8 `json:"type"`
38-
39- // Container contains the ID of the container.
40- ContainerID string `json:"container_id"`
41- }
42-
43- func (ti * TerminalInfo ) String () string {
44- encoded , err := json .Marshal (* ti )
45- if err != nil {
46- panic (err )
47- }
48- return string (encoded )
49- }
50-
51- func NewTerminalInfo (containerId string ) * TerminalInfo {
52- return & TerminalInfo {
53- Version : TerminalInfoVersion ,
54- Type : TerminalInfoType ,
55- ContainerID : containerId ,
56- }
57- }
58-
59- func GetTerminalInfo (encoded string ) (* TerminalInfo , error ) {
60- ti := new (TerminalInfo )
61- if err := json .Unmarshal ([]byte (encoded ), ti ); err != nil {
62- return nil , err
63- }
64-
65- if ti .Type != TerminalInfoType {
66- return nil , fmt .Errorf ("terminal info: incorrect type in payload (%q): %q" , TerminalInfoType , ti .Type )
67- }
68- if ti .Version != TerminalInfoVersion {
69- return nil , fmt .Errorf ("terminal info: incorrect version in payload (%q): %q" , TerminalInfoVersion , ti .Version )
70- }
71-
72- return ti , nil
73- }
0 commit comments