本文整理汇总了Golang中github.com/docker/docker/pkg/term.SetRawTerminal函数的典型用法代码示例。如果您正苦于以下问题:Golang SetRawTerminal函数的具体用法?Golang SetRawTerminal怎么用?Golang SetRawTerminal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SetRawTerminal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: createTty
func createTty(p *libcontainer.Process, rootuid int, consolePath string) (*tty, error) {
if consolePath != "" {
if err := p.ConsoleFromPath(consolePath); err != nil {
return nil, err
}
return &tty{}, nil
}
console, err := p.NewConsole(rootuid)
if err != nil {
return nil, err
}
go io.Copy(console, os.Stdin)
go io.Copy(os.Stdout, console)
state, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
return nil, fmt.Errorf("failed to set the terminal from the stdin: %v", err)
}
t := &tty{
console: console,
state: state,
closers: []io.Closer{
console,
},
}
return t, nil
}
开发者ID:kimh,项目名称:runc,代码行数:27,代码来源:tty.go
示例2: readPassword
func readPassword() string {
var oldState *term.State
var input string
oldState, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
authLogger.WithField("Error", err).Debug("Unable to Set Raw Terminal")
}
print("Password: ")
term.DisableEcho(os.Stdin.Fd(), oldState)
defer term.RestoreTerminal(os.Stdin.Fd(), oldState)
_, err = fmt.Scanln(&input)
if err != nil {
authLogger.WithField("Error", err).Debug("Unable to read password")
}
if input == "" {
authLogger.Println("Password required")
os.Exit(1)
}
print("\n")
return input
}
开发者ID:wercker,项目名称:wercker,代码行数:25,代码来源:auth.go
示例3: AttachTerminal
// AttachTerminal connects us to container and gives us a terminal
func (c *DockerClient) AttachTerminal(containerID string) error {
c.logger.Println("Attaching to ", containerID)
opts := docker.AttachToContainerOptions{
Container: containerID,
Logs: true,
Stdin: true,
Stdout: true,
Stderr: true,
Stream: true,
InputStream: os.Stdin,
ErrorStream: os.Stderr,
OutputStream: os.Stdout,
RawTerminal: true,
}
var oldState *term.State
oldState, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
return err
}
defer term.RestoreTerminal(os.Stdin.Fd(), oldState)
go func() {
err := c.AttachToContainer(opts)
if err != nil {
c.logger.Panicln("attach panic", err)
}
}()
_, err = c.WaitContainer(containerID)
return err
}
开发者ID:rlugojr,项目名称:wercker,代码行数:34,代码来源:docker.go
示例4: SetRawTerminal
// SetRawTerminal sets raw mode on the input terminal
func (i *InStream) SetRawTerminal() (err error) {
if os.Getenv("NORAW") != "" || !i.isTerminal {
return nil
}
i.state, err = term.SetRawTerminal(i.fd)
return err
}
开发者ID:SUSE,项目名称:docker.mirror,代码行数:8,代码来源:in.go
示例5: Run
// Run creates, start and attach to the container based on the image name,
// the specified configuration.
// It will always create a new container.
func (c *Container) Run(ctx context.Context, configOverride *config.ServiceConfig) (int, error) {
var (
errCh chan error
out, stderr io.Writer
in io.ReadCloser
)
if configOverride.StdinOpen {
in = os.Stdin
}
if configOverride.Tty {
out = os.Stdout
}
if configOverride.Tty {
stderr = os.Stderr
}
options := types.ContainerAttachOptions{
Stream: true,
Stdin: configOverride.StdinOpen,
Stdout: configOverride.Tty,
Stderr: configOverride.Tty,
}
resp, err := c.client.ContainerAttach(ctx, c.container.ID, options)
if err != nil {
return -1, err
}
// set raw terminal
inFd, _ := term.GetFdInfo(in)
state, err := term.SetRawTerminal(inFd)
if err != nil {
return -1, err
}
// restore raw terminal
defer term.RestoreTerminal(inFd, state)
// holdHijackedConnection (in goroutine)
errCh = promise.Go(func() error {
return holdHijackedConnection(configOverride.Tty, in, out, stderr, resp)
})
if err := c.client.ContainerStart(ctx, c.container.ID, types.ContainerStartOptions{}); err != nil {
return -1, err
}
if err := <-errCh; err != nil {
logrus.Debugf("Error hijack: %s", err)
return -1, err
}
exitedContainer, err := c.client.ContainerInspect(ctx, c.container.ID)
if err != nil {
return -1, err
}
return exitedContainer.State.ExitCode, nil
}
开发者ID:vdemeester,项目名称:rancher-compose,代码行数:61,代码来源:container.go
示例6: Run
// Run executes a validated remote execution against a pod.
func (p *AttachOptions) Run() error {
pod, err := p.Client.Pods(p.Namespace).Get(p.PodName)
if err != nil {
return err
}
if pod.Status.Phase != api.PodRunning {
return fmt.Errorf("pod %s is not running and cannot be attached to; current phase is %s", p.PodName, pod.Status.Phase)
}
// TODO: refactor with terminal helpers from the edit utility once that is merged
var stdin io.Reader
tty := p.TTY
if p.Stdin {
stdin = p.In
if tty {
if file, ok := stdin.(*os.File); ok {
inFd := file.Fd()
if term.IsTerminal(inFd) {
oldState, err := term.SetRawTerminal(inFd)
if err != nil {
glog.Fatal(err)
}
// this handles a clean exit, where the command finished
defer term.RestoreTerminal(inFd, oldState)
// SIGINT is handled by term.SetRawTerminal (it runs a goroutine that listens
// for SIGINT and restores the terminal before exiting)
// this handles SIGTERM
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM)
go func() {
<-sigChan
term.RestoreTerminal(inFd, oldState)
os.Exit(0)
}()
} else {
fmt.Fprintln(p.Err, "STDIN is not a terminal")
}
} else {
tty = false
fmt.Fprintln(p.Err, "Unable to use a TTY - input is not the right kind of file")
}
}
}
// TODO: consider abstracting into a client invocation or client helper
req := p.Client.RESTClient.Post().
Resource("pods").
Name(pod.Name).
Namespace(pod.Namespace).
SubResource("attach").
Param("container", p.GetContainerName(pod))
return p.Attach.Attach("POST", req.URL(), p.Config, stdin, p.Out, p.Err, tty)
}
开发者ID:niniwzw,项目名称:kubernetes,代码行数:58,代码来源:attach.go
示例7: setRawTerminal
func (cli *DockerCli) setRawTerminal() error {
if cli.isTerminalIn && os.Getenv("NORAW") == "" {
state, err := term.SetRawTerminal(cli.inFd)
if err != nil {
return err
}
cli.state = state
}
return nil
}
开发者ID:RAMESHBABUK,项目名称:docker,代码行数:10,代码来源:cli.go
示例8: Console
// Console opens a secure console to a code or database service. For code
// services, a command is required. This command is executed as root in the
// context of the application root directory. For database services, no command
// is needed - instead, the appropriate command for the database type is run.
// For example, for a postgres database, psql is run.
func Console(serviceLabel string, command string, settings *models.Settings) {
helpers.SignIn(settings)
service := helpers.RetrieveServiceByLabel(serviceLabel, settings)
if service == nil {
fmt.Printf("Could not find a service with the label \"%s\"\n", serviceLabel)
os.Exit(1)
}
fmt.Printf("Opening console to %s (%s)\n", serviceLabel, service.ID)
task := helpers.RequestConsole(command, service.ID, settings)
fmt.Print("Waiting for the console to be ready. This might take a minute.")
ch := make(chan string, 1)
go helpers.PollConsoleJob(task.ID, service.ID, ch, settings)
jobID := <-ch
defer helpers.DestroyConsole(jobID, service.ID, settings)
creds := helpers.RetrieveConsoleTokens(jobID, service.ID, settings)
creds.URL = strings.Replace(creds.URL, "http", "ws", 1)
fmt.Println("Connecting...")
// BEGIN websocket impl
config, _ := websocket.NewConfig(creds.URL, "ws://localhost:9443/")
config.TlsConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
config.Header["X-Console-Token"] = []string{creds.Token}
ws, err := websocket.DialConfig(config)
if err != nil {
panic(err)
}
defer ws.Close()
fmt.Println("Connection opened")
stdin, stdout, _ := term.StdStreams()
fdIn, isTermIn := term.GetFdInfo(stdin)
if !isTermIn {
panic(errors.New("StdIn is not a terminal"))
}
oldState, err := term.SetRawTerminal(fdIn)
if err != nil {
panic(err)
}
done := make(chan bool)
msgCh := make(chan []byte, 2)
go webSocketDaemon(ws, &stdout, done, msgCh)
signal.Notify(make(chan os.Signal, 1), os.Interrupt)
defer term.RestoreTerminal(fdIn, oldState)
go termDaemon(&stdin, ws)
<-done
}
开发者ID:jkoelndorfer,项目名称:cli,代码行数:58,代码来源:console.go
示例9: startInExistingContainer
// the process for execing a new process inside an existing container is that we have to exec ourself
// with the nsenter argument so that the C code can setns an the namespaces that we require. Then that
// code path will drop us into the path that we can do the final setup of the namespace and exec the users
// application.
func startInExistingContainer(config *libcontainer.Config, state *libcontainer.State, action string, context *cli.Context) (int, error) {
var (
master *os.File
console string
err error
sigc = make(chan os.Signal, 10)
stdin = os.Stdin
stdout = os.Stdout
stderr = os.Stderr
)
signal.Notify(sigc)
if config.Tty && action != "setup" {
stdin = nil
stdout = nil
stderr = nil
master, console, err = consolepkg.CreateMasterAndConsole()
if err != nil {
return -1, err
}
go io.Copy(master, os.Stdin)
go io.Copy(os.Stdout, master)
state, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
return -1, err
}
defer term.RestoreTerminal(os.Stdin.Fd(), state)
}
startCallback := func(cmd *exec.Cmd) {
go func() {
resizeTty(master)
for sig := range sigc {
switch sig {
case syscall.SIGWINCH:
resizeTty(master)
default:
cmd.Process.Signal(sig)
}
}
}()
}
return namespaces.ExecIn(config, state, context.Args(), os.Args[0], action, stdin, stdout, stderr, console, startCallback)
}
开发者ID:bmanas,项目名称:amazon-ecs-agent,代码行数:56,代码来源:exec.go
示例10: runIn
func runIn(container *libcontainer.Config, state *libcontainer.State, args []string) (int, error) {
var (
master *os.File
console string
err error
stdin = os.Stdin
stdout = os.Stdout
stderr = os.Stderr
sigc = make(chan os.Signal, 10)
)
signal.Notify(sigc)
if container.Tty {
stdin = nil
stdout = nil
stderr = nil
master, console, err = consolepkg.CreateMasterAndConsole()
if err != nil {
log.Fatal(err)
}
go io.Copy(master, os.Stdin)
go io.Copy(os.Stdout, master)
state, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
log.Fatal(err)
}
defer term.RestoreTerminal(os.Stdin.Fd(), state)
}
startCallback := func(cmd *exec.Cmd) {
go func() {
resizeTty(master)
for sig := range sigc {
switch sig {
case syscall.SIGWINCH:
resizeTty(master)
default:
cmd.Process.Signal(sig)
}
}
}()
}
return namespaces.RunIn(container, state, args, os.Args[0], stdin, stdout, stderr, console, startCallback)
}
开发者ID:JianfuLi,项目名称:docker,代码行数:52,代码来源:exec.go
示例11: AttachInteractive
// AttachInteractive starts an interactive session and runs cmd
func (c *DockerClient) AttachInteractive(containerID string, cmd []string, initialStdin []string) error {
exec, err := c.CreateExec(docker.CreateExecOptions{
AttachStdin: true,
AttachStdout: true,
AttachStderr: true,
Tty: true,
Cmd: cmd,
Container: containerID,
})
if err != nil {
return err
}
// Dump any initial stdin then go into os.Stdin
readers := []io.Reader{}
for _, s := range initialStdin {
if s != "" {
readers = append(readers, strings.NewReader(s+"\n"))
}
}
readers = append(readers, os.Stdin)
stdin := io.MultiReader(readers...)
// This causes our ctrl-c's to be passed to the stuff in the terminal
var oldState *term.State
oldState, err = term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
return err
}
defer term.RestoreTerminal(os.Stdin.Fd(), oldState)
// Handle resizes
sigchan := make(chan os.Signal, 1)
signal.Notify(sigchan, dockersignal.SIGWINCH)
go func() {
for range sigchan {
c.ResizeTTY(exec.ID)
}
}()
err = c.StartExec(exec.ID, docker.StartExecOptions{
InputStream: stdin,
OutputStream: os.Stdout,
ErrorStream: os.Stderr,
Tty: true,
RawTerminal: true,
})
return err
}
开发者ID:rlugojr,项目名称:wercker,代码行数:53,代码来源:docker.go
示例12: Connect
// Connect
func Connect(in io.Reader, out io.Writer) (*term.State, error) {
stdInFD, _ := term.GetFdInfo(in)
stdOutFD, _ := term.GetFdInfo(out)
// handle all incoming os signals and act accordingly; default behavior is to
// forward all signals to nanobox server
go monitor(stdOutFD)
// try to upgrade to a raw terminal; if accessed via a terminal this will upgrade
// with no error, if not an error will be returned
return term.SetRawTerminal(stdInFD)
}
开发者ID:pauldevelder,项目名称:nanobox,代码行数:14,代码来源:terminal.go
示例13: execInternal
func execInternal(where, params string, in io.Reader, out io.Writer) error {
// if we can't connect to the server, lets bail out early
conn, err := net.Dial("tcp4", config.ServerURI)
if err != nil {
return err
}
defer conn.Close()
// get current term info
stdInFD, isTerminal := term.GetFdInfo(in)
stdOutFD, _ := term.GetFdInfo(out)
//
terminal.PrintNanoboxHeader(where)
// begin watching for changes to the project
go func() {
if err := notifyutil.Watch(config.CWDir, NotifyServer); err != nil {
fmt.Printf(err.Error())
}
}()
// if we are using a term, lets upgrade it to RawMode
if isTerminal {
// handle all incoming os signals and act accordingly; default behavior is to
// forward all signals to nanobox server
go monitorTerminal(stdOutFD)
oldState, err := term.SetRawTerminal(stdInFD)
// we only use raw mode if it is available.
if err == nil {
defer term.RestoreTerminal(stdInFD, oldState)
}
}
// make a http request
switch where {
case "develop":
if _, err := fmt.Fprintf(conn, "POST /develop?pid=%d&%v HTTP/1.1\r\n\r\n", os.Getpid(), params); err != nil {
return err
}
default:
if _, err := fmt.Fprintf(conn, "POST /exec?pid=%d&%v HTTP/1.1\r\n\r\n", os.Getpid(), params); err != nil {
return err
}
}
return pipeToConnection(conn, in, out)
}
开发者ID:johan48191,项目名称:nanobox,代码行数:51,代码来源:exec.go
示例14: attach
func (t *tty) attach(process *libcontainer.Process) error {
if t.console != nil {
go io.Copy(t.console, os.Stdin)
go io.Copy(os.Stdout, t.console)
state, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
return err
}
t.state = state
process.Stderr = nil
process.Stdout = nil
process.Stdin = nil
}
return nil
}
开发者ID:alena1108,项目名称:kubernetes,代码行数:15,代码来源:tty.go
示例15: runContainer
func (t *Task) runContainer(ctx *context.ExecuteContext) error {
interactive := t.config.Interactive
name := ContainerName(ctx, t.name.Resource())
container, err := ctx.Client.CreateContainer(t.createOptions(ctx, name))
if err != nil {
return fmt.Errorf("failed creating container %q: %s", name, err)
}
chanSig := t.forwardSignals(ctx.Client, container.ID)
defer signal.Stop(chanSig)
defer RemoveContainer(t.logger(), ctx.Client, container.ID, true)
_, err = ctx.Client.AttachToContainerNonBlocking(docker.AttachToContainerOptions{
Container: container.ID,
OutputStream: t.output(),
ErrorStream: os.Stderr,
InputStream: ioutil.NopCloser(os.Stdin),
Stream: true,
Stdin: t.config.Interactive,
RawTerminal: t.config.Interactive,
Stdout: true,
Stderr: true,
})
if err != nil {
return fmt.Errorf("failed attaching to container %q: %s", name, err)
}
if interactive {
inFd, _ := term.GetFdInfo(os.Stdin)
state, err := term.SetRawTerminal(inFd)
if err != nil {
return err
}
defer func() {
if err := term.RestoreTerminal(inFd, state); err != nil {
t.logger().Warnf("Failed to restore fd %v: %s", inFd, err)
}
}()
}
if err := ctx.Client.StartContainer(container.ID, nil); err != nil {
return fmt.Errorf("failed starting container %q: %s", name, err)
}
return t.wait(ctx.Client, container.ID)
}
开发者ID:dnephin,项目名称:dobi,代码行数:46,代码来源:run.go
示例16: attachTty
func attachTty(consolePath *string) error {
console, err := libcontainer.NewConsole(os.Getuid(), os.Getgid())
if err != nil {
return err
}
*consolePath = console.Path()
stdin = console
go func() {
io.Copy(os.Stdout, console)
console.Close()
}()
s, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
return err
}
state = s
return nil
}
开发者ID:mynameismevin,项目名称:containerd,代码行数:18,代码来源:container.go
示例17: setRawTerminal
func (cli *DockerCli) setRawTerminal() error {
if os.Getenv("NORAW") == "" {
if cli.isTerminalIn {
state, err := term.SetRawTerminal(cli.inFd)
if err != nil {
return err
}
cli.inState = state
}
if cli.isTerminalOut {
state, err := term.SetRawTerminalOutput(cli.outFd)
if err != nil {
return err
}
cli.outState = state
}
}
return nil
}
开发者ID:Raphaeljunior,项目名称:docker,代码行数:19,代码来源:cli.go
示例18: Connect
// Connect
func Connect(in io.Reader, out io.Writer) {
stdInFD, isTerminal := term.GetFdInfo(in)
stdOutFD, _ := term.GetFdInfo(out)
// if we are using a term, lets upgrade it to RawMode
if isTerminal {
// handle all incoming os signals and act accordingly; default behavior is to
// forward all signals to nanobox server
go monitor(stdOutFD)
oldState, err := term.SetRawTerminal(stdInFD)
// we only use raw mode if it is available.
if err == nil {
defer term.RestoreTerminal(stdInFD, oldState)
}
}
}
开发者ID:sfermigier,项目名称:nanobox,代码行数:21,代码来源:terminal.go
示例19: startInteractive
func (p *process) startInteractive() error {
f, err := pty.Start(p.cmd)
if err != nil {
return err
}
p.pty = f
if p.wire.Input == os.Stdin {
// the current terminal shall pass everything to the console, make it ignores ctrl+C etc ...
// this is done by making the terminal raw. The state is saved to reset user's terminal settings
// when dock exits
state, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
return err
}
p.termState = &termState{
state: state,
fd: os.Stdin.Fd(),
}
} else {
// wire.Input is a socket (tcp, tls ...). Obvioulsy, we can't set the remote user's terminal in raw mode, however we can at least
// disable echo on the console
state, err := term.SaveState(p.pty.Fd())
if err != nil {
return err
}
if err := term.DisableEcho(p.pty.Fd(), state); err != nil {
return err
}
p.termState = &termState{
state: state,
fd: p.pty.Fd(),
}
}
p.resizePty()
go io.Copy(p.wire, f)
go io.Copy(f, p.wire)
return nil
}
开发者ID:robinmonjo,项目名称:dock,代码行数:40,代码来源:process.go
示例20: recvtty
func (t *tty) recvtty(process *libcontainer.Process, detach bool) error {
console, err := process.GetConsole()
if err != nil {
return err
}
if !detach {
go io.Copy(console, os.Stdin)
t.wg.Add(1)
go t.copyIO(os.Stdout, console)
state, err := term.SetRawTerminal(os.Stdin.Fd())
if err != nil {
return fmt.Errorf("failed to set the terminal from the stdin: %v", err)
}
t.state = state
}
t.console = console
t.closers = []io.Closer{console}
return nil
}
开发者ID:jfrazelle,项目名称:runc,代码行数:22,代码来源:tty.go
注:本文中的github.com/docker/docker/pkg/term.SetRawTerminal函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论