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

device is not configured when running in chroot'd folder #37637

Closed
rbucker opened this issue Mar 3, 2020 · 8 comments
Closed

device is not configured when running in chroot'd folder #37637

rbucker opened this issue Mar 3, 2020 · 8 comments
Labels
FrozenDueToAge OS-OpenBSD WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@rbucker
Copy link

rbucker commented Mar 3, 2020

What version of Go are you using (go version)?

$ go version
1.13.1

Does this issue reproduce with the latest release?

unknown

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/rbucker/.cache/go-build"
GOENV="/home/rbucker/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="openbsd"
GONOPROXY=""
GONOSUMDB=""
GOOS="openbsd"
GOPATH="/home/rbucker/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/openbsd_amd64"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build844217065=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I have compiled my project and it runs from the command line ok, however, in the larger scope of the project this executable is executed via os.Command("runme").Output()... and that's running inside an
OpenBSD chroot.

What did you expect to see?

I expected it to tun to completion without errors as it did in the command line

What did you see instead?

When I triggered my inside app... I received my first error which was open /dev/null file or directory not found. So I performed a MAKEDEV std on that machine in the inner most to be chroot'd folder.... then ran my program and received open /dev/null device not configured

I'm currently trying to figure out what is wrong with my /dev/null but in the meantime... which devices are required or recommended?

@dmitshur
Copy link
Contributor

dmitshur commented Mar 3, 2020

I have compiled my project and it runs from the command line ok, however, in the larger scope of the project this executable is executed via os.Command("runme").Output()... and that's running inside an
OpenBSD chroot.

Is your project closed source? Do you have a reproducible snippet (a smaller one makes investigation easier, but it doesn't have to be) that can be used to reproduce this issue?

@dmitshur dmitshur added OS-OpenBSD WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Mar 3, 2020
@rbucker
Copy link
Author

rbucker commented Mar 5, 2020

Here is a sample....

hello.go

import "fmt"

func main() {
        fmt.Println("Hello, 世界")
}

check.go

package main

import (
        "fmt"
        "os/exec"
)

func main() {
        out, err := exec.Command("./hello").Output()
        if err == nil {
                fmt.Printf("OUT: %s\n", out)
        } else {
                fmt.Printf("ERR: %s\n", err)
        }
}

To build:

go build check.go
go build hello.go

test to make certain it runs...

./check

produces

OUT: Hello, 世界

Then.... try to run in chroot

sudo chroot -g myid -u myid . ./check

and this produces....

ERR: open /dev/null: no such file or directory

so the problem is that the Output() is trying to open the NULL device and that device does not exist in OpenBSD6.6 chroot.

@rbucker
Copy link
Author

rbucker commented Mar 5, 2020

One more note. I created a dev/null in my project folder

mkdir dev
cd dev
ls -l /dev/null
sudo mknod -m 666 null c 2 2

then tried to run it again

sudo chroot -g zurvita -u zurvita . ./check

this time I got

ERR: open /dev/null: device not configured

@rbucker
Copy link
Author

rbucker commented Mar 5, 2020

LASTLY... it is possible that nodev in the /etc/fstab is causing this last error.... still researching as it is not convenient to reboot right now.

@randall77
Copy link
Contributor

You should set stdin, stdout, and stderr of your command.
The spec of exec.Cmd's Stdin field says:

	// Stdin specifies the process's standard input.
	//
	// If Stdin is nil, the process reads from the null device (os.DevNull).
	Stdin io.Reader

Same for Stdout and Stderr.
You could use, e.g., a bytes.Buffer for all of them.

@ianlancetaylor
Copy link
Contributor

Any OpenBSD system should have a file /dev/null. I don't understand why your system does not have that. I suggest asking the OpenBSD community.

@esote
Copy link

esote commented Dec 1, 2021

This appears to be working as intended. Within a chroot either

  1. mknod /dev/null -- the ENXIO ("device not configured") error is indeed from the nodev mount option and removing that should fix things
  2. or, as @randall77 mentions, use empty buffers to avoid opening /dev/null
package main

import (
        "io"
        "os/exec"
        "syscall"
        "testing/iotest"
)

func main() {
        syscall.Chroot("/my/dir")
        cmd := exec.Command("/my/cmd")
        cmd.Stdin = iotest.ErrReader(io.EOF)
        cmd.Stdout = io.Discard
        cmd.Stderr = io.Discard
        cmd.Run()
}

Any OpenBSD system should have a file /dev/null. I don't understand why your system does not have that. I suggest asking the OpenBSD community.

@ianlancetaylor this is specifically within chroot where OpenBSD won't automatically create /dev/null

@ianlancetaylor
Copy link
Contributor

Thanks. It sounds like this is not a problem in the Go standard library, so closing.

@golang golang locked and limited conversation to collaborators Dec 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge OS-OpenBSD WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants