Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/term: operation not supported by device #65095

Closed
kcmvp opened this issue Jan 13, 2024 · 4 comments
Closed

x/term: operation not supported by device #65095

kcmvp opened this issue Jan 13, 2024 · 4 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@kcmvp
Copy link

kcmvp commented Jan 13, 2024

Go version

go version go1.21.4 darwin/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/Users/kcmvp/Library/Caches/go-build'
GOENV='/Users/kcmvp/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/kcmvp/go/1.21.4/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/kcmvp/go/1.21.4'
GOPRIVATE=''
GOPROXY='https://goproxy.cn'
GOROOT='/Users/kcmvp/.goenv/versions/1.21.4'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/kcmvp/.goenv/versions/1.21.4/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/kcmvp/sandbox/gob/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/0r/y528m9x502d8w4mhps1t6qsr0000gn/T/go-build1470760717=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

run the sample code as from https://pkg.go.dev/golang.org/x/term#section-readme

oldState, err := term.MakeRaw(int(os.Stdin.Fd())) if err != nil { panic(err) } defer term.Restore(int(os.Stdin.Fd()), oldState)

What did you see happen?

The code failed with error message
operation not supported by device

What did you expect to see?

I suppose there should be no error when executing this code. at the same time the error message is so geneirc dont give any information why run into this error

@creack
Copy link
Contributor

creack commented Jan 13, 2024

This error comes from the ioctl syscall when trying to change the setting of the tty device. Are you sure your device supports such operation?

@seankhliao seankhliao changed the title x/term:operation not supported by device x/term: operation not supported by device Jan 13, 2024
@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 13, 2024
@kcmvp
Copy link
Author

kcmvp commented Jan 14, 2024

This error comes from the ioctl syscall when trying to change the setting of the tty device. Are you sure your device supports such operation?

sorry for my poor knowledge abut this. blow is from AI's suggestion. the test result shows it supports.

To check if a device supports the TTY (teletypewriter) device, you can use the test command in a shell script. Here's an example using bash:

if [[ -t 0 && -t 1 ]]; then
  echo "The device supports TTY."
else
  echo "The device does not support TTY."
fi

This script checks if file descriptors 0 (stdin) and 1 (stdout) are associated with a terminal device. If both file descriptors are associated with a terminal, it means the device supports TTY.

You can run this script in your terminal to check if your device supports TTY.

here is the output of above script

image

@seankhliao seankhliao added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jan 14, 2024
@adonovan
Copy link
Member

What is the standard input file of your process? On macOS, usually it is the Terminal application, in which case this program silently succeeds:

$ cat a.go
package main

import (
	"os"
	"golang.org/x/term"
)

func main() {
	oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
	if err != nil {
		panic(err)
	}
	defer term.Restore(int(os.Stdin.Fd()), oldState)
}

$ go run a.go 

But If you close stdin:

$ go run a.go <&-
fork/exec a: bad file descriptor

or read from a regular file:

$ go run a.go < a.go 
panic: inappropriate ioctl for device

goroutine 1 [running]:
main.main()
	/Users/adonovan/w/xtools/a.go:14 +0xf4
exit status 2

then you can't use terminal ioctls on stdin.

@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants