github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/sentry/fsimpl/devpts/terminal.go (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package devpts
    16  
    17  import (
    18  	"github.com/nicocha30/gvisor-ligolo/pkg/abi/linux"
    19  	"github.com/nicocha30/gvisor-ligolo/pkg/sentry/kernel"
    20  )
    21  
    22  // Terminal is a pseudoterminal.
    23  //
    24  // +stateify savable
    25  type Terminal struct {
    26  	// n is the terminal index. It is immutable.
    27  	n uint32
    28  
    29  	// ld is the line discipline of the terminal. It is immutable.
    30  	ld *lineDiscipline
    31  
    32  	// masterKTTY contains the controlling process of the master end of
    33  	// this terminal. This field is immutable.
    34  	masterKTTY *kernel.TTY
    35  
    36  	// replicaKTTY contains the controlling process of the replica end of this
    37  	// terminal. This field is immutable.
    38  	replicaKTTY *kernel.TTY
    39  }
    40  
    41  func newTerminal(n uint32) *Terminal {
    42  	t := &Terminal{
    43  		n:           n,
    44  		masterKTTY:  &kernel.TTY{Index: n},
    45  		replicaKTTY: &kernel.TTY{Index: n},
    46  	}
    47  	t.ld = newLineDiscipline(linux.DefaultReplicaTermios, t)
    48  
    49  	return t
    50  }