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

Open
rbucker opened this issue Mar 3, 2020 · 6 comments
Open

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

rbucker opened this issue Mar 3, 2020 · 6 comments

Comments

@rbucker
Copy link

@rbucker 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
Member

@dmitshur 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?

@rbucker
Copy link
Author

@rbucker 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 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 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

@randall77 randall77 commented Mar 5, 2020

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

@ianlancetaylor ianlancetaylor commented Mar 5, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.